Decompiled source of Moon Items v1.0.2

Mods/Moon_Items.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using Moon_Items;
using Moon_Items.Items;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "Moon Items", "0.2.1", "Threydan", null)]
[assembly: MelonGame("Buried Things", "Cursed Words")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Moon_Items")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0b3c61f11714742475d48806c53817c240788549")]
[assembly: AssemblyProduct("Moon_Items")]
[assembly: AssemblyTitle("Moon_Items")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 Moon_Items
{
	public class Core : MelonMod
	{
		public static Dictionary<string, Sprite> ItemSprites = new Dictionary<string, Sprite>();

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("[MoonItems] Initialized.");
		}

		public override void OnApplicationStart()
		{
			string text = Path.Combine(new string[2]
			{
				Application.dataPath,
				"../Mods/moonsprites"
			});
			string text2 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/moonsprites";
			AssetBundle val = AssetBundle.LoadFromFile(text) ?? AssetBundle.LoadFromFile(text2);
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Warning("[MoonItems] We couldn't find the item bundle from " + text + " or " + text2);
				return;
			}
			MelonLogger.Msg("[MoonItems] item bundle found, retrieving sprites!");
			Object[] array = val.LoadAllAssets();
			Object[] array2 = array;
			foreach (Object val2 in array2)
			{
				if (((object)val2).GetType() == typeof(Sprite))
				{
					MelonLogger.Msg("[MoonItems] Sprite with name " + val2.name + " found!");
					ItemSprites[val2.name] = (Sprite)(object)((val2 is Sprite) ? val2 : null);
				}
				else
				{
					MelonLogger.Msg("[MoonItems] item not understood, item name: " + val2.name);
				}
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	[HarmonyPatch(new Type[] { })]
	internal static class Assembly_GetTypes_Patch
	{
		private static void Postfix(Assembly __instance, ref Type[] __result)
		{
			if (__instance.GetName().Name == "Assembly-CSharp")
			{
				Type[] array = __result;
				Type[] types = Assembly.GetAssembly(typeof(HalfMoon)).GetTypes();
				int num = 0;
				Type[] array2 = new Type[array.Length + types.Length];
				ReadOnlySpan<Type> readOnlySpan = new ReadOnlySpan<Type>(array);
				readOnlySpan.CopyTo(new Span<Type>(array2).Slice(num, readOnlySpan.Length));
				num += readOnlySpan.Length;
				ReadOnlySpan<Type> readOnlySpan2 = new ReadOnlySpan<Type>(types);
				readOnlySpan2.CopyTo(new Span<Type>(array2).Slice(num, readOnlySpan2.Length));
				num += readOnlySpan2.Length;
				__result = array2;
			}
		}
	}
	[HarmonyPatch(typeof(ConsoleController), "GiveItem", new Type[] { typeof(string[]) })]
	public static class AddItemsToConsolePool_Patch
	{
		public static void Prefix(ref string[] args)
		{
			if (args.Length == 1)
			{
				return;
			}
			Type type = Type.GetType(args[1]);
			if (!(type == null))
			{
				return;
			}
			MelonLogger.Msg("Can't find item in the game, checking modded items");
			List<Item> list = new List<Item>
			{
				(Item)(object)new HalfMoon(),
				(Item)(object)new SmilingMoon(),
				(Item)(object)new CrescentMoon()
			};
			string argument = args[1];
			if (list.Exists((Item item) => ((object)item).GetType().ToString().Split('.')
				.Last() == argument))
			{
				MelonLogger.Msg("Modded item found");
				type = ((object)((IEnumerable<Item>)list).FirstOrDefault((Func<Item, bool>)((Item item) => ((object)item).GetType().ToString().Split('.')
					.Last() == argument))).GetType();
				if (type != null && type.IsSubclassOf(typeof(Item)))
				{
					object? obj = Activator.CreateInstance(type);
					Item val = (Item)((obj is Item) ? obj : null);
					if (args.Length >= 3 && (args[2] == "-f" || args[2] == "-foil"))
					{
						val.IsFoil = true;
					}
					GameStatics.GetPlayer().AddItemToInventory(val);
					CharacterInfoPanel.SingletonInventoryVisualController.PopulateAll();
					MelonLogger.Msg("Gave Item: " + val.Name);
				}
			}
			else
			{
				MelonLogger.Msg("Item Not Found Even In Modded Items");
			}
		}
	}
	[HarmonyPatch(typeof(ItemSpriteData), "GetSprite")]
	internal static class ItemSpriteData_GetSprite_Patch
	{
		private static void Prefix(ItemSpriteData __instance)
		{
			if (__instance.AssetPath.IndexOf("[MoonItems]") != -1)
			{
				try
				{
					__instance.ItemSprite = Core.ItemSprites[__instance.AssetPath.Substring(11)];
				}
				catch
				{
					MelonLogger.Msg("[MoonItems] Couldn't find the item asset \"" + __instance.AssetPath.Substring(11) + "\". Defaulting to a full moon sprite");
					__instance.AssetPath = "FullMoon";
				}
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class GridUtilitySingleton_GetValidNextTiles_patch
	{
		private static void Postfix(List<TileSelection> __result, GridData gridData, List<Tile> currentTiles, TileSelectionManager tileSelectionManager, bool noInventory)
		{
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Expected O, but got Unknown
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Expected O, but got Unknown
			if (currentTiles.Count() == 0)
			{
				return;
			}
			List<Tile> list = currentTiles;
			Tile val = list[list.Count - 1];
			Player player = GameStatics.GetPlayer();
			List<Item> list2 = (noInventory ? new List<Item>() : player.GetAllItems(false));
			Item val2 = list2.Find((Item item4) => item4 is RandomAccessMemory);
			Item val3 = list2.Find((Item item4) => item4 is Snapshot);
			List<Item> list3 = list2.Where((Item item4) => item4 is Frankenstein).ToList();
			if (val2 != null)
			{
				RandomAccessMemory val4 = (RandomAccessMemory)(object)((val2 is RandomAccessMemory) ? val2 : null);
				list2.AddRange(val4.ItemsInMemory);
			}
			if (val3 != null)
			{
				Snapshot val5 = (Snapshot)(object)((val3 is Snapshot) ? val3 : null);
				if (val5.SnapshottedItem != null)
				{
					list2.Add(val5.SnapshottedItem);
				}
			}
			foreach (Item item in list3)
			{
				Frankenstein val6 = (Frankenstein)(object)((item is Frankenstein) ? item : null);
				list2.AddRange(val6.StitchedItems);
			}
			if (list2.Exists((Item item4) => item4 is HalfMoon))
			{
				Tile tile = gridData.GetAvailableTileAtCoordinates(((Vector2Int)(ref gridData.Dimensions)).x - 1 - ((Vector2Int)(ref val.Coordinates)).x, ((Vector2Int)(ref gridData.Dimensions)).y - 1 - ((Vector2Int)(ref val.Coordinates)).y);
				if (tile != null && !currentTiles.Exists((Tile val8) => val8 == tile))
				{
					__result.Add(new TileSelection(tile, (TileSelectionMethod)3, tile.IsDisplayingAsVariableLetter(tileSelectionManager), (Tile)null, 0));
				}
			}
			if (list2.Exists((Item item4) => item4 is SmilingMoon))
			{
				SmilingMoon smilingMoon = ((IEnumerable<Item>)list2).FirstOrDefault((Func<Item, bool>)((Item item4) => item4 is SmilingMoon)) as SmilingMoon;
				Vector2Int val7 = smilingMoon.RandomTiles[((Vector2Int)(ref val.Coordinates)).x][((Vector2Int)(ref val.Coordinates)).y];
				int x = ((Vector2Int)(ref val7)).x;
				val7 = smilingMoon.RandomTiles[((Vector2Int)(ref val.Coordinates)).x][((Vector2Int)(ref val.Coordinates)).y];
				Tile availableTileAtCoordinates = gridData.GetAvailableTileAtCoordinates(x, ((Vector2Int)(ref val7)).y);
				if (availableTileAtCoordinates != null && !currentTiles.Contains(availableTileAtCoordinates))
				{
					__result.Add(new TileSelection(availableTileAtCoordinates, (TileSelectionMethod)3, availableTileAtCoordinates.IsDisplayingAsVariableLetter(tileSelectionManager), (Tile)null, 0));
				}
			}
			if (list2.Exists((Item item4) => item4 is CrescentMoon))
			{
				List<Tile> source = new List<Tile>
				{
					gridData.GetAvailableTileAtCoordinates(0, 0),
					gridData.GetAvailableTileAtCoordinates(0, ((Vector2Int)(ref gridData.Dimensions)).y - 1),
					gridData.GetAvailableTileAtCoordinates(((Vector2Int)(ref gridData.Dimensions)).x - 1, 0),
					gridData.GetAvailableTileAtCoordinates(((Vector2Int)(ref gridData.Dimensions)).x - 1, ((Vector2Int)(ref gridData.Dimensions)).y - 1)
				};
				__result.AddRange(source.Where((Tile val8) => val8 != null && !currentTiles.Contains(val8)).Select((Func<Tile, TileSelection>)((Tile val8) => new TileSelection(val8, (TileSelectionMethod)3, val8.IsDisplayingAsVariableLetter(tileSelectionManager), (Tile)null, 0))));
			}
		}
	}
}
namespace Moon_Items.Items
{
	internal class CrescentMoon : Item
	{
		public CrescentMoon()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			base.Name = "Crescent Moon";
			base.SpriteData.Add(new ItemSpriteData((ItemSpriteUsage)0, "[MoonItems]CrescentMoon"));
			base.Rarity = (ItemRarity)1;
			base.Tags = new List<ItemTag> { (ItemTag)15 };
			base.ItemFunctionTags = new List<ItemFunctionTag> { (ItemFunctionTag)5 };
			base.Cost = 11;
		}

		public override string GetDescription()
		{
			return "You can teleport to the corners at any time";
		}
	}
	internal class HalfMoon : Item
	{
		public HalfMoon()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			base.Name = "Half Moon";
			base.SpriteData.Add(new ItemSpriteData((ItemSpriteUsage)0, "[MoonItems]HalfMoon"));
			base.Rarity = (ItemRarity)0;
			base.Tags = new List<ItemTag> { (ItemTag)15 };
			base.ItemFunctionTags = new List<ItemFunctionTag> { (ItemFunctionTag)5 };
			base.Cost = 15;
		}

		public override string GetDescription()
		{
			return "You can teleport to the tile opposite on the board";
		}
	}
	internal class SmilingMoon : Item
	{
		public List<List<Vector2Int>> RandomTiles = new List<List<Vector2Int>>();

		public SmilingMoon()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			base.Name = "Smiling Moon";
			base.SpriteData.Add(new ItemSpriteData((ItemSpriteUsage)0, "[MoonItems]SmilingMoon"));
			base.Rarity = (ItemRarity)1;
			base.Tags = new List<ItemTag> { (ItemTag)15 };
			base.ItemFunctionTags = new List<ItemFunctionTag> { (ItemFunctionTag)5 };
			base.Cost = 10;
		}

		public override string GetDescription()
		{
			return "You can Teleport randomly across the board (predetermined for each grid)";
		}

		public override GridData ApplyStartOfGridEffect(GridData gridData, int gridNumber, int numberOfGrids, List<HistoricWord> previousWords, List<BoardGenVizInfo> vizSteps, bool isReroll)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			bool flag = GameStatics.GetPlayer().CurrentRunProgress.Challenge?.ChallengeName == "Call Of The Void";
			Vector2Int value = default(Vector2Int);
			for (int i = 0; i < ((Vector2Int)(ref gridData.Dimensions)).x; i++)
			{
				for (int j = 0; j < ((Vector2Int)(ref gridData.Dimensions)).y; j++)
				{
					((Vector2Int)(ref value))..ctor(Random.Range(0, ((Vector2Int)(ref gridData.Dimensions)).x), Random.Range(0, ((Vector2Int)(ref gridData.Dimensions)).y));
					if (flag)
					{
						int num = ((!Convert.ToBoolean(Random.Range(0, 2))) ? 5 : 0);
						if (Convert.ToBoolean(Random.Range(0, 2)))
						{
							((Vector2Int)(ref value)).x = num;
						}
						else
						{
							((Vector2Int)(ref value)).y = num;
						}
					}
					RandomTiles[i][j] = value;
				}
			}
			return gridData;
		}

		public override void OnAcquire()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 6; i++)
			{
				RandomTiles.Add(new List<Vector2Int>());
				for (int j = 0; j < 6; j++)
				{
					RandomTiles[i].Add(default(Vector2Int));
				}
			}
		}
	}
}