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. ///