Skip to content

Commit 6c3bd69

Browse files
committed
Switch to C++23 in game_sa
1 parent 6f4bc9c commit 6c3bd69

22 files changed

+362
-277
lines changed

Client/game_sa/CAudioEngineSA.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -413,31 +413,29 @@ void CAudioEngineSA::UpdateAmbientSoundSettings()
413413
MemPut<BYTE>(0x507814, 0x33); // No gunfire
414414
}
415415

416-
__declspec(noinline) bool _cdecl IsAmbientSoundGeneralEnabled()
416+
static bool IsAmbientSoundGeneralEnabled()
417417
{
418-
if (pGame)
419-
{
420-
return pGame->GetAudioEngine()->IsAmbientSoundEnabled(AMBIENT_SOUND_GENERAL);
421-
}
422-
return false;
418+
return pGame && pGame->GetAudioEngine()->IsAmbientSoundEnabled(AMBIENT_SOUND_GENERAL);
423419
}
424420

425421
// Hook for manual ambient sound pause
426-
void __declspec(naked) HOOK_CAEAmbienceTrackManager_CheckForPause()
422+
static void __declspec(naked) HOOK_CAEAmbienceTrackManager_CheckForPause()
427423
{
424+
MTA_VERIFY_HOOK_LOCAL_SIZE;
425+
428426
__asm
429427
{
430-
// Hooked from 004D6E21 6 bytes
431-
call IsAmbientSoundGeneralEnabled
432-
test al, al
433-
jnz skip
434-
mov dword ptr [esp+08h], 0 // Pause
435-
skip:
436-
437-
// orig
438-
mov edi, [esp+08h]
428+
push esi
429+
call IsAmbientSoundGeneralEnabled
430+
test al, al
431+
jnz continueWithOriginalCode
432+
mov dword ptr [esp+8], 0 // Pause by setting 0.0f for the last argument to CAEAudioHardware::SetChannelFrequencyScalingFactor
433+
434+
continueWithOriginalCode:
435+
pop esi
436+
mov edi, [esp+8]
439437
xor ecx, ecx
440-
jmp RETURN_CAEAmbienceTrackManager_CheckForPause // 4D6E27
438+
jmp RETURN_CAEAmbienceTrackManager_CheckForPause
441439
}
442440
}
443441

@@ -506,33 +504,34 @@ bool CAudioEngineSA::OnWorldSound(CAESound* pAESound)
506504

507505
////////////////////////////////////////////////////////////////////////////////////////////////
508506
// Return false to skip sound
509-
__declspec(noinline) bool _cdecl On_CAESoundManager_RequestNewSound(CAESound* pAESound)
507+
static bool _cdecl OnRequestNewSound(CAESound* pAESound)
510508
{
511509
return g_pAudioSA->OnWorldSound(pAESound);
512510
}
513511

514-
void __declspec(naked) HOOK_CAESoundManager_RequestNewSound()
512+
static void __declspec(naked) HOOK_CAESoundManager_RequestNewSound()
515513
{
514+
MTA_VERIFY_HOOK_LOCAL_SIZE;
515+
516516
__asm
517517
{
518518
pushad
519519
push [esp+32+4*1]
520-
call On_CAESoundManager_RequestNewSound
521-
add esp, 4*1
522-
cmp al, 0
523-
jz skip
520+
call OnRequestNewSound
521+
add esp, 4
522+
test al, al
524523
popad
524+
jnz continueWithOriginalCode
525525

526-
// Continue with standard code
526+
// Skip playing sound
527+
xor eax, eax
528+
retn 4
529+
530+
continueWithOriginalCode:
527531
push esi
528532
push edi
529533
xor esi, esi
530534
jmp RETURN_CAESoundManager_RequestNewSound
531-
532-
skip: // Skip playing sound
533-
popad
534-
xor eax, eax
535-
retn 4
536535
}
537536
}
538537

Client/game_sa/CCameraSA.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void CCameraSA::GetCameraClip(bool& bObjects, bool& bVehicles)
487487
bVehicles = bCameraClipVehicles;
488488
}
489489

490-
__declspec(noinline) void _cdecl DoCameraCollisionDetectionPokes()
490+
static void _cdecl DoCameraCollisionDetectionPokes()
491491
{
492492
if (!bCameraClipObjects)
493493
{
@@ -501,17 +501,20 @@ __declspec(noinline) void _cdecl DoCameraCollisionDetectionPokes()
501501
MemPutFast<char>(VAR_CameraClipVehicles, 0);
502502
}
503503

504-
void __declspec(naked) HOOK_Camera_CollisionDetection()
504+
static void __declspec(naked) HOOK_Camera_CollisionDetection()
505505
{
506+
MTA_VERIFY_HOOK_LOCAL_SIZE;
507+
506508
__asm
507509
{
508510
pushad
509-
call DoCameraCollisionDetectionPokes
511+
call DoCameraCollisionDetectionPokes
510512
popad
511-
sub esp,24h
512-
push ebx
513-
push ebp
514-
jmp RETURN_Camera_CollisionDetection
513+
514+
sub esp, 24h
515+
push ebx
516+
push ebp
517+
jmp RETURN_Camera_CollisionDetection
515518
}
516519
}
517520

Client/game_sa/CCheckpointSA.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,17 @@ static void __cdecl RenderTargetArrow(CCheckpointSAInterface* pCheckpoint)
157157
}
158158

159159
#define HOOKPOS_CCheckpoint__Render 0x725E56
160-
#define HOOKSIZE_CCheckpoint__Render 0x5
161-
static constexpr std::uint32_t RETURN_CCheckpoint__Render = 0x725E5B;
160+
#define HOOKSIZE_CCheckpoint__Render 5
161+
static constexpr intptr_t RETURN_CCheckpoint__Render = 0x725E5B;
162162
static void __declspec(naked) HOOK_CCheckpoint__Render()
163163
{
164+
MTA_VERIFY_HOOK_LOCAL_SIZE;
165+
164166
__asm
165167
{
166-
pushad
167-
// vvv
168-
push esi
169-
call RenderTargetArrow
170-
add esp, 4
171-
// ^^^
172-
popad
168+
push esi
169+
call RenderTargetArrow
170+
add esp, 4
173171

174172
jmp RETURN_CCheckpoint__Render
175173
}

Client/game_sa/CFireSA.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,23 +236,29 @@ static void AbortFireTask(CEntitySAInterface* entityOnFire, DWORD returnAddress)
236236

237237
#define HOOKPOS_CFire_Extinguish 0x539429
238238
#define HOOKSIZE_CFire_Extinguish 6
239-
static constexpr std::uintptr_t CONTINUE_CFire_Extinguish = 0x53942F;
239+
static constexpr intptr_t CONTINUE_CFire_Extinguish = 0x53942F;
240240
static void __declspec(naked) HOOK_CFire_Extinguish()
241241
{
242+
MTA_VERIFY_HOOK_LOCAL_SIZE;
243+
242244
__asm
243245
{
244-
mov [eax+730h], edi
246+
mov [eax+730h], edi
245247

246-
push ebx
247-
mov ebx, [esp+0Ch]
248+
push ebx
249+
mov ebx, [esp+12]
250+
push edi
251+
push esi
248252

249-
push ebx
250-
push eax
251-
call AbortFireTask
252-
add esp, 8
253+
push ebx // returnAddress
254+
push eax // entityOnFire
255+
call AbortFireTask
256+
add esp, 8
253257

254-
pop ebx
255-
jmp CONTINUE_CFire_Extinguish
258+
pop esi
259+
pop edi
260+
pop ebx
261+
jmp CONTINUE_CFire_Extinguish
256262
}
257263
}
258264

Client/game_sa/CFxSystemSA.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ __declspec(noinline) void OnMY_FxSystem_c_Update_MidA_Post()
166166
#define HOOKPOS_FxSystem_c_Update_MidA 0x04AAF70
167167
#define HOOKSIZE_FxSystem_c_Update_MidA 5
168168
DWORD RETURN_FxSystem_c_Update_MidA = 0x04AAF75;
169-
void __declspec(naked) HOOK_FxSystem_c_Update_MidA()
169+
static void __declspec(naked) HOOK_FxSystem_c_Update_MidA()
170170
{
171+
MTA_VERIFY_HOOK_LOCAL_SIZE;
172+
171173
__asm
172174
{
173175
pushad
@@ -234,8 +236,10 @@ __declspec(noinline) void OnMY_FxSystem_c_Update_MidB_Post()
234236
#define HOOKPOS_FxSystem_c_Update_MidB 0x04AB21D
235237
#define HOOKSIZE_FxSystem_c_Update_MidB 7
236238
DWORD RETURN_FxSystem_c_Update_MidB = 0x04AB224;
237-
void __declspec(naked) HOOK_FxSystem_c_Update_MidB()
239+
static void __declspec(naked) HOOK_FxSystem_c_Update_MidB()
238240
{
241+
MTA_VERIFY_HOOK_LOCAL_SIZE;
242+
239243
__asm
240244
{
241245
pushad

Client/game_sa/CHandlingManagerSA.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,22 @@ __declspec(noinline) void DumpHandlingData(tHandlingDataSA* pData)
107107

108108
static __declspec(naked) void Hook_Calculate()
109109
{
110-
tHandlingDataSA* pData;
111-
DWORD dwHandlingData;
112-
_asm
110+
MTA_VERIFY_HOOK_LOCAL_SIZE;
111+
112+
__asm
113113
{
114-
mov eax, [esp+4]
115-
mov dwHandlingData, eax
116-
}
114+
mov eax, [esp+4]
117115

118-
pData = reinterpret_cast<tHandlingDataSA*>(dwHandlingData);
119-
DumpHandlingData(pData);
116+
push ecx // As in the original code
117+
push eax // We use this value to pop it into ecx later
120118

121-
_asm
122-
{
123-
ret 4
119+
push eax
120+
call DumpHandlingData
121+
add esp, 4
122+
123+
pop ecx // adapted from original code: mov ecx, [esp+4+arg_0]
124+
mov eax, 6F5085h
125+
jmp eax
124126
}
125127
}
126128

@@ -151,7 +153,7 @@ CHandlingManagerSA::CHandlingManagerSA()
151153
}
152154

153155
#if DUMP_HANDLING_DATA
154-
HookInstall(Func_Calculate, (DWORD)Hook_Calculate, 11);
156+
HookInstall(Func_Calculate, (DWORD)Hook_Calculate, 5);
155157
#endif
156158

157159
m_HandlingNames["mass"] = HandlingProperty::HANDLING_MASS; // works (mass > 0)

Client/game_sa/CHudSA.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -899,22 +899,24 @@ void CHudSA::RenderWanted(bool empty, float x, float y, const char* strLevel)
899899
static constexpr std::uintptr_t CONTINUE_RenderWanted = 0x58DFD8;
900900
static void __declspec(naked) HOOK_RenderWanted()
901901
{
902+
MTA_VERIFY_HOOK_LOCAL_SIZE;
903+
902904
__asm
903905
{
904-
cmp ebp, edi
905-
jle empty
906+
cmp ebp, edi
907+
jle empty
906908

907-
push 0
908-
jmp render
909+
push 0
910+
jmp render
909911

910912
empty:
911-
push 1
913+
push 1
912914

913915
render:
914-
call CHudSA::RenderWanted
915-
add esp,4
916+
call CHudSA::RenderWanted
917+
add esp, 4
916918

917-
jmp CONTINUE_RenderWanted
919+
jmp CONTINUE_RenderWanted
918920
}
919921
}
920922

Client/game_sa/CModelInfoSA.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,8 +1892,10 @@ __declspec(noinline) void OnMY_NodeNameStreamRead(RwStream* stream, char* pDest,
18921892
#define HOOKPOS_NodeNameStreamRead 0x072FA68
18931893
#define HOOKSIZE_NodeNameStreamRead 15
18941894
DWORD RETURN_NodeNameStreamRead = 0x072FA77;
1895-
void __declspec(naked) HOOK_NodeNameStreamRead()
1895+
static void __declspec(naked) HOOK_NodeNameStreamRead()
18961896
{
1897+
MTA_VERIFY_HOOK_LOCAL_SIZE;
1898+
18971899
__asm
18981900
{
18991901
pushad

Client/game_sa/CObjectSA.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ static void CObject_PreRender(CObjectSAInterface* objectInterface)
2929
const std::uintptr_t RETURN_CCObject_PreRender = 0x59FD56;
3030
static void __declspec(naked) HOOK_CCObject_PreRender()
3131
{
32+
MTA_VERIFY_HOOK_LOCAL_SIZE;
33+
3234
__asm
3335
{
34-
push ecx
35-
call CObject_PreRender
36-
pop ecx
37-
sub esp, 10h
38-
push esi
39-
mov esi, ecx
40-
jmp RETURN_CCObject_PreRender
36+
push ecx
37+
call CObject_PreRender
38+
pop ecx
39+
sub esp, 16
40+
push esi
41+
mov esi, ecx
42+
jmp RETURN_CCObject_PreRender
4143
}
4244
}
4345

0 commit comments

Comments
 (0)