summaryrefslogtreecommitdiff
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
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.
-rw-r--r--context.h166
-rw-r--r--include/pso/TMenuList.h130
-rw-r--r--include/pso/TPlyGuildCardTag.h17
-rw-r--r--include/pso/forward.h6
-rw-r--r--include/pso/macros.h2
-rw-r--r--include/pso/protocol.h17
-rw-r--r--obj_files.mk2
-rw-r--r--src/pso/TPlyGuildCardTag.cpp16
-rw-r--r--src/pso/protocol.cpp9
9 files changed, 364 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;
diff --git a/include/pso/TMenuList.h b/include/pso/TMenuList.h
new file mode 100644
index 0000000..f792462
--- /dev/null
+++ b/include/pso/TMenuList.h
@@ -0,0 +1,130 @@
+#ifndef TMENULIST_H
+#define TMENULIST_H
+
+#include "pso/forward.h"
+#include "pso/protocol.h"
+#include "pso/macros.h"
+#include "pso/TPlyGuildCardTag.h"
+#include <global_types.h>
+
+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;
+}
+#endif
diff --git a/include/pso/TPlyGuildCardTag.h b/include/pso/TPlyGuildCardTag.h
new file mode 100644
index 0000000..3e193a0
--- /dev/null
+++ b/include/pso/TPlyGuildCardTag.h
@@ -0,0 +1,17 @@
+#ifndef TPLYGUILDCARDTAG_H
+#define TPLYGUILDCARDTAG_H
+
+#include "pso/forward.h"
+#include "pso/macros.h"
+#include <global_types.h>
+
+class TPlyGuildCardTag {
+ public:
+ u8 tag0;
+ u8 tag1;
+ u16 tag2;
+ u32 guildcard_number;
+ TPlyGuildCardTag &operator=(const TPlyGuildCardTag &src);
+ void bswap();
+} __packed__;
+#endif
diff --git a/include/pso/forward.h b/include/pso/forward.h
index 6c97f81..ec4d77a 100644
--- a/include/pso/forward.h
+++ b/include/pso/forward.h
@@ -1,8 +1,14 @@
#ifndef FORWARD_H
#define FORWARD_H
+/*template <typename T, int num_entries, int num_pad_entries>
+class TMenuList;
+template <typename T>
+class TMenuListEntry;*/
class THeap;
class TObject;
class TMainTask;
+class TPlyGuildCardTag;
+struct packet_header;
#endif
diff --git a/include/pso/macros.h b/include/pso/macros.h
index 8d76186..1434e16 100644
--- a/include/pso/macros.h
+++ b/include/pso/macros.h
@@ -55,4 +55,6 @@
#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__
+
#endif
diff --git a/include/pso/protocol.h b/include/pso/protocol.h
new file mode 100644
index 0000000..697f6b0
--- /dev/null
+++ b/include/pso/protocol.h
@@ -0,0 +1,17 @@
+#ifndef PROTOCOL_H
+#define PROTOCOL_H
+
+#include "pso/forward.h"
+#include "pso/macros.h"
+#include <global_types.h>
+
+struct packet_header {
+ u8 command;
+ u8 flags;
+ u16 size;
+ void bswap();
+} __packed__;
+
+extern void bswap_16(u16 *val);
+extern void bswap_32(u32 *val);
+#endif
diff --git a/obj_files.mk b/obj_files.mk
index 8632b6c..d76a0e5 100644
--- a/obj_files.mk
+++ b/obj_files.mk
@@ -1,5 +1,7 @@
O_FILES := $(BUILD_DIR)/src/main.o \
+ $(BUILD_DIR)/src/pso/TPlyGuildCardTag.o \
$(BUILD_DIR)/src/pso/THeap.o \
+ $(BUILD_DIR)/src/pso/protocol.o \
$(BUILD_DIR)/src/pso/TMainTask.o \
$(BUILD_DIR)/src/pso/TObject.o \
$(BUILD_DIR)/src/pso/TObject2.o \
diff --git a/src/pso/TPlyGuildCardTag.cpp b/src/pso/TPlyGuildCardTag.cpp
new file mode 100644
index 0000000..079fcbc
--- /dev/null
+++ b/src/pso/TPlyGuildCardTag.cpp
@@ -0,0 +1,16 @@
+#include "pso/TPlyGuildCardTag.h"
+#include "pso/protocol.h"
+#include <global_types.h>
+
+void TPlyGuildCardTag::bswap() {
+ bswap_32(&guildcard_number);
+ bswap_16(&tag2);
+}
+
+TPlyGuildCardTag &TPlyGuildCardTag::operator=(const TPlyGuildCardTag &src) {
+ tag0 = src.tag0;
+ tag1 = src.tag1;
+ tag2 = src.tag2;
+ guildcard_number = src.guildcard_number;
+ return *this;
+}
diff --git a/src/pso/protocol.cpp b/src/pso/protocol.cpp
new file mode 100644
index 0000000..280b105
--- /dev/null
+++ b/src/pso/protocol.cpp
@@ -0,0 +1,9 @@
+#include "pso/protocol.h"
+#include <global_types.h>
+
+void bswap_32(u32 *val) {}
+void bswap_16(u16 *val) {}
+
+void packet_header::bswap() {
+ bswap_16(&size);
+}