-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup, fix bugs, crashes and memory leaks
- Loading branch information
Showing
8 changed files
with
212 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: game_sa/C2DEffectSA.cpp | ||
* PURPOSE: 2DFX static class | ||
* | ||
* Multi Theft Auto is available from https://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#include "StdInc.h" | ||
#include "gamesa_renderware.h" | ||
#include "C2DEffectSA.h" | ||
#include "C2DEffectSAInterface.h" | ||
|
||
// C2DEffect::Shutdown causes random unknown crash in ntdll.dll so we need own function | ||
void C2DEffectSA::Shutdown(C2DEffectSAInterface* effect) | ||
{ | ||
if (!effect) | ||
return; | ||
|
||
if (effect->type == e2dEffectType::ROADSIGN) | ||
{ | ||
t2dEffectRoadsign& roadsign = effect->effect.roadsign; | ||
|
||
if (roadsign.text) | ||
{ | ||
std::free(roadsign.text); | ||
roadsign.text = nullptr; | ||
} | ||
|
||
if (roadsign.atomic) | ||
{ | ||
RwFrame* frame = RpAtomicGetFrame(roadsign.atomic); | ||
if (frame) | ||
{ | ||
RpAtomicSetFrame(roadsign.atomic, nullptr); | ||
RwFrameDestroy(frame); | ||
} | ||
|
||
RpAtomicDestroy(roadsign.atomic); | ||
roadsign.atomic = nullptr; | ||
} | ||
} | ||
else if (effect->type == e2dEffectType::LIGHT) | ||
{ | ||
t2dEffectLight& light = effect->effect.light; | ||
|
||
if (light.coronaTex) | ||
{ | ||
RwTextureDestroy(light.coronaTex); | ||
light.coronaTex = nullptr; | ||
} | ||
|
||
if (light.shadowTex) | ||
{ | ||
RwTextureDestroy(light.shadowTex); | ||
light.shadowTex = nullptr; | ||
} | ||
} | ||
} | ||
|
||
void C2DEffectSA::SafeDelete2DFXEffect(C2DEffectSAInterface* effect) | ||
{ | ||
if (!effect) | ||
return; | ||
|
||
if (effect->type == e2dEffectType::ROADSIGN || effect->type == e2dEffectType::LIGHT) | ||
Shutdown(effect); | ||
|
||
delete effect; | ||
effect = nullptr; | ||
} | ||
|
||
void C2DEffectSA::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) | ||
{ | ||
if (coronaTex && coronaName) | ||
RwTextureDestroy(coronaTex); | ||
if (shadowTex && shadowName) | ||
RwTextureDestroy(shadowTex); | ||
} | ||
|
||
if (coronaName) | ||
coronaTex = RwReadTexture(coronaName, nullptr); | ||
|
||
if (shadowName) | ||
shadowTex = RwReadTexture(shadowName, nullptr); | ||
|
||
// Call CTxdStore::PopCurrentTxd | ||
((void(__cdecl*)())FUNC_PopCurrentTxd)(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/***************************************************************************** | ||
* | ||
* PROJECT: Multi Theft Auto | ||
* LICENSE: See LICENSE in the top level directory | ||
* FILE: game_sa/C2DEffectSA.h | ||
* PURPOSE: Header file for 2dfx static class | ||
* | ||
* Multi Theft Auto is available from https://www.multitheftauto.com/ | ||
* | ||
*****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#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 | ||
|
||
// 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 FUNC_Fx_c_CreateEntityFx 0x4A11E0 | ||
#define VAR_G_Fx 0xA9AE00 | ||
#define OFFSET_FxSystem_Entities 0xC | ||
#define OFFSET_FxSystem_Link_Prev 0x4 | ||
|
||
class C2DEffectSAInterface; | ||
|
||
class C2DEffectSA | ||
{ | ||
public: | ||
static int effect2dPluginOffset; | ||
|
||
static void Shutdown(C2DEffectSAInterface* effect); | ||
static void SafeDelete2DFXEffect(C2DEffectSAInterface* effect); | ||
static void PrepareTexturesForLightEffect(RwTexture*& coronaTex, RwTexture*& shadowTex, const char* coronaName, const char* shadowName, bool removeIfExist); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.