summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-02-26 19:20:47 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-02-26 19:20:47 -0400
commit115fe1992e2c50fd108f7bc7cc31d7d2b1f5c6b8 (patch)
tree677098b566ba5beaac4b486943d6b8664d695315 /include
parent91a5937ef11f0503dde9d6f62e9d1f21e6f8a78f (diff)
TSocket: Start work on, and match most of `TSocket`
Still need to implement, and match `resolve_domain()`, but it's a good starting point for decompiling the netcode.
Diffstat (limited to 'include')
-rw-r--r--include/pso/TSocket.h86
-rw-r--r--include/pso/forward.h5
2 files changed, 87 insertions, 4 deletions
diff --git a/include/pso/TSocket.h b/include/pso/TSocket.h
new file mode 100644
index 0000000..1b571d9
--- /dev/null
+++ b/include/pso/TSocket.h
@@ -0,0 +1,86 @@
+#ifndef TSOCKET_H
+#define TSOCKET_H
+
+#include <global_types.h>
+#include <string.h>
+#include <pso/macros.h>
+#include <pso/forward.h>
+#include <pso/TArray.h>
+#include <pso/TObject.h>
+
+union ipv4_addr {
+ u32 addr;
+ TArray<u8, 4> addr_bytes;
+};
+
+class TSocket : public TObject {
+private:
+ void set_flags(u8 flags) {
+ m_sock_flags |= flags;
+ };
+
+ void clear_flags(u8 flags) {
+ m_sock_flags &= ~flags;
+ };
+
+ void toggle_flags(u8 flags) {
+ m_sock_flags ^= flags;
+ };
+
+ u8 get_flags(u8 flags) {
+ return m_sock_flags & flags;
+ };
+
+ ipv4_addr m_dst_addr;
+ u16 m_dst_port;
+ u16 m_src_port;
+ ipv4_addr m_src_addr;
+ s16 m_sock_fd;
+ u8 m_sock_flags;
+ bool m_buffer_cleared;
+ s16 m_size;
+ s16 m_buffer_offset;
+ u32 m_unused;
+ TArray<u8, 64> m_unused2;
+ TArray<u8, 2048> m_packet_buffer;
+ s16 m_stat;
+ u16 m_unused3;
+ u32 m_send_window;
+ u32 m_recv_window;
+ void (*m_callback)(TSocket *socket);
+public:
+ TSocket(TObject *parent);
+ virtual ~TSocket();
+
+ virtual int open() = 0;
+ virtual int close() = 0;
+ virtual void recv() = 0;
+ virtual int send(u8 *data) = 0;
+ virtual int send(u8 *data, size_t size) = 0;
+
+ int resolve_domain(char *domain);
+ void set_ip_address(u32 addr);
+ void set_port(u32 port);
+ const u8 next();
+ int is_empty();
+
+ PRIVATE_MEMBER_ACCESSORS(ipv4_addr, dst_addr);
+ PRIVATE_MEMBER_ACCESSORS(u16, dst_port);
+ PRIVATE_MEMBER_ACCESSORS(u16, src_port);
+ PRIVATE_MEMBER_ACCESSORS(ipv4_addr, src_addr);
+ PRIVATE_MEMBER_ACCESSORS(s16, sock_fd);
+ PRIVATE_MEMBER_ACCESSORS(u8, sock_flags);
+ PRIVATE_MEMBER_ACCESSORS(bool, buffer_cleared);
+ PRIVATE_MEMBER_ACCESSORS(s16, size);
+ PRIVATE_MEMBER_ACCESSORS(s16, buffer_offset);
+ PRIVATE_MEMBER_ACCESSORS(u32, unused);
+ PRIVATE_MEMBER_ACCESSORS_ARRAY(u8, unused2, 64);
+ PRIVATE_MEMBER_ACCESSORS_ARRAY(u8, packet_buffer, 2048);
+ PRIVATE_MEMBER_ACCESSORS(s16, stat);
+ PRIVATE_MEMBER_ACCESSORS(u16, unused3);
+ PRIVATE_MEMBER_ACCESSORS(u32, send_window);
+ PRIVATE_MEMBER_ACCESSORS(u32, recv_window);
+ PRIVATE_MEMBER_ACCESSORS_FUNC(void, callback, TSocket *socket);
+};
+
+#endif
diff --git a/include/pso/forward.h b/include/pso/forward.h
index ec4d77a..165b9ad 100644
--- a/include/pso/forward.h
+++ b/include/pso/forward.h
@@ -1,10 +1,7 @@
#ifndef FORWARD_H
#define FORWARD_H
-/*template <typename T, int num_entries, int num_pad_entries>
-class TMenuList;
-template <typename T>
-class TMenuListEntry;*/
+class TSocket;
class THeap;
class TObject;
class TMainTask;