Skip to content

Commit 17c66ac

Browse files
committed
fix: Linux crash on latest Portal 2 update
Well this was an adventure! We uncovered an actual bug in Memory::Scan, as well as a whole bunch of other bullshit. Did you know that m_szLevelName isn't *actually* m_szLevelName? NeKZ got some RE wrong, it's actually sv.GetMapName()! It's true!
1 parent 2dbd06a commit 17c66ac

16 files changed

+158
-258
lines changed

src/Features/Renderer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,16 +1138,15 @@ void Renderer::Init(void **videomode) {
11381138
g_movieInfo = *(MovieInfo_t **)((uintptr_t)SND_RecordBuffer + 5);
11391139
#else
11401140
if (sar.game->Is(SourceGame_Portal2)) {
1141-
SND_RecordBuffer = (void (*)())Memory::Scan(engine->Name(), "55 89 E5 57 56 53 E8 ? ? ? ? 81 C3 D5 1D 76 00 83 EC 3C 89 5D D0");
1141+
SND_RecordBuffer = (void (*)())Memory::Scan(engine->Name(), "80 3D ? ? ? ? 00 75 07 C3 ? ? ? ? ? ? 55 89 E5 57 56 53 83 EC 1C E8 ? ? ? ? 84 C0 0F 85 ? ? ? ?");
11421142
} else if (sar.game->Is(SourceGame_PortalReloaded) || sar.game->Is(SourceGame_PortalStoriesMel)) {
11431143
SND_RecordBuffer = (void (*)())Memory::Scan(engine->Name(), "55 89 E5 57 56 53 83 EC 3C 65 A1 ? ? ? ? 89 45 E4 31 C0 E8 ? ? ? ? 84 C0 75 1B");
11441144
} else { // Pre-update engine
11451145
SND_RecordBuffer = (void (*)())Memory::Scan(engine->Name(), "55 89 E5 57 56 53 83 EC 2C E8 ? ? ? ? 84 C0 75 0E 8D 65 F4 5B 5E 5F 5D C3");
11461146
}
11471147

11481148
if (sar.game->Is(SourceGame_Portal2)) {
1149-
uintptr_t SND_IsRecording = Memory::Read((uintptr_t)SND_RecordBuffer + 35);
1150-
g_movieInfo = (MovieInfo_t *)(SND_IsRecording + 6 + *(uint32_t *)(SND_IsRecording + 8) + *(uint32_t *)(SND_IsRecording + 17));
1149+
g_movieInfo = *(MovieInfo_t **)((uintptr_t)SND_RecordBuffer + 2);
11511150
} else if (sar.game->Is(SourceGame_PortalReloaded) || sar.game->Is(SourceGame_PortalStoriesMel)) {
11521151
uintptr_t SND_IsRecording = Memory::Read((uintptr_t)SND_RecordBuffer + 21);
11531152
g_movieInfo = *(MovieInfo_t **)(SND_IsRecording + 2);

src/Games/ApertureTag.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,10 @@ void ApertureTag::LoadOffsets() {
5050
// client.so
5151
m_pCommands = 228; // CInput::DecodeUserCmdFromBuffer
5252

53-
// Transferred from old Portal2 - should be removed if and when game
54-
// upgrades to new-style PIC engine
55-
GetClientStateFunction = 11; // CEngineClient::ClientCmd
56-
GetLocalClient = 92; // CEngineClient::SetViewAngles
57-
HostState_OnClientConnected = 1523; // CClientState::SetSignonState
58-
FireEventIntern = 36; // CGameEventManager::FireEventClientSide
59-
ConPrintEvent = 254; // CGameEventManager::FireEventIntern
60-
AutoCompletionFunc = 37; // listdemo_CompletionFunc
61-
Key_SetBinding = 60; // unbind
62-
VideoMode_Create = 104; // CEngineAPI::Init
63-
AirMove_Offset1 = 14; // CPortalGameMovement::~CPortalGameMovement
64-
UTIL_PlayerByIndex = 61; // CServerGameDLL::Think
65-
GetClientMode = 11; // CHLClient::HudProcessInput
66-
GetHud = 104; // cc_leaderboard_enable
67-
FindElement = 120; // cc_leaderboard_enable
68-
KeyDown = 295; // CInput::JoyStickApplyMovement
69-
KeyUp = 341; // CInput::JoyStickApplyMovement
70-
StartDrawing = 692; // CMatSystemSurface::PaintTraverseEx
71-
FinishDrawing = 627; // CMatSystemSurface::PaintTraverseEx
72-
OnGameOverlayActivated = 152; // CSteam3Client
73-
FontManager = 11; // GetFontName
53+
#define OFFSET_DEFAULT(name, win, linux)
54+
#define OFFSET_EMPTY(name)
55+
#define OFFSET_LINMOD(name, off) name = off;
56+
#include "OffsetsData.hpp"
7457
#endif
7558
}
7659
const char *ApertureTag::Version() {

src/Games/Portal2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#endif
1111

1212
#define OFFSET_EMPTY(name)
13+
#define OFFSET_LINMOD(name, off)
1314

1415
Portal2::Portal2() {
1516
this->version = SourceGame_Portal2;

src/Games/PortalReloaded.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,10 @@ void PortalReloaded::LoadOffsets() {
2929
// engine.dll
3030
OnGameOverlayActivated = 144; // CSteam3Client
3131
#else
32-
// Transferred from old Portal2 - should be removed if and when game
33-
// upgrades to new-style PIC engine
34-
GetClientStateFunction = 11; // CEngineClient::ClientCmd
35-
GetLocalClient = 92; // CEngineClient::SetViewAngles
36-
HostState_OnClientConnected = 1523; // CClientState::SetSignonState
37-
FireEventIntern = 36; // CGameEventManager::FireEventClientSide
38-
ConPrintEvent = 254; // CGameEventManager::FireEventIntern
39-
AutoCompletionFunc = 37; // listdemo_CompletionFunc
40-
Key_SetBinding = 60; // unbind
41-
VideoMode_Create = 104; // CEngineAPI::Init
42-
AirMove_Offset1 = 14; // CPortalGameMovement::~CPortalGameMovement
43-
UTIL_PlayerByIndex = 61; // CServerGameDLL::Think
44-
GetClientMode = 11; // CHLClient::HudProcessInput
45-
GetHud = 104; // cc_leaderboard_enable
46-
FindElement = 120; // cc_leaderboard_enable
47-
KeyDown = 295; // CInput::JoyStickApplyMovement
48-
KeyUp = 341; // CInput::JoyStickApplyMovement
49-
StartDrawing = 692; // CMatSystemSurface::PaintTraverseEx
50-
FinishDrawing = 627; // CMatSystemSurface::PaintTraverseEx
51-
OnGameOverlayActivated = 152; // CSteam3Client
52-
FontManager = 11; // GetFontName
32+
#define OFFSET_DEFAULT(name, win, linux)
33+
#define OFFSET_EMPTY(name)
34+
#define OFFSET_LINMOD(name, off) name = off;
35+
#include "OffsetsData.hpp"
5336
#endif
5437
}
5538
const char *PortalReloaded::Version() {

src/Games/PortalStoriesMel.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,10 @@ void PortalStoriesMel::LoadOffsets() {
7070
// engine.dll
7171
OnGameOverlayActivated = 144; // CSteam3Client
7272
#else
73-
// Transferred from old Portal2 - should be removed if and when game
74-
// upgrades to new-style PIC engine
75-
GetClientStateFunction = 11; // CEngineClient::ClientCmd
76-
GetLocalClient = 92; // CEngineClient::SetViewAngles
77-
HostState_OnClientConnected = 1523; // CClientState::SetSignonState
78-
FireEventIntern = 36; // CGameEventManager::FireEventClientSide
79-
ConPrintEvent = 254; // CGameEventManager::FireEventIntern
80-
AutoCompletionFunc = 37; // listdemo_CompletionFunc
81-
Key_SetBinding = 60; // unbind
82-
VideoMode_Create = 104; // CEngineAPI::Init
83-
AirMove_Offset1 = 14; // CPortalGameMovement::~CPortalGameMovement
84-
UTIL_PlayerByIndex = 61; // CServerGameDLL::Think
85-
GetClientMode = 11; // CHLClient::HudProcessInput
86-
GetHud = 104; // cc_leaderboard_enable
87-
FindElement = 120; // cc_leaderboard_enable
88-
KeyDown = 295; // CInput::JoyStickApplyMovement
89-
KeyUp = 341; // CInput::JoyStickApplyMovement
90-
StartDrawing = 692; // CMatSystemSurface::PaintTraverseEx
91-
FinishDrawing = 627; // CMatSystemSurface::PaintTraverseEx
92-
OnGameOverlayActivated = 152; // CSteam3Client
93-
FontManager = 11; // GetFontName
73+
#define OFFSET_DEFAULT(name, win, linux)
74+
#define OFFSET_EMPTY(name)
75+
#define OFFSET_LINMOD(name, off) name = off;
76+
#include "OffsetsData.hpp"
9477
#endif
9578
}
9679
const char *PortalStoriesMel::Version() {

src/Games/ThinkingWithTimeMachine.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,10 @@ void ThinkingWithTimeMachine::LoadOffsets() {
1818
// client.so
1919
m_pCommands = 228; // CInput::DecodeUserCmdFromBuffer
2020

21-
// Transferred from old Portal2 - should be removed if and when game
22-
// upgrades to new-style PIC engine
23-
GetClientStateFunction = 11; // CEngineClient::ClientCmd
24-
GetLocalClient = 92; // CEngineClient::SetViewAngles
25-
HostState_OnClientConnected = 1523; // CClientState::SetSignonState
26-
FireEventIntern = 36; // CGameEventManager::FireEventClientSide
27-
ConPrintEvent = 254; // CGameEventManager::FireEventIntern
28-
AutoCompletionFunc = 37; // listdemo_CompletionFunc
29-
Key_SetBinding = 60; // unbind
30-
VideoMode_Create = 104; // CEngineAPI::Init
31-
AirMove_Offset1 = 14; // CPortalGameMovement::~CPortalGameMovement
32-
UTIL_PlayerByIndex = 61; // CServerGameDLL::Think
33-
GetClientMode = 11; // CHLClient::HudProcessInput
34-
GetHud = 104; // cc_leaderboard_enable
35-
FindElement = 120; // cc_leaderboard_enable
36-
KeyDown = 295; // CInput::JoyStickApplyMovement
37-
KeyUp = 341; // CInput::JoyStickApplyMovement
38-
StartDrawing = 692; // CMatSystemSurface::PaintTraverseEx
39-
FinishDrawing = 627; // CMatSystemSurface::PaintTraverseEx
40-
OnGameOverlayActivated = 152; // CSteam3Client
41-
FontManager = 11; // GetFontName
21+
#define OFFSET_DEFAULT(name, win, linux)
22+
#define OFFSET_EMPTY(name)
23+
#define OFFSET_LINMOD(name, off) name = off;
24+
#include "OffsetsData.hpp"
4225
#endif
4326
}
4427
const char *ThinkingWithTimeMachine::Version() {

src/Modules/Client.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -544,23 +544,13 @@ bool Client::Init() {
544544
this->IN_DeactivateMouse = this->g_ClientDLL->Original<_IN_DeactivateMouse>(Offsets::IN_DeactivateMouse, readJmp);
545545

546546
auto IN_ActivateMouse = this->g_ClientDLL->Original(Offsets::IN_ActivateMouse, readJmp);
547-
void *g_InputAddr;
548-
#ifndef _WIN32
549-
if (sar.game->Is(SourceGame_EIPRelPIC)) {
550-
g_InputAddr = *(void **)(IN_ActivateMouse + 5 + *(uint32_t *)(IN_ActivateMouse + 6) + *(uint32_t *)(IN_ActivateMouse + 12));
551-
} else
552-
#endif
553-
g_InputAddr = Memory::DerefDeref<void *>(IN_ActivateMouse + Offsets::g_Input);
547+
void *g_InputAddr = Memory::DerefDeref<void *>(IN_ActivateMouse + Offsets::g_Input);
554548

555549
if (g_Input = Interface::Create(g_InputAddr)) {
556550
g_Input->Hook(Client::DecodeUserCmdFromBuffer_Hook, Client::DecodeUserCmdFromBuffer, Offsets::DecodeUserCmdFromBuffer);
557551
g_Input->Hook(Client::GetButtonBits_Hook, Client::GetButtonBits, Offsets::GetButtonBits);
558552
g_Input->Hook(Client::SteamControllerMove_Hook, Client::SteamControllerMove, Offsets::SteamControllerMove);
559553

560-
auto JoyStickApplyMovement = g_Input->Original(Offsets::JoyStickApplyMovement, readJmp);
561-
Memory::Read(JoyStickApplyMovement + Offsets::KeyDown, &this->KeyDown);
562-
Memory::Read(JoyStickApplyMovement + Offsets::KeyUp, &this->KeyUp);
563-
564554
in_forceuser = Variable("in_forceuser");
565555
if (!!in_forceuser && this->g_Input) {
566556
this->g_Input->Hook(CInput_CreateMove_Hook, CInput_CreateMove, Offsets::GetButtonBits + 1);
@@ -571,13 +561,7 @@ bool Client::Init() {
571561

572562
auto HudProcessInput = this->g_ClientDLL->Original(Offsets::HudProcessInput, readJmp);
573563
auto GetClientMode = Memory::Read<uintptr_t>(HudProcessInput + Offsets::GetClientMode);
574-
uintptr_t g_pClientMode;
575-
#ifndef _WIN32
576-
if (sar.game->Is(SourceGame_EIPRelPIC)) {
577-
g_pClientMode = GetClientMode + 6 + *(uint32_t *)(GetClientMode + 8) + *(uint32_t *)(GetClientMode + 35);
578-
} else
579-
#endif
580-
g_pClientMode = Memory::Deref<uintptr_t>(GetClientMode + Offsets::g_pClientMode);
564+
uintptr_t g_pClientMode = Memory::Deref<uintptr_t>(GetClientMode + Offsets::g_pClientMode);
581565
void *clientMode = Memory::Deref<void *>(g_pClientMode);
582566
void *clientMode2 = Memory::Deref<void *>(g_pClientMode + sizeof(void *));
583567

@@ -602,8 +586,8 @@ bool Client::Init() {
602586
Client::DrawOpaqueRenderables = (decltype(Client::DrawOpaqueRenderables))Memory::Scan(client->Name(), "55 8B EC 83 EC 54 83 7D 0C 00 A1 ? ? ? ? 53 56 0F 9F 45 EC 83 78 30 00 57 8B F1 0F 84 BA 03 00 00");
603587
#else
604588
if (sar.game->Is(SourceGame_EIPRelPIC)) {
605-
Client::DrawTranslucentRenderables = (decltype(Client::DrawTranslucentRenderables))Memory::Scan(client->Name(), "55 89 E5 57 E8 ? ? ? ? 81 C7 ? ? ? ? 56 53 81 EC 18 01 00 00 8B 45 08 8B 5D 0C 89 45 98 8B 45 10");
606-
Client::DrawOpaqueRenderables = (decltype(Client::DrawOpaqueRenderables))Memory::Scan(client->Name(), "E8 ? ? ? ? 05 ? ? ? ? 55 89 E5 57 56 53 81 EC 8C 00 00 00 8B 7D 0C 8B 75 08 89 45 A0 8B 80 00 FB FF FF");
589+
Client::DrawTranslucentRenderables = (decltype(Client::DrawTranslucentRenderables))Memory::Scan(client->Name(), "55 89 E5 57 56 53 81 EC B8 00 00 00 8B 45 10 8B 5D 0C 89 85 60 FF FF FF 88 45 A7 A1 ? ? ? ?");
590+
Client::DrawOpaqueRenderables = (decltype(Client::DrawOpaqueRenderables))Memory::Scan(client->Name(), "55 89 E5 57 56 53 83 EC 7C A1 ? ? ? ? 8B 5D 08 89 45 90 85 C0 0F 85 34 04 00 00 A1 ? ? ? ? 8B 40 30 85 C0");
607591
} else {
608592
Client::DrawTranslucentRenderables = (decltype(Client::DrawTranslucentRenderables))Memory::Scan(client->Name(), "55 89 E5 57 56 53 81 EC DC 00 00 00 8B 45 08 8B 5D 0C 89 C7 89 45 84 8B 45 10 89 85 4C FF FF FF");
609593
Client::DrawOpaqueRenderables = (decltype(Client::DrawOpaqueRenderables))Memory::Scan(client->Name(), "55 89 E5 57 56 53 81 EC 8C 00 00 00 8B 45 0C 8B 5D 08 89 45 8C 8B 45 14 89 45 90 65 A1 14 00 00 00");
@@ -617,7 +601,7 @@ bool Client::Init() {
617601
#ifdef _WIN32
618602
Client::CalcViewModelLag = (decltype(Client::CalcViewModelLag))Memory::Scan(client->Name(), "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 83 EC 1C 56 6A 00 6A 00 8D 45 F4 8B F1 8B 4B 0C 50 51 E8 ? ? ? ?");
619603
#else
620-
Client::CalcViewModelLag = (decltype(Client::CalcViewModelLag))Memory::Scan(client->Name(), "57 56 53 E8 ? ? ? ? 81 C3 ? ? ? ? 83 EC 20 8B 7C 24 30 8B 74 24 34");
604+
Client::CalcViewModelLag = (decltype(Client::CalcViewModelLag))Memory::Scan(client->Name(), "56 53 83 EC 24 8B 74 24 30 8B 5C 24 34 6A 00 6A 00 8D 44 24 1C 50 FF 74 24 44 E8 ? ? ? ? A1 ? ? ? ? 83 C4 10 66 0F EF C9");
621605
#endif
622606
}
623607

@@ -631,8 +615,8 @@ bool Client::Init() {
631615
this->gamerules = *(void ***)(cbk + 2);
632616
#else
633617
if (sar.game->Is(SourceGame_EIPRelPIC)) {
634-
cbk = cbk + 10 + *(int8_t *)(cbk + 9); // openradialmenu -> OpenRadialMenuCommand
635-
this->gamerules = (void **)(cbk + 5 + *(uint32_t *)(cbk + 6) + *(uint32_t *)(cbk + 20));
618+
cbk = (uintptr_t)Memory::Read(cbk + 9); // openradialmenu -> OpenRadialMenuCommand
619+
this->gamerules = *(void ***)(cbk + 1);
636620
} else {
637621
cbk = (uintptr_t)Memory::Read(cbk + 12); // openradialmenu -> OpenRadialMenuCommand
638622
this->gamerules = *(void ***)(cbk + 9);

src/Modules/Client.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class Client : public Module {
3636
DECL_M(GetPlayerState, CPlayerState);
3737

3838
using _GetClientEntity = ClientEnt *(__rescall *)(void *thisptr, int entnum);
39-
using _KeyDown = int(__cdecl *)(void *b, const char *c);
40-
using _KeyUp = int(__cdecl *)(void *b, const char *c);
4139
using _GetAllClasses = ClientClass *(*)();
4240
using _FrameStageNotify = void(__rescall *)(void *thisptr, int stage);
4341
using _ShouldDraw = bool(__rescall *)(void *thisptr);
@@ -47,8 +45,6 @@ class Client : public Module {
4745
using _IN_DeactivateMouse = void (*)(void *thisptr);
4846

4947
_GetClientEntity GetClientEntity = nullptr;
50-
_KeyDown KeyDown = nullptr;
51-
_KeyUp KeyUp = nullptr;
5248
_GetAllClasses GetAllClasses = nullptr;
5349
_FrameStageNotify FrameStageNotify = nullptr;
5450
_ShouldDraw ShouldDraw = nullptr;

0 commit comments

Comments
 (0)