using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Mono.Cecil; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("LCOfficeV81Preloader")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("LCOfficeV81Preloader")] [assembly: AssemblyTitle("LCOfficeV81Preloader")] [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 LCOfficeV81Preloader { public static class Patcher { private static readonly ManualLogSource Log = Logger.CreateLogSource("LCOfficeV81Preloader"); public static IEnumerable TargetDLLs => Array.Empty(); public static void Initialize() { Log.LogInfo((object)"=========================================="); Log.LogInfo((object)"[LCOfficeV81Preloader] Initialize reached."); Log.LogInfo((object)"[LCOfficeV81Preloader] Searching for original LCOffice.dll..."); Log.LogInfo((object)"=========================================="); try { string text = FindOriginalLCOfficeDll(); if (text == null) { Log.LogWarning((object)"[LCOfficeV81Preloader] Could not find LCOffice.dll under BepInEx/plugins."); return; } Log.LogInfo((object)("[LCOfficeV81Preloader] Found LCOffice.dll: " + text)); PatchLCOfficeAssembly(text); } catch (Exception ex) { Log.LogError((object)("[LCOfficeV81Preloader] Fatal patching error:\n" + ex)); } } public static void Patch(AssemblyDefinition assembly) { } private static string FindOriginalLCOfficeDll() { if (!Directory.Exists(Paths.PluginPath)) { return null; } string[] files = Directory.GetFiles(Paths.PluginPath, "LCOffice.dll", SearchOption.AllDirectories); if (files.Length == 0) { return null; } string text = files.FirstOrDefault((string path) => path.IndexOf("LCOfficeCompat", StringComparison.OrdinalIgnoreCase) < 0 && path.IndexOf("V81Compat", StringComparison.OrdinalIgnoreCase) < 0); return text ?? files[0]; } private static void PatchLCOfficeAssembly(string assemblyPath) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Expected O, but got Unknown string text = assemblyPath + ".v81compat.backup"; string text2 = assemblyPath + ".v81compat.tmp"; if (!File.Exists(text)) { File.Copy(assemblyPath, text, overwrite: false); Log.LogInfo((object)("[LCOfficeV81Preloader] Created backup: " + text)); } ReaderParameters val = new ReaderParameters { ReadWrite = false, InMemory = true }; AssemblyDefinition val2 = AssemblyDefinition.ReadAssembly(assemblyPath, val); try { ModuleDefinition mainModule = val2.MainModule; AssemblyNameReference val3 = ((IEnumerable)mainModule.AssemblyReferences).FirstOrDefault((Func)((AssemblyNameReference reference) => string.Equals(reference.Name, "DunGen", StringComparison.OrdinalIgnoreCase))); if (val3 == null) { val3 = new AssemblyNameReference("DunGen", new Version(0, 0, 0, 0)); mainModule.AssemblyReferences.Add(val3); Log.LogInfo((object)"[LCOfficeV81Preloader] Added DunGen assembly reference."); } int num = 0; foreach (TypeReference typeReference in mainModule.GetTypeReferences()) { if (typeReference != null && !string.IsNullOrEmpty(typeReference.Namespace) && typeReference.Namespace.StartsWith("DunGen", StringComparison.Ordinal)) { IMetadataScope scope = typeReference.Scope; AssemblyNameReference val4 = (AssemblyNameReference)(object)((scope is AssemblyNameReference) ? scope : null); if (val4 != null && string.Equals(val4.Name, "Assembly-CSharp", StringComparison.OrdinalIgnoreCase)) { Log.LogInfo((object)("[LCOfficeV81Preloader] Redirecting type reference: " + ((MemberReference)typeReference).FullName + " | Assembly-CSharp -> DunGen")); typeReference.Scope = (IMetadataScope)(object)val3; num++; } } } if (num == 0) { Log.LogWarning((object)"[LCOfficeV81Preloader] No old DunGen type references were found."); Log.LogWarning((object)"[LCOfficeV81Preloader] DLL may already be patched."); return; } if (File.Exists(text2)) { File.Delete(text2); } val2.Write(text2); File.Copy(text2, assemblyPath, overwrite: true); File.Delete(text2); Log.LogInfo((object)("[LCOfficeV81Preloader] Successfully redirected " + num + " DunGen type reference(s).")); Log.LogInfo((object)"[LCOfficeV81Preloader] Local LCOffice.dll patch complete."); } finally { ((IDisposable)val2)?.Dispose(); } } } }