Skip to content

Commit 12ceb6a

Browse files
authored
feat: Add layout enums and layout properties to Map (#710)
* Add layout stuff * Add Unknown value * Baguette boy changes * More Baguette boy changes * another one
1 parent 80d5397 commit 12ceb6a

File tree

5 files changed

+273
-0
lines changed

5 files changed

+273
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="EzFacilityLayout.cs" company="ExMod Team">
3+
// Copyright (c) ExMod Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.API.Enums
9+
{
10+
using Exiled.API.Features;
11+
12+
/// <summary>
13+
/// Represents different layouts each zone in the facility can have.
14+
/// </summary>
15+
/// <remarks>Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed.
16+
/// <para>Ordering comes from the order said layouts are stored in SL.</para>
17+
/// </remarks>
18+
public enum EzFacilityLayout
19+
{
20+
/// <summary>
21+
/// Represents an unknown layout. This value is only used if you try to access <see cref="Map.EzLayout"/> prematurely or if an error occured.
22+
/// </summary>
23+
Unknown,
24+
25+
/// <summary>
26+
/// See <see cref="EzFacilityLayout"/> for details.
27+
/// </summary>
28+
Rectangles,
29+
30+
/// <summary>
31+
/// See <see cref="EzFacilityLayout"/> for details.
32+
/// </summary>
33+
Handbag,
34+
35+
/// <summary>
36+
/// See <see cref="EzFacilityLayout"/> for details.
37+
/// </summary>
38+
Fractured,
39+
40+
/// <summary>
41+
/// See <see cref="EzFacilityLayout"/> for details.
42+
/// </summary>
43+
L,
44+
45+
/// <summary>
46+
/// See <see cref="EzFacilityLayout"/> for details.
47+
/// </summary>
48+
Mogus,
49+
}
50+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="HczFacilityLayout.cs" company="ExMod Team">
3+
// Copyright (c) ExMod Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.API.Enums
9+
{
10+
using Exiled.API.Features;
11+
12+
/// <summary>
13+
/// Represents different layouts each zone in the facility can have.
14+
/// </summary>
15+
/// <remarks>Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed.
16+
/// <para>Ordering comes from the order said layouts are stored in SL.</para>
17+
/// </remarks>
18+
public enum HczFacilityLayout
19+
{
20+
/// <summary>
21+
/// Represents an unknown layout. This value is only used if you try to access <see cref="Map.HczLayout"/> prematurely or if an error occured.
22+
/// </summary>
23+
Unknown,
24+
25+
/// <summary>
26+
/// See <see cref="HczFacilityLayout"/> for details.
27+
/// </summary>
28+
CCross,
29+
30+
/// <summary>
31+
/// See <see cref="HczFacilityLayout"/> for details.
32+
/// </summary>
33+
Storm,
34+
35+
/// <summary>
36+
/// See <see cref="HczFacilityLayout"/> for details.
37+
/// </summary>
38+
TopSquares,
39+
40+
/// <summary>
41+
/// See <see cref="HczFacilityLayout"/> for details.
42+
/// </summary>
43+
Inkblot,
44+
45+
/// <summary>
46+
/// See <see cref="HczFacilityLayout"/> for details.
47+
/// </summary>
48+
RottenHeart,
49+
50+
/// <summary>
51+
/// See <see cref="HczFacilityLayout"/> for details.
52+
/// </summary>
53+
NewTall,
54+
55+
/// <summary>
56+
/// See <see cref="HczFacilityLayout"/> for details.
57+
/// </summary>
58+
Split,
59+
60+
/// <summary>
61+
/// See <see cref="HczFacilityLayout"/> for details.
62+
/// </summary>
63+
NewCircuit,
64+
65+
/// <summary>
66+
/// See <see cref="HczFacilityLayout"/> for details.
67+
/// </summary>
68+
Grasp,
69+
70+
/// <summary>
71+
/// See <see cref="HczFacilityLayout"/> for details.
72+
/// </summary>
73+
Help,
74+
}
75+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="LczFacilityLayout.cs" company="ExMod Team">
3+
// Copyright (c) ExMod Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.API.Enums
9+
{
10+
using Exiled.API.Features;
11+
12+
/// <summary>
13+
/// Represents different layouts each zone in the facility can have.
14+
/// </summary>
15+
/// <remarks>Layout names come from https://steamcommunity.com/sharedfiles/filedetails/?id=2919451768, courtesy of EdgelordGreed.
16+
/// <para>Ordering comes from the order said layouts are stored in SL.</para>
17+
/// </remarks>
18+
public enum LczFacilityLayout
19+
{
20+
/// <summary>
21+
/// Represents an unknown layout. This value is only used if you try to access <see cref="Map.LczLayout"/> prematurely or if an error occured.
22+
/// </summary>
23+
Unknown,
24+
25+
/// <summary>
26+
/// See <see cref="LczFacilityLayout"/> for details.
27+
/// </summary>
28+
Clothes,
29+
30+
/// <summary>
31+
/// See <see cref="LczFacilityLayout"/> for details.
32+
/// </summary>
33+
Stool,
34+
35+
/// <summary>
36+
/// See <see cref="LczFacilityLayout"/> for details.
37+
/// </summary>
38+
Controller,
39+
40+
/// <summary>
41+
/// See <see cref="LczFacilityLayout"/> for details.
42+
/// </summary>
43+
Brain,
44+
45+
/// <summary>
46+
/// See <see cref="LczFacilityLayout"/> for details.
47+
/// </summary>
48+
Skull,
49+
}
50+
}

EXILED/Exiled.API/Features/Map.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ public static int Seed
8888
}
8989
}
9090

91+
/// <summary>
92+
/// Gets the layout of the light containment zone.
93+
/// </summary>
94+
public static LczFacilityLayout LczLayout { get; internal set; } = LczFacilityLayout.Unknown;
95+
96+
/// <summary>
97+
/// Gets the layout of the heavy containment zone.
98+
/// </summary>
99+
public static HczFacilityLayout HczLayout { get; internal set; } = HczFacilityLayout.Unknown;
100+
101+
/// <summary>
102+
/// Gets the layout of the entrance zone.
103+
/// </summary>
104+
public static EzFacilityLayout EzLayout { get; internal set; } = EzFacilityLayout.Unknown;
105+
91106
/// <summary>
92107
/// Gets or sets a value indicating whether decontamination is enabled.
93108
/// </summary>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="MapLayoutGetter.cs" company="ExMod Team">
3+
// Copyright (c) ExMod Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.Events.Patches.Generic
9+
{
10+
using System.Collections.Generic;
11+
using System.Reflection.Emit;
12+
13+
using Exiled.API.Enums;
14+
using Exiled.API.Features;
15+
using Exiled.API.Features.Pools;
16+
using HarmonyLib;
17+
using UnityEngine;
18+
19+
using static HarmonyLib.AccessTools;
20+
21+
/// <summary>
22+
/// Patches <see cref="MapGeneration.AtlasZoneGenerator"/> to set the different layout properties in <see cref="Map"/>.
23+
/// </summary>
24+
[HarmonyPatch(typeof(MapGeneration.AtlasZoneGenerator), nameof(MapGeneration.AtlasZoneGenerator.Generate))]
25+
public class MapLayoutGetter
26+
{
27+
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
28+
{
29+
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);
30+
31+
LocalBuilder local = generator.DeclareLocal(typeof(int));
32+
33+
int index = newInstructions.FindLastIndex(instruction => instruction.opcode == OpCodes.Ldelem_Ref);
34+
35+
newInstructions.InsertRange(index, new CodeInstruction[]
36+
{
37+
new(OpCodes.Stloc_S, local),
38+
new(OpCodes.Ldloc_S, local),
39+
});
40+
41+
index += 3;
42+
newInstructions.InsertRange(index, new CodeInstruction[]
43+
{
44+
new(OpCodes.Dup),
45+
new(OpCodes.Ldloc_S, local),
46+
new(OpCodes.Call, Method(typeof(MapLayoutGetter), nameof(SetLayout))),
47+
});
48+
49+
for (int z = 0; z < newInstructions.Count; z++)
50+
yield return newInstructions[z];
51+
52+
ListPool<CodeInstruction>.Pool.Return(newInstructions);
53+
}
54+
55+
private static void SetLayout(Texture2D tex, int index)
56+
{
57+
switch (tex.name.Substring(0, 3))
58+
{
59+
case "LC_":
60+
if (index > 5)
61+
Log.Warn($"Unknown layout: {tex}");
62+
63+
Map.LczLayout = (LczFacilityLayout)(index + 1);
64+
return;
65+
case "HC_":
66+
if (index > 10)
67+
Log.Warn($"Unknown layout: {tex}");
68+
69+
Map.HczLayout = (HczFacilityLayout)(index + 1);
70+
return;
71+
case "EZ_":
72+
if (index > 5)
73+
Log.Warn($"Unknown layout: {tex}");
74+
75+
Map.EzLayout = (EzFacilityLayout)(index + 1);
76+
return;
77+
default:
78+
Log.Warn($"Failed to parse layout name: {tex.name}!");
79+
return;
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)