Decompiled source of MahjongScrap v1.0.3

plugins/MahjongScrap/MahjongScrap.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using LethalLib.Modules;
using MahjongScrap.Configuration;
using MahjongScrap.NetcodePatcher;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MahjongScrap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+ff0eec4d9146f49687e76b82ef322476f99cbb7f")]
[assembly: AssemblyProduct("MahjongScrap")]
[assembly: AssemblyTitle("MahjongScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 MahjongScrap
{
	[BepInPlugin("MahjongScrap", "MahjongScrap", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle? ModAssets;

		internal static PluginConfig BoundConfig { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			InitializeNetworkBehaviours();
			string path = "mahjongscrapmodassets";
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			bool value = BoundConfig.EnableMahjongTiles.Value;
			if (value)
			{
				Logger.LogInfo((object)$"EnableMahjongTiles = [{value}] > enabling Mahjong Tiles");
				RegisterTiles();
			}
			else
			{
				Logger.LogInfo((object)$"EnableMahjongTiles = [{value}] > skipped loading Mahjong Tiles");
			}
			bool value2 = BoundConfig.EnableMahjongSoulPaintings.Value;
			if (value2)
			{
				Logger.LogInfo((object)$"EnableMahjongSoulPaintings = [{value2}] > enabling Mahjong Soul Paintings");
				RegisterPaintings();
			}
			else
			{
				Logger.LogInfo((object)$"EnableMahjongSoulPaintings = [{value2}] > skipped loading Mahjong Soul Paintings");
			}
			Logger.LogInfo((object)"Plugin MahjongScrap is loaded!");
		}

		private void RegisterTiles()
		{
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogWarning((object)"The asset bundle is null or not set!");
			}
			List<Item> list = LoadTiles();
			List<Item> list2 = LoadRedTiles();
			if (list != null && list.Count > 0)
			{
				int value = BoundConfig.MahjongTileSpawnWeight.Value;
				foreach (Item item in list)
				{
					NetworkPrefabs.RegisterNetworkPrefab(item.spawnPrefab);
					Items.RegisterScrap(item, value, (LevelTypes)(-1));
				}
				Logger.LogInfo((object)"Done loading normal tiles");
			}
			if (list2 == null || list2.Count <= 0)
			{
				return;
			}
			int value2 = BoundConfig.MahjongTileSpawnWeight.Value;
			foreach (Item item2 in list2)
			{
				NetworkPrefabs.RegisterNetworkPrefab(item2.spawnPrefab);
				Items.RegisterScrap(item2, value2, (LevelTypes)(-1));
			}
			Logger.LogInfo((object)"Done loading red fives");
		}

		private List<Item> LoadTiles()
		{
			List<Item> list = new List<Item>();
			if ((Object)(object)ModAssets != (Object)null)
			{
				list.Add(ModAssets.LoadAsset<Item>("EastTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouthTile"));
				list.Add(ModAssets.LoadAsset<Item>("WestTile"));
				list.Add(ModAssets.LoadAsset<Item>("NorthTile"));
				list.Add(ModAssets.LoadAsset<Item>("GreenDragontile"));
				list.Add(ModAssets.LoadAsset<Item>("RedDragonTile"));
				list.Add(ModAssets.LoadAsset<Item>("WhiteDragonTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuOneTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuTwoTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuThreeTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuFourTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuFiveTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuSixTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuSevenTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuEightTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuNineTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuOneTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuTwoTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuThreeTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuFourTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuFiveTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuSixTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuSevenTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuEightTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuNineTile"));
				list.Add(ModAssets.LoadAsset<Item>("ManzuOneTile"));
				list.Add(ModAssets.LoadAsset<Item>("ManzuTwoTile"));
				list.Add(ModAssets.LoadAsset<Item>("ManzuThreeTile"));
				list.Add(ModAssets.LoadAsset<Item>("ManzuFourTile"));
				list.Add(ModAssets.LoadAsset<Item>("ManzuFiveTile"));
				list.Add(ModAssets.LoadAsset<Item>("ManzuSixTile"));
				list.Add(ModAssets.LoadAsset<Item>("ManzuSevenTile"));
				list.Add(ModAssets.LoadAsset<Item>("ManzuEightTile"));
			}
			else
			{
				Logger.LogWarning((object)"Something went wrong with loading the tiles");
			}
			return list;
		}

		private List<Item> LoadRedTiles()
		{
			List<Item> list = new List<Item>();
			if ((Object)(object)ModAssets != (Object)null)
			{
				list.Add(ModAssets.LoadAsset<Item>("ManzuRedFiveTile"));
				list.Add(ModAssets.LoadAsset<Item>("PinzuRedFiveTile"));
				list.Add(ModAssets.LoadAsset<Item>("SouzuRedFiveTile"));
			}
			else
			{
				Logger.LogWarning((object)"Something went wrong with loading the red tiles");
			}
			return list;
		}

		private void RegisterPaintings()
		{
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogWarning((object)"The asset bundle is null or not set!");
			}
			List<Item> list = LoadPaintings();
			if (list == null || list.Count <= 0)
			{
				return;
			}
			int value = BoundConfig.MahjongSoulPaintingsSpawnWeight.Value;
			bool value2 = BoundConfig.EnableMahjongSoulHalloweenPaintings.Value;
			foreach (Item item in list)
			{
				NetworkPrefabs.RegisterNetworkPrefab(item.spawnPrefab);
				if (((Object)item).name.Equals("PaintingHalloween") && !value2)
				{
					Logger.LogInfo((object)"Halloween paintings are disabled");
					Items.RegisterScrap(item, 0, (LevelTypes)(-1));
				}
				else
				{
					Items.RegisterScrap(item, value, (LevelTypes)(-1));
				}
			}
			Logger.LogInfo((object)"Done loading mahjong soul paintings");
		}

		private List<Item> LoadPaintings()
		{
			List<Item> list = new List<Item>();
			if ((Object)(object)ModAssets != (Object)null)
			{
				list.Add(ModAssets.LoadAsset<Item>("PaintingPortraitIchihime"));
				list.Add(ModAssets.LoadAsset<Item>("PaintingPortraitJoseph"));
				list.Add(ModAssets.LoadAsset<Item>("PaintingPortraitGroup"));
				list.Add(ModAssets.LoadAsset<Item>("PaintingYakuman"));
				list.Add(ModAssets.LoadAsset<Item>("PaintingHalloween"));
			}
			else
			{
				Logger.LogWarning((object)"Something went wrong with loading the paintings");
			}
			return list;
		}

		private static void InitializeNetworkBehaviours()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MahjongScrap";

		public const string PLUGIN_NAME = "MahjongScrap";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace MahjongScrap.Configuration
{
	public class PluginConfig
	{
		public ConfigEntry<int> MahjongTileSpawnWeight;

		public ConfigEntry<int> MahjongRedTileSpawnWeight;

		public ConfigEntry<bool> EnableMahjongTiles;

		public ConfigEntry<bool> EnableMahjongSoulPaintings;

		public ConfigEntry<bool> EnableMahjongSoulHalloweenPaintings;

		public ConfigEntry<int> MahjongSoulPaintingsSpawnWeight;

		public PluginConfig(ConfigFile cfg)
		{
			MahjongTileSpawnWeight = cfg.Bind<int>("Mahjong Tiles", "Normal Tiles Spawn weight", 20, "The spawn chance weight for Mahjong Tiles, relative to other existing scrap.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			MahjongRedTileSpawnWeight = cfg.Bind<int>("Mahjong Tiles", "Red Five Spawn weight", 5, "The spawn chance weight for Red Fives, relative to other existing scrap.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			EnableMahjongTiles = cfg.Bind<bool>("Mahjong Tiles", "Enable Mahjong Tiles", true, "Enables or Disables Mahjong Tiles");
			EnableMahjongSoulPaintings = cfg.Bind<bool>("Paintings", "Enable Mahjong Soul paintings", true, "Enables or Disables Mahjong Soul inspired paintings");
			MahjongSoulPaintingsSpawnWeight = cfg.Bind<int>("Paintings", "SpawnWeight Mahjong Soul paintings", 5, "The spawn chance weight for Mahjong Soul paintings, relative to other existing scrap.\nGoes up from 0, lower is more rare, 100 and up is very common.");
			EnableMahjongSoulHalloweenPaintings = cfg.Bind<bool>("Paintings", "Enable Mahjong Soul Halloween paintings", true, "Enables or Disables Mahjong Soul inspired Halloween paintings");
			ClearUnusedEntries(cfg);
		}

		private void ClearUnusedEntries(ConfigFile cfg)
		{
			PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null);
			dictionary.Clear();
			cfg.Save();
		}
	}
}
namespace MahjongScrap.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}