Skip to content

Commit

Permalink
Fix Greenpath Vine platforms not syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Jul 10, 2024
1 parent 9a0eae9 commit 7695736
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
18 changes: 17 additions & 1 deletion HKMP/Fsm/FsmPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Hkmp.Util;
using Hkmp.Logging;
using HutongGames.PlayMaker.Actions;
using Logger = Hkmp.Logging.Logger;

namespace Hkmp.Fsm;

Expand Down Expand Up @@ -55,5 +55,21 @@ private void OnFsmEnable(On.PlayMakerFSM.orig_OnEnable orig, PlayMakerFSM self)
self.RemoveFirstAction<BoolTest>("Check If Nail");
}
}

// Code for modifying the collision check on collapsing floors to include remote players (not working)
// if (self.name.Equals("Collapser Small") && self.Fsm.Name.Equals("collapse small")) {
// self.InsertAction("Idle", new Collision2dEventLayer {
// Enabled = true,
// collideLayer = 9,
// collideTag = new FsmString(),
// sendEvent = FsmEvent.GetFsmEvent("BREAK"),
// storeCollider = new FsmGameObject(),
// storeForce = new FsmFloat()
// }, 7);
// self.RemoveFirstAction<Collision2dEvent>("Idle");
//
// var rigidbody = self.gameObject.AddComponent<Rigidbody2D>();
// rigidbody.isKinematic = true;
// }
}
}
11 changes: 6 additions & 5 deletions HKMP/Game/Client/Save/PersistentFsmData.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using HutongGames.PlayMaker;

namespace Hkmp.Game.Client.Save;
Expand All @@ -12,13 +13,13 @@ internal class PersistentFsmData {
public PersistentItemData PersistentItemData { get; set; }

/// <summary>
/// The FSM variable for an integer. Could be null if a boolean is used instead.
/// The function to get the current integer value. Could be null if a boolean is used instead.
/// </summary>
public FsmInt FsmInt { get; set; }
public Func<int> CurrentInt { get; set; }
/// <summary>
/// The FSM variable for a boolean. Could be null if an integer is used instead.
/// The function to get the current boolean value. Could be null if an integer is used instead.
/// </summary>
public FsmBool FsmBool { get; set; }
public Func<bool> CurrentBool { get; set; }

/// <summary>
/// The last value for the integer if used.
Expand All @@ -32,5 +33,5 @@ internal class PersistentFsmData {
/// <summary>
/// Whether an int is stored for this data.
/// </summary>
public bool IsInt => FsmInt != null;
public bool IsInt => CurrentInt != null;
}
29 changes: 19 additions & 10 deletions HKMP/Game/Client/Save/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void OnSceneChanged(Scene oldScene, Scene newScene) {

var persistentFsmData = new PersistentFsmData {
PersistentItemData = persistentItemData,
FsmInt = fsmInt,
CurrentInt = () => fsmInt.Value,
LastIntValue = fsmInt.Value
};

Expand All @@ -306,18 +306,27 @@ private void OnSceneChanged(Scene oldScene, Scene newScene) {

Logger.Info($"Found persistent bool in scene: {persistentItemData}");

Func<bool> currentBoolFunc = null;

var fsm = FSMUtility.FindFSMWithPersistentBool(itemObject.GetComponents<PlayMakerFSM>());
if (fsm == null) {
Logger.Info(" Could not find FSM belonging to persistent bool object, skipping");
continue;
if (fsm != null) {
var fsmBool = fsm.FsmVariables.GetFsmBool("Activated");
currentBoolFunc = () => fsmBool.Value;
}

var fsmBool = fsm.FsmVariables.GetFsmBool("Activated");
var vinePlatform = itemObject.GetComponent<VinePlatform>();
if (vinePlatform != null) {
currentBoolFunc = () => ReflectionHelper.GetField<VinePlatform, bool>(vinePlatform, "activated");
}

if (currentBoolFunc == null) {
continue;
}

var persistentFsmData = new PersistentFsmData {
PersistentItemData = persistentItemData,
FsmBool = fsmBool,
LastBoolValue = fsmBool.Value
CurrentBool = currentBoolFunc,
LastBoolValue = currentBoolFunc.Invoke()
};

_persistentFsmData.Add(persistentFsmData);
Expand Down Expand Up @@ -347,7 +356,7 @@ private void OnSceneChanged(Scene oldScene, Scene newScene) {

var persistentFsmData = new PersistentFsmData {
PersistentItemData = persistentItemData,
FsmInt = fsmInt,
CurrentInt = () => fsmInt.Value,
LastIntValue = fsmInt.Value
};

Expand Down Expand Up @@ -408,7 +417,7 @@ private void OnUpdatePersistents() {
}

if (persistentFsmData.IsInt) {
var value = persistentFsmData.FsmInt.Value;
var value = persistentFsmData.CurrentInt.Invoke();
if (value == persistentFsmData.LastIntValue) {
continue;
}
Expand Down Expand Up @@ -469,7 +478,7 @@ private void OnUpdatePersistents() {
Logger.Info("Cannot find persistent int/geo rock data bool, not sending save update");
}
} else {
var value = persistentFsmData.FsmBool.Value;
var value = persistentFsmData.CurrentBool.Invoke();
if (value == persistentFsmData.LastBoolValue) {
continue;
}
Expand Down

0 comments on commit 7695736

Please sign in to comment.