Decompiled source of MahjongScrap v1.0.5

plugins/MahjongScrap/MahjongScrap.dll

Decompiled 2 weeks 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.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+9eaa7753ba65d7babce413ea398e761feb18f77a")]
[assembly: AssemblyProduct("MahjongScrap")]
[assembly: AssemblyTitle("MahjongScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger = null;

		public static AssetBundle? ModAssets;

		private static readonly string[] TileNames = new string[33]
		{
			"EastTile", "SouthTile", "WestTile", "NorthTile", "GreenDragontile", "RedDragonTile", "WhiteDragonTile", "PinzuOneTile", "PinzuTwoTile", "PinzuThreeTile",
			"PinzuFourTile", "PinzuFiveTile", "PinzuSixTile", "PinzuSevenTile", "PinzuEightTile", "PinzuNineTile", "SouzuOneTile", "SouzuTwoTile", "SouzuThreeTile", "SouzuFourTile",
			"SouzuFiveTile", "SouzuSixTile", "SouzuSevenTile", "SouzuEightTile", "SouzuNineTile", "ManzuOneTile", "ManzuTwoTile", "ManzuThreeTile", "ManzuFourTile", "ManzuFiveTile",
			"ManzuSixTile", "ManzuSevenTile", "ManzuEightTile"
		};

		private static readonly string[] RedTileNames = new string[3] { "ManzuRedFiveTile", "PinzuRedFiveTile", "SouzuRedFiveTile" };

		private static readonly string[] PaintingNames = new string[6] { "PaintingPortraitIchihime", "PaintingPortraitJoseph", "PaintingPortraitGroup", "PaintingYakuman", "PaintingHalloween", "PaintingWinter" };

		private const string HalloweenPaintingName = "PaintingHalloween";

		private const string WinterPaintingName = "PaintingWinter";

		internal static PluginConfig BoundConfig { get; private set; } = null;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			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");
				RegisterScrap(TileNames, BoundConfig.MahjongTileSpawnWeight.Value);
				Logger.LogInfo((object)"Done loading normal tiles");
				RegisterScrap(RedTileNames, BoundConfig.MahjongRedTileSpawnWeight.Value);
				Logger.LogInfo((object)"Done loading red fives");
			}
			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");
				RegisterScrap(PaintingNames, BoundConfig.MahjongSoulPaintingsSpawnWeight.Value);
				Logger.LogInfo((object)"Done loading mahjong soul paintings");
			}
			else
			{
				Logger.LogInfo((object)$"EnableMahjongSoulPaintings = [{value2}] > skipped loading Mahjong Soul Paintings");
			}
			Logger.LogInfo((object)"Plugin MahjongScrap is loaded!");
		}

		private void RegisterScrap(IEnumerable<string> assetNames, int spawnWeight)
		{
			bool value = BoundConfig.EnableMahjongSoulHalloweenPaintings.Value;
			bool value2 = BoundConfig.EnableMahjongSoulWinterPaintings.Value;
			foreach (Item item in LoadItems(assetNames))
			{
				NetworkPrefabs.RegisterNetworkPrefab(item.spawnPrefab);
				if (((Object)item).name.Equals("PaintingHalloween") && !value)
				{
					Logger.LogInfo((object)"Halloween paintings are disabled");
					Items.RegisterScrap(item, 0, (LevelTypes)(-1));
				}
				else if (((Object)item).name.Equals("PaintingWinter") && !value2)
				{
					Logger.LogInfo((object)"Winter paintings are disabled");
					Items.RegisterScrap(item, 0, (LevelTypes)(-1));
				}
				else
				{
					Items.RegisterScrap(item, spawnWeight, (LevelTypes)(-1));
				}
			}
		}

		private List<Item> LoadItems(IEnumerable<string> assetNames)
		{
			List<Item> list = new List<Item>();
			foreach (string assetName in assetNames)
			{
				Item val = ModAssets.LoadAsset<Item>(assetName);
				if ((Object)(object)val == (Object)null || (Object)(object)val.spawnPrefab == (Object)null)
				{
					Logger.LogWarning((object)("Could not load item [" + assetName + "] from the asset bundle, skipping it"));
				}
				else
				{
					list.Add(val);
				}
			}
			return list;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MahjongScrap";

		public const string PLUGIN_NAME = "MahjongScrap";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}
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<bool> EnableMahjongSoulWinterPaintings;

		public ConfigEntry<int> MahjongSoulPaintingsSpawnWeight;

		public PluginConfig(ConfigFile cfg)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			MahjongTileSpawnWeight = cfg.Bind<int>("Mahjong Tiles", "Normal Tiles Spawn weight", 20, new ConfigDescription("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.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 200), Array.Empty<object>()));
			MahjongRedTileSpawnWeight = cfg.Bind<int>("Mahjong Tiles", "Red Five Spawn weight", 5, new ConfigDescription("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.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 200), Array.Empty<object>()));
			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, new ConfigDescription("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.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 200), Array.Empty<object>()));
			EnableMahjongSoulHalloweenPaintings = cfg.Bind<bool>("Paintings", "Enable Mahjong Soul Halloween paintings", true, "Enables or Disables Mahjong Soul inspired Halloween paintings");
			EnableMahjongSoulWinterPaintings = cfg.Bind<bool>("Paintings", "Enable Mahjong Soul Winter paintings", true, "Enables or Disables Mahjong Soul inspired Winter event paintings");
			ClearUnusedEntries(cfg);
		}

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