Skip to content

Commit

Permalink
feat: use fody and hkreflect and drop hkmirror
Browse files Browse the repository at this point in the history
  • Loading branch information
Clazex committed Mar 8, 2023
1 parent 44c892b commit e3267ed
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Thumbs.db
/package-lock.json
.history/
dist/
*/FodyWeavers.xsd

/HKManaged/

Expand Down
5 changes: 5 additions & 0 deletions GodSeekerPlus/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<InfoOf />
<HKReflect />
</Weavers>
16 changes: 6 additions & 10 deletions GodSeekerPlus/GodSeekerPlus.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>GodSeekerPlus</AssemblyTitle>
<Version>0.23.0</Version>
<Version>0.23.1</Version>
<Description>A Hollow Knight mod to enhance your Godhome experience</Description>
<Authors>Clazex</Authors>

Expand All @@ -13,7 +13,6 @@

<LangVersion>10.0</LangVersion>
<TargetFramework>net472</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<DebugType>portable</DebugType>
<RootNamespace>GodSeekerPlus</RootNamespace>

Expand Down Expand Up @@ -114,17 +113,14 @@
<HintPath>$(HKModRefs)/Osmi/Osmi.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="HKMirror">
<HintPath>$(HKModRefs)/HKMirror/HKMirror.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nullable" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />

<PackageReference Include="Fody" Version="6.6.4" PrivateAssets="all" />
<PackageReference Include="InfoOf.Fody" Version="2.1.1" PrivateAssets="all" />
<PackageReference Include="HKReflect.Fody" Version="0.2.0" PrivateAssets="all" />
</ItemGroup>

<Target Name="CopyMod" AfterTargets="PostBuildEvent">
Expand Down
8 changes: 4 additions & 4 deletions GodSeekerPlus/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
global using GodSeekerPlus.Settings;
global using GodSeekerPlus.Utils;

global using HKMirror.Reflection;
global using HKMirror.Reflection.SingletonClasses;
global using HKMirror.Reflection.StaticClasses;

global using HutongGames.PlayMaker;
global using HutongGames.PlayMaker.Actions;

Expand All @@ -27,6 +23,9 @@
global using Osmi.Game;
global using Osmi.Utils;

global using HKReflect;
global using HKReflect.Static;

global using Satchel;
global using Satchel.Futils;

Expand All @@ -43,3 +42,4 @@
global using USceneManager = UnityEngine.SceneManagement.SceneManager;

global using static GodSeekerPlus.Utils.Logger;
global using static HKReflect.Singletons;
4 changes: 2 additions & 2 deletions GodSeekerPlus/Modules/BossChallenge/ActivateFury.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ internal static void Activate() {
}

if (CharmUtil.EquippedCharm(Charm.JonisBlessing)) {
Ref.PD.joniHealthBlue = 1;
PlayerDataR.joniHealthBlue = 1;
} else {
Ref.PD.health = 1;
PlayerDataR.health = 1;
}

_ = Ref.HC.StartCoroutine(UpdateState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static IEnumerator Rewind() {
pitCtrl!.SendEvent("ASCEND");

// Teleport hero back
Ref.PD.isInvincible = true;
PlayerDataR.isInvincible = true;
Ref.HC.RelinquishControl();
Ref.HC.transform.SetPosition2D(heroX, heroY);
Ref.HC.FaceRight();
Expand All @@ -144,7 +144,7 @@ private static IEnumerator Rewind() {
// Give back hero control
flasher.CancelFlash();
Ref.HC.RegainControl();
Ref.PD.isInvincible = false;
PlayerDataR.isInvincible = false;

yield return new WaitForSeconds(1.5f);

Expand Down
14 changes: 10 additions & 4 deletions GodSeekerPlus/Modules/BossChallenge/P5Health.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using HKMirror.Hooks.OnHooks;
using MonoMod.RuntimeDetour;

namespace GodSeekerPlus.Modules.BossChallenge;

public sealed class P5Health : Module {
private static readonly Detour levelGetterDetour = new(
Info.OfPropertyGet<BossSceneController>(nameof(BossSceneController.BossLevel)),
Info.OfMethod<P5Health>(nameof(OverrideLevel)),
new() { ManualApply = true }
);

private static readonly SceneEdit ascendedMarkothHandle = new(
new("GG_Markoth_V", "Warrior", "Ghost Warrior Markoth"),
go => go.manageHealth(650)
Expand All @@ -11,20 +17,20 @@ public sealed class P5Health : Module {
public override ToggleableLevel ToggleableLevel => ToggleableLevel.ChangeScene;

private protected override void Load() {
OnBossSceneController.AfterOrig.get_BossLevel += OverrideLevel;
levelGetterDetour.Apply();
ascendedMarkothHandle.Enable();

ModHooks.TakeDamageHook += FixDamage;
}

private protected override void Unload() {
OnBossSceneController.AfterOrig.get_BossLevel -= OverrideLevel;
levelGetterDetour.Undo();
ascendedMarkothHandle.Disable();

ModHooks.TakeDamageHook -= FixDamage;
}

private static int OverrideLevel(OnBossSceneController.Delegates.Params_get_BossLevel @params, int level) => 0;
private static int OverrideLevel(BossSceneController self, int level) => 0;

private static int FixDamage(ref int hazardType, int damage) => damage switch {
int i when i <= 0 => i,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void SetOrdealUnlocked(On.HeroController.orig_Start orig, HeroCon
Ref.SD.persistentBoolItems
.Set("GG_Workshop", "Zote_Break_wall", true);

Ref.PD.zoteStatueWallBroken = true;
PlayerDataR.zoteStatueWallBroken = true;

LogDebug("Eternal Ordeal unlocked");
}
Expand Down
10 changes: 5 additions & 5 deletions GodSeekerPlus/Modules/NewSaveQuickstart/UnlockPantheons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ private protected override void Unload() =>
private static void Unlock(On.HeroController.orig_Start orig, HeroController self) {
orig(self);

if (!Ref.PD.bossRushMode) {
if (!PlayerDataR.bossRushMode) {
return;
}

if (!Ref.PD.bossDoorCageUnlocked) {
Ref.PD.bossDoorCageUnlocked = true;
if (!PlayerDataR.bossDoorCageUnlocked) {
PlayerDataR.bossDoorCageUnlocked = true;
LogDebug("P4 Unlocked");
}

if (!Ref.PD.finalBossDoorUnlocked) {
Ref.PD.finalBossDoorUnlocked = true;
if (!PlayerDataR.finalBossDoorUnlocked) {
PlayerDataR.finalBossDoorUnlocked = true;
Ref.SD.persistentBoolItems.Set("GG_Atrium", "gg_roof_lever", true);

LogDebug("P5 Unlocked");
Expand Down
6 changes: 3 additions & 3 deletions GodSeekerPlus/Modules/NewSaveQuickstart/UnlockRadiance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ private static void SetRadianceUnlocked(On.HeroController.orig_Start orig, HeroC
orig(self);

if (
Ref.PD.bossRushMode
&& !Ref.PD.unlockedBossScenes.Contains(sceneName)
PlayerDataR.bossRushMode
&& !PlayerDataR.unlockedBossScenes.Contains(sceneName)
) {
Ref.PD.unlockedBossScenes.Add(sceneName);
PlayerDataR.unlockedBossScenes.Add(sceneName);
Ref.SD.persistentBoolItems
.Set("GG_Workshop", "Radiance Statue Cage", true);

Expand Down
16 changes: 11 additions & 5 deletions GodSeekerPlus/Modules/QoL/DoorDefaultBegin.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
using HKMirror.Hooks.ILHooks;

using Mono.Cecil.Cil;

using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using MonoMod.Utils;

namespace GodSeekerPlus.Modules.QoL;

public sealed class DoorDefaultBegin : Module {
private static readonly ILHook hook = new(
Info.OfMethod<BossDoorChallengeUI>("ShowSequence").GetStateMachineTarget(),
ChangeSelection,
new() { ManualApply = true }
);

public override bool DefaultEnabled => true;

private protected override void Load() => ILBossDoorChallengeUI.ShowSequence += ChangeSelection;
private protected override void Load() => hook.Apply();

private protected override void Unload() => ILBossDoorChallengeUI.ShowSequence -= ChangeSelection;
private protected override void Unload() => hook.Undo();

// Remove:
//
Expand All @@ -29,7 +35,7 @@ public sealed class DoorDefaultBegin : Module {
.RemoveUntilEnd()

.Emit(OpCodes.Ldloc_1) // self
.EmitStaticMethodCall(SelectBegin)
.Emit(OpCodes.Call, Info.OfMethod<DoorDefaultBegin>(nameof(SelectBegin)))

.Emit(OpCodes.Ldc_I4_0); // Fix return

Expand Down
8 changes: 4 additions & 4 deletions GodSeekerPlus/Modules/QoL/GreyPrinceToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public sealed class GreyPrinceToggle : Module {
private static readonly SceneEdit handle = new(
new("GG_Workshop", "GG_Statue_GreyPrince"),
go => {
if (!Ref.PD.bossRushMode) {
if (!PlayerDataR.bossRushMode) {
return;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ private protected override void Load() {
private protected override void Unload() {
handle.Disable();

if (Ref.GM?.sceneName == "GG_Workshop" && Ref.PD?.bossRushMode == true) {
if (Ref.GM?.sceneName == "GG_Workshop" && PlayerDataR?.bossRushMode == true) {
Ref.HC.transform.SetPosition2D(2, 9); // leave HoG
}
}
Expand All @@ -76,8 +76,8 @@ private sealed class FakeDreamToggle : MonoBehaviour {
private ColorFader[] colorFaders;

private bool On {
get => Ref.PD.greyPrinceDefeated;
set => Ref.PD.greyPrinceDefeated = value;
get => PlayerDataR.greyPrinceDefeated;
set => PlayerDataR.greyPrinceDefeated = value;
}

public void Awake() {
Expand Down
2 changes: 1 addition & 1 deletion GodSeekerPlus/Modules/QoL/KeepCocoonLifeblood.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private protected override void Unload() =>
ModHooks.BlueHealthHook -= CocoonCompensate;

private static int CocoonCompensate() {
if (Ref.GM.sceneName != "GG_Spa" || !Ref.PD.blueRoomActivated) {
if (Ref.GM.sceneName != "GG_Spa" || !PlayerDataR.blueRoomActivated) {
return 0;
}

Expand Down
6 changes: 5 additions & 1 deletion GodSeekerPlus/Modules/QoL/P5Teleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private protected override void Unload() =>
leverEditHandle.Disable();

private static IEnumerator Teleport() {
if (teleporting || !Ref.PD.finalBossDoorUnlocked) {
if (teleporting || !PlayerDataR.finalBossDoorUnlocked) {
yield break;
}

Expand Down Expand Up @@ -49,6 +49,10 @@ private static IEnumerator Teleport() {

#region Substitute DGate data

// Here we need to bypass every hook on dgate fields such that the
// actual value is identical to what we need. This prevents
// compatibility issue with mods like SmolKnight where dgate
// position getting/setting is hooked for adding an offset
string origDGateScene = Ref.PD.dreamGateScene;
float origDGateX = Ref.PD.dreamGateX;
float origDGateY = Ref.PD.dreamGateY;
Expand Down

0 comments on commit e3267ed

Please sign in to comment.