Decompiled source of DogHaus Tools v1.0.6

plugins/DogHausTools.dll

Decompiled 4 days ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using DogHausBalance;
using DogHausCultivator;
using DogHausQoL;
using DogHausTerrain;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace DogHausToolsMod;

[HarmonyPatch(typeof(ZNetScene), "Awake")]
internal static class ZNetScene_Awake_ToolsSmooth
{
	[HarmonyPriority(0)]
	private static void Postfix(ZNetScene __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, (ObjectDB)null, (Action)delegate
			{
				SmoothTool.Register(__instance, false);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Smooth tools could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ObjectDB), "Awake")]
internal static class ObjectDB_Awake_ToolsSmooth
{
	[HarmonyPriority(0)]
	private static void Postfix()
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, (ObjectDB)null, (Action)delegate
			{
				SmoothTool.Register(ZNetScene.instance, false);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Smooth tools could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(Player), "OnSpawned")]
internal static class Player_OnSpawned_ToolsSmooth
{
	private static void Postfix(Player __instance)
	{
		if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
		{
			return;
		}
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, (ObjectDB)null, (Action)delegate
			{
				SmoothTool.Register(ZNetScene.instance, false);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Smooth tools could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ObjectDB), "Awake")]
internal static class ObjectDB_Awake_ToolsHoe
{
	[HarmonyPriority(200)]
	private static void Postfix(ObjectDB __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, __instance, (Action)delegate
			{
				HoeTiers.Apply(__instance);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Bronze hoe could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
internal static class ObjectDB_CopyOtherDB_ToolsHoe
{
	[HarmonyPriority(200)]
	private static void Postfix(ObjectDB __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, __instance, (Action)delegate
			{
				HoeTiers.Apply(__instance);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Bronze hoe could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
internal static class ZNetScene_Awake_ToolsHoe
{
	[HarmonyPriority(200)]
	private static void Postfix(ZNetScene __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, (ObjectDB)null, (Action)delegate
			{
				HoeTiers.RegisterScene(__instance);
				if ((Object)(object)ObjectDB.instance != (Object)null)
				{
					HoeTiers.Apply(ObjectDB.instance);
				}
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Bronze hoe could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
internal static class ZNetScene_Awake_ToolsWater
{
	[HarmonyPriority(800)]
	private static void Postfix(ZNetScene __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, (ObjectDB)null, (Action)delegate
			{
				WaterPieces.Register(__instance);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Water pieces could not be registered (DogHausTweaks will): " + ex.Message));
		}
	}
}
[HarmonyPatch(typeof(Hud), "SetupPieceInfo")]
internal static class Hud_SetupPieceInfo_ToolsLabel
{
	[HarmonyPriority(0)]
	private static void Postfix(Hud __instance, Piece piece)
	{
		ModSplit.LabelPiece("doghaus.tools", __instance, piece);
	}
}
[HarmonyPatch]
internal static class ItemData_GetTooltip_ToolsLabel
{
	private static bool Prepare()
	{
		return ModSplit.TooltipMethod() != null;
	}

	private static MethodBase TargetMethod()
	{
		return ModSplit.TooltipMethod();
	}

	[HarmonyPriority(0)]
	private static void Postfix(ItemData __0, bool __2, ref string __result)
	{
		ModSplit.LabelTooltip("doghaus.tools", __0, __2, ref __result);
	}
}
[BepInPlugin("doghaus.tools", "DogHaus Tools", "1.0.6")]
[BepInDependency("doghaus.tweaks", "2.0.9")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ToolsPlugin : BaseUnityPlugin
{
	public const string GUID = "doghaus.tools";

	public const string NAME = "DogHaus Tools";

	public const string VERSION = "1.0.6";

	internal const string TweaksGuid = "doghaus.tweaks";

	internal const string TweaksMinVersion = "2.0.9";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		if (Kill.Off("doghaus.tools", ((BaseUnityPlugin)this).Logger))
		{
			((Behaviour)this).enabled = false;
			return;
		}
		if (Kill.IsOff("doghaus.terrainsmooth"))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"doghaus.terrainsmooth is switched off in DogHausTweaks.disable.txt - DogHaus Tools stands down with it (no tools registered).");
			((Behaviour)this).enabled = false;
			return;
		}
		Harmony h = new Harmony("doghaus.tools");
		HookReport val = new HookReport(((BaseUnityPlugin)this).Logger, "DogHaus Tools");
		Register(h, val, typeof(ZNetScene_Awake_ToolsSmooth));
		Register(h, val, typeof(ObjectDB_Awake_ToolsSmooth));
		Register(h, val, typeof(Player_OnSpawned_ToolsSmooth));
		Register(h, val, typeof(ObjectDB_Awake_ToolsHoe));
		Register(h, val, typeof(ObjectDB_CopyOtherDB_ToolsHoe));
		Register(h, val, typeof(ZNetScene_Awake_ToolsHoe));
		Register(h, val, typeof(ObjectDB_Awake_ToolsCult));
		Register(h, val, typeof(ObjectDB_CopyOtherDB_ToolsCult));
		Register(h, val, typeof(ZNetScene_Awake_ToolsCult));
		Register(h, val, typeof(ObjectDB_Awake_ToolsMap));
		Register(h, val, typeof(ObjectDB_CopyOtherDB_ToolsMap));
		Register(h, val, typeof(ZNetScene_Awake_ToolsMap));
		Register(h, val, typeof(ZNetScene_Awake_ToolsWater));
		Register(h, val, typeof(Hud_SetupPieceInfo_ToolsLabel));
		Register(h, val, typeof(ItemData_GetTooltip_ToolsLabel));
		val.Summary();
		((BaseUnityPlugin)this).Logger.LogInfo((object)("DogHaus Tools 1.0.6 loaded: registers the DogHaus hoe tools and the Bronze hoe (code in DogHausTweaks; label line " + (ModSplit.WmatLoaded ? "from WhichModAddedThis" : "printed by this plugin") + ")."));
	}

	private static void Register(Harmony h, HookReport hooks, Type patch)
	{
		try
		{
			hooks.Patch(h, patch);
		}
		catch (Exception ex)
		{
			hooks.Failed(patch, ex);
		}
	}
}
[HarmonyPatch(typeof(ObjectDB), "Awake")]
internal static class ObjectDB_Awake_ToolsCult
{
	[HarmonyPriority(200)]
	private static void Postfix(ObjectDB __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, __instance, (Action)delegate
			{
				BlackCultivator.Apply(__instance);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Black metal cultivator could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
internal static class ObjectDB_CopyOtherDB_ToolsCult
{
	[HarmonyPriority(200)]
	private static void Postfix(ObjectDB __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, __instance, (Action)delegate
			{
				BlackCultivator.Apply(__instance);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Black metal cultivator could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
internal static class ZNetScene_Awake_ToolsCult
{
	[HarmonyPriority(200)]
	private static void Postfix(ZNetScene __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, (ObjectDB)null, (Action)delegate
			{
				BlackCultivator.RegisterScene(__instance);
				if ((Object)(object)ObjectDB.instance != (Object)null)
				{
					BlackCultivator.Apply(ObjectDB.instance);
				}
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Black metal cultivator could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ObjectDB), "Awake")]
internal static class ObjectDB_Awake_ToolsMap
{
	[HarmonyPriority(200)]
	private static void Postfix(ObjectDB __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, __instance, (Action)delegate
			{
				MapItem.Apply(__instance);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Map item could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
internal static class ObjectDB_CopyOtherDB_ToolsMap
{
	[HarmonyPriority(200)]
	private static void Postfix(ObjectDB __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, __instance, (Action)delegate
			{
				MapItem.Apply(__instance);
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Map item could not be registered (DogHausTweaks will): " + ex));
		}
	}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
internal static class ZNetScene_Awake_ToolsMap
{
	[HarmonyPriority(200)]
	private static void Postfix(ZNetScene __instance)
	{
		try
		{
			ModSplit.Shell("doghaus.tools", ToolsPlugin.Log, (ObjectDB)null, (Action)delegate
			{
				MapItem.RegisterScene(__instance);
				if ((Object)(object)ObjectDB.instance != (Object)null)
				{
					MapItem.Apply(ObjectDB.instance);
				}
			});
		}
		catch (Exception ex)
		{
			ToolsPlugin.Log.LogWarning((object)("Map item could not be registered (DogHausTweaks will): " + ex));
		}
	}
}