Decompiled source of BuildingDamageMod v4.6.4

BuildingDamageMod.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+08cda0e87d140597b94a8745f1d42ff7af7281bd")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BuildingDamageMod;

[BepInPlugin("aedenthorn.BuildingDamageMod", "Building Damage Mod", "0.5.3")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Terminal), "InputText")]
	public static class InputText_Patch
	{
		public static bool Prefix(Terminal __instance)
		{
			if (!modEnabled.Value)
			{
				return true;
			}
			string text = ((TMP_InputField)__instance.m_input).text;
			if (text.ToLower().Equals("buildingdamage reset"))
			{
				((BaseUnityPlugin)context).Config.Reload();
				((BaseUnityPlugin)context).Config.Save();
				Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
				Traverse.Create((object)__instance).Method("AddString", new object[1] { "Building Damage config reloaded" }).GetValue();
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(WearNTear), "RPC_HealthChanged")]
	public static class RPC_HealthChanged_Patch
	{
		public static bool Prefix(long peer, Piece ___m_piece)
		{
			if (___m_piece == null)
			{
				return true;
			}
			if (uncreatedDamageMult.Value == 0f && ___m_piece.GetCreator() == 0)
			{
				return false;
			}
			if (nonCreatorDamageMult.Value == 0f && ___m_piece.GetCreator() != 0L && peer != ___m_piece.GetCreator())
			{
				return false;
			}
			if (creatorDamageMult.Value == 0f && ___m_piece.GetCreator() != 0L && peer == ___m_piece.GetCreator())
			{
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(WearNTear), "RPC_Damage")]
	public static class RPC_Damage_Patch
	{
		public static void Prefix(ref HitData hit, Piece ___m_piece)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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)
			if (modEnabled.Value)
			{
				float num = 1f;
				_ = hit.m_attacker;
				num = (((ZDOID)(ref hit.m_attacker)).IsNone() ? naturalDamageMult.Value : ((___m_piece != null && ___m_piece.GetCreator() == 0) ? uncreatedDamageMult.Value : ((!(hit.m_attacker == ((Character)Player.m_localPlayer).GetZDOID()) || !((Object)(object)___m_piece != (Object)null) || !___m_piece.IsCreator()) ? nonCreatorDamageMult.Value : creatorDamageMult.Value)));
				MultiplyDamage(ref hit, num);
			}
		}

		public static void MultiplyDamage(ref HitData hit, float value)
		{
			value = Math.Max(0f, value);
			hit.m_damage.m_damage *= value;
			hit.m_damage.m_blunt *= value;
			hit.m_damage.m_slash *= value;
			hit.m_damage.m_pierce *= value;
			hit.m_damage.m_chop *= value;
			hit.m_damage.m_pickaxe *= value;
			hit.m_damage.m_fire *= value;
			hit.m_damage.m_frost *= value;
			hit.m_damage.m_lightning *= value;
			hit.m_damage.m_poison *= value;
			hit.m_damage.m_spirit *= value;
		}
	}

	[HarmonyPatch(typeof(WearNTear), "ApplyDamage")]
	public static class ApplyDamage_Patch
	{
		public static void Prefix(ref float damage)
		{
			if (modEnabled.Value && !Environment.StackTrace.Contains("RPC_Damage"))
			{
				damage *= naturalDamageMult.Value;
			}
		}
	}

	public static readonly bool isDebug = true;

	public static BepInExPlugin context;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<float> creatorDamageMult;

	public static ConfigEntry<float> nonCreatorDamageMult;

	public static ConfigEntry<float> uncreatedDamageMult;

	public static ConfigEntry<float> naturalDamageMult;

	public static ConfigEntry<bool> preventWearDamage;

	public static ConfigEntry<int> nexusID;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	public void Awake()
	{
		context = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		creatorDamageMult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CreatorDamageMult", 1f, "Multiply damage by creators by this much");
		nonCreatorDamageMult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "NonCreatorDamageMult", 1f, "Multiply damage by non-creators by this much");
		uncreatedDamageMult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "UncreatedDamageMult", 1f, "Multiply damage to uncreated buildings by this much");
		naturalDamageMult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "NaturalDamageMult", 1f, "Multiply natural wear damage to buildings by this much");
		nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 233, "Nexus mod ID for updates");
		if (modEnabled.Value)
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}
	}
}