using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2Cpp;
using Il2CppFusion;
using Il2CppInterop.Runtime.InteropTypes;
using JoofOTHFramework;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WinchUnlimited;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Mod), "WinchUnlimited", "1.1.0", "Joof", null)]
[assembly: MelonGame("Funselektor", "over the hill")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WinchUnlimited")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+97a63a253e3a6c21ef5c094eb537b60f53e95a65")]
[assembly: AssemblyProduct("WinchUnlimited")]
[assembly: AssemblyTitle("WinchUnlimited")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 WinchUnlimited
{
public class Mod : MelonMod
{
internal static Instance Log;
internal static MelonPreferences_Entry<bool> Enabled;
internal static MelonPreferences_Entry<float> MinRopeLength;
internal static MelonPreferences_Entry<bool> NoStall;
internal static MelonPreferences_Entry<float> ReelSpeedMultiplier;
internal static MelonPreferences_Entry<float> MaxExtension;
public override void OnInitializeMelon()
{
Log = ((MelonBase)this).LoggerInstance;
MelonPreferences_Category obj = MelonPreferences.CreateCategory("WinchUnlimited");
Enabled = obj.CreateEntry<bool>("Enabled", true, (string)null, "Unlimited winch retraction.", false, false, (ValueValidator)null, (string)null);
MinRopeLength = obj.CreateEntry<float>("MinRopeLength", 0.3f, (string)null, "Shortest the rope can be reeled in to, in metres. Don't go to 0, the physics can explode.", false, false, (ValueValidator)null, (string)null);
NoStall = obj.CreateEntry<bool>("NoStall", true, (string)null, "Stop the winch stalling or slipping under heavy load.", false, false, (ValueValidator)null, (string)null);
ReelSpeedMultiplier = obj.CreateEntry<float>("ReelSpeedMultiplier", 1f, (string)null, "Multiplier for winch reel speed (1 = game default).", false, false, (ValueValidator)null, (string)null);
MaxExtension = obj.CreateEntry<float>("MaxExtension", 9000f, (string)null, "How far (m) the rope can be paid out once attached. Attaching still uses the game's normal range. 0 = game default.", false, false, (ValueValidator)null, (string)null);
Net.Register();
WinchHooks.BeforeTick += WinchPatch.Prefix;
}
public override void OnUpdate()
{
if (!Core.Quitting)
{
HillNet.Tick();
}
}
internal static WinchSettings LocalWinchSettings()
{
return new WinchSettings
{
Enabled = Enabled.Value,
MinRopeLength = MinRopeLength.Value,
NoStall = NoStall.Value,
ReelSpeedMultiplier = ReelSpeedMultiplier.Value,
MaxExtension = MaxExtension.Value
};
}
}
internal static class Net
{
private const string Channel = "WinchUnlimited";
private static readonly Dictionary<int, WinchSettings> remote = new Dictionary<int, WinchSettings>();
public static WinchSettings GetRemoteWinchSettings(int playerId)
{
if (!HillNet.PlayerHas(playerId, "WinchUnlimited") || !remote.TryGetValue(playerId, out var value))
{
return null;
}
return value;
}
internal static void Register()
{
HillNet.Register<WinchSettings>("WinchUnlimited", (Action<NetworkRunner, PlayerRef, WinchSettings>)OnReceive);
HillNet.SessionReset += delegate
{
remote.Clear();
};
HillNet.PlayerLeft += delegate(int id)
{
remote.Remove(id);
};
HillNet.HostReady += Send;
((MelonEventBase<LemonAction<bool, bool>>)(object)Mod.Enabled.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate
{
Send();
}, 0, false);
((MelonEventBase<LemonAction<float, float>>)(object)Mod.MinRopeLength.OnEntryValueChanged).Subscribe((LemonAction<float, float>)delegate
{
Send();
}, 0, false);
((MelonEventBase<LemonAction<bool, bool>>)(object)Mod.NoStall.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate
{
Send();
}, 0, false);
((MelonEventBase<LemonAction<float, float>>)(object)Mod.ReelSpeedMultiplier.OnEntryValueChanged).Subscribe((LemonAction<float, float>)delegate
{
Send();
}, 0, false);
((MelonEventBase<LemonAction<float, float>>)(object)Mod.MaxExtension.OnEntryValueChanged).Subscribe((LemonAction<float, float>)delegate
{
Send();
}, 0, false);
}
private static void Send()
{
NetworkRunner runner = HillNet.Runner;
if (!((Object)(object)runner == (Object)null) && !runner.IsServer && HillNet.HostHas("WinchUnlimited"))
{
HillNet.SendToHost("WinchUnlimited", (object)Mod.LocalWinchSettings());
}
}
private static void OnReceive(NetworkRunner runner, PlayerRef from, WinchSettings s)
{
if (runner.IsServer)
{
remote[((PlayerRef)(ref from)).PlayerId] = s;
}
}
}
public class WinchSettings
{
public bool Enabled { get; set; }
public float MinRopeLength { get; set; }
public bool NoStall { get; set; }
public float ReelSpeedMultiplier { get; set; }
public float MaxExtension { get; set; }
}
internal static class WinchPatch
{
private class Defaults
{
public float MinRope;
public float Stall;
public float MaxTension;
public float ReelSpeed;
public bool Slip;
}
private static readonly Dictionary<IntPtr, Defaults> defaults = new Dictionary<IntPtr, Defaults>();
internal static void Prefix(VehicleWinchSystem __instance)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
try
{
NetworkObject val = ((SimulationBehaviour)__instance).Object;
if ((Object)(object)val == (Object)null)
{
return;
}
WinchSettings winchSettings = null;
if (val.HasInputAuthority)
{
winchSettings = Mod.LocalWinchSettings();
}
else if ((Object)(object)((SimulationBehaviour)__instance).Runner != (Object)null && ((SimulationBehaviour)__instance).Runner.IsServer)
{
PlayerRef inputAuthority = val.InputAuthority;
winchSettings = Net.GetRemoteWinchSettings(((PlayerRef)(ref inputAuthority)).PlayerId);
}
if (!defaults.TryGetValue(((Il2CppObjectBase)__instance).Pointer, out var value))
{
Dictionary<IntPtr, Defaults> dictionary = defaults;
IntPtr pointer = ((Il2CppObjectBase)__instance).Pointer;
Defaults obj = new Defaults
{
MinRope = __instance.minRopeLength,
Stall = __instance.stallTension,
MaxTension = __instance.maxTension,
Slip = __instance.slipAboveMaxTension,
ReelSpeed = __instance.winchReelSpeed
};
value = obj;
dictionary[pointer] = obj;
}
if (winchSettings == null || !winchSettings.Enabled)
{
__instance.minRopeLength = value.MinRope;
__instance.stallTension = value.Stall;
__instance.maxTension = value.MaxTension;
__instance.slipAboveMaxTension = value.Slip;
__instance.winchReelSpeed = value.ReelSpeed;
return;
}
__instance.minRopeLength = Math.Max(0.05f, winchSettings.MinRopeLength);
__instance.stallTension = (winchSettings.NoStall ? 1E+09f : value.Stall);
__instance.maxTension = (winchSettings.NoStall ? 1E+09f : value.MaxTension);
__instance.slipAboveMaxTension = !winchSettings.NoStall && value.Slip;
__instance.winchReelSpeed = value.ReelSpeed * Math.Clamp(winchSettings.ReelSpeedMultiplier, 0.1f, 10f);
if (winchSettings.MaxExtension > 0f && val.HasStateAuthority && (int)__instance.WinchState != 0 && __instance.MaxRopeLength < winchSettings.MaxExtension)
{
__instance.MaxRopeLength = winchSettings.MaxExtension;
}
}
catch (Exception ex)
{
Mod.Log.Error(ex.ToString());
}
}
}
}