Skip to content

Commit

Permalink
Merge pull request #19 from Extremelyd1/modding-api-1.5
Browse files Browse the repository at this point in the history
Update HKMP to use modding API for Hollow Knight 1.5.*
  • Loading branch information
Extremelyd1 authored Sep 12, 2021
2 parents a0873a3 + ee1abd1 commit 04fd20e
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 30 deletions.
8 changes: 4 additions & 4 deletions HKMP/Animation/AnimationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ Game.Settings.GameSettings gameSettings
On.HeroController.CancelDash += HeroControllerOnCancelDash;

// Register a callback so we can check the nail art charge status
ModHooks.Instance.HeroUpdateHook += OnHeroUpdateHook;

ModHooks.HeroUpdateHook += OnHeroUpdateHook;
// Register a callback for when we get hit by a hazard
On.HeroController.DieFromHazard += HeroControllerOnDieFromHazard;
// Also register a callback from when we respawn from a hazard
Expand All @@ -590,8 +590,8 @@ Game.Settings.GameSettings gameSettings
On.HeroController.RelinquishControl += HeroControllerOnRelinquishControl;

// Register when the player dies to send the animation
ModHooks.Instance.BeforePlayerDeadHook += OnDeath;

ModHooks.BeforePlayerDeadHook += OnDeath;
// Set the game settings for all animation effects
foreach (var effect in AnimationEffects.Values) {
effect.SetGameSettings(gameSettings);
Expand Down
2 changes: 1 addition & 1 deletion HKMP/Animation/Effects/FocusBurst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override bool[] GetEffectInfo() {
} else {
// Since the event already happened locally, the FSM move to the Cooldown state
// thus the only way to check whether we activated the cloud is when the cooldown is "fresh" aka ~0
var timeOnCooldown = ReflectionHelper.GetAttr<Wait, float>(
var timeOnCooldown = ReflectionHelper.GetField<Wait, float>(
sporeCooldownFsm.GetAction<Wait>("Cooldown", 0),
"timer"
);
Expand Down
2 changes: 1 addition & 1 deletion HKMP/Game/Client/ClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ PacketManager packetManager
_netClient.RegisterOnTimeout(OnTimeout);

// Register application quit handler
ModHooks.Instance.ApplicationQuitHook += OnApplicationQuit;
ModHooks.ApplicationQuitHook += OnApplicationQuit;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions HKMP/Game/Client/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ public Vector3 GetMapLocation() {
} else {
var playerPosition = HeroController.instance.gameObject.transform.position;

var originOffsetX = ReflectionHelper.GetAttr<GameMap, float>(gameMap, "originOffsetX");
var originOffsetY = ReflectionHelper.GetAttr<GameMap, float>(gameMap, "originOffsetY");
var sceneWidth = ReflectionHelper.GetAttr<GameMap, float>(gameMap, "sceneWidth");
var sceneHeight = ReflectionHelper.GetAttr<GameMap, float>(gameMap, "sceneHeight");
var originOffsetX = ReflectionHelper.GetField<GameMap, float>(gameMap, "originOffsetX");
var originOffsetY = ReflectionHelper.GetField<GameMap, float>(gameMap, "originOffsetY");
var sceneWidth = ReflectionHelper.GetField<GameMap, float>(gameMap, "sceneWidth");
var sceneHeight = ReflectionHelper.GetField<GameMap, float>(gameMap, "sceneHeight");

position = new Vector3(
currentScenePos.x - size.x / 2.0f + (playerPosition.x + originOffsetX) / sceneWidth *
Expand Down Expand Up @@ -246,7 +246,7 @@ private void OnCloseQuickMap(On.GameMap.orig_CloseQuickMap orig, GameMap self) {
private void OnPositionCompass(On.GameMap.orig_PositionCompass orig, GameMap self, bool posShade) {
orig(self, posShade);

var posGate = ReflectionHelper.GetAttr<GameMap, bool>(self, "posGate");
var posGate = ReflectionHelper.GetField<GameMap, bool>(self, "posGate");

// If this is a call where we either update the shade position or the dream gate position,
// we don't want to display the icons again, because we haven't opened the map
Expand Down
7 changes: 3 additions & 4 deletions HKMP/Game/Client/PauseManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections;
using System.Reflection;
using GlobalEnums;
Expand Down Expand Up @@ -28,7 +27,7 @@ public void RegisterHooks() {
On.TransitionPoint.OnTriggerEnter2D += TransitionPointOnOnTriggerEnter2D;
On.HeroController.DieFromHazard += HeroControllerOnDieFromHazard;

ModHooks.Instance.BeforePlayerDeadHook += OnDeath;
ModHooks.BeforePlayerDeadHook += OnDeath;
}

private void UIManagerOnTogglePauseGame(On.UIManager.orig_TogglePauseGame orig, UIManager self) {
Expand All @@ -39,7 +38,7 @@ private void UIManagerOnTogglePauseGame(On.UIManager.orig_TogglePauseGame orig,

// First evaluate whether the original method would have started the coroutine:
// GameManager#PauseGameToggleByMenu
var setTimeScale = !ReflectionHelper.GetAttr<UIManager, bool>(self, "ignoreUnpause");
var setTimeScale = !ReflectionHelper.GetField<UIManager, bool>(self, "ignoreUnpause");

// Now we execute the original method, which will potentially set the timescale to 0f
orig(self);
Expand Down Expand Up @@ -145,7 +144,7 @@ private void ImmediateUnpauseIfPaused() {
if (UIManager.instance.uiState.Equals(UIState.PAUSED)) {
var gm = global::GameManager.instance;

ReflectionHelper.GetAttr<global::GameManager, GameCameras>(gm, "gameCams").ResumeCameraShake();
ReflectionHelper.GetField<global::GameManager, GameCameras>(gm, "gameCams").ResumeCameraShake();
gm.inputHandler.PreventPause();
gm.actorSnapshotUnpaused.TransitionTo(0f);
gm.isPaused = false;
Expand Down
11 changes: 7 additions & 4 deletions HKMP/Game/Settings/ModSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Hkmp.Game.Settings {
/**
* Settings file that stores last used addresses and ports
* Settings class that stored user preferences
*/
public class ModSettings : Modding.ModSettings {
public class ModSettings {
public int HideUiKey { get; set; } = 307;

public string JoinAddress { get; set; }
Expand All @@ -11,10 +11,13 @@ public class ModSettings : Modding.ModSettings {

public string Username { get; set; }

public int HostPort { get; set; } = -1;
public int HostPort { get; set; } = 26950;

public bool DisplayPing { get; set; }

public Game.Settings.GameSettings GameSettings { get; set; }
public bool AutoConnectWhenHosting { get; set; } = true;

public GameSettings GameSettings { get; set; }

}
}
10 changes: 9 additions & 1 deletion HKMP/HKMP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HKMP</RootNamespace>
<AssemblyName>HKMP</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -36,6 +36,10 @@
<HintPath>lib\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MMHOOK_Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>lib\MMHOOK_Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="PlayMaker, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>lib\PlayMaker.dll</HintPath>
<Private>False</Private>
Expand All @@ -59,6 +63,10 @@
<HintPath>lib\UnityEngine.ImageConversionModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>lib\UnityEngine.InputLegacyModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.ParticleSystemModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>lib\UnityEngine.ParticleSystemModule.dll</HintPath>
<Private>False</Private>
Expand Down
14 changes: 10 additions & 4 deletions HKMP/Hkmp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

namespace Hkmp {
// Main class of the mod
public class Hkmp : Mod {
public class Hkmp : Mod, IGlobalSettings<ModSettings> {
// Statically create Settings object, so it can be accessed early
private ModSettings _modSettings = new ModSettings();

public Hkmp() : base("HKMP") {
}

public override string GetVersion() {
return Version.String;
}
Expand All @@ -27,9 +30,12 @@ public override void Initialize() {
new Game.GameManager(_modSettings);
}

public override Modding.ModSettings GlobalSettings {
get => _modSettings;
set => _modSettings = (ModSettings) value;
public void OnLoadGlobal(ModSettings modSettings) {
_modSettings = modSettings;
}

public ModSettings OnSaveGlobal() {
return _modSettings;
}
}
}
1 change: 1 addition & 0 deletions HKMP/ModLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Hkmp {
// Singleton class providing methods for logging purposes
public class ModLogger : ILogger {

private static string GetOriginString(object origin) {
if (origin is string s) {
return s;
Expand Down
4 changes: 2 additions & 2 deletions HKMP/Ui/Component/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected Component(ComponentGroup componentGroup, Vector2 position, Vector2 siz
public void SetGroupActive(bool groupActive) {
// TODO: figure out why this could be happening
if (GameObject == null) {
Logger.Get().Error(this,
$"The GameObject belonging to this component (type: {GetType()}) is null, this shouldn't happen");
// Logger.Get().Error(this,
// $"The GameObject belonging to this component (type: {GetType()}) is null, this shouldn't happen");
return;
}

Expand Down
2 changes: 2 additions & 0 deletions HKMP/Ui/Component/IInputComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Hkmp.Ui.Component {
public interface IInputComponent : IComponent {
void SetInput(string input);

string GetInput();
}
}
4 changes: 4 additions & 0 deletions HKMP/Ui/Component/InputComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public InputComponent(
InputField.characterLimit = characterLimit;
}

public void SetInput(string input) {
InputField.text = input;
}

public string GetInput() {
return InputField.text;
}
Expand Down
10 changes: 10 additions & 0 deletions HKMP/Ui/ConnectInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Hkmp.Ui {
public class ConnectInterface {
private const string LocalhostAddress = "127.0.0.1";

private readonly ModSettings _modSettings;
private readonly ClientManager _clientManager;
private readonly ServerManager _serverManager;
Expand Down Expand Up @@ -361,6 +363,14 @@ private void OnStartButtonPressed() {
_serverFeedbackText.SetColor(Color.green);
_serverFeedbackText.SetText("Started server");
_serverFeedbackText.SetActive(true);

// If the setting for automatically connecting when hosting is enabled,
// we connect the client to itself as well
if (_modSettings.AutoConnectWhenHosting) {
_addressInput.SetInput(LocalhostAddress);

OnConnectButtonPressed();
}
}

private void OnStopButtonPressed() {
Expand Down
12 changes: 12 additions & 0 deletions HKMP/Ui/Resources/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ public static void LoadFonts() {
break;
}
}

if (UIFontRegular == null) {
Logger.Get().Error("FontManager", "UI font regular is missing!");
}

if (UIFontBold == null) {
Logger.Get().Error("FontManager", "UI font bold is missing!");
}

if (InGameNameFont == null) {
Logger.Get().Error("FontManager", "In-game name font is missing!");
}
}
}
}
4 changes: 2 additions & 2 deletions HKMP/Ui/UiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ NetClient netClient
// The game is automatically unpaused when the knight dies, so we need
// to disable the UI menu manually
// TODO: this still gives issues, since it displays the cursor while we are supposed to be unpaused
ModHooks.Instance.AfterPlayerDeadHook += () => { pauseMenuGroup.SetActive(false); };

ModHooks.AfterPlayerDeadHook += () => { pauseMenuGroup.SetActive(false); };
MonoBehaviourUtil.Instance.OnUpdateEvent += () => { CheckKeyBinds(pauseMenuGroup); };
}

Expand Down
2 changes: 1 addition & 1 deletion HKMPServer/HKMPServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HKMPServer</RootNamespace>
<AssemblyName>HKMPServer</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
2 changes: 1 addition & 1 deletion HKMPShared/Version.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Hkmp {
public static class Version {
public const string String = "0.7.2";
public const string String = "1.0.0";
}
}

0 comments on commit 04fd20e

Please sign in to comment.