Title screen patch

This commit is contained in:
Bepis committed 2018-02-11 14:18:15 +11:00
1 parent 02c58db9bb
commit bb7f7de4e4
5 files changed
+97 -10

No files matched your search

+1
View File
@@ -54,6 +54,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Internal\TitleScenePlugin.cs" />
<Compile Include="Internal\ExitScenePlugin.cs" />
<Compile Include="Internal\SliderPlugin.cs" />
<Compile Include="IPatchPlugin.cs" />
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace BepInEx.Patcher.Internal
{
public class TitleScenePlugin : IPatchPlugin
{
public void Patch(AssemblyDefinition assembly)
{
TypeDefinition CustomTrialTitle = assembly.MainModule.Types.First(x => x.Name == "CustomTrialTitle");
var enter = CustomTrialTitle.Methods.First(x => x.Name == "Enter");
var IL = enter.Body.GetILProcessor();
//IL.Replace(enter.Body.Instructions[32], IL.Create(OpCodes.Ldstr, "Title"));
IL.Replace(enter.Body.Instructions[15], IL.Create(OpCodes.Ldstr, "Title"));
var lambda = (MethodDefinition)enter.Body.Instructions[45].Operand;
var onCustom = CustomTrialTitle.Methods.First(x => x.Name == "OnCustom");
onCustom.Body.Instructions[1].Operand = "Title";
IL = lambda.Body.GetILProcessor();
var method = (GenericInstanceMethod)lambda.Body.Instructions[2].Operand;
method.GenericArguments[0] = assembly.MainModule.Types.First(x => x.Name == "TitleScene");
//IL.Remove(lambda.Body.Instructions[1]);
//IL.Remove(lambda.Body.Instructions[0]);
//IL.InsertBefore(lambda.Body.Instructions[0], IL.Create(OpCodes.Ldstr, "Title"));
}
}
}
+32 -4
View File
@@ -46,17 +46,22 @@ namespace BepInEx.Patcher
IPatchPlugin slider = new SliderPlugin();
slider.Patch(assembly);
IPatchPlugin title = new TitleScenePlugin();
title.Patch(assembly);
InjectAssembly(unity, injected);
InjectAssembly(assembly, unity, injected);
assembly.Write(outputDLL);
unity.Write(unityOutputDLL);
}
static void InjectAssembly(AssemblyDefinition unity, AssemblyDefinition injected)
static void InjectAssembly(AssemblyDefinition assembly, AssemblyDefinition unity, AssemblyDefinition injected)
{
//unity.MainModule.AssemblyReferences.Add(new AssemblyNameReference(injected.Name, injected.MainModule.v);
ILProcessor IL;
//Initialize
var originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Target").Methods.First(x => x.Name == "Initialize");
var injectMethod = unity.MainModule.Import(originalInjectMethod);
@@ -65,10 +70,33 @@ namespace BepInEx.Patcher
foreach (var loadScene in sceneManager.Methods.Where(x => x.Name == "LoadScene"))
{
var IL = loadScene.Body.GetILProcessor();
IL = loadScene.Body.GetILProcessor();
IL.InsertBefore(loadScene.Body.Instructions[0], IL.Create(OpCodes.Call, injectMethod));
}
//CustomInitializer
originalInjectMethod = injected.MainModule.Types.First(x => x.Name == "Target").Methods.First(x => x.Name == "InitializeCustomBase");
injectMethod = assembly.MainModule.Import(originalInjectMethod);
var customControl = assembly.MainModule.Types.First(x => x.Name == "CustomControl");
var customInitialize = customControl.Methods.First(x => x.Name == "Initialize");
IL = customInitialize.Body.GetILProcessor();
//IL.Replace(customInitialize.Body.Instructions[169], IL.Create(OpCodes.Call, customControl.Properties[4].GetMethod));
//IL.Append(IL.Create(OpCodes.Call, injectMethod));
IL.Replace(customInitialize.Body.Instructions[169], IL.Create(OpCodes.Call, injectMethod));
customInitialize.Body.Instructions[169].Offset = 0x01f0;
IL.Append(IL.Create(OpCodes.Ret));
//injected.MainModule.Import(assembly.MainModule.Types.First(x => x.Name == "CustomBase"));
}
}
}
+6 -4
View File
@@ -36,8 +36,9 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>M:\koikatu\KoikatuTrial_Data\Managed\Assembly-CSharp.dll</HintPath>
<Reference Include="Assembly-CSharp-original, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>M:\koikatu\KoikatuTrial_Data\Managed\Assembly-CSharp-original.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net20\Newtonsoft.Json.dll</HintPath>
@@ -46,8 +47,9 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>M:\koikatu\KoikatuTrial_Data\Managed\UnityEngine.dll</HintPath>
<Reference Include="UnityEngine-original, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>M:\koikatu\KoikatuTrial_Data\Managed\UnityEngine-original.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
+18 -2
View File
@@ -1,4 +1,5 @@
using System;
using ChaCustom;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -14,9 +15,24 @@ namespace BepInEx
if (loaded)
return;
UnityEngine.Debug.logger.LogWarning("inject", "Loaded!!!");
UnityEngine.Debug.logger.Log("inject: Loaded!!!");
loaded = true;
}
public static void InitializeCustomBase() //CustomBase customBase
{
UnityEngine.Debug.logger.Log("inject: CustomBase loaded!!!");
CustomBase customBase = Singleton<CustomBase>.Instance;
foreach (var entry in customBase.lstSelectList)
{
UnityEngine.Debug.Log(entry.list[2]);
entry.list[2] = "TL TEST TL TEST";
}
}
}
}