From 13bbfb9ba8af618e47b80aba6a11f04e3492ae7b Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 3 Feb 2023 17:19:41 -0400 Subject: global: Add context for decomp.me --- context.h | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 context.h diff --git a/context.h b/context.h new file mode 100644 index 0000000..38e55fe --- /dev/null +++ b/context.h @@ -0,0 +1,192 @@ +// Typedefs. +typedef signed char s8; +typedef signed short int s16; +typedef signed long s32; +typedef signed long long int s64; +typedef unsigned char u8; +typedef unsigned short int u16; +typedef unsigned long u32; +typedef unsigned long long int u64; +typedef int BOOL; + +// Macros. +#define FALSE 0 +#define TRUE 1 + +#define NULL 0 +#if !defined(__cplusplus) || __cplusplus < 201103L +#ifndef nullptr +#define nullptr NULL +#endif +#endif +#define ATTRIBUTE_ALIGN(num) __attribute__((aligned(num))) + +#define OBJECT_NAME(name) const char *name##_name = #name; +#define OBJECT_NAMES \ + o(TObject) \ + o(TMainTask) + +#define FOREACH_NODE(type, first, varname) for (type *varname = (type *)(first); varname != NULL; varname = (type *)(varname->next)) +#define FOREACH_NODE_NODECL(type, first, varname) for (varname = (type *)(first); varname != NULL; varname = (type *)(varname->next)) + +#define FOREACH_NODE_MULTI_ITER(type, first, varname, ...) for (type *varname = (type *)(first); varname != NULL; varname = (type *)(varname->next), __VA_ARGS__) +#define FOREACH_NODE_NODECL_MULTI_ITER(type, first, varname, ...) for (varname = (type *)(first); varname != NULL; varname = (type *)(varname->next), __VA_ARGS__) + +#define SET_OR_CLEAR_CHILD_FLAGS(flags, old_flags, flag_bit) \ + if (flags != old_flags) { \ + TMainTask *child; \ + u32 bit = 1; \ + FOREACH_NODE_NODECL_MULTI_ITER(TMainTask, main_task.down, child, bit <<= 1) { \ + if (main_task_flags & bit) { \ + child->set_flag_##flag_bit(); \ + } else { \ + child->clear_flag_##flag_bit(); \ + } \ + } \ + old_flags = flags; \ + } + + +// Class forward. +class TObject; +class TMainTask; + +// Extern defs. +#define o(name) extern const char *name##_name; +OBJECT_NAMES +#undef o + +extern TMainTask main_task; +extern TObject global_obj1; +extern TObject global_obj2; + + +// Class defs. +class TMainTask : public TObject { +public: + u32 task_flags; + u32 mbr_0x20; + u32 mbr_0x24; +public: + TMainTask(); + virtual ~TMainTask(); + virtual void run_task(); +private: + void set_task_flags(u32 flags) { + this->task_flags |= flags; + } + + void clear_task_flags(u32 flags) { + this->task_flags &= ~flags; + } + + u32 get_task_flags(u32 flags) { + return this->task_flags & flags; + }; +}; + +class TObject { +public: + const char *name; + u16 flags; + u16 id; + TObject *prev; + TObject *next; + TObject *up; + TObject *down; +public: + void set_flag_3(); + void clear_flag_3(); + void set_flag_0(); + void set_flag_9(); + u32 get_flag_9(); + void clear_flag_9(); + + TObject(TObject *parent = NULL); + virtual ~TObject(); + + void *operator new (unsigned long size) { return alloc(size); }; + void operator delete(void *ptr) { free(ptr); }; + + void delete_children(); + void set_flag_0_for_each_node(); + void run_tasks(); + void call_func_0x10_for_each_node(); + void call_func_0x14_for_each_node(); + void call_func_0x10_for_each_node2(); + void empty_func(); + void set_parent(TObject *parent); + + virtual void run_task(); + virtual void func_0x10(); + virtual void func_0x14(); + + void empty_func2(); + void log(const char *str); + int get_node_count(); + bool is_flag_0_clear_for_all_parents(); + static void *alloc(unsigned long size); + static void free(void *ptr); + bool toggle_flag_9_if_flag_10_is_clear(); + +private: + void _delete_children() { + while (this->down != NULL) { + delete this->down; + } + }; + void add_parent(TObject *parent, bool set_parent) { + if (set_parent) { + up = parent; + } + TObject *child; + if (parent == NULL) { + this->prev = this; + this->next = NULL; + return; + } + child = parent->down; + if (child != NULL) { + this->prev = child->next; + this->next = NULL; + child->prev->next = this; + child->prev = this; + } else { + this->prev = this; + parent->down = this; + this->next = NULL; + } + }; + void remove_parent() { + if (this->up != NULL) { + if (this->prev == this) { + this->up->down = NULL; + } else if (this->up->down == this) { + this->up->down = this->prev; + this->prev->next = NULL; + if (this->next != NULL) { + this->next->prev = this->next; + } + } else { + this->prev->next = this->next; + if (this->next != NULL) { + this->next->prev = this->prev; + } else { + this->up->down->prev = this->prev; + } + } + } + }; + + void set_flags(u16 flags) { + this->flags |= flags; + } + + void clear_flags(u16 flags) { + this->flags &= ~flags; + } + + u32 get_flags(u16 flags) { + return this->flags & flags; + }; +}; -- cgit v1.2.3-13-gbd6f