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. --- include/pso/TMenuList.h | 130 +++++++++++++++++++++++++++++++++++++++++ include/pso/TPlyGuildCardTag.h | 17 ++++++ include/pso/forward.h | 6 ++ include/pso/macros.h | 2 + include/pso/protocol.h | 17 ++++++ 5 files changed, 172 insertions(+) create mode 100644 include/pso/TMenuList.h create mode 100644 include/pso/TPlyGuildCardTag.h create mode 100644 include/pso/protocol.h (limited to 'include/pso') 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 + +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; +} +#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 + +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 +class TMenuList; +template +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 + +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 -- cgit v1.2.3-13-gbd6f