Decompiled source of FreeplayFreeplace v1.0.0

Freeplace.dll

Decompiled 11 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UCHMod1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UCHMod1")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("aa4e3efd-4ed5-4b66-a930-2838d695f27e")]
[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")]
namespace UCHMod1;

[BepInPlugin("judwickvonrossington.freeplayfreeplace", "Freeplay Freeplace", "1.4.0")]
public class Class1 : BaseUnityPlugin
{
	private static Class1 Instance;

	private static bool FreeplayPlacementActive;

	private void Awake()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Expected O, but got Unknown
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Expected O, but got Unknown
		Instance = this;
		Harmony val = new Harmony("judwickvonrossington.freeplayfreeplace");
		SceneManager.sceneLoaded += OnSceneLoaded;
		try
		{
			MethodInfo method = typeof(FreePlayControl).GetMethod("ToPlaceMode", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not find FreePlayControl.ToPlaceMode()!");
			}
			else
			{
				MethodInfo method2 = typeof(Class1).GetMethod("FreeplayToPlaceModePrefix", BindingFlags.Static | BindingFlags.NonPublic);
				val.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"PATCH SUCCESS: FreePlayControl.ToPlaceMode()");
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("PATCH FAILED: FreePlayControl.ToPlaceMode() - " + ex));
		}
		try
		{
			MethodInfo method3 = typeof(Placeable).GetMethod("CanPlaceCheck", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method3 == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not find Placeable.CanPlaceCheck()!");
			}
			else
			{
				MethodInfo method4 = typeof(Class1).GetMethod("CanPlaceCheckPrefix", BindingFlags.Static | BindingFlags.NonPublic);
				val.Patch((MethodBase)method3, new HarmonyMethod(method4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"PATCH SUCCESS: Placeable.CanPlaceCheck()");
			}
		}
		catch (Exception ex2)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("PATCH FAILED: Placeable.CanPlaceCheck() - " + ex2));
		}
		try
		{
			MethodInfo method5 = typeof(Placeable).GetMethod("CanPlace", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method5 == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not find Placeable.CanPlace()!");
			}
			else
			{
				MethodInfo method6 = typeof(Class1).GetMethod("CanPlacePrefix", BindingFlags.Static | BindingFlags.NonPublic);
				val.Patch((MethodBase)method5, new HarmonyMethod(method6), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"PATCH SUCCESS: Placeable.CanPlace()");
			}
		}
		catch (Exception ex3)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("PATCH FAILED: Placeable.CanPlace() - " + ex3));
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Freeplay Freeplace v1.4.0 loaded.");
	}

	private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		FreeplayPlacementActive = false;
		if ((Object)(object)Instance != (Object)null)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[FreeplayFreeplace] Scene loaded: " + ((Scene)(ref scene)).name + " | Freeplay placement reset."));
		}
	}

	private static void FreeplayToPlaceModePrefix()
	{
		FreeplayPlacementActive = true;
		if ((Object)(object)Instance != (Object)null)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)"[FreeplayFreeplace] Freeplay placement mode ACTIVE.");
		}
	}

	private static bool CanPlaceCheckPrefix(ref bool __result)
	{
		if (FreeplayPlacementActive)
		{
			__result = true;
			return false;
		}
		return true;
	}

	private static bool CanPlacePrefix(ref bool __result)
	{
		if (FreeplayPlacementActive)
		{
			__result = true;
			return false;
		}
		return true;
	}
}