Skip to content

Commit 3ce2cc1

Browse files
committed
Switch to C++23 in multiplayer_sa (part 2)
Fix all problematic hook functions
1 parent 1af8a67 commit 3ce2cc1

File tree

1 file changed

+108
-129
lines changed

1 file changed

+108
-129
lines changed

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 108 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -3872,25 +3872,26 @@ static void SetObjectAlpha()
38723872
}
38733873
}
38743874

3875-
DWORD dwCObjectRenderRet = 0;
3876-
static void __declspec(naked) HOOK_CObject_PostRender()
3875+
static void CObjectRenderWithTiming(CObjectSAInterface* object)
38773876
{
3878-
MTA_VERIFY_HOOK_LOCAL_SIZE;
3877+
dwAlphaEntity = reinterpret_cast<DWORD>(object);
38793878

3880-
__asm
3879+
SetObjectAlpha();
3880+
TIMING_CHECKPOINT("+ObjRndr");
38813881
{
3882-
pushad
3882+
if (bObjectIsAGangTag)
3883+
{
3884+
void(__cdecl * CTagManager__RenderTagForPC)(RpAtomic*) = reinterpret_cast<decltype(CTagManager__RenderTagForPC)>(0x49CE40);
3885+
CTagManager__RenderTagForPC(reinterpret_cast<RpAtomic*>(object->m_pRwObject));
3886+
}
3887+
else
3888+
{
3889+
void(__fastcall * CObject__Render)(CObjectSAInterface*) = reinterpret_cast<decltype(CObject__Render)>(0x534310);
3890+
CObject__Render(object);
3891+
}
38833892
}
3884-
38853893
TIMING_CHECKPOINT("-ObjRndr");
38863894
RestoreAlphaValues();
3887-
3888-
__asm
3889-
{
3890-
popad
3891-
mov edx, dwCObjectRenderRet
3892-
jmp edx
3893-
}
38943895
}
38953896

38963897
// Note: This hook is also called for world objects (light poles, wooden fences, etc).
@@ -3900,47 +3901,10 @@ static void __declspec(naked) HOOK_CObject_Render()
39003901

39013902
__asm
39023903
{
3903-
mov dwAlphaEntity, ecx
3904-
pushad
3905-
}
3906-
3907-
TIMING_CHECKPOINT("+ObjRndr");
3908-
SetObjectAlpha();
3909-
3910-
__asm
3911-
{
3912-
popad
3913-
mov edx, [esp]
3914-
mov dwCObjectRenderRet, edx
3915-
mov edx, HOOK_CObject_PostRender
3916-
mov [esp], edx
3917-
pushad
3918-
}
3919-
3920-
if (bObjectIsAGangTag) goto render_a_tag;
3921-
3922-
__asm
3923-
{
3924-
popad
3925-
jmp FUNC_CEntity_Render
3926-
}
3927-
3928-
render_a_tag:
3929-
__asm
3930-
{
3931-
popad
3932-
// We simulate here the header of the CEntity::Render function
3933-
// but then go straight to CTagManager::RenderTagForPC.
3934-
push ecx
3935-
push esi
3936-
mov eax, [esi+0x18]
3937-
test eax, eax
3938-
jz no_clump
3939-
mov eax, 0x534331
3940-
jmp eax
3941-
no_clump:
3942-
mov eax, 0x5343EB
3943-
jmp eax
3904+
push ecx
3905+
call CObjectRenderWithTiming
3906+
add esp, 4
3907+
retn
39443908
}
39453909
}
39463910

@@ -4055,24 +4019,26 @@ static void __declspec(naked) HOOK_ComputeDamageResponse_StartChoking()
40554019
pushad
40564020
mov al, [esp+0x8C]
40574021
mov ucChokingWeaponType, al
4058-
}
40594022

4060-
if (m_pChokingHandler && m_pChokingHandler(ucChokingWeaponType) == false) goto dont_choke;
4023+
mov ebx, [m_pChokingHandler]
4024+
test ebx, ebx
4025+
jz continueWithOriginalCode
40614026

4062-
__asm
4063-
{
4027+
push eax
4028+
call ebx
4029+
add esp, 4
4030+
test al, al
4031+
popad
4032+
4033+
jnz continueWithOriginalCode
4034+
jmp dwChokingDontchoke
4035+
4036+
continueWithOriginalCode:
40644037
popad
40654038
mov ecx, [edi]
40664039
mov eax, [ecx+0x47C]
40674040
jmp dwChokingChoke
40684041
}
4069-
4070-
dont_choke:
4071-
__asm
4072-
{
4073-
popad
4074-
jmp dwChokingDontchoke
4075-
}
40764042
}
40774043

40784044
void CMultiplayerSA::DisableEnterExitVehicleKey(bool bDisabled)
@@ -5135,6 +5101,22 @@ static void __declspec(naked) HOOK_ApplyCarBlowHop()
51355101

51365102
// ---------------------------------------------------
51375103

5104+
static void Pre_CGame_Process()
5105+
{
5106+
TIMING_CHECKPOINT("+CWorld_Process");
5107+
5108+
if (m_pPreWorldProcessHandler)
5109+
m_pPreWorldProcessHandler();
5110+
}
5111+
5112+
static void Post_CGame_Process()
5113+
{
5114+
if (m_pPostWorldProcessHandler)
5115+
m_pPostWorldProcessHandler();
5116+
5117+
TIMING_CHECKPOINT("-CWorld_Process");
5118+
}
5119+
51385120
DWORD CALL_CWorld_Process = 0x5684a0;
51395121
static void __declspec(naked) HOOK_CGame_Process()
51405122
{
@@ -5143,26 +5125,12 @@ static void __declspec(naked) HOOK_CGame_Process()
51435125
__asm
51445126
{
51455127
pushad
5146-
}
5147-
5148-
TIMING_CHECKPOINT("+CWorld_Process");
5149-
if (m_pPreWorldProcessHandler)
5150-
m_pPreWorldProcessHandler();
5151-
5152-
__asm
5153-
{
5128+
call Pre_CGame_Process
51545129
popad
51555130
call CALL_CWorld_Process
51565131
mov ecx, 0B72978h
51575132
pushad
5158-
}
5159-
5160-
if (m_pPostWorldProcessHandler) m_pPostWorldProcessHandler();
5161-
5162-
TIMING_CHECKPOINT("-CWorld_Process");
5163-
5164-
__asm
5165-
{
5133+
call Post_CGame_Process
51665134
popad
51675135
jmp RETURN_CGame_Process;
51685136
}
@@ -5181,28 +5149,38 @@ void __cdecl HandleIdle()
51815149
m_pIdleHandler();
51825150
}
51835151

5184-
DWORD CALL_CGame_Process = 0x53BEE0;
5185-
static void __declspec(naked) HOOK_Idle()
5152+
static void CGameProcessWithTiming()
51865153
{
5187-
MTA_VERIFY_HOOK_LOCAL_SIZE;
5188-
51895154
TIMING_CHECKPOINT("+CGame_Process");
5190-
__asm
51915155
{
5192-
call CALL_CGame_Process
5193-
pushad
5156+
void(__cdecl * CGame__Process)() = reinterpret_cast<decltype(CGame__Process)>(0x53BEE0);
5157+
CGame__Process();
51945158
}
5195-
51965159
TIMING_CHECKPOINT("-CGame_Process");
5160+
}
51975161

5162+
static void IdleWithTiming()
5163+
{
51985164
TIMING_CHECKPOINT("+Idle");
5199-
if (m_pIdleHandler)
5200-
HandleIdle();
5165+
{
5166+
if (m_pIdleHandler)
5167+
HandleIdle();
5168+
}
52015169
TIMING_CHECKPOINT("-Idle");
5170+
}
5171+
5172+
DWORD CALL_CGame_Process = 0x53BEE0;
5173+
static void __declspec(naked) HOOK_Idle()
5174+
{
5175+
MTA_VERIFY_HOOK_LOCAL_SIZE;
52025176

52035177
__asm
52045178
{
5179+
pushad
5180+
call CGameProcessWithTiming
5181+
call IdleWithTiming
52055182
popad
5183+
52065184
mov ecx, 0B6BC90h
52075185
jmp RETURN_Idle
52085186
}
@@ -6587,20 +6565,8 @@ void RemovePointerToBuilding()
65876565
}
65886566
}
65896567

6590-
DWORD dwCWorldRemove = 0x563280;
6591-
// Call to CWorld::Remove in CPopulation::ConvertToDummyObject this is called just before deleting a CObject so we remove the CObject while we are there and
6592-
// remove the new dummy if we need to do so before returning
6593-
static void __declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject()
6568+
static void RemovePointerToBuildingWithTiming()
65946569
{
6595-
MTA_VERIFY_HOOK_LOCAL_SIZE;
6596-
6597-
__asm
6598-
{
6599-
pushad
6600-
mov pBuildingRemove, esi
6601-
mov pBuildingAdd, edi
6602-
mov pLODInterface, edi
6603-
}
66046570
TIMING_CHECKPOINT("+RemovePointerToBuilding");
66056571
RemovePointerToBuilding();
66066572
StorePointerToBuilding();
@@ -6611,12 +6577,28 @@ static void __declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObjec
66116577
RemoveObjectIfNeeded();
66126578

66136579
TIMING_CHECKPOINT("-RemovePointerToBuilding");
6580+
}
6581+
6582+
DWORD dwCWorldRemove = 0x563280;
6583+
// Call to CWorld::Remove in CPopulation::ConvertToDummyObject this is called just before deleting a CObject so we remove the CObject while we are there and
6584+
// remove the new dummy if we need to do so before returning
6585+
static void __declspec(naked) HOOK_CWorld_Remove_CPopulation_ConvertToDummyObject()
6586+
{
6587+
MTA_VERIFY_HOOK_LOCAL_SIZE;
6588+
66146589
__asm
66156590
{
6591+
pushad
6592+
mov pBuildingRemove, esi
6593+
mov pBuildingAdd, edi
6594+
mov pLODInterface, edi
6595+
call RemovePointerToBuildingWithTiming
66166596
popad
6617-
jmp dwCWorldRemove
6597+
6598+
jmp dwCWorldRemove
66186599
}
66196600
}
6601+
66206602
// if it's replaced get rid of it
66216603
void RemoveDummyIfReplaced()
66226604
{
@@ -6631,6 +6613,15 @@ void RemoveDummyIfReplaced()
66316613
}
66326614
}
66336615

6616+
static bool CheckForRemovalWithTiming()
6617+
{
6618+
TIMING_CHECKPOINT("+CheckForRemoval");
6619+
StorePointerToBuilding();
6620+
bool result = CheckForRemoval();
6621+
TIMING_CHECKPOINT("-CheckForRemoval");
6622+
return result;
6623+
}
6624+
66346625
// Function that handles dummy -> object so we can cancel this process if need be
66356626
static void __declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject()
66366627
{
@@ -6639,31 +6630,19 @@ static void __declspec(naked) HOOK_CWorld_Add_CPopulation_ConvertToDummyObject()
66396630
__asm
66406631
{
66416632
pushad
6642-
mov pLODInterface, edi
6643-
mov pBuildingAdd, edi
6644-
}
6633+
mov pLODInterface, edi
6634+
mov pBuildingAdd, edi
66456635

6646-
TIMING_CHECKPOINT("+CheckForRemoval");
6647-
StorePointerToBuilding();
6648-
if (CheckForRemoval())
6649-
{
6650-
TIMING_CHECKPOINT("-CheckForRemoval");
6651-
__asm
6652-
{
6653-
popad
6654-
jmp JMP_RETN_Cancelled_CPopulation_ConvertToDummyObject
6655-
}
6656-
}
6657-
else
6658-
{
6659-
TIMING_CHECKPOINT("-CheckForRemoval");
6660-
__asm
6661-
{
6662-
popad
6663-
push edi
6664-
call CALL_CWorld_Add_CPopulation_ConvertToDummyObject
6665-
jmp JMP_RETN_Called_CPopulation_ConvertToDummyObject
6666-
}
6636+
call CheckForRemovalWithTiming
6637+
test al, al
6638+
popad
6639+
jz continueWithOriginalCode
6640+
jmp JMP_RETN_Cancelled_CPopulation_ConvertToDummyObject
6641+
6642+
continueWithOriginalCode:
6643+
push edi
6644+
call CALL_CWorld_Add_CPopulation_ConvertToDummyObject
6645+
jmp JMP_RETN_Called_CPopulation_ConvertToDummyObject
66676646
}
66686647
}
66696648

0 commit comments

Comments
 (0)