Add methods for StateMachineWrapper

This commit is contained in:
Atony committed 2026-04-03 09:46:44 -05:00
1 parent d89bce6956
commit 00a60bb7ad
2 files changed
+17 -2

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<VersionPrefix>0.3.8</VersionPrefix> <VersionPrefix>0.3.9</VersionPrefix>
<VersionSuffix>dev</VersionSuffix> <VersionSuffix>dev</VersionSuffix>
<Authors>All Of Us, XtraCube, Angxl</Authors> <Authors>All Of Us, XtraCube, Angxl</Authors>
+16 -1
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using HarmonyLib; using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes;
using Object = Il2CppSystem.Object;
namespace MiraAPI.Utilities; namespace MiraAPI.Utilities;
@@ -17,6 +18,7 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
// normally it is fields, but IL2CPP turns them into properties // normally it is fields, but IL2CPP turns them into properties
private readonly PropertyInfo _thisProperty; private readonly PropertyInfo _thisProperty;
private readonly PropertyInfo _stateProperty; private readonly PropertyInfo _stateProperty;
private readonly PropertyInfo _currentProperty;
private readonly Dictionary<string, PropertyInfo> _propertyCache; private readonly Dictionary<string, PropertyInfo> _propertyCache;
private T? _parentInstance; private T? _parentInstance;
@@ -37,8 +39,9 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
var type = _stateMachine.GetType(); var type = _stateMachine.GetType();
_thisProperty = AccessTools.Property(type, "__4__this"); _thisProperty = AccessTools.Property(type, "__4__this");
_stateProperty = AccessTools.Property(type, "__1__state"); _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}'."); throw new MissingMemberException($"Could not find required properties in type '{type}'.");
} }
@@ -52,6 +55,18 @@ public class StateMachineWrapper<T> where T : Il2CppObjectBase
/// <returns>The current state as an integer.</returns> /// <returns>The current state as an integer.</returns>
public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!; public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!;
/// <summary>
/// Sets the current state of the state machine.
/// </summary>
/// <param name="newState">The new state to use.</param>
public void SetState(int newState) => _stateProperty.SetValue(_stateMachine, newState);
/// <summary>
/// Sets the newest yield return of the state machine.
/// </summary>
/// <param name="newReturn">The new return to use.</param>
public void SetRecentReturn(Object newReturn) => _currentProperty.SetValue(_stateMachine, newReturn);
/// <summary> /// <summary>
/// Gets a parameter from the state machine by its name. /// Gets a parameter from the state machine by its name.
/// </summary> /// </summary>