Decompiled source of CheaperStonePieces v1.0.0

plugins/BaraphorSharedLibs.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using JotunnLib.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("shared-libs")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("shared-libs")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("146dae52-6034-4645-a498-32734e490365")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BaraphorSharedLibs;

public class AssetBundleHelper
{
	public static AssetBundle GetAssetBundleFromResources(string fileName, Assembly assembly)
	{
		string name = assembly.GetManifestResourceNames().Single((string str) => str.EndsWith(fileName));
		using Stream stream = assembly.GetManifestResourceStream(name);
		return AssetBundle.LoadFromStream(stream);
	}
}
public class BaseValheimMod : BaseUnityPlugin
{
	protected bool IsDebugging;

	protected AssetBundle AssetBundle;

	protected Harmony Harmony;

	public BaseValheimMod(string guid)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		Harmony = new Harmony(guid);
	}

	public void LoadAssetBundle(string file, Assembly assembly)
	{
		AssetBundle = AssetBundleHelper.GetAssetBundleFromResources(file, assembly);
	}

	public void RegisterPrefab(string path, string name)
	{
		if ((Object)(object)AssetBundle != (Object)null)
		{
			AccessTools.Method(typeof(PrefabManager), "RegisterPrefab", new Type[2]
			{
				typeof(GameObject),
				typeof(string)
			}, (Type[])null).Invoke(PrefabManager.Instance, new object[2]
			{
				AssetBundle.LoadAsset<GameObject>(path),
				name
			});
		}
	}

	public void Log(object data, LogLevel level = 16)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Invalid comparison between Unknown and I4
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Invalid comparison between Unknown and I4
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected I4, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Invalid comparison between Unknown and I4
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Invalid comparison between Unknown and I4
		if (!IsDebugging)
		{
			return;
		}
		if ((int)level <= 16)
		{
			switch ((int)level)
			{
			default:
				if ((int)level != 16)
				{
					break;
				}
				LogInfo(data);
				return;
			case 0:
				LogInfo(data);
				return;
			case 8:
				LogMessage(data);
				return;
			case 4:
				LogWarning(data);
				return;
			case 2:
				LogError(data);
				return;
			case 1:
				LogFatal(data);
				return;
			case 3:
			case 5:
			case 6:
			case 7:
				break;
			}
		}
		else
		{
			if ((int)level == 32)
			{
				LogDebug(data);
				return;
			}
			if ((int)level == 63)
			{
				LogInfo(data);
				return;
			}
		}
		LogInfo(data);
	}

	private void LogDebug(object data)
	{
		if (IsDebugging)
		{
			((BaseUnityPlugin)this).Logger.LogDebug(data);
		}
	}

	private void LogError(object data)
	{
		if (IsDebugging)
		{
			((BaseUnityPlugin)this).Logger.LogError(data);
		}
	}

	private void LogFatal(object data)
	{
		if (IsDebugging)
		{
			((BaseUnityPlugin)this).Logger.LogFatal(data);
		}
	}

	private void LogInfo(object data)
	{
		if (IsDebugging)
		{
			((BaseUnityPlugin)this).Logger.LogInfo(data);
		}
	}

	private void LogMessage(object data)
	{
		if (IsDebugging)
		{
			((BaseUnityPlugin)this).Logger.LogMessage(data);
		}
	}

	private void LogWarning(object data)
	{
		if (IsDebugging)
		{
			((BaseUnityPlugin)this).Logger.LogWarning(data);
		}
	}
}

plugins/CheaperStonePieces.dll

Decompiled 10 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BaraphorSharedLibs;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("cheaper-stone-pieces")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("cheaper-stone-pieces")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("56310632-a8f4-496b-875a-97d1b4069f48")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CheaperStonePieces;

[BepInPlugin("com.baraphor.cheaperstonepieces", "Cheaper Stone Pieces", "1.0.0")]
[BepInProcess("valheim.exe")]
public class CheaperStonePiecesMod : BaseValheimMod
{
	public static ConfigEntry<int> stone_wall_4x2;

	public static ConfigEntry<int> stone_wall_2x1;

	public static ConfigEntry<int> stone_wall_1x1;

	public static ConfigEntry<int> stone_floor_2x2;

	public static ConfigEntry<int> stone_arch;

	public static ConfigEntry<int> stone_pillar;

	public static ConfigEntry<int> stone_stair;

	public CheaperStonePiecesMod()
		: base("com.baraphor.cheaperstonepieces")
	{
		stone_wall_4x2 = ((BaseUnityPlugin)this).Config.Bind<int>("StonePieceCosts", "StoneWall4x2", 8, "The cost of the the StoneWall4x2 piece, the unmodded value is 6.");
		stone_wall_2x1 = ((BaseUnityPlugin)this).Config.Bind<int>("StonePieceCosts", "StoneWall2x1", 2, "The cost of the the StoneWall4x2 piece, the unmodded value is 6.");
		stone_wall_1x1 = ((BaseUnityPlugin)this).Config.Bind<int>("StonePieceCosts", "StoneWall1x1", 1, "The cost of the the StoneWall4x2 piece, the unmodded value is 3.");
		stone_floor_2x2 = ((BaseUnityPlugin)this).Config.Bind<int>("StonePieceCosts", "StoneFloor2x2", 4, "The cost of the the StoneWall4x2 piece, the unmodded value is 6.");
		stone_arch = ((BaseUnityPlugin)this).Config.Bind<int>("StonePieceCosts", "StoneArch", 2, "The cost of the the StoneWall4x2 piece, the unmodded value is 4.");
		stone_pillar = ((BaseUnityPlugin)this).Config.Bind<int>("StonePieceCosts", "StonePillar", 2, "The cost of the the StoneWall4x2 piece, the unmodded value is 5.");
		stone_stair = ((BaseUnityPlugin)this).Config.Bind<int>("StonePieceCosts", "StoneStair", 4, "The cost of the the StoneWall4x2 piece, the unmodded value is 8.");
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Loaded com.baraphor.cheaperstonepieces");
	}

	public void Awake()
	{
		base.Harmony.PatchAll();
	}
}
[HarmonyPatch]
public class Patch
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	public static void PieceTable_Awake_WallCost(ref ObjectDB __instance)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		Object[] array = Resources.FindObjectsOfTypeAll(typeof(GameObject));
		for (int i = 0; i < array.Length; i++)
		{
			GameObject val = (GameObject)array[i];
			if (((Object)val).name == "stone_wall_4x2")
			{
				val.GetComponent<Piece>().m_resources[0].m_amount = CheaperStonePiecesMod.stone_wall_4x2.Value;
			}
			else if (((Object)val).name == "stone_wall_2x1")
			{
				val.GetComponent<Piece>().m_resources[0].m_amount = CheaperStonePiecesMod.stone_wall_2x1.Value;
			}
			else if (((Object)val).name == "stone_wall_1x1")
			{
				val.GetComponent<Piece>().m_resources[0].m_amount = CheaperStonePiecesMod.stone_wall_1x1.Value;
			}
			else if (((Object)val).name == "stone_floor_2x2")
			{
				val.GetComponent<Piece>().m_resources[0].m_amount = CheaperStonePiecesMod.stone_floor_2x2.Value;
			}
			else if (((Object)val).name == "stone_arch")
			{
				val.GetComponent<Piece>().m_resources[0].m_amount = CheaperStonePiecesMod.stone_arch.Value;
			}
			else if (((Object)val).name == "stone_pillar")
			{
				val.GetComponent<Piece>().m_resources[0].m_amount = CheaperStonePiecesMod.stone_pillar.Value;
			}
			else if (((Object)val).name == "stone_stair")
			{
				val.GetComponent<Piece>().m_resources[0].m_amount = CheaperStonePiecesMod.stone_stair.Value;
			}
		}
	}
}