1
0
Files
UnrestrictedPlacement/Plugin.cs

98 lines
3.2 KiB
C#

using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using UnityEngine;
namespace UnrestrictedPlacement;
[BepInPlugin(PLUGIN_GUID, PLUGIN_NAME, PLUGIN_VERSION)]
public class Plugin : BasePlugin
{
public const string PLUGIN_GUID = "de.mpburgmann.UnrestrictedPlacement";
public const string PLUGIN_NAME = "Unrestricted Placement";
public const string PLUGIN_VERSION = "1.0.1";
internal static new ManualLogSource Log;
public static ConfigEntry<bool> Enabled;
public static ConfigEntry<KeyCode> SwitchKey;
public override void Load()
{
Log = base.Log;
Log.LogInfo($"Plugin {PLUGIN_GUID} is loaded!");
ClassInjector.RegisterTypeInIl2Cpp<Behaviour>();
GameObject gameObject = new("UnrestrictedPlacementBehaviour");
Object.DontDestroyOnLoad(gameObject);
gameObject.AddComponent<Behaviour>();
Enabled = Config.Bind("Settings", "Enabled", true);
SwitchKey = Config.Bind("Settings", "SwitchKey", KeyCode.F8, "The key with which to enable and disable the mod.");
Harmony harmony = new(PLUGIN_GUID);
harmony.PatchAll();
}
public static class UnrestrictedPlacementPatch
{
[HarmonyPatch(typeof(FurniturePlacer), "PlaceFurniture")]
public static class FurniturePlacer_PlaceFurniture_Patch
{
[HarmonyPrefix]
public static void Prefix(FurniturePlacer __instance)
{
if (!Enabled.Value) return;
__instance.m_CurrentPlacingMode.PlacedOnCorrectSurface = true;
}
}
[HarmonyPatch(typeof(FurniturePlacer), "PlacingRaycast")]
public static class FurniturePlacer_PlacingRaycast_Patch
{
[HarmonyPostfix]
public static void Postfix(FurniturePlacer __instance)
{
if (!Enabled.Value) return;
__instance.m_CurrentPlacingMode.PlacedOnCorrectSurface = true;
}
}
[HarmonyPatch(typeof(IPlacingMode), "OverlapBoxes")]
public static class IPlacingMode_OverlapsBoxes_Patch
{
[HarmonyPrefix]
public static bool Prefix(IPlacingMode __instance)
{
if (!Enabled.Value) return true;
__instance.m_Triggers.Clear();
return false;
}
}
[HarmonyPatch(typeof(IPlacingMode), "UpdateHologramColor")]
public static class IPlacingMode_UpdateHologramColor_Patch
{
[HarmonyPostfix]
public static void Postfix(IPlacingMode __instance)
{
if (!Enabled.Value) return;
__instance.HologramColor = Color.green;
}
}
}
public class Behaviour : MonoBehaviour
{
internal void Update()
{
if(Input.GetKeyDown(SwitchKey.Value))
{
Enabled.Value = !Enabled.Value;
Log.LogError($"Plugin {PLUGIN_GUID} is enabled: {Enabled.Value}");
}
}
}
}