Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
|sar_find_server_class|cmd|sar_find_server_class \<class_name> - finds specific server class tables and props with their offset|
|<i title="Portal Reloaded">sar_fix_reloaded_cheats</i>|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 \<id> - 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 \<fov> - forces player FOV|
Expand Down
37 changes: 37 additions & 0 deletions src/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
}
Expand All @@ -372,6 +383,9 @@ void Cheats::Shutdown() {

Variable::UnregisterAll();
Command::UnregisterAll();

g_floorReportalPatch->Restore();
SAFE_DELETE(g_floorReportalPatch);
}


Expand Down Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions src/Cheats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Modules/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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});

Expand Down
3 changes: 2 additions & 1 deletion src/Offsets/Portal 2 4554.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
OFFSET_WINDOWS(C_m_surfaceFriction, 5532) // found
2 changes: 2 additions & 0 deletions src/Offsets/Portal 2 9568.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Utils/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/Utils/Memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace Memory {
}
bool Restore();
bool IsPatched();
bool IsInit();
};

struct Pattern {
Expand Down