From 68760ae968a2b13b0ba1433ff755679df8998edd Mon Sep 17 00:00:00 2001 From: AMJ <69196954+ThisAMJ@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:41:12 +1100 Subject: [PATCH] refactor: cleaning up various things --- src/Cheats.cpp | 14 ++------------ src/Entity.cpp | 2 -- src/Features/Tas/TasTools/StrafeTool.cpp | 2 +- src/Modules/Engine.cpp | 2 +- src/Modules/Engine.hpp | 4 ---- src/Offsets/Portal 2 8491.hpp | 5 +++++ 6 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/Cheats.cpp b/src/Cheats.cpp index abb4218b1..cc1f50f0b 100644 --- a/src/Cheats.cpp +++ b/src/Cheats.cpp @@ -93,26 +93,16 @@ CON_COMMAND(sar_autoaim_point, "sar_autoaim_point - automatically ai engine->ExecuteCommand(Utils::ssprintf("setang %f %f\n", pitch, yaw).c_str()); } -// P2, INFRA and HL2 only -#ifdef _WIN32 -# define TRACE_SHUTDOWN_PATTERN "6A 00 68 ? ? ? ? E8 ? ? ? ? E8 ? ? ? ? " -# define TRACE_SHUTDOWN_OFFSET1 3 -# define TRACE_SHUTDOWN_OFFSET2 10 -#else -# define TRACE_SHUTDOWN_PATTERN "C7 44 24 04 00 00 00 00 C7 04 24 ? ? ? ? E8 ? ? ? ? E8 ? ? ? ? C7" -# define TRACE_SHUTDOWN_OFFSET1 11 -# define TRACE_SHUTDOWN_OFFSET2 10 -#endif CON_COMMAND(sar_delete_alias_cmds, "sar_delete_alias_cmds - deletes all alias commands\n") { using _Cmd_Shutdown = int (*)(); static _Cmd_Shutdown Cmd_Shutdown = nullptr; if (!Cmd_Shutdown) { - auto result = Memory::MultiScan(engine->Name(), TRACE_SHUTDOWN_PATTERN, TRACE_SHUTDOWN_OFFSET1); + auto result = Memory::MultiScan(engine->Name(), Offsets::Cmd_ShutdownSig, Offsets::Cmd_ShutdownOff); if (!result.empty()) { for (auto const &addr : result) { if (!std::strcmp(*reinterpret_cast(addr), "Cmd_Shutdown()")) { - Cmd_Shutdown = Memory::Read<_Cmd_Shutdown>(addr + TRACE_SHUTDOWN_OFFSET2); + Cmd_Shutdown = Memory::Read<_Cmd_Shutdown>(addr + Offsets::Cmd_ShutdownOff2); break; } } diff --git a/src/Entity.cpp b/src/Entity.cpp index 102936f94..60d1343d3 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -150,7 +150,6 @@ const std::pair &EntField::getClientOffset(void *ent, co return g_client_offsets[class_name][std::string(field)]; } -#define S(x) #x static const char *g_type_names[] = { "void", "bool", @@ -169,7 +168,6 @@ static const char *g_type_names[] = { "matrix3x4_t", "other", }; -#undef S void EntField::warnBadFieldType(void *ent, const char *field, const char *expect_type, Type actual_type, bool server) { if (actual_type == Type::NONE) { diff --git a/src/Features/Tas/TasTools/StrafeTool.cpp b/src/Features/Tas/TasTools/StrafeTool.cpp index 8c395bee1..bf43e2654 100644 --- a/src/Features/Tas/TasTools/StrafeTool.cpp +++ b/src/Features/Tas/TasTools/StrafeTool.cpp @@ -260,7 +260,7 @@ float AutoStrafeTool::GetMaxSpeed(const TasPlayerInfo &player, Vector wishDir, b if (sar.game->Is(SourceGame_INFRA)) { duckMultiplier = 1.0f; // idk man. 1/2 seems correct but this produces better results. } - float waterMultiplier = (player.waterLevel == 1) ? 0.75f : 1.0f; + float waterMultiplier = (player.waterLevel == WL_Feet) ? 0.75f : 1.0f; wishDir.y *= player.maxSpeed; wishDir.x *= player.maxSpeed; float maxSpeed = fminf(player.maxSpeed, wishDir.Length2D()) * duckMultiplier * waterMultiplier; diff --git a/src/Modules/Engine.cpp b/src/Modules/Engine.cpp index 284e52eba..930f03569 100644 --- a/src/Modules/Engine.cpp +++ b/src/Modules/Engine.cpp @@ -1026,7 +1026,7 @@ bool Engine::Init() { this->cl->Hook(Engine::SetSignonState_Hook, Engine::SetSignonState, Offsets::Disconnect - 1); this->cl->Hook(Engine::Disconnect_Hook, Engine::Disconnect, Offsets::Disconnect); #if _WIN32 - auto IServerMessageHandler_VMT = Memory::Deref((uintptr_t)this->cl->ThisPtr() + IServerMessageHandler_VMT_Offset); + auto IServerMessageHandler_VMT = Memory::Deref((uintptr_t)this->cl->ThisPtr() + Offsets::IServerMessageHandler); auto ProcessTick = Memory::Deref(IServerMessageHandler_VMT + sizeof(uintptr_t) * Offsets::ProcessTick); #else auto ProcessTick = this->cl->Original(Offsets::ProcessTick); diff --git a/src/Modules/Engine.hpp b/src/Modules/Engine.hpp index 2ae1a319a..e92087f3a 100644 --- a/src/Modules/Engine.hpp +++ b/src/Modules/Engine.hpp @@ -7,10 +7,6 @@ #include "Utils.hpp" #include "Variable.hpp" -#if _WIN32 -# define IServerMessageHandler_VMT_Offset 8 -#endif - class Engine : public Module { public: Interface *engineClient = nullptr; diff --git a/src/Offsets/Portal 2 8491.hpp b/src/Offsets/Portal 2 8491.hpp index 4b98d2318..592fcdb1e 100644 --- a/src/Offsets/Portal 2 8491.hpp +++ b/src/Offsets/Portal 2 8491.hpp @@ -144,6 +144,7 @@ OFFSET_DEFAULT(m_szFileName, 4, 4) // CClientState OFFSET_DEFAULT(ProcessTick, 1, 12) +OFFSET_DEFAULT(IServerMessageHandler, 8, -1) OFFSET_DEFAULT(Disconnect, 16, 37) OFFSET_DEFAULT(viewangles, 19040, 19012) @@ -439,6 +440,10 @@ SIGSCAN_DEFAULT(InsertCommand, "55 8B EC 56 57 8B 7D ? 8B F1 81 FF FF 01 00 00", "55 57 56 53 83 EC 1C 8B 6C 24 ? 8B 5C 24 ? 8B 74 24 ? 81 FD FE 01 00 00") // "WARNING: Command too long... ignoring!\n%s\n" SIGSCAN_DEFAULT(Convar_PrintDescription, "25 2D 38 30 73 20 2D 20 25 2E 38 30 73 0A 00", "25 2D 38 30 73 20 2D 20 25 2E 38 30 73 0A 00") // "%-80s - %.80s\n" +SIGSCAN_DEFAULT(Cmd_ShutdownSig, "6A 00 68 ? ? ? ? E8 ? ? ? ? E8 ? ? ? ?", + "C7 44 24 04 00 00 00 00 C7 04 24 ? ? ? ? E8 ? ? ? ? E8 ? ? ? ? C7") +OFFSET_DEFAULT(Cmd_ShutdownOff, 3, 11) +OFFSET_DEFAULT(Cmd_ShutdownOff2, 10, 10) // EngineDemoPlayer