r5sdk/r5dev/game/shared/r1/weapon_bolt.h
Kawe Mazidjatari 8e379457bf Fix server code crasher in 'FireWeaponBolt'
The function 'FireWeaponBolt' calls 'CreateWeaponBolt' to create a bolt entity, but it can return NULL. 'FireWeaponBolt' does NOT check for NULL and derefs the pointer regardless. This rarely happens though; in all cases, it was caused by a defect in scripts. Code has been hooked to throw an engine error instead of crashing.
2023-05-31 23:58:10 +02:00

46 lines
1.7 KiB
C++

#ifndef GAME_WEAPON_BOLT_H
#define GAME_WEAPON_BOLT_H
#ifndef CLIENT_DLL
#include <game/server/baseentity.h>
#include <game/server/player.h>
#else
#include <game/client/c_baseentity.h>
#include <game/client/c_baseplayer.h>
#endif
CBaseEntity* CreateWeaponBolt(Vector3D* origin, Vector3D* end, __int64 unused, float scale, CPlayer* unkEnt,
int a6, int modelindex, int a8, unsigned __int8 a9, unsigned int a10, CBaseEntity* weaponEnt);
inline CMemory p_CreateWeaponBolt;
inline auto v_CreateWeaponBolt = p_CreateWeaponBolt.RCast<CBaseEntity*(*)(
Vector3D* origin, Vector3D* end, __int64 unused, float scale, CPlayer* player,
int a6, int modelindex, int a8, unsigned __int8 a9, unsigned int a10, CBaseEntity* weapon)>();
///////////////////////////////////////////////////////////////////////////////
class V_Weapon_Bolt : public IDetour
{
virtual void GetAdr(void) const
{
LogFunAdr("CreateWeaponBolt", p_CreateWeaponBolt.GetPtr());
}
virtual void GetFun(void) const { }
virtual void GetVar(void) const
{
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
p_CreateWeaponBolt = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 56 57 41 54 41 55 41 56 48 81 EC ?? ?? ?? ??");
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
p_CreateWeaponBolt = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 57 41 56 41 57 48 83 EC 70");
#endif
v_CreateWeaponBolt = p_CreateWeaponBolt.RCast<CBaseEntity* (*)(
Vector3D*, Vector3D*, __int64, float, CPlayer*,
int, int, int, unsigned __int8, unsigned int, CBaseEntity*)>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const;
virtual void Detach(void) const;
};
///////////////////////////////////////////////////////////////////////////////
#endif // GAME_WEAPON_BOLT_H