Skip to content

Commit a8d51d8

Browse files
Renzo904ThisAMJ
andauthored
feat: improve sar_portalcolor_* in sp (#297)
Co-authored-by: AMJ <[email protected]>
1 parent d2675a4 commit a8d51d8

File tree

9 files changed

+172
-28
lines changed

9 files changed

+172
-28
lines changed

docs/cvars.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@
423423
|sar_portalcolor_mp2_1|255 179 31|Portal color for P-Body (orange)'s left portal.|
424424
|sar_portalcolor_mp2_2|57 2 2|Portal color for P-Body (orange)'s right portal.|
425425
|sar_portalcolor_rainbow|0|Rainbow portals!|
426-
|sar_portalcolor_sp_1|64 160 255|Portal color for Chell's left portal.|
427-
|sar_portalcolor_sp_2|255 160 32|Portal color for Chell's right portal.|
426+
|sar_portalcolor_sp_1|64 160 255|Portal color for Chell's left portal. r_portal_fastpath 0 required.|
427+
|sar_portalcolor_sp_2|255 160 32|Portal color for Chell's right portal. r_portal_fastpath 0 required.|
428428
|sar_portalgun_hud|0|Enables the portalgun HUD.|
429429
|sar_portalgun_hud_x|5|The x position of the portalgun HUD.|
430430
|sar_portalgun_hud_y|5|The y position of the portalgun HUD.|

src/Modules/Client.cpp

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include "Features/FovChanger.hpp"
1212
#include "Features/GroundFramesCounter.hpp"
1313
#include "Features/Hud/InputHud.hpp"
14+
#include "Features/Hud/RhythmGame.hpp"
1415
#include "Features/Hud/ScrollSpeed.hpp"
1516
#include "Features/Hud/StrafeHud.hpp"
16-
#include "Features/Hud/RhythmGame.hpp"
1717
#include "Features/Hud/StrafeQuality.hpp"
1818
#include "Features/NetMessage.hpp"
1919
#include "Features/OverlayRender.hpp"
@@ -84,8 +84,8 @@ Variable sar_patch_minor_angle_decay("sar_patch_minor_angle_decay", "0", "Patche
8484
Variable sar_unlocked_chapters("sar_unlocked_chapters", "-1", "Max unlocked chapter.\n");
8585

8686
Variable sar_portalcolor_enable("sar_portalcolor_enable", "0", "Enable custom portal colors.\n");
87-
Variable sar_portalcolor_sp_1("sar_portalcolor_sp_1", "64 160 255", "Portal color for Chell's left portal.\n");
88-
Variable sar_portalcolor_sp_2("sar_portalcolor_sp_2", "255 160 32", "Portal color for Chell's right portal.\n");
87+
Variable sar_portalcolor_sp_1("sar_portalcolor_sp_1", "64 160 255", "Portal color for Chell's left portal. r_portal_fastpath 0 required.\n");
88+
Variable sar_portalcolor_sp_2("sar_portalcolor_sp_2", "255 160 32", "Portal color for Chell's right portal. r_portal_fastpath 0 required.\n");
8989
Variable sar_portalcolor_mp1_1("sar_portalcolor_mp1_1", "31 127 210", "Portal color for Atlas (blue)'s left portal.\n");
9090
Variable sar_portalcolor_mp1_2("sar_portalcolor_mp1_2", "19 0 210", "Portal color for Atlas (blue)'s right portal.\n");
9191
Variable sar_portalcolor_mp2_1("sar_portalcolor_mp2_1", "255 179 31", "Portal color for P-Body (orange)'s left portal.\n");
@@ -124,6 +124,7 @@ REDECL(Client::OnCommand);
124124
REDECL(Client::ApplyMouse_Mid);
125125
REDECL(Client::ApplyMouse_Mid_Continue);
126126
#endif
127+
REDECL(Client::DrawPortal);
127128
REDECL(Client::GetChapterProgress);
128129

129130

@@ -330,12 +331,44 @@ DETOUR_COMMAND(Client::openleaderboard) {
330331
}
331332
}
332333

334+
Memory::Patch *g_drawPortalPatch;
335+
Memory::Patch *g_drawPortalGhostPatch;
336+
// C_Prop_Portal::DrawPortal
337+
extern Hook g_DrawPortalHook;
338+
DETOUR(Client::DrawPortal, void *pRenderContext) {
339+
if (sar_portalcolor_enable.GetBool()) {
340+
g_drawPortalPatch->Execute();
341+
} else {
342+
g_drawPortalPatch->Restore();
343+
}
344+
g_DrawPortalHook.Disable();
345+
auto ret = Client::DrawPortal(thisptr, pRenderContext);
346+
g_DrawPortalHook.Enable();
347+
return ret;
348+
}
349+
Hook g_DrawPortalHook(&Client::DrawPortal_Hook);
350+
351+
static void (*g_DrawPortalGhost)(void *pRenderContext);
352+
353+
// C_Prop_Portal::DrawPortalGhostLocations
354+
extern Hook g_DrawPortalGhostHook;
355+
static void DrawPortalGhost_Hook(void *pRenderContext) {
356+
if (sar_portalcolor_enable.GetBool()) {
357+
g_drawPortalGhostPatch->Execute();
358+
} else {
359+
g_drawPortalGhostPatch->Restore();
360+
}
361+
g_DrawPortalGhostHook.Disable();
362+
g_DrawPortalGhost(pRenderContext);
363+
g_DrawPortalGhostHook.Enable();
364+
return;
365+
}
366+
Hook g_DrawPortalGhostHook(&DrawPortalGhost_Hook);
367+
368+
333369
static SourceColor (*UTIL_Portal_Color)(int iPortal, int iTeamNumber);
334370
extern Hook UTIL_Portal_Color_Hook;
335371
static SourceColor UTIL_Portal_Color_Detour(int iPortal, int iTeamNumber) {
336-
// FIXME: SP portal rendering does not use this but rather the
337-
// texture's color itself. This does however work on the color
338-
// of the SP *crosshair* and particles.
339372
UTIL_Portal_Color_Hook.Disable();
340373
SourceColor ret = UTIL_Portal_Color(iPortal, iTeamNumber);
341374
UTIL_Portal_Color_Hook.Enable();
@@ -992,13 +1025,45 @@ bool Client::Init() {
9921025

9931026
#ifdef _WIN32
9941027
auto ApplyMouse_Mid_addr = (uintptr_t)(Client::ApplyMouse) + Offsets::ApplyMouse_Mid;
995-
g_ApplyMouseMidHook.SetFunc(ApplyMouse_Mid_addr);
996-
g_ApplyMouseMidHook.Disable();
1028+
g_ApplyMouseMidHook.SetFunc(ApplyMouse_Mid_addr, false);
9971029
Client::ApplyMouse_Mid_Continue = ApplyMouse_Mid_addr + 0x5;
9981030
#endif
9991031
MatrixBuildRotationAboutAxis = (decltype(MatrixBuildRotationAboutAxis))Memory::Scan(client->Name(), Offsets::MatrixBuildRotationAboutAxis);
1000-
MatrixBuildRotationAboutAxisHook.SetFunc(MatrixBuildRotationAboutAxis);
1001-
MatrixBuildRotationAboutAxisHook.Disable(); // only during ApplyMouse
1032+
MatrixBuildRotationAboutAxisHook.SetFunc(MatrixBuildRotationAboutAxis, false); // only during ApplyMouse
1033+
1034+
auto drawPortalSpBranch = Memory::Scan(client->Name(), Offsets::DrawPortalSpBranch);
1035+
auto drawPortalGhostSpBranch = Memory::Scan(client->Name(), Offsets::DrawPortalGhostSpBranch);
1036+
1037+
Client::DrawPortal = (decltype(Client::DrawPortal))Memory::Scan(client->Name(), Offsets::DrawPortal);
1038+
g_DrawPortalGhost = (decltype(g_DrawPortalGhost))Memory::Scan(client->Name(), Offsets::DrawPortalGhost);
1039+
1040+
g_DrawPortalHook.SetFunc(Client::DrawPortal);
1041+
g_DrawPortalGhostHook.SetFunc(g_DrawPortalGhost);
1042+
1043+
g_drawPortalPatch = new Memory::Patch();
1044+
g_drawPortalGhostPatch = new Memory::Patch();
1045+
1046+
unsigned char drawPortalGhostByte = 0x80;
1047+
if (drawPortalSpBranch && drawPortalGhostSpBranch) {
1048+
#ifndef _WIN32
1049+
unsigned char drawPortalBytes[5];
1050+
1051+
*(int32_t *)(drawPortalBytes + 1) = *(int32_t *)(drawPortalSpBranch + 2) + Offsets::DrawPortalSpBranchOff;
1052+
drawPortalBytes[0] = 0x81;
1053+
1054+
g_drawPortalPatch->Execute(drawPortalSpBranch + 1, drawPortalBytes, 5);
1055+
g_drawPortalGhostPatch->Execute(drawPortalGhostSpBranch + 1, &drawPortalGhostByte, 1);
1056+
1057+
#else
1058+
unsigned char drawPortalBytes[2];
1059+
1060+
drawPortalBytes[0] = 0xEB;
1061+
drawPortalBytes[1] = Offsets::DrawPortalSpBranchOff;
1062+
1063+
g_drawPortalPatch->Execute(drawPortalSpBranch, drawPortalBytes, 2);
1064+
g_drawPortalGhostPatch->Execute(drawPortalGhostSpBranch + 1, &drawPortalGhostByte, 1);
1065+
#endif
1066+
}
10021067

10031068
in_forceuser = Variable("in_forceuser");
10041069
if (!!in_forceuser && this->g_Input) {
@@ -1057,8 +1122,8 @@ bool Client::Init() {
10571122

10581123
g_AddShadowToReceiverHook.SetFunc(Client::AddShadowToReceiver);
10591124

1060-
UTIL_Portal_Color = (decltype (UTIL_Portal_Color))Memory::Scan(client->Name(), Offsets::UTIL_Portal_Color);
1061-
UTIL_Portal_Color_Particles = (decltype (UTIL_Portal_Color_Particles))Memory::Scan(client->Name(), Offsets::UTIL_Portal_Color_Particles);
1125+
UTIL_Portal_Color = (decltype(UTIL_Portal_Color))Memory::Scan(client->Name(), Offsets::UTIL_Portal_Color);
1126+
UTIL_Portal_Color_Particles = (decltype(UTIL_Portal_Color_Particles))Memory::Scan(client->Name(), Offsets::UTIL_Portal_Color_Particles);
10621127
UTIL_Portal_Color_Hook.SetFunc(UTIL_Portal_Color);
10631128
UTIL_Portal_Color_Particles_Hook.SetFunc(UTIL_Portal_Color_Particles);
10641129

src/Modules/Client.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ class Client : public Module {
167167
DECL_DETOUR_MID_MH(ApplyMouse_Mid);
168168
#endif
169169

170+
// C_Prop_Portal::DrawPortal
171+
DECL_DETOUR(DrawPortal, void *pRenderContext);
172+
170173
bool Init() override;
171174
void Shutdown() override;
172175
const char *Name() override {

src/Offsets/INFRA 6905.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ SIGSCAN_WINDOWS(SND_RecordBuffer, "55 8B EC 80 3D ? ? ? ? 00 56")
9595

9696
// Client
9797
SIGSCAN_WINDOWS(DrawTranslucentRenderables, "55 8B EC 81 EC 80 00 00 00 53 56 8B F1")
98+
SIGSCAN_WINDOWS(DrawPortalGhost, "")
9899
SIGSCAN_WINDOWS(DrawOpaqueRenderables, "55 8B EC 83 EC 54 A1 ? ? ? ? 83 7D ? 00")
99100
SIGSCAN_WINDOWS(GetHudSig, "55 8B EC 8B 45 ? 83 F8 FF 75 ? 8B 0D ? ? ? ? 8B 01 8B 90 ? ? ? ? FF D2 69 C0 84 00 00 00") // usage of FindElement -> probably previous function call
100101
SIGSCAN_WINDOWS(FindElementSig, "55 8B EC 53 8B 5D ? 56 57 8B F1 33 FF") // "[%d] Could not find Hud Element: %s\n" xref

src/Offsets/Portal 2 5723.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,13 @@ OFFSET_LINUX(snd_linear_count, 33)
1919
OFFSET_LINUX(snd_p, 72)
2020
OFFSET_LINUX(snd_vol, 80)
2121

22+
// Pathmatch
2223
SIGSCAN_LINUX(PathMatch, "55 89 E5 57 56 53 83 EC ? 0F B6 45 ? 80 3D")
24+
25+
// Client
26+
SIGSCAN_LINUX(DrawPortal, "55 89 E5 83 EC 58 A1 ? ? ? ? 89 5D ? 89 75 ? 8B 5D ? 89 7D ? 8B 75 ? 8B 10")
27+
SIGSCAN_LINUX(DrawPortalSpBranch, "0F 85 ? ? ? ? 0F B6 83 ? ? ? ? 8B 3C 85 ? ? ? ? A1 ? ? ? ? 89 04 24 E8 ? ? ? ? 84 C0 74")
28+
OFFSET_LINUX(DrawPortalSpBranchOff, 0x15)
29+
SIGSCAN_LINUX(DrawPortalGhost, "55 89 E5 57 56 53 83 EC 5C A1 ? ? ? ? 8B 40")
30+
SIGSCAN_LINUX(DrawPortalGhostSpBranch, "0F 84 ? ? ? ? FF 90 ? ? ? ? 80 BB ? ? ? ? 01")
2331
SIGSCAN_LINUX(GetChapterProgress, "55 89 E5 57 56 53 83 EC 2C 8B 7D 08 E8 ? ? ? ? 8B 10 C7")

src/Offsets/Portal 2 8151.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ SIGSCAN_LINUX(SND_RecordBuffer, "55 89 E5 57 56 53 83 EC 3C 65 A1 ? ? ? ? 89 45
5454
// Client
5555
SIGSCAN_LINUX(MatrixBuildRotationAboutAxis, "55 89 E5 56 53 8D 45 ? 8D 55 ? 83 EC 20")
5656
SIGSCAN_LINUX(DrawTranslucentRenderables, "55 89 E5 57 56 53 81 EC DC 00 00 00 8B 45 08 8B 5D 0C 89 C7 89 45 84 8B 45 10 89 85 4C FF FF FF")
57+
SIGSCAN_LINUX(DrawPortal, "55 89 E5 57 56 53 83 EC 3C A1 ? ? ? ? 8B 5D ? 8B 10 89 04 24 FF 52 ? A8 02")
58+
SIGSCAN_LINUX(DrawPortalSpBranch, "0F 85 ? ? ? ? 0F B6 83 ? ? ? ? 8B 34 85")
59+
OFFSET_LINUX(DrawPortalSpBranchOff, 0x15)
60+
SIGSCAN_LINUX(DrawPortalGhost, "A1 ? ? ? ? 8B 40 ? 85 C0 74 ? 55 89 E5 57 56 53 83 EC 4C")
61+
SIGSCAN_LINUX(DrawPortalGhostSpBranch, "0F 84 ? ? ? ? 8B 03 89 1C 24 FF 90 ? ? ? ? 80 BB ? ? ? ? 01")
5762
SIGSCAN_LINUX(DrawOpaqueRenderables, "55 89 E5 57 56 53 81 EC 8C 00 00 00 8B 45 0C 8B 5D 08 89 45 8C 8B 45 14 89 45 90 65 A1 14 00 00 00")
5863
SIGSCAN_LINUX(AddShadowToReceiver, "55 89 E5 57 56 53 83 EC ? 8B 45 ? 8B 4D ? 8B 7D ? 89 45 ? 0F B7 C0")
5964
SIGSCAN_LINUX(UTIL_Portal_Color, "55 89 E5 56 53 83 EC 10 8B 75 ? 8B 5D ? 85 F6 0F 84")

src/Offsets/Portal 2 8491.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ SIGSCAN_DEFAULT(MatrixBuildRotationAboutAxis, "55 8B EC 51 F3 0F 10 45 ? 0F 5A C
394394
"56 66 0F EF C0 53 83 EC 14 8B 5C 24 ? 8D 44 24")
395395
SIGSCAN_DEFAULT(DrawTranslucentRenderables, "55 8B EC 81 EC 80 00 00 00 53 56 8B F1 8B 0D ? ? ? ? 8B 01 8B 90 C4 01 00 00 57 89 75 F0 FF D2 8B F8",
396396
"55 89 E5 57 56 53 81 EC B8 00 00 00 8B 45 10 8B 5D 0C 89 85 60 FF FF FF 88 45 A7 A1 ? ? ? ?")
397+
SIGSCAN_DEFAULT(DrawPortal, "55 8B EC 83 EC 14 53 8B D9 8B 0D ? ? ? ? 8B 01",
398+
"55 57 56 53 83 EC 2C A1 ? ? ? ? 8B 5C 24 ? 8B 74 24 ? 8B 10") // "$PortalColorGradientLight" xref[0] -> C_Prop_Portal::DrawPortal
399+
SIGSCAN_DEFAULT(DrawPortalSpBranch, "8B 15 ? ? ? ? 33 C0 32 C9",
400+
"0F 85 ? ? ? ? 0F B6 83 ? ? ? ? 8B 2C 85")
401+
OFFSET_DEFAULT(DrawPortalSpBranchOff, -14, 0x19)
402+
SIGSCAN_DEFAULT(DrawPortalGhost, "55 8B EC A1 ? ? ? ? 83 EC 24 83 78 ? ? 0F 84 1E 02 00 00 A1 ? ? ? ?",
403+
"A1 ? ? ? ? 8B 40 ? 85 C0 0F 84 ? ? ? ? 55 57") // "Portal Ghosts" xref[1] -> next function call has sig (int *) -> C_Prop_Portal::DrawPortalGhostLocations
404+
SIGSCAN_DEFAULT(DrawPortalGhostSpBranch, "0F 84 ? ? ? ? 8B 90 ? ? ? ? FF D2 50 33 C0 38 86 ? ? ? ? 8D 4D ? 0F 95 C0",
405+
"0F 84 ? ? ? ? 8B 03 83 EC 0C 53 FF 90 ? ? ? ? 83 C4 10 80 BB ? ? ? ? 01")
397406
SIGSCAN_DEFAULT(DrawOpaqueRenderables, "55 8B EC 83 EC 54 83 7D 0C 00 A1 ? ? ? ? 53 56 0F 9F 45 EC 83 78 30 00 57 8B F1 0F 84 BA 03 00 00",
398407
"55 89 E5 57 56 53 83 EC 7C A1 ? ? ? ? 8B 5D 08 89 45 90 85 C0 0F 85 34 04 00 00 A1 ? ? ? ? 8B 40 30 85 C0")
399408
SIGSCAN_DEFAULT(MsgPreSkipToNextLevel, "57 8B F9 E8 ? ? ? ? 8B C8 E8 ? ? ? ? 0B C2",
@@ -403,9 +412,9 @@ SIGSCAN_DEFAULT(CalcViewModelLag, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B
403412
SIGSCAN_DEFAULT(AddShadowToReceiver, "55 8B EC 51 53 56 57 0F B7 7D 08",
404413
"55 89 E5 57 56 53 83 EC 44 8B 45 0C 8B 5D 08 8B 55 14 8B 75 10")
405414
SIGSCAN_DEFAULT(UTIL_Portal_Color, "55 8B EC 56 8B 75 ? 85 F6 0F 84 ? ? ? ? 0F 8E",
406-
"56 53 83 EC 04 8B 44 24 ? 8B 74 24 ? 85 C0 74 ? 8D 58")
415+
"56 53 83 EC 04 8B 44 24 ? 8B 74 24 ? 85 C0 74 ? 8D 58")
407416
SIGSCAN_DEFAULT(UTIL_Portal_Color_Particles, "55 8B EC 51 8B 0D ? ? ? ? 8B 01 8B 90 ? ? ? ? FF D2 84 C0",
408-
"53 83 EC 14 A1 ? ? ? ? 8B 5C 24 ? 8B 10 50 FF 92 ? ? ? ? 83 C4 10 84 C0 75")
417+
"53 83 EC 14 A1 ? ? ? ? 8B 5C 24 ? 8B 10 50 FF 92 ? ? ? ? 83 C4 10 84 C0 75")
409418
SIGSCAN_DEFAULT(GetNumChapters, "55 8B EC 80 7D 08 00 57 74 0C",
410419
"55 89 E5 56 80 7D")
411420
SIGSCAN_DEFAULT(CPortalLeaderboardPanel_OnThink, "55 8B EC A1 ? ? ? ? 81 EC ? ? ? ? 53 56 32 DB",

src/Utils/Memory.cpp

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,49 @@ std::vector<std::vector<uintptr_t>> Memory::MultiScan(const char *moduleName, co
231231
return results;
232232
}
233233

234-
#ifdef _WIN32
235234
Memory::Patch::~Patch() {
236235
if (this->original) {
237236
this->Restore();
238-
delete this->original;
237+
delete[] this->original;
239238
this->original = nullptr;
240239
}
240+
if (this->patch) {
241+
delete[] this->patch;
242+
this->patch = nullptr;
243+
}
244+
this->isPatched = false;
241245
}
246+
bool Memory::Patch::Execute() {
247+
if (this->isPatched) return true; // already executed
248+
unsigned char *tmpPatch = new unsigned char[this->size];
249+
// We create another patch, because this->patch is gonna be deleted
250+
memcpy(tmpPatch, this->patch, this->size);
251+
auto ret = this->Execute(this->location, tmpPatch, this->size);
252+
delete[] tmpPatch;
253+
return ret;
254+
}
255+
242256
bool Memory::Patch::Execute(uintptr_t location, unsigned char *bytes, size_t size) {
257+
if (this->isPatched) return true; // already executed
243258
this->location = location;
244259
this->size = size;
260+
if (this->original) {
261+
delete[] this->original;
262+
this->original = nullptr;
263+
}
245264
this->original = new unsigned char[this->size];
246265

266+
if (!bytes) {
267+
return false;
268+
}
269+
if (this->patch) {
270+
delete[] this->patch;
271+
this->patch = nullptr;
272+
}
273+
this->patch = new unsigned char[this->size];
274+
memcpy(this->patch, bytes, size);
275+
276+
#ifdef _WIN32
247277
for (size_t i = 0; i < this->size; ++i) {
248278
if (!ReadProcessMemory(GetCurrentProcess(), reinterpret_cast<LPVOID>(this->location + i), &this->original[i], 1, 0)) {
249279
return false;
@@ -255,17 +285,38 @@ bool Memory::Patch::Execute(uintptr_t location, unsigned char *bytes, size_t siz
255285
return false;
256286
}
257287
}
288+
#else
289+
Memory::UnProtect(reinterpret_cast<void *>(this->location), this->size);
290+
for (size_t i = 0; i < this->size; ++i) {
291+
this->original[i] = *(uint8_t *)(this->location + i);
292+
*(uint8_t *)(this->location + i) = bytes[i];
293+
}
294+
#endif
295+
this->isPatched = true;
258296
return true;
259297
}
260298
bool Memory::Patch::Restore() {
261-
if (this->location && this->original) {
262-
for (size_t i = 0; i < this->size; ++i) {
263-
if (!WriteProcessMemory(GetCurrentProcess(), reinterpret_cast<LPVOID>(this->location + i), &this->original[i], 1, 0)) {
264-
return false;
265-
}
299+
if (!this->location || !this->original) {
300+
return false;
301+
}
302+
if (!this->isPatched) return true; // already restored
303+
#ifdef _WIN32
304+
for (size_t i = 0; i < this->size; ++i) {
305+
if (!WriteProcessMemory(GetCurrentProcess(), reinterpret_cast<LPVOID>(this->location + i), &this->original[i], 1, 0)) {
306+
return false;
266307
}
267-
return true;
268308
}
269-
return false;
270-
}
309+
#else
310+
// Should be already unprotected, but just in case
311+
Memory::UnProtect(reinterpret_cast<void *>(this->location), this->size);
312+
for (size_t i = 0; i < this->size; ++i) {
313+
*(uint8_t *)(this->location + i) = this->original[i];
314+
}
271315
#endif
316+
this->isPatched = false;
317+
return true;
318+
}
319+
320+
bool Memory::Patch::IsPatched() {
321+
return this->isPatched;
322+
}

src/Utils/Memory.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,25 @@ namespace Memory {
3333
uintptr_t Scan(const char *moduleName, const char *pattern, int offset = 0);
3434
std::vector<uintptr_t> MultiScan(const char *moduleName, const char *pattern, int offset = 0);
3535

36-
#ifdef _WIN32
3736
class Patch {
3837
private:
3938
uintptr_t location;
4039
unsigned char *original;
40+
unsigned char *patch;
4141
size_t size;
42+
bool isPatched;
4243

4344
public:
4445
~Patch();
46+
bool Execute();
4547
bool Execute(uintptr_t location, unsigned char *bytes, size_t size);
4648
template <size_t size>
4749
bool Execute(uintptr_t location, unsigned char (&bytes)[size]) {
4850
return Execute(location, bytes, size);
4951
}
5052
bool Restore();
53+
bool IsPatched();
5154
};
52-
#endif
5355

5456
struct Pattern {
5557
const char *signature;

0 commit comments

Comments
 (0)