casualexpiesource

cu-trainer/Ultra Paradise Application/src/Engine.cs

1505 lines · 58.7 KB · plain text · download

1using System.Collections;
2using System.Collections.Generic;
3using System.Text;
4using HarmonyLib;
5using UnityEngine;
6
7namespace UltraParadise
8{
9 internal static partial class Plugin
10 {
11 internal static void ApplyKeeps(Body b)
12 {
13 Limb[] ls = b.limbs;
14 if (ls != null && (NoBleeding.Value || NoPain.Value || NoInfection.Value))
15 {
16 for (int i = 0; i < ls.Length; i++)
17 {
18 Limb l = ls[i];
19 if (l == null || l.dismembered) continue;
20 if (NoBleeding.Value) l.bleedAmount = 0f;
21 if (NoPain.Value) l.pain = 0f;
22 if (NoInfection.Value) { l.infectionAmount = 0f; l.infected = false; }
23 }
24 }
25 if (NoBleeding.Value) { b.internalBleeding = 0f; b.hemothorax = 0f; }
26 if (NoPain.Value) b.painShock = 0f;
27 if (NoInfection.Value) b.septicShock = 0f;
28 if (NoSickness.Value) { b.sicknessAmount = 0f; b.venomCurrent = 0f; }
29 if (NoRadiation.Value) b.radiationSickness = 0f;
30 if (UnlimitedOxygen.Value) b.bloodOxygen = 100f;
31 if (StableTemperature.Value) b.temperature = 37f;
32 if (UnlimitedCarry.Value) b.overEncumberance = 0f;
33 if (InfiniteStamina.Value) b.stamina = 100f;
34 if (NoHunger.Value && b.hunger < 100f) b.hunger = 100f;
35 if (NoThirst.Value && b.thirst < 100f) b.thirst = 100f;
36 if (NoTiredness.Value) b.energy = 100f;
37 if (MoodLock.Value)
38 {
39 if (MoodBody != b || float.IsNaN(MoodTarget))
40 {
41 MoodBody = b;
42 MoodTarget = Mathf.Max(b.happiness, 60f);
43 }
44 b.happiness = MoodTarget;
45 b.traumaAmount = 0f;
46 }
47 else MoodTarget = float.NaN;
48 }
49
50 internal static Body MoodBody;
51 internal static float MoodTarget = float.NaN;
52
53 internal static float MoodMax(Body b)
54 {
55 return 100f * (b.charType == 2 ? 1.5151515f : 1f);
56 }
57
58 internal static void SetMood(Body b, float v)
59 {
60 float m = MoodMax(b);
61 v = Mathf.Clamp(v, -m, m);
62 b.happiness = v;
63 if (MoodLock.Value)
64 {
65 MoodBody = b;
66 MoodTarget = v;
67 }
68 }
69 internal static float RagdollUntil;
70 internal static Body PausedBody;
71 internal static string PauseReason;
72 internal static bool PauseResumable;
73 internal static float PausedAt;
74
75 internal static bool IsPlayer(Body body)
76 {
77 return body != null && PlayerCamera.main != null && PlayerCamera.main.body == body;
78 }
79
80 internal static bool GodOn(Body body)
81 {
82 return GodMode.Value && IsPlayer(body) && !Paused(body);
83 }
84
85 internal static bool Paused(Body body)
86 {
87 return body != null && PausedBody != null && body == PausedBody;
88 }
89
90 internal static void Pause(Body body, string reason, bool resumable)
91 {
92 if (body == null) return;
93 if (Paused(body) && !PauseResumable) return;
94 PausedBody = body;
95 PauseReason = reason;
96 PauseResumable = resumable;
97 PausedAt = Time.time;
98 Log.LogInfo("God Mode paused: " + reason);
99 Feed.Add("WARNING", "#ff6b6b", "God Mode PAUSED: " + reason);
100 }
101
102 internal static void TryResume()
103 {
104 Body b = PausedBody;
105 if (b == null || !PauseResumable) return;
106 if (!b.alive) { PauseResumable = false; return; }
107 bool harming = b.harmer != null && b.harmer.harming;
108 if (Time.time - PausedAt > 20f && b.totalBleedSpeed < 0.01f && !harming && !b.forceNoMovement)
109 {
110 PausedBody = null;
111 PauseReason = null;
112 Log.LogInfo("God Mode resumed (survived).");
113 Feed.Add("WARNING", "#9cff8a", "Survived - God Mode resumed");
114 }
115 }
116
117 internal static string DamageSummary(Body b)
118 {
119 List<string> parts = new List<string>();
120 if (b.brainHealth < 99.9f) parts.Add("brain -" + (100f - b.brainHealth).ToString("0.0"));
121 if (b.bloodVolume < 99f) parts.Add("blood -" + (100f - b.bloodVolume).ToString("0.0"));
122 if (b.internalBleeding > 0.1f) parts.Add("internal bleed");
123 Limb[] limbs = b.limbs;
124 if (limbs != null)
125 {
126 for (int i = 0; i < limbs.Length; i++)
127 {
128 Limb l = limbs[i];
129 if (l == null || l.dismembered) continue;
130 float lost = (100f - l.skinHealth) + (100f - l.muscleHealth);
131 if (lost > 0.5f || l.bleedAmount > 0.1f || l.shrapnel > 0)
132 parts.Add(l.gameObject.name + " -" + lost.ToString("0.0") + (l.bleedAmount > 0.1f ? " bleeding" : ""));
133 }
134 }
135 return parts.Count == 0 ? null : string.Join(", ", parts.ToArray());
136 }
137
138 internal static void Restore(Body b)
139 {
140 Stats.Restores++;
141 b.brainHealth = 100f;
142 if (!b.sleeping) b.consciousness = 100f;
143 b.bloodVolume = 100f;
144 b.bloodOxygen = 100f;
145 if (b.bloodPressure < 100f) b.bloodPressure = 100f;
146 else if (b.bloodPressure > 140f) b.bloodPressure = 140f;
147 if (b.heartRate > 160f) b.heartRate = 160f;
148 b.fibrillationProgress = 0f;
149 b.hasPulmonaryEmbolism = false;
150 b.strokeAmount = 0f;
151 b.shock = Time.time < RagdollUntil ? 20f : 0f;
152 b.painShock = 0f;
153 b.internalBleeding = 0f;
154 b.hemothorax = 0f;
155 b.septicShock = 0f;
156 b.sicknessAmount = 0f;
157 b.radiationSickness = 0f;
158 b.venomCurrent = 0f;
159 b.barotrauma = 0f;
160 b.temperature = 37f;
161 if (b.hunger < 30f) b.hunger = 30f;
162 if (b.thirst < 30f) b.thirst = 30f;
163 if (b.thirst > 150f) b.thirst = 150f;
164
165 Limb[] limbs = b.limbs;
166 if (limbs == null) return;
167 for (int i = 0; i < limbs.Length; i++)
168 {
169 Limb l = limbs[i];
170 if (l == null || l.dismembered) continue;
171 l.skinHealth = 100f;
172 l.muscleHealth = 100f;
173 l.bleedAmount = 0f;
174 l.pain = 0f;
175 l.infectionAmount = 0f;
176 l.infected = false;
177 l.shrapnel = 0;
178 }
179 }
180 }
181
182 internal static class Stats
183 {
184 internal static int Restores;
185 private static readonly Dictionary<string, int> counts = new Dictionary<string, int>();
186 internal static readonly List<string> Order = new List<string>();
187
188 internal static void Hit(string key)
189 {
190 int n;
191 if (!counts.TryGetValue(key, out n)) Order.Add(key);
192 counts[key] = n + 1;
193 }
194
195 internal static int Get(string key)
196 {
197 int n;
198 counts.TryGetValue(key, out n);
199 return n;
200 }
201 }
202
203 [HarmonyPatch]
204 internal static class FreezeEnemiesPatch
205 {
206 private static IEnumerable<System.Reflection.MethodBase> TargetMethods()
207 {
208 List<System.Reflection.MethodBase> list = new List<System.Reflection.MethodBase>();
209 Add(list, typeof(GuardScript), "Update");
210 Add(list, typeof(TurretScript), "Update");
211 Add(list, typeof(CeilingTurret), "Update");
212 Add(list, typeof(LaserDroneScript), "Update");
213 Add(list, typeof(LaserDroneScript), "FixedUpdate");
214 Add(list, typeof(LaserDroneScript), "OnCollisionEnter2D");
215 Add(list, typeof(CrystalEnemy), "Update");
216 Add(list, typeof(CrystalEnemy), "FixedUpdate");
217 Add(list, typeof(SpiderHandler), "Update");
218 Add(list, typeof(SpiderHandler), "FixedUpdate");
219 Add(list, typeof(SpiderHandler), "OnCollisionStay2D");
220 Add(list, typeof(SpiderHandler), "OnCollisionEnter2D");
221 Add(list, typeof(ElderThornbackBehaviour), "Update");
222 Add(list, typeof(ScrapEaterScript), "Update");
223 Add(list, typeof(BloodSuckerScript), "OnTriggerEnter2D");
224 return list;
225 }
226
227 private static void Add(List<System.Reflection.MethodBase> list, System.Type t, string name)
228 {
229 System.Reflection.MethodInfo m = AccessTools.Method(t, name);
230 if (m != null) list.Add(m);
231 else Plugin.Log.LogWarning("Freeze: " + t.Name + "." + name + " not found");
232 }
233
234 private static bool Prefix(MonoBehaviour __instance)
235 {
236 if (!Plugin.FreezeEnemies.Value) return true;
237 BuildingEntity be = __instance.GetComponent<BuildingEntity>();
238 if (be != null && be.health <= 0f) return true;
239 return false;
240 }
241 }
242
243 internal static class OneHit
244 {
245 internal static bool Active;
246
247 internal static bool IsEnemy(BuildingEntity e)
248 {
249 if (e.GetComponent<TraderScript>() != null || e.GetComponent<CorpseScript>() != null) return false;
250 return e.animal || e.GetComponent<GuardScript>() != null || e.GetComponent<TurretScript>() != null
251 || e.GetComponent<CeilingTurret>() != null || e.GetComponent<LaserDroneScript>() != null
252 || e.GetComponent<CrystalEnemy>() != null || e.GetComponent<SpiderHandler>() != null
253 || e.GetComponent<ElderThornbackBehaviour>() != null || e.GetComponent<ScrapEaterScript>() != null;
254 }
255 }
256
257 [HarmonyPatch(typeof(Body), "Attack")]
258 internal static class MeleeHitPatch
259 {
260 internal static bool Melee;
261 private static void Prefix(Body __instance) { OneHit.Active = Plugin.IsPlayer(__instance); Melee = OneHit.Active; }
262 private static void Postfix(Body __instance, bool __result)
263 {
264 if (__result && Plugin.FasterAttacks.Value && Plugin.IsPlayer(__instance))
265 __instance.attackCooldown /= Mathf.Max(1f, Plugin.AttackSpeedMult.Value);
266 }
267 private static System.Exception Finalizer(System.Exception __exception) { OneHit.Active = false; Melee = false; return __exception; }
268 }
269
270 [HarmonyPatch(typeof(WorldGeneration), "DamageBlock", new[] { typeof(Vector2Int), typeof(float), typeof(bool), typeof(bool), typeof(bool) })]
271 internal static class InstantMinePatch
272 {
273 private static void Prefix(WorldGeneration __instance, Vector2Int pos, ref float dmg)
274 {
275 if (!MeleeHitPatch.Melee || !Plugin.InstantMine.Value || dmg <= 0f) return;
276 BlockInfo info = __instance.GetBlockInfo(__instance.GetBlock(pos));
277 if (info == null || info.health <= 0f || info.health >= 1E+08f) return;
278 if (dmg < info.health)
279 {
280 dmg = info.health;
281 Stats.Hit("Instant mines");
282 }
283 }
284 }
285
286 [HarmonyPatch(typeof(GunScript), "Fire")]
287 internal static class GunHitPatch
288 {
289 private static bool recoilSaved;
290 private static float savedKnock;
291 private static float savedSpread;
292
293 private static void Prefix(GunScript __instance, bool suicide)
294 {
295 OneHit.Active = !suicide;
296 if (!suicide && Plugin.NoRecoil.Value)
297 {
298 recoilSaved = true;
299 savedKnock = __instance.knockBack;
300 savedSpread = __instance.verticalSpread;
301 __instance.knockBack = 0f;
302 __instance.verticalSpread = 0f;
303 }
304 }
305 private static void Postfix(GunScript __instance, bool suicide)
306 {
307 if (recoilSaved)
308 {
309 recoilSaved = false;
310 __instance.knockBack = savedKnock;
311 __instance.verticalSpread = savedSpread;
312 }
313 if (suicide || !Plugin.UnlimitedAmmo.Value) return;
314 if (!__instance.hasMag && __instance.feedType != GunScript.FeedType.Direct) return;
315 if (__instance.magCapacity > 0 && __instance.roundsInMag < __instance.magCapacity)
316 {
317 __instance.roundsInMag = __instance.magCapacity;
318 Stats.Hit("Ammo refills");
319 }
320 }
321 private static System.Exception Finalizer(GunScript __instance, System.Exception __exception)
322 {
323 OneHit.Active = false;
324 if (recoilSaved)
325 {
326 recoilSaved = false;
327 __instance.knockBack = savedKnock;
328 __instance.verticalSpread = savedSpread;
329 }
330 return __exception;
331 }
332 }
333
334 [HarmonyPatch(typeof(EndLabScript), "Update")]
335 internal static class EscapeTimerPatch
336 {
337 private static readonly System.Reflection.FieldInfo TimeLeft = AccessTools.Field(typeof(EndLabScript), "timeLeft");
338 private static EndLabScript extended;
339
340 private static void Prefix(EndLabScript __instance)
341 {
342 if (!Plugin.LongerEscape.Value || !__instance.doTimer || extended == __instance || TimeLeft == null) return;
343 extended = __instance;
344 TimeLeft.SetValue(__instance, (float)TimeLeft.GetValue(__instance) + 60f);
345 Feed.Mod("Escape timer +60s (2 minutes before the guards)");
346 }
347 }
348
349 [HarmonyPatch(typeof(BuildingEntity), "health", MethodType.Setter)]
350 internal static class OneHitKillPatch
351 {
352 internal static bool Bypass;
353
354 private static void Prefix(BuildingEntity __instance, ref float value)
355 {
356 if (Bypass) return;
357 float cur = __instance.health;
358 if (value >= cur || cur <= 0f) return;
359 bool player = OneHit.Active;
360 bool stronger = Plugin.StrongerEnemies.Value;
361 if (!player && !stronger) return;
362 if (!(player && (Plugin.OneHitKills.Value || Plugin.MoreDamage.Value)) && !stronger) return;
363 if (!OneHit.IsEnemy(__instance)) return;
364 float dmg = cur - value;
365 if (stronger) dmg *= 0.5f;
366 if (player && Plugin.MoreDamage.Value) dmg *= Mathf.Max(1f, Plugin.DamageMult.Value);
367 value = Mathf.Max(0f, cur - dmg);
368 if (player && Plugin.OneHitKills.Value && value > 0f)
369 {
370 value = 0f;
371 Stats.Hit("One-hit kills");
372 Feed.Mod("One-hit kill: " + __instance.gameObject.name.Replace("(Clone)", "").Trim());
373 }
374 }
375 }
376
377 [HarmonyPatch(typeof(TraderScript), "ItemPrice")]
378 internal static class FreeShoppingPatch
379 {
380 private static void Postfix(ref int __result) { if (Plugin.FreeShopping.Value) __result = 0; }
381 }
382
383 [HarmonyPatch(typeof(ConsoleScript), "CheckForCheats")]
384 internal static class CheatCheckPatch
385 {
386 private static bool Prefix()
387 {
388 Stats.Hit("Cheat flags blocked");
389 Feed.Mod("Blocked the game's cheat-command flag (achievements stay on)");
390 return false;
391 }
392 }
393
394 [HarmonyPatch(typeof(SaveSystem), "SaveGame")]
395 internal static class CleanSavePatch
396 {
397 private static void Prefix()
398 {
399 if (!SteamManager.disableAchievements) return;
400 SteamManager.disableAchievements = false;
401 Stats.Hit("Cheat flags blocked");
402 Feed.Mod("Saved without the cheated mark");
403 }
404 }
405
406 [HarmonyPatch(typeof(SaveSystem), "TryLoadGame")]
407 internal static class CleanLoadPatch
408 {
409 private static void Postfix()
410 {
411 if (!SteamManager.disableAchievements) return;
412 SteamManager.disableAchievements = false;
413 Stats.Hit("Cheat flags blocked");
414 Feed.Mod("Removed the cheated mark from a loaded save");
415 }
416 }
417
418 [HarmonyPatch(typeof(ConsoleScript), "Alert")]
419 internal static class CheatAlertPatch
420 {
421 private static bool Prefix(string message)
422 {
423 return message == null || message.IndexOf("Achievements are disabled", System.StringComparison.OrdinalIgnoreCase) < 0;
424 }
425 }
426
427 [HarmonyPatch(typeof(PlayerCamera), "StartSelfDestruct")]
428 internal static class GiveUpPatch
429 {
430 private static void Prefix(PlayerCamera __instance)
431 {
432 Plugin.Pause(__instance.body, "you gave up this run", false);
433 }
434 }
435
436 [HarmonyPatch(typeof(SelfHarmer), "Suicide")]
437 internal static class SuicidePatch
438 {
439 private static void Prefix(Body ___body)
440 {
441 if (!Plugin.GodMode.Value || !Plugin.IsPlayer(___body)) return;
442 Item gun;
443 bool hasGun = ___body.FindByTagThorough("gun", out gun);
444 Plugin.Pause(___body, "suicide attempt (" + (hasGun ? "gun" : "no gun, heavy bleeding") + ")", true);
445 }
446 }
447
448 internal static class MoodWatch
449 {
450 private static int lastStage;
451
452 internal static float SuicideAt(Body b)
453 {
454 if (Body.censorMood || b.charType == 2) return float.NegativeInfinity;
455 return b.charType == 1 ? -95f : -90f;
456 }
457
458 internal static int Stage(Body b)
459 {
460 if (b == null || !b.alive || b.harmer == null || !WorldGeneration.GetRunSettingBool("lowmoodevents")) return 0;
461 float mood = b.totalHappiness;
462 if (mood > -50f) return 0;
463 if (mood > -70f) return 1;
464 if (mood > SuicideAt(b)) return 2;
465 return b.harmer.timeWasStill > 20f ? 4 : 3;
466 }
467
468 internal static void Tick()
469 {
470 Body b = PlayerCamera.main != null ? PlayerCamera.main.body : null;
471 int s = Stage(b);
472 if (s > lastStage)
473 {
474 if (s == 1) Feed.Add("WARNING", "#ffd966", "Mood is getting low (" + b.totalHappiness.ToString("0") + "). Self-harm starts at -70.");
475 else if (s == 2) Feed.Add("WARNING", "#ff9a3c", "Mood " + b.totalHappiness.ToString("0") + ": standing still will trigger self-harm (God Mode heals it).");
476 else if (s == 3) Feed.Add("WARNING", "#ff6b6b", "SUICIDE RISK: mood " + b.totalHappiness.ToString("0") + ". Standing still triggers an attempt and God Mode will turn OFF.");
477 else if (s == 4) Feed.Add("WARNING", "#ff3030", "SUICIDE ATTEMPT IMMINENT - keep moving!");
478 }
479 lastStage = s;
480 }
481
482 internal static void Describe(StringBuilder sb, Body b)
483 {
484 if (b == null) return;
485 sb.Append("<b><color=#7fd4ff>MOOD</color></b>\n");
486 float mood = b.totalHappiness;
487 sb.Append("Mood: ").Append(mood.ToString("0")).Append(" | low-mood events: ")
488 .Append(WorldGeneration.GetRunSettingBool("lowmoodevents") ? "on" : "off").Append('\n');
489 if (Plugin.Paused(b))
490 sb.Append("<color=#ff6b6b><b>God Mode PAUSED: ").Append(Plugin.PauseReason).Append("</b></color>\n");
491 int s = Stage(b);
492 if (s == 0)
493 {
494 sb.Append("<color=#9cff8a>No self-harm risk</color>\n\n");
495 return;
496 }
497 if (s == 1)
498 {
499 sb.Append("<color=#ffd966>Mood is low. Self-harm starts at -70.</color>\n\n");
500 return;
501 }
502 SelfHarmer h = b.harmer;
503 if (h.cooldownTime > 0f)
504 sb.Append("Cooldown after last attempt: ").Append(h.cooldownTime.ToString("0")).Append("s\n");
505 else
506 sb.Append("Standing still: ").Append(h.timeWasStill.ToString("0.0")).Append(" / 30s (warning sound at 20s)\n");
507 if (s == 2)
508 {
509 sb.Append("<color=#ff9a3c>Next attempt: self-harm (not deadly, God Mode heals it).</color>\n");
510 if (SuicideAt(b) > float.NegativeInfinity)
511 sb.Append("<color=#ff9a3c>At ").Append(SuicideAt(b).ToString("0")).Append(" it becomes a suicide attempt.</color>\n");
512 }
513 else
514 {
515 Item gun;
516 bool hasGun = b.FindByTagThorough("gun", out gun);
517 sb.Append("<color=#ff3030><b>SUICIDE RISK.</b> Next attempt is suicide (").Append(hasGun ? "has a gun - instant death" : "no gun - heavy bleeding")
518 .Append("). God Mode will turn OFF and let it happen. Keep moving and raise the mood.</color>\n");
519 }
520 sb.Append('\n');
521 }
522 }
523
524 [HarmonyPatch(typeof(Limb), "ImpactDamage")]
525 internal static class ImpactPatch
526 {
527 private static bool Prefix(Limb __instance, float force)
528 {
529 if (!Plugin.IsPlayer(__instance.body)) return true;
530 if (!(Plugin.NoFallDamage.Value || Plugin.GodMode.Value || Plugin.FlyMode.Value || Plugin.Noclip.Value)) return true;
531 if (force > __instance.body.jumpSpeed)
532 {
533 Stats.Hit("Impacts blocked");
534 Feed.Mod("Blocked impact damage on " + __instance.gameObject.name);
535 }
536 return false;
537 }
538 }
539
540 [HarmonyPatch(typeof(Body), "Scream")]
541 internal static class ScreamPatch
542 {
543 private static bool Prefix(Body __instance)
544 {
545 if (!Plugin.IsPlayer(__instance)) return true;
546 bool fallingFast = __instance.rb != null && __instance.rb.velocity.y < -__instance.jumpSpeed * 2.25f;
547 if (fallingFast) return true;
548 if (Plugin.GodOn(__instance))
549 {
550 Stats.Hit("Screams muted");
551 Feed.Mod("Muted hazard scream");
552 return false;
553 }
554 return true;
555 }
556 }
557
558 [HarmonyPatch(typeof(Talker), "Talk", new[] { typeof(List<string>), typeof(Limb), typeof(bool), typeof(bool) })]
559 internal static class TalkListPatch
560 {
561 private static bool Prefix(Talker __instance, List<string> lines)
562 {
563 return !DamageLines.ShouldMute(__instance, lines, null);
564 }
565 }
566
567 [HarmonyPatch(typeof(Talker), "Talk", new[] { typeof(string), typeof(Limb), typeof(bool), typeof(bool) })]
568 internal static class TalkStringPatch
569 {
570 private static bool Prefix(Talker __instance, string text)
571 {
572 return !DamageLines.ShouldMute(__instance, null, text);
573 }
574 }
575
576 internal static class DamageLines
577 {
578 private static readonly string[] Keys =
579 {
580 "steponglass", "hitbycreature", "cargoimpale", "cargoimpale2", "cargoimpale3",
581 "vomitblood", "pain", "bigpain", "bleeding", "bleedingheavy", "limbskin", "limbmuscle", "limbinfected",
582 "braindamaged", "cantBreathe", "lastmoments", "sick", "verysick", "freezing", "hot", "cold", "warm", "confused"
583 };
584
585 internal static bool ShouldMute(Talker t, List<string> lines, string text)
586 {
587 if (t == null || !Plugin.GodOn(t.body)) return false;
588 int chr = t.body.charType;
589 for (int i = 0; i < Keys.Length; i++)
590 {
591 List<string> known;
592 try { known = Locale.GetCharacter(Keys[i], chr); }
593 catch (System.Exception) { continue; }
594 if (known == null || known.Count == 0 || (known.Count == 1 && known[0] == Keys[i])) continue;
595 bool hit = (lines != null && (ReferenceEquals(lines, known) || (lines.Count > 0 && known.Contains(lines[0]))))
596 || (text != null && known.Contains(text));
597 if (hit)
598 {
599 Stats.Hit("Damage lines muted");
600 Feed.Mod("Muted damage line (" + Keys[i] + ")");
601 return true;
602 }
603 }
604 return false;
605 }
606 }
607
608 [HarmonyPatch(typeof(WorldGeneration), "CreateExplosion")]
609 internal static class ExplosionPatch
610 {
611 internal static bool Active;
612 private static float savedHearingLoss;
613
614 private static void Prefix(ExplosionParams param)
615 {
616 Body b = PlayerCamera.main != null ? PlayerCamera.main.body : null;
617 Active = Plugin.GodOn(b);
618 if (Active) savedHearingLoss = b.hearingLoss;
619 string where = b != null ? Vector2.Distance(param.position, b.transform.position).ToString("0.0") + "m away" : "";
620 Feed.Add("EXPLOSION", "#ff9a3c", "Range " + param.range.ToString("0.#") + ", " + where);
621 }
622
623 private static void Postfix()
624 {
625 if (!Active) return;
626 Active = false;
627 Body b = PlayerCamera.main.body;
628 b.hearingLoss = savedHearingLoss;
629 if (b.shock >= 100f)
630 {
631 Plugin.RagdollUntil = Time.time + 1.5f;
632 Stats.Hit("Explosions absorbed");
633 string dmg = Plugin.DamageSummary(b);
634 Feed.Mod("Absorbed explosion" + (dmg != null ? ": undid " + dmg : "") + " - ragdoll 1.5s");
635 }
636 Plugin.Restore(b);
637 }
638
639 private static System.Exception Finalizer(System.Exception __exception)
640 {
641 Active = false;
642 return __exception;
643 }
644 }
645
646 [HarmonyPatch(typeof(Limb), "Dismember")]
647 internal static class DismemberPatch
648 {
649 private static bool Prefix(Limb __instance)
650 {
651 if (ExplosionPatch.Active && Plugin.IsPlayer(__instance.body))
652 {
653 Stats.Hit("Limb losses blocked");
654 Feed.Mod("Blocked explosion dismembering " + __instance.gameObject.name);
655 return false;
656 }
657 return true;
658 }
659 }
660
661 [HarmonyPatch(typeof(Body), "Disfigure")]
662 internal static class DisfigurePatch
663 {
664 private static bool Prefix(Body __instance)
665 {
666 if (ExplosionPatch.Active && Plugin.IsPlayer(__instance)) { Stats.Hit("Disfigures blocked"); Feed.Mod("Blocked disfigurement"); return false; }
667 return true;
668 }
669 }
670
671 [HarmonyPatch(typeof(Body), "RemoveEye")]
672 internal static class RemoveEyePatch
673 {
674 private static bool Prefix(Body __instance)
675 {
676 if (ExplosionPatch.Active && Plugin.IsPlayer(__instance)) { Stats.Hit("Eye losses blocked"); Feed.Mod("Blocked eye loss"); return false; }
677 return true;
678 }
679 }
680
681 [HarmonyPatch(typeof(Limb), "DamageWearables")]
682 internal static class WearablesPatch
683 {
684 private static bool Prefix(Limb __instance)
685 {
686 if (ExplosionPatch.Active && Plugin.IsPlayer(__instance.body)) { Stats.Hit("Armor hits blocked"); return false; }
687 return true;
688 }
689 }
690
691 [HarmonyPatch(typeof(Limb), "BreakBone")]
692 internal static class BreakBonePatch
693 {
694 private static bool Prefix(Limb __instance)
695 {
696 if (Plugin.GodOn(__instance.body) && !__instance.broken)
697 {
698 Stats.Hit("Bone breaks blocked");
699 Feed.Mod("Blocked broken bone: " + __instance.gameObject.name);
700 return false;
701 }
702 return !Plugin.GodOn(__instance.body);
703 }
704 }
705
706 [HarmonyPatch(typeof(Limb), "Dislocate")]
707 internal static class DislocatePatch
708 {
709 private static bool Prefix(Limb __instance)
710 {
711 if (!Plugin.GodOn(__instance.body)) return true;
712 if (!__instance.dislocated)
713 {
714 Stats.Hit("Dislocations blocked");
715 Feed.Mod("Blocked dislocation: " + __instance.gameObject.name);
716 }
717 return false;
718 }
719 }
720
721 [HarmonyPatch(typeof(Body), "Update")]
722 internal static class BodyUpdatePatch
723 {
724 private static float lastLog;
725 private static void Prefix(Body __instance)
726 {
727 if (!Plugin.GodOn(__instance)) return;
728 string dmg = Plugin.DamageSummary(__instance);
729 if (dmg != null)
730 {
731 Stats.Hit("Damage undone");
732 if (Time.unscaledTime - lastLog > 0.25f)
733 {
734 lastLog = Time.unscaledTime;
735 Feed.Mod("Undid damage: " + dmg);
736 }
737 }
738 Plugin.Restore(__instance);
739 }
740 private static void Postfix(Body __instance)
741 {
742 if (Plugin.GodOn(__instance)) Plugin.Restore(__instance);
743 if (Plugin.IsPlayer(__instance)) Plugin.ApplyKeeps(__instance);
744 }
745 }
746
747 [HarmonyPatch(typeof(Body), "HandlePeriodicChecks")]
748 internal static class EncumbrancePatch
749 {
750 private static void Postfix(Body __instance)
751 {
752 if (Plugin.UnlimitedCarry.Value && Plugin.IsPlayer(__instance)) __instance.overEncumberance = 0f;
753 }
754 }
755
756 internal static class Targets
757 {
758 internal static void Add(List<System.Reflection.MethodBase> list, System.Type t, string name)
759 {
760 System.Reflection.MethodInfo m = AccessTools.DeclaredMethod(t, name);
761 if (m != null) list.Add(m);
762 else Plugin.Log.LogWarning("Patch target " + t.Name + "." + name + " not found");
763 }
764 }
765
766 [HarmonyPatch(typeof(WorldGeneration), "GetRunSettingFloat")]
767 internal static class RunFloatPatch
768 {
769 private static void Postfix(string name, ref float __result)
770 {
771 switch (name)
772 {
773 case "healingrate": if (Plugin.FasterHealing.Value) __result *= Mathf.Max(1f, Plugin.HealingMult.Value); break;
774 case "metabolismrate": if (Plugin.FastMetabolism.Value) __result *= 2f; break;
775 case "xpgain": if (Plugin.MoreXp.Value) __result *= Mathf.Max(1f, Plugin.XpMult.Value); break;
776 case "baselootdensity":
777 if (Plugin.MoreLoot.Value) __result *= Mathf.Max(1f, Plugin.LootMult.Value);
778 if (Plugin.LootScarcity.Value) __result *= 0.4f;
779 break;
780 case "basetrapdensity": if (Plugin.MoreTraps.Value) __result *= 2f; break;
781 case "enemystrength": if (Plugin.StrongerEnemies.Value) __result *= 1.75f; break;
782 case "temperatureoffset": if (Plugin.ColdCaves.Value) __result -= 15f; break;
783 case "itemdecayrate": if (Plugin.BrittleGear.Value) __result *= 3f; break;
784 case "timelimit": if (Plugin.FastRadiation.Value) __result *= 0.5f; break;
785 }
786 }
787 }
788
789 [HarmonyPatch(typeof(WorldGeneration), "GetRunSettingInt")]
790 internal static class RunIntPatch
791 {
792 private static void Postfix(string name, ref int __result)
793 {
794 if (name == "startingsupplies" && Plugin.HopelessStart.Value) __result = 0;
795 }
796 }
797
798 [HarmonyPatch(typeof(WorldGeneration), "GetRunSettingBool")]
799 internal static class RunBoolPatch
800 {
801 private static void Postfix(string name, ref bool __result)
802 {
803 if (name == "unchipped" && Plugin.UnchippedChallenge.Value) __result = true;
804 }
805 }
806
807 [HarmonyPatch(typeof(Body), "actualMaxSpeed", MethodType.Getter)]
808 internal static class MaxSpeedPatch
809 {
810 private static void Postfix(Body __instance, ref float __result)
811 {
812 if (Plugin.FasterMovement.Value && Plugin.IsPlayer(__instance)) __result *= Mathf.Max(1f, Plugin.MoveSpeedMult.Value);
813 }
814 }
815
816 [HarmonyPatch(typeof(Body), "actualMoveForce", MethodType.Getter)]
817 internal static class MoveForcePatch
818 {
819 private static void Postfix(Body __instance, ref float __result)
820 {
821 if (Plugin.FasterMovement.Value && Plugin.IsPlayer(__instance)) __result *= Mathf.Max(1f, Plugin.MoveSpeedMult.Value);
822 }
823 }
824
825 [HarmonyPatch(typeof(Body), "actualJumpSpeed", MethodType.Getter)]
826 internal static class JumpSpeedPatch
827 {
828 private static void Postfix(Body __instance, ref float __result)
829 {
830 if (Plugin.HigherJumps.Value && Plugin.IsPlayer(__instance)) __result *= Mathf.Max(1f, Plugin.JumpMult.Value);
831 }
832 }
833
834 [HarmonyPatch(typeof(Body), "HandleClimbing")]
835 internal static class ClimbPatch
836 {
837 private static void Postfix(Body __instance)
838 {
839 if (!Plugin.FasterClimbing.Value || !Plugin.IsPlayer(__instance)) return;
840 Climbable c = __instance.currentClimbable;
841 if (c == null || !__instance.standing) return;
842 float extra = __instance.climbVelocity * Time.fixedDeltaTime * (Mathf.Max(1f, Plugin.ClimbSpeedMult.Value) - 1f);
843 if (extra == 0f) return;
844 __instance.climbableProgress = Mathf.Clamp(__instance.climbableProgress + extra, 0.01f, c.totalLength);
845 __instance.rb.MovePosition(c.GetPositionAtDistance(__instance.climbableProgress));
846 }
847 }
848
849 [HarmonyPatch(typeof(Body), "Jump")]
850 internal static class JumpPatch
851 {
852 private static readonly System.Reflection.FieldInfo Cooldown = AccessTools.Field(typeof(Body), "jumpCooldown");
853 private static readonly System.Reflection.FieldInfo SinceGrounded = AccessTools.Field(typeof(Body), "timeSinceGrounded");
854 private static readonly System.Reflection.FieldInfo FirstWall = AccessTools.Field(typeof(Body), "firstWallJump");
855
856 private static void Prefix(Body __instance)
857 {
858 if (!Plugin.IsPlayer(__instance)) return;
859 if (Plugin.UnlimitedJumps.Value && __instance.standing && !__instance.grounded)
860 {
861 if (Cooldown != null) Cooldown.SetValue(__instance, 0f);
862 if (SinceGrounded != null) SinceGrounded.SetValue(__instance, 0f);
863 }
864 if (Plugin.UnlimitedWallJumps.Value && FirstWall != null) FirstWall.SetValue(__instance, true);
865 }
866 }
867
868 [HarmonyPatch(typeof(Limb), "GetArmorReduction")]
869 internal static class FragilePatch
870 {
871 private static void Postfix(Limb __instance, ref float __result)
872 {
873 if (Plugin.FragileBody.Value && Plugin.IsPlayer(__instance.body)) __result *= 0.5f;
874 }
875 }
876
877 [HarmonyPatch(typeof(Recipe), "TryMake")]
878 internal static class FreeCraftPatch
879 {
880 private static bool Prefix(Recipe __instance)
881 {
882 if (!Plugin.FreeCrafting.Value) return true;
883 Body b = PlayerCamera.main != null ? PlayerCamera.main.body : null;
884 if (b == null) return true;
885 __instance.result.SpawnResult(__instance.INT);
886 Sound.Play("combine", b.transform.position);
887 if (!__instance.hasMadeBefore)
888 {
889 __instance.hasMadeBefore = true;
890 b.happiness++;
891 b.skills.AddExp(2, 10f);
892 }
893 PlayerCamera.main.PlayUISound(PlayerCamera.UISoundType.Click);
894 Stats.Hit("Free crafts");
895 return false;
896 }
897 }
898
899 [HarmonyPatch(typeof(Recipe), "GetItemsForRecipe")]
900 internal static class FreeCraftListPatch
901 {
902 private static void Postfix(ref List<Item> __result)
903 {
904 if (__result == null && Plugin.FreeCrafting.Value) __result = new List<Item>();
905 }
906 }
907
908 [HarmonyPatch(typeof(Recipe), "visible", MethodType.Getter)]
909 internal static class AllRecipesPatch
910 {
911 private static void Postfix(ref bool __result)
912 {
913 if (Plugin.AllRecipes.Value) __result = true;
914 }
915 }
916
917 [HarmonyPatch(typeof(RecipeResult), "SpawnResult")]
918 internal static class NoCraftFailPatch
919 {
920 private static void Prefix(ref int recipeInt)
921 {
922 if (Plugin.NoCraftFail.Value) recipeInt = -1000;
923 }
924 }
925
926 internal static class Durability
927 {
928 private static readonly Dictionary<Item, float> held = new Dictionary<Item, float>();
929 private static readonly Dictionary<string, bool> cache = new Dictionary<string, bool>();
930 private static float nextSweep;
931
932 private static bool Protected(Item it)
933 {
934 if (string.IsNullOrEmpty(it.id)) return false;
935 bool r;
936 if (cache.TryGetValue(it.id, out r)) return r;
937 r = Decide(it);
938 cache[it.id] = r;
939 return r;
940 }
941
942 private static bool Decide(Item it)
943 {
944 ItemInfo s;
945 try { s = it.Stats; }
946 catch (System.Exception) { return false; }
947 if (s == null) return false;
948 if (s is LiquidItemInfo || it.GetComponent<WaterContainerItem>() != null) return false;
949 if (s is BatteryInfo || it.GetComponent<BatteryItem>() != null) return true;
950 if (it.GetComponent<GunScript>() != null) return true;
951 if (s.category == "container" || it.GetComponent<Container>() != null) return true;
952 if (s.category == "tool") return true;
953 try { if (s.HasTag("tool")) return true; } catch (System.Exception) { }
954 return s.wearable;
955 }
956
957 internal static void Hold(Item it)
958 {
959 if (!Plugin.NoDegradation.Value || it == null || !Protected(it)) return;
960 float c = it.condition;
961 float t;
962 if (it.battery != null && !it.battery.hasBattery) { held[it] = c; return; }
963 if (!held.TryGetValue(it, out t) || c >= t) { held[it] = c; return; }
964 it.condition = t;
965 }
966
967 internal static void Accept(Item it)
968 {
969 if (it != null && held.ContainsKey(it)) held[it] = it.condition;
970 }
971
972 internal static void Sweep()
973 {
974 if (Time.unscaledTime < nextSweep) return;
975 nextSweep = Time.unscaledTime + 30f;
976 if (!Plugin.NoDegradation.Value) { held.Clear(); return; }
977 List<Item> dead = null;
978 foreach (Item k in held.Keys)
979 if (k == null) { if (dead == null) dead = new List<Item>(); dead.Add(k); }
980 if (dead != null) for (int i = 0; i < dead.Count; i++) held.Remove(dead[i]);
981 }
982 }
983
984 [HarmonyPatch(typeof(Item), "Update")]
985 internal static class ItemHoldPatch
986 {
987 private static void Prefix(Item __instance) { Durability.Hold(__instance); }
988 }
989
990 [HarmonyPatch(typeof(RecipeItem), "UseItem")]
991 internal static class RecipeUsePatch
992 {
993 private static void Postfix(RecipeItem __instance, Item item)
994 {
995 if (__instance != null && __instance.destroyItem) Durability.Accept(item);
996 }
997 }
998
999 [HarmonyPatch(typeof(Body), "CombineItems")]
1000 internal static class CombinePatch
1001 {
1002 private static void Postfix(Item it1, Item it2)
1003 {
1004 Durability.Accept(it1);
1005 Durability.Accept(it2);
1006 }
1007 }
1008
1009 [HarmonyPatch(typeof(BatteryItem), "DrainCharge")]
1010 internal static class BatteryPatch
1011 {
1012 private static bool Prefix() { return !Plugin.UnlimitedBattery.Value; }
1013 }
1014
1015 [HarmonyPatch(typeof(WaterContainerItem), "Drain")]
1016 internal static class LiquidPatch
1017 {
1018 private static bool Prefix() { return !Plugin.UnlimitedLiquids.Value; }
1019 }
1020
1021 [HarmonyPatch(typeof(LockpingMinigame), "MaxTurnProgress")]
1022 internal static class LockAnglePatch
1023 {
1024 private static void Postfix(ref float __result)
1025 {
1026 if (Plugin.MasterLockpick.Value) __result = 1f;
1027 }
1028 }
1029
1030 [HarmonyPatch(typeof(LockpingMinigame), "Update")]
1031 internal static class LockSpeedPatch
1032 {
1033 private static void Prefix(LockpingMinigame __instance)
1034 {
1035 if (Plugin.MasterLockpick.Value && __instance.clickingInside && __instance.lockProgress < 0.98f) __instance.lockProgress = 0.98f;
1036 }
1037 }
1038
1039 [HarmonyPatch(typeof(GunScript), "JamChance")]
1040 internal static class JamPatch
1041 {
1042 private static void Postfix(ref float __result)
1043 {
1044 if (Plugin.NoGunJams.Value) __result = 0f;
1045 }
1046 }
1047
1048 [HarmonyPatch]
1049 internal static class InvisibilityPatch
1050 {
1051 private static IEnumerable<System.Reflection.MethodBase> TargetMethods()
1052 {
1053 List<System.Reflection.MethodBase> list = new List<System.Reflection.MethodBase>();
1054 Targets.Add(list, typeof(TurretScript), "Update");
1055 Targets.Add(list, typeof(CeilingTurret), "Update");
1056 Targets.Add(list, typeof(LaserDroneScript), "FireShot");
1057 Targets.Add(list, typeof(GuardScript), "Fire");
1058 Targets.Add(list, typeof(CrystalEnemy), "Lunge");
1059 Targets.Add(list, typeof(GrabberPlant), "Update");
1060 Targets.Add(list, typeof(GrabberPlant), "FixedUpdate");
1061 Targets.Add(list, typeof(ElderThornbackBehaviour), "Update");
1062 return list;
1063 }
1064
1065 private static bool Prefix() { return !Plugin.Invisibility.Value; }
1066 }
1067
1068 [HarmonyPatch(typeof(GuardScript), "MeleeAttack")]
1069 internal static class GuardMeleePatch
1070 {
1071 private static IEnumerator Nothing() { yield break; }
1072
1073 private static bool Prefix(ref IEnumerator __result)
1074 {
1075 if (!Plugin.Invisibility.Value) return true;
1076 __result = Nothing();
1077 return false;
1078 }
1079 }
1080
1081 [HarmonyPatch]
1082 internal static class SpiderBitePatch
1083 {
1084 private static IEnumerable<System.Reflection.MethodBase> TargetMethods()
1085 {
1086 List<System.Reflection.MethodBase> list = new List<System.Reflection.MethodBase>();
1087 Targets.Add(list, typeof(SpiderHandler), "DamageLimb");
1088 Targets.Add(list, typeof(SpiderHandlerTBE), "DamageLimb");
1089 return list;
1090 }
1091
1092 private static bool Prefix(Limb limb)
1093 {
1094 return !(Plugin.Invisibility.Value && limb != null && Plugin.IsPlayer(limb.body));
1095 }
1096 }
1097
1098 [HarmonyPatch(typeof(BloodSuckerScript), "BeginSucc")]
1099 internal static class BloodSuckerPatch
1100 {
1101 private static bool Prefix(Limb lm)
1102 {
1103 return !(Plugin.Invisibility.Value && lm != null && Plugin.IsPlayer(lm.body));
1104 }
1105 }
1106
1107 [HarmonyPatch]
1108 internal static class TrapPatch
1109 {
1110 private static IEnumerable<System.Reflection.MethodBase> TargetMethods()
1111 {
1112 List<System.Reflection.MethodBase> list = new List<System.Reflection.MethodBase>();
1113 Targets.Add(list, typeof(BearTrap), "OnTriggerEnter2D");
1114 Targets.Add(list, typeof(MineScript), "Update");
1115 Targets.Add(list, typeof(MineScript), "OnCollisionEnter2D");
1116 Targets.Add(list, typeof(SpikeStabberScript), "OnTriggerEnter2D");
1117 Targets.Add(list, typeof(SpikeStabberScript), "Stab");
1118 Targets.Add(list, typeof(SpikeStabberScript), "CheckStab");
1119 Targets.Add(list, typeof(SoundCannon), "Update");
1120 Targets.Add(list, typeof(FanTrap), "Update");
1121 Targets.Add(list, typeof(FanTrap), "FixedUpdate");
1122 Targets.Add(list, typeof(GunmineScript), "OnWillRenderObject");
1123 Targets.Add(list, typeof(TurretScript), "Update");
1124 Targets.Add(list, typeof(CeilingTurret), "Update");
1125 return list;
1126 }
1127
1128 private static bool Prefix() { return !Plugin.DisableTraps.Value; }
1129 }
1130
1131 [HarmonyPatch(typeof(RadiationLine), "Update")]
1132 internal static class RadiationPatch
1133 {
1134 private static readonly System.Reflection.FieldInfo Gone = AccessTools.Field(typeof(RadiationLine), "timeGone");
1135
1136 private static bool Prefix() { return !Plugin.PauseRadiation.Value; }
1137
1138 private static void Postfix(RadiationLine __instance)
1139 {
1140 if (Plugin.PauseRadiation.Value || !Plugin.FastRadiation.Value || !__instance.active) return;
1141 Body b = PlayerCamera.main != null ? PlayerCamera.main.body : null;
1142 if (b == null || Gone == null) return;
1143 Gone.SetValue(__instance, (float)Gone.GetValue(__instance) + Time.deltaTime * (b.conscious ? 1f : 0.2f) * 1.5f);
1144 }
1145 }
1146
1147 [HarmonyPatch(typeof(WorldGeneration), "Update")]
1148 internal static class WorldUpdatePatch
1149 {
1150 private static float savedLayerTime;
1151
1152 private static void Prefix(WorldGeneration __instance)
1153 {
1154 savedLayerTime = __instance.layerTimeSpent;
1155 if (Plugin.NoEarthquakes.Value)
1156 {
1157 if (__instance.earthquakeDelay < 30f) __instance.earthquakeDelay = 30f;
1158 __instance.earthquakeTime = 0f;
1159 __instance.earthquakeIntensity = 0f;
1160 }
1161 }
1162
1163 private static void Postfix(WorldGeneration __instance)
1164 {
1165 if (Plugin.PauseRadiation.Value) __instance.layerTimeSpent = savedLayerTime;
1166 else if (Plugin.FastRadiation.Value) __instance.layerTimeSpent += Time.deltaTime;
1167 if (Actions.DownpourUntil <= Time.time || !__instance.worldExists) return;
1168 Body b = PlayerCamera.main != null ? PlayerCamera.main.body : null;
1169 if (b == null) return;
1170 __instance.fungusRainIntensity = 1f;
1171 if (__instance.rainSprite != null) __instance.rainSprite.color = Color.white;
1172 if (__instance.rainLoopSource != null) __instance.rainLoopSource.volume = 1f;
1173 if (b.wetness < 100f) b.wetness = Mathf.MoveTowards(b.wetness, 100f, Time.deltaTime);
1174 b.dirtyness = Mathf.MoveTowards(b.dirtyness, 0f, Time.deltaTime);
1175 }
1176 }
1177
1178 internal static class Actions
1179 {
1180 internal static float DownpourUntil;
1181 private static float skipCooldown;
1182
1183 private static Body Player()
1184 {
1185 return PlayerCamera.main != null && WorldGeneration.world != null ? PlayerCamera.main.body : null;
1186 }
1187
1188 internal static string HealWounds()
1189 {
1190 Body b = Player();
1191 if (b == null) return "Not in a run";
1192 Limb[] ls = b.limbs;
1193 for (int i = 0; i < ls.Length; i++)
1194 if (ls[i] != null && !ls[i].dismembered) ls[i].Heal();
1195 Plugin.Restore(b);
1196 b.hearingLoss = 0f;
1197 return "Healed all wounds";
1198 }
1199
1200 internal static string Emergency(string id)
1201 {
1202 Body b = Player();
1203 if (b == null) return "Not in a run";
1204 Limb[] ls = b.limbs ?? new Limb[0];
1205 switch (id)
1206 {
1207 case "em_full":
1208 HealWounds();
1209 ReattachLimbs();
1210 if (b.hunger < 100f) b.hunger = 100f;
1211 if (b.thirst < 100f) b.thirst = 100f;
1212 return "Full restore: wounds, limbs, blood, food and water";
1213 case "em_bleed":
1214 for (int i = 0; i < ls.Length; i++) if (ls[i] != null && !ls[i].dismembered) ls[i].bleedAmount = 0f;
1215 b.internalBleeding = 0f;
1216 b.hemothorax = 0f;
1217 if (b.bloodVolume < 70f) b.bloodVolume = 70f;
1218 return "Bleeding stopped";
1219 case "em_breathe":
1220 b.bloodOxygen = 100f;
1221 b.hasPulmonaryEmbolism = false;
1222 b.hemothorax = 0f;
1223 b.barotrauma = 0f;
1224 return "Breathing fixed, oxygen full";
1225 case "em_heart":
1226 b.fibrillationProgress = 0f;
1227 if (b.heartRate > 160f || b.heartRate < 40f) b.heartRate = 80f;
1228 if (b.bloodPressure < 100f) b.bloodPressure = 110f;
1229 b.shock = 0f;
1230 b.painShock = 0f;
1231 b.strokeAmount = 0f;
1232 if (b.brainHealth < 60f) b.brainHealth = 60f;
1233 if (!b.sleeping) b.consciousness = 100f;
1234 return "Heart and circulation stabilised";
1235 case "em_cure":
1236 for (int i = 0; i < ls.Length; i++) if (ls[i] != null && !ls[i].dismembered) { ls[i].infectionAmount = 0f; ls[i].infected = false; }
1237 b.sicknessAmount = 0f;
1238 b.radiationSickness = 0f;
1239 b.venomCurrent = 0f;
1240 b.septicShock = 0f;
1241 return "Infection, sickness, radiation and venom cured";
1242 case "em_body":
1243 b.temperature = 37f;
1244 if (b.hunger < 100f) b.hunger = 100f;
1245 if (b.thirst < 100f) b.thirst = 100f;
1246 else if (b.thirst > 150f) b.thirst = 120f;
1247 for (int i = 0; i < ls.Length; i++) if (ls[i] != null) ls[i].pain = 0f;
1248 return "Fed, watered, warm and pain-free";
1249 }
1250 return null;
1251 }
1252
1253 internal static string ReattachLimbs()
1254 {
1255 Body b = Player();
1256 if (b == null) return "Not in a run";
1257 int n = 0;
1258 Limb[] ls = b.limbs;
1259 for (int i = 0; i < ls.Length; i++)
1260 {
1261 Limb l = ls[i];
1262 if (l == null || !l.dismembered || l.prostheticInfo.hasProsthetic) continue;
1263 l.Reattach();
1264 n++;
1265 }
1266 return n == 0 ? "No missing limbs" : "Reattached " + n + " limb" + (n == 1 ? "" : "s");
1267 }
1268
1269 internal static string KillAllEnemies()
1270 {
1271 if (Player() == null) return "Not in a run";
1272 int n = 0;
1273 BuildingEntity[] all = Object.FindObjectsOfType<BuildingEntity>();
1274 OneHitKillPatch.Bypass = true;
1275 try
1276 {
1277 for (int i = 0; i < all.Length; i++)
1278 {
1279 BuildingEntity e = all[i];
1280 if (e == null || e.health <= 0f || !OneHit.IsEnemy(e)) continue;
1281 e.health = 0f;
1282 n++;
1283 }
1284 }
1285 finally { OneHitKillPatch.Bypass = false; }
1286 return "Killed " + n + " enem" + (n == 1 ? "y" : "ies");
1287 }
1288
1289 internal static string SpiderAmbush()
1290 {
1291 Body b = Player();
1292 if (b == null) return "Not in a run";
1293 WorldGeneration w = WorldGeneration.world;
1294 int n = 0;
1295 for (int tries = 0; tries < 60 && n < 4; tries++)
1296 {
1297 Vector2 pos = (Vector2)b.transform.position + Random.insideUnitCircle.normalized * Random.Range(5f, 11f);
1298 try
1299 {
1300 if (w.GetBlock(pos) != 0) continue;
1301 Utils.Create("cavetick", pos, 0f);
1302 n++;
1303 }
1304 catch (System.Exception) { }
1305 }
1306 return n == 0 ? "No room for spiders here" : n + " spiders incoming!";
1307 }
1308
1309 internal static string SkipLayer()
1310 {
1311 Body b = Player();
1312 WorldGeneration w = WorldGeneration.world;
1313 if (b == null) return "Not in a run";
1314 if (w.generatingWorld || !w.worldExists || Time.unscaledTime < skipCooldown) return "Wait for the layer to finish loading";
1315 if (w.biomeOverride != WorldGeneration.OverrideSceneType.None) return "Can't skip layers here";
1316 if (w.biomeDepth >= 9) return "Can't skip from this layer";
1317 skipCooldown = Time.unscaledTime + 8f;
1318 b.forceWalk = false;
1319 if (w.savePanel != null) w.savePanel.SetActive(false);
1320 PlayerPrefs.SetInt("deepestlayer", System.Math.Max(w.biomeDepth + 1, PlayerPrefs.GetInt("deepestlayer")));
1321 w.StartCoroutine(w.RegenerateWorld(false));
1322 return "Skipping to the next layer";
1323 }
1324
1325 private static readonly System.Reflection.MethodInfo InstantiateWorldMethod = AccessTools.Method(typeof(WorldGeneration), "InstantiateWorld");
1326 private static readonly System.Reflection.FieldInfo DoingRegenField = AccessTools.Field(typeof(WorldGeneration), "doingRegen");
1327
1328 internal static string PreviousLayer()
1329 {
1330 Body b = Player();
1331 WorldGeneration w = WorldGeneration.world;
1332 if (b == null) return "Not in a run";
1333 if (w.generatingWorld || !w.worldExists || Time.unscaledTime < skipCooldown) return "Wait for the layer to finish loading";
1334 if (w.biomeOverride != WorldGeneration.OverrideSceneType.None) return "Can't change layers here";
1335 if (w.biomeDepth < 1) return "You're already on the first layer";
1336 if (InstantiateWorldMethod == null || GlobalDark.main == null) return "Couldn't go back a layer in this game version";
1337 skipCooldown = Time.unscaledTime + 8f;
1338 b.forceWalk = false;
1339 if (w.savePanel != null) w.savePanel.SetActive(false);
1340 int target = w.biomeDepth - 1;
1341 w.StartCoroutine(GoBack(w, target));
1342 return "Going back to layer " + (target + 1);
1343 }
1344
1345 private static IEnumerator GoBack(WorldGeneration w, int target)
1346 {
1347 if (DoingRegenField != null) DoingRegenField.SetValue(w, true);
1348 w.canStartMercRun = false;
1349 GlobalDark.main.Darken();
1350 while (GlobalDark.main.IsDarkening()) yield return null;
1351 w.biomeDepth = target;
1352 Feed.Mod("Going back to layer " + (target + 1));
1353 yield return w.Clear();
1354 if (DoingRegenField != null) DoingRegenField.SetValue(w, false);
1355 yield return (IEnumerator)InstantiateWorldMethod.Invoke(w, new object[] { true });
1356 }
1357
1358 internal static void Teleport(Body b, Vector2 pos)
1359 {
1360 b.transform.position = pos;
1361 if (b.rb != null) b.rb.velocity = Vector2.zero;
1362 Vector3 cp = PlayerCamera.main.transform.position;
1363 PlayerCamera.main.transform.position = new Vector3(pos.x, pos.y, cp.z);
1364 if (ConsoleScript.instance != null) ConsoleScript.instance.noClipPos = pos;
1365 }
1366
1367 internal static string TeleportToCursor()
1368 {
1369 Body b = Player();
1370 if (b == null || Camera.main == null) return "Not in a run";
1371 Teleport(b, Camera.main.ScreenToWorldPoint(Input.mousePosition));
1372 return null;
1373 }
1374
1375 internal static string TeleportToExit()
1376 {
1377 Body b = Player();
1378 WorldGeneration w = WorldGeneration.world;
1379 if (b == null) return "Not in a run";
1380 if (w.generatingWorld || !w.worldExists) return "Wait for the layer to finish loading";
1381 if (w.biomeOverride != WorldGeneration.OverrideSceneType.None || w.biomeDepth >= 9) return "No layer exit here";
1382 Vector2 pos = new Vector2(b.transform.position.x, -(float)w.halfHeight + 2.5f);
1383 w.GenerateBlockCircle(pos, 3, 0, 1f, 1f, true);
1384 Teleport(b, pos);
1385 return "Teleported to the layer exit";
1386 }
1387
1388 internal static string StartEarthquake()
1389 {
1390 WorldGeneration w = WorldGeneration.world;
1391 if (Player() == null) return "Not in a run";
1392 if (Plugin.NoEarthquakes.Value) return "Turn off No Earthquakes first";
1393 w.earthquakeTime = Random.Range(10f, 20f);
1394 if (PlayerCamera.main.shaker != null) PlayerCamera.main.shaker.Shake(150f);
1395 return "Earthquake!";
1396 }
1397
1398 internal static string FungalDownpour()
1399 {
1400 if (Player() == null) return "Not in a run";
1401 DownpourUntil = Time.time + 60f;
1402 return "Fungal downpour for 60 seconds";
1403 }
1404
1405 internal static string UnlockCharacters()
1406 {
1407 for (int i = 0; i < 10; i++)
1408 if (PlayerPrefs.GetInt("wonchar" + i, 0) <= 0) PlayerPrefs.SetInt("wonchar" + i, 1);
1409 PlayerPrefs.Save();
1410 return "All characters unlocked";
1411 }
1412
1413 internal static string SpawnItem(string id, int amount)
1414 {
1415 Body b = Player();
1416 if (b == null) return "Not in a run";
1417 if (Resources.Load(id) as GameObject == null) return "Can't spawn " + id;
1418 for (int i = 0; i < amount; i++)
1419 {
1420 GameObject g = Utils.Create(id, b.transform.position, 0f);
1421 Item it = g != null ? g.GetComponent<Item>() : null;
1422 if (it != null) b.AutoPickUpItem(it);
1423 }
1424 Stats.Hit("Items spawned");
1425 return "Spawned " + ItemName(id) + (amount > 1 ? " x" + amount : "");
1426 }
1427
1428 internal static string StarterKit()
1429 {
1430 if (Player() == null || ConsoleScript.instance == null) return "Not in a run";
1431 System.Reflection.MethodInfo m = AccessTools.Method(typeof(ConsoleScript), "RunCommandString");
1432 if (m == null) return "Starter kit isn't available";
1433 m.Invoke(ConsoleScript.instance, new object[] { "starterkit" });
1434 return "Starter kit spawned";
1435 }
1436
1437 internal static string RandomLoadout()
1438 {
1439 Body b = Player();
1440 if (b == null || Item.GlobalItems == null) return "Not in a run";
1441 List<string> ids = new List<string>(Item.GlobalItems.Keys);
1442 int n = 0;
1443 for (int tries = 0; tries < 60 && n < 6; tries++)
1444 {
1445 string id = ids[Random.Range(0, ids.Count)];
1446 GameObject prefab = Resources.Load(id) as GameObject;
1447 if (prefab == null || prefab.GetComponent<Item>() == null) continue;
1448 SpawnItem(id, 1);
1449 n++;
1450 }
1451 return "Random loadout: " + n + " items";
1452 }
1453
1454 internal static string ItemName(string id)
1455 {
1456 try
1457 {
1458 string s = Locale.GetItem(id);
1459 if (!string.IsNullOrEmpty(s)) return s;
1460 }
1461 catch (System.Exception) { }
1462 return id;
1463 }
1464
1465 internal static string AddSkill(int stat, int delta)
1466 {
1467 Body b = Player();
1468 if (b == null || b.skills == null) return "Not in a run";
1469 Skills s = b.skills;
1470 int v = Mathf.Clamp((stat == 0 ? s.STR : stat == 1 ? s.RES : s.INT) + delta, 0, 40);
1471 float xp = Skills.GetExperienceForLevel(v);
1472 if (stat == 0) { s.STR = v; s.expSTR = xp; }
1473 else if (stat == 1) { s.RES = v; s.expRES = xp; }
1474 else { s.INT = v; s.expINT = xp; }
1475 s.UpdateExpBoundaries();
1476 return (stat == 0 ? "Strength " : stat == 1 ? "Resilience " : "Intelligence ") + v;
1477 }
1478 }
1479
1480 [HarmonyPatch(typeof(Body), "FixedUpdate")]
1481 internal static class BodyFixedUpdatePatch
1482 {
1483 private static void Postfix(Body __instance)
1484 {
1485 if (Plugin.GodOn(__instance)) Plugin.Restore(__instance);
1486 if (!Plugin.IsPlayer(__instance)) return;
1487 Plugin.ApplyKeeps(__instance);
1488 Rigidbody2D rb = __instance.rb;
1489 if (rb == null || !rb.simulated) return;
1490 if (Plugin.FlyMode.Value && __instance.standing && __instance.currentClimbable == null)
1491 {
1492 rb.gravityScale = 0f;
1493 Vector2 dir = __instance.moveDir;
1494 if (Input.GetKey(KeyCode.Space)) dir.y = 1f;
1495 if (dir.sqrMagnitude > 1f) dir.Normalize();
1496 float speed = Mathf.Max(1f, Plugin.FlySpeed.Value) * (Input.GetKey(KeyCode.LeftShift) ? 2.5f : 1f);
1497 rb.velocity = Vector2.Lerp(rb.velocity, dir * speed, 0.35f);
1498 }
1499 else if (Plugin.LowGravity.Value)
1500 {
1501 rb.gravityScale *= Mathf.Clamp(Plugin.GravityScale.Value, 0.05f, 1f);
1502 }
1503 }
1504 }
1505}