From 5ac9b5576aa4d5e0deb0e910de51d5091cc94f9c Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Fri, 14 May 2021 13:04:56 +0100 Subject: [PATCH] DEV9: Add PayloadData classes --- pcsx2/DEV9/PacketReader/IP/IP_Payload.h | 36 +++++++++++++++++++++++++ pcsx2/DEV9/PacketReader/Payload.h | 31 +++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/pcsx2/DEV9/PacketReader/IP/IP_Payload.h b/pcsx2/DEV9/PacketReader/IP/IP_Payload.h index 393d3d6b89..0b03e1730b 100644 --- a/pcsx2/DEV9/PacketReader/IP/IP_Payload.h +++ b/pcsx2/DEV9/PacketReader/IP/IP_Payload.h @@ -28,6 +28,42 @@ namespace PacketReader::IP virtual ~IP_Payload() {} }; + class IP_PayloadData : public IP_Payload + { + public: + std::unique_ptr data; + + private: + int length; + u8 protocol; + + public: + IP_PayloadData(int len, u8 prot) + { + protocol = prot; + length = len; + + if (len != 0) + data = std::make_unique(len); + } + virtual int GetLength() + { + return length; + } + virtual void WriteBytes(u8* buffer, int* offset) + { + if (length == 0) + return; + + memcpy(&buffer[*offset], data.get(), length); + *offset += length; + } + virtual u8 GetProtocol() + { + return protocol; + } + }; + //Pointer to bytes not owned by class class IP_PayloadPtr : public IP_Payload { diff --git a/pcsx2/DEV9/PacketReader/Payload.h b/pcsx2/DEV9/PacketReader/Payload.h index 06a58282ca..fb0c3f07cf 100644 --- a/pcsx2/DEV9/PacketReader/Payload.h +++ b/pcsx2/DEV9/PacketReader/Payload.h @@ -25,6 +25,37 @@ namespace PacketReader virtual ~Payload() {} }; + //Data owned by class + class PayloadData : public Payload + { + public: + std::unique_ptr data; + + private: + int length; + + public: + PayloadData(int len) + { + length = len; + + if (len != 0) + data = std::make_unique(len); + } + virtual int GetLength() + { + return length; + } + virtual void WriteBytes(u8* buffer, int* offset) + { + if (length == 0) + return; + + memcpy(&buffer[*offset], data.get(), length); + *offset += length; + } + }; + //Pointer to bytes not owned by class class PayloadPtr : public Payload {