Skip to content

Commit cc516a5

Browse files
added direct EXILED support
1 parent 114350b commit cc516a5

File tree

9 files changed

+179
-39
lines changed

9 files changed

+179
-39
lines changed

Code/ContextSystem/Contexts/Control/IfStatementContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using SER.Code.ContextSystem.BaseContexts;
2-
using SER.Code.ContextSystem.Extensions;
32
using SER.Code.ContextSystem.Structures;
43
using SER.Code.Helpers;
54
using SER.Code.Helpers.Exceptions;

Code/Helpers/ExiledHelper.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using LabApi.Loader;
2+
using MEC;
3+
using UnityEngine;
4+
using Logger = LabApi.Features.Console.Logger;
5+
6+
namespace SER.Code.Helpers;
7+
8+
public static class ExiledHelper
9+
{
10+
private const string ExiledLoaderName = "Exiled Loader";
11+
12+
public static event Action? OnExiledDetected;
13+
14+
public static IEnumerator<float> ExiledAwaiter()
15+
{
16+
uint attempts = 0;
17+
while (PluginLoader.EnabledPlugins.All(p => p.Name != ExiledLoaderName))
18+
{
19+
if (attempts++ > 20)
20+
{
21+
Logger.Raw("SER <-> EXILED bind failed. EXILED specific methods will NOT be loaded.", ConsoleColor.DarkYellow);
22+
yield break;
23+
}
24+
25+
yield return Timing.WaitForSeconds(0.1f);
26+
}
27+
28+
Logger.Raw("SER <-> EXILED bind was successful. EXILED specific methods will be loaded.", ConsoleColor.Green);
29+
OnExiledDetected?.Invoke();
30+
}
31+
}

Code/MethodSystem/MethodIndex.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
using System.Reflection;
22
using LabApi.Features.Console;
3+
using SER.Code.Helpers;
34
using SER.Code.Helpers.ResultSystem;
45
using SER.Code.MethodSystem.BaseMethods;
6+
using SER.Code.MethodSystem.Structures;
57

68
namespace SER.Code.MethodSystem;
79

810
public static class MethodIndex
911
{
10-
private static readonly Dictionary<string, Method> NameToMethodIndex = new();
12+
private static readonly Dictionary<string, Method> NameToMethodIndex = [];
13+
private static readonly HashSet<Type> ExiledMethods = [];
1114

1215
/// <summary>
1316
/// Initializes the method index.
1417
/// </summary>
1518
internal static void Initialize()
1619
{
1720
NameToMethodIndex.Clear();
18-
21+
1922
AddAllDefinedMethodsInAssembly();
23+
24+
ExiledHelper.OnExiledDetected += () =>
25+
{
26+
foreach (var method in ExiledMethods)
27+
{
28+
AddMethod((Method)Activator.CreateInstance(method));
29+
}
30+
};
2031
}
2132

2233
/// <summary>
@@ -38,6 +49,13 @@ public static void AddAllDefinedMethodsInAssembly(Assembly? assembly = null)
3849
assembly ??= Assembly.GetCallingAssembly();
3950
var definedMethods = assembly.GetTypes()
4051
.Where(t => t.IsClass && !t.IsAbstract && typeof(Method).IsAssignableFrom(t))
52+
.Where(t =>
53+
{
54+
if (!typeof(IExiledMethod).IsAssignableFrom(t)) return true;
55+
56+
ExiledMethods.Add(t);
57+
return false;
58+
})
4159
.Select(t => Activator.CreateInstance(t) as Method)
4260
.ToList();
4361

Code/MethodSystem/Methods/CASSIEMethods/CassieMethod.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class CassieMethod : SynchronousMethod
1717
"noJingle"
1818
),
1919
new TextArgument("message"),
20-
new TextArgument("translation")
20+
new TextArgument("subtitles")
2121
{
2222
DefaultValue = new("", "empty"),
2323
},
@@ -32,9 +32,10 @@ public override void Execute()
3232
{
3333
var isNoisy = Args.GetOption("mode") == "jingle";
3434
var message = Args.GetText("message");
35-
var translation = Args.GetText("translation");
35+
var subtitles = Args.GetText("subtitles");
3636
var glitch = Args.GetBool("should glitch");
3737

38+
// todo: check if this is still needed
3839
if (glitch)
3940
{
4041
// taken from Respawning.Announcements.WaveAnnouncementBase.PlayAnnouncement()
@@ -66,23 +67,11 @@ public override void Execute()
6667
}
6768
}
6869

69-
if (string.IsNullOrEmpty(translation))
70-
{
71-
LabApi.Features.Wrappers.Cassie.Message(
72-
message,
73-
true,
74-
isNoisy
75-
);
76-
}
77-
else
78-
{
79-
LabApi.Features.Wrappers.Cassie.Message(
80-
message,
81-
true,
82-
isNoisy,
83-
true,
84-
translation
85-
);
86-
}
70+
// todo: check how to make the cassie silent again
71+
LabApi.Features.Wrappers.Cassie.Message(
72+
message,
73+
subtitles,
74+
glitchScale: isNoisy ? 1f : 0f
75+
);
8776
}
8877
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Exiled.API.Extensions;
2+
using Exiled.API.Features;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods;
6+
using SER.Code.MethodSystem.Structures;
7+
8+
namespace SER.Code.MethodSystem.Methods.CASSIEMethods;
9+
10+
public class PlayerCassieMethod : SynchronousMethod, IExiledMethod
11+
{
12+
public override string Description => "Makes a CASSIE announcement to specified players only.";
13+
14+
public override Argument[] ExpectedArguments { get; } =
15+
[
16+
new PlayersArgument("players"),
17+
new OptionsArgument("mode",
18+
"jingle",
19+
"noJingle"
20+
),
21+
new TextArgument("message"),
22+
new TextArgument("subtitles")
23+
{
24+
DefaultValue = new("", "empty"),
25+
}
26+
];
27+
28+
public override void Execute()
29+
{
30+
var players = Args.GetPlayers("players");
31+
var isNoisy = Args.GetOption("mode") == "jingle";
32+
var message = Args.GetText("message");
33+
var subtitles = Args.GetText("subtitles");
34+
35+
foreach (var player in players.Select(Player.Get))
36+
{
37+
player.MessageTranslated(
38+
message,
39+
subtitles,
40+
subtitles,
41+
isNoisy,
42+
!string.IsNullOrWhiteSpace(subtitles)
43+
);
44+
}
45+
}
46+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Exiled.API.Enums;
2+
using Exiled.API.Features;
3+
using JetBrains.Annotations;
4+
using SER.Code.ArgumentSystem.Arguments;
5+
using SER.Code.ArgumentSystem.BaseArguments;
6+
using SER.Code.MethodSystem.BaseMethods;
7+
using SER.Code.MethodSystem.Structures;
8+
9+
namespace SER.Code.MethodSystem.Methods.PlayerMethods;
10+
11+
[UsedImplicitly]
12+
public class GiveEffectMethod : SynchronousMethod, IExiledMethod
13+
{
14+
public override string Description => "Adds a provided effect to a player.";
15+
16+
public override Argument[] ExpectedArguments { get; } =
17+
[
18+
new PlayersArgument("players"),
19+
new EnumArgument<EffectType>("effect type"),
20+
new DurationArgument("duration")
21+
{
22+
DefaultValue = new(TimeSpan.Zero, "infinite")
23+
},
24+
new IntArgument("intensity", 0, 255)
25+
{
26+
DefaultValue = new(1, null)
27+
},
28+
new BoolArgument("add duration if active")
29+
{
30+
DefaultValue = new(false, null)
31+
}
32+
];
33+
34+
public override void Execute()
35+
{
36+
var players = Args.GetPlayers("players");
37+
var effectType = Args.GetEnum<EffectType>("effect type");
38+
var duration = (float)Args.GetDuration("duration").TotalSeconds;
39+
var intensity = (byte)Args.GetInt("intensity");
40+
41+
players.ForEach(plr
42+
=> Player.Get(plr).EnableEffect(effectType, intensity, duration)
43+
);
44+
}
45+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SER.Code.MethodSystem.Structures;
2+
3+
/// <summary>
4+
/// Marks that this method can only load when EXILED is loaded as well
5+
/// </summary>
6+
public interface IExiledMethod;

Code/Plugin/MainPlugin.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using LabApi.Features.Console;
44
using MEC;
55
using SER.Code.FlagSystem.Flags;
6+
using SER.Code.Helpers;
67
using SER.Code.Helpers.Extensions;
78
using SER.Code.MethodSystem;
89
using SER.Code.MethodSystem.Methods.PlayerDataMethods;
@@ -21,11 +22,11 @@ public class MainPlugin : LabApi.Loader.Features.Plugins.Plugin<Config>
2122
public override string Author => "Elektryk_Andrzej";
2223
public override Version RequiredApiVersion => LabApiProperties.CurrentVersion;
2324
public override Version Version => new(0, 13, 0);
24-
25+
2526
public static string GitHubLink => "https://github.com/ScriptedEvents/ScriptedEventsReloaded";
2627
public static string DocsLink => "https://scriptedeventsreloaded.gitbook.io/docs/tutorial";
2728
public static string DiscordLink => "https://discord.gg/3j54zBnbbD";
28-
29+
2930
public static string HelpCommandName => "serhelp";
3031
public static MainPlugin Instance { get; private set; } = null!;
3132

@@ -34,17 +35,17 @@ public record struct Contributor(string Name, Contribution Contribution);
3435
[Flags]
3536
public enum Contribution
3637
{
37-
None = 0,
38-
LeadDeveloper = 1 << 1,
39-
Developer = 1 << 2,
38+
None = 0,
39+
LeadDeveloper = 1 << 1,
40+
Developer = 1 << 2,
4041
QualityAssurance = 1 << 3,
41-
Sponsor = 1 << 4,
42-
Betatester = 1 << 5,
43-
EarlyAdopter = 1 << 6,
44-
TechSupport = 1 << 7,
42+
Sponsor = 1 << 4,
43+
Betatester = 1 << 5,
44+
EarlyAdopter = 1 << 6,
45+
TechSupport = 1 << 7,
4546
}
4647

47-
public static Contributor[] Contributors =>
48+
public static Contributor[] Contributors =>
4849
[
4950
new(Instance.Author, Contribution.LeadDeveloper),
5051
new("Whitty985playz", Contribution.QualityAssurance | Contribution.EarlyAdopter),
@@ -59,18 +60,19 @@ public enum Contribution
5960
public override void Enable()
6061
{
6162
Instance = this;
62-
63+
6364
Script.StopAll();
6465
EventHandler.Initialize();
6566
MethodIndex.Initialize();
6667
VariableIndex.Initialize();
6768
Flag.RegisterFlags();
6869
CommandEvents.Initialize();
70+
ExiledHelper.ExiledAwaiter().RunCoroutine();
6971
SendLogo();
70-
72+
7173
Events.ServerEvents.WaitingForPlayers += OnServerFullyInit;
7274
Events.ServerEvents.RoundRestarted += Disable;
73-
75+
7476
Timing.CallDelayed(1.5f, FileSystem.FileSystem.Initialize);
7577
}
7678

@@ -79,11 +81,11 @@ public override void Disable()
7981
Script.StopAll();
8082
SetPlayerDataMethod.PlayerData.Clear();
8183
}
82-
84+
8385
private void OnServerFullyInit()
8486
{
8587
if (Config?.SendHelpMessageOnServerInitialization is false) return;
86-
88+
8789
Logger.Raw(
8890
$"""
8991
Thank you for using ### Scripted Events Reloaded ### by {Author}!
@@ -102,7 +104,7 @@ private static void SendLogo()
102104
Logger.Raw(
103105
"""
104106
#####################################
105-
107+
106108
█████████ ██████████ ███████████
107109
███░░░░░███░░███░░░░░█░░███░░░░░███
108110
░███ ░░░ ░███ █ ░ ░███ ░███

SER.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
<Reference Include="UnityEngine.CoreModule">
5959
<HintPath>$(SL_DEV_REFERENCES)\UnityEngine.CoreModule.dll</HintPath>
6060
</Reference>
61+
<Reference Include="UnityEngine.PhysicsModule">
62+
<HintPath>$(SL_DEV_REFERENCES)\UnityEngine.PhysicsModule.dll</HintPath>
63+
</Reference>
6164
</ItemGroup>
6265

6366
<!-- QoL moving the dll -->
@@ -82,6 +85,7 @@
8285
<!-- nuget refs -->
8386
<ItemGroup>
8487
<PackageReference Include="AudioPlayerApi" Version="1.1.2" />
88+
<PackageReference Include="ExMod.Exiled" Version="9.12.2" />
8589
<PackageReference Include="NCalc" Version="1.3.8" />
8690
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
8791
<PackageReference Include="Northwood.LabAPI" Version="1.1.4" />

0 commit comments

Comments
 (0)