Decompiled source of CursedWilds v1.0.0

CursedWilds.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using CursedWilds;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
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), "Cursed Wilds", "1.2.0", "Neptune6866", null)]
[assembly: MelonGame("Buried Things", "Cursed Words")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RandomWildcards")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RandomWildcards")]
[assembly: AssemblyTitle("RandomWildcards")]
[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]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 CursedWilds
{
	public class Core : MelonMod
	{
		[CompilerGenerated]
		private sealed class <ReloadAfterDelay>d__8 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Core <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ReloadAfterDelay>d__8(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(0.25f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.LoadSymbols();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static List<string> BlankSymbols = new List<string>();

		private static FileSystemWatcher watcher;

		private static string SymbolFilePath => Path.Combine(MelonEnvironment.UserDataDirectory, "CursedWildsSymbols.txt");

		public override void OnInitializeMelon()
		{
			LoadSymbols();
			SetupWatcher();
		}

		private void LoadSymbols()
		{
			try
			{
				if (!File.Exists(SymbolFilePath))
				{
					MelonLogger.Msg("Symbol file missing — creating default one.");
					File.WriteAllLines(SymbolFilePath, new string[11]
					{
						"!", "@", "#", "$", "%", "^", "&", "*", "?", "/",
						"¬"
					});
				}
				List<string> list = new List<string>();
				string[] array = File.ReadAllLines(SymbolFilePath);
				foreach (string text in array)
				{
					string text2 = text.Trim();
					if (!string.IsNullOrEmpty(text2))
					{
						list.Add(text2);
					}
				}
				if (list.Count == 0)
				{
					MelonLogger.Warning("Symbol list empty — using fallback defaults.");
					list.AddRange(new string[11]
					{
						"!", "@", "#", "$", "%", "^", "&", "*", "?", "/",
						"¬"
					});
				}
				BlankSymbols = list;
				MelonLogger.Msg($"Loaded {BlankSymbols.Count} blank symbols.");
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Failed to load symbol file: {arg}");
			}
		}

		private void SetupWatcher()
		{
			watcher = new FileSystemWatcher(Path.GetDirectoryName(SymbolFilePath), Path.GetFileName(SymbolFilePath));
			watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite;
			watcher.Changed += OnSymbolFileChanged;
			watcher.Created += OnSymbolFileChanged;
			watcher.Renamed += OnSymbolFileChanged;
			watcher.EnableRaisingEvents = true;
		}

		private void OnSymbolFileChanged(object sender, FileSystemEventArgs e)
		{
			MelonLogger.Msg("Symbol file changed — reloading...");
			MelonCoroutines.Start(ReloadAfterDelay());
		}

		[IteratorStateMachine(typeof(<ReloadAfterDelay>d__8))]
		private IEnumerator ReloadAfterDelay()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ReloadAfterDelay>d__8(0)
			{
				<>4__this = this
			};
		}
	}
	[HarmonyPatch(typeof(Tile), "GetStringRepresentation")]
	public static class BlankSymbolPatch
	{
		private static Dictionary<Tile, string> tileSymbols = new Dictionary<Tile, string>();

		private static bool Prefix(Tile __instance, bool forWordValidity, ref string __result)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			if ((int)__instance.GetGlyphType() == 0 && !forWordValidity)
			{
				if (!tileSymbols.TryGetValue(__instance, out var value))
				{
					if (Core.BlankSymbols.Count == 0)
					{
						return true;
					}
					value = Core.BlankSymbols[Random.Range(0, Core.BlankSymbols.Count)];
					tileSymbols[__instance] = value;
				}
				__result = value;
				return false;
			}
			return true;
		}
	}
}