mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Temporary measures for clearing up memory leaks
This commit is contained in:
1 parent
90921ff786
commit
e3b0eb68c0
13 files changed
+74
-31
No files matched your search
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Il2CppInterop.Runtime.Attributes;
|
using Il2CppInterop.Runtime.Attributes;
|
||||||
using MiraAPI.LocalSettings;
|
using MiraAPI.LocalSettings;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Utilities.Attributes;
|
using Reactor.Utilities.Attributes;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
@@ -137,7 +138,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
internal void DestroyComponent(ModifierUiComponent component)
|
internal void DestroyComponent(ModifierUiComponent component)
|
||||||
{
|
{
|
||||||
_modifiers.Remove(component.Modifier!);
|
_modifiers.Remove(component.Modifier!);
|
||||||
component.gameObject.DestroyImmediate();
|
component.gameObject.FakeDestroy();
|
||||||
RefreshModifiers();
|
RefreshModifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod.Value.gameObject.Destroy();
|
mod.Value.gameObject.FakeDestroy();
|
||||||
_modifiers.Remove(mod.Key);
|
_modifiers.Remove(mod.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ public static class TaskAdderPatches
|
|||||||
__instance.transform.FindChild("TitleText_TMP")?.gameObject.DestroyImmediate();
|
__instance.transform.FindChild("TitleText_TMP")?.gameObject.DestroyImmediate();
|
||||||
}
|
}
|
||||||
|
|
||||||
__instance.ActiveItems.ToArray().Do(x => x.gameObject.Destroy());
|
__instance.ActiveItems.ToArray().Do(x => x.gameObject.FakeDestroy());
|
||||||
__instance.ActiveItems.Clear();
|
__instance.ActiveItems.Clear();
|
||||||
|
|
||||||
float num = 0f;
|
float num = 0f;
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ public static class HudManagerPatches
|
|||||||
|
|
||||||
foreach (var t in BottomLeft.GetComponentsInChildren<ActionButton>(true))
|
foreach (var t in BottomLeft.GetComponentsInChildren<ActionButton>(true))
|
||||||
{
|
{
|
||||||
t.gameObject.Destroy();
|
t.gameObject.FakeDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
var gridArrange = BottomLeft.GetComponent<GridArrange>();
|
var gridArrange = BottomLeft.GetComponent<GridArrange>();
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ using Reactor.Utilities;
|
|||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Menu;
|
namespace MiraAPI.Patches.Menu;
|
||||||
@@ -94,9 +92,9 @@ public static class HatsTabPatches
|
|||||||
if (loadRoutine != null) Coroutines.Stop(loadRoutine);
|
if (loadRoutine != null) Coroutines.Stop(loadRoutine);
|
||||||
|
|
||||||
hatIndex = 0;
|
hatIndex = 0;
|
||||||
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
foreach (var instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.FakeDestroy();
|
||||||
__instance.ColorChips.Clear();
|
__instance.ColorChips.Clear();
|
||||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.FakeDestroy());
|
||||||
|
|
||||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ public static class NameplatesTabPatches
|
|||||||
|
|
||||||
private static void GenerateHats(NameplatesTab __instance, int page)
|
private static void GenerateHats(NameplatesTab __instance, int page)
|
||||||
{
|
{
|
||||||
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.FakeDestroy();
|
||||||
__instance.ColorChips.Clear();
|
__instance.ColorChips.Clear();
|
||||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.FakeDestroy());
|
||||||
|
|
||||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
|
||||||
|
|||||||
@@ -83,9 +83,9 @@ public static class SkinsTabPatches
|
|||||||
|
|
||||||
private static void GenerateHats(SkinsTab __instance, int page)
|
private static void GenerateHats(SkinsTab __instance, int page)
|
||||||
{
|
{
|
||||||
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.FakeDestroy();
|
||||||
__instance.ColorChips.Clear();
|
__instance.ColorChips.Clear();
|
||||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.FakeDestroy());
|
||||||
|
|
||||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ public static class VisorsTabPatches
|
|||||||
|
|
||||||
private static void GenerateHats(VisorsTab __instance, int page)
|
private static void GenerateHats(VisorsTab __instance, int page)
|
||||||
{
|
{
|
||||||
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.FakeDestroy();
|
||||||
__instance.ColorChips.Clear();
|
__instance.ColorChips.Clear();
|
||||||
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.FakeDestroy());
|
||||||
|
|
||||||
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ internal static class GamePresetsTabPatches
|
|||||||
iconSpriteRend.sprite = MiraAssets.RefreshIcon.LoadAsset();
|
iconSpriteRend.sprite = MiraAssets.RefreshIcon.LoadAsset();
|
||||||
|
|
||||||
Helpers.DivideSize(refreshButton.gameObject, 2f);
|
Helpers.DivideSize(refreshButton.gameObject, 2f);
|
||||||
refreshButton.buttonText.gameObject.Destroy();
|
refreshButton.buttonText.gameObject.FakeDestroy();
|
||||||
|
|
||||||
refreshButton.OnClick = new Button.ButtonClickedEvent();
|
refreshButton.OnClick = new Button.ButtonClickedEvent();
|
||||||
refreshButton.OnClick.AddListener((UnityAction)Refresh);
|
refreshButton.OnClick.AddListener((UnityAction)Refresh);
|
||||||
|
|||||||
@@ -53,9 +53,23 @@ public static class RoleSettingMenuPatches
|
|||||||
[HarmonyPatch(nameof(RolesSettingsMenu.SetQuotaTab))]
|
[HarmonyPatch(nameof(RolesSettingsMenu.SetQuotaTab))]
|
||||||
public static bool SetQuotaTabPatch(RolesSettingsMenu __instance)
|
public static bool SetQuotaTabPatch(RolesSettingsMenu __instance)
|
||||||
{
|
{
|
||||||
Headers.ForEach(Object.Destroy);
|
foreach (var obj in Headers)
|
||||||
RoleOptionSettings.ForEach(Object.Destroy);
|
{
|
||||||
|
if (!obj)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
obj.FakeDestroy();
|
||||||
|
}
|
||||||
Headers.Clear();
|
Headers.Clear();
|
||||||
|
foreach (var obj in RoleOptionSettings)
|
||||||
|
{
|
||||||
|
if (!obj)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
obj.gameObject.FakeDestroy();
|
||||||
|
}
|
||||||
RoleOptionSettings.Clear();
|
RoleOptionSettings.Clear();
|
||||||
CurrentRole = null;
|
CurrentRole = null;
|
||||||
CurrentRoleOptions = null;
|
CurrentRoleOptions = null;
|
||||||
@@ -204,9 +218,9 @@ public static class RoleSettingMenuPatches
|
|||||||
var blankLabel = quotaInst.transform.FindChild("BlankLabel").gameObject;
|
var blankLabel = quotaInst.transform.FindChild("BlankLabel").gameObject;
|
||||||
var chanceLabel = quotaInst.transform.FindChild("Chance Label").gameObject;
|
var chanceLabel = quotaInst.transform.FindChild("Chance Label").gameObject;
|
||||||
var countLabel = quotaInst.transform.FindChild("# Label").gameObject;
|
var countLabel = quotaInst.transform.FindChild("# Label").gameObject;
|
||||||
blankLabel.Destroy();
|
blankLabel.FakeDestroy();
|
||||||
chanceLabel.Destroy();
|
chanceLabel.FakeDestroy();
|
||||||
countLabel.Destroy();
|
countLabel.FakeDestroy();
|
||||||
|
|
||||||
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
|
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
|
||||||
categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
|
categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
|
||||||
@@ -289,14 +303,22 @@ public static class RoleSettingMenuPatches
|
|||||||
{
|
{
|
||||||
RoleGroupHidden[group] = !groupHidden;
|
RoleGroupHidden[group] = !groupHidden;
|
||||||
}
|
}
|
||||||
foreach (var header in Headers)
|
foreach (var obj in Headers)
|
||||||
{
|
{
|
||||||
header.Destroy();
|
if (!obj)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
obj.FakeDestroy();
|
||||||
}
|
}
|
||||||
Headers.Clear();
|
Headers.Clear();
|
||||||
foreach (var option in RoleOptionSettings)
|
foreach (var obj in RoleOptionSettings)
|
||||||
{
|
{
|
||||||
option.gameObject.Destroy();
|
if (!obj)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
obj.gameObject.FakeDestroy();
|
||||||
}
|
}
|
||||||
RoleOptionSettings.Clear();
|
RoleOptionSettings.Clear();
|
||||||
__instance.SetQuotaTab();
|
__instance.SetQuotaTab();
|
||||||
@@ -422,7 +444,7 @@ public static class RoleSettingMenuPatches
|
|||||||
{
|
{
|
||||||
foreach (var optBehaviour in __instance.AdvancedRolesSettings.GetComponentsInChildren<OptionBehaviour>())
|
foreach (var optBehaviour in __instance.AdvancedRolesSettings.GetComponentsInChildren<OptionBehaviour>())
|
||||||
{
|
{
|
||||||
optBehaviour.gameObject.DestroyImmediate();
|
optBehaviour.gameObject.FakeDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentRole = role;
|
CurrentRole = role;
|
||||||
@@ -618,7 +640,7 @@ public static class RoleSettingMenuPatches
|
|||||||
var newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
|
var newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
|
||||||
newButton.name = "ConfigButton";
|
newButton.name = "ConfigButton";
|
||||||
newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f);
|
newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f);
|
||||||
newButton.transform.FindChild("Text_TMP").gameObject.DestroyImmediate();
|
newButton.transform.FindChild("Text_TMP").gameObject.FakeDestroy();
|
||||||
newButton.activeSprites.Destroy();
|
newButton.activeSprites.Destroy();
|
||||||
|
|
||||||
var btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
|
var btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using InnerNet;
|
using InnerNet;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Roles;
|
namespace MiraAPI.Patches.Roles;
|
||||||
|
|
||||||
@@ -69,9 +71,10 @@ public static class HudManagerPatches
|
|||||||
|
|
||||||
CustomRoleManager.UpdateRoleTab(RoleTab, customRole);
|
CustomRoleManager.UpdateRoleTab(RoleTab, customRole);
|
||||||
}
|
}
|
||||||
else if (RoleTab)
|
else if (RoleTab != null)
|
||||||
{
|
{
|
||||||
RoleTab?.gameObject.Destroy();
|
RoleTab.gameObject.FakeDestroy();
|
||||||
|
RoleTab = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ public static class PresetManager
|
|||||||
{
|
{
|
||||||
if (btn != null)
|
if (btn != null)
|
||||||
{
|
{
|
||||||
Object.DestroyImmediate(btn);
|
btn.FakeDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class SavePresetPopup(nint cppPtr) : Minigame(cppPtr)
|
|||||||
// Cleanup holder object
|
// Cleanup holder object
|
||||||
public void OnDestroy()
|
public void OnDestroy()
|
||||||
{
|
{
|
||||||
transform.parent.gameObject.Destroy();
|
transform.parent.gameObject.FakeDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Close()
|
public override void Close()
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public static class Extensions
|
|||||||
bool isComplete;
|
bool isComplete;
|
||||||
if (self.amClosing == Minigame.CloseState.Closing)
|
if (self.amClosing == Minigame.CloseState.Closing)
|
||||||
{
|
{
|
||||||
UnityEngine.Object.Destroy(self.gameObject);
|
self.gameObject.FakeDestroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (self.CloseSound && Constants.ShouldPlaySfx())
|
if (self.CloseSound && Constants.ShouldPlaySfx())
|
||||||
@@ -219,6 +219,24 @@ public static class Extensions
|
|||||||
return Mathf.Approximately(number, Mathf.Round(number));
|
return Mathf.Approximately(number, Mathf.Round(number));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hides the object away rather than destroy it to prevent memory leaks.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The object to hide.</param>
|
||||||
|
public static void FakeDestroy(this GameObject obj)
|
||||||
|
{
|
||||||
|
obj.hideFlags = HideFlags.HideAndDontSave;
|
||||||
|
if (!toDestroyHolder)
|
||||||
|
{
|
||||||
|
toDestroyHolder = new GameObject("ToDestroyHolder");
|
||||||
|
toDestroyHolder.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
obj.transform.SetParent(toDestroyHolder.transform);
|
||||||
|
obj.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GameObject toDestroyHolder;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a cache of player's vote data components to improve performance.
|
/// Gets a cache of player's vote data components to improve performance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in new issue
Block a user