From 00a60bb7ad0b6d56422b2a14d43aa98ae89f6dbb Mon Sep 17 00:00:00 2001
From: Atony <75191600+AtonyGit@users.noreply.github.com>
Date: Fri, 3 Apr 2026 09:46:44 -0500
Subject: [PATCH] Add methods for StateMachineWrapper
---
Directory.Build.props | 2 +-
MiraAPI/Utilities/StateMachineWrapper.cs | 17 ++++++++++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index 4b87d91..a729bf5 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -8,7 +8,7 @@
true
- 0.3.8
+ 0.3.9
dev
All Of Us, XtraCube, Angxl
diff --git a/MiraAPI/Utilities/StateMachineWrapper.cs b/MiraAPI/Utilities/StateMachineWrapper.cs
index a760e8e..e590f57 100644
--- a/MiraAPI/Utilities/StateMachineWrapper.cs
+++ b/MiraAPI/Utilities/StateMachineWrapper.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
+using Object = Il2CppSystem.Object;
namespace MiraAPI.Utilities;
@@ -17,6 +18,7 @@ public class StateMachineWrapper where T : Il2CppObjectBase
// normally it is fields, but IL2CPP turns them into properties
private readonly PropertyInfo _thisProperty;
private readonly PropertyInfo _stateProperty;
+ private readonly PropertyInfo _currentProperty;
private readonly Dictionary _propertyCache;
private T? _parentInstance;
@@ -37,8 +39,9 @@ public class StateMachineWrapper where T : Il2CppObjectBase
var type = _stateMachine.GetType();
_thisProperty = AccessTools.Property(type, "__4__this");
_stateProperty = AccessTools.Property(type, "__1__state");
+ _currentProperty = AccessTools.Property(type, "__2__current");
- if (_thisProperty == null || _stateProperty == null)
+ if (_thisProperty == null || _stateProperty == null || _currentProperty == null)
{
throw new MissingMemberException($"Could not find required properties in type '{type}'.");
}
@@ -52,6 +55,18 @@ public class StateMachineWrapper where T : Il2CppObjectBase
/// The current state as an integer.
public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!;
+ ///
+ /// Sets the current state of the state machine.
+ ///
+ /// The new state to use.
+ public void SetState(int newState) => _stateProperty.SetValue(_stateMachine, newState);
+
+ ///
+ /// Sets the newest yield return of the state machine.
+ ///
+ /// The new return to use.
+ public void SetRecentReturn(Object newReturn) => _currentProperty.SetValue(_stateMachine, newReturn);
+
///
/// Gets a parameter from the state machine by its name.
///