Skip to content

Commit

Permalink
Run HookGen on tML rather than vanilla
Browse files Browse the repository at this point in the history
  • Loading branch information
Chicken-Bones committed Dec 24, 2019
1 parent 203f5e8 commit be2c202
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 9 deletions.
Binary file modified references/TerrariaHooks.FNA.dll
Binary file not shown.
Binary file modified references/TerrariaHooks.XNA.dll
Binary file not shown.
15 changes: 12 additions & 3 deletions setup/HookGenWrapper/HookGenWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Mono.Cecil;
using MonoMod;
using MonoMod.RuntimeDetour.HookGen;
using System;
using System.IO;
using XnaToFna;

Expand All @@ -23,15 +24,23 @@ public static void HookGen(string inputPath, string outputPath, string refsDir)
mm.Read();
mm.MapDependencies();
mm.DependencyCache["MonoMod.RuntimeDetour"] = ModuleDefinition.ReadModule(Path.Combine(refsDir, "MonoMod.RuntimeDetour.dll"));

HookGenerator gen = new HookGenerator(mm, "TerrariaHooks") {
mm.DependencyCache["MonoMod.Utils"] = ModuleDefinition.ReadModule(Path.Combine(refsDir, "MonoMod.Utils.dll"));

HookGenerator gen = new HookGenerator(mm, "TerrariaHooks") {
HookPrivate = true,
};
gen.Generate();
gen.OutputModule.Write(outputPath);
RemoveModLoaderTypes(gen.OutputModule);
gen.OutputModule.Write(outputPath);
}
}

private static void RemoveModLoaderTypes(ModuleDefinition module) {
for (int i = module.Types.Count-1; i >= 0; i--)
if (module.Types[i].FullName.Contains("Terraria.ModLoader"))
module.Types.RemoveAt(i);
}

public static void XnaToFna(string inputPath, string refsDir)
{
using (var xnaToFnaUtil = new XnaToFnaUtil {
Expand Down
4 changes: 4 additions & 0 deletions setup/HookGenWrapper/HookGenWrapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
<ItemGroup>
<Reference Include="Mono.Cecil">
<HintPath>..\..\references\Mono.Cecil.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MonoMod">
<HintPath>..\lib\MonoMod.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MonoMod.RuntimeDetour.HookGen">
<HintPath>..\lib\MonoMod.RuntimeDetour.HookGen.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -43,6 +46,7 @@
<Reference Include="System.Xml" />
<Reference Include="XnaToFna">
<HintPath>..\lib\XnaToFna.exe</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
26 changes: 20 additions & 6 deletions setup/Setup/HookGenTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.IO;
using System.Windows;
using static Terraria.ModLoader.Setup.Program;

namespace Terraria.ModLoader.Setup
{
Expand All @@ -10,24 +12,36 @@ public HookGenTask(ITaskInterface taskInterface) : base(taskInterface)

public override void Run()
{
if (!File.Exists(Program.TerrariaPath))
throw new FileNotFoundException(Program.TerrariaPath);
string targetExePath = Path.Combine(baseDir, @"src\tModLoader\bin\WindowsDebug\net45\Terraria.exe");
if (!File.Exists(targetExePath)) {
var result = MessageBox.Show($"\"{targetExePath}\" does not exist. Use Vanilla exe instead?", "tML exe not found", MessageBoxButton.YesNo);
if (result != MessageBoxResult.Yes) {
taskInterface.SetStatus("Cancelled");
return;
}

if (!File.Exists(TerrariaPath))
throw new FileNotFoundException(TerrariaPath);

targetExePath = TerrariaPath;
}


var outputPath = Path.Combine(Program.ReferencesDir, "TerrariaHooks.XNA.dll");
var outputPath = Path.Combine(ReferencesDir, "TerrariaHooks.XNA.dll");
if (File.Exists(outputPath))
File.Delete(outputPath);

taskInterface.SetStatus($"Hooking: Terraria.exe -> TerrariaHooks.XNA.dll");
HookGenWrapper.HookGenWrapper.HookGen(Program.TerrariaPath, outputPath, Program.ReferencesDir);
HookGenWrapper.HookGenWrapper.HookGen(targetExePath, outputPath, ReferencesDir);

taskInterface.SetStatus($"XnaToFna: TerrariaHooks.XNA.dll -> TerrariaHooks.FNA.dll");

var monoPath = Path.Combine(Program.ReferencesDir, "TerrariaHooks.FNA.dll");
var monoPath = Path.Combine(ReferencesDir, "TerrariaHooks.FNA.dll");
if (File.Exists(monoPath))
File.Delete(monoPath);

File.Copy(outputPath, monoPath);
HookGenWrapper.HookGenWrapper.XnaToFna(monoPath, Program.ReferencesDir);
HookGenWrapper.HookGenWrapper.XnaToFna(monoPath, ReferencesDir);

File.Delete(Path.ChangeExtension(monoPath, "pdb"));
}
Expand Down
Binary file modified setup/bin/HookGenWrapper.dll
Binary file not shown.
Binary file modified setup/bin/setup.exe
Binary file not shown.
Binary file modified setup/bin/setup.pdb
Binary file not shown.
Binary file removed setup/lib/Mono.Cecil.Mdb.dll
Binary file not shown.
Binary file modified setup/lib/MonoMod.RuntimeDetour.HookGen.exe
Binary file not shown.
Binary file modified setup/lib/MonoMod.exe
Binary file not shown.
Binary file modified setup/lib/XnaToFna.exe
Binary file not shown.

0 comments on commit be2c202

Please sign in to comment.