From 80e337e5e5f3ddbd09157ac807edbfb9def62dbe Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 11 Feb 2022 21:23:32 -0800 Subject: [PATCH] proxy scripts: call base.ctor to init fields --- ProxyInjector/Program.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ProxyInjector/Program.cs b/ProxyInjector/Program.cs index a04060a0..d3e0591b 100644 --- a/ProxyInjector/Program.cs +++ b/ProxyInjector/Program.cs @@ -1,8 +1,10 @@ using Mono.Cecil; +using Mono.Cecil.Cil; using MonoMod.Utils; using System; using System.Diagnostics; using System.IO; +using System.Linq; using UnityEngine; namespace ProxyInjector @@ -37,6 +39,15 @@ namespace ProxyInjector } var proxyTd = new TypeDefinition(td.Namespace, "PROXY_" + td.Name, td.Attributes, qsbModule.ImportReference(td)); + + var ctor = td.Methods.First(md => md.Name == ".ctor" && !md.HasParameters); + var proxyCtor = new MethodDefinition(ctor.Name, ctor.Attributes, qsbModule.ImportReference(ctor.ReturnType)); + proxyCtor.Body = new MethodBody(proxyCtor); + proxyCtor.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0)); + proxyCtor.Body.Instructions.Add(Instruction.Create(OpCodes.Call, qsbModule.ImportReference(ctor))); + proxyCtor.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); + proxyTd.Methods.Add(proxyCtor); + qsbModule.Types.Add(proxyTd); count++; }