Decompiled source of StatCreditFix v1.0.0

StatCreditFix.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("StatCreditFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StatCreditFix")]
[assembly: AssemblyTitle("StatCreditFix")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace StatCreditFix
{
	[BepInPlugin("qua8ion.valheim.statcreditfix", "StatCreditFix", "1.0.0")]
	public class StatCreditFixPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "qua8ion.valheim.statcreditfix";

		public const string PluginName = "StatCreditFix";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ClaimTrees;

		internal static ConfigEntry<bool> ClaimCookingStations;

		internal static ConfigEntry<bool> LogClaims;

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			ClaimTrees = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ClaimTrees", true, "Take ownership of a tree when you hit it, so felled trees count for you (The Lumberjack).");
			ClaimCookingStations = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ClaimCookingStations", true, "Take ownership of a cooking station or oven when you take finished food from it, so the dish counts for you (The Master Chef).");
			LogClaims = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LogClaims", true, "Write a line to the BepInEx log each time ownership is taken.");
			new Harmony("qua8ion.valheim.statcreditfix").PatchAll(Assembly.GetExecutingAssembly());
		}

		internal static void Claim(ZNetView nview, string what)
		{
			if (!((Object)(object)nview == (Object)null) && nview.IsValid() && !nview.IsOwner())
			{
				nview.ClaimOwnership();
				if (LogClaims.Value)
				{
					Log.LogInfo((object)("Took ownership of " + what));
				}
			}
		}
	}
	[HarmonyPatch(typeof(TreeBase), "Damage")]
	internal static class TreeBase_Damage_Patch
	{
		private static void Prefix(TreeBase __instance, HitData hit)
		{
			if (StatCreditFixPlugin.ClaimTrees.Value && hit != null)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)hit.GetAttacker() != (Object)(object)localPlayer))
				{
					StatCreditFixPlugin.Claim(((Component)__instance).GetComponent<ZNetView>(), ((Object)__instance).name);
				}
			}
		}
	}
	[HarmonyPatch(typeof(CookingStation), "OnInteract")]
	internal static class CookingStation_OnInteract_Patch
	{
		private static readonly MethodInfo HaveDoneItem = AccessTools.Method(typeof(CookingStation), "HaveDoneItem", (Type[])null, (Type[])null);

		private static void Prefix(CookingStation __instance, Humanoid user)
		{
			if (StatCreditFixPlugin.ClaimCookingStations.Value && !((Object)(object)user == (Object)null) && !((Object)(object)user != (Object)(object)Player.m_localPlayer) && !(HaveDoneItem == null) && (bool)HaveDoneItem.Invoke(__instance, null))
			{
				StatCreditFixPlugin.Claim(((Component)__instance).GetComponent<ZNetView>(), ((Object)__instance).name);
			}
		}
	}
}