Decompiled source of YuGiOhCards v1.0.1

BepInEx/patchers/YuGiOhContentExtractor/YuGiOhContentExtractor.dll

Decompiled 3 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 BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Mono.Cecil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("YuGiOhContentExtractor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("YuGiOhContentExtractor")]
[assembly: AssemblyTitle("YuGiOhContentExtractor")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 YuGiOhContentExtractor
{
	public static class Patcher
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("YuGiOhContentExtractor");

		public static IEnumerable<string> TargetDLLs => new string[0];

		public static void Patch(AssemblyDefinition assembly)
		{
		}

		public static void Initialize()
		{
			try
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				string text = Path.Combine(directoryName, "Content");
				if (!Directory.Exists(text))
				{
					Log.LogWarning((object)("Bundled Content folder not found next to patcher (" + text + "); nothing to extract."));
					return;
				}
				DirectoryInfo directoryInfo = new DirectoryInfo(directoryName);
				while (directoryInfo != null && !directoryInfo.Name.Equals("BepInEx", StringComparison.OrdinalIgnoreCase))
				{
					directoryInfo = directoryInfo.Parent;
				}
				if (directoryInfo == null)
				{
					Log.LogError((object)("Could not locate the BepInEx root from " + directoryName));
					return;
				}
				string text2 = Path.Combine(directoryInfo.FullName, "plugins");
				if (!Directory.Exists(text2))
				{
					Log.LogError((object)("plugins folder not found at " + text2));
					return;
				}
				string text3 = null;
				string[] files = Directory.GetFiles(text2, "LethalCardLoader.dll", SearchOption.AllDirectories);
				int num = 0;
				if (num < files.Length)
				{
					text3 = Path.GetDirectoryName(files[num]);
				}
				if (text3 == null)
				{
					Log.LogError((object)("LethalCardLoader.dll not found under " + text2 + " — is the dependency installed?"));
					return;
				}
				string text4 = Path.Combine(text3, "Content");
				int num2 = CopyDir(text, text4);
				Log.LogInfo((object)("Extracted Yu-Gi-Oh! content (" + num2 + " files) into " + text4));
				EnsureSetRegistered(directoryInfo.FullName);
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Yu-Gi-Oh! content extraction failed: " + ex));
			}
		}

		private static void EnsureSetRegistered(string bepinexRoot)
		{
			try
			{
				string text = Path.Combine(bepinexRoot, "config");
				Directory.CreateDirectory(text);
				string text2 = Path.Combine(text, "com.sholiver.lethalcardloader.cfg");
				string text3 = (File.Exists(text2) ? File.ReadAllText(text2) : "");
				if (text3.IndexOf("Key = YuGiOh", StringComparison.OrdinalIgnoreCase) >= 0 || text3.IndexOf("[Set: Yu-Gi-Oh!]", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					Log.LogInfo((object)"Yu-Gi-Oh! set already registered in LethalCardLoader config.");
					return;
				}
				string newLine = Environment.NewLine;
				string text4 = "[Set: Yu-Gi-Oh!]" + newLine + "Name = Yu-Gi-Oh!" + newLine + "Key = YuGiOh" + newLine + "Id = 200" + newLine + "Spawn Group = Default" + newLine;
				string text5 = ((text3.Length == 0) ? "" : (text3.EndsWith("\n") ? newLine : (newLine + newLine)));
				File.AppendAllText(text2, text5 + text4);
				Log.LogInfo((object)("Registered Yu-Gi-Oh! set in LethalCardLoader config: " + text2));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to register Yu-Gi-Oh! set in config: " + ex));
			}
		}

		private static int CopyDir(string src, string dst)
		{
			Directory.CreateDirectory(dst);
			int num = 0;
			string[] files = Directory.GetFiles(src);
			foreach (string text in files)
			{
				File.Copy(text, Path.Combine(dst, Path.GetFileName(text)), overwrite: true);
				num++;
			}
			files = Directory.GetDirectories(src);
			foreach (string text2 in files)
			{
				num += CopyDir(text2, Path.Combine(dst, Path.GetFileName(text2)));
			}
			return num;
		}
	}
}