diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2023-02-25 12:25:33 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2023-02-25 12:25:33 -0400 |
commit | 25e3c303b8f47785a0056077a66b7a77449ff827 (patch) | |
tree | f19aedf782acf4c78c238e26f735e6f7b89163a9 /include | |
parent | e4af5aabc6b9b70b514e8c124dd766aa44dcab7a (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 'include')
-rw-r--r-- | include/pso/TMenuList.h | 130 | ||||
-rw-r--r-- | include/pso/TPlyGuildCardTag.h | 17 | ||||
-rw-r--r-- | include/pso/forward.h | 6 | ||||
-rw-r--r-- | include/pso/macros.h | 2 | ||||
-rw-r--r-- | include/pso/protocol.h | 17 |
5 files changed, 172 insertions, 0 deletions
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 |