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.Logging; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Collections.Generic; using MonoMod.Utils; [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("PAMultiplayer.Preloader")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+2449a663dd6a8aa20bf6670ef118ae704f14f34d")] [assembly: AssemblyProduct("PAMultiplayer.Preloader")] [assembly: AssemblyTitle("PAMultiplayer.Preloader")] [assembly: AssemblyVersion("1.0.0.0")] namespace PAMultiplayer.Preloader; public static class Patcher { public static IEnumerable TargetDLLs { get; } = new string[2] { "Facepunch.Steamworks.Win64.dll", "DiscordRPC.dll" }; public static void Patch(ref AssemblyDefinition assembly) { string name = ((AssemblyNameReference)assembly.Name).Name; if (!(name == "DiscordRPC")) { if (name == "Facepunch.Steamworks.Win64") { assembly = AssemblyDefinition.ReadAssembly(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Facepunch.Steamworks.Win64.dll"); PatchFacepunch(assembly); } } else { assembly = AssemblyDefinition.ReadAssembly(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\DiscordRPC.dll"); } } private static void PatchFacepunch(AssemblyDefinition assembly) { //IL_002b: 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) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) ManualLogSource val = Logger.CreateLogSource("me.ytarame.multiplayer.preloader2"); try { string name = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\steam_api64.dll"; Enumerator enumerator = assembly.Modules.GetEnumerator(); try { while (enumerator.MoveNext()) { Enumerator enumerator2 = enumerator.Current.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { Enumerator enumerator3 = enumerator2.Current.Methods.GetEnumerator(); try { while (enumerator3.MoveNext()) { MethodDefinition current = enumerator3.Current; if (current.IsPInvokeImpl && current.PInvokeInfo != null && !(current.PInvokeInfo.Module.Name != "steam_api64")) { val.LogInfo((object)"Found steam_api64 import"); current.PInvokeInfo.Module.Name = name; break; } } } finally { ((IDisposable)enumerator3).Dispose(); } } } finally { ((IDisposable)enumerator2).Dispose(); } } } finally { ((IDisposable)enumerator).Dispose(); } TypeDefinition type = assembly.MainModule.GetType("Steamworks.Ugc.Editor"); MethodDefinition val2 = ((IEnumerable)type.Methods).First((MethodDefinition m) => ((MemberReference)m).Name == "SubmitAsync"); MethodDefinition val3 = Extensions.Clone(val2, (MethodDefinition)null); val3.Body.Instructions.Clear(); ((MethodReference)val3).Parameters.RemoveAt(1); ILProcessor iLProcessor = val3.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_1); iLProcessor.Emit(OpCodes.Ldnull); iLProcessor.Emit(OpCodes.Call, assembly.MainModule.ImportReference((MethodReference)(object)val2)); iLProcessor.Emit(OpCodes.Ret); type.Methods.Add(val3); } finally { ((IDisposable)val)?.Dispose(); } } }