mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
Merge branch 'dev' of https://github.com/All-Of-Us-Mods/MiraAPI into dev
This commit is contained in:
commit
93e8b9ae4e
25 files changed
+123
-103
No files matched your search
@@ -72,18 +72,18 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu<CustomPaginableMenu.
|
||||
nextButton.transform.localScale = new Vector3(0.65f, 0.65f, 1);
|
||||
nextButton.name = "RightArrowButton";
|
||||
nextButton.GetComponent<SpriteRenderer>().sprite = MiraAssets.NextButton.LoadAsset();
|
||||
nextButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
nextButton.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
|
||||
var passiveButton = nextButton.gameObject.GetComponent<PassiveButton>();
|
||||
var passiveButton = nextButton.GetComponent<PassiveButton>();
|
||||
passiveButton.OnClick = new Button.ButtonClickedEvent();
|
||||
passiveButton.OnClick.AddListener((UnityAction)customMenu.NextPage);
|
||||
|
||||
var backButton = Object.Instantiate(nextButton, customMenu.transform).gameObject;
|
||||
backButton.transform.localPosition = new Vector3(-1.85f, -2.185f, customMenu.MenuDepth);
|
||||
backButton.name = "LeftArrowButton";
|
||||
backButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
backButton.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
backButton.GetComponent<SpriteRenderer>().flipX = true;
|
||||
var prevPassive = backButton.gameObject.GetComponent<PassiveButton>();
|
||||
var prevPassive = backButton.GetComponent<PassiveButton>();
|
||||
prevPassive.OnClick.AddListener((UnityAction)customMenu.PreviousPage);
|
||||
|
||||
customMenu.PhoneUI.GetChild(0).GetComponent<SpriteRenderer>().material =
|
||||
|
||||
@@ -260,7 +260,7 @@ public abstract class CustomPhoneMenu : ICustomMenu
|
||||
MenuEntries.Add(menuEntry);
|
||||
|
||||
var button = shapeshifterPanel.Button;
|
||||
var nameplate = shapeshifterPanel.gameObject.transform.FindChild("Nameplate");
|
||||
var nameplate = shapeshifterPanel.transform.FindChild("Nameplate");
|
||||
var highlight = nameplate.FindChild("Highlight").GetComponent<SpriteRenderer>();
|
||||
var icon = highlight.transform.GetChild(0).GetComponent<SpriteRenderer>();
|
||||
|
||||
@@ -317,7 +317,7 @@ public abstract class CustomPhoneMenu : ICustomMenu
|
||||
{
|
||||
ShapeshifterPanel panel = menuEntry.Panel;
|
||||
|
||||
var nameplate = panel.gameObject.transform.FindChild("Nameplate");
|
||||
var nameplate = panel.transform.FindChild("Nameplate");
|
||||
var highlight = nameplate.FindChild("Highlight").GetComponent<SpriteRenderer>();
|
||||
var icon = highlight.transform.GetChild(0).GetComponent<SpriteRenderer>();
|
||||
if (sprite != null)
|
||||
|
||||
@@ -89,7 +89,7 @@ public abstract class TargetedMeetingButton
|
||||
if (MeetingHud.Instance == null) return null!;
|
||||
|
||||
var btn = Object.Instantiate(MeetingHud.Instance.PlayerButtonPrefab.ConfirmButton).GetComponent<PassiveButton>();
|
||||
btn.gameObject.name = Name + "Button";
|
||||
btn.name = Name + "Button";
|
||||
|
||||
var spriteRenderer = btn.GetComponent<SpriteRenderer>();
|
||||
spriteRenderer.sprite = Sprite.LoadAsset();
|
||||
|
||||
@@ -144,15 +144,15 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
|
||||
if (button.transform.name.Contains("Friends List Button"))
|
||||
{
|
||||
button.gameObject.transform.localScale = new Vector3(0.2675f * actualScaleVal, 0.2675f * actualScaleVal, 1);
|
||||
button.transform.localScale = new Vector3(0.2675f * actualScaleVal, 0.2675f * actualScaleVal, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
button.gameObject.transform.localScale = actualScale;
|
||||
button.transform.localScale = actualScale;
|
||||
}
|
||||
|
||||
baseGrid.CellSize = new Vector2(alteredScale, alteredScale);
|
||||
if (baseGrid.gameObject.transform.childCount != 0)
|
||||
if (baseGrid.transform.childCount != 0)
|
||||
{
|
||||
baseGrid.ArrangeChilds();
|
||||
}
|
||||
@@ -175,15 +175,15 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
|
||||
if (button.transform.name.Contains("Modifiers"))
|
||||
{
|
||||
button.gameObject.transform.localScale = new Vector3(0.65f * scaleFactor, 0.65f * scaleFactor, 1);
|
||||
button.transform.localScale = new Vector3(0.65f * scaleFactor, 0.65f * scaleFactor, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
button.gameObject.transform.localScale = actualScale;
|
||||
button.transform.localScale = actualScale;
|
||||
}
|
||||
|
||||
extraGrid.CellSize = new Vector2(alteredScale, alteredScale);
|
||||
if (extraGrid.gameObject.transform.childCount != 0)
|
||||
if (extraGrid.transform.childCount != 0)
|
||||
{
|
||||
extraGrid.ArrangeChilds();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ModifierUiComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
icon = modBg.transform.GetChild(1).GetComponent<SpriteRenderer>();
|
||||
var nameBg = transform.GetChild(1);
|
||||
nameText = nameBg.GetChild(0).GetComponent<TextMeshPro>();
|
||||
descRect = desc.gameObject.GetComponent<RectTransform>();
|
||||
descRect = desc.GetComponent<RectTransform>();
|
||||
|
||||
nameText.font = desc.font = HudManager.Instance.TaskPanel.taskText.font;
|
||||
nameText.fontMaterial = desc.fontMaterial = HudManager.Instance.TaskPanel.taskText.fontMaterial;
|
||||
|
||||
@@ -1,23 +1,35 @@
|
||||
using HarmonyLib;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using InnerNet;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Player;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
/// <summary>
|
||||
/// Sync all settings to the player when they join the game.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(AmongUsClient))]
|
||||
[HarmonyPatch]
|
||||
internal static class AmongUsClientSyncPatch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CreatePlayer))]
|
||||
public static void CreatePlayerPatch(ClientData clientData)
|
||||
public static MethodBase TargetMethod()
|
||||
{
|
||||
return Helpers.GetStateMachineMoveNext<AmongUsClient>(nameof(AmongUsClient.CreatePlayer))!;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
public static void CreatePlayerPatch(Il2CppObjectBase __instance, bool __result)
|
||||
{
|
||||
if (__result)
|
||||
return;
|
||||
|
||||
var wrapper = new StateMachineWrapper<AmongUsClient>(__instance);
|
||||
var clientData = wrapper.GetParameter<ClientData>("clientData");
|
||||
var joinEvent = new PlayerJoinEvent(clientData);
|
||||
MiraEventManager.InvokeEvent(joinEvent);
|
||||
|
||||
@@ -35,9 +47,12 @@ internal static class AmongUsClientSyncPatch
|
||||
CustomRoleManager.SyncAllRoleSettings(clientData.Id);
|
||||
GameModeOption.RpcSyncGamemode(PlayerControl.LocalPlayer, GameModeOption.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerLeft))]
|
||||
internal static class AmongUsClientSyncPatch2
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerLeft))]
|
||||
public static void PlayerLeftPatch(ClientData data, DisconnectReasons reason)
|
||||
{
|
||||
var leftEvent = new PlayerLeaveEvent(data, reason);
|
||||
|
||||
@@ -111,8 +111,7 @@ public static class TaskAdderPatches
|
||||
|
||||
if (plugin.InternalModifiers.Exists(x => x.ShowInFreeplay))
|
||||
{
|
||||
__instance.CreateFolder(plugin.PluginInfo.Metadata.Name, modifiersFolder)
|
||||
.gameObject.name = plugin.PluginId;
|
||||
__instance.CreateFolder(plugin.PluginInfo.Metadata.Name, modifiersFolder).name = plugin.PluginId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ internal static class HudPatches
|
||||
yield return new WaitUntil((Il2CppSystem.Func<bool>)(() => GameManager.Instance != null));
|
||||
if (GameManager.Instance.IsHideAndSeek())
|
||||
yield return null;
|
||||
var infoPane = instance.gameObject.transform.FindChild("LobbyInfoPane");
|
||||
var aspect = infoPane.gameObject.transform.Find("AspectSize");
|
||||
var infoPane = instance.transform.FindChild("LobbyInfoPane");
|
||||
var aspect = infoPane.transform.Find("AspectSize");
|
||||
var modeLabel = aspect!.Find("ModeLabel");
|
||||
var modeValue = aspect.Find("ModeValue");
|
||||
var modelText = modeLabel!.Find("Text_TMP").gameObject;
|
||||
|
||||
@@ -47,9 +47,9 @@ public static class HudManagerPatches
|
||||
{
|
||||
if (!aspect.gameObject) continue;
|
||||
|
||||
if (aspect.gameObject.transform.parent.name == "TopRight") continue;
|
||||
if (aspect.transform.parent.name == "TopRight") continue;
|
||||
|
||||
if (aspect.gameObject.name.Contains("TopRight")) continue;
|
||||
if (aspect.name.Contains("TopRight")) continue;
|
||||
|
||||
aspect.gameObject.SetActive(!aspect.isActiveAndEnabled);
|
||||
aspect.DistanceFromEdge *= new Vector2(scaleFactor, scaleFactor);
|
||||
@@ -62,7 +62,7 @@ public static class HudManagerPatches
|
||||
if (!button.gameObject) continue;
|
||||
|
||||
button.gameObject.SetActive(!button.isActiveAndEnabled);
|
||||
button.gameObject.transform.localScale *= scaleFactor;
|
||||
button.transform.localScale *= scaleFactor;
|
||||
button.gameObject.SetActive(!button.isActiveAndEnabled);
|
||||
}
|
||||
|
||||
@@ -71,12 +71,12 @@ public static class HudManagerPatches
|
||||
{
|
||||
if (!arrange.gameObject || !arrange.transform) continue;
|
||||
|
||||
if (arrange.gameObject.name.Contains("TopRight")) continue;
|
||||
if (arrange.name.Contains("TopRight")) continue;
|
||||
|
||||
arrange.gameObject.SetActive(!arrange.isActiveAndEnabled);
|
||||
arrange.CellSize = new Vector2(scaleFactor, scaleFactor);
|
||||
arrange.gameObject.SetActive(!arrange.isActiveAndEnabled);
|
||||
if (!arrange.isActiveAndEnabled || arrange.gameObject.transform.childCount == 0) continue;
|
||||
if (!arrange.isActiveAndEnabled || arrange.transform.childCount == 0) continue;
|
||||
try
|
||||
{
|
||||
arrange.ArrangeChilds();
|
||||
|
||||
@@ -313,7 +313,7 @@ internal static class GameOptionsMenuPatch
|
||||
};
|
||||
_modIcon = modIconObj.AddComponent<SpriteRenderer>();
|
||||
_modIcon.sprite = MiraAssets.BlankSprite.LoadAsset();
|
||||
_modIcon.material = gamemodeBg.gameObject.GetComponent<SpriteRenderer>().material;
|
||||
_modIcon.material = gamemodeBg.GetComponent<SpriteRenderer>().material;
|
||||
|
||||
var gamemodeTextObj = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(1).gameObject, modeInfoHolder);
|
||||
gamemodeTextObj.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
|
||||
@@ -739,7 +739,7 @@ internal static class GameOptionsMenuPatch
|
||||
var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform);
|
||||
newText.text = $"<size=70%>({"MiraApi.GameSetting.Global.ClickToClose".Translate()})</size>";
|
||||
newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f);
|
||||
newText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
newText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
|
||||
var boxCol = categoryHeaderMasked.gameObject.AddComponent<BoxCollider2D>();
|
||||
boxCol.size = new Vector2(7, 0.7f);
|
||||
|
||||
@@ -164,7 +164,7 @@ internal static class GamePresetsTabPatches
|
||||
return;
|
||||
}
|
||||
|
||||
var tmpTranslator = presetTab.PresetDescriptionText.gameObject.GetComponent<TextTranslatorTMP>();
|
||||
var tmpTranslator = presetTab.PresetDescriptionText.GetComponent<TextTranslatorTMP>();
|
||||
if (tmpTranslator)
|
||||
{
|
||||
tmpTranslator.Destroy();
|
||||
@@ -184,7 +184,7 @@ internal static class GamePresetsTabPatches
|
||||
{
|
||||
saveButton = Object.Instantiate(prefab, presetTab.transform);
|
||||
_saveButton = saveButton.gameObject;
|
||||
_saveButton.gameObject.name = "SaveButton";
|
||||
_saveButton.name = "SaveButton";
|
||||
_saveButton.transform.localPosition = new Vector3(3.2f, 1.7f, -2);
|
||||
|
||||
// set the button text and alignment
|
||||
@@ -282,7 +282,7 @@ internal static class GamePresetsTabPatches
|
||||
_folderButton.name = "OpenFolderButton";
|
||||
_folderButton.transform.localPosition = new Vector3(3.55f, 1.1f, -2);
|
||||
|
||||
var folderRend = openFolderButton.transform.FindChild("Sprite").gameObject.GetComponent<SpriteRenderer>();
|
||||
var folderRend = openFolderButton.transform.FindChild("Sprite").GetComponent<SpriteRenderer>();
|
||||
folderRend.sprite = MiraAssets.FolderIcon.LoadAsset();
|
||||
folderRend.transform.localScale = new Vector3(0.4f, 0.4f, 1);
|
||||
|
||||
|
||||
@@ -20,9 +20,10 @@ internal static class GameSettingMenuPatches
|
||||
}
|
||||
|
||||
// Add Menu State object
|
||||
if (!__instance.gameObject.GetComponent<MenuState>())
|
||||
__instance.gameObject.GetOrAddComponent<MenuState>(out var existed);
|
||||
|
||||
if (!existed)
|
||||
{
|
||||
__instance.gameObject.AddComponent<MenuState>();
|
||||
Info("MenuState component added to GameSettingMenu.");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -72,7 +72,7 @@ public static class LobbyViewPanePatches
|
||||
|
||||
// create modifiers button
|
||||
modifiersTabButton = Object.Instantiate(__instance.rolesTabButton, __instance.rolesTabButton.transform.parent);
|
||||
modifiersTabButton.buttonText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
modifiersTabButton.buttonText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
modifiersTabButton.name = "ModifiersTabButton";
|
||||
var pos = modifiersTabButton.transform.localPosition;
|
||||
pos.x = 2.1f;
|
||||
@@ -101,7 +101,7 @@ public static class LobbyViewPanePatches
|
||||
hover.transform.localPosition = new Vector3(0, 0f, 0.3f);
|
||||
hover.sprite = MiraAssets.NextButtonActive.LoadAsset();
|
||||
|
||||
var passiveButton = nextButton.gameObject.GetComponent<PassiveButton>();
|
||||
var passiveButton = nextButton.GetComponent<PassiveButton>();
|
||||
passiveButton.OnClick = new Button.ButtonClickedEvent();
|
||||
passiveButton.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
@@ -123,7 +123,7 @@ public static class LobbyViewPanePatches
|
||||
= backButton.transform.FindChild("Hover").gameObject.GetComponentInChildren<SpriteRenderer>().flipX
|
||||
= true;
|
||||
|
||||
var passiveButton2 = backButton.gameObject.GetComponent<PassiveButton>();
|
||||
var passiveButton2 = backButton.GetComponent<PassiveButton>();
|
||||
passiveButton2.OnClick = new Button.ButtonClickedEvent();
|
||||
passiveButton2.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
|
||||
@@ -121,24 +121,24 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
var nextButton = Instantiate(Gsm.BackButton, Gsm.BackButton.transform.parent).gameObject;
|
||||
nextButton.transform.localPosition = new Vector3(-2.2663f, 1.5272f, -25f);
|
||||
nextButton.name = "RightArrowButton";
|
||||
nextButton.transform.FindChild("Inactive").gameObject.GetComponent<SpriteRenderer>().sprite =
|
||||
nextButton.transform.FindChild("Inactive").GetComponent<SpriteRenderer>().sprite =
|
||||
MiraAssets.NextButton.LoadAsset();
|
||||
nextButton.transform.FindChild("Active").gameObject.GetComponent<SpriteRenderer>().sprite =
|
||||
nextButton.transform.FindChild("Active").GetComponent<SpriteRenderer>().sprite =
|
||||
MiraAssets.NextButtonActive.LoadAsset();
|
||||
nextButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
nextButton.GetComponent<CloseButtonConsoleBehaviour>().DestroyImmediate();
|
||||
|
||||
var nextPassiveButton = nextButton.gameObject.GetComponent<PassiveButton>();
|
||||
var nextPassiveButton = nextButton.GetComponent<PassiveButton>();
|
||||
nextPassiveButton.OnClick = new Button.ButtonClickedEvent();
|
||||
nextPassiveButton.OnClick.AddListener((UnityAction)NextMod);
|
||||
|
||||
var previousButton = Instantiate(nextButton, Gsm.BackButton.transform.parent).gameObject;
|
||||
previousButton.transform.localPosition = new Vector3(-4.4209f, 1.5272f, -25f);
|
||||
previousButton.name = "LeftArrowButton";
|
||||
previousButton.gameObject.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
previousButton.transform.FindChild("Active").gameObject.GetComponent<SpriteRenderer>().flipX =
|
||||
previousButton.transform.FindChild("Inactive").gameObject.GetComponent<SpriteRenderer>().flipX = true;
|
||||
previousButton.GetComponent<CloseButtonConsoleBehaviour>().Destroy();
|
||||
previousButton.transform.FindChild("Active").GetComponent<SpriteRenderer>().flipX =
|
||||
previousButton.transform.FindChild("Inactive").GetComponent<SpriteRenderer>().flipX = true;
|
||||
|
||||
var prevPassiveButton = previousButton.gameObject.GetComponent<PassiveButton>();
|
||||
var prevPassiveButton = previousButton.GetComponent<PassiveButton>();
|
||||
prevPassiveButton.OnClick = new Button.ButtonClickedEvent();
|
||||
prevPassiveButton.OnClick.AddListener((UnityAction)PreviousMod);
|
||||
|
||||
@@ -149,7 +149,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
var mBtn = Instantiate(Gsm.RoleSettingsButton, Gsm.RoleSettingsButton.transform.parent);
|
||||
_largeButtons[MenuButton.Modifiers] = mBtn;
|
||||
mBtn.name = "ModifiersButton";
|
||||
mBtn.buttonText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
mBtn.buttonText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
mBtn.buttonText.text = "Modifiers".Translate();
|
||||
mBtn.OnClick = new Button.ButtonClickedEvent();
|
||||
mBtn.OnClick.AddListener(
|
||||
@@ -168,7 +168,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
var c1Btn = Instantiate(mBtn, mBtn.transform.parent);
|
||||
_largeButtons[MenuButton.CustomOne] = c1Btn;
|
||||
c1Btn.name = "CustomOneButton";
|
||||
c1Btn.buttonText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
c1Btn.buttonText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
c1Btn.OnClick = new Button.ButtonClickedEvent();
|
||||
c1Btn.OnClick.AddListener(
|
||||
(UnityAction)(() =>
|
||||
@@ -322,7 +322,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
// Create game options container
|
||||
var gameContainer = Containers[MenuCategory.Game][idx + 1] = Instantiate(
|
||||
Gsm.GameSettingsTab.settingsContainer.gameObject,
|
||||
Gsm.GameSettingsTab.settingsContainer.gameObject.transform.parent);
|
||||
Gsm.GameSettingsTab.settingsContainer.transform.parent);
|
||||
gameContainer.name = $"GameSettings_{mod.PluginInfo.Metadata.Name}";
|
||||
gameContainer.transform.DestroyChildren();
|
||||
gameContainer.SetActive(false);
|
||||
@@ -340,7 +340,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
var cont = Containers[i][idx + 1] = Instantiate(
|
||||
Gsm.GameSettingsTab.settingsContainer.gameObject,
|
||||
Gsm.GameSettingsTab.settingsContainer.gameObject.transform.parent);
|
||||
Gsm.GameSettingsTab.settingsContainer.transform.parent);
|
||||
cont.name = $"{i}_{mod.PluginInfo.Metadata.Name}";
|
||||
cont.transform.DestroyChildren();
|
||||
cont.SetActive(false);
|
||||
|
||||
@@ -309,7 +309,7 @@ public static class RoleSettingMenuPatches
|
||||
var newText = Object.Instantiate(categoryHeaderMasked.Title, categoryHeaderMasked.transform);
|
||||
newText.text = $"<size=70%>{label}</size>";
|
||||
newText.transform.localPosition = new Vector3(2.6249f, -0.165f, 0f);
|
||||
newText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
newText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
|
||||
scrollerNum -= 0.422f;
|
||||
|
||||
@@ -604,14 +604,14 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
var categoryHeaderMasked = __instance.AdvancedRolesSettings.transform.Find("CategoryHeaderMasked").GetComponent<CategoryHeaderMasked>();
|
||||
|
||||
if (categoryHeaderMasked.Title.gameObject.TryGetComponent<TextTranslatorTMP>(out var comp))
|
||||
if (categoryHeaderMasked.Title.TryGetComponent<TextTranslatorTMP>(out var comp))
|
||||
{
|
||||
comp.Destroy();
|
||||
}
|
||||
|
||||
categoryHeaderMasked.Title.text = "MiraApi.ReturnToRoleSettings".Translate();
|
||||
|
||||
if (!categoryHeaderMasked.gameObject.TryGetComponent<PassiveButton>(out _))
|
||||
if (!categoryHeaderMasked.TryGetComponent<PassiveButton>(out _))
|
||||
{
|
||||
var boxCol = categoryHeaderMasked.gameObject.AddComponent<BoxCollider2D>();
|
||||
boxCol.size = new Vector2(7, 0.7f);
|
||||
|
||||
@@ -52,7 +52,7 @@ public static class SettingPatches
|
||||
MiraNumberSuffixes.None => part,
|
||||
MiraNumberSuffixes.Multiplier => part + "x",
|
||||
MiraNumberSuffixes.Percent => part + "%",
|
||||
MiraNumberSuffixes.Distance => string.Concat(part, " ", MiraApiPlugin.DistanceSuffix.Value),
|
||||
MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value,
|
||||
_ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part),
|
||||
};
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public static class SettingPatches
|
||||
MiraNumberSuffixes.None => part,
|
||||
MiraNumberSuffixes.Multiplier => part + "x",
|
||||
MiraNumberSuffixes.Percent => part + "%",
|
||||
MiraNumberSuffixes.Distance => string.Concat(part, " ", MiraApiPlugin.DistanceSuffix.Value),
|
||||
MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value,
|
||||
_ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ internal static class PlayerControlPatches
|
||||
[HarmonyPatch(nameof(PlayerControl.Start))]
|
||||
public static void PlayerControlStartPostfix(PlayerControl __instance)
|
||||
{
|
||||
if (__instance.gameObject.TryGetComponent<ModifierComponent>(out var modifierComp))
|
||||
if (__instance.TryGetComponent<ModifierComponent>(out var modifierComp))
|
||||
{
|
||||
modifierComp.DestroyImmediate();
|
||||
}
|
||||
|
||||
if (__instance.gameObject.TryGetComponent<PlayerVoteData>(out var voteComp))
|
||||
if (__instance.TryGetComponent<PlayerVoteData>(out var voteComp))
|
||||
{
|
||||
voteComp.DestroyImmediate();
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public static class RoleGuidePatches
|
||||
if (_titleText)
|
||||
{
|
||||
_titleText.transform.localPosition += new Vector3(0.5f, 0);
|
||||
_titleText.transform.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
_titleText.GetComponent<TextTranslatorTMP>().Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1565,20 +1565,13 @@ public static class RoleGuidePatches
|
||||
|
||||
private static void SetupPanelButton(MatchInfoRolePanel panel, Action onClick)
|
||||
{
|
||||
var collider = panel.roleIcon.gameObject.GetComponent<BoxCollider2D>();
|
||||
if (!collider)
|
||||
{
|
||||
collider = panel.roleIcon.gameObject.AddComponent<BoxCollider2D>();
|
||||
}
|
||||
var collider = panel.roleIcon.gameObject.GetOrAddComponent<BoxCollider2D>();
|
||||
|
||||
collider.size = new Vector2(0.13f, 0.13f);
|
||||
collider.offset = new Vector2(0, 0);
|
||||
collider.enabled = true;
|
||||
var passiveButton = panel.roleIcon.gameObject.GetComponent<PassiveButton>();
|
||||
if (!passiveButton)
|
||||
{
|
||||
passiveButton = panel.roleIcon.gameObject.AddComponent<PassiveButton>();
|
||||
}
|
||||
|
||||
var passiveButton = panel.roleIcon.gameObject.GetOrAddComponent<PassiveButton>();
|
||||
|
||||
passiveButton.enabled = true;
|
||||
passiveButton.ClickSound = HudManager.Instance.MapButton.ClickSound;
|
||||
|
||||
@@ -37,7 +37,7 @@ public static class RoleManagerPatches
|
||||
Object.Destroy(data.Role.gameObject);
|
||||
}
|
||||
|
||||
var roleBehaviour = Object.Instantiate<RoleBehaviour>(__instance.AllRoles.ToArray().First(r => r.Role == roleType), data.gameObject.transform);
|
||||
var roleBehaviour = Object.Instantiate(__instance.AllRoles.ToArray().First(r => r.Role == roleType), data.transform);
|
||||
roleBehaviour.Initialize(targetPlayer);
|
||||
targetPlayer.Data.Role = roleBehaviour;
|
||||
targetPlayer.Data.RoleType = roleType;
|
||||
|
||||
@@ -15,7 +15,7 @@ internal static class TaskPanelPatch
|
||||
[HarmonyPatch(nameof(TaskPanelBehaviour.Update))]
|
||||
public static bool UpdatePrefix(TaskPanelBehaviour __instance)
|
||||
{
|
||||
if (__instance.gameObject.name != "RolePanel")
|
||||
if (__instance.name != "RolePanel")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SavePresetPopup(nint cppPtr) : Minigame(cppPtr)
|
||||
|
||||
foreach (var tmp in gameObject.GetComponentsInChildren<TextMeshPro>())
|
||||
{
|
||||
if (tmp.gameObject.transform.parent.name == "Textbox")
|
||||
if (tmp.transform.parent.name == "Textbox")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ public static class CustomRoleManager
|
||||
|
||||
internal static TaskPanelBehaviour CreateRoleTab(ICustomRole role)
|
||||
{
|
||||
var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent<TaskPanelBehaviour>();
|
||||
var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").GetComponent<TaskPanelBehaviour>();
|
||||
var clonePanel = Object.Instantiate(ogPanel.gameObject, ogPanel.transform.parent);
|
||||
clonePanel.name = "RolePanel";
|
||||
|
||||
@@ -257,8 +257,8 @@ public static class CustomRoleManager
|
||||
|
||||
internal static void UpdateRoleTab(TaskPanelBehaviour panel, ICustomRole role)
|
||||
{
|
||||
var tabText = panel.tab.gameObject.GetComponentInChildren<TextMeshPro>();
|
||||
var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").gameObject.GetComponent<TaskPanelBehaviour>();
|
||||
var tabText = panel.tab.GetComponentInChildren<TextMeshPro>();
|
||||
var ogPanel = HudManager.Instance.TaskStuff.transform.FindChild("TaskPanel").GetComponent<TaskPanelBehaviour>();
|
||||
if (tabText.text != role.RoleName)
|
||||
{
|
||||
tabText.text = role.RoleName;
|
||||
|
||||
@@ -843,6 +843,21 @@ public static class Extensions
|
||||
return comp ? comp : go.AddComponent<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a component that is attached to the provided <see cref="GameObject"/>, attaching and returning the component if it wasn't found, and returns a bool that indicates if the component already existed before.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The component type.</typeparam>
|
||||
/// <param name="go">The <see cref="GameObject"/> to get the component from.</param>
|
||||
/// <param name="exists">When this method returns true if the component already existed; otherwise false.</param>
|
||||
/// <returns>The component.</returns>
|
||||
public static T GetOrAddComponent<T>(this GameObject go, out bool exists)
|
||||
where T : Component
|
||||
{
|
||||
var comp = go.GetComponent<T>();
|
||||
exists = comp;
|
||||
return exists ? comp : go.AddComponent<T>();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Attribute.IsDefined(MemberInfo, Type, bool)"/>
|
||||
/// <typeparam name="T">The type of the attribute.</typeparam>
|
||||
/// <returns>true if a custom attribute of type <typeparamref name="T"/> is applied to element; otherwise, false.</returns>
|
||||
|
||||
@@ -177,7 +177,7 @@ public static class Helpers
|
||||
{
|
||||
var keybindIcon = Object.Instantiate(HudManager.Instance.AbilityButton.usesRemainingSprite.gameObject, button.transform);
|
||||
keybindIcon.GetComponent<SpriteRenderer>().sprite = MiraAssets.KeybindButton.LoadAsset();
|
||||
keybindIcon.transform.GetComponentInChildren<TextMeshPro>().text = keyCode.ToString();
|
||||
keybindIcon.GetComponentInChildren<TextMeshPro>().text = keyCode.ToString();
|
||||
keybindIcon.name = "KeybindIcon";
|
||||
keybindIcon.transform.localPosition = localPos;
|
||||
return keybindIcon;
|
||||
@@ -191,26 +191,21 @@ public static class Helpers
|
||||
/// <returns>THe corresponding method to patch.</returns>
|
||||
public static MethodBase? GetStateMachineMoveNext<T>(string methodName)
|
||||
{
|
||||
var typeName = typeof(T).FullName;
|
||||
var showRoleStateMachine =
|
||||
typeof(T)
|
||||
.GetNestedTypes()
|
||||
.FirstOrDefault(x => x.Name.Contains(methodName));
|
||||
var stateMachine = typeof(T).GetNestedTypes().FirstOrDefault(x => x.Name.Contains(methodName, StringComparison.Ordinal));
|
||||
|
||||
if (showRoleStateMachine == null)
|
||||
if (stateMachine == null)
|
||||
{
|
||||
Error($"Failed to find {methodName} state machine for {typeName}");
|
||||
Error($"Failed to find {methodName} state machine for {typeof(T).FullName}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var moveNext = AccessTools.Method(showRoleStateMachine, "MoveNext");
|
||||
var moveNext = AccessTools.Method(stateMachine, "MoveNext");
|
||||
|
||||
if (moveNext == null)
|
||||
{
|
||||
Error($"Failed to find MoveNext method for {typeName}.{methodName}");
|
||||
return null;
|
||||
}
|
||||
Error($"Failed to find MoveNext method for {typeof(T).FullName}.{methodName}");
|
||||
else
|
||||
Info($"Found {methodName}.MoveNext");
|
||||
|
||||
Info($"Found {methodName}.MoveNext");
|
||||
return moveNext;
|
||||
}
|
||||
|
||||
@@ -309,7 +304,7 @@ public static class Helpers
|
||||
{
|
||||
var prefab = Object.FindObjectOfType<ArrowBehaviour>(true);
|
||||
var arrow = Object.Instantiate(prefab, parent);
|
||||
arrow.image = arrow.gameObject.GetComponent<SpriteRenderer>();
|
||||
arrow.image = arrow.GetComponent<SpriteRenderer>();
|
||||
arrow.image.color = color;
|
||||
arrow.gameObject.layer = 5;
|
||||
arrow.gameObject.SetActive(true);
|
||||
@@ -619,6 +614,7 @@ public static class Helpers
|
||||
MiraNumberSuffixes.Multiplier => "x",
|
||||
MiraNumberSuffixes.Seconds => "s",
|
||||
MiraNumberSuffixes.Percent => "%",
|
||||
MiraNumberSuffixes.Distance => MiraApiPlugin.DistanceSuffix.Value,
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
@@ -653,14 +649,14 @@ public static class Helpers
|
||||
/// <returns>The formatted value.</returns>
|
||||
public static string FormatValue(float value, MiraNumberSuffixes suffix = MiraNumberSuffixes.None, string formatString = "0.0")
|
||||
{
|
||||
var part = value.ToString(formatString, NumberFormatInfo.InvariantInfo);
|
||||
return suffix switch
|
||||
{
|
||||
MiraNumberSuffixes.None => value.ToString(formatString, NumberFormatInfo.InvariantInfo),
|
||||
MiraNumberSuffixes.Multiplier => value.ToString(formatString, NumberFormatInfo.InvariantInfo) + "x",
|
||||
MiraNumberSuffixes.Percent => value.ToString(formatString, NumberFormatInfo.InvariantInfo) + "%",
|
||||
_ => TranslationController.Instance.GetString(
|
||||
StringNames.GameSecondsAbbrev,
|
||||
(Il2CppSystem.Object[])[value.ToString(formatString, CultureInfo.InvariantCulture)]),
|
||||
MiraNumberSuffixes.None => part,
|
||||
MiraNumberSuffixes.Percent => part + "%",
|
||||
MiraNumberSuffixes.Multiplier => part + "x",
|
||||
MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value,
|
||||
_ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public class StateMachineWrapper<T>
|
||||
private readonly PropertyInfo _stateProperty;
|
||||
private readonly PropertyInfo _currentProperty;
|
||||
private readonly Dictionary<string, PropertyInfo> _propertyCache;
|
||||
private readonly Type _type;
|
||||
|
||||
private T? _parentInstance;
|
||||
|
||||
@@ -37,14 +38,14 @@ public class StateMachineWrapper<T>
|
||||
{
|
||||
_stateMachine = stateMachine;
|
||||
|
||||
var type = _stateMachine.GetType();
|
||||
_thisProperty = AccessTools.Property(type, "__4__this");
|
||||
_stateProperty = AccessTools.Property(type, "__1__state");
|
||||
_currentProperty = AccessTools.Property(type, "__2__current");
|
||||
_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 || _currentProperty == null)
|
||||
{
|
||||
throw new MissingMemberException($"Could not find required properties in type '{type}'.");
|
||||
throw new MissingMemberException($"Could not find required properties in type '{_type}'.");
|
||||
}
|
||||
|
||||
_propertyCache = [];
|
||||
@@ -91,8 +92,8 @@ public class StateMachineWrapper<T>
|
||||
return (TField)property.GetValue(_stateMachine)!;
|
||||
}
|
||||
|
||||
property = AccessTools.Property(_stateMachine.GetType(), parameterName)
|
||||
?? throw new MissingFieldException($"Could not find parameter '{parameterName}' in state machine of type '{_stateMachine.GetType()}'.");
|
||||
property = AccessTools.Property(_type, parameterName)
|
||||
?? throw new MissingFieldException($"Could not find parameter '{parameterName}' in state machine of type '{_type.Name}'.");
|
||||
|
||||
_propertyCache[parameterName] = property;
|
||||
return (TField)property.GetValue(_stateMachine)!;
|
||||
|
||||
Reference in new issue
Block a user