TitleScenePlugin.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Mono.Cecil;
  7. using Mono.Cecil.Cil;
  8. namespace BepInEx.Patcher.Internal
  9. {
  10. public class TitleScenePlugin : IPatchPlugin
  11. {
  12. public void Patch(AssemblyDefinition assembly)
  13. {
  14. TypeDefinition CustomTrialTitle = assembly.MainModule.Types.First(x => x.Name == "CustomTrialTitle");
  15. var enter = CustomTrialTitle.Methods.First(x => x.Name == "Enter");
  16. var IL = enter.Body.GetILProcessor();
  17. //IL.Replace(enter.Body.Instructions[32], IL.Create(OpCodes.Ldstr, "Title"));
  18. IL.Replace(enter.Body.Instructions[15], IL.Create(OpCodes.Ldstr, "Title"));
  19. var lambda = (MethodDefinition)enter.Body.Instructions[45].Operand;
  20. var onCustom = CustomTrialTitle.Methods.First(x => x.Name == "OnCustom");
  21. onCustom.Body.Instructions[1].Operand = "Title";
  22. IL = lambda.Body.GetILProcessor();
  23. var method = (GenericInstanceMethod)lambda.Body.Instructions[2].Operand;
  24. method.GenericArguments[0] = assembly.MainModule.Types.First(x => x.Name == "TitleScene");
  25. //IL.Remove(lambda.Body.Instructions[1]);
  26. //IL.Remove(lambda.Body.Instructions[0]);
  27. //IL.InsertBefore(lambda.Body.Instructions[0], IL.Create(OpCodes.Ldstr, "Title"));
  28. }
  29. }
  30. }