Skip to content

Commit

Permalink
feat: use osmi
Browse files Browse the repository at this point in the history
  • Loading branch information
Clazex committed Apr 23, 2022
1 parent afc7a75 commit 29c695c
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 213 deletions.
9 changes: 8 additions & 1 deletion GodSeekerPlus/GodSeekerPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ public sealed partial class GodSeekerPlus : Mod, ITogglableMod {
public static GodSeekerPlus? Instance { get; private set; }
public static GodSeekerPlus UnsafeInstance => Instance!;

public override string GetVersion() => VersionUtil.Version.Value;
private static readonly Lazy<string> version = AssemblyUtil
#if DEBUG
.GetMyDefaultVersionWithHash();
#else
.GetMyDefaultVersion();
#endif

public override string GetVersion() => version.Value;

internal static bool satchelPresent = false;

Expand Down
2 changes: 1 addition & 1 deletion 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.19.5</Version>
<Version>0.19.6</Version>
<Description>A Hollow Knight mod to enhance your Godhome experience</Description>
<Authors>Clazex</Authors>

Expand Down
7 changes: 5 additions & 2 deletions GodSeekerPlus/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

global using GodSeekerPlus.Modules;
global using GodSeekerPlus.Settings;
global using GodSeekerPlus.Util;
global using GodSeekerPlus.Utils;

global using HutongGames.PlayMaker;
global using HutongGames.PlayMaker.Actions;
Expand All @@ -18,6 +18,9 @@

global using Newtonsoft.Json;

global using Osmi.FsmActions;
global using Osmi.Utils;

global using Satchel;
global using Satchel.Futils;

Expand All @@ -27,7 +30,7 @@
global using UnityEngine.UI;

global using Module = GodSeekerPlus.Modules.Module;
global using Logger = GodSeekerPlus.Util.Logger;
global using Logger = GodSeekerPlus.Utils.Logger;
global using Lang = Language.Language;
global using ReflectionHelper = Modding.ReflectionHelper;
global using UObject = UnityEngine.Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ private void ModifyGPFSM(On.PlayMakerFSM.orig_Start orig, PlayMakerFSM self) {
private static void ModifyGPFSM(PlayMakerFSM fsm) =>
fsm.AddCustomAction(
"Enter 1",
() => fsm.FsmVariables.FindFsmBool("Faced Zote").Value = Ref.GS.gpzEnterType
() => fsm.GetVariable<FsmBool>("Faced Zote").Value = Ref.GS.gpzEnterType
);
}
18 changes: 7 additions & 11 deletions GodSeekerPlus/Modules/BossChallenge/InfiniteRadianceClimbing.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using InvokeMethod = Osmi.FsmActions.InvokeMethod;

namespace GodSeekerPlus.Modules.BossChallenge;

[ToggleableLevel(ToggleableLevel.ChangeScene)]
Expand Down Expand Up @@ -63,25 +65,19 @@ private void ModifyAbsRadFSM(PlayMakerFSM fsm) {
// Spawn P2 plats before appearance
fsm.ChangeTransition("Set Arena 1", "FINISHED", "Climb Plats1");

fsm.InsertAction("Set Arena 1", new CustomFsmAction() {
method = () => fsm.StartCoroutine(TeleportSetup())
}, 0);
fsm.InsertAction("Set Arena 1", new InvokeCoroutine(TeleportSetup), 0);

FsmState spawnPlatsState = fsm.GetState("Climb Plats1");
spawnPlatsState.Actions = new[] {
spawnPlatsState.Actions[2], // Spawn plats
new CustomFsmAction() {
method = () => fsm.gameObject.manageHealth(1100)
}
new InvokeMethod(() => fsm.gameObject.manageHealth(int.MaxValue))
};
(spawnPlatsState.Actions[0] as SendEventByName)!.delay = 0;

FsmState screamState = fsm.GetState("Scream");
screamState.Actions = new[] {
screamState.Actions[0], // Play audio clip
new CustomFsmAction() {
method = () => rewindCoro ??= radCtrl!.StartCoroutine(Rewind())
},
new InvokeMethod(() => rewindCoro ??= radCtrl!.StartCoroutine(Rewind())),
new Wait() { time = 60f } // Wait for Rewind coroutine
};
}
Expand Down Expand Up @@ -118,8 +114,8 @@ private IEnumerator Rewind() {
beam.SetActive(false); // Remove last beam

// Reset abyss pit
pitCtrl!.FsmVariables.FindFsmFloat("Hero Y").Value = 33f;
pitCtrl.SendEvent("ASCEND");
pitCtrl!.GetVariable<FsmFloat>("Hero Y").Value = 33f;
pitCtrl!.SendEvent("ASCEND");

// Teleport hero back
Ref.PD.isInvincible = true;
Expand Down
3 changes: 1 addition & 2 deletions GodSeekerPlus/Modules/BossChallenge/SegmentedP5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ string playerData

int firstSceneIndex = BossSequenceController.BossIndex;
segP5!.GetComponent<BossSequenceDoor>()
.challengeFSM.FsmVariables
.FindFsmString("To Scene")
.challengeFSM.GetVariable<FsmString>("To Scene")
.Value = sequence.GetSceneAt(firstSceneIndex);

if (firstSceneIndex != 0) {
Expand Down
5 changes: 4 additions & 1 deletion GodSeekerPlus/Modules/Misc/LocalizeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ namespace GodSeekerPlus.Modules.Misc;

[Hidden]
internal sealed class LocalizeMenu : Module {
private static readonly Lazy<string> versionWithHash = AssemblyUtil
.GetMyDefaultVersionWithHash();

private protected override void Load() =>
Ref.GM.StartCoroutine(WaitForTitle());

Expand All @@ -28,7 +31,7 @@ private static void EditText() {
"ModName".Localize() + ' ' + "Settings".Localize();

btn.Child("Description")!.GetComponent<Text>().text =
'v' + VersionUtil.VersionWithHash.Value;
'v' + versionWithHash.Value;

Logger.LogDebug("Menu localized");
}
Expand Down
2 changes: 1 addition & 1 deletion GodSeekerPlus/Modules/QoL/EternalOrdealPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private void AddPlatform(Scene _, Scene next) {
GameObject origPlat = next.GetRootGameObjects()
.First(go => go.name == "gg_plat_float_wide");

var plat = GameObject.Instantiate(origPlat);
GameObject plat = UObject.Instantiate(origPlat);
plat.transform.SetPosition2D(204.15f, 42.3f);
}
}
2 changes: 1 addition & 1 deletion GodSeekerPlus/Modules/QoL/FastDash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private protected override void Unload() =>
USceneManager.activeSceneChanged -= HookDash;

// Hook only when needed for zero performance impact
private void HookDash(Scene prev, Scene next) {
private void HookDash(Scene _, Scene next) {
On.HeroController.HeroDash -= CancelCooldown;

if (next.name == "GG_Workshop") {
Expand Down
2 changes: 1 addition & 1 deletion GodSeekerPlus/Modules/QoL/P5Teleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static IEnumerator Teleport() {
.ForEach(state => ReflectionHelper.CallMethod(state, "ActivateActions", 0));

Ref.HC.gameObject.LocateMyFSM("Roar Lock")
.FsmVariables.FindFsmBool("No Roar")
.GetVariable<FsmBool>("No Roar")
.Value = false;
StaticVariableList.SetValue("skipRemoveDreamOrbs", true);

Expand Down
2 changes: 1 addition & 1 deletion GodSeekerPlus/Settings/LocalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public int RABCompletion {
[JsonProperty(PropertyName = "selectedP5Segment")]
public int SelectedP5Segment {
get => selectedP5Segment;
set => selectedP5Segment = MiscUtil.Clamp(value, 0, Modules.BossChallenge.SegmentedP5.segments.Length - 1);
set => selectedP5Segment = value.Clamp(0, Modules.BossChallenge.SegmentedP5.segments.Length - 1);
}

#region RAB Completions Getter/Setter
Expand Down
27 changes: 0 additions & 27 deletions GodSeekerPlus/Util/EnumerableUtil.cs

This file was deleted.

28 changes: 0 additions & 28 deletions GodSeekerPlus/Util/GameObjectUtil.cs

This file was deleted.

58 changes: 0 additions & 58 deletions GodSeekerPlus/Util/L11nUtil.cs

This file was deleted.

24 changes: 0 additions & 24 deletions GodSeekerPlus/Util/MiscUtil.cs

This file was deleted.

29 changes: 0 additions & 29 deletions GodSeekerPlus/Util/SceneDataUtil.cs

This file was deleted.

22 changes: 0 additions & 22 deletions GodSeekerPlus/Util/VersionUtil.cs

This file was deleted.

25 changes: 25 additions & 0 deletions GodSeekerPlus/Utils/L11nUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Language;

namespace GodSeekerPlus.Utils;

internal static class L11nUtil {
private const string langPrefix = "GodSeekerPlus.Resources.Lang.";
private const string langSuffix = ".json";

internal static Lazy<Dictionary<string, Lazy<Dictionary<string, string>>>> Dict = new(() => {
Assembly asm = typeof(GodSeekerPlus).Assembly;
return LangUtil.LoadLangs(asm, asm
.GetManifestResourceNames()
.Filter(name => name.EnclosedWith(langPrefix, langSuffix))
.Map(name => (
name.StripStart(langPrefix).StripEnd(langSuffix),
name
)));
});

internal static string Localize(this string key) {
Dict.Value.TryGetValue(LangUtil.CurrentLang, out Lazy<Dictionary<string, string>>? table);
table ??= Dict.Value[LanguageCode.EN.ToIdentifier()];
return table.Value.TryGetValue(key, out string value) ? value : key;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using L = Modding.Logger;

namespace GodSeekerPlus.Util;
namespace GodSeekerPlus.Utils;

internal static class Logger {
private static readonly string prefix = $"[{nameof(GodSeekerPlus)}] - ";
Expand Down
Loading

0 comments on commit 29c695c

Please sign in to comment.