using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib.BoneMenu;
using HandsOffPrototype;
using HarmonyLib;
using Il2CppSLZ.Marrow;
using LabFusion.Data;
using LabFusion.Entities;
using LabFusion.Player;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(HandsOff), "Hands Off", "1.0.0", "goofygoober_7 + OpenAI Codex (AI-assisted)", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HandsOff")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HandsOff")]
[assembly: AssemblyTitle("HandsOff")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace HandsOffPrototype
{
public sealed class HandsOff : MelonMod
{
private const string HarmonyId = "goofygoober7.handsoff";
private Harmony? _harmony;
private static bool _userWantsProtection = true;
private static bool _deathSuspend;
private static DateTime _resumeAtUtc;
private static bool _respawnRecoveryPending;
private static DateTime _respawnRecoveryAtUtc;
internal static bool ProtectionEnabled { get; private set; } = true;
public override void OnInitializeMelon()
{
//IL_000a: 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_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Expected O, but got Unknown
Page obj = Page.Root.CreatePage("Hands Off", Color.cyan, 0, true);
obj.CreateBool("Stop others grabbing me", Color.green, true, (Action<bool>)SetEnabled);
Page obj2 = obj.CreatePage("Credits", Color.magenta, 0, true);
obj2.CreateFunction("Creator: goofygoober_7", Color.cyan, (Action)NoOp);
obj2.CreateFunction("AI assistant: OpenAI Codex", Color.yellow, (Action)NoOp);
obj2.CreateFunction("Made with AI assistance", Color.green, (Action)NoOp);
LocalHealth.OnRespawn += ScheduleRespawnRecovery;
_harmony = new Harmony("goofygoober7.handsoff");
_harmony.PatchAll(typeof(HandsOff).Assembly);
MelonLogger.Msg("Hands Off 1.0.0 loaded. Protection starts enabled. This mod was made with AI assistance.");
}
public override void OnDeinitializeMelon()
{
ProtectionEnabled = false;
LocalHealth.OnRespawn -= ScheduleRespawnRecovery;
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
_harmony = null;
}
private static void SetEnabled(bool value)
{
_userWantsProtection = value;
ProtectionEnabled = value && !_deathSuspend;
MelonLogger.Msg("Stop others grabbing me: " + (value ? "ON" : "OFF"));
}
private static void NoOp()
{
}
private static void ScheduleRespawnRecovery()
{
DateTime utcNow = DateTime.UtcNow;
_deathSuspend = true;
ProtectionEnabled = false;
_respawnRecoveryPending = true;
_respawnRecoveryAtUtc = utcNow.AddMilliseconds(750.0);
_resumeAtUtc = utcNow.AddSeconds(2.0);
MelonLogger.Msg("Respawn recovery scheduled.");
}
public override void OnUpdate()
{
DateTime utcNow = DateTime.UtcNow;
if (_respawnRecoveryPending && utcNow >= _respawnRecoveryAtUtc)
{
_respawnRecoveryPending = false;
RecoverRespawnPosition();
}
if (_deathSuspend && utcNow >= _resumeAtUtc)
{
_deathSuspend = false;
ProtectionEnabled = _userWantsProtection;
MelonLogger.Msg("Protection " + (ProtectionEnabled ? "resumed" : "remains off") + " after respawn.");
}
}
private static void RecoverRespawnPosition()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
try
{
if (RigData.HasPlayer && RigData.Refs != null && !((Object)(object)RigData.Refs.RigManager == (Object)null))
{
RigManager rigManager = RigData.Refs.RigManager;
Vector3 val = rigManager.checkpointPosition + Vector3.up;
LocalRagdoll.ToggleRagdoll(false);
LocalPlayer.TeleportToPosition(val, rigManager.checkpointFwd);
ClearRigVelocity(rigManager);
MelonLogger.Msg("Respawn recovery: unragdolled, moved above the checkpoint, and cleared rig velocity.");
}
}
catch (Exception ex)
{
MelonLogger.Warning("Hands Off could not correct the respawn position: " + ex.Message);
}
}
private static void ClearRigVelocity(RigManager rigManager)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
foreach (Rigidbody componentsInChild in ((Component)rigManager).GetComponentsInChildren<Rigidbody>(true))
{
if (!((Object)(object)componentsInChild == (Object)null) && !componentsInChild.isKinematic)
{
componentsInChild.velocity = Vector3.zero;
componentsInChild.angularVelocity = Vector3.zero;
}
}
}
internal static bool IsLocalPlayerGrip(Grip targetGrip)
{
foreach (NetworkPlayer player in NetworkPlayer.Players)
{
if (player == null || player.PlayerID == null || !player.PlayerID.IsMe)
{
continue;
}
RigRefs rigRefs = player.RigRefs;
if (rigRefs == null || !rigRefs.IsValid || rigRefs.RigGrips == null)
{
return false;
}
Grip[] rigGrips = rigRefs.RigGrips;
foreach (Grip val in rigGrips)
{
if ((Object)(object)val != (Object)null && (Object)(object)val == (Object)(object)targetGrip)
{
return true;
}
}
return false;
}
return false;
}
}
[HarmonyPatch(typeof(RigGrabber), "Attach")]
internal static class RigGrabberAttachPatch
{
private static bool Prefix(Grip grip, ref bool __state)
{
__state = false;
if (!HandsOff.ProtectionEnabled || (Object)(object)grip == (Object)null)
{
return true;
}
try
{
if (!HandsOff.IsLocalPlayerGrip(grip) || grip.IsInteractionDisabled)
{
return true;
}
((HandReciever)grip).DisableInteraction();
__state = true;
return true;
}
catch (Exception ex)
{
MelonLogger.Warning("Hands Off could not guard a Fusion grip: " + ex.Message);
return true;
}
}
private static Exception? Finalizer(Grip grip, bool __state, Exception? __exception)
{
if (__state && (Object)(object)grip != (Object)null)
{
try
{
((HandReciever)grip).EnableInteraction();
}
catch (Exception ex)
{
MelonLogger.Warning("Hands Off could not restore a Fusion grip: " + ex.Message);
}
}
return __exception;
}
}
}