Decompiled source of Venture Rough Stone v0.1.0

Plugins/VentureValheim.PiecesRoughStone.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("VentureValheim.PiecesRoughStone")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VentureValheim.PiecesRoughStone")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("640FA3FD-69DD-4F28-8C2F-1D91C78B3A7B")]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace VentureValheim
{
	public class PieceMaker
	{
		public struct PieceMakerConfiguration
		{
			public string PrefabPrefix;

			public string NamePrefix;

			public List<PieceConfiguration> Pieces;

			public string PrefabReference;

			public string PieceTableCategory;

			public Material ReplacementMaterial;
		}

		public struct PieceConfiguration
		{
			public string Prefab;

			public int ResourceAmount;
		}

		public static PieceTable GetPieceTable(GameObject item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return null;
			}
			ItemDrop component = item.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				return null;
			}
			return component.m_itemData?.m_shared.m_buildPieces;
		}

		public static List<PieceConfiguration> FindVanillaPieces(PieceTable pieceTable)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			List<PieceConfiguration> list = new List<PieceConfiguration>();
			Piece val = default(Piece);
			foreach (GameObject piece in pieceTable.m_pieces)
			{
				if (piece.TryGetComponent<Piece>(ref val) && (int)val.m_category == 3 && val.m_resources.Length == 1 && ((Object)val.m_resources[0].m_resItem).name == "BlackMarble")
				{
					list.Add(new PieceConfiguration
					{
						Prefab = Utils.GetPrefabName(((Object)piece).name),
						ResourceAmount = val.m_resources[0].m_amount
					});
				}
			}
			return list;
		}

		public static void AddCopies(PieceMakerConfiguration config, GameObject root, ManualLogSource logger)
		{
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Expected O, but got Unknown
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Expected O, but got Unknown
			if (config.Pieces == null || config.Pieces.Count == 0)
			{
				logger.LogError((object)"No pieces found! Can not add new options.");
				return;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab(config.PrefabReference);
			Piece val = null;
			WearNTear val2 = null;
			if ((Object)(object)prefab == (Object)null)
			{
				logger.LogWarning((object)"Could not find stone piece to copy effects. Using defaults.");
			}
			else
			{
				val = prefab.GetComponent<Piece>();
				val2 = prefab.GetComponent<WearNTear>();
			}
			if ((Object)(object)config.ReplacementMaterial == (Object)null)
			{
				MeshRenderer componentInChildren = prefab.GetComponentInChildren<MeshRenderer>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					config.ReplacementMaterial = ((Renderer)componentInChildren).material;
				}
				if ((Object)(object)config.ReplacementMaterial == (Object)null)
				{
					logger.LogError((object)("Could not find material to copy from prefab " + config.PrefabReference + "!"));
				}
			}
			int num = 0;
			foreach (PieceConfiguration piece in config.Pieces)
			{
				GameObject prefab2 = ZNetScene.instance.GetPrefab(piece.Prefab);
				GameObject val3 = Object.Instantiate<GameObject>(prefab2, root.transform, false);
				((Object)val3).name = config.PrefabPrefix + Utils.GetPrefabName(val3);
				Piece component = val3.GetComponent<Piece>();
				if ((Object)(object)component != (Object)null)
				{
					Piece component2 = prefab2.GetComponent<Piece>();
					component.m_name = config.NamePrefix + component2.m_name;
					component.m_icon = component2.m_icon;
					component.m_placeEffect = val.m_placeEffect;
					WearNTear component3 = val3.GetComponent<WearNTear>();
					if ((Object)(object)component3 != (Object)null)
					{
						component3.m_health = val2.m_health;
						component3.m_destroyedEffect = val2.m_destroyedEffect;
						component3.m_hitEffect = val2.m_hitEffect;
						component3.m_materialType = val2.m_materialType;
						component3.m_damages = val2.m_damages;
					}
					MeshRenderer[] componentsInChildren = val3.GetComponentsInChildren<MeshRenderer>(true);
					if (componentsInChildren != null)
					{
						MeshRenderer[] array = componentsInChildren;
						for (int i = 0; i < array.Length; i++)
						{
							((Renderer)array[i]).material = config.ReplacementMaterial;
						}
					}
					PieceConfig val4 = new PieceConfig();
					val4.Name = component.m_name;
					val4.Description = component.m_description;
					val4.PieceTable = PieceTables.Hammer;
					val4.Category = config.PieceTableCategory;
					val4.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
					{
						new RequirementConfig
						{
							Item = "Stone",
							Amount = piece.ResourceAmount,
							Recover = true
						}
					};
					PieceConfig val5 = val4;
					PieceManager.Instance.AddPiece(new CustomPiece(val3, true, val5));
					num++;
					continue;
				}
				logger.LogDebug((object)(((Object)val3).name + " is not a piece, skipping."));
				break;
			}
			logger.LogInfo((object)$"Done adding {num} additional pieces.");
		}
	}
}
namespace VentureValheim.PiecesRoughStone
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.orianaventure.mod.VenturePiecesRoughStone", "VenturePiecesRoughStone", "0.1.0")]
	public class PiecesRoughStonePlugin : BaseUnityPlugin
	{
		private const string ModName = "VenturePiecesRoughStone";

		private const string ModVersion = "0.1.0";

		private const string Author = "com.orianaventure.mod";

		private const string ModGUID = "com.orianaventure.mod.VenturePiecesRoughStone";

		private readonly Harmony HarmonyInstance = new Harmony("com.orianaventure.mod.VenturePiecesRoughStone");

		public static readonly ManualLogSource PiecesRoughStoneLogger = Logger.CreateLogSource("VenturePiecesRoughStone");

		public static GameObject Root;

		internal static AssetBundle StoneBundle;

		internal static Material StoneTexture;

		public void Awake()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			PiecesRoughStoneLogger.LogInfo((object)"My girlfriend turned into the moon.");
			Root = new GameObject("RoughStoneRoot");
			Root.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)Root);
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			HarmonyInstance.PatchAll(executingAssembly);
			PrefabManager.OnPrefabsRegistered += PiecesRoughStone.Initialize;
			StoneBundle = AssetUtils.LoadAssetBundleFromResources("vv_roughstone", Assembly.GetExecutingAssembly());
			StoneTexture = StoneBundle.LoadAsset<Material>("vv_rough_stone");
		}
	}
	public class PiecesRoughStone
	{
		public static void Initialize()
		{
			PieceTable pieceTable = PieceMaker.GetPieceTable(ObjectDB.instance.GetItemPrefab(StringExtensionMethods.GetStableHashCode("Hammer")));
			if ((Object)(object)pieceTable == (Object)null)
			{
				PiecesRoughStonePlugin.PiecesRoughStoneLogger.LogError((object)"Could not add new pieces! Original piece table cannot be found.");
			}
			else
			{
				List<PieceMaker.PieceConfiguration> pieces = PieceMaker.FindVanillaPieces(pieceTable);
				PieceMaker.PieceMakerConfiguration config = default(PieceMaker.PieceMakerConfiguration);
				config.Pieces = pieces;
				config.PieceTableCategory = "VentureRoughStone";
				config.PrefabPrefix = "VV_RS_";
				config.NamePrefix = "VRS ";
				config.PrefabReference = "stone_wall_4x2";
				config.ReplacementMaterial = PiecesRoughStonePlugin.StoneTexture;
				PieceMaker.AddCopies(config, PiecesRoughStonePlugin.Root, PiecesRoughStonePlugin.PiecesRoughStoneLogger);
			}
			PrefabManager.OnPrefabsRegistered -= Initialize;
		}
	}
}