diff --git a/BrokenNodeDetector/BrokenNodeDetector.cs b/BrokenNodeDetector/BrokenNodeDetector.cs index 7e88f5b..68cfa1f 100644 --- a/BrokenNodeDetector/BrokenNodeDetector.cs +++ b/BrokenNodeDetector/BrokenNodeDetector.cs @@ -8,7 +8,7 @@ namespace BrokenNodeDetector { public class BrokenNodeDetector : IUserMod { - public static readonly string Version = "0.2"; + public static readonly string Version = "0.3"; public string Name => "Broken Node Detector " + Version; diff --git a/BrokenNodeDetector/LoadingExtension.cs b/BrokenNodeDetector/LoadingExtension.cs index 6e1133d..32fbad2 100644 --- a/BrokenNodeDetector/LoadingExtension.cs +++ b/BrokenNodeDetector/LoadingExtension.cs @@ -13,14 +13,8 @@ public class LoadingExtension : LoadingExtensionBase { public bool DetourInited { get; private set; } public static MainUI MainUi { get; private set; } public static IDictionary DetouredMethodStates { get; private set; } = new Dictionary(); - - public override void OnCreated(ILoading loading) { - base.OnCreated(loading); - Debug.Log("OnCreated"); - } public override void OnLevelLoaded(LoadMode mode) { - Debug.Log("OnLevelLoaded Mode: " + mode); base.OnLevelLoaded(mode); if (mode == LoadMode.NewGame @@ -35,10 +29,13 @@ public class LoadingExtension : LoadingExtensionBase { } public override void OnLevelUnloading() { - Debug.Log("OnLevelUnloading"); base.OnLevelUnloading(); RevertDetours(); + if (MainUi != null) { + UnityEngine.Object.Destroy(MainUi); + MainUi = null; + } } private void InitDetours() { @@ -46,11 +43,11 @@ public class LoadingExtension : LoadingExtensionBase { bool detourFailed = false; try { - Debug.Log("BND: Deploying manual detours"); + Debug.Log("[BND] Deploying manual detours"); DetouredMethodStates = AssemblyRedirector.Deploy(); } catch (Exception e) { - Debug.LogError("Could not deploy manual detours for Broken Nodes Detector"); + Debug.LogError("[BND] Could not deploy manual detours for Broken Nodes Detector"); Debug.Log(e.ToString()); Debug.Log(e.StackTrace); detourFailed = true; @@ -61,7 +58,7 @@ public class LoadingExtension : LoadingExtensionBase { UIView.library.ShowModal("ExceptionPanel").SetMessage("Broken Nodes Detector failed to load", "Broken Nodes Detector failed to load. You can continue playing but the mod may not work properly.", true); }); } else { - Debug.Log("Detours successful"); + Debug.Log("[BND] Detours successful"); } DetourInited = true; diff --git a/BrokenNodeDetector/ModService.cs b/BrokenNodeDetector/ModService.cs index 7f195c7..204194c 100644 --- a/BrokenNodeDetector/ModService.cs +++ b/BrokenNodeDetector/ModService.cs @@ -10,7 +10,6 @@ public class ModService { private readonly Dictionary _nodeCalls; public List Results { get; private set; } -// public List SegmentList { get; private set; } static ModService() { Instance = new ModService(); @@ -19,7 +18,6 @@ public class ModService { private ModService() { _nodeCalls = new Dictionary(); Results = new List(); -// SegmentList = new List(); } public void StartDetector() { @@ -54,34 +52,6 @@ public class ModService { Results.Add(pair.Key); } }); -// CalculateSegments(); } - -// /// -// /// Calculates unique segments ids from list of Result node ids -// /// -// private void CalculateSegments() { -// SegmentList.Clear(); -// int count = Results.Count; -// ushort node1 = 0; -// ushort node2 = 0; -// for (int i = 0; i < count - 1; i++) { -// for (int j = i + 1; j < count - 1; j++) { -// node1 = Results[i]; -// node2 = Results[j]; -// if (!NetManager.instance.m_nodes.m_buffer[node1].IsConnectedTo(node2)) continue; -// ushort currentSegment; -// for (int k = 0; k < 8; k++) { -// currentSegment = NetManager.instance.m_nodes.m_buffer[node1].GetSegment(k); -// -// if (currentSegment == 0) continue; -// -// if (node2 == NetManager.instance.m_segments.m_buffer[currentSegment].GetOtherNode(node1)) { -// SegmentList.Add(node2); -// } -// } -// } -// } -// } } } \ No newline at end of file diff --git a/BrokenNodeDetector/UI/MainPanel.cs b/BrokenNodeDetector/UI/MainPanel.cs index 40487f4..3037d12 100644 --- a/BrokenNodeDetector/UI/MainPanel.cs +++ b/BrokenNodeDetector/UI/MainPanel.cs @@ -189,7 +189,7 @@ public class MainPanel : UIPanel { if (ModService.Instance.Results.Count == 0) { _brokenNodesLabel.text = "Great! Nothing found :-)"; _mainPanel.height = 160; - Debug.Log("BrokenNodeDetector - nothing found"); + Debug.Log("[BND] Nothing found :-)"); } else { _brokenNodesLabel.relativePosition = new Vector2(10, 120); _brokenNodesLabel.text = $"Found {ModService.Instance.Results.Count} possibly broken nodes\n" + @@ -198,11 +198,18 @@ public class MainPanel : UIPanel { "3. Repeat 1-2 until nothing new found\n" + "Run detector again if you want :)"; _invalidNodes = ModService.Instance.Results; - Debug.Log($"BrokenNodeDetector found {_invalidNodes.Count} nodes. ({string.Join(",", _invalidNodes.Select(i => i.ToString()).ToArray())})"); + Debug.Log($"[BND] Found {_invalidNodes.Count} nodes. ({string.Join(",", _invalidNodes.Select(i => i.ToString()).ToArray())})"); _invalidNodesEnumerator = _invalidNodes.GetEnumerator(); _moveNextButton.Show(); _mainPanel.height = 300; } } + + private new void OnDestroy() { + base.OnDestroy(); + if (_mainPanel != null) { + Destroy(_mainPanel); + } + } } } \ No newline at end of file diff --git a/BrokenNodeDetector/UI/MainUI.cs b/BrokenNodeDetector/UI/MainUI.cs index d1c675b..b41c473 100644 --- a/BrokenNodeDetector/UI/MainUI.cs +++ b/BrokenNodeDetector/UI/MainUI.cs @@ -31,7 +31,11 @@ public class MainUI : UIComponent { public override void OnDestroy() { base.OnDestroy(); - MainPanel.OnDestroy(); + if (MainPanel != null) { + Destroy(MainPanel); + MainPanel = null; + MainKey = null; + } } } } \ No newline at end of file