Skip to content

Commit 0dba0c2

Browse files
committed
Implement GetValue and SetValue methods for ZString specialization of TCheatProtect
1 parent 14973c1 commit 0dba0c2

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

ZHMModSDK/Include/Glacier/TCheatProtect.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,41 @@ class TCheatProtect {
2626
template <>
2727
class TCheatProtect<ZString> {
2828
public:
29+
ZString GetValue() {
30+
const uint32_t s_Length = m_sScrambledString.size();
31+
32+
std::vector<uint8_t> s_Buffer(s_Length);
33+
34+
memcpy(s_Buffer.data(), m_sScrambledString.c_str(), s_Length);
35+
36+
for (uint32_t i = 0; i < s_Length - 1; ++i) {
37+
s_Buffer[i] ^= static_cast<uint8_t>(s_Buffer[i + 1] + m_sScrambledString.m_nLength);
38+
}
39+
40+
s_Buffer[s_Length - 1] ^= static_cast<uint8_t>(m_sScrambledString.m_nLength);
41+
42+
return ZString::AllocateFromCStr(
43+
reinterpret_cast<const char*>(s_Buffer.data()), s_Length
44+
);
45+
}
46+
47+
void SetValue(const ZString& s_Value) {
48+
const uint32_t s_Length = m_sScrambledString.size();
49+
50+
std::vector<uint8_t> s_Buffer(s_Length);
51+
52+
memcpy(s_Buffer.data(), s_Value.c_str(), s_Length);
53+
54+
s_Buffer[s_Length - 1] ^= static_cast<uint8_t>(s_Value.m_nLength);
55+
56+
for (uint32_t i = s_Length - 2; i >= 0; --i) {
57+
s_Buffer[i] ^= static_cast<uint8_t>(s_Buffer[i + 1] + s_Value.m_nLength);
58+
}
59+
60+
m_sScrambledString = ZString::AllocateFromCStr(
61+
reinterpret_cast<const char*>(s_Buffer.data()), s_Length
62+
);
63+
}
64+
2965
ZString m_sScrambledString;
3066
};

0 commit comments

Comments
 (0)