diff --git a/docs/cvars.md b/docs/cvars.md index 569acbb3..9e4e4cd9 100644 --- a/docs/cvars.md +++ b/docs/cvars.md @@ -219,6 +219,7 @@ |sar_find_server_class|cmd|sar_find_server_class \ - finds specific server class tables and props with their offset| |sar_fix_reloaded_cheats|1|Overrides map execution of specific console commands in Reloaded in order to separate map usage from player usage for these commands.| |sar_fix_viewmodel_bug|0|Fixes the viewmodel seemingly randomly disappearing.| +|sar_floor_reportals|0|Toggles floor reportals. Requires cheats.| |sar_font_get_name|cmd|sar_font_get_name \ - gets the name of a font from its index| |sar_font_list|cmd|sar_font_list - lists all available fonts| |sar_force_fov|cmd|sar_force_fov \ - forces player FOV| diff --git a/src/Cheats.cpp b/src/Cheats.cpp index d134a7ff..85a5fb86 100644 --- a/src/Cheats.cpp +++ b/src/Cheats.cpp @@ -50,6 +50,7 @@ Variable sar_patch_cfg("sar_patch_cfg", "0", 0, 1, "Patches Crouch Flying Glitch Variable sar_prevent_ehm("sar_prevent_ehm", "0", 0, 1, "Prevents Entity Handle Misinterpretation (EHM) from happening.\n"); Variable sar_disable_weapon_sway("sar_disable_weapon_sway", "0", 0, 1, "Disables the viewmodel lagging behind.\n"); Variable sar_disable_viewmodel_shadows("sar_disable_viewmodel_shadows", "0", 0, 1, "Disables the shadows on the viewmodel.\n"); +Variable sar_floor_reportals("sar_floor_reportals", "0", "Toggles floor reportals. Requires cheats.\n", FCVAR_CHEAT); Variable sv_laser_cube_autoaim; Variable ui_loadingscreen_transition_time; @@ -319,6 +320,8 @@ CON_COMMAND_F(sar_challenge_autosubmit_reload_api_key, "sar_challenge_autosubmit AutoSubmit::LoadApiKey(true); } +Memory::Patch *g_floorReportalPatch; + void Cheats::Init() { sv_laser_cube_autoaim = Variable("sv_laser_cube_autoaim"); ui_loadingscreen_transition_time = Variable("ui_loadingscreen_transition_time"); @@ -358,6 +361,14 @@ void Cheats::Init() { Variable("upgrade_portalgun").RemoveFlag(FCVAR_CHEAT); } + g_floorReportalPatch = new Memory::Patch(); + auto floorReportalBranch = Memory::Scan(MODULE("server"), Offsets::FloorReportalBranch); + if (floorReportalBranch) { + unsigned char floorReportalBranchByte = 0x70; + g_floorReportalPatch->Execute(floorReportalBranch, &floorReportalBranchByte, 1); + g_floorReportalPatch->Restore(); + } + Variable::RegisterAll(); Command::RegisterAll(); } @@ -372,6 +383,9 @@ void Cheats::Shutdown() { Variable::UnregisterAll(); Command::UnregisterAll(); + + g_floorReportalPatch->Restore(); + SAFE_DELETE(g_floorReportalPatch); } @@ -467,3 +481,26 @@ void Cheats::EnsureSlopeBoost(const CHLMoveData *move, void *player, CGameTrace } } + +void Cheats::CheckFloorReportals() { + bool enabled = sar_floor_reportals.GetBool(); + if (enabled && (!g_floorReportalPatch || !g_floorReportalPatch->IsInit())) { + console->Print("sar_floor_reportals is not available.\n"); + sar_floor_reportals.SetValue(0); + return; + } + if (!sv_cheats.GetBool() && enabled) { + console->Print("sar_floor_reportals requires sv_cheats 1.\n"); + sar_floor_reportals.SetValue(0); + enabled = false; + } + if (enabled == g_floorReportalPatch->IsPatched()) { + return; + } + + if (enabled) { + g_floorReportalPatch->Execute(); + } else { + g_floorReportalPatch->Restore(); + } +} diff --git a/src/Cheats.hpp b/src/Cheats.hpp index 75d03e85..23b40355 100644 --- a/src/Cheats.hpp +++ b/src/Cheats.hpp @@ -10,6 +10,7 @@ class Cheats { static void PatchBhop(int slot, void *player, CUserCmd *cmd); static void AutoStrafe(int slot, void *player, CUserCmd *cmd); static void EnsureSlopeBoost(const CHLMoveData *move, void *player, CGameTrace **tr); + static void CheckFloorReportals(); }; extern Variable sar_autorecord; diff --git a/src/Modules/Server.cpp b/src/Modules/Server.cpp index 58d4d119..aef67ce3 100644 --- a/src/Modules/Server.cpp +++ b/src/Modules/Server.cpp @@ -284,6 +284,7 @@ DETOUR(Server::PlayerRunCommand, CUserCmd *cmd, void *moveHelper) { } Cheats::AutoStrafe(slot, thisptr, cmd); + Cheats::CheckFloorReportals(); inputHud.SetInputInfo(slot, cmd->buttons, {cmd->sidemove, cmd->forwardmove, cmd->upmove}); diff --git a/src/Offsets/Portal 2 4554.hpp b/src/Offsets/Portal 2 4554.hpp index a5c74f01..0b6751a9 100644 --- a/src/Offsets/Portal 2 4554.hpp +++ b/src/Offsets/Portal 2 4554.hpp @@ -79,6 +79,7 @@ OFFSET_WINDOWS(PrecacheModel, 62) // Server SIGSCAN_WINDOWS(ViewPunch, "55 8B EC A1 ? ? ? ? 83 EC 0C 83 78 ? 00 56 8B F1") // this works for 9568 too, maybe shorten that pattern/adjust to match this? +SIGSCAN_EMPTY(FloorReportalBranch) // CBasePlayer OFFSET_WINDOWS(m_pShadowStand, 3156) // found @@ -130,4 +131,4 @@ OFFSET_WINDOWS(m_pCommands, 224) // found // check/refind these OFFSET_WINDOWS(m_pSurfaceData, 4088) // found but unsure OFFSET_WINDOWS(S_m_surfaceFriction, 4092) // found -OFFSET_WINDOWS(C_m_surfaceFriction, 5532) // found \ No newline at end of file +OFFSET_WINDOWS(C_m_surfaceFriction, 5532) // found diff --git a/src/Offsets/Portal 2 9568.hpp b/src/Offsets/Portal 2 9568.hpp index 1658067d..94a163be 100644 --- a/src/Offsets/Portal 2 9568.hpp +++ b/src/Offsets/Portal 2 9568.hpp @@ -507,6 +507,8 @@ SIGSCAN_DEFAULT(CreateViewModel, "E8 ? ? ? ? 5F 5D C2 04 00 53", SIGSCAN_DEFAULT(aircontrol_fling_speedSig, "0F 2F 25 ? ? ? ? F3 0F 11 45", "0F 2F 05 ? ? ? ? 0F 86 ? ? ? ? 0F 2F D1") // "%s: Make in time? %s velocity %f wish %f\n" -> CPortalGameMovement::AirPortalFunnel -> xref CPortalGameMovement::PortalFunnel -> xref(has 90000) CPortalGameMovement::AirMove, [U]COMISS XMM dword ptr OFFSET_DEFAULT(aircontrol_fling_speedOff, 3, 3) +SIGSCAN_DEFAULT(FloorReportalBranch, "75 7D 8B 8E C0 04 00 00", + "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] // Steam API diff --git a/src/Utils/Memory.cpp b/src/Utils/Memory.cpp index 0e720cd1..8c883161 100644 --- a/src/Utils/Memory.cpp +++ b/src/Utils/Memory.cpp @@ -318,3 +318,7 @@ bool Memory::Patch::Restore() { bool Memory::Patch::IsPatched() { return this->isPatched; } + +bool Memory::Patch::IsInit() { + return this->original != nullptr && this->patch != nullptr; +} diff --git a/src/Utils/Memory.hpp b/src/Utils/Memory.hpp index b4c48471..f300575b 100644 --- a/src/Utils/Memory.hpp +++ b/src/Utils/Memory.hpp @@ -51,6 +51,7 @@ namespace Memory { } bool Restore(); bool IsPatched(); + bool IsInit(); }; struct Pattern {