I am trying to conduct some AI experiments for multiplayer based on client side. For that I enabled automatic vehicle spawn, automatic ped spawn etc... but the pGame->GetPools it not being correctly updated with the vehicle information. I found out that the PED's are being updated correctly thanks to the following code found in CPopulationSA.cpp in sa_multiplayer:
DWORD pedVtable;
VOID HOOK_EndOf_CPopulation__Add();
VOID HOOK_CPopulation__RemovePed();
#define HOOKPOS_EndOf_CPopulation__Add 0x612C76
#define HOOKPOS_CPopulation__RemovePed 0x610F20
#define VTBL_CPlayerPed 0x86D168
CPopulationSA::CPopulationSA()
{
dwPedCount = 0;
HookInstall(HOOKPOS_EndOf_CPopulation__Add, (DWORD)HOOK_EndOf_CPopulation__Add, 6);
HookInstall(HOOKPOS_CPopulation__RemovePed, (DWORD)HOOK_CPopulation__RemovePed, 6);
pSingleton = this;
m_pCivilianRemoveHandler = NULL;
m_pCivilianAddHandler = NULL;
}
VOID _declspec(naked) HOOK_EndOf_CPopulation__Add()
{
_asm
{
mov pPedStorage, eax
pushad
}
pSingleton->AddPed ( pPedStorage );
_asm
{
popad
add esp, 0x3C
retn
}
}
VOID _declspec(naked) HOOK_CPopulation__RemovePed()
{
/*
00610F20 /$ 56 PUSH ESI
00610F21 |. 8B7424 08 MOV ESI,DWORD PTR SS:[ESP+8]
00610F25 |. 56 PUSH ESI
*/
_asm
{
push esi
mov esi, [esp+8]
push esi
mov pPedStorage, esi
mov ecx, [esi]
mov pedVtable, ecx
pushad
}
if ( pedVtable == VTBL_CPlayerPed )
{
_asm
{
popad
pop esi
pop esi
retn
}
}
pSingleton->RemovePed(pPedStorage);
_asm
{
popad
mov ecx, HOOKPOS_CPopulation__RemovePed
add ecx, 6
jmp ecx
}
}
I however cannot find the same code for CVehicle or CObject, could someone give me the adresses of all the required stuff so I can make the same for CVehicle and CObject? I want it to update the pools just like CPed automatically does thanks to the above code.
#define HOOKPOS_EndOf_CPopulation__Add 0x612C76
#define HOOKPOS_CPopulation__RemovePed 0x610F20
#define VTBL_CPlayerPed 0x86D168
#define HOOKPOS_CVehicle_Create ????????
#define HOOKPOS_CVehicle_Remove ????????
#define VTBL_CVehicle ????????
#define HOOKPOS_CObject_Create ????????
#define HOOKPOS_CObject_Remove ????????
#define VTBL_CObject ????????
http://ideone.com/I9OvKt
http://ideone.com/7sgIlL
http://ideone.com/eNR7og
Feel free to contribute to the above code, it would be really great if it will work.