diff --git a/EXILED/Exiled.API/Enums/FacilityLayouts/EzFacilityLayout.cs b/EXILED/Exiled.API/Enums/FacilityLayouts/EzFacilityLayout.cs new file mode 100644 index 000000000..6428cdbc0 --- /dev/null +++ b/EXILED/Exiled.API/Enums/FacilityLayouts/EzFacilityLayout.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Enums +{ + using Exiled.API.Features; + + /// + /// Represents different layouts each zone in the facility can have. + /// + /// Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed. + /// Ordering comes from the order said layouts are stored in SL. + /// + public enum EzFacilityLayout + { + /// + /// Represents an unknown layout. This value is only used if you try to access prematurely or if an error occured. + /// + Unknown, + + /// + /// See for details. + /// + Rectangles, + + /// + /// See for details. + /// + Handbag, + + /// + /// See for details. + /// + Fractured, + + /// + /// See for details. + /// + L, + + /// + /// See for details. + /// + Mogus, + } +} \ No newline at end of file diff --git a/EXILED/Exiled.API/Enums/FacilityLayouts/HczFacilityLayout.cs b/EXILED/Exiled.API/Enums/FacilityLayouts/HczFacilityLayout.cs new file mode 100644 index 000000000..e67bcdbf8 --- /dev/null +++ b/EXILED/Exiled.API/Enums/FacilityLayouts/HczFacilityLayout.cs @@ -0,0 +1,75 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Enums +{ + using Exiled.API.Features; + + /// + /// Represents different layouts each zone in the facility can have. + /// + /// Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed. + /// Ordering comes from the order said layouts are stored in SL. + /// + public enum HczFacilityLayout + { + /// + /// Represents an unknown layout. This value is only used if you try to access prematurely or if an error occured. + /// + Unknown, + + /// + /// See for details. + /// + CCross, + + /// + /// See for details. + /// + Storm, + + /// + /// See for details. + /// + TopSquares, + + /// + /// See for details. + /// + Inkblot, + + /// + /// See for details. + /// + RottenHeart, + + /// + /// See for details. + /// + NewTall, + + /// + /// See for details. + /// + Split, + + /// + /// See for details. + /// + NewCircuit, + + /// + /// See for details. + /// + Grasp, + + /// + /// See for details. + /// + Help, + } +} \ No newline at end of file diff --git a/EXILED/Exiled.API/Enums/FacilityLayouts/LczFacilityLayout.cs b/EXILED/Exiled.API/Enums/FacilityLayouts/LczFacilityLayout.cs new file mode 100644 index 000000000..0f2f2b027 --- /dev/null +++ b/EXILED/Exiled.API/Enums/FacilityLayouts/LczFacilityLayout.cs @@ -0,0 +1,50 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Enums +{ + using Exiled.API.Features; + + /// + /// Represents different layouts each zone in the facility can have. + /// + /// Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed. + /// Ordering comes from the order said layouts are stored in SL. + /// + public enum LczFacilityLayout + { + /// + /// Represents an unknown layout. This value is only used if you try to access prematurely or if an error occured. + /// + Unknown, + + /// + /// See for details. + /// + Clothes, + + /// + /// See for details. + /// + Stool, + + /// + /// See for details. + /// + Controller, + + /// + /// See for details. + /// + Brain, + + /// + /// See for details. + /// + Skull, + } +} \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Map.cs b/EXILED/Exiled.API/Features/Map.cs index 8eb89e022..b9788edb6 100644 --- a/EXILED/Exiled.API/Features/Map.cs +++ b/EXILED/Exiled.API/Features/Map.cs @@ -88,6 +88,21 @@ public static int Seed } } + /// + /// Gets the layout of the light containment zone. + /// + public static LczFacilityLayout LczLayout { get; internal set; } = LczFacilityLayout.Unknown; + + /// + /// Gets the layout of the heavy containment zone. + /// + public static HczFacilityLayout HczLayout { get; internal set; } = HczFacilityLayout.Unknown; + + /// + /// Gets the layout of the entrance zone. + /// + public static EzFacilityLayout EzLayout { get; internal set; } = EzFacilityLayout.Unknown; + /// /// Gets or sets a value indicating whether decontamination is enabled. /// diff --git a/EXILED/Exiled.Events/Patches/Generic/MapLayoutGetter.cs b/EXILED/Exiled.Events/Patches/Generic/MapLayoutGetter.cs new file mode 100644 index 000000000..39d15716d --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Generic/MapLayoutGetter.cs @@ -0,0 +1,83 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Generic +{ + using System.Collections.Generic; + using System.Reflection.Emit; + + using Exiled.API.Enums; + using Exiled.API.Features; + using Exiled.API.Features.Pools; + using HarmonyLib; + using UnityEngine; + + using static HarmonyLib.AccessTools; + + /// + /// Patches to set the different layout properties in . + /// + [HarmonyPatch(typeof(MapGeneration.AtlasZoneGenerator), nameof(MapGeneration.AtlasZoneGenerator.Generate))] + public class MapLayoutGetter + { + private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) + { + List newInstructions = ListPool.Pool.Get(instructions); + + LocalBuilder local = generator.DeclareLocal(typeof(int)); + + int index = newInstructions.FindLastIndex(instruction => instruction.opcode == OpCodes.Ldelem_Ref); + + newInstructions.InsertRange(index, new CodeInstruction[] + { + new(OpCodes.Stloc_S, local), + new(OpCodes.Ldloc_S, local), + }); + + index += 3; + newInstructions.InsertRange(index, new CodeInstruction[] + { + new(OpCodes.Dup), + new(OpCodes.Ldloc_S, local), + new(OpCodes.Call, Method(typeof(MapLayoutGetter), nameof(SetLayout))), + }); + + for (int z = 0; z < newInstructions.Count; z++) + yield return newInstructions[z]; + + ListPool.Pool.Return(newInstructions); + } + + private static void SetLayout(Texture2D tex, int index) + { + switch (tex.name.Substring(0, 3)) + { + case "LC_": + if (index > 5) + Log.Warn($"Unknown layout: {tex}"); + + Map.LczLayout = (LczFacilityLayout)(index + 1); + return; + case "HC_": + if (index > 10) + Log.Warn($"Unknown layout: {tex}"); + + Map.HczLayout = (HczFacilityLayout)(index + 1); + return; + case "EZ_": + if (index > 5) + Log.Warn($"Unknown layout: {tex}"); + + Map.EzLayout = (EzFacilityLayout)(index + 1); + return; + default: + Log.Warn($"Failed to parse layout name: {tex.name}!"); + return; + } + } + } +} \ No newline at end of file