Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions EXILED/Exiled.API/Enums/FacilityLayouts/EzFacilityLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ο»Ώ// -----------------------------------------------------------------------
// <copyright file="EzFacilityLayout.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Enums
{
using Exiled.API.Features;

/// <summary>
/// Represents different layouts each zone in the facility can have.
/// </summary>
/// <remarks>Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed.
/// <para>Ordering comes from the order said layouts are stored in SL.</para>
/// </remarks>
public enum EzFacilityLayout
{
/// <summary>
/// Represents an unknown layout. This value is only used if you try to access <see cref="Map.EzLayout"/> prematurely or if an error occured.
/// </summary>
Unknown,

/// <summary>
/// See <see cref="EzFacilityLayout"/> for details.
/// </summary>
Rectangles,

/// <summary>
/// See <see cref="EzFacilityLayout"/> for details.
/// </summary>
Handbag,

/// <summary>
/// See <see cref="EzFacilityLayout"/> for details.
/// </summary>
Fractured,

/// <summary>
/// See <see cref="EzFacilityLayout"/> for details.
/// </summary>
L,

/// <summary>
/// See <see cref="EzFacilityLayout"/> for details.
/// </summary>
Mogus,
}
}
75 changes: 75 additions & 0 deletions EXILED/Exiled.API/Enums/FacilityLayouts/HczFacilityLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
ο»Ώ// -----------------------------------------------------------------------
// <copyright file="HczFacilityLayout.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Enums
{
using Exiled.API.Features;

/// <summary>
/// Represents different layouts each zone in the facility can have.
/// </summary>
/// <remarks>Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed.
/// <para>Ordering comes from the order said layouts are stored in SL.</para>
/// </remarks>
public enum HczFacilityLayout
{
/// <summary>
/// Represents an unknown layout. This value is only used if you try to access <see cref="Map.HczLayout"/> prematurely or if an error occured.
/// </summary>
Unknown,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
CCross,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
Storm,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
TopSquares,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
Inkblot,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
RottenHeart,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
NewTall,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
Split,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
NewCircuit,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
Grasp,

/// <summary>
/// See <see cref="HczFacilityLayout"/> for details.
/// </summary>
Help,
}
}
50 changes: 50 additions & 0 deletions EXILED/Exiled.API/Enums/FacilityLayouts/LczFacilityLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ο»Ώ// -----------------------------------------------------------------------
// <copyright file="LczFacilityLayout.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Enums
{
using Exiled.API.Features;

/// <summary>
/// Represents different layouts each zone in the facility can have.
/// </summary>
/// <remarks>Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed.
/// <para>Ordering comes from the order said layouts are stored in SL.</para>
/// </remarks>
public enum LczFacilityLayout
{
/// <summary>
/// Represents an unknown layout. This value is only used if you try to access <see cref="Map.LczLayout"/> prematurely or if an error occured.
/// </summary>
Unknown,

/// <summary>
/// See <see cref="LczFacilityLayout"/> for details.
/// </summary>
Clothes,

/// <summary>
/// See <see cref="LczFacilityLayout"/> for details.
/// </summary>
Stool,

/// <summary>
/// See <see cref="LczFacilityLayout"/> for details.
/// </summary>
Controller,

/// <summary>
/// See <see cref="LczFacilityLayout"/> for details.
/// </summary>
Brain,

/// <summary>
/// See <see cref="LczFacilityLayout"/> for details.
/// </summary>
Skull,
}
}
15 changes: 15 additions & 0 deletions EXILED/Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ public static int Seed
}
}

/// <summary>
/// Gets the layout of the light containment zone.
/// </summary>
public static LczFacilityLayout LczLayout { get; internal set; } = LczFacilityLayout.Unknown;

/// <summary>
/// Gets the layout of the heavy containment zone.
/// </summary>
public static HczFacilityLayout HczLayout { get; internal set; } = HczFacilityLayout.Unknown;

/// <summary>
/// Gets the layout of the entrance zone.
/// </summary>
public static EzFacilityLayout EzLayout { get; internal set; } = EzFacilityLayout.Unknown;

/// <summary>
/// Gets or sets a value indicating whether decontamination is enabled.
/// </summary>
Expand Down
83 changes: 83 additions & 0 deletions EXILED/Exiled.Events/Patches/Generic/MapLayoutGetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
ο»Ώ// -----------------------------------------------------------------------
// <copyright file="MapLayoutGetter.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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;

/// <summary>
/// Patches <see cref="MapGeneration.AtlasZoneGenerator"/> to set the different layout properties in <see cref="Map"/>.
/// </summary>
[HarmonyPatch(typeof(MapGeneration.AtlasZoneGenerator), nameof(MapGeneration.AtlasZoneGenerator.Generate))]
public class MapLayoutGetter
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.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<CodeInstruction>.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;
}
}
}
}
Loading