Skip to content

Commit a620671

Browse files
committed
Small changes
1 parent da77edc commit a620671

4 files changed

Lines changed: 25 additions & 50 deletions

File tree

UncomplicatedCustomItems/API/YAMLCaster.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static class YAMLCaster
2626
/// <returns>The <see cref="Dictionary{string, object}"/> of the class</returns>
2727
public static Dictionary<string, object> Encode(Data element)
2828
{
29-
Dictionary<string, object> serialized = new();
29+
Dictionary<string, object> serialized = [];
3030
SnakeCaseNamingStrategy snakeCaseStrategy = new();
3131

3232
foreach (PropertyInfo property in element.GetType().GetProperties())

UncomplicatedCustomItems/Intergrations/ECR.cs

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,26 @@
77
using UncomplicatedCustomItems.API;
88
using LabApi.Features.Wrappers;
99
using UnityEngine;
10-
using MEC;
1110
using UncomplicatedCustomItems.API.Interfaces;
1211

1312
namespace UncomplicatedCustomItems.Integrations
1413
{
15-
public static class ECRIntegration
14+
internal static class ECRIntegration
1615
{
1716
private static bool _isPatched = false;
18-
private static Harmony _harmonyInstance;
17+
private static bool Found;
1918

20-
public static void Initialize(Harmony harmonyInstance)
19+
public static void Init()
2120
{
22-
_harmonyInstance = harmonyInstance;
23-
2421
if (TryPatchECRIntegration())
2522
{
26-
LogManager.Silent("ECR Integration patched successfully on initialization.");
23+
LogManager.Silent("ECR Integration patched.");
24+
Found = true;
2725
return;
2826
}
2927

30-
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
31-
LogManager.Silent("ECR Integration waiting for Exiled.CustomRoles to load...");
32-
}
33-
34-
private static void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
35-
{
36-
if (_isPatched)
37-
return;
38-
39-
if (args.LoadedAssembly.GetName().Name.Contains("Exiled.CustomRoles"))
40-
{
41-
LogManager.Silent($"Detected Exiled.CustomRoles assembly load: {args.LoadedAssembly.FullName}");
42-
43-
Timing.CallDelayed(1f, () =>
44-
{
45-
if (TryPatchECRIntegration())
46-
{
47-
LogManager.Silent("ECR Integration patched successfully after assembly load.");
48-
AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
49-
}
50-
});
51-
}
28+
if (Found)
29+
LogManager.Silent($"ECR found! :D");
5230
}
5331

5432
private static bool TryPatchECRIntegration()
@@ -61,13 +39,13 @@ private static bool TryPatchECRIntegration()
6139
MethodBase targetMethod = GetTargetMethod();
6240
if (targetMethod == null)
6341
{
64-
LogManager.Silent("ECR target method not found - Exiled.CustomRoles may not be loaded yet.");
42+
LogManager.Silent("ECR target method not found.");
6543
return false;
6644
}
6745

6846
MethodInfo prefixMethod = typeof(ECRIntegration).GetMethod(nameof(Prefix), BindingFlags.Static | BindingFlags.Public);
6947

70-
_harmonyInstance.Patch(targetMethod, new HarmonyMethod(prefixMethod));
48+
Plugin.Instance._harmony.Patch(targetMethod, new HarmonyMethod(prefixMethod));
7149
_isPatched = true;
7250
LogManager.Silent("ECR Integration successfully patched TryAddItem method.");
7351
return true;
@@ -83,27 +61,21 @@ private static MethodBase GetTargetMethod()
8361
{
8462
try
8563
{
86-
Type customRoleType = AppDomain.CurrentDomain.GetAssemblies()
87-
.SelectMany(GetTypesFromAssembly)
88-
.FirstOrDefault(t => t.FullName == "Exiled.CustomRoles.API.Features.CustomRole");
89-
64+
Type customRoleType = AppDomain.CurrentDomain.GetAssemblies().SelectMany(GetTypesFromAssembly).FirstOrDefault(t => t.FullName == "Exiled.CustomRoles.API.Features.CustomRole");
9065
if (customRoleType == null)
9166
return null;
9267

93-
MethodInfo method = customRoleType.GetMethod("TryAddItem",
94-
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
95-
null,
96-
[
97-
Type.GetType("Exiled.API.Features.Player, Exiled.API"),
98-
typeof(string)
99-
],
100-
null);
68+
Type[] paramTypes = [
69+
Type.GetType("Exiled.API.Features.Player, Exiled.API"),
70+
typeof(string)
71+
];
10172

73+
MethodInfo method = customRoleType.GetMethod("TryAddItem", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, paramTypes, null);
10274
return method;
10375
}
10476
catch (Exception ex)
10577
{
106-
LogManager.Debug($"Error in GetTargetMethod(): {ex.Message}");
78+
LogManager.Debug($"{nameof(GetTargetMethod)}: {ex.Message}");
10779
return null;
10880
}
10981
}
@@ -163,14 +135,13 @@ public static bool Prefix(object __instance, object player, string itemName, ref
163135
}
164136
catch (Exception ex)
165137
{
166-
LogManager.Error($"Error in ECRIntegration.Prefix(): {ex}");
138+
LogManager.Error($"{nameof(ECRIntegration)}: {ex}");
167139
return true;
168140
}
169141
}
170142

171143
public static void Cleanup()
172144
{
173-
AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
174145
_isPatched = false;
175146
}
176147
}

UncomplicatedCustomItems/Intergrations/MER.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void Init()
3434

3535
if (Found)
3636
{
37-
LogManager.Silent($"MER Found!");
37+
LogManager.Silent($"MER Found! :D");
3838
Register();
3939
}
4040
else

UncomplicatedCustomItems/Plugin.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class Plugin : Plugin<Config>
4444
#endif
4545
public override string Author => "SpGerg, FoxWorn & Mr. Baguetter";
4646
#if EXILED
47-
public override Version RequiredExiledVersion { get; } = new(9, 9, 1);
47+
public override Version RequiredExiledVersion { get; } = new(9, 8, 1);
4848
#else
4949
public override Version RequiredApiVersion { get; } = LabApi.Features.LabApiProperties.CurrentVersion;
5050
#endif
@@ -172,9 +172,12 @@ public override void Enable()
172172
FileConfig.LoadAll(Server.Port.ToString());
173173
FileConfig.LoadAll("Actions");
174174

175+
#if EXILED
176+
_harmony = new($"com.ucs.uci_exiled-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}");
177+
#else
175178
_harmony = new($"com.ucs.uci_labapi-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}");
179+
#endif
176180
_harmony.PatchAll();
177-
ECRIntegration.Initialize(_harmony);
178181
#if EXILED
179182
if (Round.IsStarted)
180183
#else
@@ -261,6 +264,7 @@ public void OnFinishedLoading()
261264

262265
LabAPIExtensions.Init();
263266
MERIntergration.Init();
267+
ECRIntegration.Init();
264268
#if EXILED
265269
CommonUtilitiesPatch.Initialize();
266270
#endif

0 commit comments

Comments
 (0)