summaryrefslogtreecommitdiff
path: root/context.h
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-02-25 12:25:33 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-02-25 12:25:33 -0400
commit25e3c303b8f47785a0056077a66b7a77449ff827 (patch)
treef19aedf782acf4c78c238e26f735e6f7b89163a9 /context.h
parente4af5aabc6b9b70b514e8c124dd766aa44dcab7a (diff)
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.
Diffstat (limited to 'context.h')
-rw-r--r--context.h166
1 files changed, 165 insertions, 1 deletions
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 <typename T>
+class TMenuListEntry : public TPlyGuildCardTag {
+ public:
+ T entry;
+
+ void bswap();
+ TMenuListEntry &operator=(const TMenuListEntry &src);
+} __packed__;
+
+template <typename T, int num_entries, int num_pad_entries>
+class TMenuList {
+ public:
+ packet_header header;
+ TMenuListEntry<T> pad_entries[num_pad_entries];
+ TMenuListEntry<T> entries[num_entries];
+
+ void bswap();
+ TMenuList &operator=(const TMenuList &src);
+
+} __packed__;
+
+template <typename T, int num_entries>
+class TMenuList<T, num_entries, 0> {
+ public:
+ packet_header header;
+ TMenuListEntry<T> entries[num_entries];
+
+ void bswap();
+ TMenuList &operator=(const TMenuList &src);
+} __packed__;
+
+template <typename T, int num_pad_entries>
+class TMenuList<T, 0, num_pad_entries> {
+ public:
+ packet_header header;
+ TMenuListEntry<T> pad_entries[num_pad_entries];
+
+ void bswap();
+ TMenuList &operator=(const TMenuList &src);
+} __packed__;
+
+
+template <typename T, int num_entries>
+void TMenuList<T, num_entries, 0>::bswap() {
+ header.bswap();
+ for (int i = 0; i < num_entries; i++) {
+ entries[i].bswap();
+ }
+}
+
+template <typename T, int num_pad_entries>
+void TMenuList<T, 0, num_pad_entries>::bswap() {
+ header.bswap();
+ for (int i = 0; i < num_pad_entries; i++) {
+ pad_entries[i].bswap();
+ }
+}
+
+template <typename T, int num_entries, int num_pad_entries>
+void TMenuList<T, num_entries, num_pad_entries>::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 <typename T>
+void TMenuListEntry<T>::bswap() {
+ TPlyGuildCardTag::bswap();
+ entry.bswap();
+}
+
+template <typename T, int num_entries>
+TMenuList<T, num_entries, 0> &TMenuList<T, num_entries, 0>::operator=(const TMenuList<T, num_entries, 0> &src) {
+ header = src.header;
+ for (int i = 0; i < num_entries; i++) {
+ entries[i] = src.entries[i];
+ }
+ return *this;
+}
+
+template <typename T, int num_pad_entries>
+TMenuList<T, 0, num_pad_entries> &TMenuList<T, 0, num_pad_entries>::operator=(const TMenuList<T, 0, num_pad_entries> &src) {
+ header = src.header;
+ for (int i = 0; i < num_pad_entries; i++) {
+ pad_entries[i] = src.pad_entries[i];
+ }
+ return *this;
+}
+
+template <typename T, int num_entries, int num_pad_entries>
+TMenuList<T, num_entries, num_pad_entries> &TMenuList<T, num_entries, num_pad_entries>::operator=(const TMenuList<T, num_entries, num_pad_entries> &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 <typename T>
+TMenuListEntry<T> &TMenuListEntry<T>::operator=(const TMenuListEntry<T> &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;