Skip to content

Commit

Permalink
Clean & Rework
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Sep 20, 2024
1 parent 1d2c3f5 commit dba4364
Show file tree
Hide file tree
Showing 16 changed files with 1,126 additions and 382 deletions.
90 changes: 87 additions & 3 deletions Client/game_sa/C2DEffectSAInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,30 @@
#pragma once

#include "game/RenderWare.h"
#include "game/CModelInfo.h"
#include "CObjectSA.h"

#define ARRAY_2DFXInfoStore 0xB4C2D8 // C2dfxInfoStore d2fxModels

#define FUNC_C2DEffect_Shutdown 0x4C57D0
#define FUNC_PushCurrentTxd 0x7316A0
#define FUNC_FindTxdSlot 0x731850
#define FUNC_SetCurrentTxd 0x7319C0
#define FUNC_PopCurrentTxd 0x7316B0
#define FUNC_RwReadTexture 0x7F3AC0

// Escalators stuff
#define ARRAY_CEscalators 0xC6E9A8
#define NUM_MAX_ESCALATORS 32
#define FUNC_CEscalator_SwitchOff 0x717860

// fx stuff
#define FUNC_Fx_c_DestroyEntityFx 0x4A1280
#define VAR_G_Fx 0xA9AE00
#define OFFSET_FxSystem_Entities 0xC
#define OFFSET_FxSystem_Link_Prev 0x4

#define FUNC_RwTextureDestroy 0x7F3820

struct t2dEffectLight
{
RwColor color;
Expand Down Expand Up @@ -131,7 +151,7 @@ struct t2dEffectRoadsign
};

std::uint8_t field_16[2];
char* text; // size 64
char* text; // size 64
RpAtomic* atomic;
};

Expand All @@ -154,6 +174,7 @@ struct t2dEffectEscalator
};

// Example in kb_bandit_u.dff
// Used to determine additional coordinates that can be used in scripts
struct t2dEffectTriggerPoint
{
std::int32_t id;
Expand Down Expand Up @@ -215,5 +236,68 @@ class C2DEffectInfoStoreSAInterface
{
public:
std::uint32_t objCount;
C2DEffectSAInterface objects[180]; // or 100
C2DEffectSAInterface objects[100];
};

class C2DEffectPluginDataSAInterface
{
public:
std::uint32_t count;
C2DEffectSAInterface objects[];
};

class CEscalatorSAInterface
{
public:
RwV3d startPos;
RwV3d bottomPos;
RwV3d topPos;
RwV3d endPos;
std::uint8_t rotation[72]; // CMatrixSAInterface
bool exist;
bool objectCreated;
bool moveDown;
std::uint8_t field_7B; // pad
std::int32_t numIntermediatePlanes;
std::uint32_t numBottomPlanes;
std::uint32_t numTopPlanes;
std::uint8_t field_88[8]; // unused field
RwSphere bounding;
float currentPosition;
CEntitySAInterface* entity;
CObjectSAInterface* objects[42];
};

class C2DEffectSA
{
public:
static int effect2dPluginOffset;
};

static void PrepareTexturesForLightEffect(RwTexture* coronaTex, RwTexture* shadowTex, const char* coronaName, const char* shadowName, bool removeIfExist)
{
// Call CTxdStore::PushCurrentTxd
((void(__cdecl*)())FUNC_PushCurrentTxd)();
// Call CTxdStore::FindTxdSlot
int slot = ((int(__cdecl*)(const char*))FUNC_FindTxdSlot)("particle");
// Call CTxdStore::SetCurrentTxd
((void(__cdecl*)(int))FUNC_SetCurrentTxd)(slot);

if (removeIfExist)
{
using RwTextureDestroy = void(__cdecl*)(RwTexture*);

if (coronaTex)
((RwTextureDestroy)FUNC_RwTextureDestroy)(coronaTex);
if (shadowTex)
((RwTextureDestroy)FUNC_RwTextureDestroy)(shadowTex);
}

// Call RwReadTexture
using RwReadTexture = RwTexture*(__cdecl*)(const char*, const char*);
coronaTex = ((RwReadTexture)FUNC_RwReadTexture)(coronaName, nullptr);
shadowTex = ((RwReadTexture)FUNC_RwReadTexture)(shadowName, nullptr);

// Call CTxdStore::PopCurrentTxd
((void(__cdecl*)())FUNC_PopCurrentTxd)();
}
4 changes: 2 additions & 2 deletions Client/game_sa/CFxSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void CFxSA::AddParticle(eFxParticleSystems eFxParticle, const CVector& vecPositi
FxPrtMult_c fxPrt{{fR,fG,fB,fA}, fSize, 0, fLife};
CVector newDirection;

FxSystem_c* fxParticleSystem;
FxSystem_cSAInterface* fxParticleSystem;

switch (eFxParticle)
{
Expand Down Expand Up @@ -326,6 +326,6 @@ void CFxSA::AddParticle(eFxParticleSystems eFxParticle, const CVector& vecPositi
newDirection.fZ = (rand() % 10000) * 0.0001f * 4 - 2 + newDirection.fZ;

// Call FxSystem_c::AddParticle
((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);
((int(__thiscall*)(FxSystem_cSAInterface*, 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);
}
}
150 changes: 114 additions & 36 deletions Client/game_sa/CFxSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,125 @@
#pragma once

#include <game/CFx.h>
#include "CFxSystemBPSA.h"
#include "CVector.h"

struct RwColor;
class FxSystem_c;

#define FUNC_CFx_AddBlood 0x49eb00
#define FUNC_CFx_AddWood 0x49ee10
#define FUNC_CFx_AddSparks 0x49f040
#define FUNC_CFx_AddTyreBurst 0x49f300
#define FUNC_CFx_AddBulletImpact 0x49f3d0
#define FUNC_CFx_AddPunchImpact 0x49f670
#define FUNC_CFx_AddDebris 0x49f750
#define FUNC_CFx_AddGlass 0x49f970
#define FUNC_CFx_TriggerWaterHydrant 0x4a0d70
#define FUNC_CFx_TriggerGunshot 0x4a0de0
#define FUNC_CFx_TriggerTankFire 0x4a0fa0
#define FUNC_CFx_TriggerWaterSplash 0x4a1070
#define FUNC_CFx_TriggerBulletSplash 0x4a10e0
#define FUNC_CFx_TriggerFootSplash 0x4a1150
#define FUNC_FXSystem_c_AddParticle 0x4AA440
struct RwRaster;
struct RwMatrix;

#define FUNC_CFx_AddBlood 0x49eb00
#define FUNC_CFx_AddWood 0x49ee10
#define FUNC_CFx_AddSparks 0x49f040
#define FUNC_CFx_AddTyreBurst 0x49f300
#define FUNC_CFx_AddBulletImpact 0x49f3d0
#define FUNC_CFx_AddPunchImpact 0x49f670
#define FUNC_CFx_AddDebris 0x49f750
#define FUNC_CFx_AddGlass 0x49f970
#define FUNC_CFx_TriggerWaterHydrant 0x4a0d70
#define FUNC_CFx_TriggerGunshot 0x4a0de0
#define FUNC_CFx_TriggerTankFire 0x4a0fa0
#define FUNC_CFx_TriggerWaterSplash 0x4a1070
#define FUNC_CFx_TriggerBulletSplash 0x4a10e0
#define FUNC_CFx_TriggerFootSplash 0x4a1150
#define FUNC_FxSystem_c_AddParticle 0x4AA440

enum class eFXQuality : std::uint32_t
{
QUALITY_LOW = 0,
QUALITY_MEDIUM,
QUALITY_HIGH,
QUALITY_VERY_HIGH,
};

enum class eFxSystemPlayState : std::uint8_t
{
PLAYING = 0,
STOPPED,
UNKNOWN,
};

enum class eFxSystemKillState : std::uint8_t
{
NOT_KILLED = 0,
PLAY_AND_KILL,
KILLED,
UNKNOWN,
};

class FxSystem_cSAInterface
{
public:
std::uint32_t m_link[2]; // ListItem_c
CFxSystemBPSAInterface* m_bluePrint;
void* m_transformMatrix; // RwMatrixTag*
std::uint8_t m_baseMatrix[64]; // RwMatrixTag
eFxSystemPlayState m_playState;
eFxSystemKillState m_killState;
bool m_useConstTime;
std::uint8_t field_53[2];
float m_cameraDistance;
std::uint16_t m_constTime;
std::uint16_t m_rateMult;
std::uint16_t m_timeMult;

union
{
struct
{
std::uint8_t m_hasOwnMatrix : 1;
std::uint8_t m_local : 1;
std::uint8_t m_useZTest : 1;
std::uint8_t m_stopParticleCreation : 1;
std::uint8_t m_prevCulled : 1;
std::uint8_t m_mustCreateParticles : 1;
};

std::uint8_t flags;
};

std::uint8_t field_63;
float m_loopInterval;
CVector m_velAdd;
void* m_boundingSphere; // CParticleBounding* or FxSphere_c*
void** m_primsList; // FxPrim_c**
std::uint8_t m_fireAE[136]; // CAEFireAudioEntity
};

class CFxSAInterface
{
public:
FxSystem_c* m_fxSysBlood;
FxSystem_c* m_fxSysBoatSplash;
FxSystem_c* m_fxSysBubble;
FxSystem_c* m_fxSysDebris;
FxSystem_c* m_fxSysSmoke;
FxSystem_c* m_fxSysGunshell;
FxSystem_c* m_fxSysSand;
FxSystem_c* m_fxSysSand2;
FxSystem_c* m_fxSysSmokeHuge;
FxSystem_c* m_fxSysSmoke2;
FxSystem_c* m_fxSysSpark;
FxSystem_c* m_fxSysSpark2;
FxSystem_c* m_fxSysSplash;
FxSystem_c* m_fxSysWake;
FxSystem_c* m_fxSysWaterSplash;
FxSystem_c* m_fxSysWheelDirt;
FxSystem_c* m_fxSysGlass;
FxSystem_cSAInterface* m_fxSysBlood;
FxSystem_cSAInterface* m_fxSysBoatSplash;
FxSystem_cSAInterface* m_fxSysBubble;
FxSystem_cSAInterface* m_fxSysDebris;
FxSystem_cSAInterface* m_fxSysSmoke;
FxSystem_cSAInterface* m_fxSysGunshell;
FxSystem_cSAInterface* m_fxSysSand;
FxSystem_cSAInterface* m_fxSysSand2;
FxSystem_cSAInterface* m_fxSysSmokeHuge;
FxSystem_cSAInterface* m_fxSysSmoke2;
FxSystem_cSAInterface* m_fxSysSpark;
FxSystem_cSAInterface* m_fxSysSpark2;
FxSystem_cSAInterface* m_fxSysSplash;
FxSystem_cSAInterface* m_fxSysWake;
FxSystem_cSAInterface* m_fxSysWaterSplash;
FxSystem_cSAInterface* m_fxSysWheelDirt;
FxSystem_cSAInterface* m_fxSysGlass;

private:
// List_c<??>
void* m_lastParticleEntity;
void* m_firstParticleEntity;
std::uint32_t m_particleEntitiesCount;

std::uint32_t m_numCreatedBloodPools;
eFXQuality m_fxQuality;
std::uint32_t m_verticesCount2;
std::uint32_t m_verticesCount;
std::uint32_t m_transformRenderFlags;
RwRaster* m_rasterToRender;
RwMatrix* m_transformLTM;
void* m_verts; // RxObjSpace3DVertex*
};

class CFxSA : public CFx
Expand All @@ -76,7 +153,8 @@ class CFxSA : public CFx
void TriggerWaterSplash(CVector& vecPosition);
void TriggerBulletSplash(CVector& vecPosition);
void TriggerFootSplash(CVector& vecPosition);
void AddParticle(eFxParticleSystems 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);
void AddParticle(eFxParticleSystems 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);

private:
CFxSAInterface* m_pInterface;
Expand Down
5 changes: 5 additions & 0 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,11 @@ void CGameSA::ResetAlphaTransparencies()
CModelInfoSA::StaticResetAlphaTransparencies();
}

void CGameSA::ResetModel2DFXEffects()
{
CModelInfoSA::StaticReset2DFXEffects();
}

// Disable VSync by forcing what normally happends at the end of the loading screens
// Note #1: This causes the D3D device to be reset after the next frame
// Note #2: Some players do not need this to disable VSync. (Possibly because their video card driver settings override it somewhere)
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class CGameSA : public CGame
void ResetModelLodDistances();
void ResetModelFlags();
void ResetAlphaTransparencies();
void ResetModel2DFXEffects();
void DisableVSync();
void ResetModelTimes();

Expand Down
Loading

0 comments on commit dba4364

Please sign in to comment.