From 115fe1992e2c50fd108f7bc7cc31d7d2b1f5c6b8 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sun, 26 Feb 2023 19:20:47 -0400 Subject: 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. --- src/pso/TSocket.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/pso/TSocket.cpp (limited to 'src/pso/TSocket.cpp') diff --git a/src/pso/TSocket.cpp b/src/pso/TSocket.cpp new file mode 100644 index 0000000..f9e954d --- /dev/null +++ b/src/pso/TSocket.cpp @@ -0,0 +1,59 @@ +#include +#include +#include "pso/macros.h" +#include "pso/TArray.h" +#include "pso/TObject.h" +#include "pso/TSocket.h" + +u16 bswap_word(u16 val); + +int TSocket::is_empty() { + if (all_parents_unqueued_for_destruction()) { + return !m_size; + } else { + return true; + } +} + +const u8 TSocket::next() { + const u8 val = m_packet_buffer[m_buffer_offset++]; + if (m_buffer_offset >= m_size) { + m_buffer_offset = 0; + m_size = 0; + } + return val; +} + +void TSocket::set_port(u32 port) { + m_dst_port = bswap_word(port); +} + +void TSocket::set_ip_address(u32 addr) { + m_dst_addr.addr_bytes.fast_copy_reverse(addr); +} + +int TSocket::resolve_domain(char *domain) { + /* TODO: Implement, and match this. */ + return 0; +} + +TSocket::TSocket(TObject *parent) : TObject(parent) { + m_dst_addr.addr_bytes.fast_fill_with(0); + m_dst_port = 0; + m_src_port = 0; + m_sock_fd = -1; + m_sock_flags = 0; + m_size = 0; + m_buffer_offset = 0; + m_buffer_cleared = true; + m_callback = nullptr; +} + +u16 bswap_word(u16 val) { + u8 *ptr = reinterpret_cast(&val); + return ptr[1] + (ptr[0] << 8); +} + +TSocket::~TSocket() { + +} -- cgit v1.2.3-13-gbd6f