Skip to content

Commit edfc611

Browse files
committed
Re-add CrossRoad's stuff with modifications
1 parent 1660597 commit edfc611

File tree

9 files changed

+133
-2
lines changed

9 files changed

+133
-2
lines changed

Client/game_sa/CFxSA.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include "game/Common.h"
14+
#include "game/RenderWare.h"
15+
#include "CVector2D.h"
1316
#include "CFxSA.h"
1417
#include "CEntitySA.h"
18+
;
19+
using StoreShadowToBeRendered_t = int(__cdecl*)(eShadowType, struct RwTexture*, const CVector*, float, float, float, float, short, unsigned char, unsigned char,
20+
unsigned char, float, bool, float, class CRealTimeShadow*, bool);
21+
auto StoreShadowToBeRendered = reinterpret_cast<StoreShadowToBeRendered_t>(0x707390);
22+
unsigned short& CShadows_ShadowsStoredToBeRendered = *(unsigned short*)0xC403DC;
1523

1624
void CFxSA::AddBlood(CVector& vecPosition, CVector& vecDirection, int iCount, float fBrightness)
1725
{
@@ -329,3 +337,22 @@ void CFxSA::AddParticle(FxParticleSystems eFxParticle, const CVector& vecPositio
329337
((int(__thiscall*)(FxSystem_c*, const CVector*, const CVector*, float, FxPrtMult_c*, float, float, float, int))FUNC_FXSystem_c_AddParticle)(fxParticleSystem, &vecPosition, &newDirection, 0, &fxPrt, -1.0f, fBrightness, 0, 0);
330338
}
331339
}
340+
341+
bool CFxSA::IsShadowsLimitReached()
342+
{
343+
constexpr int shadowsLimit = 48;
344+
return CShadows_ShadowsStoredToBeRendered >= shadowsLimit;
345+
}
346+
347+
bool CFxSA::AddShadow(eShadowTextureType shadowTextureType, const CVector& vecPosition, const CVector2D& vecOffset1, const CVector2D& vecOffset2, SColor color,
348+
eShadowType shadowType, float fZDistance, bool bDrawOnWater, bool bDrawOnBuildings)
349+
{
350+
if (IsShadowsLimitReached())
351+
return false;
352+
353+
void* textureAddress = *(void**)(FUNC_FXSystem_BaseShadow + (int)shadowTextureType * 4);
354+
RwTexture* pRwTexture = reinterpret_cast<RwTexture*>(textureAddress);
355+
356+
return StoreShadowToBeRendered(shadowType, pRwTexture, &vecPosition, vecOffset1.fX, vecOffset1.fY, vecOffset2.fX, vecOffset2.fY, color.A, color.R, color.G,
357+
color.B, fZDistance, bDrawOnWater, 1, 0, bDrawOnBuildings);
358+
}

Client/game_sa/CFxSA.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#pragma once
1313

1414
#include <game/CFx.h>
15+
#include <SharedUtil.Misc.h>
1516

1617
struct RwColor;
1718
class FxSystem_c;
@@ -31,7 +32,7 @@ class FxSystem_c;
3132
#define FUNC_CFx_TriggerBulletSplash 0x4a10e0
3233
#define FUNC_CFx_TriggerFootSplash 0x4a1150
3334
#define FUNC_FXSystem_c_AddParticle 0x4AA440
34-
35+
#define FUNC_FXSystem_BaseShadow 0xC403E0
3536
class CFxSAInterface
3637
{
3738
public:
@@ -77,6 +78,9 @@ class CFxSA : public CFx
7778
void TriggerBulletSplash(CVector& vecPosition);
7879
void TriggerFootSplash(CVector& vecPosition);
7980
void AddParticle(FxParticleSystems eFxParticle, const CVector& vecPosition, const CVector& vecDirection, float fR, float fG, float fB, float fA, bool bRandomizeColors, std::uint32_t iCount, float fBrightness, float fSize, bool bRandomizeSizes, float fLife);
81+
bool AddShadow(eShadowTextureType shadowTextureType, const CVector& vecPosition, const CVector2D& vecOffset1, const CVector2D& vecOffset2, SColor color,
82+
eShadowType shadowType, float fZDistance, bool bDrawOnWater, bool bDrawOnBuildings);
83+
static bool IsShadowsLimitReached();
8084

8185
private:
8286
CFxSAInterface* m_pInterface;

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8076,6 +8076,13 @@ bool CStaticFunctionDefinitions::FxCreateParticle(FxParticleSystems eFxParticle,
80768076
return true;
80778077
}
80788078

8079+
bool CStaticFunctionDefinitions::FxAddShadow(eShadowTextureType shadowTextureType, const CVector& vecPosition, const CVector2D& vecOffset1,
8080+
const CVector2D& vecOffset2, SColor color, eShadowType shadowType, float fZDistance, bool bDrawOnWater,
8081+
bool bDrawOnBuildings)
8082+
{
8083+
return g_pGame->GetFx()->AddShadow(shadowTextureType, vecPosition, vecOffset1, vecOffset2, color, shadowType, fZDistance, bDrawOnWater, bDrawOnBuildings);
8084+
}
8085+
80798086
CClientEffect* CStaticFunctionDefinitions::CreateEffect(CResource& Resource, const SString& strFxName, const CVector& vecPosition, bool bSoundEnable)
80808087
{
80818088
CClientEffect* pFx = m_pManager->GetEffectManager()->Create(strFxName, vecPosition, INVALID_ELEMENT_ID, bSoundEnable);

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@ class CStaticFunctionDefinitions
740740
static bool FxAddBulletSplash(CVector& vecPosition);
741741
static bool FxAddFootSplash(CVector& vecPosition);
742742
static bool FxCreateParticle(FxParticleSystems eFxParticle, CVector& vecPosition, CVector& vecDirection, float fR, float fG, float fB, float fA, bool bRandomizeColors, std::uint32_t iCount, float fBrightness, float fSize, bool bRandomizeSizes, float fLife);
743+
static bool FxAddShadow(eShadowTextureType shadowTextureType, const CVector& vecPosition, const CVector2D& vecOffset1, const CVector2D& vecOffset2,
744+
SColor color, eShadowType shadowType, float fZDistance, bool bDrawOnWater, bool bDrawOnBuildings);
743745
static CClientEffect* CreateEffect(CResource& Resource, const SString& strFxName, const CVector& vecPosition, bool bSoundEnable);
744746

745747
// Sound funcs

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,28 @@ ADD_ENUM(_D3DFORMAT::D3DFMT_G32R32F, "g32r32f")
860860
ADD_ENUM(_D3DFORMAT::D3DFMT_A32B32G32R32F, "a32b32g32r32f")
861861
IMPLEMENT_ENUM_CLASS_END("surface-format")
862862

863+
IMPLEMENT_ENUM_CLASS_BEGIN(eShadowTextureType)
864+
ADD_ENUM(eShadowTextureType::PLANE, "plane")
865+
ADD_ENUM(eShadowTextureType::CAR, "car")
866+
ADD_ENUM(eShadowTextureType::PED, "ped")
867+
ADD_ENUM(eShadowTextureType::HELI, "heli")
868+
ADD_ENUM(eShadowTextureType::BIKE, "bike")
869+
ADD_ENUM(eShadowTextureType::RCBARON, "rcbaron")
870+
ADD_ENUM(eShadowTextureType::EXPLOSION, "explosion")
871+
ADD_ENUM(eShadowTextureType::HEADLIGHT1, "headlight1")
872+
ADD_ENUM(eShadowTextureType::HEADLIGHT2, "headlight2")
873+
ADD_ENUM(eShadowTextureType::BLOOD, "blood")
874+
ADD_ENUM(eShadowTextureType::HANDMAN, "handman")
875+
ADD_ENUM(eShadowTextureType::WINCRACK, "wincrack")
876+
ADD_ENUM(eShadowTextureType::LAMP, "lamp")
877+
IMPLEMENT_ENUM_CLASS_END("shadow-texture-type")
878+
879+
IMPLEMENT_ENUM_CLASS_BEGIN(eShadowType)
880+
ADD_ENUM(eShadowType::DEFAULT, "default")
881+
ADD_ENUM(eShadowType::ADDITIVE, "additive")
882+
ADD_ENUM(eShadowType::INVCOLOR, "invcolor")
883+
IMPLEMENT_ENUM_CLASS_END("shadow-type")
884+
863885
IMPLEMENT_ENUM_CLASS_BEGIN(eRenderStage)
864886
ADD_ENUM(eRenderStage::PRE_FX, "prefx")
865887
ADD_ENUM(eRenderStage::POST_FX, "postfx")

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <game/CRenderWare.h>
1515
#include <game/CHud.h>
1616
#include <game/CStreaming.h>
17+
#include <game/CFx.h>
1718
#include <type_traits>
1819

1920
#include "enums/VehicleComponent.h"
@@ -94,6 +95,8 @@ DECLARE_ENUM_CLASS(eModelIdeFlag);
9495
DECLARE_ENUM_CLASS(_D3DFORMAT);
9596
DECLARE_ENUM_CLASS(eRenderStage);
9697
DECLARE_ENUM_CLASS(FxParticleSystems);
98+
DECLARE_ENUM_CLASS(eShadowTextureType);
99+
DECLARE_ENUM_CLASS(eShadowType);
97100
DECLARE_ENUM(ePools);
98101
DECLARE_ENUM_CLASS(WorldProperty);
99102
DECLARE_ENUM_CLASS(eModelLoadState);
@@ -522,6 +525,14 @@ inline SString GetClassTypeName(WorldProperty*)
522525
{
523526
return "world-property";
524527
}
528+
inline SString GetClassTypeName(eShadowTextureType*)
529+
{
530+
return "shadow-texture-type";
531+
}
532+
inline SString GetClassTypeName(eShadowType*)
533+
{
534+
return "shadow-type";
535+
}
525536

526537
inline SString GetClassTypeName(CClientVectorGraphic*)
527538
{

Client/mods/deathmatch/logic/luadefs/CLuaEffectDefs.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "StdInc.h"
1313
#include "lua/CLuaFunctionParser.h"
14+
#include <game/CFx.h>
1415

1516
void CLuaEffectDefs::LoadFunctions()
1617
{
@@ -35,6 +36,7 @@ void CLuaEffectDefs::LoadFunctions()
3536
{"setEffectDensity", SetEffectDensity},
3637
{"getEffectDensity", GetEffectDensity},
3738
{"fxCreateParticle", ArgumentParser<FxCreateParticle>},
39+
{"fxAddShadow", ArgumentParser<FxAddShadow>},
3840
};
3941

4042
// Add functions
@@ -62,6 +64,7 @@ void CLuaEffectDefs::AddClass(lua_State* luaVM)
6264
lua_classfunction(luaVM, "addWaterSplash", "fxAddWaterSplash");
6365
lua_classfunction(luaVM, "addWood", "fxAddWood");
6466
lua_classfunction(luaVM, "createParticle", "fxCreateParticle");
67+
lua_classfunction(luaVM, "createShadow", "fxAddShadow");
6568

6669
lua_classfunction(luaVM, "setDensity", "setEffectDensity");
6770
lua_classfunction(luaVM, "setSpeed", "setEffectSpeed");
@@ -647,3 +650,23 @@ bool CLuaEffectDefs::FxCreateParticle(FxParticleSystems eParticleSystem, CVector
647650
{
648651
return CStaticFunctionDefinitions::FxCreateParticle(eParticleSystem, vecPosition, vecDirection, fR/255, fG/255, fB/255, fA/255, bRandomizeColors.value_or(false), iCount.value_or(1), fBrightness.value_or(1.0f), fSize.value_or(0.3f), bRandomizeSizes.value_or(false), fLife.value_or(1.0f));
649652
}
653+
654+
bool CLuaEffectDefs::FxAddShadow(eShadowTextureType shadowTextureType, CVector vecPosition, CVector2D vecOffset1, CVector2D vecOffset2, SColor color,
655+
eShadowType shadowType,
656+
float zDistance, bool bDrawOnWater, bool bDrawOnBuildings)
657+
{
658+
if (vecOffset1.Length() > 32)
659+
{
660+
throw std::invalid_argument("First offset can not be longer than 32 units");
661+
}
662+
else if (vecOffset2.Length() > 32) // bigger and close to limit shadows size can be partially invisible
663+
{
664+
throw std::invalid_argument("Second offset can not be longer than 32 units");
665+
}
666+
else if (zDistance < 0 || zDistance > 3000) // negative distance not working
667+
{
668+
throw std::invalid_argument("Z Distance must be between 0.0 and 3000.0");
669+
}
670+
return CStaticFunctionDefinitions::FxAddShadow(shadowTextureType, vecPosition, vecOffset1, vecOffset2, color, shadowType, zDistance, bDrawOnWater,
671+
bDrawOnBuildings);
672+
}

Client/mods/deathmatch/logic/luadefs/CLuaEffectDefs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@ class CLuaEffectDefs : public CLuaDefs
3838
LUA_DECLARE(SetEffectDensity);
3939
LUA_DECLARE(GetEffectDensity);
4040

41-
static bool FxCreateParticle(FxParticleSystems eParticleSystem, CVector vecPosition, CVector vecDirection, float fR, float fG, float fB, float fA, std::optional<bool> bRandomizeColors, std::optional<std::uint32_t> iCount, std::optional<float> fBrightness, std::optional<float> fSize, std::optional<bool> bRandomizeSizes, std::optional<float> fLife);
41+
static bool FxCreateParticle(FxParticleSystems eParticleSystem, CVector vecPosition, CVector vecDirection, float fR, float fG, float fB, float fA,
42+
std::optional<bool> bRandomizeColors, std::optional<std::uint32_t> iCount, std::optional<float> fBrightness,
43+
std::optional<float> fSize, std::optional<bool> bRandomizeSizes, std::optional<float> fLife);
44+
static bool FxAddShadow(eShadowTextureType shadowTextureType, CVector vecPosition, CVector2D vecOffset1, CVector2D vecOffset2, SColor color,
45+
eShadowType shadowType, float zDistance, bool bDrawOnWater, bool bDrawOnBuildings);
4246
};

Client/sdk/game/CFx.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,41 @@
1111

1212
#pragma once
1313
#include "enums/FxParticleSystems.h"
14+
#include <SharedUtil.Misc.h>
1415

1516
class CEntity;
1617
class CVector;
18+
class CVector2D;
1719
class CVehicle;
1820
struct RwColor;
1921

22+
enum class eShadowTextureType
23+
{
24+
// use only color instead of texture
25+
PLANE = -1,
26+
CAR,
27+
PED,
28+
HELI,
29+
BIKE,
30+
RCBARON,
31+
EXPLOSION,
32+
HEADLIGHT1,
33+
HEADLIGHT2,
34+
BLOOD,
35+
HANDMAN,
36+
WINCRACK,
37+
LAMP,
38+
};
39+
40+
enum class eShadowType
41+
{
42+
NONE,
43+
DEFAULT,
44+
ADDITIVE,
45+
INVCOLOR,
46+
};
47+
48+
2049
class CFx
2150
{
2251
public:
@@ -36,4 +65,6 @@ class CFx
3665
virtual void TriggerBulletSplash(CVector& vecPosition) = 0;
3766
virtual void TriggerFootSplash(CVector& vecPosition) = 0;
3867
virtual void AddParticle(FxParticleSystems eFxParticle, const CVector& vecPosition, const CVector& vecDirection, float fR, float fG, float fB, float fA, bool bRandomizeColors, std::uint32_t iCount, float fBrightness, float fSize, bool bRandomizeSizes, float fLife) = 0;
68+
virtual bool AddShadow(eShadowTextureType shadowTextureType, const CVector& vecPosition, const CVector2D& vecOffset1, const CVector2D& vecOffset2,
69+
SharedUtil::SColor color, eShadowType shadowType, float fZDistance, bool bDrawOnWater, bool bDrawOnBuildings) = 0;
3970
};

0 commit comments

Comments
 (0)