Skip to content

Commit 6b09d9b

Browse files
committed
Halloween fixes
1 parent e5fe46f commit 6b09d9b

4 files changed

Lines changed: 176 additions & 17 deletions

File tree

LabExtended/API/Containers/EffectContainer.cs

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using LabApi.Events.Arguments.PlayerEvents;
2020

2121
using UnityEngine;
22+
using InventorySystem.Items.MarshmallowMan;
2223
// ReSharper disable UnusedAutoPropertyAccessor.Local
2324

2425
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
@@ -275,7 +276,12 @@ static EffectContainer()
275276
/// Gets the player's SCP-1576 effect.
276277
/// </summary>
277278
public Scp1576 Scp1576 { get; private set; }
278-
279+
280+
/// <summary>
281+
/// Gets the player's <see cref="CustomPlayerEffects.Scp1509Resurrected"/> effect.
282+
/// </summary>
283+
public Scp1509Resurrected Scp1509Resurrected { get; private set; }
284+
279285
/// <summary>
280286
/// Gets the player's AmnesiaVision effect.
281287
/// </summary>
@@ -342,6 +348,73 @@ static EffectContainer()
342348
public Vitality Vitality { get; private set; }
343349
#endregion
344350

351+
#region Halloween Effects
352+
/// <summary>
353+
/// Gets the player's <see cref="MarshmallowEffect"/> effect.
354+
/// </summary>
355+
public MarshmallowEffect Marshmallow { get; private set; }
356+
357+
/// <summary>
358+
/// Gets the player's <see cref="CustomPlayerEffects.Metal"/> effect.
359+
/// </summary>
360+
public Metal Metal { get; private set; }
361+
362+
/// <summary>
363+
/// Gets the player's <see cref="CustomPlayerEffects.Prismatic"/> effect.
364+
/// </summary>
365+
public Prismatic Prismatic { get; private set; }
366+
367+
/// <summary>
368+
/// Gets the player's <see cref="CustomPlayerEffects.Spicy"/> effect.
369+
/// </summary>
370+
public Spicy Spicy { get; private set; }
371+
372+
/// <summary>
373+
/// Gets the player's <see cref="CustomPlayerEffects.SugarRush"/> effect.
374+
/// </summary>
375+
public SugarRush SugarRush { get; private set; }
376+
377+
/// <summary>
378+
/// Gets the player's <see cref="CustomPlayerEffects.SugarHigh"/> effect.
379+
/// </summary>
380+
public SugarHigh SugarHigh { get; private set; }
381+
382+
/// <summary>
383+
/// Gets the player's <see cref="CustomPlayerEffects.SugarCrave"/> effect.
384+
/// </summary>
385+
public SugarCrave SugarCrave { get; private set; }
386+
387+
/// <summary>
388+
/// Gets the player's <see cref="CustomPlayerEffects.OrangeCandy"/> effect.
389+
/// </summary>
390+
public OrangeCandy OrangeCandy { get; private set; }
391+
392+
/// <summary>
393+
/// Gets the player's <see cref="CustomPlayerEffects.OrangeWitness"/> effect.
394+
/// </summary>
395+
public OrangeWitness OrangeWitness { get; private set; }
396+
397+
/// <summary>
398+
/// Gets the player's <see cref="CustomPlayerEffects.WhiteCandy"/> effect.
399+
/// </summary>
400+
public WhiteCandy WhiteCandy { get; private set; }
401+
402+
/// <summary>
403+
/// Gets the player's <see cref="CustomPlayerEffects.SlowMetabolism"/> effect.
404+
/// </summary>
405+
public SlowMetabolism SlowMetabolism { get; private set; }
406+
407+
/// <summary>
408+
/// Gets the player's <see cref="CustomPlayerEffects.TemporaryBypass"/> effect.
409+
/// </summary>
410+
public TemporaryBypass TemporaryBypass { get; private set; }
411+
412+
/// <summary>
413+
/// Gets the player's <see cref="CustomPlayerEffects.TraumatizedByEvil"/> effect.
414+
/// </summary>
415+
public TraumatizedByEvil TraumatizedByEvil { get; private set; }
416+
#endregion
417+
345418
/// <summary>
346419
/// Whether or not the player has a forced fog type.
347420
/// </summary>
@@ -464,7 +537,7 @@ internal EffectContainer(PlayerEffectsController controller, ExPlayer player)
464537
}
465538
else
466539
{
467-
ApiLog.Warn("Effect API", $"No properties are defined for effect: {type.FullName}");
540+
ApiLog.Error("LabExtended", $"Effect &3{type.Name}&r does not have any properties!");
468541
}
469542
}
470543

@@ -478,24 +551,22 @@ internal EffectContainer(PlayerEffectsController controller, ExPlayer player)
478551

479552
if (props.Count != _properties.Count())
480553
{
481-
ApiLog.Warn("Effect API",
482-
$"Failed to set some effect properties (total={_properties.Count()} / set={props.Count})");
554+
ApiLog.Error("LabExtended", $"Some effects are missing! (set &6{props.Count}&r / &3{_properties.Count()}&r)");
483555

484556
foreach (var prop in _properties)
485557
{
486558
if (props.Contains(prop))
487559
continue;
488560

489-
ApiLog.Warn("Effect API", $"Missing effect for property: {prop.GetMemberName()}");
561+
ApiLog.Error("LabExtended", $"- &3{prop.Name}&r (&1{prop.PropertyType.Name}&r)");
490562
}
491563
}
492564

493565
ListPool<PropertyInfo>.Shared.Return(props);
494566
}
495567
catch (Exception ex)
496568
{
497-
ApiLog.Error("Effect API",
498-
$"An error occurred while setting up the effect container!\n{ex.ToColoredString()}");
569+
ApiLog.Error("LabExtended", $"An error occurred while setting up the effect container!\n{ex.ToColoredString()}");
499570
}
500571
}
501572

LabExtended/Extensions/EnumExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ public enum EnumOperation
2828

2929
private static readonly Dictionary<Type, Enum[]> _enumValuesCache = new();
3030

31+
/// <summary>
32+
/// Retrieves the highest value from the specified enumeration type.
33+
/// </summary>
34+
/// <remarks>This method uses the default comparer to determine the highest value in the
35+
/// enumeration.</remarks>
36+
/// <param name="enumType">The enumeration type to evaluate. Must be a valid enumeration type.</param>
37+
/// <returns>The highest value in the enumeration as an object, or <see langword="null"/> if the enumeration has no values.</returns>
38+
public static object? GetHighestEnumValue(this Type enumType)
39+
{
40+
var values = enumType.GetEnumValues();
41+
var highest = default(object);
42+
var type = Enum.GetUnderlyingType(enumType);
43+
44+
foreach (var value in values)
45+
{
46+
var underlyingValue = Convert.ChangeType(value, type);
47+
48+
if (highest is null
49+
|| Comparer<object>.Default.Compare(underlyingValue, highest) > 0)
50+
highest = underlyingValue;
51+
}
52+
53+
return highest;
54+
}
55+
3156
/// <summary>
3257
/// Gets all (cached) enum members.
3358
/// </summary>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using HarmonyLib;
2+
3+
using InventorySystem.Items.Pickups;
4+
5+
using LabApi.Features.Console;
6+
using LabApi.Features.Wrappers;
7+
8+
namespace LabExtended.Patches.Fixes
9+
{
10+
/// <summary>
11+
/// Supresses certain logs from the LabAPI that are deemed unnecessary or overly verbose.
12+
/// </summary>
13+
public static class LabApiSupressLogsPatch
14+
{
15+
private static HashSet<Type> missingWrappersLogged = new();
16+
17+
[HarmonyPatch(typeof(Pickup), nameof(Pickup.CreateItemWrapper))]
18+
private static bool PickupWrapperPrefix(ItemPickupBase pickupBase, ref Pickup __result)
19+
{
20+
var type = pickupBase.GetType();
21+
22+
if (Pickup.TypeWrappers.TryGetValue(type, out var constructor))
23+
{
24+
__result = constructor(pickupBase);
25+
}
26+
else if (missingWrappersLogged.Add(type))
27+
{
28+
ServerConsole.AddLog($"[LabApi] Failed to find pickup wrapper for type {type}", ConsoleColor.Yellow);
29+
}
30+
31+
return false;
32+
}
33+
}
34+
}

LabExtended/Patches/Functions/Items/ItemWeightPatches.cs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
using InventorySystem.Items.ToggleableLights.Lantern;
2020

2121
using LabExtended.API.Custom.Items;
22+
using LabExtended.Extensions;
23+
using LabExtended.Core;
2224

2325
namespace LabExtended.Patches.Functions.Items;
2426

@@ -27,11 +29,7 @@ namespace LabExtended.Patches.Functions.Items;
2729
/// </summary>
2830
public static class ItemWeightPatches
2931
{
30-
/// <summary>
31-
/// Gets the highest item ID.
32-
/// </summary>
33-
public const int HighestItemId = 66;
34-
32+
private static int loggedOutOfRange = 0;
3533
private static float[] customWeightArray;
3634

3735
/// <summary>
@@ -46,9 +44,16 @@ public static float[] GlobalCustomWeight
4644
{
4745
if (customWeightArray is null)
4846
{
49-
customWeightArray = new float[HighestItemId];
47+
var highestItemId = typeof(ItemType).GetHighestEnumValue();
48+
49+
if (highestItemId is null)
50+
throw new InvalidOperationException("Unable to determine the highest item ID from ItemType enum.");
51+
52+
var castItemId = (int)highestItemId;
5053

51-
for (var x = 0; x < HighestItemId; x++)
54+
customWeightArray = new float[castItemId + 1];
55+
56+
for (var x = 0; x < castItemId; x++)
5257
customWeightArray[x] = -1f;
5358
}
5459

@@ -67,12 +72,17 @@ public static float[] GlobalCustomWeight
6772
/// <param name="type">The item type for which to set the custom weight. Must be a valid, non-negative value.</param>
6873
/// <param name="weight">The weight value to assign to the specified item type.</param>
6974
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="type"/> is less than zero.</exception>
70-
public static void SetWeight(ItemType type, float weight)
75+
public static void SetWeight(this ItemType type, float weight)
7176
{
7277
if (type < 0)
7378
throw new ArgumentOutOfRangeException(nameof(type));
7479

75-
GlobalCustomWeight[(int)type] = weight;
80+
var index = (int)type;
81+
82+
if (index < 0 || index >= GlobalCustomWeight.Length)
83+
return;
84+
85+
GlobalCustomWeight[index] = weight;
7686
}
7787

7888
/// <summary>
@@ -100,7 +110,26 @@ public static void SetWeight(ushort serial, float weight)
100110
/// customizations are found.</returns>
101111
public static float GetWeight(ItemType type, ushort serial, float baseWeight)
102112
{
103-
var globalWeight = GlobalCustomWeight[(int)type];
113+
if (type is ItemType.None)
114+
return baseWeight;
115+
116+
var index = (int)type;
117+
118+
if (index < 0 || index >= GlobalCustomWeight.Length)
119+
{
120+
var logBit = index << 1;
121+
122+
if ((loggedOutOfRange & logBit) == 0)
123+
{
124+
ApiLog.Error("LabExtended", $"ItemType &3{type}&r (&6{(int)type}&r) is out of range for custom weight array!");
125+
126+
loggedOutOfRange |= logBit;
127+
}
128+
129+
return baseWeight;
130+
}
131+
132+
var globalWeight = GlobalCustomWeight[index];
104133

105134
if (type > 0 && globalWeight != -1f)
106135
baseWeight = globalWeight;

0 commit comments

Comments
 (0)