From d2e3f8cf70e57b49d9a302a7589247a20e3eb83e Mon Sep 17 00:00:00 2001 From: Yamato Date: Mon, 23 Dec 2024 16:40:22 +0100 Subject: [PATCH 1/3] StoredComponent --- EXILED/Exiled.API/Features/PrefabHelper.cs | 12 ++++++------ .../Exiled.Events/Handlers/Internal/ClientStarted.cs | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/EXILED/Exiled.API/Features/PrefabHelper.cs b/EXILED/Exiled.API/Features/PrefabHelper.cs index 82180ac9a6..e51ed94f58 100644 --- a/EXILED/Exiled.API/Features/PrefabHelper.cs +++ b/EXILED/Exiled.API/Features/PrefabHelper.cs @@ -24,12 +24,12 @@ public static class PrefabHelper /// /// A containing all and their corresponding . /// - internal static readonly Dictionary Prefabs = new(Enum.GetValues(typeof(PrefabType)).Length); + internal static readonly Dictionary Prefabs = new(Enum.GetValues(typeof(PrefabType)).Length); /// /// Gets a of and their corresponding . /// - public static IReadOnlyDictionary PrefabToGameObject => Prefabs; + public static IReadOnlyDictionary PrefabToGameObject => Prefabs; /// /// Gets the from a . @@ -49,8 +49,8 @@ public static PrefabAttribute GetPrefabAttribute(this PrefabType prefabType) /// Returns the . public static GameObject GetPrefab(PrefabType prefabType) { - if (Prefabs.TryGetValue(prefabType, out GameObject prefab)) - return prefab; + if (Prefabs.TryGetValue(prefabType, out (GameObject, Component) prefab)) + return prefab.Item1; return null; } @@ -76,8 +76,8 @@ public static bool TryGetPrefab(PrefabType prefabType, out GameObject gameObject public static T GetPrefab(PrefabType prefabType) where T : Component { - if (Prefabs.TryGetValue(prefabType, out GameObject prefab) && prefab.TryGetComponent(out T component)) - return component; + if (Prefabs.TryGetValue(prefabType, out (GameObject, Component) prefab)) + return (T)prefab.Item2; return null; } diff --git a/EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs b/EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs index a260cf4957..4607dd71f4 100644 --- a/EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs +++ b/EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs @@ -29,24 +29,24 @@ public static void OnClientStarted() { PrefabHelper.Prefabs.Clear(); - Dictionary prefabs = new(); + Dictionary prefabs = new(); foreach (KeyValuePair prefab in NetworkClient.prefabs) { - if(!prefabs.ContainsKey(prefab.Key)) - prefabs.Add(prefab.Key, prefab.Value); + if(!prefabs.ContainsKey(prefab.Key) && prefab.Value.TryGetComponent(out Component component)) + prefabs.Add(prefab.Key, (prefab.Value, component)); } foreach (NetworkIdentity ragdollPrefab in RagdollManager.AllRagdollPrefabs) { - if(!prefabs.ContainsKey(ragdollPrefab.assetId)) - prefabs.Add(ragdollPrefab.assetId, ragdollPrefab.gameObject); + if(!prefabs.ContainsKey(ragdollPrefab.assetId) && ragdollPrefab.gameObject.TryGetComponent(out Component component)) + prefabs.Add(ragdollPrefab.assetId, (ragdollPrefab.gameObject, component)); } foreach (PrefabType prefabType in EnumUtils.Values) { PrefabAttribute attribute = prefabType.GetPrefabAttribute(); - PrefabHelper.Prefabs.Add(prefabType, prefabs.FirstOrDefault(prefab => prefab.Key == attribute.AssetId || prefab.Value.name.Contains(attribute.Name)).Value); + PrefabHelper.Prefabs.Add(prefabType, prefabs.FirstOrDefault(prefab => prefab.Key == attribute.AssetId || prefab.Value.Item1.name.Contains(attribute.Name)).Value); } } } From aadc1c40f8928a48389bc18171e0b87c6f163ea8 Mon Sep 17 00:00:00 2001 From: Yamato Date: Mon, 23 Dec 2024 16:57:36 +0100 Subject: [PATCH 2/3] Fix BreakingChange --- EXILED/Exiled.API/Features/PrefabHelper.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/PrefabHelper.cs b/EXILED/Exiled.API/Features/PrefabHelper.cs index e51ed94f58..cb17160b50 100644 --- a/EXILED/Exiled.API/Features/PrefabHelper.cs +++ b/EXILED/Exiled.API/Features/PrefabHelper.cs @@ -9,6 +9,7 @@ namespace Exiled.API.Features { using System; using System.Collections.Generic; + using System.Linq; using System.Reflection; using Exiled.API.Enums; @@ -29,7 +30,12 @@ public static class PrefabHelper /// /// Gets a of and their corresponding . /// - public static IReadOnlyDictionary PrefabToGameObject => Prefabs; + public static IReadOnlyDictionary PrefabToGameObjectAndComponent => Prefabs; + + /// + /// Gets a of and their corresponding . + /// + public static IReadOnlyDictionary PrefabToGameObject => Prefabs.ToDictionary(x => x.Key, x => x.Value.Item1); /// /// Gets the from a . From 61e70a07e67ba4a35a494925635c0ae456de14c6 Mon Sep 17 00:00:00 2001 From: Yamato Date: Thu, 31 Jul 2025 19:42:16 +0200 Subject: [PATCH 3/3] Fix new Log Warning --- EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs b/EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs index 3d5f5921d7..46e1f5881d 100644 --- a/EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs +++ b/EXILED/Exiled.Events/Handlers/Internal/ClientStarted.cs @@ -47,14 +47,15 @@ public static void OnClientStarted() { PrefabType prefabType = EnumUtils.Values[i]; PrefabAttribute attribute = prefabType.GetPrefabAttribute(); - if (prefabs.TryGetValue(attribute.AssetId, out GameObject gameObject)) + if (prefabs.TryGetValue(attribute.AssetId, out (GameObject, Component) tuple)) { + GameObject gameObject = tuple.Item1; PrefabHelper.Prefabs.Add(prefabType, prefabs.FirstOrDefault(prefab => prefab.Key == attribute.AssetId || prefab.Value.Item1.name.Contains(attribute.Name)).Value); prefabs.Remove(attribute.AssetId); continue; } - KeyValuePair? value = prefabs.FirstOrDefault(x => x.Value.name == attribute.Name); + KeyValuePair? value = prefabs.FirstOrDefault(x => x.Value.Item1.name == attribute.Name); if (value.HasValue) { PrefabHelper.Prefabs.Add(prefabType, prefabs.FirstOrDefault(prefab => prefab.Key == attribute.AssetId || prefab.Value.Item1.name.Contains(attribute.Name)).Value); @@ -63,8 +64,8 @@ public static void OnClientStarted() } } - foreach (KeyValuePair missing in prefabs) - Log.Warn($"Missing prefab in {nameof(PrefabType)}: {missing.Value.name} ({missing.Key})"); + foreach (KeyValuePair missing in prefabs) + Log.Warn($"Missing prefab in {nameof(PrefabType)}: {missing.Value.Item1.name} ({missing.Key})"); } } } \ No newline at end of file