diff --git a/EXILED/Exiled.API/Features/Room.cs b/EXILED/Exiled.API/Features/Room.cs
index 4efae3acd..1af977bbd 100644
--- a/EXILED/Exiled.API/Features/Room.cs
+++ b/EXILED/Exiled.API/Features/Room.cs
@@ -401,10 +401,46 @@ public void UnlockAll()
/// Factory method to create and add a component to a Transform.
/// We can add parameters to be set privately here.
///
- /// The Game Object to attach the Room component to.
- internal static void CreateComponent(GameObject roomGameObject)
+ /// The Game Object to attach the Room component to.
+ internal static void CreateComponent(RoomIdentifier roomIdentifier) => roomIdentifier.gameObject.AddComponent();
+
+ ///
+ /// Factory method to complete all element inside a Room.
+ ///
+ internal void InternalCreate()
{
- roomGameObject.AddComponent().InternalCreate();
+ Identifier = gameObject.GetComponent();
+ RoomIdentifierToRoom.Add(Identifier, this);
+
+ Zone = FindZone(gameObject);
+#if DEBUG
+ if (Zone is ZoneType.Unspecified)
+ Log.Error($"[ZONETYPE UNKNOWN] {this} Zone : {Identifier?.Zone}");
+#endif
+ Type = FindType(gameObject);
+#if DEBUG
+ if (Type is RoomType.Unknown)
+ Log.Error($"[ROOMTYPE UNKNOWN] {this} Name : {gameObject?.name} Shape : {Identifier?.Shape}");
+#endif
+
+ RoomLightControllers = RoomLightControllersValue.AsReadOnly();
+
+ GetComponentsInChildren().ForEach(component =>
+ {
+ Window window = new(component, this);
+ window.Room.WindowsValue.Add(window);
+ });
+
+ if (GetComponentInChildren() is global::TeslaGate tesla)
+ {
+ TeslaGate = new TeslaGate(tesla, this);
+ }
+
+ Windows = WindowsValue.AsReadOnly();
+ Doors = DoorsValue.AsReadOnly();
+ NearestRooms = NearestRoomsValue.AsReadOnly();
+ Speakers = SpeakersValue.AsReadOnly();
+ Cameras = CamerasValue.AsReadOnly();
}
private static RoomType FindType(GameObject gameObject)
@@ -500,41 +536,5 @@ private static ZoneType FindZone(GameObject gameObject)
_ => transform.position.y > 900 ? ZoneType.Surface : ZoneType.Unspecified,
};
}
-
- private void InternalCreate()
- {
- Identifier = gameObject.GetComponent();
- RoomIdentifierToRoom.Add(Identifier, this);
-
- Zone = FindZone(gameObject);
-#if DEBUG
- if (Zone is ZoneType.Unspecified)
- Log.Error($"[ZONETYPE UNKNOWN] {this} Zone : {Identifier?.Zone}");
-#endif
- Type = FindType(gameObject);
-#if DEBUG
- if (Type is RoomType.Unknown)
- Log.Error($"[ROOMTYPE UNKNOWN] {this} Name : {gameObject?.name} Shape : {Identifier?.Shape}");
-#endif
-
- RoomLightControllers = RoomLightControllersValue.AsReadOnly();
-
- GetComponentsInChildren().ForEach(component =>
- {
- Window window = new(component, this);
- window.Room.WindowsValue.Add(window);
- });
-
- if (GetComponentInChildren() is global::TeslaGate tesla)
- {
- TeslaGate = new TeslaGate(tesla, this);
- }
-
- Windows = WindowsValue.AsReadOnly();
- Doors = DoorsValue.AsReadOnly();
- NearestRooms = NearestRoomsValue.AsReadOnly();
- Speakers = SpeakersValue.AsReadOnly();
- Cameras = CamerasValue.AsReadOnly();
- }
}
}
diff --git a/EXILED/Exiled.Events/Patches/Generic/RoomList.cs b/EXILED/Exiled.Events/Patches/Generic/RoomList.cs
index 3686e2f1d..53f6ada70 100644
--- a/EXILED/Exiled.Events/Patches/Generic/RoomList.cs
+++ b/EXILED/Exiled.Events/Patches/Generic/RoomList.cs
@@ -37,14 +37,15 @@ private static IEnumerable Transpiler(IEnumerable i.Calls(Method(typeof(RoomIdUtils), nameof(RoomIdUtils.PositionToCoords)))) + offset;
- // Room.CreateComponent(gameObject);
+ // Room.Get(gameObject).InternalCreate();
newInstructions.InsertRange(
index,
new CodeInstruction[]
{
new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
new(OpCodes.Callvirt, PropertyGetter(typeof(Component), nameof(Component.gameObject))),
- new(OpCodes.Call, Method(typeof(Room), nameof(Room.CreateComponent))),
+ new(OpCodes.Callvirt, Method(typeof(Room), nameof(Room.FindParentRoom), new System.Type[] { typeof(GameObject) })),
+ new(OpCodes.Callvirt, Method(typeof(Room), nameof(Room.InternalCreate))),
});
for (int z = 0; z < newInstructions.Count; z++)
@@ -54,6 +55,18 @@ private static IEnumerable Transpiler(IEnumerable
+ /// Patches .
+ ///
+ [HarmonyPatch(typeof(RoomIdentifier), nameof(RoomIdentifier.Awake))]
+ internal class RoomListAdd
+ {
+ private static void Postfix(RoomIdentifier __instance)
+ {
+ Room.CreateComponent(__instance);
+ }
+ }
+
///
/// Patches .
///