diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 263cafbc..977baa93 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -27,7 +27,7 @@ jobs: - name: Add plugins to server.cfg file run: | echo "" >> ctf-gamemode-windows/server.cfg - echo "plugins SampSharp streamer" >> ctf-gamemode-windows/server.cfg + echo "plugins SampSharp streamer YSF" >> ctf-gamemode-windows/server.cfg - name: Build game mode run: dotnet publish src/Host -c Release -o bin --framework=net8.0 - name: Copy artifacts diff --git a/plugins/YSF.cfg b/plugins/YSF.cfg new file mode 100644 index 00000000..b7e7c4f9 --- /dev/null +++ b/plugins/YSF.cfg @@ -0,0 +1,41 @@ +# Turning this on disables all hooks and custom processing, as well as natives that rely on that +PassiveMode 0 + +# Protection against fake pickup ids +PickupProtection 0 + +# Protection against fakekill +DeathProtection 0 + +# Protection against sproofed dialog ids +DialogProtection 0 + +# Use redirected YSF's own RPC for spawning +UseCustomSpawn 0 + +# Set it to 1 when you want to use per player gangzones +UsePerPlayerGangZones 0 + +# Allowing remote RCON connections with banned IPs (its very good to enable when you need to unban yourself) +AllowRemoteRCONWithBannedIPs 0 + +# Use this if you want to use SetMaxPlayers to increase your server slots at runtime +# DANGER: With enabling this option server will allow to connect 1000 players, doesn't matter what is your "maxplayers" value in server.cfg! +IncreaseRakNetInternalPlayers 0 + +# If the option above isn't enabled this option won't have any effect +# Change raknet internal threads sleeping time, lowering the value migh result in smoother sync - by default is 5ms +RakNetInternalSleepTime 5 + +# Delay im ms - object will be attached to player after this delay passed, lowering this delay might result in crashes +AttachObjectDelay 2000 + +# SA-MP by default doesn't store material info for per-player objects, which made GetPlayerObjectMaterial/MaterialText broken +# If you just use streamer for objects and you don't wanna use those two natives below, then disable this option +StorePlayerObjectsMaterial 1 + +# With this option you can load YSF on whatever server version, but it can result unwanted behavior +SkipVersionCheck 0 + +# This option makes newly created player objects prioritize IDs used by other existing player objects. +GroupPlayerObjects 0 \ No newline at end of file diff --git a/plugins/YSF.dll b/plugins/YSF.dll new file mode 100644 index 00000000..217b3d14 Binary files /dev/null and b/plugins/YSF.dll differ diff --git a/plugins/YSF.so b/plugins/YSF.so new file mode 100644 index 00000000..d1b2eb72 Binary files /dev/null and b/plugins/YSF.so differ diff --git a/server.cfg.example b/server.cfg.example index dbecbc66..e0b740e0 100644 --- a/server.cfg.example +++ b/server.cfg.example @@ -1,7 +1,7 @@ echo Executing Server Config... gamemode0 empty skip_empty_check true -plugins libSampSharp.so streamer.so +plugins libSampSharp.so streamer.so YSF.so filterscripts rcon_password password port 7777 diff --git a/src/Host/Extensions/HostEcsBuilderExtensions.cs b/src/Host/Extensions/HostEcsBuilderExtensions.cs index b1deaf0a..2b768018 100644 --- a/src/Host/Extensions/HostEcsBuilderExtensions.cs +++ b/src/Host/Extensions/HostEcsBuilderExtensions.cs @@ -23,7 +23,8 @@ public static IEcsBuilder EnableExceptionHandler(this IEcsBuilder builder) "OnPlayerPickUpPickup", "OnPlayerSpawn", "OnPlayerRequestClass", - "OnPlayerRequestSpawn" + "OnPlayerRequestSpawn", + "OnPlayerPauseStateChange" ]; foreach (string @event in events) @@ -33,4 +34,13 @@ public static IEcsBuilder EnableExceptionHandler(this IEcsBuilder builder) return builder; } + + public static IEcsBuilder EnableYsfEvents(this IEcsBuilder builder) + { + builder + .EnableEvent("OnPlayerPauseStateChange"); + + builder.UseMiddleware("OnPlayerPauseStateChange"); + return builder; + } } diff --git a/src/Host/Middlewares/PlayerPauseStateChangeMiddleware.cs b/src/Host/Middlewares/PlayerPauseStateChangeMiddleware.cs new file mode 100644 index 00000000..cc9d04d4 --- /dev/null +++ b/src/Host/Middlewares/PlayerPauseStateChangeMiddleware.cs @@ -0,0 +1,15 @@ +namespace CTF.Host.Middlewares; + +public class PlayerPauseStateChangeMiddleware(EventDelegate next) +{ + public object Invoke(EventContext context, IEntityManager entityManager) + { + var playerEntity = SampEntities.GetPlayerId((int)context.Arguments[0]); + + if (!entityManager.Exists(playerEntity)) + return null; + + context.Arguments[0] = playerEntity; + return next(context); + } +} diff --git a/src/Host/Startup.cs b/src/Host/Startup.cs index 201c8dfb..981f014e 100644 --- a/src/Host/Startup.cs +++ b/src/Host/Startup.cs @@ -32,6 +32,7 @@ public void Configure(IEcsBuilder builder) .EnableSampEvents() .EnablePlayerCommands() .EnableRconCommands() - .EnableStreamerEvents(); + .EnableStreamerEvents() + .EnableYsfEvents(); } }