Skip to content
Permalink
Browse files

Rename onClientElementHitByWaterCannon to onClientVehicleWeaponHit

  • Loading branch information...
botder committed Dec 4, 2018
1 parent 9643505 commit 1055587fbf84eaeb3597e1507b98ae842b348ef4
@@ -284,7 +284,7 @@ CClientGame::CClientGame(bool bLocalPlay)
g_pMultiplayer->SetFxSystemDestructionHandler(CClientGame::StaticFxSystemDestructionHandler);
g_pMultiplayer->SetDrivebyAnimationHandler(CClientGame::StaticDrivebyAnimationHandler);
g_pMultiplayer->SetPedStepHandler(CClientGame::StaticPedStepHandler);
g_pMultiplayer->SetWaterCannonHitWorldHandler(CClientGame::StaticWaterCannonHitWorldHandler);
g_pMultiplayer->SetVehicleWeaponHitHandler(CClientGame::StaticVehicleWeaponHitHandler);
g_pGame->SetPreWeaponFireHandler(CClientGame::PreWeaponFire);
g_pGame->SetPostWeaponFireHandler(CClientGame::PostWeaponFire);
g_pGame->SetTaskSimpleBeHitHandler(CClientGame::StaticTaskSimpleBeHitHandler);
@@ -446,7 +446,7 @@ CClientGame::~CClientGame(void)
g_pMultiplayer->SetGameEntityRenderHandler(NULL);
g_pMultiplayer->SetDrivebyAnimationHandler(nullptr);
g_pMultiplayer->SetPedStepHandler(nullptr);
g_pMultiplayer->SetWaterCannonHitWorldHandler(nullptr);
g_pMultiplayer->SetVehicleWeaponHitHandler(nullptr);
g_pGame->SetPreWeaponFireHandler(NULL);
g_pGame->SetPostWeaponFireHandler(NULL);
g_pGame->SetTaskSimpleBeHitHandler(NULL);
@@ -2751,7 +2751,6 @@ void CClientGame::AddBuiltInEvents(void)
m_Events.AddEvent("onClientElementStreamIn", "", NULL, false);
m_Events.AddEvent("onClientElementStreamOut", "", NULL, false);
m_Events.AddEvent("onClientElementDestroy", "", NULL, false);
m_Events.AddEvent("onClientElementHitByWaterCannon", "vehicle, hitX, hitY, hitZ, normalX, normalY, normalZ, model, materialID", nullptr, false);

// Player events
m_Events.AddEvent("onClientPlayerJoin", "", NULL, false);
@@ -2802,6 +2801,7 @@ void CClientGame::AddBuiltInEvents(void)
m_Events.AddEvent("onClientVehicleCollision", "collidedelement, damageImpulseMag, bodypart, x, y, z, velX, velY, velZ", NULL, false);
m_Events.AddEvent("onClientVehicleDamage", "attacker, weapon, loss, x, y, z, tyre", NULL, false);
m_Events.AddEvent("onClientVehicleNitroStateChange", "activated", NULL, false);
m_Events.AddEvent("onClientVehicleWeaponHit", "weaponType, hitElement, hitX, hitY, hitZ, model, materialID", nullptr, false);

// GUI events
m_Events.AddEvent("onClientGUIClick", "button, state, absoluteX, absoluteY", NULL, false);
@@ -3812,9 +3812,9 @@ void CClientGame::StaticPedStepHandler(CPedSAInterface* pPed, bool bFoot)
return g_pClientGame->PedStepHandler(pPed, bFoot);
}

void CClientGame::StaticWaterCannonHitWorldHandler(SWaterCannonHitEvent& event)
void CClientGame::StaticVehicleWeaponHitHandler(SVehicleWeaponHitEvent& event)
{
g_pClientGame->WaterCannonHitWorldHandler(event);
g_pClientGame->VehicleWeaponHitHandler(event);
}

void CClientGame::DrawRadarAreasHandler(void)
@@ -6918,7 +6918,7 @@ void CClientGame::PedStepHandler(CPedSAInterface* pPedSA, bool bFoot)
pClientPed->CallEvent("onClientPedStep", Arguments, true);
}

void CClientGame::WaterCannonHitWorldHandler(SWaterCannonHitEvent& event)
void CClientGame::VehicleWeaponHitHandler(SVehicleWeaponHitEvent& event)
{
CClientEntity* const pVehicle = event.pGameVehicle ? g_pClientGame->GetGameEntityXRefManager()->FindClientVehicle(event.pGameVehicle) : nullptr;

@@ -6927,18 +6927,18 @@ void CClientGame::WaterCannonHitWorldHandler(SWaterCannonHitEvent& event)

CClientEntity* pEntity = event.pHitGameEntity ? g_pClientGame->GetGameEntityXRefManager()->FindClientEntity(event.pHitGameEntity) : nullptr;

if (!pEntity)
pEntity = m_pRootEntity;

CLuaArguments arguments;
arguments.PushElement(pVehicle);
arguments.PushNumber(static_cast<int>(event.weaponType));

if (pEntity)
arguments.PushElement(pEntity);
else
arguments.PushBoolean(false);

arguments.PushNumber(event.vecPosition.fX);
arguments.PushNumber(event.vecPosition.fY);
arguments.PushNumber(event.vecPosition.fZ);
arguments.PushNumber(event.vecNormal.fX);
arguments.PushNumber(event.vecNormal.fY);
arguments.PushNumber(event.vecNormal.fZ);
arguments.PushNumber(event.iModel);
arguments.PushNumber(event.ucColSurface);
pEntity->CallEvent("onClientElementHitByWaterCannon", arguments, false);
arguments.PushNumber(event.iColSurface);
pVehicle->CallEvent("onClientVehicleWeaponHit", arguments, false);
}
@@ -527,7 +527,7 @@ class CClientGame
static void StaticTaskSimpleBeHitHandler(CPedSAInterface* pPedAttacker, ePedPieceTypes hitBodyPart, int hitBodySide, int weaponId);
static void StaticFxSystemDestructionHandler(void* pFxSAInterface);
static void StaticPedStepHandler(CPedSAInterface* pPed, bool bFoot);
static void StaticWaterCannonHitWorldHandler(SWaterCannonHitEvent& event);
static void StaticVehicleWeaponHitHandler(SVehicleWeaponHitEvent& event);

static AnimationId StaticDrivebyAnimationHandler(AnimationId animGroup, AssocGroupId animId);

@@ -618,7 +618,7 @@ class CClientGame
void RemoveAnimationAssociationFromMap(CAnimBlendAssociationSAInterface* pAnimAssociation);

void PedStepHandler(CPedSAInterface* pPed, bool bFoot);
void WaterCannonHitWorldHandler(SWaterCannonHitEvent& event);
void VehicleWeaponHitHandler(SVehicleWeaponHitEvent& event);

private:
eStatus m_Status;
@@ -291,9 +291,6 @@ DWORD dwFUNC_CAEVehicleAudioEntity__ProcessAIProp = FUNC_CAEVehicleAudioEntity__
#define HOOKPOS_CTaskSimpleSwim_ProcessSwimmingResistance 0x68A4EF
DWORD RETURN_CTaskSimpleSwim_ProcessSwimmingResistance = 0x68A50E;

#define HOOKPOS_CWaterCannon__Render 0x72932A
static DWORD CONTINUE_CWaterCannon__Render = 0x72932F;

CPed* pContextSwitchedPed = 0;
CVector vecCenterOfWorld;
FLOAT fFalseHeading;
@@ -360,7 +357,6 @@ ObjectDamageHandler* m_pObjectDamageHandler = NULL;
ObjectBreakHandler* m_pObjectBreakHandler = NULL;
FxSystemDestructionHandler* m_pFxSystemDestructionHandler = NULL;
DrivebyAnimationHandler* m_pDrivebyAnimationHandler = NULL;
WaterCannonHitWorldHandler* m_pWaterCannonHitWorldHandler = nullptr;

CEntitySAInterface* dwSavedPlayerPointer = 0;
CEntitySAInterface* activeEntityForStreaming = 0; // the entity that the streaming system considers active
@@ -512,8 +508,6 @@ void HOOK_CAEVehicleAudioEntity__ProcessDummyProp();

void HOOK_CTaskSimpleSwim_ProcessSwimmingResistance();

static void HOOK_CWaterCannon__Render();

CMultiplayerSA::CMultiplayerSA()
{
// Unprotect all of the GTASA code at once and leave it that way
@@ -735,8 +729,6 @@ void CMultiplayerSA::InitHooks()
// Fix GTA:SA swimming speed problem on higher fps
HookInstall(HOOKPOS_CTaskSimpleSwim_ProcessSwimmingResistance, (DWORD)HOOK_CTaskSimpleSwim_ProcessSwimmingResistance, 6);

HookInstall(HOOKPOS_CWaterCannon__Render, (DWORD)HOOK_CWaterCannon__Render, 5);

// Disable GTA setting g_bGotFocus to false when we minimize
MemSet((void*)ADDR_GotFocus, 0x90, pGameInterface->GetGameVersion() == VERSION_EU_10 ? 6 : 10);

@@ -1502,6 +1494,7 @@ void CMultiplayerSA::InitHooks()
InitHooks_FixLineOfSightArgs();
InitHooks_VehicleDamage();
InitHooks_VehicleLights();
InitHooks_VehicleWeapons();
}

// Used to store copied pointers for explosions in the FxSystem
@@ -2272,11 +2265,6 @@ void CMultiplayerSA::SetDrivebyAnimationHandler(DrivebyAnimationHandler* pHandle
m_pDrivebyAnimationHandler = pHandler;
}

void CMultiplayerSA::SetWaterCannonHitWorldHandler(WaterCannonHitWorldHandler* pHandler)
{
m_pWaterCannonHitWorldHandler = pHandler;
}

// What we do here is check if the idle handler has been set
bool CMultiplayerSA::IsConnected(void)
{
@@ -6815,37 +6803,3 @@ void _declspec(naked) HOOK_CTaskSimpleSwim_ProcessSwimmingResistance()
jmp RETURN_CTaskSimpleSwim_ProcessSwimmingResistance
}
}

static void __cdecl WaterCannonHitWorld(CVehicleSAInterface* pGameVehicle, CColPointSAInterface* pColPoint, CEntitySAInterface** ppGameEntity)
{
if (m_pWaterCannonHitWorldHandler)
{
CEntitySAInterface* const pGameEntity = ppGameEntity ? *ppGameEntity : nullptr;
const int iModel = pGameEntity ? pGameEntity->m_nModelIndex : -1;

SWaterCannonHitEvent event = {
pGameVehicle, pGameEntity, pColPoint->Position, pColPoint->Normal, iModel, pColPoint->ucSurfaceTypeB,
};

m_pWaterCannonHitWorldHandler(event);
}
}

static void _declspec(naked) HOOK_CWaterCannon__Render()
{
_asm
{
pushad
mov eax, [ebx] // CVehicleSAInterface* CWaterCannon::m_pVehicle
lea ebx, [esp + 100h - 54h] // CColPointSAInterface*
lea ecx, [esp + 100h - 58h] // CEntitySAInterface**
push ecx // ppGameEntity
push ebx // pColPoint
push eax // pGameVehicle
call WaterCannonHitWorld
add esp, 12
popad
push 3E4CCCCDh
jmp CONTINUE_CWaterCannon__Render
}
}
@@ -71,6 +71,7 @@ class CMultiplayerSA : public CMultiplayer
void InitHooks_LicensePlate(void);
void InitHooks_VehicleLights(void);
void InitHooks_VehicleDamage(void);
void InitHooks_VehicleWeapons();
void InitHooks_Direct3D(void);
void InitHooks_FixLineOfSightArgs(void);
CRemoteDataStorage* CreateRemoteDataStorage();
@@ -135,7 +136,7 @@ class CMultiplayerSA : public CMultiplayer
void SetFxSystemDestructionHandler(FxSystemDestructionHandler* pHandler);
void SetDrivebyAnimationHandler(DrivebyAnimationHandler* pHandler);
void SetPedStepHandler(PedStepHandler* pHandler);
void SetWaterCannonHitWorldHandler(WaterCannonHitWorldHandler* pHandler);
void SetVehicleWeaponHitHandler(VehicleWeaponHitHandler* pHandler) override;

void AllowMouseMovement(bool bAllow);
void DoSoundHacksOnLostFocus(bool bLostFocus);
@@ -0,0 +1,91 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: multiplayer_sa/CMultiplayerSA_VehicleWeapons.cpp
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"

VehicleWeaponHitHandler* pVehicleWeaponHitHandler = nullptr;

void CMultiplayerSA::SetVehicleWeaponHitHandler(VehicleWeaponHitHandler* pHandler)
{
pVehicleWeaponHitHandler = pHandler;
}

static void TriggerVehicleWeaponHitEvent(EVehicleWeaponType weaponType, CVehicleSAInterface* pGameVehicle, CEntitySAInterface* pHitGameEntity, CVector& vecPosition, int iModel, int iSurfaceType)
{
if (!pVehicleWeaponHitHandler)
return;

SVehicleWeaponHitEvent event = {
weaponType,
pGameVehicle,
pHitGameEntity,
vecPosition,
iModel,
iSurfaceType,
};

pVehicleWeaponHitHandler(event);
}

//////////////////////////////////////////////////////////////////////////////////////////
//
// CWaterCannon::Render()
//
// Calculates the destination of the water stream, renders the splash fx there and
// informs the water cannon audio entity.
//
//////////////////////////////////////////////////////////////////////////////////////////
// 0x729324 | 0F 84 1C 02 00 00 | jz 0x729546
// >>> 0x72932A | 68 CD CC 4C 3E | push 3E4CCCCDh
// 0x72932F | 68 00 00 80 3F | push 3F800000h
#define HOOKPOS_CWaterCannon__Render 0x72932A
#define HOOKSIZE_CWaterCannon__Render 5
static DWORD CONTINUE_CWaterCannon__Render = 0x72932F;

static void HandleWaterCannonHit(CVehicleSAInterface* pGameVehicle, CColPointSAInterface* pColPoint, CEntitySAInterface** ppHitGameEntity)
{
if (!pVehicleWeaponHitHandler)
return;

CEntitySAInterface* const pHitGameEntity = ppHitGameEntity ? *ppHitGameEntity : nullptr;
const int iModel = pHitGameEntity ? pHitGameEntity->m_nModelIndex : -1;

TriggerVehicleWeaponHitEvent(EVehicleWeaponType::WATER_CANNON, pGameVehicle, pHitGameEntity, pColPoint->Position, iModel, pColPoint->ucSurfaceTypeB);
}

static void _declspec(naked) HOOK_CWaterCannon__Render()
{
_asm
{
pushad
mov eax, [ebx] // CVehicleSAInterface* CWaterCannon::m_pVehicle
lea ebx, [esp + 100h - 54h] // CColPointSAInterface*
lea ecx, [esp + 100h - 58h] // CEntitySAInterface**
push ecx // ppHitGameEntity
push ebx // pColPoint
push eax // pGameVehicle
call HandleWaterCannonHit
add esp, 12
popad
push 3E4CCCCDh
jmp CONTINUE_CWaterCannon__Render
}
}

//////////////////////////////////////////////////////////////////////////////////////////
//
// CMultiplayerSA::InitHooks_VehicleWeapons
//
// Setup hooks for vehicle weapon related events
//
//////////////////////////////////////////////////////////////////////////////////////////
void CMultiplayerSA::InitHooks_VehicleWeapons(void)
{
EZHookInstall(CWaterCannon__Render);
}
@@ -37,14 +37,23 @@ struct SClothesCacheStats
uint uiNumRemoved;
};

struct SWaterCannonHitEvent
enum EVehicleWeaponType : int
{
INVALID,
WATER_CANNON,
TANK_GUN,
ROCKET,
HEAT_SEAKING_ROCKET,

This comment has been minimized.

Copy link
@ArranTuna

ArranTuna Dec 5, 2018

Contributor

Typo?

This comment has been minimized.

Copy link
@botder

botder Dec 5, 2018

Author Member

Yes

};

struct SVehicleWeaponHitEvent
{
EVehicleWeaponType weaponType;
CEntitySAInterface* pGameVehicle;
CEntitySAInterface* pHitGameEntity;
CVector vecPosition;
CVector vecNormal;
int iModel;
unsigned char ucColSurface;
int iColSurface;
};

class CAnimBlendAssociationSAInterface;
@@ -108,7 +117,8 @@ typedef void(GameEntityRenderHandler)(CEntitySAInterface* pEntity);
typedef void(FxSystemDestructionHandler)(void* pFxSA);
typedef AnimationId(DrivebyAnimationHandler)(AnimationId animGroup, AssocGroupId animId);
typedef void(PedStepHandler)(CPedSAInterface* pPed, bool bFoot);
typedef void(WaterCannonHitWorldHandler)(SWaterCannonHitEvent& event);

using VehicleWeaponHitHandler = void(SVehicleWeaponHitEvent& event);

/**
* This class contains information used for shot syncing, one exists per player.
@@ -228,7 +238,7 @@ class CMultiplayer
virtual void SetFxSystemDestructionHandler(FxSystemDestructionHandler* pHandler) = 0;
virtual void SetDrivebyAnimationHandler(DrivebyAnimationHandler* pHandler) = 0;
virtual void SetPedStepHandler(PedStepHandler* pHandler) = 0;
virtual void SetWaterCannonHitWorldHandler(WaterCannonHitWorldHandler* pHandler) = 0;
virtual void SetVehicleWeaponHitHandler(VehicleWeaponHitHandler* pHandler) = 0;
virtual void AllowMouseMovement(bool bAllow) = 0;
virtual void DoSoundHacksOnLostFocus(bool bLostFocus) = 0;
virtual bool HasSkyColor() = 0;

2 comments on commit 1055587

@ArranTuna

This comment has been minimized.

Copy link
Contributor

replied Dec 5, 2018

I've documented this event: https://wiki.multitheftauto.com/wiki/OnClientVehicleWeaponHit to the best of my ability looking at the source code and testing it ingame. I couldn't get it to trigger with tank, hydra, or hunter.

@botder

This comment has been minimized.

Copy link
Member Author

replied Dec 5, 2018

Because I didn't implement the hooks for these weapon types yet.

Please sign in to comment.
You can’t perform that action at this time.