From 25e3c303b8f47785a0056077a66b7a77449ff827 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 25 Feb 2023 12:25:33 -0400 Subject: TMenuList: Add `TMenuList`, and everything else that's needed to get it working I feel this is a good starting point for working on the protocol related code. --- context.h | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) (limited to 'context.h') diff --git a/context.h b/context.h index e09f701..def7359 100644 --- a/context.h +++ b/context.h @@ -30,6 +30,7 @@ typedef long ptrdiff_t; #endif #define ATTRIBUTE_ALIGN(num) __attribute__((aligned(num))) +// pso/macros.h #define OBJECT_NAME(name) const char *name##_name = #name; #define OBJECT_NAMES \ o(TObject) \ @@ -84,6 +85,9 @@ typedef long ptrdiff_t; #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 __packed__ + +// pso/TMainTask.h #define X_OR_Y_CHILD(flags, old_flags, one_prefix, zero_prefix, suffix) \ if (flags != old_flags) { \ TMainTask *child; \ @@ -104,20 +108,148 @@ typedef long ptrdiff_t; #define DISALLOW_OR_ALLOW_CHILD(flags, old_flags, flag_name) \ X_OR_Y_CHILD(flags, old_flags, allow, disallow, flag_name) - +// pso/forward.h // Class forward. class THeap; class TObject; class TMainTask; +class TPlyGuildCardTag; +struct packet_header; + +// pso/TMenuList.h +// Template defs. +template +class TMenuListEntry : public TPlyGuildCardTag { + public: + T entry; + + void bswap(); + TMenuListEntry &operator=(const TMenuListEntry &src); +} __packed__; + +template +class TMenuList { + public: + packet_header header; + TMenuListEntry pad_entries[num_pad_entries]; + TMenuListEntry entries[num_entries]; + + void bswap(); + TMenuList &operator=(const TMenuList &src); + +} __packed__; + +template +class TMenuList { + public: + packet_header header; + TMenuListEntry entries[num_entries]; + + void bswap(); + TMenuList &operator=(const TMenuList &src); +} __packed__; + +template +class TMenuList { + public: + packet_header header; + TMenuListEntry pad_entries[num_pad_entries]; + + void bswap(); + TMenuList &operator=(const TMenuList &src); +} __packed__; + + +template +void TMenuList::bswap() { + header.bswap(); + for (int i = 0; i < num_entries; i++) { + entries[i].bswap(); + } +} + +template +void TMenuList::bswap() { + header.bswap(); + for (int i = 0; i < num_pad_entries; i++) { + pad_entries[i].bswap(); + } +} + +template +void TMenuList::bswap() { + header.bswap(); + if (num_pad_entries) { + for (int i = 0; i < num_pad_entries; i++) { + pad_entries[i].bswap(); + } + } + if (num_entries) { + for (int i = 0; i < num_entries; i++) { + entries[i].bswap(); + } + } +} + +template +void TMenuListEntry::bswap() { + TPlyGuildCardTag::bswap(); + entry.bswap(); +} + +template +TMenuList &TMenuList::operator=(const TMenuList &src) { + header = src.header; + for (int i = 0; i < num_entries; i++) { + entries[i] = src.entries[i]; + } + return *this; +} + +template +TMenuList &TMenuList::operator=(const TMenuList &src) { + header = src.header; + for (int i = 0; i < num_pad_entries; i++) { + pad_entries[i] = src.pad_entries[i]; + } + return *this; +} + +template +TMenuList &TMenuList::operator=(const TMenuList &src) { + header = src.header; + if (num_pad_entries) { + for (int i = 0; i < num_pad_entries; i++) { + pad_entries[i] = src.pad_entries[i]; + } + } + if (num_entries) { + for (int i = 0; i < num_entries; i++) { + entries[i] = src.entries[i]; + } + } + return *this; +} + +template +TMenuListEntry &TMenuListEntry::operator=(const TMenuListEntry &src) { + TPlyGuildCardTag::operator=(src); + entry = src.entry; + return *this; +} + +// TMainTask.cpp // Const defs. static const int tl_object_count = 20; +// TObject.cpp // Extern defs. #define o(name) extern const char *name##_name; OBJECT_NAMES #undef o +// TMainTask.cpp #define o(var, name) extern const char *var##_name; TL_OBJECTS #undef o @@ -126,12 +258,15 @@ TL_OBJECTS TL_OBJECTS #undef o +// THeap.cpp extern THeap *obj_heap; extern THeap *alt_heap; +// TObject.cpp extern TMainTask main_task; extern TObject global_obj1; extern TObject global_obj2; +// TMainTask.cpp // Variable defs. u32 some_main_task_flag = 1; u32 update_flags; @@ -142,10 +277,12 @@ u32 render_shadow_flags; u32 old_render_shadow_flags; u32 some_id_805c6f74; +// THeap.cpp // func defs. extern void heap_xfree(void *ptr); extern void *heap_xmalloc(size_t size); +// TMainTask.cpp extern void camera_stuff(); extern void set_depth_buffer_settings_1(); @@ -163,6 +300,19 @@ extern void func_803e11f0(); extern void func_803369b4(); +// pso/protocol.h +extern void bswap_16(u16 *val); +extern void bswap_32(u32 *val); + +// Struct defs. +struct packet_header { + u8 command; + u8 flags; + u16 size; + void bswap(); +} __packed__; + +// pso/TObject.h // Enum defs. enum object_flags { NONE = 0, @@ -193,7 +343,19 @@ static inline void operator^=(object_flags &a, object_flags b) { a = a ^ b; }; static inline void operator&=(object_flags &a, object_flags b) { a = a & b; }; static inline void operator|=(object_flags &a, object_flags b) { a = a | b; }; +// pso/TPlyGuildCardTag.h // Class defs. +class TPlyGuildCardTag { + public: + u8 tag0; + u8 tag1; + u16 tag2; + u32 guildcard_number; + TPlyGuildCardTag &operator=(const TPlyGuildCardTag &src); + void bswap(); +} __packed__; + +// pso/THeap.h class THeap { public: struct heap_node { @@ -215,6 +377,7 @@ public: void heap_free(void *ptr); }; +// pso/TObject.h class TObject { private: void _delete_children() { @@ -351,6 +514,7 @@ public: bool toggle_flag_9_if_flag_10_is_clear(); }; +// pso/TMainTask.h class TMainTask : public TObject { public: u32 task_flags; -- cgit v1.2.3-13-gbd6f