Skip to content

Commit a001130

Browse files
KiIoOnlineThisAMJ
authored andcommitted
feat: autograb toggle support
Disables the autograb feature in coop. Host dependent patch. Linux is not supported currently.
1 parent 4efd216 commit a001130

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/Cheats.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Variable sar_disable_weapon_sway("sar_disable_weapon_sway", "0", 0, 1, "Disables
5252
Variable sar_disable_viewmodel_shadows("sar_disable_viewmodel_shadows", "0", 0, 1, "Disables the shadows on the viewmodel.\n");
5353
Variable sar_floor_reportals("sar_floor_reportals", "0", "Toggles floor reportals. Requires cheats.\n", FCVAR_CHEAT);
5454
Variable sar_loads_coop_dots("sar_loads_coop_dots", "0", "Toggles the loading screen dots during map transitions in coop.\n");
55+
Variable sar_patch_autograb("sar_patch_autograb", "0", 0, 1, "Patches the auto-grab in coop. Requires host to enable it for everyone that also enables it.\n");
5556

5657
Variable sv_laser_cube_autoaim;
5758
Variable ui_loadingscreen_transition_time;
@@ -323,6 +324,8 @@ CON_COMMAND_F(sar_challenge_autosubmit_reload_api_key, "sar_challenge_autosubmit
323324

324325
Memory::Patch *g_floorReportalPatch;
325326
Memory::Patch *g_coopLoadingDotsPatch;
327+
Memory::Patch *g_autoGrabPatchServer;
328+
Memory::Patch *g_autoGrabPatchClient;
326329

327330
void Cheats::Init() {
328331
sv_laser_cube_autoaim = Variable("sv_laser_cube_autoaim");
@@ -379,6 +382,18 @@ void Cheats::Init() {
379382
g_coopLoadingDotsPatch->Restore();
380383
}
381384

385+
g_autoGrabPatchServer = new Memory::Patch();
386+
g_autoGrabPatchClient = new Memory::Patch();
387+
auto autoGrabServerBranch = Memory::Scan(MODULE("server"), Offsets::CPortal_Player__PollForUseEntity_CheckMP);
388+
auto autoGrabClientBranch = Memory::Scan(MODULE("client"), Offsets::CPortal_Player__PollForUseEntity_CheckMP); // Note: Same signature as the server.
389+
if (autoGrabServerBranch && autoGrabClientBranch) {
390+
unsigned char autoGrabBranchByte = 0xEB;
391+
g_autoGrabPatchServer->Execute(autoGrabServerBranch, &autoGrabBranchByte, 1);
392+
g_autoGrabPatchServer->Restore();
393+
g_autoGrabPatchClient->Execute(autoGrabClientBranch, &autoGrabBranchByte, 1);
394+
g_autoGrabPatchClient->Restore();
395+
}
396+
382397
Variable::RegisterAll();
383398
Command::RegisterAll();
384399
}
@@ -398,6 +413,10 @@ void Cheats::Shutdown() {
398413
SAFE_DELETE(g_floorReportalPatch);
399414
g_coopLoadingDotsPatch->Restore();
400415
SAFE_DELETE(g_coopLoadingDotsPatch);
416+
g_autoGrabPatchServer->Restore();
417+
SAFE_DELETE(g_autoGrabPatchServer);
418+
g_autoGrabPatchClient->Restore();
419+
SAFE_DELETE(g_autoGrabPatchClient);
401420
}
402421

403422

@@ -534,3 +553,34 @@ void Cheats::CheckUICoopDots() {
534553
g_coopLoadingDotsPatch->Restore();
535554
}
536555
}
556+
557+
void Cheats::CheckAutoGrab() {
558+
bool enabled = sar_patch_autograb.GetBool();
559+
if (enabled && (!g_autoGrabPatchServer || !g_autoGrabPatchServer->IsInit())) {
560+
console->Print("sar_patch_autograb is not available (Server).\n");
561+
sar_patch_autograb.SetValue(0);
562+
return;
563+
}
564+
if (enabled && (!g_autoGrabPatchClient || !g_autoGrabPatchClient->IsInit())) {
565+
console->Print("sar_patch_autograb is not available (Client).\n");
566+
sar_patch_autograb.SetValue(0);
567+
return;
568+
}
569+
if (!sv_cheats.GetBool() && enabled) {
570+
console->Print("sar_patch_autograb requires sv_cheats 1.\n");
571+
sar_patch_autograb.SetValue(0);
572+
enabled = false;
573+
}
574+
575+
if (enabled == g_autoGrabPatchServer->IsPatched() && enabled == g_autoGrabPatchClient->IsPatched()) {
576+
return;
577+
}
578+
579+
if (enabled) {
580+
g_autoGrabPatchServer->Execute();
581+
g_autoGrabPatchClient->Execute();
582+
} else {
583+
g_autoGrabPatchServer->Restore();
584+
g_autoGrabPatchClient->Restore();
585+
}
586+
}

src/Cheats.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Cheats {
1212
static void EnsureSlopeBoost(const CHLMoveData *move, void *player, CGameTrace **tr);
1313
static void CheckFloorReportals();
1414
static void CheckUICoopDots();
15+
static void CheckAutoGrab();
1516
};
1617

1718
extern Variable sar_autorecord;
@@ -35,6 +36,7 @@ extern Variable sar_disable_weapon_sway;
3536
extern Variable sar_disable_viewmodel_shadows;
3637
extern Variable sar_floor_reportals;
3738
extern Variable sar_loads_coop_dots;
39+
extern Variable sar_patch_autograb;
3840

3941
extern Variable sv_laser_cube_autoaim;
4042
extern Variable ui_loadingscreen_transition_time;

src/Modules/Server.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ DETOUR(Server::PlayerRunCommand, CUserCmd *cmd, void *moveHelper) {
286286
Cheats::AutoStrafe(slot, thisptr, cmd);
287287
Cheats::CheckFloorReportals();
288288
Cheats::CheckUICoopDots();
289+
Cheats::CheckAutoGrab();
289290

290291
inputHud.SetInputInfo(slot, cmd->buttons, {cmd->sidemove, cmd->forwardmove, cmd->upmove});
291292

src/Offsets/Portal 2 9568.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ OFFSET_DEFAULT(aircontrol_fling_speedOff, 3, 3)
512512
SIGSCAN_DEFAULT(FloorReportalBranch, "75 7D 8B 8E C0 04 00 00",
513513
"75 ? 8B 85 ? ? ? ? 8B 0D") // "Portal.open_red" xref(nothing after if) -> CProp_Portal::NewLocation -> first function call CPortal_Base2D::NewLocation -> 4x func call followed by test, [jnz]
514514

515+
// TODO: Linux Support
516+
SIGSCAN_DEFAULT(CPortal_Player__PollForUseEntity_CheckMP, "74 ? ? ? 8B 82 ? ? ? ? FF D0 84 C0 74 ? 8B CE",
517+
"") // CPortal_Player vtable -> Add offset 0x6D8 -> CPortal_Player::PlayerUse -> Second function call from disassembly -> CPortal_Player::PollForUseEntity -> jz instruction
515518

516519
// VPhysics
517520
OFFSET_EMPTY(DestroyEnvironment)

0 commit comments

Comments
 (0)