Skip to content

Commit 77531ec

Browse files
committed
Crash fix (plane was sometimes working, sometimes not - instant crash)
1 parent edfc611 commit 77531ec

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

Client/game_sa/CFxSA.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
#include "CFxSA.h"
1717
#include "CEntitySA.h"
1818
;
19-
using StoreShadowToBeRendered_t = int(__cdecl*)(eShadowType, struct RwTexture*, const CVector*, float, float, float, float, short, unsigned char, unsigned char,
19+
using StoreShadowToBeRendered_t = int(__cdecl*)(eShadowType, RwTexture*, const CVector*, float, float, float, float, short, unsigned char, unsigned char,
2020
unsigned char, float, bool, float, class CRealTimeShadow*, bool);
21-
auto StoreShadowToBeRendered = reinterpret_cast<StoreShadowToBeRendered_t>(0x707390);
22-
unsigned short& CShadows_ShadowsStoredToBeRendered = *(unsigned short*)0xC403DC;
21+
inline auto StoreShadowToBeRendered = reinterpret_cast<StoreShadowToBeRendered_t>(FUNC_FXSystem_StoreShadows);
22+
inline unsigned short& CShadows_ShadowsStoredToBeRendered = *(unsigned short*)VAR_FXSystem_StoreShadows;
2323

2424
void CFxSA::AddBlood(CVector& vecPosition, CVector& vecDirection, int iCount, float fBrightness)
2525
{
@@ -340,19 +340,22 @@ void CFxSA::AddParticle(FxParticleSystems eFxParticle, const CVector& vecPositio
340340

341341
bool CFxSA::IsShadowsLimitReached()
342342
{
343-
constexpr int shadowsLimit = 48;
344-
return CShadows_ShadowsStoredToBeRendered >= shadowsLimit;
343+
// GTA:SA can handle max 48 shadows per frame
344+
return CShadows_ShadowsStoredToBeRendered >= 48;
345345
}
346346

347347
bool CFxSA::AddShadow(eShadowTextureType shadowTextureType, const CVector& vecPosition, const CVector2D& vecOffset1, const CVector2D& vecOffset2, SColor color,
348348
eShadowType shadowType, float fZDistance, bool bDrawOnWater, bool bDrawOnBuildings)
349349
{
350-
if (IsShadowsLimitReached())
350+
// Check if we can add more shadows this frame
351+
if (IsShadowsLimitReached() || shadowTextureType >= eShadowTextureType::COUNT)
351352
return false;
352353

353-
void* textureAddress = *(void**)(FUNC_FXSystem_BaseShadow + (int)shadowTextureType * 4);
354+
// Get the RwTexture for the shadow
355+
void* textureAddress = *(void**)(TEXTURE_FXSystem_Shadow + (int)shadowTextureType * 4);
354356
RwTexture* pRwTexture = reinterpret_cast<RwTexture*>(textureAddress);
355357

358+
// Store the shadow to be rendered
356359
return StoreShadowToBeRendered(shadowType, pRwTexture, &vecPosition, vecOffset1.fX, vecOffset1.fY, vecOffset2.fX, vecOffset2.fY, color.A, color.R, color.G,
357360
color.B, fZDistance, bDrawOnWater, 1, 0, bDrawOnBuildings);
358361
}

Client/game_sa/CFxSA.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class FxSystem_c;
3232
#define FUNC_CFx_TriggerBulletSplash 0x4a10e0
3333
#define FUNC_CFx_TriggerFootSplash 0x4a1150
3434
#define FUNC_FXSystem_c_AddParticle 0x4AA440
35-
#define FUNC_FXSystem_BaseShadow 0xC403E0
35+
#define FUNC_FXSystem_StoreShadows 0x707390
36+
#define VAR_FXSystem_StoreShadows 0xC403DC
37+
#define TEXTURE_FXSystem_Shadow 0xC403E0
3638
class CFxSAInterface
3739
{
3840
public:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,6 @@ ADD_ENUM(_D3DFORMAT::D3DFMT_A32B32G32R32F, "a32b32g32r32f")
861861
IMPLEMENT_ENUM_CLASS_END("surface-format")
862862

863863
IMPLEMENT_ENUM_CLASS_BEGIN(eShadowTextureType)
864-
ADD_ENUM(eShadowTextureType::PLANE, "plane")
865864
ADD_ENUM(eShadowTextureType::CAR, "car")
866865
ADD_ENUM(eShadowTextureType::PED, "ped")
867866
ADD_ENUM(eShadowTextureType::HELI, "heli")

Client/sdk/game/CFx.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ struct RwColor;
2121

2222
enum class eShadowTextureType
2323
{
24-
// use only color instead of texture
25-
PLANE = -1,
2624
CAR,
2725
PED,
2826
HELI,
@@ -35,6 +33,7 @@ enum class eShadowTextureType
3533
HANDMAN,
3634
WINCRACK,
3735
LAMP,
36+
COUNT
3837
};
3938

4039
enum class eShadowType

0 commit comments

Comments
 (0)