Decompiled source of VeinBooster v0.0.5

plugins/VeinBooster/VeinBooster.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("VeinBooster")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VeinBooster")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("64443039-edc2-4adb-8193-a459b7477663")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.2.0")]
namespace VeinBooster;

[BepInPlugin("veinbooster.nhickling.co.uk", "VeinBooster", "0.0.0.5")]
public class VeinBooster : BaseUnityPlugin
{
	public const string pluginGuid = "veinbooster.nhickling.co.uk";

	public const string pluginName = "VeinBooster";

	public const string pluginVersion = "0.0.0.5";

	private static ManualLogSource ModLogger;

	public static ConfigEntry<int> ProtectionChance;

	public void Awake()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Expected O, but got Unknown
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Expected O, but got Unknown
		ModLogger = ((BaseUnityPlugin)this).Logger;
		ModLogger.LogInfo((object)"VeinBooster: started");
		Harmony val = new Harmony("veinbooster.nhickling.co.uk");
		ModLogger.LogInfo((object)"VeinBooster: Fetching patch references");
		MethodInfo methodInfo = AccessTools.Method(typeof(PendingVoxelChanges), "TryDig", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(VeinBooster), "TryDig_Patch", (Type[])null, (Type[])null);
		ModLogger.LogInfo((object)"VeinBooster: Starting Patch");
		val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		ModLogger.LogInfo((object)"VeinBooster: Patched");
		ProtectionChance = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "ProtectionChance", 100, new ConfigDescription("Percentage chance damage to the ore is prevented, reduce this to lower the power of the mod.", (AcceptableValueBase)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
	}

	public static void TryDig_Patch(PendingVoxelChanges __instance, in Vector3Int coord, int digStrength, int miningTier, ref int numResourcesTaken, bool __result)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!__result && numResourcesTaken > 0 && ShouldRepairVoxel())
			{
				Vector3Int val = coord;
				int x = ((Vector3Int)(ref val)).x;
				val = coord;
				int y = ((Vector3Int)(ref val)).y;
				val = coord;
				int z = ((Vector3Int)(ref val)).z;
				int chunkId = VoxelManager.GetChunkId(ref x, ref y, ref z);
				ref ChunkPendingVoxelChanges reference = ref __instance.chunkData[__instance.GetOrCreateIndexForChunk(ref chunkId)];
				val = coord;
				x = ((Vector3Int)(ref val)).x;
				val = coord;
				y = ((Vector3Int)(ref val)).y;
				val = coord;
				z = ((Vector3Int)(ref val)).z;
				int index = ((ChunkPendingVoxelChanges)(ref reference)).GetIndex(ref x, ref y, ref z);
				((ChunkPendingVoxelChanges)(ref reference)).GetOrAdd(index).integrity += numResourcesTaken;
			}
		}
		catch (Exception ex)
		{
			ModLogger.LogError((object)("VeinBooster: TryDig: " + ex.Message));
		}
	}

	private static bool ShouldRepairVoxel()
	{
		return ProtectionChance.Value > Random.Range(0, 99);
	}
}