using System; using System.CodeDom.Compiler; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ModMogulFix")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ModMogulFix")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("8aeb57fa-48f1-4f43-9a83-5dc16f57da6b")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] internal static class ModInfo { internal const string PLUGIN_GUID = "com.maxgerman.modmogulfix"; internal const string PLUGIN_NAME = "Mod Mogul Fix"; internal const string PLUGIN_VERSION = "1.0.0"; internal const string ASSEMBLY_VERSION = "1.0.0"; internal const string FILE_VERSION = "1.0.0"; internal const string INFORMATIONAL_VERSION = "1.0.0"; internal const string HARMONY_ID = "com.maxgerman.modmogulfix"; internal const string LOG_PREFIX = "[ModMogulFix] "; internal const string DISPLAY_NAME_SHORT = "ModMogulFix"; internal const string DISPLAY_NAME_LONG = "Mod Mogul Fix"; } internal static class ModLog { private static readonly ManualLogSource _bepInExLogger = Logger.CreateLogSource("Mod Mogul Fix"); internal static void Log(string message, string tag = "") { _bepInExLogger.LogMessage((object)FormatMessage(message, tag)); } internal static void Warn(string message, string tag = "") { _bepInExLogger.LogWarning((object)FormatMessage(message, tag)); } internal static void Error(string message, string tag = "") { _bepInExLogger.LogError((object)FormatMessage(message, tag)); } private static string FormatMessage(string message, string tag) { if (string.IsNullOrEmpty(tag)) { return message; } return "[" + tag + "] " + message; } } internal class Tools { public static string FindPluginFolder(string pluginDllName) { string pluginPath = Paths.PluginPath; if (!pluginDllName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { pluginDllName += ".dll"; } string[] files = Directory.GetFiles(pluginPath, pluginDllName, SearchOption.AllDirectories); if (files.Length == 0) { return null; } return Path.GetDirectoryName(files[0]); } public static string FindPluginFolder() { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } public static bool ExtractAsset(string resourceName, string targetFile) { try { using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { string directoryName = Path.GetDirectoryName(targetFile); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } using FileStream destination = File.Create(targetFile); stream.CopyTo(destination); } return File.Exists(targetFile); } catch (Exception) { ModLog.Warn("ERROR: Mod not fixed"); return false; } } } namespace ModMogulFix { [BepInPlugin("com.maxgerman.modmogulfix", "Mod Mogul Fix", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class ModMogulFix : BaseUnityPlugin { private void Awake() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) string text = Tools.FindPluginFolder("ModMogul"); string text2 = "modmogul.assets"; if (text != null) { if (Directory.GetFiles(text, text2, SearchOption.AllDirectories).Length == 0) { string text3 = Path.Combine(text, "ModMogul"); string targetFile = Path.Combine(text3, text2); string targetFile2 = Path.Combine(text, text2); string resourceName = "ModMogulFix.Assets.modmogul.assets"; if (Directory.Exists(text3)) { Tools.ExtractAsset(resourceName, targetFile); } else { Tools.ExtractAsset(resourceName, targetFile2); } ModLog.Log("ModMogul fixed successfully"); } else { ModLog.Log("ModMogul already fixed"); } } new Harmony("com.maxgerman.modmogulfix").PatchAll(Assembly.GetExecutingAssembly()); } } [HarmonyPatch] public class BepInExPathPatch { private static MethodBase TargetMethod() { return AccessTools.PropertyGetter(typeof(Paths), "PluginPath"); } private static bool Prefix(ref string __result) { StackTrace stackTrace = new StackTrace(); for (int i = 1; i < stackTrace.FrameCount; i++) { Type type = stackTrace.GetFrame(i).GetMethod()?.DeclaringType; if (!(type != null)) { continue; } string name = type.Assembly.GetName().Name; if (name == null || !name.ToLower().Contains("modmogul")) { continue; } string directoryName = Path.GetDirectoryName(type.Assembly.Location); string text = Path.Combine(directoryName, "ModMogul"); if (!Directory.Exists(text)) { Directory.CreateDirectory(text); string[] array = new string[2] { "modmogul.assets", "ModMogul_Logo.png" }; foreach (string path in array) { string text2 = Path.Combine(directoryName, path); string destFileName = Path.Combine(text, path); if (File.Exists(text2)) { File.Move(text2, destFileName); } } } __result = Path.Combine(text, ".."); return false; } return true; } } } namespace ModMogulFix.Properties { [GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")] [DebuggerNonUserCode] [CompilerGenerated] internal class Resources { private static ResourceManager resourceMan; private static CultureInfo resourceCulture; [EditorBrowsable(EditorBrowsableState.Advanced)] internal static ResourceManager ResourceManager { get { if (resourceMan == null) { resourceMan = new ResourceManager("ModMogulFix.Properties.Resources", typeof(Resources).Assembly); } return resourceMan; } } [EditorBrowsable(EditorBrowsableState.Advanced)] internal static CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } internal Resources() { } } }