From 06ef51db2ed7238a04de4614dd52a8dd69923fff Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Mon, 16 Jan 2023 21:38:06 +0000 Subject: [PATCH] DEV9: Move NetLib functions into header and mark as inline --- pcsx2/CMakeLists.txt | 1 - pcsx2/DEV9/PacketReader/NetLib.cpp | 98 ------------------------------ pcsx2/DEV9/PacketReader/NetLib.h | 82 +++++++++++++++++++++---- pcsx2/pcsx2core.vcxproj | 1 - pcsx2/pcsx2core.vcxproj.filters | 3 - 5 files changed, 70 insertions(+), 115 deletions(-) delete mode 100644 pcsx2/DEV9/PacketReader/NetLib.cpp diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 558d42a9cb..f1eade721a 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -339,7 +339,6 @@ set(pcsx2DEV9Sources DEV9/PacketReader/IP/IP_Options.cpp DEV9/PacketReader/IP/IP_Packet.cpp DEV9/PacketReader/EthernetFrame.cpp - DEV9/PacketReader/NetLib.cpp DEV9/Sessions/BaseSession.cpp DEV9/Sessions/ICMP_Session/ICMP_Session.cpp DEV9/Sessions/TCP_Session/TCP_Session.cpp diff --git a/pcsx2/DEV9/PacketReader/NetLib.cpp b/pcsx2/DEV9/PacketReader/NetLib.cpp deleted file mode 100644 index cfc1496f2e..0000000000 --- a/pcsx2/DEV9/PacketReader/NetLib.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2021 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#include "PrecompiledHeader.h" - -#include "NetLib.h" - -#ifdef _WIN32 -#include "winsock.h" -#else -#include -#endif - -using namespace PacketReader; -using namespace PacketReader::IP; - -namespace PacketReader::NetLib -{ - void WriteByte08(u8* data, int* index, u8 value) - { - data[*index] = value; - *index += sizeof(u8); - } - void WriteUInt16(u8* data, int* index, u16 value) - { - *(u16*)&data[*index] = htons(value); - *index += sizeof(u16); - } - void WriteUInt32(u8* data, int* index, u32 value) - { - *(u32*)&data[*index] = htonl(value); - *index += sizeof(u32); - } - - //Special - void WriteMACAddress(u8* data, int* index, MAC_Address value) - { - *(MAC_Address*)&data[*index] = value; - *index += sizeof(MAC_Address); - } - void WriteIPAddress(u8* data, int* index, IP_Address value) - { - *(IP_Address*)&data[*index] = value; - *index += sizeof(IP_Address); - } - void WriteByteArray(u8* data, int* index, int length, u8* value) - { - memcpy(&data[*index], value, length); - *index += length; - } - - - //Read - void ReadByte08(u8* data, int* index, u8* value) - { - *value = data[*index]; - *index += sizeof(u8); - } - void ReadUInt16(u8* data, int* index, u16* value) - { - *value = ntohs(*(u16*)&data[*index]); - *index += sizeof(u16); - } - void ReadUInt32(u8* data, int* index, u32* value) - { - *value = ntohl(*(u32*)&data[*index]); - *index += sizeof(u32); - } - - //Special - void ReadMACAddress(u8* data, int* index, MAC_Address* value) - { - *value = *(MAC_Address*)&data[*index]; - *index += sizeof(MAC_Address); - } - void ReadIPAddress(u8* data, int* index, IP_Address* value) - { - *value = *(IP_Address*)&data[*index]; - *index += sizeof(IP_Address); - } - void ReadByteArray(u8* data, int* index, int length, u8* value) - { - memcpy(value, &data[*index], length); - *index += length; - } -} // namespace PacketReader::NetLib diff --git a/pcsx2/DEV9/PacketReader/NetLib.h b/pcsx2/DEV9/PacketReader/NetLib.h index 29c20d7d1c..cd1ddbb5cb 100644 --- a/pcsx2/DEV9/PacketReader/NetLib.h +++ b/pcsx2/DEV9/PacketReader/NetLib.h @@ -18,21 +18,79 @@ #include "DEV9/PacketReader/MAC_Address.h" #include "DEV9/PacketReader/IP/IP_Address.h" +#ifdef _WIN32 +#include "winsock.h" +#else +#include +#endif + namespace PacketReader::NetLib { - void WriteByte08(u8* data, int* index, u8 value); - void WriteUInt16(u8* data, int* index, u16 value); - void WriteUInt32(u8* data, int* index, u32 value); + // Write. + inline void WriteByte08(u8* data, int* index, u8 value) + { + data[*index] = value; + *index += sizeof(u8); + } + inline void WriteUInt16(u8* data, int* index, u16 value) + { + *(u16*)&data[*index] = htons(value); + *index += sizeof(u16); + } + inline void WriteUInt32(u8* data, int* index, u32 value) + { + *(u32*)&data[*index] = htonl(value); + *index += sizeof(u32); + } - void WriteMACAddress(u8* data, int* index, PacketReader::MAC_Address value); - void WriteIPAddress(u8* data, int* index, PacketReader::IP::IP_Address value); - void WriteByteArray(u8* data, int* index, int length, u8* value); + // Special write. + inline void WriteMACAddress(u8* data, int* index, PacketReader::MAC_Address value) + { + *(PacketReader::MAC_Address*)&data[*index] = value; + *index += sizeof(PacketReader::MAC_Address); + } + inline void WriteIPAddress(u8* data, int* index, PacketReader::IP::IP_Address value) + { + *(PacketReader::IP::IP_Address*)&data[*index] = value; + *index += sizeof(PacketReader::IP::IP_Address); + } + inline void WriteByteArray(u8* data, int* index, int length, u8* value) + { + memcpy(&data[*index], value, length); + *index += length; + } - void ReadByte08(u8* data, int* index, u8* value); - void ReadUInt16(u8* data, int* index, u16* value); - void ReadUInt32(u8* data, int* index, u32* value); + // Read. + inline void ReadByte08(u8* data, int* index, u8* value) + { + *value = data[*index]; + *index += sizeof(u8); + } + inline void ReadUInt16(u8* data, int* index, u16* value) + { + *value = ntohs(*(u16*)&data[*index]); + *index += sizeof(u16); + } + inline void ReadUInt32(u8* data, int* index, u32* value) + { + *value = ntohl(*(u32*)&data[*index]); + *index += sizeof(u32); + } - void ReadMACAddress(u8* data, int* index, PacketReader::MAC_Address* value); - void ReadIPAddress(u8* data, int* index, PacketReader::IP::IP_Address* value); - void ReadByteArray(u8* data, int* index, int length, u8* value); + // Special read. + inline void ReadMACAddress(u8* data, int* index, PacketReader::MAC_Address* value) + { + *value = *(PacketReader::MAC_Address*)&data[*index]; + *index += sizeof(PacketReader::MAC_Address); + } + inline void ReadIPAddress(u8* data, int* index, PacketReader::IP::IP_Address* value) + { + *value = *(PacketReader::IP::IP_Address*)&data[*index]; + *index += sizeof(PacketReader::IP::IP_Address); + } + inline void ReadByteArray(u8* data, int* index, int length, u8* value) + { + memcpy(value, &data[*index], length); + *index += length; + } } // namespace PacketReader::NetLib diff --git a/pcsx2/pcsx2core.vcxproj b/pcsx2/pcsx2core.vcxproj index 82afd4c657..3f63f88be4 100644 --- a/pcsx2/pcsx2core.vcxproj +++ b/pcsx2/pcsx2core.vcxproj @@ -177,7 +177,6 @@ - diff --git a/pcsx2/pcsx2core.vcxproj.filters b/pcsx2/pcsx2core.vcxproj.filters index 8ae95fd31f..15686ccdee 100644 --- a/pcsx2/pcsx2core.vcxproj.filters +++ b/pcsx2/pcsx2core.vcxproj.filters @@ -941,9 +941,6 @@ System\Ps2\DEV9\PacketReader - - System\Ps2\DEV9\PacketReader - System\Ps2\DEV9