Decompiled source of MahjongScrap v1.0.0

plugins/MahjongScrap/MahjongScrap.dll

Decompiled 5 hours 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.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1386da020716d56b96fa196a9900801d8ec2e71b")]
[assembly: AssemblyProduct("MahjongScrap")]
[assembly: AssemblyTitle("MahjongScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.0")]
	[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");
			}
			Logger.LogInfo((object)"Plugin MahjongScrap is loaded!");
		}

		private void RegisterTiles()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogWarning((object)"The asset bundel is null or not set!");
			}
			List<Item> list = LoadTiles();
			List<Item> list2 = LoadRedTiles();
			if (list != null && list.Count > 0)
			{
				int value = BoundConfig.MahjongTileSpawnWeight.Value;
				Vector3 rotationOffset = default(Vector3);
				foreach (Item item in list)
				{
					((Vector3)(ref rotationOffset))..ctor(0f, 0f, 90f);
					item.rotationOffset = rotationOffset;
					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;
			Vector3 rotationOffset2 = default(Vector3);
			foreach (Item item2 in list2)
			{
				((Vector3)(ref rotationOffset2))..ctor(0f, 0f, 90f);
				item2.rotationOffset = rotationOffset2;
				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 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.0";
	}
}
namespace MahjongScrap.Configuration
{
	public class PluginConfig
	{
		public ConfigEntry<int> MahjongTileSpawnWeight;

		public ConfigEntry<int> MahjongRedTileSpawnWeight;

		public ConfigEntry<bool> EnableMahjongTiles;

		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");
			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
	{
	}
}