Skip to content

Commit

Permalink
Update Everest and MonoMod, switch to MMHOOK
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade committed May 6, 2018
1 parent 3a965e1 commit c6bc8a5
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 57 deletions.
33 changes: 22 additions & 11 deletions CelesteTAS-EverestInterop/CelesteTAS-EverestInterop.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.6.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.6.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -41,22 +40,38 @@
<HintPath>..\Everest\lib-stripped\FNA.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MMHOOK_Celeste">
<HintPath>..\MMHOOK_Celeste.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.0-beta7\lib\net40\Mono.Cecil.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.0-beta7\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.0-beta7\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MonoMod">
<HintPath>..\Everest\lib\MonoMod.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MonoMod.RuntimeDetour">
<HintPath>..\Everest\lib\MonoMod.RuntimeDetour.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MonoMod.Utils">
<HintPath>..\Everest\lib\MonoMod.Utils.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
Expand All @@ -69,7 +84,6 @@
<Content Include="metadata.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Everest\Celeste.Mod.mm\Celeste.Mod.mm.csproj">
Expand All @@ -78,13 +92,10 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.6.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.6.1\build\Microsoft.Net.Compilers.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
78 changes: 39 additions & 39 deletions CelesteTAS-EverestInterop/CelesteTASModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
using Mono.Cecil.Cil;
using Monocle;
using MonoMod;
using MonoMod.Detour;
using MonoMod.RuntimeDetour;
using MonoMod.Utils;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -73,15 +74,6 @@ public static State state {

private static bool SkipBaseUpdate;

// The methods we want to hook.

// The original mod adds a few lines of code into Monocle.Engine::Update.
private readonly static MethodInfo m_Engine_Update = typeof(Engine).GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
// The original mod makes the MInput.Update call conditional and invokes UpdateInputs afterwards.
private readonly static MethodInfo m_MInput_Update = typeof(MInput).GetMethod("Update", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
// The original mod makes the base.Update call conditional.
private readonly static MethodInfo m_Game_Update = typeof(Game).GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

public CelesteTASModule() {
Instance = this;
}
Expand Down Expand Up @@ -155,7 +147,7 @@ public override void Load() {
}
} catch (Exception e) {
Logger.Log("tas-interop", "Failed loading Celeste-Addons");
e.LogDetailed();
Logger.LogDetailed(e);
}
if (CelesteAddons == null)
return;
Expand All @@ -171,27 +163,37 @@ public override void Load() {
Type t_CelesteTASModule = GetType();

// Relink UpdateInputs to TAS.Manager.UpdateInputs because reflection invoke is slow.
if (t_CelesteTASModule.GetMethod("UpdateInputs").GetDetourLevel() == 0) {
t_CelesteTASModule.GetMethod("UpdateInputs").Detour(
Manager.GetMethod("UpdateInputs")
);
}

orig_Engine_Update = m_Engine_Update.Detour<d_Engine_Update>(t_CelesteTASModule.GetMethod("Engine_Update"));
orig_MInput_Update = m_MInput_Update.Detour<d_MInput_Update>(t_CelesteTASModule.GetMethod("MInput_Update"));
orig_Game_Update = m_Game_Update.Detour<d_Game_Update>(t_CelesteTASModule.GetMethod("Game_Update"));

h_UpdateInputs = new Detour(
typeof(CelesteTASModule).GetMethod("UpdateInputs"),
Manager.GetMethod("UpdateInputs")
);

// The original mod adds a few lines of code into Monocle.Engine::Update.
On.Monocle.Engine.Update += Engine_Update;

// The original mod makes the MInput.Update call conditional and invokes UpdateInputs afterwards.
On.Monocle.MInput.Update += MInput_Update;

// The original mod makes the base.Update call conditional.
// We need to use Detour for two reasons:
// 1. Expose the trampoline to be used for the base.Update call in MInput_Update
// 2. XNA Framework methods would require a separate MMHOOK .dll
orig_Game_Update = (h_Game_Update = new Detour(
typeof(Game).GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic),
typeof(CelesteTASModule).GetMethod("Game_Update")
)).GenerateTrampoline<d_Game_Update>();
}

public override void Unload() {
if (CelesteAddons == null)
return;

// Undetouring UpdateInputs isn't required.

// Let's just hope that nothing else detoured this, as this is depth-based...
RuntimeDetour.Undetour(m_Engine_Update);
RuntimeDetour.Undetour(m_MInput_Update);
h_Game_Update.Undo();
h_Game_Update.Free();
On.Monocle.Engine.Update -= Engine_Update;
On.Monocle.MInput.Update -= MInput_Update;
h_Game_Update.Undo();
h_Game_Update.Free();
}

private TypeDefinition td_Engine;
Expand Down Expand Up @@ -229,19 +231,18 @@ public void PatchAddonsMethod(MonoModder modder, MethodDefinition method) {
}
}

public static Detour h_UpdateInputs;
[MethodImpl(MethodImplOptions.NoInlining)]
public static void UpdateInputs() {
// This gets relinked to TAS.Manager.UpdateInputs
throw new Exception("UpdateInputs not relinked!");
throw new Exception("Failed relinking UpdateInputs!");
}

public delegate void d_Engine_Update(Engine self, GameTime gameTime);
public static d_Engine_Update orig_Engine_Update;
public static void Engine_Update(Engine self, GameTime gameTime) {
public static void Engine_Update(On.Monocle.Engine.orig_Update orig, Engine self, GameTime gameTime) {
SkipBaseUpdate = false;

if (!Settings.Enabled) {
orig_Engine_Update(self, gameTime);
orig(self, gameTime);
return;
}

Expand All @@ -252,31 +253,29 @@ public static void Engine_Update(Engine self, GameTime gameTime) {
// Loop without base.Update(), then call base.Update() once.
SkipBaseUpdate = true;
for (int i = 0; i < loops; i++) {
orig_Engine_Update(self, gameTime);
orig(self, gameTime);
}
SkipBaseUpdate = false;
// This _should_ work...
orig_Game_Update(self, gameTime);
orig(self, gameTime);

return;
}

loops = Math.Min(10, loops);
for (int i = 0; i < loops; i++) {
orig_Engine_Update(self, gameTime);
orig(self, gameTime);
}
}

public delegate void d_MInput_Update();
public static d_MInput_Update orig_MInput_Update;
public static void MInput_Update() {
public static void MInput_Update(On.Monocle.MInput.orig_Update orig) {
if (!Settings.Enabled) {
orig_MInput_Update();
orig();
return;
}

if (!Running || Recording) {
orig_MInput_Update();
orig();
}
UpdateInputs();

Expand All @@ -288,6 +287,7 @@ public static void MInput_Update() {
}
}

public static Detour h_Game_Update;
public delegate void d_Game_Update(Game self, GameTime gameTime);
public static d_Game_Update orig_Game_Update;
public static void Game_Update(Game self, GameTime gameTime) {
Expand Down
6 changes: 3 additions & 3 deletions CelesteTAS-EverestInterop/CelesteTASProxies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Monocle;
using MonoMod;
using MonoMod.Detour;
using MonoMod.Helpers;
using MonoMod.InlineRT;
using MonoMod.Utils;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -40,15 +40,15 @@ public static float Player_get_dashCooldownTimer(Player self)
public readonly static MethodInfo m_Player_WallJumpCheck = t_Player.GetMethod("WallJumpCheck", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
[CelesteTASProxy("System.Boolean Celeste.Player::WallJumpCheck(System.Int32)")]
public static bool Player_WallJumpCheck(Player self, int dir)
=> (bool) m_Player_WallJumpCheck.GetDelegate().Invoke(self, dir);
=> (bool) m_Player_WallJumpCheck.GetFastDelegate().Invoke(self, dir);


public readonly static Type t_MInput = typeof(MInput);

public readonly static MethodInfo m_UpdateVirualInputs = t_MInput.GetMethod("UpdateVirtualInputs", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
[CelesteTASProxy("System.Void Monocle.MInput::UpdateVirtualInputs()")]
public static void MInput_UpdateVirtualInputs()
=> m_UpdateVirualInputs.GetDelegate().Invoke(null);
=> m_UpdateVirualInputs.GetFastDelegate().Invoke(null);


public readonly static Type t_SummitVignette = typeof(SummitVignette);
Expand Down
2 changes: 1 addition & 1 deletion CelesteTAS-EverestInterop/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: CelesteTAS
Version: 1.1.2
Version: 1.1.3
DLL: CelesteTAS-EverestInterop.dll
Dependencies:
- Name: Everest
Expand Down
3 changes: 1 addition & 2 deletions CelesteTAS-EverestInterop/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.6.1" targetFramework="net452" developmentDependency="true" />
<package id="Mono.Cecil" version="0.10.0-beta7" targetFramework="net452" />
<package id="Mono.Cecil" version="0.10.0" targetFramework="net452" />
</packages>
2 changes: 1 addition & 1 deletion Everest
Submodule Everest updated 94 files
+77 −13 Celeste.Mod.mm/Celeste.Mod.mm.csproj
+50 −35 Celeste.Mod.mm/Content/Dialog/English.txt
+ Celeste.Mod.mm/Content/Graphics/Atlases/Gui/emoji/glad.png
+ Celeste.Mod.mm/Content/Graphics/Atlases/Gui/emoji/gladbw.m.png
+ Celeste.Mod.mm/Content/Graphics/Atlases/Gui/emoji/thinking.png
+ Celeste.Mod.mm/Content/Graphics/Atlases/Gui/emoji/thinkingbw.m.png
+ Celeste.Mod.mm/Content/Graphics/Atlases/Gui/menu/everest.png
+63 −41 Celeste.Mod.mm/Mod/Core/CoreModule.cs
+1 −0 Celeste.Mod.mm/Mod/Core/CoreModuleSaveData.cs
+89 −3 Celeste.Mod.mm/Mod/Core/CoreModuleSettings.cs
+3 −3 Celeste.Mod.mm/Mod/Entities/CustomMemorial.cs
+1 −1 Celeste.Mod.mm/Mod/Entities/CustomMemorialText.cs
+1 −1 Celeste.Mod.mm/Mod/Everest/ContentExtensions.cs
+151 −0 Celeste.Mod.mm/Mod/Everest/Emoji.cs
+96 −22 Celeste.Mod.mm/Mod/Everest/Everest.Content.cs
+139 −0 Celeste.Mod.mm/Mod/Everest/Everest.Discord.cs
+31 −95 Celeste.Mod.mm/Mod/Everest/Everest.Events.cs
+88 −0 Celeste.Mod.mm/Mod/Everest/Everest.Flags.cs
+114 −14 Celeste.Mod.mm/Mod/Everest/Everest.Loader.cs
+84 −16 Celeste.Mod.mm/Mod/Everest/Everest.Relinker.cs
+39 −10 Celeste.Mod.mm/Mod/Everest/Everest.Update.cs
+28 −10 Celeste.Mod.mm/Mod/Everest/Everest.cs
+39 −3 Celeste.Mod.mm/Mod/Everest/Extensions.cs
+11 −65 Celeste.Mod.mm/Mod/Everest/MTextureOverride.cs
+3 −1 Celeste.Mod.mm/Mod/Everest/ModAsset.cs
+56 −0 Celeste.Mod.mm/Mod/Everest/TextInput.cs
+1 −1 Celeste.Mod.mm/Mod/Helpers/Commands.cs
+224 −0 Celeste.Mod.mm/Mod/Helpers/DiscordRpc.cs
+1 −1 Celeste.Mod.mm/Mod/Helpers/FakeAssembly.cs
+0 −219 Celeste.Mod.mm/Mod/Helpers/LimitedStream.cs
+51 −0 Celeste.Mod.mm/Mod/Helpers/RelinkerSymbolReaderProvider.cs
+102 −0 Celeste.Mod.mm/Mod/Helpers/XNAFormsHook.cs
+1 −1 Celeste.Mod.mm/Mod/Meta/MapMeta.cs
+30 −2 Celeste.Mod.mm/Mod/Module/EverestModule.cs
+9 −22 Celeste.Mod.mm/Mod/Module/EverestModuleMetadata.cs
+103 −0 Celeste.Mod.mm/Mod/Touch/TouchInputManager.cs
+36 −0 Celeste.Mod.mm/Mod/Touch/TouchInputNodes.cs
+136 −0 Celeste.Mod.mm/Mod/Touch/TouchRegion.cs
+5 −1 Celeste.Mod.mm/Mod/UI/OuiHelper_ChapterSelect_LevelSet.cs
+1 −1 Celeste.Mod.mm/Mod/UI/OuiLoggedProgress.cs
+4 −4 Celeste.Mod.mm/Mod/UI/OuiMapList.cs
+82 −14 Celeste.Mod.mm/Mod/UI/OuiModOptionString.cs
+8 −5 Celeste.Mod.mm/Mod/UI/OuiModOptions.cs
+226 −0 Celeste.Mod.mm/Mod/UI/OuiSoundTest.cs
+2 −2 Celeste.Mod.mm/Mod/UI/OuiVersionList.cs
+78 −0 Celeste.Mod.mm/Mod/UI/SubHudRenderer.cs
+50 −2 Celeste.Mod.mm/Mod/UI/TextMenuExt.cs
+288 −5 Celeste.Mod.mm/MonoModRules.cs
+2 −10 Celeste.Mod.mm/Patches/AreaData.cs
+198 −0 Celeste.Mod.mm/Patches/Audio.cs
+10 −2 Celeste.Mod.mm/Patches/Celeste.cs
+4 −8 Celeste.Mod.mm/Patches/Dialog.cs
+30 −0 Celeste.Mod.mm/Patches/FMOD/Studio/EventDescription.cs
+44 −0 Celeste.Mod.mm/Patches/FancyText.cs
+26 −0 Celeste.Mod.mm/Patches/Fonts.cs
+0 −106 Celeste.Mod.mm/Patches/GFX.cs
+48 −0 Celeste.Mod.mm/Patches/GameLoader.cs
+47 −0 Celeste.Mod.mm/Patches/GameplayRenderer.cs
+0 −9 Celeste.Mod.mm/Patches/Input.cs
+70 −0 Celeste.Mod.mm/Patches/Level.cs
+10 −9 Celeste.Mod.mm/Patches/LevelEnter.cs
+34 −0 Celeste.Mod.mm/Patches/LevelLoader.cs
+223 −36 Celeste.Mod.mm/Patches/Monocle/Atlas.cs
+21 −6 Celeste.Mod.mm/Patches/Monocle/Calc.cs
+740 −59 Celeste.Mod.mm/Patches/Monocle/MTexture.cs
+105 −0 Celeste.Mod.mm/Patches/Monocle/PixelFontSize.cs
+20 −0 Celeste.Mod.mm/Patches/Monocle/VirtualAsset.cs
+24 −0 Celeste.Mod.mm/Patches/Monocle/VirtualContent.cs
+122 −3 Celeste.Mod.mm/Patches/Monocle/VirtualTexture.cs
+4 −3 Celeste.Mod.mm/Patches/OuiChapterPanel.cs
+6 −4 Celeste.Mod.mm/Patches/OuiChapterSelect.cs
+116 −0 Celeste.Mod.mm/Patches/OuiFileNaming.cs
+1 −1 Celeste.Mod.mm/Patches/OuiJournal.cs
+11 −1 Celeste.Mod.mm/Patches/OuiMainMenu.cs
+49 −0 Celeste.Mod.mm/Patches/OverworldLoader.cs
+31 −0 Celeste.Mod.mm/Patches/Sfxs.cs
+31 −0 Celeste.Mod.mm/Patches/Strawberry.cs
+36 −0 Celeste.Mod.mm/Patches/Tags.cs
+31 −0 Celeste.Mod.mm/Patches/UserIO.cs
+2 −3 Celeste.Mod.mm/packages.config
+6 −2 MiniInstaller/MiniInstaller.csproj
+42 −17 MiniInstaller/Program.cs
+3 −0 MiniInstaller/app.config
+22 −0 default.nix
+5 −0 generateEmbeddedResource.sh
+ lib-ext/discord-rpc.dll
+ lib-ext/libdiscord-rpc.dylib
+ lib-ext/libdiscord-rpc.so
+ lib-stripped/Celeste.exe
+ lib/MonoMod.RuntimeDetour.HookGen.exe
+ lib/MonoMod.RuntimeDetour.dll
+ lib/MonoMod.Utils.dll
+ lib/MonoMod.exe
+3 −0 run-nuget.sh
Binary file added MMHOOK_Celeste.dll
Binary file not shown.

0 comments on commit c6bc8a5

Please sign in to comment.