using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HoldItemMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HoldItemMod")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0efe8610-34d8-4f1c-ba89-7ee1b00aac8a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.yourname.repo.holditem", "Hold Item Mod", "1.0.0")]
public class HoldItemMod : BaseUnityPlugin
{
private GameObject carriedObject = null;
private Transform holdPoint;
private Component physGrabber;
private FieldInfo grabbedObjectField;
private Component playerAvatarSingleton;
private Transform avatarTransform;
private Component playerController;
private FieldInfo moveSpeedField;
private FieldInfo crouchSpeedField;
private FieldInfo sprintSpeedField;
private float logTimer = 0f;
private void Start()
{
TryFindComponents();
ModLog("???????????????????????????????????????????");
ModLog("?? Hold Item Mod Loaded!");
ModLog("?? Press Z to pick up or drop held object from PhysGrabber.");
ModLog("???????????????????????????????????????????");
}
private void Update()
{
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)physGrabber == (Object)null || grabbedObjectField == null || (Object)(object)avatarTransform == (Object)null || (Object)(object)playerController == (Object)null || moveSpeedField == null)
{
TryFindComponents();
}
if (Input.GetKeyDown((KeyCode)122))
{
if ((Object)(object)carriedObject != (Object)null)
{
Drop();
}
else
{
GameObject heldObjectFromPhysGrabber = GetHeldObjectFromPhysGrabber();
if ((Object)(object)heldObjectFromPhysGrabber != (Object)null)
{
ModLog($"?? Carrying: {heldObjectFromPhysGrabber}");
Carry(heldObjectFromPhysGrabber);
}
else
{
ModLog("? No valid held object found in PhysGrabber.");
DumpPhysGrabberInfo();
}
}
}
if ((Object)(object)carriedObject != (Object)null && (Object)(object)avatarTransform != (Object)null)
{
Vector3 position = avatarTransform.position;
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(0f, Mathf.Sin(Time.time * 2f) * 0.1f, 0f);
Vector3 val2 = position + new Vector3(0f, 2.2f, 0f) + val;
carriedObject.transform.position = Vector3.Lerp(carriedObject.transform.position, val2, Time.deltaTime * 10f);
carriedObject.transform.rotation = Quaternion.Lerp(carriedObject.transform.rotation, Quaternion.identity, Time.deltaTime * 10f);
}
}
private void TryFindComponents()
{
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
Type typeFromAssemblies = GetTypeFromAssemblies("PhysGrabber");
if (typeFromAssemblies != null)
{
ModLog("Alright, let me get this started...");
ref Component reference = ref physGrabber;
object? obj = typeFromAssemblies.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null);
reference = (Component)((obj is Component) ? obj : null);
if ((Object)(object)physGrabber == (Object)null)
{
Object[] array = Object.FindObjectsOfType(typeFromAssemblies, true);
if (array.Length != 0)
{
ref Component reference2 = ref physGrabber;
Object obj2 = array[0];
reference2 = (Component)(object)((obj2 is Component) ? obj2 : null);
}
}
if ((Object)(object)physGrabber != (Object)null)
{
grabbedObjectField = typeFromAssemblies.GetField("grabbedObject", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (!(grabbedObjectField != null))
{
}
}
}
Type typeFromAssemblies2 = GetTypeFromAssemblies("PlayerAvatar");
if (typeFromAssemblies2 != null)
{
FieldInfo field = typeFromAssemblies2.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
ref Component reference3 = ref playerAvatarSingleton;
object? value = field.GetValue(null);
reference3 = (Component)((value is Component) ? value : null);
if ((Object)(object)playerAvatarSingleton != (Object)null)
{
avatarTransform = playerAvatarSingleton.transform;
}
}
}
Type typeFromAssemblies3 = GetTypeFromAssemblies("PlayerController");
if (typeFromAssemblies3 != null)
{
FieldInfo field2 = typeFromAssemblies3.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (field2 != null)
{
object value2 = field2.GetValue(null);
if (value2 != null)
{
playerController = (Component)((value2 is Component) ? value2 : null);
moveSpeedField = typeFromAssemblies3.GetField("MoveSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
crouchSpeedField = typeFromAssemblies3.GetField("CrouchSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
sprintSpeedField = typeFromAssemblies3.GetField("SprintSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
else
{
ModLog("? PlayerController.instance is null.");
}
}
}
if ((Object)(object)holdPoint == (Object)null)
{
holdPoint = new GameObject("HoldPoint").transform;
ModLog("Wow, did it actually load... omg, it works!");
}
}
private GameObject GetHeldObjectFromPhysGrabber()
{
if ((Object)(object)physGrabber == (Object)null || grabbedObjectField == null)
{
return null;
}
object value = grabbedObjectField.GetValue(physGrabber);
GameObject val = (GameObject)((value is GameObject) ? value : null);
if (val != null)
{
return val;
}
Component val2 = (Component)((value is Component) ? value : null);
if (val2 != null)
{
return val2.gameObject;
}
return null;
}
private void DumpPhysGrabberInfo()
{
if ((Object)(object)physGrabber == (Object)null)
{
return;
}
FieldInfo[] fields = ((object)physGrabber).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
try
{
object value = fieldInfo.GetValue(physGrabber);
}
catch (Exception)
{
}
}
}
private void Carry(GameObject obj)
{
carriedObject = obj;
Rigidbody component = carriedObject.GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null)
{
component.isKinematic = true;
component.useGravity = false;
float mass = component.mass;
if (moveSpeedField != null && (Object)(object)playerController != (Object)null)
{
float num = Mathf.Max(0.5f, 2f - mass * 0.1f);
float num2 = Mathf.Clamp(num * 0.5f, 0.3f, 2f);
float num3 = Mathf.Clamp(num * 2.5f, 1f, 7f);
moveSpeedField.SetValue(playerController, num);
crouchSpeedField?.SetValue(playerController, num2);
sprintSpeedField?.SetValue(playerController, num3);
}
}
else
{
ModLog("?? No Rigidbody found on object, cannot determine mass.");
}
}
private void Drop()
{
if (!((Object)(object)carriedObject == (Object)null))
{
Rigidbody component = carriedObject.GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null)
{
component.isKinematic = false;
component.useGravity = true;
}
if ((Object)(object)playerController != (Object)null)
{
moveSpeedField?.SetValue(playerController, 2f);
crouchSpeedField?.SetValue(playerController, 1f);
sprintSpeedField?.SetValue(playerController, 5f);
}
ModLog("?? Dropped: " + ((Object)carriedObject).name);
carriedObject = null;
}
}
private void ModLog(string message)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("?? [HoldItemMod] " + message));
}
private Type GetTypeFromAssemblies(string typeName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
Type type = assembly.GetType(typeName);
if (type != null)
{
return type;
}
}
return null;
}
}