Skip to content

Commit

Permalink
refactor: cleaning up various things
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisAMJ committed Oct 25, 2024
1 parent 8b30271 commit 68760ae
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
14 changes: 2 additions & 12 deletions src/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,16 @@ CON_COMMAND(sar_autoaim_point, "sar_autoaim_point <x> <y> <z> - 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<char **>(addr), "Cmd_Shutdown()")) {
Cmd_Shutdown = Memory::Read<_Cmd_Shutdown>(addr + TRACE_SHUTDOWN_OFFSET2);
Cmd_Shutdown = Memory::Read<_Cmd_Shutdown>(addr + Offsets::Cmd_ShutdownOff2);
break;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ const std::pair<size_t, EntField::Type> &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",
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Tas/TasTools/StrafeTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>((uintptr_t)this->cl->ThisPtr() + IServerMessageHandler_VMT_Offset);
auto IServerMessageHandler_VMT = Memory::Deref<uintptr_t>((uintptr_t)this->cl->ThisPtr() + Offsets::IServerMessageHandler);
auto ProcessTick = Memory::Deref<uintptr_t>(IServerMessageHandler_VMT + sizeof(uintptr_t) * Offsets::ProcessTick);
#else
auto ProcessTick = this->cl->Original(Offsets::ProcessTick);
Expand Down
4 changes: 0 additions & 4 deletions src/Modules/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/Offsets/Portal 2 8491.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 68760ae

Please sign in to comment.