using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using AudioImportLib;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.AI;
using Il2CppSLZ.Marrow.PuppetMasta;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using TimeFreezeMod;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(TimeFreezeController), "TimeFreeze", "1.1.0", "VoidIndustries", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace TimeFreezeMod;
public class TimeFreezeController : MelonMod
{
private struct FrozenRigidbody
{
public Rigidbody Rb;
public bool WasKinematic;
public Vector3 Velocity;
public Vector3 AngularVelocity;
}
private struct SavedLight
{
public Light Light;
public float OrigIntensity;
public Color OrigColor;
}
private volatile bool _modEnabled = true;
private volatile bool _pendingToggleMod;
private bool _isFrozen;
private readonly List<FrozenRigidbody> _frozenObjects = new List<FrozenRigidbody>(256);
private readonly HashSet<Rigidbody> _playerRbs = new HashSet<Rigidbody>(32);
private bool _playerRbsCached;
private float _lastCacheTime = -999f;
private const float PlayerRbsCacheInterval = 2f;
private readonly Dictionary<Rigidbody, FrozenRigidbody> _heldObjects = new Dictionary<Rigidbody, FrozenRigidbody>(32);
private readonly HashSet<Rigidbody> _prevHeldObjects = new HashSet<Rigidbody>(32);
private readonly HashSet<Rigidbody> _currHeldObjects = new HashSet<Rigidbody>(32);
private readonly Dictionary<Rigidbody, int> _recentlyGrabbed = new Dictionary<Rigidbody, int>(32);
private const int RecentlyGrabbedGraceFrames = 10;
private BodyVitals _cachedVitals;
private Light[] _cachedLights;
private AudioClip _stopSound;
private AudioClip _resumeSound;
private AudioClip _scrubSound;
private GameObject _audioObj;
private AudioSource _audioSource;
private Volume _postProcessVolume;
private ColorAdjustments _colorAdjustments;
private Bloom _bloom;
private Vignette _vignette;
private ChromaticAberration _chromaticAberration;
private bool _origPostProcessEnabled;
private bool _origFogEnabled;
private Color _origFogColor;
private float _origFogDensity;
private readonly List<SavedLight> _savedLights = new List<SavedLight>(32);
private bool _origSlowTimeEnabled;
private float _origTimeScale;
private float _origFixedDeltaTime;
private Page _boneMenuPage;
private Type _timeManagerType;
private static FieldInfo _field_curTimeScale;
private static FieldInfo _field_tar_intensity;
private static FieldInfo _field_lrp_time;
private static FieldInfo _field_max_intensity;
private static FieldInfo _field_cur_intensity;
private static FieldInfo _field_tmp_intensity;
private static FieldInfo _field_cur_timeScaleStep;
private static FieldInfo _field_max_timeScaleStep;
private static FieldInfo _field_slowMoEnabled;
private static FieldInfo _field_isPaused;
private static FieldInfo _field_controllingTime;
private static TimeFreezeController _instance;
private readonly Dictionary<Rigidbody, BehaviourPuppet> _npcPuppets = new Dictionary<Rigidbody, BehaviourPuppet>(32);
private readonly Dictionary<Rigidbody, Animator> _npcAnimators = new Dictionary<Rigidbody, Animator>(32);
public override void OnInitializeMelon()
{
_instance = this;
LoadSounds();
MelonLogger.Msg("[TimeFreeze] Initialized. Left X: freeze, disables slow motion.");
try
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Assembly[] array = assemblies;
foreach (Assembly assembly in array)
{
if (!assembly.FullName.StartsWith("Il2CppSLZ") && !assembly.FullName.StartsWith("Assembly-CSharp"))
{
continue;
}
string[] array2 = new string[5] { "SLZ.Marrow.TimeManager", "TimeManager", "SLZ.Bonelab.TimeManager", "SLZ.TimeManager", "Marrow.TimeManager" };
string[] array3 = array2;
foreach (string name in array3)
{
Type type = assembly.GetType(name);
if (type != null && type.IsClass)
{
_timeManagerType = type;
break;
}
}
if (_timeManagerType != null)
{
break;
}
if (_timeManagerType == null)
{
try
{
Type[] types = assembly.GetTypes();
foreach (Type type2 in types)
{
if (type2.IsClass && (type2.Name.Contains("TimeManager") || type2.Name.Contains("TimeScale")))
{
_timeManagerType = type2;
break;
}
}
}
catch (ReflectionTypeLoadException ex)
{
Type[] types2 = ex.Types;
foreach (Type type3 in types2)
{
if (type3 != null && type3.IsClass && (type3.Name.Contains("TimeManager") || type3.Name.Contains("TimeScale")))
{
_timeManagerType = type3;
break;
}
}
}
catch
{
}
}
if (_timeManagerType != null)
{
break;
}
}
}
catch (Exception ex2)
{
MelonLogger.Error("[TimeFreeze] Could not find TimeManager: " + ex2.Message);
}
ApplyTimeManagerPatch();
}
public override void OnLateInitializeMelon()
{
SetupPostProcessing();
SetupBoneMenu();
}
private void ApplyTimeManagerPatch()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
try
{
if (!(_timeManagerType == null))
{
Harmony val = new Harmony("com.timefreeze.patch");
MethodInfo method = _timeManagerType.GetMethod("SET_TIMESCALE", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (method != null)
{
MethodInfo method2 = typeof(TimeFreezeController).GetMethod("SetTimeScalePrefix", BindingFlags.Static | BindingFlags.NonPublic);
val.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
else
{
MelonLogger.Warning("[TimeFreeze] TimeManager.SET_TIMESCALE method not found");
}
CacheTimeManagerFields();
}
}
catch (Exception ex)
{
MelonLogger.Error("[TimeFreeze] Failed to patch TimeManager: " + ex.Message + "\n" + ex.StackTrace);
}
}
private static bool SetTimeScalePrefix(float intensity)
{
return !(_instance?._isFrozen ?? false);
}
private static void ForceTimeManagerNormalStatic()
{
TimeFreezeController instance = _instance;
if (instance != null && instance._isFrozen && Time.timeScale != 1f)
{
_instance?.ForceTimeManagerNormal();
}
}
private void CacheTimeManagerFields()
{
if (_timeManagerType == null)
{
return;
}
try
{
_field_curTimeScale = _timeManagerType.GetField("_curTimeScale", BindingFlags.Static | BindingFlags.NonPublic);
_field_tar_intensity = _timeManagerType.GetField("tar_intensity", BindingFlags.Static | BindingFlags.NonPublic);
_field_lrp_time = _timeManagerType.GetField("lrp_time", BindingFlags.Static | BindingFlags.NonPublic);
_field_max_intensity = _timeManagerType.GetField("max_intensity", BindingFlags.Static | BindingFlags.NonPublic);
_field_cur_intensity = _timeManagerType.GetField("cur_intensity", BindingFlags.Static | BindingFlags.NonPublic);
_field_tmp_intensity = _timeManagerType.GetField("tmp_intensity", BindingFlags.Static | BindingFlags.NonPublic);
_field_cur_timeScaleStep = _timeManagerType.GetField("cur_timeScaleStep", BindingFlags.Static | BindingFlags.NonPublic);
_field_max_timeScaleStep = _timeManagerType.GetField("max_timeScaleStep", BindingFlags.Static | BindingFlags.NonPublic);
_field_slowMoEnabled = _timeManagerType.GetField("_slowMoEnabled", BindingFlags.Static | BindingFlags.NonPublic);
_field_isPaused = _timeManagerType.GetField("_isPaused", BindingFlags.Static | BindingFlags.NonPublic);
_field_controllingTime = _timeManagerType.GetField("_controllingTime", BindingFlags.Static | BindingFlags.NonPublic);
}
catch (Exception ex)
{
MelonLogger.Warning("[TimeFreeze] Failed to cache TimeManager fields: " + ex.Message);
}
}
private void ForceTimeManagerNormal()
{
try
{
if (_field_curTimeScale != null)
{
_field_curTimeScale.SetValue(null, 1f);
}
if (_field_tar_intensity != null)
{
_field_tar_intensity.SetValue(null, 1f);
}
if (_field_lrp_time != null)
{
_field_lrp_time.SetValue(null, 0f);
}
if (_field_max_intensity != null)
{
_field_max_intensity.SetValue(null, 1f);
}
if (_field_cur_intensity != null)
{
_field_cur_intensity.SetValue(null, 1f);
}
if (_field_tmp_intensity != null)
{
_field_tmp_intensity.SetValue(null, 1f);
}
if (_field_cur_timeScaleStep != null)
{
_field_cur_timeScaleStep.SetValue(null, 0);
}
if (_field_max_timeScaleStep != null)
{
_field_max_timeScaleStep.SetValue(null, 0);
}
if (_field_slowMoEnabled != null)
{
_field_slowMoEnabled.SetValue(null, false);
}
if (_field_isPaused != null)
{
_field_isPaused.SetValue(null, false);
}
if (_field_controllingTime != null)
{
_field_controllingTime.SetValue(null, false);
}
Time.timeScale = 1f;
Time.fixedDeltaTime = 0.02f;
}
catch (Exception ex)
{
MelonLogger.Warning("[TimeFreeze] ForceTimeManagerNormal failed: " + ex.Message);
}
}
private void RestoreTimeManagerState()
{
try
{
if (_field_slowMoEnabled != null)
{
_field_slowMoEnabled.SetValue(null, _origSlowTimeEnabled);
}
if (_field_max_timeScaleStep != null)
{
_field_max_timeScaleStep.SetValue(null, 10);
}
}
catch (Exception ex)
{
MelonLogger.Warning("[TimeFreeze] RestoreTimeManagerState failed: " + ex.Message);
}
}
private void LoadSounds()
{
//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Expected O, but got Unknown
try
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(directoryName, "Sounds");
PropertyInfo property = typeof(MelonUtils).GetProperty("GameDirectory", BindingFlags.Static | BindingFlags.Public);
string path2 = Path.Combine((string)property.GetValue(null), "UserData", "TimeFreeze", "Sounds");
string[] array = new string[9]
{
Path.Combine(path, "time-stop.wav"),
Path.Combine(path, "freeze_stop.wav"),
Path.Combine(path, "time stop.wav"),
Path.Combine(path, "freeze_stop.mp3"),
Path.Combine(path, "time stop.mp3"),
Path.Combine(path2, "freeze_stop.wav"),
Path.Combine(path2, "freeze_stop.mp3"),
Path.Combine(path2, "time stop.wav"),
Path.Combine(path2, "time stop.mp3")
};
string[] array2 = new string[9]
{
Path.Combine(path, "time-resume.wav"),
Path.Combine(path, "freeze_resume.wav"),
Path.Combine(path, "time resume.wav"),
Path.Combine(path, "freeze_resume.mp3"),
Path.Combine(path, "time resume.mp3"),
Path.Combine(path2, "freeze_resume.wav"),
Path.Combine(path2, "freeze_resume.mp3"),
Path.Combine(path2, "time resume.wav"),
Path.Combine(path2, "time resume.mp3")
};
string[] array3 = new string[8]
{
Path.Combine(path, "freeze_scrub.wav"),
Path.Combine(path, "time scrub.wav"),
Path.Combine(path, "freeze_scrub.mp3"),
Path.Combine(path, "time scrub.mp3"),
Path.Combine(path2, "freeze_scrub.wav"),
Path.Combine(path2, "freeze_scrub.mp3"),
Path.Combine(path2, "time scrub.wav"),
Path.Combine(path2, "time scrub.mp3")
};
string[] array4 = array;
foreach (string text in array4)
{
if (File.Exists(text))
{
_stopSound = API.LoadAudioClip(text, true);
if ((Object)(object)_stopSound != (Object)null)
{
break;
}
}
}
string[] array5 = array2;
foreach (string text2 in array5)
{
if (File.Exists(text2))
{
_resumeSound = API.LoadAudioClip(text2, true);
if ((Object)(object)_resumeSound != (Object)null)
{
break;
}
}
}
string[] array6 = array3;
foreach (string text3 in array6)
{
if (File.Exists(text3))
{
_scrubSound = API.LoadAudioClip(text3, true);
if ((Object)(object)_scrubSound != (Object)null)
{
break;
}
}
}
_audioObj = new GameObject("TimeFreezeAudio");
Object.DontDestroyOnLoad((Object)(object)_audioObj);
_audioSource = _audioObj.AddComponent<AudioSource>();
_audioSource.spatialBlend = 0f;
_audioSource.volume = 1f;
_audioSource.playOnAwake = false;
if ((Object)(object)_stopSound == (Object)null && (Object)(object)_resumeSound == (Object)null)
{
MelonLogger.Warning("[TimeFreeze] No sounds loaded!");
}
}
catch (Exception ex)
{
MelonLogger.Error("[TimeFreeze] Failed to load sounds: " + ex.Message + "\n" + ex.StackTrace);
}
}
private void SetupPostProcessing()
{
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
try
{
Il2CppArrayBase<Volume> val = Resources.FindObjectsOfTypeAll<Volume>();
foreach (Volume item in val)
{
if ((Object)(object)item.profile != (Object)null && item.profile.Has<ColorAdjustments>())
{
_postProcessVolume = item;
break;
}
}
if ((Object)(object)_postProcessVolume == (Object)null)
{
GameObject val2 = new GameObject("TimeFreezePostProcess");
Object.DontDestroyOnLoad((Object)(object)val2);
_postProcessVolume = val2.AddComponent<Volume>();
_postProcessVolume.isGlobal = true;
_postProcessVolume.priority = 100f;
_postProcessVolume.profile = ScriptableObject.CreateInstance<VolumeProfile>();
}
VolumeProfile profile = _postProcessVolume.profile;
if (!profile.TryGet<ColorAdjustments>(ref _colorAdjustments))
{
_colorAdjustments = profile.Add<ColorAdjustments>(true);
}
if (!profile.TryGet<Bloom>(ref _bloom))
{
_bloom = profile.Add<Bloom>(true);
}
if (!profile.TryGet<Vignette>(ref _vignette))
{
_vignette = profile.Add<Vignette>(true);
}
if (!profile.TryGet<ChromaticAberration>(ref _chromaticAberration))
{
_chromaticAberration = profile.Add<ChromaticAberration>(true);
}
_origPostProcessEnabled = ((Behaviour)_postProcessVolume).enabled;
((Behaviour)_postProcessVolume).enabled = false;
}
catch (Exception ex)
{
MelonLogger.Error("[TimeFreeze] Post-processing setup failed: " + ex.Message);
}
}
private void SetupBoneMenu()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
try
{
_boneMenuPage = Page.Root.CreatePage("TimeFreeze", Color.cyan, 0, true);
RebuildBoneMenu();
}
catch (Exception ex)
{
MelonLogger.Error("[TimeFreeze] BoneMenu setup failed: " + ex.Message);
}
}
private void RebuildBoneMenu()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (_boneMenuPage == null)
{
return;
}
_boneMenuPage.RemoveAll();
Color val = (_modEnabled ? Color.green : Color.red);
string text = (_modEnabled ? "MOD: ON (Left X: Freeze)" : "MOD: OFF");
_boneMenuPage.CreateFunction(text, val, (Action)delegate
{
_modEnabled = !_modEnabled;
RebuildBoneMenu();
if (!_modEnabled && _isFrozen)
{
UnfreezeTime();
}
});
}
public override void OnUpdate()
{
if (_modEnabled)
{
if ((Object)(object)Player.LeftController != (Object)null && Player.LeftController.GetAButtonDown())
{
_pendingToggleMod = true;
}
if (_pendingToggleMod)
{
ToggleFreeze();
_pendingToggleMod = false;
}
if (_isFrozen && Time.frameCount % 3 == 0)
{
HandleHeldObjects();
}
}
}
private void ToggleFreeze()
{
if (_modEnabled)
{
if (!_isFrozen)
{
FreezeTime();
}
else
{
UnfreezeTime();
}
}
}
private void HandleHeldObjects()
{
if (!_isFrozen)
{
return;
}
List<Rigidbody> list = new List<Rigidbody>();
foreach (KeyValuePair<Rigidbody, int> item in _recentlyGrabbed)
{
_recentlyGrabbed[item.Key] = item.Value - 1;
if (_recentlyGrabbed[item.Key] <= 0)
{
list.Add(item.Key);
}
}
foreach (Rigidbody item2 in list)
{
_recentlyGrabbed.Remove(item2);
}
_currHeldObjects.Clear();
CheckHand(Player.LeftHand);
CheckHand(Player.RightHand);
foreach (Rigidbody prevHeldObject in _prevHeldObjects)
{
if (_currHeldObjects.Contains(prevHeldObject) || !_heldObjects.TryGetValue(prevHeldObject, out var _))
{
continue;
}
List<Rigidbody> allConnectedRigidbodies = GetAllConnectedRigidbodies(prevHeldObject);
foreach (Rigidbody item3 in allConnectedRigidbodies)
{
RefreezeSingleObject(item3);
_heldObjects.Remove(item3);
}
_recentlyGrabbed.Remove(prevHeldObject);
}
_prevHeldObjects.Clear();
foreach (Rigidbody currHeldObject in _currHeldObjects)
{
_prevHeldObjects.Add(currHeldObject);
}
}
private void CheckHand(Hand hand)
{
if ((Object)(object)hand == (Object)null)
{
return;
}
HandReciever attachedReceiver = hand.AttachedReceiver;
if ((Object)(object)attachedReceiver != (Object)null)
{
IGrippable host = attachedReceiver.Host;
if (host != null && host.HasRigidbody)
{
Rigidbody rb = host.Rb;
if ((Object)(object)rb != (Object)null)
{
_currHeldObjects.Add(rb);
if (!_heldObjects.ContainsKey(rb))
{
UnfreezeHeldObjectWithConnected(rb);
_recentlyGrabbed[rb] = 10;
}
}
}
}
if (hand.GetIndexButtonDown())
{
TryUnfreezeForGrab(hand);
}
}
private void TryUnfreezeForGrab(Hand hand)
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)hand == (Object)null)
{
return;
}
HandReciever hoveringReceiver = hand.HoveringReceiver;
if ((Object)(object)hoveringReceiver == (Object)null)
{
return;
}
IGrippable host = hoveringReceiver.Host;
if (host != null && host.HasRigidbody)
{
Rigidbody rb = host.Rb;
if (!((Object)(object)rb == (Object)null) && (rb.isKinematic || (rb.velocity == Vector3.zero && rb.angularVelocity == Vector3.zero)))
{
UnfreezeHeldObjectWithConnected(rb);
_recentlyGrabbed[rb] = 10;
}
}
}
private void UnfreezeHeldObjectWithConnected(Rigidbody rb)
{
List<Rigidbody> allConnectedRigidbodies = GetAllConnectedRigidbodies(rb);
foreach (Rigidbody item in allConnectedRigidbodies)
{
UnfreezeSingleHeldObject(item);
}
}
private void UnfreezeSingleHeldObject(Rigidbody rb)
{
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
for (int num = _frozenObjects.Count - 1; num >= 0; num--)
{
if ((Object)(object)_frozenObjects[num].Rb == (Object)(object)rb)
{
FrozenRigidbody value = _frozenObjects[num];
_frozenObjects.RemoveAt(num);
rb.isKinematic = value.WasKinematic;
if (!value.WasKinematic)
{
rb.velocity = value.Velocity;
rb.angularVelocity = value.AngularVelocity;
}
_heldObjects[rb] = value;
return;
}
}
FrozenRigidbody value2 = new FrozenRigidbody
{
Rb = rb,
WasKinematic = rb.isKinematic,
Velocity = rb.velocity,
AngularVelocity = rb.angularVelocity
};
rb.isKinematic = false;
_heldObjects[rb] = value2;
}
private List<Rigidbody> GetAllConnectedRigidbodies(Rigidbody rootRb)
{
List<Rigidbody> list = new List<Rigidbody>();
HashSet<Rigidbody> hashSet = new HashSet<Rigidbody>();
Queue<Rigidbody> queue = new Queue<Rigidbody>();
queue.Enqueue(rootRb);
hashSet.Add(rootRb);
while (queue.Count > 0)
{
Rigidbody val = queue.Dequeue();
list.Add(val);
Il2CppArrayBase<Joint> components = ((Component)val).GetComponents<Joint>();
foreach (Joint item in components)
{
if ((Object)(object)item.connectedBody != (Object)null && !hashSet.Contains(item.connectedBody) && !_playerRbs.Contains(item.connectedBody))
{
hashSet.Add(item.connectedBody);
queue.Enqueue(item.connectedBody);
}
}
Il2CppArrayBase<Rigidbody> componentsInChildren = ((Component)val).GetComponentsInChildren<Rigidbody>();
foreach (Rigidbody item2 in componentsInChildren)
{
if (!hashSet.Contains(item2) && !_playerRbs.Contains(item2))
{
hashSet.Add(item2);
queue.Enqueue(item2);
}
}
if ((Object)(object)((Component)val).transform.parent != (Object)null)
{
Rigidbody component = ((Component)((Component)val).transform.parent).GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null && !hashSet.Contains(component) && !_playerRbs.Contains(component))
{
hashSet.Add(component);
queue.Enqueue(component);
}
}
}
return list;
}
private void UnfreezeHeldObject(Rigidbody rb)
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
for (int num = _frozenObjects.Count - 1; num >= 0; num--)
{
if ((Object)(object)_frozenObjects[num].Rb == (Object)(object)rb)
{
FrozenRigidbody value = _frozenObjects[num];
_frozenObjects.RemoveAt(num);
rb.isKinematic = value.WasKinematic;
if (!value.WasKinematic)
{
rb.velocity = value.Velocity;
rb.angularVelocity = value.AngularVelocity;
}
_heldObjects[rb] = value;
break;
}
}
}
private void RefreezeObject(Rigidbody rb, FrozenRigidbody frozen)
{
List<Rigidbody> allConnectedRigidbodies = GetAllConnectedRigidbodies(rb);
foreach (Rigidbody item in allConnectedRigidbodies)
{
RefreezeSingleObject(item);
}
}
private void RefreezeSingleObject(Rigidbody rb)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
_frozenObjects.Add(new FrozenRigidbody
{
Rb = rb,
WasKinematic = rb.isKinematic,
Velocity = rb.velocity,
AngularVelocity = rb.angularVelocity
});
rb.isKinematic = true;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
}
private void FreezeTime()
{
_isFrozen = true;
MelonLogger.Msg("[TimeFreeze] Time FROZEN");
if ((Object)(object)_cachedVitals == (Object)null)
{
_cachedVitals = ((IEnumerable<BodyVitals>)Resources.FindObjectsOfTypeAll<BodyVitals>()).FirstOrDefault();
}
if ((Object)(object)_cachedVitals != (Object)null)
{
_origSlowTimeEnabled = _cachedVitals.slowTimeEnabled;
_cachedVitals.slowTimeEnabled = false;
}
_origTimeScale = Time.timeScale;
_origFixedDeltaTime = Time.fixedDeltaTime;
Time.timeScale = 1f;
Time.fixedDeltaTime = 0.02f;
TryCallTimeManager("RESET_TIMESCALE");
TrySetTimeManagerSlowMo(enabled: false);
ForceTimeManagerNormal();
PlaySound(_stopSound);
ApplyContrast(enable: true);
FreezeRigidbodies();
}
private void UnfreezeTime()
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
_isFrozen = false;
MelonLogger.Msg("[TimeFreeze] Time UNFROZEN");
foreach (KeyValuePair<Rigidbody, FrozenRigidbody> heldObject in _heldObjects)
{
Rigidbody key = heldObject.Key;
FrozenRigidbody value = heldObject.Value;
if ((Object)(object)key != (Object)null)
{
key.isKinematic = value.WasKinematic;
if (!value.WasKinematic && key.velocity == Vector3.zero && key.angularVelocity == Vector3.zero)
{
key.velocity = value.Velocity;
key.angularVelocity = value.AngularVelocity;
}
}
}
_heldObjects.Clear();
_prevHeldObjects.Clear();
if ((Object)(object)_cachedVitals != (Object)null)
{
_cachedVitals.slowTimeEnabled = _origSlowTimeEnabled;
}
Time.timeScale = _origTimeScale;
Time.fixedDeltaTime = _origFixedDeltaTime;
TrySetTimeManagerSlowMo(_origSlowTimeEnabled);
RestoreTimeManagerState();
PlaySound(_resumeSound);
ApplyContrast(enable: false);
UnfreezeRigidbodies();
CleanupStuckKinematicObjects();
}
private void CleanupStuckKinematicObjects()
{
Il2CppArrayBase<Rigidbody> val = Resources.FindObjectsOfTypeAll<Rigidbody>();
int num = 0;
foreach (Rigidbody item in val)
{
if (!((Object)(object)item == (Object)null) && item.isKinematic && !_playerRbs.Contains(item) && !IsNPCRigidbody(item) && (item.mass < 0.5f || ((Object)((Component)item).gameObject).name.ToLower().Contains("case") || ((Object)((Component)item).gameObject).name.ToLower().Contains("shell") || ((Object)((Component)item).gameObject).name.ToLower().Contains("debris")))
{
item.isKinematic = false;
num++;
}
}
if (num > 0)
{
MelonLogger.Msg($"[TimeFreeze] Cleaned up {num} stuck kinematic objects");
}
}
private void TryCallTimeManager(string methodName)
{
if (_timeManagerType == null)
{
return;
}
try
{
MethodInfo method = _timeManagerType.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public);
if (method != null)
{
method.Invoke(null, null);
MelonLogger.Msg("[TimeFreeze] Called TimeManager." + methodName + "()");
}
else
{
MelonLogger.Warning("[TimeFreeze] TimeManager." + methodName + "() not found");
}
}
catch (Exception ex)
{
MelonLogger.Warning("[TimeFreeze] Failed to call TimeManager." + methodName + ": " + ex.Message);
}
}
private void TrySetTimeManagerSlowMo(bool enabled)
{
if (_timeManagerType == null)
{
return;
}
try
{
PropertyInfo property = _timeManagerType.GetProperty("slowMoEnabled", BindingFlags.Static | BindingFlags.Public);
if (property != null && property.CanWrite)
{
property.SetValue(null, enabled);
}
}
catch
{
}
}
private void ApplyContrast(bool enable)
{
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
try
{
if (enable)
{
BackupVisualState();
if ((Object)(object)_postProcessVolume != (Object)null)
{
((Behaviour)_postProcessVolume).enabled = true;
}
if ((Object)(object)_colorAdjustments != (Object)null)
{
((VolumeParameter<float>)(object)_colorAdjustments.saturation).value = -100f;
((VolumeParameter<float>)(object)_colorAdjustments.contrast).value = 50f;
((VolumeParameter<float>)(object)_colorAdjustments.postExposure).value = 0.3f;
((VolumeParameter<Color>)(object)_colorAdjustments.colorFilter).value = new Color(0.85f, 0.9f, 1f);
}
if ((Object)(object)_bloom != (Object)null)
{
((VolumeComponent)_bloom).active = true;
((VolumeParameter<float>)(object)_bloom.intensity).value = 0.3f;
((VolumeParameter<float>)(object)_bloom.threshold).value = 0.9f;
((VolumeParameter<float>)(object)_bloom.scatter).value = 0.5f;
((VolumeParameter<Color>)(object)_bloom.tint).value = new Color(0.9f, 0.95f, 1f);
}
if ((Object)(object)_vignette != (Object)null)
{
((VolumeComponent)_vignette).active = true;
((VolumeParameter<float>)(object)_vignette.intensity).value = 0.35f;
((VolumeParameter<float>)(object)_vignette.smoothness).value = 0.4f;
((VolumeParameter<Color>)(object)_vignette.color).value = Color.black;
}
if ((Object)(object)_chromaticAberration != (Object)null)
{
((VolumeComponent)_chromaticAberration).active = true;
((VolumeParameter<float>)(object)_chromaticAberration.intensity).value = 0.15f;
}
RenderSettings.fog = true;
RenderSettings.fogColor = new Color(0.15f, 0.2f, 0.3f);
RenderSettings.fogDensity = 0.015f;
ApplyLightChanges(enable: true);
}
else
{
RestoreVisualState();
}
}
catch (Exception ex)
{
MelonLogger.Error("[TimeFreeze] ApplyContrast failed: " + ex.Message);
}
}
private void BackupVisualState()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Invalid comparison between Unknown and I4
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
_origFogEnabled = RenderSettings.fog;
_origFogColor = RenderSettings.fogColor;
_origFogDensity = RenderSettings.fogDensity;
_cachedLights = Il2CppArrayBase<Light>.op_Implicit(Resources.FindObjectsOfTypeAll<Light>());
_savedLights.Clear();
if (_cachedLights == null)
{
return;
}
Light[] cachedLights = _cachedLights;
foreach (Light val in cachedLights)
{
if ((Object)(object)val != (Object)null && (int)val.type != 1)
{
_savedLights.Add(new SavedLight
{
Light = val,
OrigIntensity = val.intensity,
OrigColor = val.color
});
}
}
}
private void RestoreVisualState()
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_postProcessVolume != (Object)null)
{
((Behaviour)_postProcessVolume).enabled = _origPostProcessEnabled;
}
if ((Object)(object)_colorAdjustments != (Object)null)
{
((VolumeParameter<float>)(object)_colorAdjustments.saturation).value = 0f;
((VolumeParameter<float>)(object)_colorAdjustments.contrast).value = 0f;
((VolumeParameter<float>)(object)_colorAdjustments.postExposure).value = 0f;
((VolumeParameter<Color>)(object)_colorAdjustments.colorFilter).value = Color.white;
}
if ((Object)(object)_bloom != (Object)null)
{
((VolumeComponent)_bloom).active = false;
}
if ((Object)(object)_vignette != (Object)null)
{
((VolumeComponent)_vignette).active = false;
}
if ((Object)(object)_chromaticAberration != (Object)null)
{
((VolumeComponent)_chromaticAberration).active = false;
}
RenderSettings.fog = _origFogEnabled;
RenderSettings.fogColor = _origFogColor;
RenderSettings.fogDensity = _origFogDensity;
foreach (SavedLight savedLight in _savedLights)
{
if ((Object)(object)savedLight.Light != (Object)null)
{
savedLight.Light.intensity = savedLight.OrigIntensity;
savedLight.Light.color = savedLight.OrigColor;
}
}
_savedLights.Clear();
MelonLogger.Msg("[TimeFreeze] Visual state restored");
}
private void ApplyLightChanges(bool enable)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Invalid comparison between Unknown and I4
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
if (_cachedLights == null)
{
return;
}
Light[] cachedLights = _cachedLights;
foreach (Light light in cachedLights)
{
if ((Object)(object)light == (Object)null || (int)light.type == 1)
{
continue;
}
if (enable)
{
light.color = Color.Lerp(light.color, new Color(0.85f, 0.9f, 1f), 0.4f);
Light obj = light;
obj.intensity *= 1.15f;
continue;
}
SavedLight savedLight = _savedLights.Find((SavedLight s) => (Object)(object)s.Light == (Object)(object)light);
if ((Object)(object)savedLight.Light != (Object)null)
{
light.intensity = savedLight.OrigIntensity;
light.color = savedLight.OrigColor;
}
}
}
private void FreezeRigidbodies()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
_frozenObjects.Clear();
CachePlayerRigidbodies();
Il2CppArrayBase<Rigidbody> val = Resources.FindObjectsOfTypeAll<Rigidbody>();
foreach (Rigidbody item in val)
{
if ((Object)(object)item == (Object)null || _playerRbs.Contains(item))
{
continue;
}
_frozenObjects.Add(new FrozenRigidbody
{
Rb = item,
WasKinematic = item.isKinematic,
Velocity = item.velocity,
AngularVelocity = item.angularVelocity
});
item.isKinematic = true;
item.velocity = Vector3.zero;
item.angularVelocity = Vector3.zero;
if (IsNPCRigidbody(item))
{
BehaviourPuppet componentInParent = ((Component)item).GetComponentInParent<BehaviourPuppet>();
if ((Object)(object)componentInParent != (Object)null)
{
_npcPuppets[item] = componentInParent;
((Behaviour)componentInParent).enabled = false;
}
Animator componentInParent2 = ((Component)item).GetComponentInParent<Animator>();
if ((Object)(object)componentInParent2 != (Object)null)
{
_npcAnimators[item] = componentInParent2;
((Behaviour)componentInParent2).enabled = false;
}
}
}
MelonLogger.Msg($"[TimeFreeze] Froze {_frozenObjects.Count} rigidbodies");
}
private bool IsNPCRigidbody(Rigidbody rb)
{
GameObject gameObject = ((Component)rb).gameObject;
if ((Object)(object)gameObject == (Object)null)
{
return false;
}
return (Object)(object)gameObject.GetComponentInParent<AIBrain>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<BehaviourPuppet>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<BehaviourBaseNav>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<BehaviourBase>() != (Object)null;
}
private void UnfreezeRigidbodies()
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
foreach (FrozenRigidbody frozenObject in _frozenObjects)
{
if ((Object)(object)frozenObject.Rb != (Object)null && !_heldObjects.ContainsKey(frozenObject.Rb))
{
frozenObject.Rb.isKinematic = frozenObject.WasKinematic;
if (!frozenObject.WasKinematic)
{
frozenObject.Rb.velocity = frozenObject.Velocity;
frozenObject.Rb.angularVelocity = frozenObject.AngularVelocity;
}
if (_npcPuppets.TryGetValue(frozenObject.Rb, out var value) && (Object)(object)value != (Object)null)
{
((Behaviour)value).enabled = true;
}
if (_npcAnimators.TryGetValue(frozenObject.Rb, out var value2) && (Object)(object)value2 != (Object)null)
{
((Behaviour)value2).enabled = true;
}
}
}
_frozenObjects.Clear();
_npcPuppets.Clear();
_npcAnimators.Clear();
}
private void CachePlayerRigidbodies()
{
if (_playerRbsCached && Time.time - _lastCacheTime < 2f)
{
return;
}
_playerRbs.Clear();
RigManager rigManager = Player.RigManager;
if ((Object)(object)rigManager != (Object)null)
{
PhysicsRig physicsRig = rigManager.physicsRig;
if ((Object)(object)physicsRig != (Object)null && physicsRig.selfRbs != null)
{
Enumerator<Rigidbody> enumerator = physicsRig.selfRbs.GetEnumerator();
while (enumerator.MoveNext())
{
Rigidbody current = enumerator.Current;
if ((Object)(object)current != (Object)null)
{
_playerRbs.Add(current);
}
}
}
else
{
Il2CppArrayBase<Rigidbody> componentsInChildren = ((Component)rigManager).GetComponentsInChildren<Rigidbody>(true);
foreach (Rigidbody item in componentsInChildren)
{
if ((Object)(object)item != (Object)null)
{
_playerRbs.Add(item);
}
}
}
}
_playerRbsCached = true;
_lastCacheTime = Time.time;
}
private void EnsureAudioSource()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
if ((Object)(object)_audioObj == (Object)null || (Object)(object)_audioSource == (Object)null)
{
_audioObj = new GameObject("TimeFreezeAudio");
Object.DontDestroyOnLoad((Object)(object)_audioObj);
_audioSource = _audioObj.AddComponent<AudioSource>();
_audioSource.spatialBlend = 0f;
_audioSource.volume = 1f;
_audioSource.playOnAwake = false;
_audioSource.loop = false;
MelonLogger.Msg("[TimeFreeze] AudioSource created");
}
}
private void PlaySound(AudioClip clip)
{
if ((Object)(object)clip != (Object)null)
{
EnsureAudioSource();
if ((Object)(object)_audioSource != (Object)null)
{
_audioSource.PlayOneShot(clip);
MelonLogger.Msg($"[TimeFreeze] Played sound: {((Object)clip).name}, length: {clip.length}s");
}
}
else
{
MelonLogger.Warning("[TimeFreeze] PlaySound called with null clip");
}
}
public override void OnDeinitializeMelon()
{
if (_isFrozen)
{
UnfreezeTime();
}
if ((Object)(object)_audioObj != (Object)null)
{
Object.Destroy((Object)(object)_audioObj);
}
if ((Object)(object)_postProcessVolume != (Object)null && (Object)(object)((Component)_postProcessVolume).gameObject != (Object)null)
{
Object.Destroy((Object)(object)((Component)_postProcessVolume).gameObject);
}
MelonLogger.Msg("[TimeFreeze] Deinitialized");
}
}
public class TimeManagerInspector : MelonMod
{
public override void OnInitializeMelon()
{
MelonLogger.Msg("[TimeManagerInspector] Starting inspection...");
try
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Assembly[] array = assemblies;
foreach (Assembly assembly in array)
{
if (!assembly.FullName.StartsWith("Il2CppSLZ.Marrow"))
{
continue;
}
MelonLogger.Msg("[TimeManagerInspector] Found assembly: " + assembly.FullName);
Type type = assembly.GetType("SLZ.Marrow.TimeManager");
if (type != null)
{
MelonLogger.Msg("[TimeManagerInspector] Found TimeManager: " + type.FullName);
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
MelonLogger.Msg($"[TimeManagerInspector] Fields ({fields.Length}):");
FieldInfo[] array2 = fields;
foreach (FieldInfo fieldInfo in array2)
{
MelonLogger.Msg($" {fieldInfo.FieldType.Name} {fieldInfo.Name} (Static: {fieldInfo.IsStatic}, Public: {fieldInfo.IsPublic})");
}
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
MelonLogger.Msg($"[TimeManagerInspector] Methods ({methods.Length}):");
MethodInfo[] array3 = methods;
foreach (MethodInfo methodInfo in array3)
{
if (!methodInfo.Name.StartsWith("get_") && !methodInfo.Name.StartsWith("set_") && !methodInfo.Name.StartsWith("add_") && !methodInfo.Name.StartsWith("remove_"))
{
string value = string.Join(", ", from p in methodInfo.GetParameters()
select p.ParameterType.Name + " " + p.Name);
MelonLogger.Msg($" {methodInfo.ReturnType.Name} {methodInfo.Name}({value}) (Static: {methodInfo.IsStatic}, Public: {methodInfo.IsPublic})");
}
}
}
else
{
MelonLogger.Msg("[TimeManagerInspector] TimeManager not found in " + assembly.FullName);
}
}
}
catch (Exception ex)
{
MelonLogger.Error("[TimeManagerInspector] Error: " + ex.Message + "\n" + ex.StackTrace);
}
}
}