Compare commits

..
8 Commits
Author SHA1 Message Date
Atony f9096b6160 Merge pull request #69 from All-Of-Us-Mods/dev
MiraAPI v0.3.1
2025-09-28 13:17:06 -05:00
Atony 8bf101534f Bump version 2025-09-28 13:13:21 -05:00
Atony 479323acdd Merge pull request #68 from yanpla/dev
Fix DetectiveNotesMinigame
2025-09-28 13:06:21 -05:00
Atony 50c5899f4d Merge branch 'dev' into dev 2025-09-28 13:06:12 -05:00
XtraCube fd719ae42f Merge remote-tracking branch 'origin/dev' into dev 2025-09-26 12:18:18 -04:00
XtraCube e050b043cb use reflection for intro cutscene patches 2025-09-26 12:18:13 -04:00
yanpla b5fe3c7afd Remove custom roles from DetectiveNotesMinigame 2025-09-24 19:53:24 +02:00
XtraCube 1750cd3db9 Merge pull request #67 from All-Of-Us-Mods/dev
0.3.0
2025-09-24 08:54:52 -04:00
5 changed files with 189 additions and 20 deletions

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<VersionPrefix>0.3.0</VersionPrefix>
<VersionPrefix>0.3.1</VersionPrefix>
<VersionSuffix>dev</VersionSuffix>
<Authors>All Of Us, XtraCube, Angxl</Authors>
@@ -0,0 +1,44 @@
using System.Linq;
using AmongUs.GameOptions;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using MiraAPI.Roles;
using UnityEngine;
namespace MiraAPI.Patches;
[HarmonyPatch(typeof(DetectiveNotesMinigame), nameof(DetectiveNotesMinigame.OpenBodyPopup))]
public static class DetectiveNotesMinigamePatch
{
public static void Prefix(DetectiveNotesMinigame __instance, bool active)
{
__instance.impostorTypePopup.SetActive(active);
if (!active)
{
ControllerManager.Instance.CloseOverlayMenu(__instance.ImpostorOverlay);
ControllerManager.Instance.SetUpSelectables(ControllerManager.Instance.CurrentUiState, __instance.ControllerSelectable[0], __instance.ControllerSelectable);
ControllerManager.Instance.SetCurrentSelected(__instance.ControllerSelectable[2]);
return;
}
if (__instance.impostorButton != null)
{
ControllerManager.Instance.OpenOverlayMenu(__instance.ImpostorOverlay, null, __instance.ImpostorIconControllerSelectables[0], __instance.ImpostorIconControllerSelectables, false);
return;
}
__instance.impostorButton = new List<GameObject>();
int num = 0;
var allRoles = DestroyableSingleton<RoleManager>.Instance.AllRoles;
var customRoles = CustomRoleManager.CustomRoleBehaviours;
foreach (var role in allRoles)
{
if (role.TeamType != RoleTeamTypes.Impostor || role.Role == RoleTypes.ImpostorGhost || customRoles.Contains(role) )
continue;
GameObject gameObject = Object.Instantiate<GameObject>(__instance.impostorTypePrefab, __instance.impostorTypeParent);
__instance.impostorButton.Add(gameObject);
gameObject.GetComponent<DetectiveImpostorType>().Initialize(__instance, role);
num++;
__instance.ImpostorIconControllerSelectables.Add(gameObject.GetComponent<PassiveButton>());
}
ControllerManager.Instance.OpenOverlayMenu(__instance.ImpostorOverlay, null, __instance.ImpostorIconControllerSelectables[0], __instance.ImpostorIconControllerSelectables, false);
}
}
+73 -16
View File
@@ -1,8 +1,12 @@
using HarmonyLib;
using System.Linq;
using System.Reflection;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using MiraAPI.Events;
using MiraAPI.Events.Vanilla.Gameplay;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using Reactor.Utilities;
namespace MiraAPI.Patches;
@@ -29,14 +33,29 @@ public static class IntroCutscenePatches
MiraEventManager.InvokeEvent(@event);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(IntroCutscene._ShowRole_d__41), nameof(IntroCutscene._ShowRole_d__41.MoveNext))]
[HarmonyPriority(Priority.Last)]
public static void ShowRolePatch(IntroCutscene._ShowRole_d__41 __instance)
[HarmonyPatch]
public static class IntroCutsceneShowRolePatch
{
var realInstance = __instance.__4__this;
var @event = new IntroRoleRevealEvent(realInstance);
MiraEventManager.InvokeEvent(@event);
public static MethodBase TargetMethod()
{
return Helpers.GetStateMachineMoveNext<IntroCutscene>("ShowRole")!;
}
public static void Postfix(Il2CppObjectBase __instance)
{
var wrapper = new StateMachineWrapper<IntroCutscene>(__instance);
// run before the first yield
if (wrapper.GetState() != 1)
{
return;
}
var introCutscene = wrapper.Instance;
Logger<MiraApiPlugin>.Info("IntroCutscene ShowRole reached");
var @event = new IntroRoleRevealEvent(introCutscene);
MiraEventManager.InvokeEvent(@event);
}
}
[HarmonyPrefix]
@@ -66,16 +85,54 @@ public static class IntroCutscenePatches
}
}
[HarmonyPostfix]
[HarmonyPatch(nameof(IntroCutscene.OnDestroy))]
public static void GameBeginPatch(IntroCutscene __instance)
[HarmonyPatch]
public static class IntroCutsceneDestroyPatch
{
MiraEventManager.InvokeEvent(new IntroEndEvent(__instance));
private static bool _usedFallback;
var @event = new BeforeRoundStartEvent(true);
MiraEventManager.InvokeEvent(@event);
public static MethodBase TargetMethod()
{
var onDestroy = AccessTools.Method(typeof(IntroCutscene), "OnDestroy");
if (onDestroy != null)
{
_usedFallback = false;
Logger<MiraApiPlugin>.Info("Using OnDestroy for IntroCutsceneDestroyPatch");
return onDestroy;
}
if (@event.IsCancelled) return;
MiraEventManager.InvokeEvent(new RoundStartEvent(true));
_usedFallback = true;
return Helpers.GetStateMachineMoveNext<IntroCutscene>("CoBegin")!;
}
public static void Postfix(Il2CppObjectBase __instance)
{
IntroCutscene introCutscene;
if (_usedFallback)
{
var wrapper = new StateMachineWrapper<IntroCutscene>(__instance);
// run after the final yield
if (wrapper.GetState() != -1)
{
return;
}
introCutscene = wrapper.Instance;
}
else
{
introCutscene = __instance.Cast<IntroCutscene>();
}
Logger<MiraApiPlugin>.Info("IntroCutscene ended");
MiraEventManager.InvokeEvent(new IntroEndEvent(introCutscene));
var @event = new BeforeRoundStartEvent(true);
MiraEventManager.InvokeEvent(@event);
if (@event.IsCancelled) return;
MiraEventManager.InvokeEvent(new RoundStartEvent(true));
}
}
}
+29 -3
View File
@@ -1,15 +1,16 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MiraAPI.Keybinds;
using MiraAPI.Roles;
using MiraAPI.Utilities.Assets;
using Reactor.Utilities;
using Rewired;
using TMPro;
using UnityEngine;
using MethodBase = System.Reflection.MethodBase;
using Object = UnityEngine.Object;
namespace MiraAPI.Utilities;
@@ -38,6 +39,31 @@ public static class Helpers
return keybindIcon;
}
public static MethodBase? GetStateMachineMoveNext<T>(string methodName)
{
var typeName = typeof(T).FullName;
var showRoleStateMachine =
typeof(T)
.GetNestedTypes()
.FirstOrDefault(x=>x.Name.Contains(methodName));
if (showRoleStateMachine == null)
{
Logger<MiraApiPlugin>.Error($"Failed to find {methodName} state machine for {typeName}");
return null;
}
var moveNext = AccessTools.Method(showRoleStateMachine, "MoveNext");
if (moveNext == null)
{
Logger<MiraApiPlugin>.Error($"Failed to find MoveNext method for {typeName}.{methodName}");
return null;
}
Logger<MiraApiPlugin>.Info($"Found {methodName}.MoveNext");
return moveNext;
}
/// <summary>
/// Creates a draggable scroller. Add items into the scroller.Inner transform. This does not automatically position children.
/// </summary>
+42
View File
@@ -0,0 +1,42 @@
using System.Reflection;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
namespace MiraAPI.Utilities;
/// <summary>
/// A wrapper for state machine objects to access their parent instance and state.
/// </summary>
/// <typeparam name="T">The type of the parent class that owns the state machine.</typeparam>
public class StateMachineWrapper<T> where T : Il2CppObjectBase
{
private readonly Il2CppObjectBase _stateMachine;
private readonly PropertyInfo _thisProperty;
private readonly PropertyInfo _stateProperty;
private T? _parentInstance;
/// <summary>
/// Gets the instance of the parent class that owns the state machine.
/// </summary>
public T Instance => _parentInstance ??= (T)_thisProperty.GetValue(_stateMachine)!;
/// <summary>
/// Initializes a new instance of the <see cref="StateMachineWrapper{T}"/> class.
/// </summary>
/// <param name="stateMachine">The state machine instance to wrap.</param>
public StateMachineWrapper(Il2CppObjectBase stateMachine)
{
_stateMachine = stateMachine;
var type = _stateMachine.GetType();
_thisProperty = AccessTools.Property(type, "__4__this");
_stateProperty = AccessTools.Property(type, "__1__state");
}
/// <summary>
/// Gets the current state of the state machine.
/// </summary>
/// <returns>The current state as an integer.</returns>
public int GetState() => (int)_stateProperty.GetValue(_stateMachine)!;
}