Use new keybindings API instead of Harmony

master
D4VID 4 months ago
parent 3bff2ca727
commit fad6ead9ed

@ -8,9 +8,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\HarmonyForLogicWorld\HarmonyForLogicWorld\assemblies\client\0Harmony.dll</HintPath>
</Reference>
<Reference Include="FancyInput"> <Reference Include="FancyInput">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\FancyInput.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\FancyInput.dll</HintPath>
</Reference> </Reference>
@ -29,6 +26,9 @@
<Reference Include="LogicLog"> <Reference Include="LogicLog">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicUI.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicUI.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.Building"> <Reference Include="LogicWorld.Building">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Building.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Building.dll</HintPath>
</Reference> </Reference>

@ -1,8 +1,7 @@
ID: CriticalPathAnalyzer ID: CriticalPathAnalyzer
Name: CriticalPathAnalyzer Name: CriticalPathAnalyzer
Author: D4VID Author: D4VID
Version: 0.2.2 Version: 0.3.0
Priority: 0 Priority: 0
Dependencies: Dependencies:
- HarmonyForLogicWorld
- EccsLogicWorldAPI - EccsLogicWorldAPI

@ -6,6 +6,8 @@ using EccsLogicWorldAPI.Client.Injectors;
using FancyInput; using FancyInput;
using LogicAPI.Client; using LogicAPI.Client;
using LogicLog; using LogicLog;
using LogicWorld;
using LogicWorld.GameStates;
namespace CriticalPathAnalyzer.Client { namespace CriticalPathAnalyzer.Client {
public class CriticalPathAnalyzerClient : ClientMod { public class CriticalPathAnalyzerClient : ClientMod {
@ -22,8 +24,14 @@ namespace CriticalPathAnalyzer.Client {
// Inject our own game state // Inject our own game state
GameStateInjector.inject(CriticalPathAnalyzerGameState.Id, typeof(CriticalPathAnalyzerGameState)); GameStateInjector.inject(CriticalPathAnalyzerGameState.Id, typeof(CriticalPathAnalyzerGameState));
// Inject a hook into the game code to check for our keybindings // Register the keybinding to enter the path analyzer game state
KeybindingsInjector.Inject(); FirstPersonInteraction.RegisterBuildingKeybinding(
CriticalPathAnalyzerTrigger.OpenPathAnalyzer,
() => {
GameStateManager.TransitionTo(CriticalPathAnalyzerGameState.Id);
return true;
}
);
// Inject packet handlers // Inject packet handlers
RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version)); RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version));

@ -1,31 +0,0 @@
using CriticalPathAnalyzer.Client.Keybindings;
using EccsLogicWorldAPI.Shared.AccessHelper;
using FancyInput;
using HarmonyLib;
using LogicWorld.Building;
using LogicWorld.GameStates;
namespace CriticalPathAnalyzer.Client {
public class KeybindingsInjector {
// Fairly generic hook into adding custom keybindings to the main building game state of LW.
// Allows to add keybindings to open new GUI elements or add new core building actions (which are not build-operations).
public static void Inject() {
var methodTarget = Methods.getPrivateStatic(typeof(StuffDeleter), "RunFirstPersonWireDeleting");
var methodHook = Methods.getPrivateStatic(typeof(KeybindingsInjector), nameof(Hook));
var harmony = new Harmony(nameof(CriticalPathAnalyzer));
harmony.Patch(methodTarget, prefix: new HarmonyMethod(methodHook));
}
private static bool Hook(out bool deletedWire) {
if (CustomInput.DownThisFrame(CriticalPathAnalyzerTrigger.OpenPathAnalyzer)) {
GameStateManager.TransitionTo(CriticalPathAnalyzerGameState.Id);
deletedWire = true; // True = Cancel remaining keybinding handling.
return false; // Prevent execution of the original/further functionality.
}
deletedWire = false; // Default, might be overwritten. False = Do not cancel remaining keybinding handling.
return true; // Allow original/further functionality.
}
}
}
Loading…
Cancel
Save