77
88static void (*ResetFunction)();
99
10- static void (*OG_UpdateEffects)(int a );
11- static void HK_UpdateEffects (int a )
10+ static void (*OG_UpdateEffects)(int cycleType );
11+ static void HK_UpdateEffects (int cycleType )
1212{
13- OG_UpdateEffects (a );
14- GetComponent<ZChaosManager>()->RunEffectsOnTick (a );
13+ OG_UpdateEffects (cycleType );
14+ GetComponent<ZChaosManager>()->RunEffectsOnTick (cycleType );
1515}
1616
17- static __int64 (*OG_StartEffect)(__int64 a );
18- static __int64 HK_StartEffect (__int64 a )
17+ static __int64 (*OG_StartEffect)(ZChaosManager::ZChaosEffect* effect );
18+ static __int64 HK_StartEffect (ZChaosManager::ZChaosEffect *effect )
1919{
20+ LOG (" Trying to trigger effect " << effect->name );
21+ const auto effectId = GetComponent<ZChaosManager>()->GetIdForEffect (effect);
22+ if ((!GetRegisteredEffect (effectId) || !g_dictEnabledEffects.contains (effectId)) && !effect->enabledManually )
23+ {
24+ return 0 ;
25+ }
26+ if (!GetRegisteredEffect (effectId))
27+ {
28+ GetComponent<ZChaosManager>()->RegisterZChaosEffect (effect, effectId);
29+ }
30+ if (!g_dictEnabledEffects.contains (effectId))
31+ {
32+ GetComponent<ZChaosManager>()->EnableEffect (effect, effectId);
33+ }
34+ GetComponent<EffectDispatcher>()->DispatchEffect (effectId);
35+
2036 return 0 ;
2137}
2238
39+ static std::vector<std::pair<const char *, const char *>> labelOverrides = {
40+ { " ~r~CHAOS WARNING" , " ~r~There used to be a warning here... right?" },
41+ { " ~r~AAAAAAAAAAAAA" , " ~r~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" },
42+ { " ~r~CHAOS WARNING" , " ~r~Something version something something, no one cares" },
43+ { " ~r~Oh no!" , " ~r~The game crashed, you'll have to start over again" },
44+ { " ~r~warning" , " ~r~not so scary now, huh?" },
45+ { " ~r~BOO!" , " ~r~The above text is very spooky, be scared" },
46+ { " ~b~I'm blue" , " ~b~Da ba dee da ba dae" },
47+ { " ~r~DID YOU KNOW" , " ~r~THAT A JIFFY IS AN ACTUAL MEASUREMENT OF TIME???" },
48+ { " ~r~blalala" , " ~r~blelelelelelelele" },
49+ { " ~r~PLINK" , " ~r~OR BUHH????" },
50+ };
51+
52+ void ZChaosManager::RegisterZChaosEffect (ZChaosEffect *effect, std::string effectId)
53+ {
54+ if (effect->m_OnTick )
55+ {
56+ g_RegisteredEffects.emplace_back (
57+ effectId,
58+ [this , effect, effectId]() -> void
59+ {
60+ ZChaosEffect e (*effect);
61+ m_rgActiveZChaosEffects.emplace (effectId, e);
62+ if (e.m_OnStart )
63+ {
64+ e.m_OnStart (&e);
65+ }
66+ e.cutoutTime = 0 ;
67+ },
68+ [this , effectId]() -> void
69+ {
70+ auto effect = &m_rgActiveZChaosEffects.at (effectId);
71+ effect->time = -1000 ;
72+ effect->cutoutTime = 0 ;
73+ },
74+ [this , effectId]() -> void
75+ {
76+ auto effect = &m_rgActiveZChaosEffects.at (effectId);
77+ effect->time = GetComponent<EffectDispatcher>()->GetRemainingTimeForEffect (effectId) * 1000 ;
78+ });
79+ }
80+ else
81+ {
82+ g_RegisteredEffects.emplace_back (
83+ effectId,
84+ [this , effect, effectId]() -> void
85+ {
86+ ZChaosEffect e (*effect);
87+ if (e.m_OnStart )
88+ {
89+ e.m_OnStart (&e);
90+ }
91+ e.cutoutTime = 0 ;
92+ },
93+ nullptr , nullptr );
94+ }
95+ }
96+
97+ void ZChaosManager::EnableEffect (ZChaosManager::ZChaosEffect* effect, std::string effectId)
98+ {
99+ EffectData effectData;
100+ effectData.Name = effect->name ;
101+ effectData.Id = effectId;
102+ effectData.TimedType = effect->m_OnTick ? EEffectTimedType::Custom : EEffectTimedType::NotTimed;
103+ if (effect->m_OnTick )
104+ {
105+ effectData.CustomTime = effect->defaultTime / 1000 ;
106+ }
107+
108+ g_dictEnabledEffects.emplace (effectId, effectData);
109+ }
110+
23111void ZChaosManager::CheckAndAddEffects ()
24112{
25113 for (int i = 0 ; i < m_iEffectCount; ++i)
@@ -32,38 +120,13 @@ void ZChaosManager::CheckAndAddEffects()
32120 continue ;
33121 }
34122
35- std::ostringstream oss;
36- oss << " zchaos_" << i << " _" ;
37- char *ptr = effect->name ;
38- for (char c = *ptr; c; c = *++ptr)
39- {
40- if (' a' <= c && c <= ' z' )
41- {
42- oss << c;
43- }
44- if (' A' <= c && c <= ' Z' )
45- {
46- oss << (char )(c - ' A' + ' a' );
47- }
48- }
49-
50- std::string effectId = oss.str ();
51-
52-
53- EffectData effectData;
54- effectData.Name = effect->name ;
55- effectData.Id = effectId;
56- effectData.TimedType = effect->m_OnTick ? EEffectTimedType::Custom : EEffectTimedType::NotTimed;
57- if (effect->m_OnTick )
58- {
59- effectData.CustomTime = effect->defaultTime / 1000 ;
60- }
123+ const auto effectId = GetIdForEffect (effect, i);
61124
62125 if ((!IsEffectEnabled || IsEffectEnabled (effect, false )) && effect->enabledManually )
63126 {
64127 if (!g_dictEnabledEffects.contains (effectId))
65128 {
66- g_dictEnabledEffects. emplace (effectId, effectData );
129+ EnableEffect (effect, effectId );
67130 LOG (" Effect " << effect->name << " has been enabled" );
68131 }
69132 }
@@ -78,50 +141,62 @@ void ZChaosManager::CheckAndAddEffects()
78141 continue ;
79142 }
80143
81- if (effect->m_OnTick )
144+ RegisterZChaosEffect (effect, effectId);
145+
146+ LOG (" Registered ZChaos effect \" " << effect->name << " \" with id " << effectId);
147+ }
148+ }
149+
150+ std::string ZChaosManager::GetIdForEffect (ZChaosEffect *effect)
151+ {
152+ for (int i = 0 ; i < m_iEffectCount; ++i)
153+ {
154+ if (effect->name == m_rgEffectsArray[i]->name )
155+ {
156+ return GetIdForEffect (effect, i);
157+ }
158+ }
159+
160+ return GetIdForEffect (effect, 100000 );
161+ }
162+
163+ std::string ZChaosManager::GetIdForEffect (ZChaosEffect *effect, int index)
164+ {
165+ std::ostringstream oss;
166+ oss << " zchaos_" << index << " _" ;
167+ char *ptr = effect->name ;
168+ for (char c = *ptr; c; c = *++ptr)
169+ {
170+ if (' a' <= c && c <= ' z' )
82171 {
83- g_RegisteredEffects.emplace_back (
84- effectId,
85- [this , effect, effectId]() -> void
86- {
87- ZChaosEffect e (*effect);
88- m_rgActiveZChaosEffects.emplace (effectId, e);
89- if (e.m_OnStart )
90- {
91- e.m_OnStart (&e);
92- }
93- e.cutoutTime = 0 ;
94- },
95- [this , effectId]() -> void
96- {
97- auto effect = &m_rgActiveZChaosEffects.at (effectId);
98- effect->time = -1000 ;
99- effect->cutoutTime = 0 ;
100- },
101- [this , effectId]() -> void
102- {
103- auto effect = &m_rgActiveZChaosEffects.at (effectId);
104- effect->time = GetComponent<EffectDispatcher>()->GetRemainingTimeForEffect (effectId) * 1000 ;
105- });
172+ oss << c;
106173 }
107- else
174+ if ( ' A ' <= c && c <= ' Z ' )
108175 {
109- g_RegisteredEffects.emplace_back (
110- effectId,
111- [this , effect, effectId]() -> void
112- {
113- ZChaosEffect e (*effect);
114- if (e.m_OnStart )
115- {
116- e.m_OnStart (&e);
117- }
118- e.cutoutTime = 0 ;
119- },
120- nullptr , nullptr );
176+ oss << (char )(c - ' A' + ' a' );
121177 }
178+ }
122179
123- LOG (" Registered ZChaos effect \" " << effect->name << " \" with id " << effectId);
180+ return oss.str ();
181+ }
182+
183+ static void OverrideStr (char *orig, const char *newValue)
184+ {
185+ int i = 0 ;
186+ for (; newValue[i]; ++i)
187+ {
188+ Memory::Write (orig + i, newValue[i]);
124189 }
190+ Memory::Write (orig + i, ' \0 ' );
191+ }
192+
193+ void ZChaosManager::OverrideWarning ()
194+ {
195+ *m_pWarningTime = 8 ;
196+ const auto pair = labelOverrides[g_Random.GetRandomInt (0 , labelOverrides.size () - 1 )];
197+
198+ OverrideStr (m_pWarningStr, pair.first );
199+ OverrideStr (m_pWarningStr2, pair.second );
125200}
126201
127202ZChaosManager::ZChaosManager ()
@@ -130,7 +205,10 @@ ZChaosManager::ZChaosManager()
130205 IsEffectEnabled(nullptr ),
131206 m_pDisableChaosUI(nullptr ),
132207 m_pNoTimer(nullptr ),
133- m_pZChaosActive(nullptr )
208+ m_pZChaosActive(nullptr ),
209+ m_pWarningTime(nullptr ),
210+ m_pWarningStr(nullptr ),
211+ m_pWarningStr2(nullptr )
134212{
135213 auto lib = GetModuleHandle (L" ZChaosV.asi" );
136214 if (!lib)
@@ -159,19 +237,26 @@ ZChaosManager::ZChaosManager()
159237 LOG (" Added update effects hook" );
160238 }
161239
162- handle = Memory::FindPattern (" 0F B6 3D ?? ?? ?? ?? 8B 05" , range);
240+ handle = Memory::FindPattern (" 0F B6 3D ?? ?? ?? ?? 8B 05" , range);
163241 m_pZChaosActive = handle.At (2 ).Into ().Get <char >();
164242
165- handle = Memory::FindPattern (" 44 38 3D ?? ?? ?? ?? 75 09 41 0F 28 C2" , range);
243+ handle = Memory::FindPattern (" 44 38 3D ?? ?? ?? ?? 75 09 41 0F 28 C2" , range);
166244 m_pDisableChaosUI = handle.At (2 ).Into ().Get <char >();
167245
168- handle = Memory::FindPattern (" 44 38 3D ?? ?? ?? ?? 0F 85 48 03 00 00" , range);
246+ handle = Memory::FindPattern (" 44 38 3D ?? ?? ?? ?? 0F 85 48 03 00 00" , range);
169247 m_pNoTimer = handle.At (2 ).Into ().Get <char >();
170248
171- handle = Memory::FindPattern (" 40 53 48 83 EC 20 33 C0 48 " , range);
172- IsEffectEnabled = handle.Get < bool (ZChaosEffect *, bool ) >();
249+ handle = Memory::FindPattern (" F2 0F 10 0D ?? ?? ?? ?? 66 41 0F 2F C8 0F 86 00 01 00 00 " , range);
250+ m_pWarningTime = handle.At ( 3 ). Into (). Get < double >();
173251
174- LOG (IsEffectEnabled);
252+ handle = Memory::FindPattern (" 48 8D 05 ?? ?? ?? ?? 48 89 44 24 60 BF FF 00 00 00" , range);
253+ m_pWarningStr = handle.At (2 ).Into ().Get <char >();
254+
255+ handle = Memory::FindPattern (" 48 8D 05 ?? ?? ?? ?? 48 89 44 24 60 89 7C 24 58" , range);
256+ m_pWarningStr2 = handle.At (2 ).Into ().Get <char >();
257+
258+ handle = Memory::FindPattern (" 40 53 48 83 EC 20 33 C0 48" , range);
259+ IsEffectEnabled = handle.Get <bool (ZChaosEffect *, bool )>();
175260
176261 auto GetZChaosVersion = (void (*)(int *version, int *success))GetProcAddress (lib, " GetZChaosVersion" );
177262 auto GetZChaosEffectCount = (int (*)())GetProcAddress (lib, " GetZChaosEffectCount" );
@@ -200,6 +285,10 @@ ZChaosManager::ZChaosManager()
200285 LOG (" Added start effect hook" );
201286 }
202287
288+ if (m_pWarningTime && *m_pWarningTime > 0 )
289+ {
290+ OverrideWarning ();
291+ }
203292 CheckAndAddEffects ();
204293}
205294
@@ -236,32 +325,8 @@ void ZChaosManager::OnModPauseCleanup()
236325 continue ;
237326 }
238327
239- std::ostringstream oss;
240- oss << " zchaos_" << i << " _" ;
241- char *ptr = effect->name ;
242- for (char c = *ptr; c; c = *++ptr)
243- {
244- if (' a' <= c && c <= ' z' )
245- {
246- oss << c;
247- }
248- if (' A' <= c && c <= ' Z' )
249- {
250- oss << (char )(c - ' A' + ' a' );
251- }
252- }
253-
254- std::string effectId = oss.str ();
255-
256- EffectData effectData;
257- effectData.Name = effect->name ;
258- effectData.Id = effectId;
259- effectData.TimedType = effect->m_OnTick ? EEffectTimedType::Custom : EEffectTimedType::NotTimed;
260- if (effect->m_OnTick )
261- {
262- effectData.CustomTime = effect->defaultTime / 1000 ;
263- }
264-
328+ std::string effectId = GetIdForEffect (effect);
329+
265330 if (g_dictEnabledEffects.contains (effectId))
266331 {
267332 g_dictEnabledEffects.erase (effectId);
@@ -281,14 +346,14 @@ void ZChaosManager::OnModPauseCleanup()
281346 m_iEffectCount = 0 ;
282347}
283348
284- void ZChaosManager::RunEffectsOnTick (int a )
349+ void ZChaosManager::RunEffectsOnTick (int cycleType )
285350{
286351 for (auto it = m_rgActiveZChaosEffects.begin (); it != m_rgActiveZChaosEffects.end ();)
287352 {
288353 auto &[effectId, effect] = *it;
289354 bool flag = false ;
290355
291- if (effect.m_OnTick && effect.field_28 == a )
356+ if (effect.m_OnTick && effect.cycleType == cycleType )
292357 {
293358 effect.m_OnTick (&effect);
294359 if ((double )effect.time * 0.001 <= effect.cutoutTime )
0 commit comments