using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.InteropTypes.Fields;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WeatherElectric.WaterDynamics;
using WeatherElectric.WaterDynamics.Behaviours;
using WeatherElectric.WaterDynamics.Behaviours.Internal;
using WeatherElectric.WaterDynamics.Melon;
using WeatherElectric.WaterDynamics.Resources;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Water Physics for BONELAB")]
[assembly: AssemblyDescription("Water Physics for BONELAB")]
[assembly: AssemblyCompany("Weather Electric")]
[assembly: AssemblyProduct("WaterDynamics")]
[assembly: AssemblyCopyright("Developed by SoulWithMae")]
[assembly: AssemblyTrademark("Weather Electric")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: MelonInfo(typeof(Main), "WaterDynamics", "1.1.0", "SoulWithMae", "https://thunderstore.io/c/bonelab/p/SoulWithMae/WaterDynamics/")]
[assembly: MelonColor(255, 30, 152, 255)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace WeatherElectric.WaterDynamics
{
internal static class FieldInjection
{
private static bool _injected;
public static void Inject()
{
if (!_injected)
{
ClassInjector.RegisterTypeInIl2Cpp<FloatingObject>();
ClassInjector.RegisterTypeInIl2Cpp<HandSwimmingController>();
ClassInjector.RegisterTypeInIl2Cpp<WaterZone>();
_injected = true;
}
}
}
public class Main : MelonMod
{
internal const string Name = "WaterDynamics";
internal const string Description = "Water Physics for BONELAB";
internal const string Author = "SoulWithMae";
internal const string Company = "Weather Electric";
internal const string Version = "1.1.0";
internal const string DownloadLink = "https://thunderstore.io/c/bonelab/p/SoulWithMae/WaterDynamics/";
public override void OnInitializeMelon()
{
ModConsole.Setup(((MelonBase)this).LoggerInstance);
Preferences.Setup();
Assets.LoadAssets();
FieldInjection.Inject();
}
}
}
namespace WeatherElectric.WaterDynamics.Resources
{
internal static class Assets
{
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
private static AssetBundle _assetBundle;
public static GameObject DefaultSplashParticles { get; private set; }
public static void LoadAssets()
{
_assetBundle = AssetLoader.LoadEmbeddedAssetBundle(Assembly, "WeatherElectric.WaterDynamics.Resources.SplashPrefab.Windows.pack");
DefaultSplashParticles = _assetBundle.LoadPersistentAsset<GameObject>("Assets/Splash.prefab");
}
}
internal static class AssetLoader
{
public static AssetBundle LoadEmbeddedAssetBundle(Assembly assembly, string name)
{
string[] manifestResourceNames = assembly.GetManifestResourceNames();
AssetBundle result = null;
if (manifestResourceNames.Contains(name))
{
ModConsole.Msg("Loading embedded resource data " + name + "...", 1);
using Stream stream = assembly.GetManifestResourceStream(name);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
ModConsole.Msg("Done!", 1);
byte[] array = memoryStream.ToArray();
ModConsole.Msg("Loading assetBundle from data " + name + ", please be patient...", 1);
result = AssetBundle.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
ModConsole.Msg("Done!", 1);
}
return result;
}
public static T LoadPersistentAsset<T>(this AssetBundle assetBundle, string name) where T : Object
{
Object val = assetBundle.LoadAsset(name);
if (val != (Object)null)
{
val.hideFlags = (HideFlags)32;
return ((Il2CppObjectBase)val).TryCast<T>();
}
return default(T);
}
}
}
namespace WeatherElectric.WaterDynamics.Melon
{
internal static class ModConsole
{
private static Instance _logger;
public static void Setup(Instance loggerInstance)
{
_logger = loggerInstance;
}
public static void Msg(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text);
}
}
public static void Msg(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text);
}
}
public static void Msg(ConsoleColor txtcolor, object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text);
}
}
public static void Msg(ConsoleColor txtcolor, string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text);
}
}
public static void Msg(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text, args);
}
}
public static void Msg(ConsoleColor txtcolor, string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text, args);
}
}
public static void Error(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text);
}
}
public static void Error(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text);
}
}
public static void Error(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text, args);
}
}
public static void Warning(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text);
}
}
public static void Warning(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text);
}
}
public static void Warning(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text, args);
}
}
}
internal static class Preferences
{
public static readonly MelonPreferences_Category GlobalCategory = MelonPreferences.CreateCategory("Global");
public static MelonPreferences_Entry<int> LoggingMode { get; set; }
public static void Setup()
{
LoggingMode = GlobalCategory.GetEntry<int>("LoggingMode") ?? GlobalCategory.CreateEntry<int>("LoggingMode", 0, "Logging Mode", "The level of logging to use. 0 = Important Only, 1 = All", false, false, (ValueValidator)null, (string)null);
GlobalCategory.SetFilePath(MelonEnvironment.UserDataDirectory + "/WeatherElectric.cfg");
GlobalCategory.SaveToFile(false);
ModConsole.Msg("Finished preferences setup for WaterDynamics", 1);
}
}
}
namespace WeatherElectric.WaterDynamics.Behaviours
{
public class WaterZone : MonoBehaviour
{
private readonly List<FloatingObject> _inTriggerCol = new List<FloatingObject>();
public Il2CppValueField<float> BuoyancyMultiplier;
public Il2CppValueField<float> Midpoint;
public Il2CppValueField<bool> MidpointSink;
public Il2CppValueField<bool> Dampening;
public Il2CppValueField<float> DampeningAmount;
public Il2CppValueField<bool> IgnoreRigManager;
public Il2CppValueField<bool> AllowSwimming;
public Il2CppValueField<float> MinimumVelocity;
public Il2CppValueField<float> VelocityMultiplier;
public Il2CppValueField<bool> EnableSplashParticles;
public Il2CppReferenceField<GameObject> SplashParticlePrefab;
public Il2CppValueField<float> SplashParticleLifetime;
public Il2CppValueField<float> MinimumVelocityForSplash;
private void Start()
{
if ((Object)(object)SplashParticlePrefab.Get() == (Object)null)
{
SplashParticlePrefab.Set(Assets.DefaultSplashParticles);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.isTrigger)
{
return;
}
Rigidbody attachedRigidbody = other.attachedRigidbody;
RigManager componentInParent = ((Component)other).GetComponentInParent<RigManager>();
if ((Object)(object)componentInParent != (Object)null && IgnoreRigManager.Get())
{
return;
}
AddHandMonitors(componentInParent);
SpawnSplashParticle(other);
FloatingObject floatingObject = null;
if ((Object)(object)attachedRigidbody != (Object)null)
{
floatingObject = ((Component)attachedRigidbody).GetComponent<FloatingObject>();
}
if ((Object)(object)floatingObject != (Object)null)
{
((Behaviour)floatingObject).enabled = true;
_inTriggerCol.Add(floatingObject);
}
else
{
if (!((Object)(object)attachedRigidbody != (Object)null) || !((Object)(object)((Component)attachedRigidbody).GetComponent<FloatingObject>() == (Object)null))
{
return;
}
FloatingObject floatingObject2 = ((Component)attachedRigidbody).gameObject.AddComponent<FloatingObject>();
floatingObject2.Dampening = Il2CppValueField<bool>.op_Implicit(Dampening);
floatingObject2.BuoyancyMultiplier = Il2CppValueField<float>.op_Implicit(BuoyancyMultiplier);
floatingObject2.Midpoint = Il2CppValueField<float>.op_Implicit(Midpoint);
floatingObject2.DampeningAmount = Il2CppValueField<float>.op_Implicit(DampeningAmount);
floatingObject2.MidpointSink = Il2CppValueField<bool>.op_Implicit(MidpointSink);
floatingObject2.OnDestroyed = OnBuoyancyManagerDestroyed;
Rigidbody[] array = Il2CppArrayBase<Rigidbody>.op_Implicit(((Component)attachedRigidbody).GetComponentsInChildren<Rigidbody>(true));
foreach (Rigidbody val in array)
{
if (val.isKinematic && (Object)(object)((Component)val).GetComponent<FloatingObject>() == (Object)null)
{
FloatingObject floatingObject3 = ((Component)val).gameObject.AddComponent<FloatingObject>();
floatingObject3.BuoyancyMultiplier = Il2CppValueField<float>.op_Implicit(BuoyancyMultiplier);
floatingObject3.Dampening = Il2CppValueField<bool>.op_Implicit(Dampening);
floatingObject3.Midpoint = Il2CppValueField<float>.op_Implicit(Midpoint);
floatingObject3.DampeningAmount = Il2CppValueField<float>.op_Implicit(DampeningAmount);
floatingObject3.MidpointSink = Il2CppValueField<bool>.op_Implicit(MidpointSink);
}
}
_inTriggerCol.Add(floatingObject2);
}
}
private void SpawnSplashParticle(Collider other)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
if (EnableSplashParticles.Get())
{
Vector3 velocity = other.attachedRigidbody.velocity;
if (!(((Vector3)(ref velocity)).sqrMagnitude < Il2CppValueField<float>.op_Implicit(MinimumVelocityForSplash)))
{
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(((Component)other).transform.position.x, ((Component)other).transform.position.y, ((Component)other).transform.position.z);
Object.Destroy((Object)(object)Object.Instantiate<GameObject>(SplashParticlePrefab.Get(), val, Quaternion.identity), SplashParticleLifetime.Get());
}
}
}
private void AddHandMonitors(RigManager rigManager)
{
if (!((Object)(object)rigManager == (Object)null) && AllowSwimming.Get())
{
if ((Object)(object)((Component)rigManager.physicsRig.leftHand).GetComponent<HandSwimmingController>() == (Object)null)
{
HandSwimmingController handSwimmingController = ((Component)rigManager.physicsRig.leftHand).gameObject.AddComponent<HandSwimmingController>();
handSwimmingController.RigManager = rigManager;
handSwimmingController.MinVelocity = Il2CppValueField<float>.op_Implicit(MinimumVelocity);
handSwimmingController.VelocityMult = Il2CppValueField<float>.op_Implicit(VelocityMultiplier);
}
if ((Object)(object)((Component)rigManager.physicsRig.rightHand).GetComponent<HandSwimmingController>() == (Object)null)
{
HandSwimmingController handSwimmingController2 = ((Component)rigManager.physicsRig.rightHand).gameObject.AddComponent<HandSwimmingController>();
handSwimmingController2.RigManager = rigManager;
handSwimmingController2.MinVelocity = Il2CppValueField<float>.op_Implicit(MinimumVelocity);
handSwimmingController2.VelocityMult = Il2CppValueField<float>.op_Implicit(VelocityMultiplier);
}
}
}
private void RemoveHandMonitors(RigManager rigManager)
{
if (!((Object)(object)rigManager == (Object)null) && AllowSwimming.Get())
{
if ((Object)(object)((Component)rigManager.physicsRig.leftHand).GetComponent<HandSwimmingController>() != (Object)null)
{
Object.Destroy((Object)(object)((Component)rigManager.physicsRig.leftHand).GetComponent<HandSwimmingController>());
}
if ((Object)(object)((Component)rigManager.physicsRig.rightHand).GetComponent<HandSwimmingController>() != (Object)null)
{
Object.Destroy((Object)(object)((Component)rigManager.physicsRig.rightHand).GetComponent<HandSwimmingController>());
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.isTrigger)
{
return;
}
RigManager componentInParent = ((Component)other).GetComponentInParent<RigManager>();
RemoveHandMonitors(componentInParent);
Rigidbody attachedRigidbody = other.attachedRigidbody;
FloatingObject floatingObject = null;
if ((Object)(object)attachedRigidbody != (Object)null)
{
floatingObject = ((Component)attachedRigidbody).GetComponent<FloatingObject>();
}
if (!_inTriggerCol.Contains(floatingObject))
{
return;
}
attachedRigidbody.useGravity = true;
Object.Destroy((Object)(object)floatingObject);
Rigidbody[] array = Il2CppArrayBase<Rigidbody>.op_Implicit(((Component)attachedRigidbody).GetComponentsInChildren<Rigidbody>(true));
foreach (Rigidbody val in array)
{
if (val.isKinematic && (Object)(object)((Component)val).GetComponent<FloatingObject>() != (Object)null)
{
Object.Destroy((Object)(object)((Component)val).GetComponent<FloatingObject>());
}
}
}
[HideFromIl2Cpp]
private void OnBuoyancyManagerDestroyed(FloatingObject manager)
{
_inTriggerCol.Remove(manager);
}
public WaterZone(IntPtr ptr)
: base(ptr)
{
}
}
}
namespace WeatherElectric.WaterDynamics.Behaviours.Internal
{
public class FloatingObject : MonoBehaviour
{
[NonSerialized]
private Rigidbody _thisRb;
[NonSerialized]
public float BuoyancyMultiplier;
[NonSerialized]
public float Midpoint;
[NonSerialized]
public bool MidpointSink;
[NonSerialized]
public bool Dampening;
[NonSerialized]
public float DampeningAmount;
[NonSerialized]
internal Action<FloatingObject> OnDestroyed;
private void Start()
{
_thisRb = ((Component)this).GetComponent<Rigidbody>();
if ((Object)(object)_thisRb != (Object)null)
{
_thisRb.useGravity = false;
}
}
private void OnDisable()
{
if ((Object)(object)_thisRb != (Object)null)
{
_thisRb.useGravity = true;
}
Object.Destroy((Object)(object)this);
}
private void OnDestroy()
{
OnDestroyed?.Invoke(this);
}
private void FixedUpdate()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_thisRb) && _thisRb.useGravity)
{
_thisRb.useGravity = false;
}
Vector3 gravity;
if (Object.op_Implicit((Object)(object)_thisRb) && _thisRb.mass < Midpoint)
{
float mass = _thisRb.mass;
gravity = Physics.gravity;
float num = mass + ((Vector3)(ref gravity)).magnitude * BuoyancyMultiplier;
_thisRb.AddForce(Vector3.up * num);
if (Dampening)
{
Rigidbody thisRb = _thisRb;
thisRb.velocity *= DampeningAmount;
}
}
if (Object.op_Implicit((Object)(object)_thisRb) && _thisRb.mass > Midpoint)
{
float mass2 = _thisRb.mass;
gravity = Physics.gravity;
float num2 = mass2 + ((Vector3)(ref gravity)).magnitude * BuoyancyMultiplier;
_thisRb.AddForce(Vector3.down * num2);
if (Dampening)
{
Rigidbody thisRb2 = _thisRb;
thisRb2.velocity *= DampeningAmount;
}
}
if (!Object.op_Implicit((Object)(object)_thisRb) || !Mathf.Approximately(_thisRb.mass, Midpoint))
{
return;
}
if (MidpointSink)
{
float mass3 = _thisRb.mass;
gravity = Physics.gravity;
float num3 = mass3 + ((Vector3)(ref gravity)).magnitude * BuoyancyMultiplier;
_thisRb.AddForce(Vector3.down * num3);
if (Dampening)
{
Rigidbody thisRb3 = _thisRb;
thisRb3.velocity *= DampeningAmount;
}
}
else
{
float mass4 = _thisRb.mass;
gravity = Physics.gravity;
float num4 = mass4 + ((Vector3)(ref gravity)).magnitude * BuoyancyMultiplier;
_thisRb.AddForce(Vector3.up * num4);
if (Dampening)
{
Rigidbody thisRb4 = _thisRb;
thisRb4.velocity *= DampeningAmount;
}
}
}
public FloatingObject(IntPtr ptr)
: base(ptr)
{
}
}
public class HandSwimmingController : MonoBehaviour
{
private Vector3 _velocity;
internal RigManager RigManager;
internal float MinVelocity;
internal float VelocityMult;
private Rigidbody _handRb;
private Rigidbody _chestRb;
private Rigidbody _headRb;
private void Start()
{
_headRb = ((Component)((Rig)RigManager.physicsRig).m_head).GetComponent<Rigidbody>();
_chestRb = ((Component)((Rig)RigManager.physicsRig).m_chest).GetComponent<Rigidbody>();
_handRb = ((Component)this).GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
//IL_0007: 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_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
_velocity = _handRb.velocity - _chestRb.velocity;
if (((Vector3)(ref _velocity)).sqrMagnitude > MinVelocity)
{
_headRb.AddRelativeForce(new Vector3(0f, 0f, ((Vector3)(ref _velocity)).sqrMagnitude * VelocityMult));
}
}
public HandSwimmingController(IntPtr ptr)
: base(ptr)
{
}
}
}