diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2023-03-07 15:23:51 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2023-03-07 15:23:51 -0400 |
commit | 09c901655db3bb42d2aac4b506846b18833d777c (patch) | |
tree | c980f1c6b42ee503a699200a55b4cabfded1ffd5 /src/pso | |
parent | 5df9bdde16d30a8bfe520e178c5810a7163e9d6c (diff) |
global: Completly disable inlining
This is because it looks more, and more clear that the entire codebase
was compiled without inlining. Likely to reduce code size from all the
byteswap functions, only present on the GameCube version.
Diffstat (limited to 'src/pso')
-rw-r--r-- | src/pso/PSOV3Encryption.cpp | 21 | ||||
-rw-r--r-- | src/pso/TMainTask.cpp | 40 | ||||
-rw-r--r-- | src/pso/TObject.cpp | 32 | ||||
-rw-r--r-- | src/pso/TObject2.cpp | 45 | ||||
-rw-r--r-- | src/pso/TPlyGuildCardTag.cpp | 30 | ||||
-rw-r--r-- | src/pso/TProtocol.cpp | 106 | ||||
-rw-r--r-- | src/pso/TSocket.cpp | 11 | ||||
-rw-r--r-- | src/pso/TTcpSocket.cpp | 128 | ||||
-rw-r--r-- | src/pso/protocol.cpp | 4 |
9 files changed, 173 insertions, 244 deletions
diff --git a/src/pso/PSOV3Encryption.cpp b/src/pso/PSOV3Encryption.cpp index 38225bf..867c864 100644 --- a/src/pso/PSOV3Encryption.cpp +++ b/src/pso/PSOV3Encryption.cpp @@ -16,9 +16,9 @@ void PSOV3Encryption::update_stream() { u32 *part1; u32 *part2; - part2 = m_buffer.start(); - m_buffer_start = m_buffer.start(); - ptr = m_buffer.start(); + part2 = m_buffer; + m_buffer_start = m_buffer; + ptr = m_buffer; part1 = &ptr[489]; for (; part1 != m_buffer_end; *ptr++ ^= *part1++); @@ -27,10 +27,9 @@ void PSOV3Encryption::update_stream() { } void PSOV3Encryption::init(u32 seed) { - const size_t size = m_buffer.size(); - u32 thing; - m_buffer_end = &m_buffer[size]; - m_buffer_start = m_buffer.start(); + const size_t size = (sizeof(m_buffer)/sizeof(*m_buffer))-1; + m_buffer_end = &m_buffer[size+1]; + m_buffer_start = m_buffer; u32 value = 0; for (int i = 0; i <= 16; ++i, *m_buffer_start++ = value) { @@ -41,8 +40,8 @@ void PSOV3Encryption::init(u32 seed) { } --m_buffer_start; - thing = m_buffer[0xf]; - *m_buffer_start = (m_buffer[0] >> 9) ^ (*m_buffer_start << 23) ^ thing; + + *m_buffer_start = (*m_buffer_start << 23) ^ (m_buffer[0] >> 9) ^ m_buffer[0xf]; for (u32 *buf_val = &m_buffer[0], *next_buf_val = &m_buffer[1], *buf = m_buffer_start++; m_buffer_start != m_buffer_end;) { *m_buffer_start++ = (*buf_val++ << 23) ^ (*next_buf_val++ >> 9) ^ *buf++; @@ -51,11 +50,11 @@ void PSOV3Encryption::init(u32 seed) { update_stream(); update_stream(); update_stream(); - m_buffer_start = m_buffer.end(); + m_buffer_start = &m_buffer[size-1]; } PSOV3Encryption::~PSOV3Encryption() { - m_buffer.fill(0); + memset(m_buffer, 0, sizeof(m_buffer)); m_buffer_start = nullptr; m_buffer_end = nullptr; } diff --git a/src/pso/TMainTask.cpp b/src/pso/TMainTask.cpp index 0458c3e..f02b179 100644 --- a/src/pso/TMainTask.cpp +++ b/src/pso/TMainTask.cpp @@ -39,13 +39,13 @@ void func_803e11f0() {} void func_803369b4() {} void TMainTask::render_screen_overlay() { - if (!get_task_flags(0x100)) { + if (!(task_flags & 0x100)) { render_clipout_and_fade(); empty_func(); empty_render_screen_overlay_func(); func_803369b4(); } - clear_task_flags(0x180); + task_flags &= ~0x180; } void TMainTask::some_empty_func() {} @@ -83,14 +83,14 @@ void TMainTask::tl_02_clear_flag_3() { void TMainTask::empty_render_screen_overlay_func() {} void TMainTask::run_tl_camera_tasks() { - set_task_flags(1); + task_flags |= 1; tl_camera->run_tasks(); - clear_task_flags(1); + task_flags &= ~1; } void TMainTask::render() { DISALLOW_OR_ALLOW_CHILD(render_flags, old_render_flags, rendering); - set_task_flags(2); + task_flags |= 2; some_main_task_flag = 0; render_geometry(); some_main_task_flag = 1; @@ -102,8 +102,8 @@ void TMainTask::render() { some_main_task_flag = 0; unused_render_func(); render_ui(); - clear_task_flags(2); - set_task_flags(0x100); + task_flags &= ~2; + task_flags |= 0x100; } void TMainTask::unused_render_func() { @@ -111,7 +111,7 @@ void TMainTask::unused_render_func() { } void TMainTask::render_objects() { - set_task_flags(0x200); + task_flags |= 0x200; tl_03->render_nodes2(); tl_04->render_nodes2(); @@ -125,7 +125,7 @@ void TMainTask::render_objects() { func_80141618(); func_803e11f0(); - clear_task_flags(0x200); + task_flags &= ~0x200; set_depth_buffer_settings_id(2); func_803e11e8(2); @@ -217,7 +217,7 @@ void TMainTask::render_geometry() { } void TMainTask::func_80228bbc() { - set_task_flags(0x40); + task_flags |= 0x40; some_main_task_flag = 0; set_depth_buffer_settings_3(); set_depth_buffer_settings_id(1); @@ -235,11 +235,11 @@ void TMainTask::func_80228bbc() { tl_02->render_nodes(); restore_depth_buffer_settings(); - clear_task_flags(0x40); + task_flags &= ~0x40; } void TMainTask::func_80228c44(s32 arg0) { - set_task_flags(0x20); + task_flags |= 0x20; some_main_task_flag = 0; set_depth_buffer_settings_3(); set_depth_buffer_settings_id(1); @@ -300,11 +300,11 @@ void TMainTask::func_80228c44(s32 arg0) { save_depth_buffer_settings(); restore_depth_buffer_settings(); - clear_task_flags(0x20); + task_flags &= ~0x20; } void TMainTask::func_80228dbc() { - set_task_flags(0x10); + task_flags |= 0x10; some_main_task_flag = 0; render_geometry(); some_main_task_flag = 1; @@ -313,12 +313,12 @@ void TMainTask::func_80228dbc() { some_main_task_flag = 0; render_particle_effects(); unused_render_func(); - clear_task_flags(0x10); + task_flags &= ~0x10; } void TMainTask::render_clipout_and_fade() { u32 some_id; - set_task_flags(2); + task_flags |= 2; set_depth_buffer_settings_2(); set_depth_buffer_settings_id(1); @@ -336,16 +336,16 @@ void TMainTask::render_clipout_and_fade() { set_some_id(some_id); restore_depth_buffer_settings(); - clear_task_flags(2); + task_flags &= ~2; }; void TMainTask::run_task() { SET_OR_CLEAR_CHILD_FLAGS(update_flags, old_update_flags, 3); some_main_task_flag = 0; - set_task_flags(1); + task_flags |= 1; run_tasks(); - clear_task_flags(1); - set_task_flags(0x80); + task_flags &= ~1; + task_flags |= 0x80; } void TMainTask::render_shadows() { diff --git a/src/pso/TObject.cpp b/src/pso/TObject.cpp index ed56035..c832ebe 100644 --- a/src/pso/TObject.cpp +++ b/src/pso/TObject.cpp @@ -1,7 +1,8 @@ +#define TOBJECT_CPP + #include "pso/THeap.h" #include "pso/TMainTask.h" #include "pso/TObject.h" -#define MATCHING TMainTask main_task; TObject global_obj1; @@ -20,7 +21,7 @@ void debug_print(const char *fmt) { } bool TObject::toggle_flag_9_if_flag_10_is_clear() { - if (get_flags(BIT_10)) { + if (m_flags & BIT_10) { return false; } if (!get_flag_9()) { @@ -40,10 +41,9 @@ void *TObject::operator new(size_t size) { return obj_heap->heap_alloc(size); } - int TObject::all_parents_unqueued_for_destruction() { for (TObject *parent = this; parent != NULL; parent = parent->m_up) { - if (parent->get_flags(QUEUE_DESTRUCTION)) { + if (parent->m_flags & QUEUE_DESTRUCTION) { return false; } } @@ -91,7 +91,7 @@ void TObject::empty_func() { void TObject::render_nodes2() { FOREACH_NODE(TObject, this->m_down, child) { - if (child->get_flags(BIT_9)) { + if (child->m_flags & BIT_9) { child->render(); child->clear_flag_9(); } @@ -101,7 +101,7 @@ void TObject::render_nodes2() { void TObject::render_shadows_for_each_node() { FOREACH_NODE(TObject, this->m_down, child) { - if (!child->get_flags(DISALLOW_RENDER_SHADOWS)) { + if (!(child->m_flags & DISALLOW_RENDER_SHADOWS)) { child->render_shadows(); child->render_shadows_for_each_node(); } @@ -110,7 +110,7 @@ void TObject::render_shadows_for_each_node() { void TObject::render_nodes() { FOREACH_NODE(TObject, this->m_down, child) { - if (!child->get_flags(DISALLOW_RENDER)) { + if (!(child->m_flags & DISALLOW_RENDER)) { child->render(); child->render_nodes(); } @@ -123,22 +123,22 @@ void TObject::run_tasks() { while (this->m_down != NULL && child != NULL) { TObject *node = child; child = child->m_next; - if (node->get_flags(DISALLOW_UPDATE)) { + if (node->m_flags & DISALLOW_UPDATE) { // Clearing flag 0 in the if statement is required to match. - if (node->get_flags(QUEUE_DESTRUCTION) && (node->clear_flags(QUEUE_DESTRUCTION), !node->get_flags(DISALLOW_DESTRUCTION))) { + if (node->m_flags & QUEUE_DESTRUCTION && (node->m_flags &= ~QUEUE_DESTRUCTION, !(node->m_flags & DISALLOW_DESTRUCTION))) { delete node; } else { - if (node->get_flags(CHILD_QUEUE_DESTRUCTION)) { + if (node->m_flags & CHILD_QUEUE_DESTRUCTION) { node->delete_children(); node->run_task(); - node->clear_flags(CHILD_QUEUE_DESTRUCTION); + node->m_flags &= ~CHILD_QUEUE_DESTRUCTION; } - if (!node->get_flags(BIT_2)) { + if (!(node->m_flags & BIT_2)) { // Adding this here somehow causes the // dead code to be compiled. // `volatile` typecast is required to match. - (vu16)node->get_flags(QUEUE_DESTRUCTION); + (vu16)node->m_flags & QUEUE_DESTRUCTION; } } } else { @@ -160,8 +160,8 @@ void TObject::delete_children() { } TObject::~TObject() { - if (!get_flags(DISALLOW_DESTRUCTION)) { - set_flags(DISALLOW_DESTRUCTION); + if (!(m_flags & DISALLOW_DESTRUCTION)) { + m_flags |= DISALLOW_DESTRUCTION; _delete_children(); remove_parent(); } @@ -174,3 +174,5 @@ TObject::TObject(TObject *parent) { m_name = TObject_name; add_parent(parent, false); } + +#undef TOBJECT_CPP diff --git a/src/pso/TObject2.cpp b/src/pso/TObject2.cpp deleted file mode 100644 index f020bd3..0000000 --- a/src/pso/TObject2.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "pso/TObject.h" - -void TObject::allow_rendering_shadows() { - clear_flags(DISALLOW_RENDER_SHADOWS); -} - -void TObject::clear_flag_9() { - clear_flags(BIT_9); -} - -void TObject::set_flag_9() { - set_flags(BIT_9); -} - -u32 TObject::get_flag_9() { - return get_flags(BIT_9); -} - -void TObject::queue_destruction() { - set_flags(QUEUE_DESTRUCTION); -} - -void TObject::clear_flag_3() { - clear_flags(BIT_3); -} - -void TObject::set_flag_3() { - set_flags(BIT_3); -} - -void TObject::toggle_flag_3() { - toggle_flags(BIT_3); -} - -void TObject::allow_rendering() { - clear_flags(DISALLOW_RENDER); -} - -void TObject::disallow_rendering() { - set_flags(DISALLOW_RENDER); -} - -void TObject::disallow_rendering_shadows() { - set_flags(DISALLOW_RENDER_SHADOWS); -} diff --git a/src/pso/TPlyGuildCardTag.cpp b/src/pso/TPlyGuildCardTag.cpp deleted file mode 100644 index 021c644..0000000 --- a/src/pso/TPlyGuildCardTag.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "pso/TPlyGuildCardTag.h" -#include "pso/protocol.h" -#include <global_types.h> - -TPlyGuildCardTag::TPlyGuildCardTag() {} - -TPlyGuildCardTag::TPlyGuildCardTag(u16 tag2, u32 guildcard_number) { - m_tag.tag0 = 0; - m_tag.tag1 = 0; - m_tag.tag2 = tag2; - m_guildcard_number = guildcard_number; -} - -void TPlyGuildCardTag::bswap() { - bswap_32(&m_guildcard_number); - bswap_16(&m_tag.tag2); -} - -TPlyGuildCardTag &TPlyGuildCardTag::operator=(const TPlyGuildCardTag &src) { - _assign(src); - return *this; -} - -void TPlyGuildCardTag::assign(const TPlyGuildCardTag &src) { - _assign(src); -} - -void TPlyGuildCardTag::assign(const TPlyGuildCardTag *src) { - _assign(*src); -} diff --git a/src/pso/TProtocol.cpp b/src/pso/TProtocol.cpp index 0e243d0..dacb966 100644 --- a/src/pso/TProtocol.cpp +++ b/src/pso/TProtocol.cpp @@ -96,7 +96,7 @@ TProtocol::~TProtocol() { } #define fill_with(name, value) memset(&m_##name, value, sizeof(m_##name)) -#define copy(name) strncpy(m_##name.m_data, name, sizeof(m_##name.m_data)) +#define copy(name) strncpy(m_##name, name, sizeof(m_##name)) TProtocol::TProtocol(TObject *parent, u16 sub_version, int language, char *serial_number, char *access_key, char *password) : TTcpSocket(parent) { u8 thing[6]; @@ -105,15 +105,15 @@ TProtocol::TProtocol(TObject *parent, u16 sub_version, int language, char *seria { int i = 0; int j = 0; - m_smth.m_smth.m_data[i++] = 0; - m_smth.m_smth.m_data[i++] = 0; - m_smth.m_smth.m_data[i++] = thing[j++]; - m_smth.m_smth.m_data[i++] = thing[j++]; + m_smth.m_smth[i++] = 0; + m_smth.m_smth[i++] = 0; + m_smth.m_smth[i++] = thing[j++]; + m_smth.m_smth[i++] = thing[j++]; i = 0; - m_smth.m_smth1.m_data[i++] = thing[j++]; - m_smth.m_smth1.m_data[i++] = thing[j++]; - m_smth.m_smth1.m_data[i++] = thing[j++]; - m_smth.m_smth1.m_data[i++] = thing[j++]; + m_smth.m_smth1[i++] = thing[j++]; + m_smth.m_smth1[i++] = thing[j++]; + m_smth.m_smth1[i++] = thing[j++]; + m_smth.m_smth1[i++] = thing[j++]; } m_guildcard_tag = TPlyGuildCardTag(-1, -1); m_login_response_state = 0; @@ -124,7 +124,7 @@ TProtocol::TProtocol(TObject *parent, u16 sub_version, int language, char *seria m_entry_count = 0; m_unused = 0; m_lobby_list_count = 0; - m_unused5.m_data[0] = 0; + m_unused5[0] = 0; m_unused2 = 0; m_udp_disabled = 0; m_packet_offset = 0; @@ -142,49 +142,49 @@ TProtocol::TProtocol(TObject *parent, u16 sub_version, int language, char *seria fill_with(client_config, 0); - m_recv_handlers.m_data[0] = nullptr; - m_recv_handlers.m_data[1] = nullptr; - m_recv_handlers.m_data[2] = nullptr; - m_recv_handlers.m_data[3] = nullptr; - m_recv_handlers.m_data[4] = nullptr; - m_recv_handlers.m_data[6] = nullptr; - m_recv_handlers.m_data[7] = nullptr; - m_recv_handlers.m_data[8] = nullptr; - m_recv_handlers.m_data[10] = nullptr; - m_recv_handlers.m_data[11] = nullptr; - m_recv_handlers.m_data[12] = nullptr; - m_recv_handlers.m_data[13] = nullptr; - m_recv_handlers.m_data[14] = nullptr; - m_recv_handlers.m_data[36] = nullptr; - m_recv_handlers.m_data[15] = nullptr; - m_recv_handlers.m_data[16] = nullptr; - m_recv_handlers.m_data[17] = nullptr; - m_recv_handlers.m_data[18] = nullptr; - m_recv_handlers.m_data[19] = nullptr; - m_recv_handlers.m_data[20] = nullptr; - m_recv_handlers.m_data[22] = nullptr; - m_recv_handlers.m_data[23] = nullptr; - m_recv_handlers.m_data[25] = nullptr; - m_recv_handlers.m_data[26] = nullptr; - m_recv_handlers.m_data[33] = nullptr; - m_recv_handlers.m_data[34] = nullptr; - m_recv_handlers.m_data[35] = nullptr; - m_recv_handlers.m_data[36] = nullptr; - m_recv_handlers.m_data[37] = nullptr; - m_recv_handlers.m_data[38] = nullptr; - m_recv_handlers.m_data[41] = nullptr; - m_recv_handlers.m_data[28] = nullptr; - m_recv_handlers.m_data[43] = nullptr; - m_recv_handlers.m_data[42] = nullptr; - m_recv_handlers.m_data[44] = nullptr; - m_recv_handlers.m_data[45] = nullptr; - m_recv_handlers.m_data[46] = nullptr; - m_recv_handlers.m_data[49] = nullptr; - m_recv_handlers.m_data[50] = nullptr; - m_recv_handlers.m_data[51] = nullptr; - m_recv_handlers.m_data[32] = nullptr; - m_recv_handlers.m_data[47] = nullptr; - m_recv_handlers.m_data[48] = nullptr; + m_recv_handlers[0] = nullptr; + m_recv_handlers[1] = nullptr; + m_recv_handlers[2] = nullptr; + m_recv_handlers[3] = nullptr; + m_recv_handlers[4] = nullptr; + m_recv_handlers[6] = nullptr; + m_recv_handlers[7] = nullptr; + m_recv_handlers[8] = nullptr; + m_recv_handlers[10] = nullptr; + m_recv_handlers[11] = nullptr; + m_recv_handlers[12] = nullptr; + m_recv_handlers[13] = nullptr; + m_recv_handlers[14] = nullptr; + m_recv_handlers[36] = nullptr; + m_recv_handlers[15] = nullptr; + m_recv_handlers[16] = nullptr; + m_recv_handlers[17] = nullptr; + m_recv_handlers[18] = nullptr; + m_recv_handlers[19] = nullptr; + m_recv_handlers[20] = nullptr; + m_recv_handlers[22] = nullptr; + m_recv_handlers[23] = nullptr; + m_recv_handlers[25] = nullptr; + m_recv_handlers[26] = nullptr; + m_recv_handlers[33] = nullptr; + m_recv_handlers[34] = nullptr; + m_recv_handlers[35] = nullptr; + m_recv_handlers[36] = nullptr; + m_recv_handlers[37] = nullptr; + m_recv_handlers[38] = nullptr; + m_recv_handlers[41] = nullptr; + m_recv_handlers[28] = nullptr; + m_recv_handlers[43] = nullptr; + m_recv_handlers[42] = nullptr; + m_recv_handlers[44] = nullptr; + m_recv_handlers[45] = nullptr; + m_recv_handlers[46] = nullptr; + m_recv_handlers[49] = nullptr; + m_recv_handlers[50] = nullptr; + m_recv_handlers[51] = nullptr; + m_recv_handlers[32] = nullptr; + m_recv_handlers[47] = nullptr; + m_recv_handlers[48] = nullptr; } #undef fill_with diff --git a/src/pso/TSocket.cpp b/src/pso/TSocket.cpp index 3c5576f..d7d22a0 100644 --- a/src/pso/TSocket.cpp +++ b/src/pso/TSocket.cpp @@ -27,7 +27,11 @@ void TSocket::set_port(u32 port) { } void TSocket::set_ip_address(u32 addr) { - m_dst_addr.addr_bytes.fast_copy_reverse<u32>(addr); + u8 *ptr = reinterpret_cast<u8 *>(&addr); + m_dst_addr.addr_bytes[3] = ptr[0]; + m_dst_addr.addr_bytes[2] = ptr[1]; + m_dst_addr.addr_bytes[1] = ptr[2]; + m_dst_addr.addr_bytes[0] = ptr[3]; } int TSocket::resolve_domain(char *domain) { @@ -36,7 +40,10 @@ int TSocket::resolve_domain(char *domain) { } TSocket::TSocket(TObject *parent) : TObject(parent) { - m_dst_addr.addr_bytes.fast_fill_with<u8>(0); + m_dst_addr.addr_bytes[0] = 0; + m_dst_addr.addr_bytes[1] = 0; + m_dst_addr.addr_bytes[2] = 0; + m_dst_addr.addr_bytes[3] = 0; m_dst_port = 0; m_src_port = 0; m_sock_fd = -1; diff --git a/src/pso/TTcpSocket.cpp b/src/pso/TTcpSocket.cpp index 949f962..55bf360 100644 --- a/src/pso/TTcpSocket.cpp +++ b/src/pso/TTcpSocket.cpp @@ -66,10 +66,10 @@ TTcpSocket::~TTcpSocket() { } void TTcpSocket::recv() { - if (sock_fd() != -1) { - packet_buffer().fill(0); - set_buffer_cleared(true); - (int)tcp_receive(sock_fd(), notify, packet_buffer().size(), packet_buffer().data()); + if (m_sock_fd != -1) { + memset(m_packet_buffer, 0, sizeof(m_packet_buffer)); + m_buffer_cleared = true; + (int)tcp_receive(m_sock_fd, notify, sizeof(m_packet_buffer), m_packet_buffer); } } @@ -79,49 +79,49 @@ void TTcpSocket::notify(short size, short sock_fd) { if (socket != nullptr) { if (size > 0) { - socket->set_buffer_cleared(false); - socket->set_size(size); - socket->set_buffer_offset(0); + socket->m_buffer_cleared = false; + socket->m_size = size; + socket->m_buffer_offset = 0; sprintf(tmp_str, "Rcv:%d byte", size); socket->log(tmp_str); - if (socket->callback() != nullptr) { - socket->callback()(socket); + if (socket->m_callback != nullptr) { + socket->m_callback(socket); } } else { - socket->set_flags(1); + socket->m_is_invalid_packet |= 1; } } } short TTcpSocket::send(u8 *data, size_t size) { - if (sock_fd() != -1) { + if (m_sock_fd != -1) { if (!m_is_encrypted) { m_send_crypt.encrypt(data, size); } - if (is_invalid_packet() || !get_link_status()) { + if (m_is_invalid_packet || !get_link_status()) { return -1; } else { if (int status = stat()) { log(get_sock_status_name(status)); - set_flags(1); + m_is_invalid_packet |= 1; return 1; } else { - if (send_window() <= size) { - set_flags(1); + if (m_send_window <= size) { + m_is_invalid_packet |= 1; return 1; } else { - if (stat_val() < 0) { - set_flags(1); + if (m_stat_val < 0) { + m_is_invalid_packet |= 1; return 1; } else { struct send_buffs sb; sb.buff = data; sb.len = size; - set_unused(0); - int ret = tcp_send(sock_fd(), nullptr, 1, &sb); + m_unused = 0; + int ret = tcp_send(m_sock_fd, nullptr, 1, &sb); if (ret >= 1 || ret < -1) { - set_flags(1); + m_is_invalid_packet |= 1; log(get_sock_status_name(ret)); close(); return ret; @@ -136,28 +136,28 @@ short TTcpSocket::send(u8 *data, size_t size) { } short TTcpSocket::send(u8 *data) { - if (sock_fd() != -1) { - if (is_invalid_packet() || !get_link_status()) { + if (m_sock_fd != -1) { + if (m_is_invalid_packet || !get_link_status()) { return -1; } else { if (short status = stat()) { log(get_sock_status_name(status)); - set_flags(1); + m_is_invalid_packet |= 1; return 1; } else { - if (stat_val() < 0) { - set_flags(1); + if (m_stat_val < 0) { + m_is_invalid_packet |= 1; return 1; } else { s8 len = strlen(reinterpret_cast<const char *>(data)); struct send_buffs sb; sb.buff = data; sb.len = len; - if (send_window() <= len) { - set_flags(1); + if (m_send_window <= len) { + m_is_invalid_packet |= 1; return 1; } else { - short ret = tcp_send(sock_fd(), nullptr, 1, &sb); + short ret = tcp_send(m_sock_fd, nullptr, 1, &sb); if (ret) { close(); } @@ -175,18 +175,18 @@ int TTcpSocket::test_connection() { for (int i = 0; i < 1800; ++i) { if (int status = stat()) { log(get_sock_status_name(status)); - set_flags(1); + m_is_invalid_packet |= 1; return 1; - } else if (send_window() <= 128) { - set_flags(1); + } else if (m_send_window <= 128) { + m_is_invalid_packet |= 1; return 1; - } else if (stat_val() < 0) { - set_flags(1); + } else if (m_stat_val < 0) { + m_is_invalid_packet |= 1; return 1; } else if (!get_link_status()) { - set_flags(1); + m_is_invalid_packet |= 1; return 1; - } else if (send_window() > 4095) { + } else if (m_send_window > 4095) { return 0; } else { main_task.some_empty_func(); @@ -198,45 +198,45 @@ int TTcpSocket::test_connection() { } } - set_flags(1); + m_is_invalid_packet |= 1; return 1; } void TTcpSocket::some_stub() {} short TTcpSocket::stat() { - if (sock_fd() != -1) { - return tcp_stat(sock_fd(), &stat_val(), nullptr, &send_window(), &recv_window()); + if (m_sock_fd != -1) { + return tcp_stat(m_sock_fd, &m_stat_val, nullptr, &m_send_window, &m_recv_window); } else { return 0; } } short TTcpSocket::close() { - if (sock_fd() != -1) { - (short)tcp_abort(sock_fd()); - (short)tcp_delete(sock_fd()); - tcp_socket_table[sock_fd()] = nullptr; - set_sock_fd(-1); + if (m_sock_fd != -1) { + (short)tcp_abort(m_sock_fd); + (short)tcp_delete(m_sock_fd); + tcp_socket_table[m_sock_fd] = nullptr; + m_sock_fd = -1; m_is_encrypted = 0; - set_size(0); - set_buffer_offset(0); - set_buffer_cleared(true); + m_size = 0; + m_buffer_offset = 0; + m_buffer_cleared = true; } - return sock_fd(); + return m_sock_fd; } short TTcpSocket::open() { - set_sock_fd(-1); + m_sock_fd = -1; m_is_encrypted = 0; - set_size(0); - set_buffer_offset(0); - set_buffer_cleared(true); - set_unused(0); - set_sock_fd(tcp_create()); + m_size = 0; + m_buffer_offset = 0; + m_buffer_cleared = true; + m_unused = 0; + m_sock_fd = tcp_create(); - if (sock_fd() < 0) { - log(get_sock_status_name(sock_fd())); + if (m_sock_fd < 0) { + log(get_sock_status_name(m_sock_fd)); return -1; } else { struct at_ip_option connect_option; @@ -245,23 +245,23 @@ short TTcpSocket::open() { u32 opt = 1; - tcp_get_opt(sock_fd(), 0x2001, &opt); + tcp_get_opt(m_sock_fd, 0x2001, &opt); bind_addr.type = 4; bind_addr.ip46.ip4 = 0; - tcp_bind(sock_fd(), &bind_addr, src_port()); + tcp_bind(m_sock_fd, &bind_addr, m_src_port); connect_addr.type = 4; - connect_addr.ip46.ip4 = dst_addr().addr; + connect_addr.ip46.ip4 = m_dst_addr.addr; connect_option.type = 4; connect_option.ip46.ip4.ttl = 120; connect_option.ip46.ip4.svctype = 0; connect_option.ip46.ip4.df_flag = 0; - if (tcp_connect(sock_fd(), &connect_addr, dst_port(), &connect_option)) { - log(get_sock_status_name(sock_fd())); + if (tcp_connect(m_sock_fd, &connect_addr, m_dst_port, &connect_option)) { + log(get_sock_status_name(m_sock_fd)); return -1; } else { for (;;) { @@ -270,11 +270,11 @@ short TTcpSocket::open() { if (short status = stat()) { log(get_sock_status_name(status)); return -2; - } else if (stat_val() < 0) { + } else if (m_stat_val < 0) { return -2; } else { some_stub(); - if (stat_val() < 4) { + if (m_stat_val < 4) { if (!get_link_status()) { return -3; } else if (func_801a5d1c()) { @@ -288,8 +288,8 @@ short TTcpSocket::open() { render_tick(); } } else { - tcp_socket_table[sock_fd()] = this; - return sock_fd(); + tcp_socket_table[m_sock_fd] = this; + return m_sock_fd; } } } diff --git a/src/pso/protocol.cpp b/src/pso/protocol.cpp index 280b105..09ef213 100644 --- a/src/pso/protocol.cpp +++ b/src/pso/protocol.cpp @@ -3,7 +3,3 @@ void bswap_32(u32 *val) {} void bswap_16(u16 *val) {} - -void packet_header::bswap() { - bswap_16(&size); -} |