From 43b38df986e9bdef51270ea324e3c307dece3435 Mon Sep 17 00:00:00 2001 From: REL <25654009+34736384@users.noreply.github.com> Date: Thu, 9 Jan 2025 01:05:46 -0500 Subject: [PATCH] fix bugs --- lib/src/NamedPipe.h | 12 ++++++++++-- lib/src/dllmain.cpp | 8 ++++---- lib/src/globals.h | 2 +- lib/src/il2cpp-types.h | 16 ++++++++++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/src/NamedPipe.h b/lib/src/NamedPipe.h index 8be4097..c1cb0f5 100644 --- a/lib/src/NamedPipe.h +++ b/lib/src/NamedPipe.h @@ -2,6 +2,13 @@ #include #include +template +concept IsSpan = requires(T t) { + { t.data() } -> std::convertible_to; + { t.size() } -> std::convertible_to; + { t.size_bytes() } -> std::convertible_to; +}; + class NamedPipe { HANDLE m_hPipe = INVALID_HANDLE_VALUE; @@ -24,9 +31,10 @@ public: return true; } - bool Write(std::span data) const + template + bool Write(const T data) const { - return Write(data.data(), data.size()); + return Write(data.data(), data.size_bytes()); } template diff --git a/lib/src/dllmain.cpp b/lib/src/dllmain.cpp index 1f76ad0..2e54aa8 100644 --- a/lib/src/dllmain.cpp +++ b/lib/src/dllmain.cpp @@ -58,7 +58,7 @@ namespace Hook { #ifdef _DEBUG std::println("PacketType: {}", static_cast(packetType)); std::println("CmdId: {}", packet->CmdId); - std::println("DataLength: {}", packet->m_DataLength); + std::println("DataLength: {}", packet->DataLength); //std::println("Data: {}", Util::Base64Encode(packet->AsSpan())); #endif @@ -74,10 +74,10 @@ namespace Hook { if (!AchievementsWritten) AchievementsWritten = packetType == PacketType::Achivement; - if (packetType == PacketType::Inventory) - PlayerStoreWrittenCount++; + if (!PlayerStoreWritten) + PlayerStoreWritten = packetType == PacketType::Inventory; - if (AchievementsWritten && PlayerStoreWrittenCount == 2) + if (AchievementsWritten && PlayerStoreWritten) { #ifdef _DEBUG system("pause"); diff --git a/lib/src/globals.h b/lib/src/globals.h index eecf2f5..b84d721 100644 --- a/lib/src/globals.h +++ b/lib/src/globals.h @@ -25,7 +25,7 @@ namespace Globals inline uint16_t PlayerStoreId = 0; // use non-zero to override dynamic search inline bool AchievementsWritten = false; - inline int32_t PlayerStoreWrittenCount = 0; + inline bool PlayerStoreWritten = false; class Offsets { diff --git a/lib/src/il2cpp-types.h b/lib/src/il2cpp-types.h index 6903648..25dad07 100644 --- a/lib/src/il2cpp-types.h +++ b/lib/src/il2cpp-types.h @@ -45,12 +45,12 @@ static_assert(offsetof(Array, vector) == 32, "vector offset is incorrec #pragma pack(push, 1) class PacketMeta { -public: uint16_t m_HeadMagic; uint16_t m_CmdId; uint16_t m_HeaderLength; uint32_t m_DataLength; uint8_t m_Data[1]; +public: PacketMeta() = delete; @@ -60,13 +60,17 @@ public: PROPERTY_GET_CONST(uint32_t, DataLength, { return _byteswap_ulong(m_DataLength); }); std::span AsSpan() { - return { m_Data, DataLength }; + return { m_Data + HeaderLength, DataLength }; } + friend struct PacketMetaStaticAssertHelper; }; #pragma pack(pop) -static_assert(offsetof(PacketMeta, m_CmdId) == 2, "CmdId offset is incorrect"); -static_assert(offsetof(PacketMeta, m_HeaderLength) == 4, "HeadLength offset is incorrect"); -static_assert(offsetof(PacketMeta, m_DataLength) == 6, "DataLength offset is incorrect"); -static_assert(offsetof(PacketMeta, m_Data) == 10, "Data offset is incorrect"); \ No newline at end of file +struct PacketMetaStaticAssertHelper +{ + static_assert(offsetof(PacketMeta, m_CmdId) == 2, "CmdId offset is incorrect"); + static_assert(offsetof(PacketMeta, m_HeaderLength) == 4, "HeadLength offset is incorrect"); + static_assert(offsetof(PacketMeta, m_DataLength) == 6, "DataLength offset is incorrect"); + static_assert(offsetof(PacketMeta, m_Data) == 10, "Data offset is incorrect"); +}; \ No newline at end of file