Skip to content

Commit

Permalink
ChaosMod: Make effect global data thread local
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Jan 19, 2025
1 parent 88b6b8c commit c5474a1
Show file tree
Hide file tree
Showing 93 changed files with 276 additions and 280 deletions.
2 changes: 1 addition & 1 deletion ChaosMod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ target_link_directories(ChaosMod PUBLIC ${PROJECT_SOURCE_DIR}/../vendor/lua)
target_link_libraries(ChaosMod PUBLIC ${link_libs})

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(ChaosMod PUBLIC -DUNICODE -D_UNICODE -DNOMINMAX /Zi)
target_compile_options(ChaosMod PUBLIC -DUNICODE -D_UNICODE -DNOMINMAX /Zi /GT)
target_link_options(ChaosMod PUBLIC /DEBUG /OPT:REF /OPT:ICF)
else()
target_compile_options(ChaosMod PUBLIC -municode)
Expand Down
3 changes: 2 additions & 1 deletion ChaosMod/Effects/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include "Components/LuaScripts.h"

#include "Effects/EffectIdentifier.h"
#include "Effects/EffectTimedType.h"
#include "Effects/EffectsInfo.h"

#include "Util/File.h"

#include <algorithm>
#include <string>

#define CHAOS_VAR static thread_local

#define _EFFECT_CONCAT(a, b) a##b
#define EFFECT_CONCAT(a, b) _EFFECT_CONCAT(a, b)
#define REGISTER_EFFECT(OnStart, OnStop, OnTick, ...) \
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Effects/db/Misc/MiscAirstrike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <stdafx.h>

static int lastAirStrike = 0;
static Hash airstrikeHash;
CHAOS_VAR int lastAirStrike = 0;
CHAOS_VAR Hash airstrikeHash;

static void OnStart()
{
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Effects/db/Misc/MiscBlackHole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "Util/XInput.h"

static Vector3 ms_BlackHolePos;
static float ms_CurRadius;
CHAOS_VAR Vector3 ms_BlackHolePos;
CHAOS_VAR float ms_CurRadius;

static void OnStart()
{
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Effects/db/Misc/MiscCloneOnDeath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ struct TemporarilyInvincibleEntity
}
};

static std::vector<TemporarilyInvincibleEntity> temporarilyInvincibleEntities;
CHAOS_VAR std::vector<TemporarilyInvincibleEntity> temporarilyInvincibleEntities;

static std::vector<Entity> excludeEntities;
CHAOS_VAR std::vector<Entity> excludeEntities;

static void OnStart()
{
Expand Down
6 changes: 2 additions & 4 deletions ChaosMod/Effects/db/Misc/MiscCocktail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

#include <stdafx.h>

#include "Memory/Gravity.h"

#define PI 3.14159265

static float x, y;
CHAOS_VAR float x, y;

static DWORD lastTick = 0;
CHAOS_VAR DWORD lastTick = 0;
static void OnStart()
{
Ped playerPed = PLAYER_PED_ID();
Expand Down
10 changes: 5 additions & 5 deletions ChaosMod/Effects/db/Misc/MiscEsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
// This file is manually formatted.
// clang-format off

static const float maxDistance = 75.0f;
static const float thickness = 0.001f;
CHAOS_VAR const float maxDistance = 75.0f;
CHAOS_VAR const float thickness = 0.001f;

static Color lineColor;
CHAOS_VAR Color lineColor;

static const std::array<int, 19> BONE_IDS = {
CHAOS_VAR const std::array<int, 19> BONE_IDS = {
0x796e, 0x9995, 0xfcd9, 0x58b7,
0xb1c5, 0xeeeb, 0x49d9, 0x29d2,
0x0bb0, 0x9d4d, 0x6e5c, 0xdead,
0x2e28, 0xe39f, 0xf9bb, 0xca72,
0x9000, 0x3779, 0xcc4d
};

constexpr std::array<std::array<int, 2>, 14> connections = {{
CHAOS_VAR std::array<std::array<int, 2>, 14> connections = {{
{ 0, 1 }, { 1, 4 }, { 4, 5 }, { 5, 6 },
{ 1, 9 }, { 9, 10 }, { 10, 11 }, { 1, 12 },
{ 12, 13 }, { 13, 14 }, { 12, 15 }, { 15, 16 },
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Misc/MiscFireworks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <stdafx.h>

static int last_firework = 0;
CHAOS_VAR int last_firework = 0;

static void OnStart()
{
Expand Down
6 changes: 3 additions & 3 deletions ChaosMod/Effects/db/Misc/MiscFlamethrower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ struct ShooterInfo
int FxHandle = 0;
};

static int MAX_DURATION_BETWEEN_SHOTS = 10;
static int MAX_DURATION_ANIMATION = 150;
CHAOS_VAR int MAX_DURATION_BETWEEN_SHOTS = 10;
CHAOS_VAR int MAX_DURATION_ANIMATION = 150;

static std::map<Ped, ShooterInfo> animationHandleByPed;
CHAOS_VAR std::map<Ped, ShooterInfo> animationHandleByPed;

static void OnStop()
{
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Misc/MiscGoToJail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <stdafx.h>

static const Vector3 destination = Vector3::Init(473.1f, -1023.5f, 28.1f);
CHAOS_VAR const Vector3 destination = Vector3::Init(473.1f, -1023.5f, 28.1f);

static void OnStart()
{
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Misc/MiscHighPitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Memory/Hooks/AudioPitchHook.h"

static int ms_TargetPitch;
CHAOS_VAR int ms_TargetPitch;

static void OnStart()
{
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Misc/MiscJumpyProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct PropData
int startOffset;
};

static std::map<Object, PropData> propDataMap = {};
CHAOS_VAR std::map<Object, PropData> propDataMap = {};

static void OnTick()
{
Expand Down
6 changes: 3 additions & 3 deletions ChaosMod/Effects/db/Misc/MiscLag.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <stdafx.h>

static int ms_State;
static std::map<Ped, Vector3> ms_ToTpPeds;
static std::map<Vehicle, Vector3> ms_ToTpVehs;
CHAOS_VAR int ms_State;
CHAOS_VAR std::map<Ped, Vector3> ms_ToTpPeds;
CHAOS_VAR std::map<Vehicle, Vector3> ms_ToTpVehs;

static void OnStart()
{
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Misc/MiscLowPitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Effect by ProfessorBiddle, but the code is pretty much copied and pasted

static int ms_TargetPitch;
CHAOS_VAR int ms_TargetPitch;

static void OnStart()
{
Expand Down
80 changes: 40 additions & 40 deletions ChaosMod/Effects/db/Misc/MiscNewsTeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,63 @@ static Vector3 GetCoordsAround(Vector3 pos, float radius)
return res;
}

static Vehicle heli = 0;
static Ped pilot = 0;
static Camera heliCam = 0;
static int lastPositionGoal = 0;
static int scaleForm = 0;
static Vector3 targetCoords;
CHAOS_VAR Vehicle heli = 0;
CHAOS_VAR Ped pilot = 0;
CHAOS_VAR Camera heliCam = 0;
CHAOS_VAR int lastPositionGoal = 0;
CHAOS_VAR int scaleForm = 0;
CHAOS_VAR Vector3 targetCoords;

static const char *ms_TextPairs[] = { "Chaos Mod Player Trying To Survive",
"\"He won't survive\", Mod Contributors Say",
CHAOS_VAR const char *ms_TextPairs[] = { "Chaos Mod Player Trying To Survive",
"\"He won't survive\", Mod Contributors Say",

"Crazy Lunatic Going On A Rampage",
"This Report Was Brought To You By eCola",
"Crazy Lunatic Going On A Rampage",
"This Report Was Brought To You By eCola",

"The Aftermath Of An Experiment Gone Wrong",
"THE NEXT HEADLINE WILL TOTALLY SHOCK YOU!",
"The Aftermath Of An Experiment Gone Wrong",
"THE NEXT HEADLINE WILL TOTALLY SHOCK YOU!",

"Wow Look At This",
"Crazy Ain't It?",
"Wow Look At This",
"Crazy Ain't It?",

"An Example Of Our Average Law-Abiding Citizen",
"\"Video Games cause violence\" Officials Say",
"An Example Of Our Average Law-Abiding Citizen",
"\"Video Games cause violence\" Officials Say",

"Holy Shit Wow Omg",
"LULW WTFFF xDDDDDDDD",
"Holy Shit Wow Omg",
"LULW WTFFF xDDDDDDDD",

"What Bad RNG Looks Like",
"Researchers Estimate The Chances Being Close To Millions To One",
"What Bad RNG Looks Like",
"Researchers Estimate The Chances Being Close To Millions To One",

"A Speedrunner In Action",
"Criticizers Claim Mods Might Be At Play",
"A Speedrunner In Action",
"Criticizers Claim Mods Might Be At Play",

"An Ongoing Riot All Over San Andreas",
"A War Ensued Between The So Claimed \"Bus Bois\" And \"Scooter Brothers\"",
"An Ongoing Riot All Over San Andreas",
"A War Ensued Between The So Claimed \"Bus Bois\" And \"Scooter Brothers\"",

"Hey You're On Camera",
"Come On Do Something Cool!",
"Hey You're On Camera",
"Come On Do Something Cool!",

"Look Up And Smile",
"It's The LSPD",
"Look Up And Smile",
"It's The LSPD",

"This Is A Nice Scaleform",
"Wow Is This Self-Aware?",
"This Is A Nice Scaleform",
"Wow Is This Self-Aware?",

"This Is Why We Can't Have Nice Things",
"SMH",
"This Is Why We Can't Have Nice Things",
"SMH",

"IS THAT A SUPRA???",
":o",
"IS THAT A SUPRA???",
":o",

"Don't Mind Us",
"Just Getting Some Footage For The Trailer Of Expanded & Enhanced 2",
"Don't Mind Us",
"Just Getting Some Footage For The Trailer Of Expanded & Enhanced 2",

"HMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM",
"HMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM",
"HMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM",
"HMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM",

"Just Imagine All The Stuff I Could Put In Here",
"Oh Wait..." };
"Just Imagine All The Stuff I Could Put In Here",
"Oh Wait..." };

static void OnStart()
{
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Effects/db/Misc/MiscNoWater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ struct CWaterQuad
};
static_assert(sizeof(CWaterQuad) == 0x1C);

static CWaterQuad *WaterQuads;
static std::vector<float> WaterHeights;
CHAOS_VAR CWaterQuad *WaterQuads;
CHAOS_VAR std::vector<float> WaterHeights;

static CWaterQuad *GetWaterQuads()
{
Expand Down
42 changes: 21 additions & 21 deletions ChaosMod/Effects/db/Misc/MiscNothing.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#include <stdafx.h>

static const std::array options = { "Nothing",
"All Peds Are Peds",
"Teleport To Current Location",
"Expanded & Enhanced",
"Spawn Air",
"Destroy All Destroyed Vehicles",
"Kill All Dead Peds",
"+0 Wanted Stars",
"Jesus Watches Over You",
"Set Time To Current Time",
"Set Player Into Current Vehicle",
"All Cops Are Cops",
"Aim to Point Gun",
"Give Everyone A Nose",
"Teleport Player A Few Millimeters",
"Flying Birds",
"Teleport All Elephants To Player",
"PC Experience",
"All Enemies Attack Player",
"No Crash",
" " };
CHAOS_VAR const std::array options = { "Nothing",
"All Peds Are Peds",
"Teleport To Current Location",
"Expanded & Enhanced",
"Spawn Air",
"Destroy All Destroyed Vehicles",
"Kill All Dead Peds",
"+0 Wanted Stars",
"Jesus Watches Over You",
"Set Time To Current Time",
"Set Player Into Current Vehicle",
"All Cops Are Cops",
"Aim to Point Gun",
"Give Everyone A Nose",
"Teleport Player A Few Millimeters",
"Flying Birds",
"Teleport All Elephants To Player",
"PC Experience",
"All Enemies Attack Player",
"No Crash",
" " };

static void OnStart()
{
Expand Down
10 changes: 5 additions & 5 deletions ChaosMod/Effects/db/Misc/MiscPayRespects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

#define WAIT_TIME 10000 // ms

static int ms_Overlay = 0;
static const int ms_MaxPressInterval = 1000;
static int ms_LastPressTick = 0;
CHAOS_VAR int ms_Overlay = 0;
CHAOS_VAR const int ms_MaxPressInterval = 1000;
CHAOS_VAR int ms_LastPressTick = 0;

static DWORD64 ms_TimeReserve;
static DWORD64 ms_LastTick = 0;
CHAOS_VAR DWORD64 ms_TimeReserve;
CHAOS_VAR DWORD64 ms_LastTick = 0;

static inline bool Beepable(DWORD64 reserveValue)
{
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Effects/db/Misc/MiscPortraitMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <stdafx.h>

static const double maxBoxWidth = 0.35;
static double currentBoxWidth = 0;
CHAOS_VAR const double maxBoxWidth = 0.35;
CHAOS_VAR double currentBoxWidth = 0;

static void OnStart()
{
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Misc/MiscQuickSprunkStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <stdafx.h>

static const char *scriptName = "ob_vend1";
CHAOS_VAR const char *scriptName = "ob_vend1";

static void OnStart()
{
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Effects/db/Misc/MiscSpinningProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <stdafx.h>

// Degrees per millisecond, current value means 1.3 full rotations per second
static constexpr float ROTATION_SPEED = (1.3f * 360.f) / 1000.f;
CHAOS_VAR constexpr float ROTATION_SPEED = (1.3f * 360.f) / 1000.f;

static int lastTick = 0;
CHAOS_VAR int lastTick = 0;

static void OnStart()
{
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Misc/MiscTotalChaos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Memory/Physics.h"
#include "Util/XInput.h"

static DWORD64 ms_AnchorTick;
CHAOS_VAR DWORD64 ms_AnchorTick;

static void OnStart()
{
Expand Down
Loading

0 comments on commit c5474a1

Please sign in to comment.