Merge branch 'dev' into translation-improvements

This commit is contained in:
Az committed 2026-11-06 17:15:13 -05:00
commit b3566e4f19
26 files changed
+177 -105

No files matched your search

+4 -4
View File
@@ -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 =
+2 -2
View File
@@ -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)
+16
View File
@@ -89,6 +89,22 @@ public class CustomPlayerMenu : CustomMultiSelectMenu<PlayerControl>
{
var flag = PlayerControl.LocalPlayer.Data.Role.NameColor == entry.Data.Role.NameColor;
panel.SetPlayer(i, entry.Data, (Il2CppSystem.Action)onClick);
var outfit = entry.Data.DefaultOutfit;
if (entry.Data.IsDead)
{
var currentOutfit = entry.CurrentOutfit;
if (!string.IsNullOrEmpty(currentOutfit.SkinId))
{
outfit = currentOutfit;
}
}
panel.PlayerIcon.cosmetics.SetSkin(outfit.SkinId, outfit.ColorId);
panel.PlayerIcon.cosmetics.SetHat(outfit.HatId, outfit.ColorId);
panel.PlayerIcon.cosmetics.SetVisor(outfit.VisorId, outfit.ColorId);
panel.NameText.color = flag ? entry.Data.Role.NameColor : Color.white;
}
}
@@ -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();
+6 -6
View File
@@ -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;
+21 -6
View File
@@ -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);
+1 -2
View File
@@ -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;
}
}
+2 -2
View File
@@ -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;
+5 -5
View File
@@ -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)(() =>
+29 -13
View File
@@ -50,7 +50,8 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
private readonly Dictionary<MenuButton, PassiveButton> _smallButtons = [];
private readonly Dictionary<MenuButton, PassiveButton> _largeButtons = [];
private Vector3 _gameSettingsButtonOrig;
private Vector3 _roleSettingsButtonOrig;
[HideFromIl2Cpp]
public Dictionary<MenuCategory, Dictionary<int, GameObject>> Containers { get; } = new()
{
@@ -121,35 +122,39 @@ 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);
// Create menu buttons
_largeButtons[(int)MenuButton.Roles] = Gsm.RoleSettingsButton;
// cache
_gameSettingsButtonOrig = Gsm.GameSettingsButton.transform.localPosition;
_roleSettingsButtonOrig = Gsm.RoleSettingsButton.transform.localPosition;
// modifiers button
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 +173,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 +327,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 +345,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);
@@ -409,6 +414,11 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
btn.gameObject.SetActive(false);
}
// The mod options page moves RoleSettingsButton as needed.
// But when hasOptions == false, it leaves the button at the GameSettingsButton spot.
// So before each re-layout, always put the original button back into the prefab slot first.
RestoreButtonLayout();
if (CurrentModIdx == 0)
{
Gsm.GameSettingsButton.gameObject.SetActive(true);
@@ -532,6 +542,12 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr)
}
}
private void RestoreButtonLayout()
{
Gsm.GameSettingsButton.transform.localPosition = _gameSettingsButtonOrig;
Gsm.RoleSettingsButton.transform.localPosition = _roleSettingsButtonOrig;
}
internal void ChangeTabPatch(GameSettingMenu menu, int tabNum, bool previewOnly)
{
Info($"Changed tab to {(MenuCategory)tabNum} (previewOnly: {previewOnly}) for mod {CurrentModIdx}");
@@ -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);
+2 -2
View File
@@ -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),
};
}
+2 -2
View File
@@ -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();
}
+25 -12
View File
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using AmongUs.GameOptions;
using HarmonyLib;
using Innersloth.Assets;
@@ -296,7 +297,7 @@ public static class RoleGuidePatches
if (_titleText)
{
_titleText.transform.localPosition += new Vector3(0.5f, 0);
_titleText.transform.GetComponent<TextTranslatorTMP>().Destroy();
_titleText.GetComponent<TextTranslatorTMP>().Destroy();
}
}
@@ -656,7 +657,7 @@ public static class RoleGuidePatches
_searchBoxTmp.Pipe.transform.localPosition = new Vector3(
outputText.transform.localPosition.x -
(outputText.rectTransform.sizeDelta.x * outputText.rectTransform.pivot.x),
outputText.transform.localPosition.y + _searchBoxTmp.caretYOffset,
outputText.transform.localPosition.y + GetCaretYOffset(_searchBoxTmp),
-0.3f);
}
@@ -831,6 +832,25 @@ public static class RoleGuidePatches
button.gameObject.AddComponent<RectTransform>();
}
private static float GetCaretYOffset(TextBoxTMP box)
{
try
{
var prop = typeof(TextBoxTMP).GetProperty("caretYOffset", BindingFlags.Instance | BindingFlags.Public);
if (prop == null)
{
return 0f;
}
return Convert.ToSingle(prop.GetValue(box), CultureInfo.InvariantCulture);
}
catch
{
return 0f;
}
}
private static void SetupSearchButton(PassiveButton button, string objName, Action onClick, Sprite inactive, Sprite hover, Vector3 pos, out SpriteRenderer inactiveSprite, out SpriteRenderer hoverSprite)
{
button.name = objName;
@@ -1565,20 +1585,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;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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;
}
+3 -3
View File
@@ -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;
+15
View File
@@ -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>
+17 -21
View File
@@ -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),
};
}
+8 -7
View File
@@ -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)!;