This commit is contained in:
REL
2025-01-09 01:05:46 -05:00
parent 6e1c8f275f
commit 43b38df986
4 changed files with 25 additions and 13 deletions

View File

@@ -2,6 +2,13 @@
#include <Windows.h> #include <Windows.h>
#include <span> #include <span>
template <typename T>
concept IsSpan = requires(T t) {
{ t.data() } -> std::convertible_to<const void*>;
{ t.size() } -> std::convertible_to<std::size_t>;
{ t.size_bytes() } -> std::convertible_to<std::size_t>;
};
class NamedPipe class NamedPipe
{ {
HANDLE m_hPipe = INVALID_HANDLE_VALUE; HANDLE m_hPipe = INVALID_HANDLE_VALUE;
@@ -24,9 +31,10 @@ public:
return true; return true;
} }
bool Write(std::span<const uint8_t> data) const template <IsSpan T>
bool Write(const T data) const
{ {
return Write(data.data(), data.size()); return Write(data.data(), data.size_bytes());
} }
template <typename T> template <typename T>

View File

@@ -58,7 +58,7 @@ namespace Hook {
#ifdef _DEBUG #ifdef _DEBUG
std::println("PacketType: {}", static_cast<uint8_t>(packetType)); std::println("PacketType: {}", static_cast<uint8_t>(packetType));
std::println("CmdId: {}", packet->CmdId); std::println("CmdId: {}", packet->CmdId);
std::println("DataLength: {}", packet->m_DataLength); std::println("DataLength: {}", packet->DataLength);
//std::println("Data: {}", Util::Base64Encode(packet->AsSpan())); //std::println("Data: {}", Util::Base64Encode(packet->AsSpan()));
#endif #endif
@@ -74,10 +74,10 @@ namespace Hook {
if (!AchievementsWritten) if (!AchievementsWritten)
AchievementsWritten = packetType == PacketType::Achivement; AchievementsWritten = packetType == PacketType::Achivement;
if (packetType == PacketType::Inventory) if (!PlayerStoreWritten)
PlayerStoreWrittenCount++; PlayerStoreWritten = packetType == PacketType::Inventory;
if (AchievementsWritten && PlayerStoreWrittenCount == 2) if (AchievementsWritten && PlayerStoreWritten)
{ {
#ifdef _DEBUG #ifdef _DEBUG
system("pause"); system("pause");

View File

@@ -25,7 +25,7 @@ namespace Globals
inline uint16_t PlayerStoreId = 0; // use non-zero to override dynamic search inline uint16_t PlayerStoreId = 0; // use non-zero to override dynamic search
inline bool AchievementsWritten = false; inline bool AchievementsWritten = false;
inline int32_t PlayerStoreWrittenCount = 0; inline bool PlayerStoreWritten = false;
class Offsets class Offsets
{ {

View File

@@ -45,12 +45,12 @@ static_assert(offsetof(Array<uint8_t>, vector) == 32, "vector offset is incorrec
#pragma pack(push, 1) #pragma pack(push, 1)
class PacketMeta class PacketMeta
{ {
public:
uint16_t m_HeadMagic; uint16_t m_HeadMagic;
uint16_t m_CmdId; uint16_t m_CmdId;
uint16_t m_HeaderLength; uint16_t m_HeaderLength;
uint32_t m_DataLength; uint32_t m_DataLength;
uint8_t m_Data[1]; uint8_t m_Data[1];
public:
PacketMeta() = delete; PacketMeta() = delete;
@@ -60,13 +60,17 @@ public:
PROPERTY_GET_CONST(uint32_t, DataLength, { return _byteswap_ulong(m_DataLength); }); PROPERTY_GET_CONST(uint32_t, DataLength, { return _byteswap_ulong(m_DataLength); });
std::span<uint8_t> AsSpan() { std::span<uint8_t> AsSpan() {
return { m_Data, DataLength }; return { m_Data + HeaderLength, DataLength };
} }
friend struct PacketMetaStaticAssertHelper;
}; };
#pragma pack(pop) #pragma pack(pop)
static_assert(offsetof(PacketMeta, m_CmdId) == 2, "CmdId offset is incorrect"); struct PacketMetaStaticAssertHelper
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_CmdId) == 2, "CmdId offset is incorrect");
static_assert(offsetof(PacketMeta, m_Data) == 10, "Data 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");
};