diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 68de403..5af870c 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -20,7 +20,7 @@ public static class Map /// /// Gives you a list of all lifts /// - public static List Lifts => Object.FindObjectsOfType().ToList(); + public static List Lifts => Server.GetObjectsOf(); private static Broadcast BroadcastComponent => Player.Host.GetComponent(); @@ -175,6 +175,32 @@ public static Vector3 GetRandomSpawnPoint(this RoleType type) public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) => Player.Host.Inventory.SetPickup(itemType, durability, position, rotation, sight, barrel, other); + public static WorkStation SpawnWorkStation(Vector3 position,Vector3 rotation,Vector3 size) + { + GameObject bench = + Object.Instantiate( + NetworkManager.singleton.spawnPrefabs.Find(p => p.gameObject.name == "Work Station")); + Offset offset = new Offset(); + offset.position = position; + offset.rotation = rotation; + offset.scale = Vector3.one; + bench.gameObject.transform.localScale = size; + + NetworkServer.Spawn(bench); + bench.GetComponent().Networkposition = offset; + bench.AddComponent(); + + return bench.GetComponent(); + } + + public static void SpawnRagdoll(Vector3 Position,RoleType role,string killer = "World") + { + Server.Host.GetComponent().SpawnRagdoll( + Position, Quaternion.identity, Vector3.zero, (int)role, + new PlayerStats.HitInfo(1000f, killer, DamageTypes.Falldown, 1) + , false, killer, killer, 1); + } + public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Vector3 scale, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) { var p = Server.Host.Inventory.SetPickup(itemType, -4.656647E+11f, position,Quaternion.identity, 0, 0, 0); diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 599affa..f4d7794 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -248,7 +248,7 @@ public Room Room get { var playerPos = Position; - var end = playerPos - new Vector3(0f, 10f, 0f); + var end = playerPos - new Vector3(0f, 30f, 0f); var flag = Physics.Linecast(playerPos, end, out var rayCastHit, -84058629); if (!flag || rayCastHit.transform == null) @@ -393,6 +393,11 @@ public Player Cuffer public string UnitName { get => ClassManager.NetworkCurUnitName; set => ClassManager.NetworkCurUnitName = value; } + /// + /// If the Client sends a DnT Signal, useful for storing data + /// + public bool DoNotTrack => ServerRoles.DoNotTrack; + //Methods /// /// Kicks the player @@ -511,6 +516,8 @@ public void InstantBroadcast(ushort time, string message) /// public void GiveItem(ItemType itemType, float duration = float.NegativeInfinity, int sight = 0, int barrel = 0, int other = 0) => Hub.inventory.AddNewItem(itemType, duration, sight, barrel, other); + public void DropAllItems() => Inventory.ServerDropAll(); + public void DropItem(Inventory.SyncItemInfo item) { Inventory.SetPickup(item.id, item.durability, Position, Inventory.camera.transform.rotation, item.modSight, item.modBarrel, item.modOther); @@ -579,5 +586,36 @@ public void SendToServer(ushort port) Connection.Send(msg); NetworkWriterPool.Recycle(writer); } + + public void DimScreen() + { + var component = RoundSummary.singleton; + var writer = NetworkWriterPool.GetWriter(); + var msg = new RpcMessage + { + netId = component.netId, + componentIndex = component.ComponentIndex, + functionHash = Server.GetMethodHash(typeof(RoundSummary), "RpcDimScreen"), + payload = writer.ToArraySegment() + }; + Connection.Send(msg); + NetworkWriterPool.Recycle(writer); + } + + public void ShakeScreen(bool achieve = false) + { + var component = Warhead.Controller; + var writer = NetworkWriterPool.GetWriter(); + writer.WriteBoolean(achieve); + var msg = new RpcMessage + { + netId = component.netId, + componentIndex = component.ComponentIndex, + functionHash = Server.GetMethodHash(typeof(AlphaWarheadController), "RpcShake"), + payload = writer.ToArraySegment() + }; + Connection.Send(msg); + NetworkWriterPool.Recycle(writer); + } } } diff --git a/Synapse/Api/Plugin/Plugin.cs b/Synapse/Api/Plugin/Plugin.cs index 9a4aa0c..571a893 100644 --- a/Synapse/Api/Plugin/Plugin.cs +++ b/Synapse/Api/Plugin/Plugin.cs @@ -15,9 +15,10 @@ public abstract class Plugin // ReSharper disable once NotAccessedField.Global public static YamlConfig Config; + [Obsolete("Please use public override void ReloadConfigs() now!")] public delegate void OnConfigReload(); + [Obsolete("Please use public override void ReloadConfigs() now!")] public event OnConfigReload ConfigReloadEvent; - internal void InvokeConfigReloadEvent() => ConfigReloadEvent?.Invoke(); // ReSharper disable once UnusedAutoPropertyAccessor.Global public Translation Translation { get; internal set; } @@ -81,5 +82,7 @@ public virtual void RegisterCommands() } } } + + public virtual void ReloadConfigs() => ConfigReloadEvent.Invoke(); } } \ No newline at end of file diff --git a/Synapse/Api/Round.cs b/Synapse/Api/Round.cs index a045e1d..f0a176b 100644 --- a/Synapse/Api/Round.cs +++ b/Synapse/Api/Round.cs @@ -6,9 +6,12 @@ namespace Synapse.Api { public static class Round { + [Obsolete("Please use RoundLength")] public static TimeSpan RoundLenght => RoundStart.RoundLenght; - public static DateTime StartedTime => DateTime.Now - RoundLenght; + public static TimeSpan RoundLength => RoundStart.RoundLenght; + + public static DateTime StartedTime => DateTime.Now - RoundLength; public static bool IsStarted => RoundSummary.RoundInProgress(); diff --git a/Synapse/Api/Server.cs b/Synapse/Api/Server.cs index 5024fe8..348c126 100644 --- a/Synapse/Api/Server.cs +++ b/Synapse/Api/Server.cs @@ -2,6 +2,8 @@ using Mirror; using RemoteAdmin; using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; namespace Synapse.Api @@ -70,6 +72,8 @@ public static BanPlayer BanPlayer public static ClientCommandHandler ClientCommandHandler => QueryProcessor.DotCommandHandler; + public static List GetObjectsOf() where TObject : UnityEngine.Object => UnityEngine.Object.FindObjectsOfType().ToList(); + public static int GetMethodHash(Type invokeClass, string methodName) => invokeClass.FullName.GetStableHashCode() * 503 + methodName.GetStableHashCode(); } } diff --git a/Synapse/Commands/KeyPressCommand.cs b/Synapse/Commands/KeyPressCommand.cs new file mode 100644 index 0000000..73b290e --- /dev/null +++ b/Synapse/Commands/KeyPressCommand.cs @@ -0,0 +1,70 @@ +using CommandSystem; +using Synapse.Api; +using System; +using System.Linq; +using UnityEngine; + +namespace Synapse.Commands +{ + [CommandHandler(typeof(ClientCommandHandler))] + public class KeyPressCommand : ICommand + { + public string Command { get; } = "keypress"; + + public string[] Aliases { get; } = new string[] + { + "kp", + "key", + "keybind" + }; + + public string Description { get; } = "A Command for the KeyPressEvent from Synapse!"; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string respone) + { + if (sender.GetPlayer() == Server.Host) + { + respone = "Nope the Console cant use this!"; + return false; + } + + if (arguments.Count < 1) + { + respone = "Use .key sync in order to sync your binds and use all Features of the Plugins!"; + return false; + } + + switch (arguments.FirstOrDefault().ToUpper()) + { + case "SYNC": + var component = sender.GetPlayer().ClassManager; + foreach(var key in (KeyCode[])Enum.GetValues(typeof(KeyCode))) + component.TargetChangeCmdBinding(component.connectionToClient, key, $".key send {(int)key}"); + + respone = "All Keys was synced!"; + return true; + + case "SEND": + if(!Enum.TryParse(arguments.ElementAt(1), out var key2)) + { + respone = "Invalid KeyBind! If they are binded by Synapse please report this!"; + return false; + } + + try + { + Events.Events.InvokeKeyPressEvent(sender.GetPlayer(), key2); + } + catch (Exception e) + { + Log.Error($"KeyPressEvent Error: {e} "); + } + respone = "Key was accepted"; + return true; + default: + respone = "Use .key sync in order to sync your binds and use all Features of the Plugins!"; + return false; + } + } + } +} diff --git a/Synapse/Commands/PluginInfoCommand.cs b/Synapse/Commands/PluginInfoCommand.cs new file mode 100644 index 0000000..9c1f072 --- /dev/null +++ b/Synapse/Commands/PluginInfoCommand.cs @@ -0,0 +1,42 @@ +using CommandSystem; +using System; +using System.Linq; + +namespace Synapse.Commands +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + [CommandHandler(typeof(GameConsoleCommandHandler))] + [CommandHandler(typeof(ClientCommandHandler))] + public class PluginInfoCommand : ICommand + { + public string Command { get; } = "plugin"; + + public string[] Aliases { get; } = new string[] + { + "plugininfo", + "pi" + }; + + public string Description { get; } = "Gives you Informations about a Plugin"; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string respone) + { + if (arguments.Count < 1) + { + respone = "You also have to enter a plugin name: plugin ExamplePlugin"; + return false; + } + + foreach(var plugin in Synapse.Plugins) + if (plugin.Name.ToLower().Contains(arguments.FirstOrDefault().ToLower())) + { + respone = $"The Plugin {plugin.Name} Version {plugin.Version} was created by {plugin.Author} and was made for Synapse v.{plugin.SynapseMajor}.{plugin.SynapseMinor}.{plugin.SynapsePatch}" + + $"\nPlugin Description: {plugin.Description}"; + return true; + } + + respone = "No Plugin with such a name was found!"; + return false; + } + } +} diff --git a/Synapse/Commands/PluginsCommand.cs b/Synapse/Commands/PluginsCommand.cs new file mode 100644 index 0000000..7c34ceb --- /dev/null +++ b/Synapse/Commands/PluginsCommand.cs @@ -0,0 +1,32 @@ +using CommandSystem; +using System; + +namespace Synapse.Commands +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + [CommandHandler(typeof(GameConsoleCommandHandler))] + [CommandHandler(typeof(ClientCommandHandler))] + public class PluginsCommand : ICommand + { + public string Command { get; } = "plugins"; + + public string[] Aliases { get; } = new string[] + { + "pl", + }; + + public string Description { get; } = "Gives you all Plugins installed on the Server"; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string respone) + { + var msg = "\nAll Plugins:"; + foreach(var plugin in Synapse.Plugins) + { + msg += $"\n{plugin.Name} Version: {plugin.Version} by {plugin.Author}"; + } + + respone = msg; + return true; + } + } +} diff --git a/Synapse/Commands/ReloadConfigsCommand.cs b/Synapse/Commands/ReloadConfigsCommand.cs new file mode 100644 index 0000000..b934d0c --- /dev/null +++ b/Synapse/Commands/ReloadConfigsCommand.cs @@ -0,0 +1,34 @@ +using CommandSystem; +using Synapse.Api; +using Synapse.Config; +using System; + +namespace Synapse.Commands +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class ReloadConfigsCommand : ICommand + { + public string Command { get; } = "reloadconfigs"; + + public string[] Aliases { get; } = new string[] + { + "rc", + "reloadc" + }; + + public string Description { get; } = "A Command to Relaod the Configs of Synapse"; + + public bool Execute(ArraySegment arguments,ICommandSender sender,out string respone) + { + if (!sender.GetPlayer().CheckPermission("sy.reload.configs")) + { + respone = "You have no Permission for Reload Configs"; + return false; + } + + ConfigManager.ReloadAllConfigs(); + respone = "Configs Reloaded!"; + return true; + } + } +} diff --git a/Synapse/Commands/ReloadPermissionsCommand.cs b/Synapse/Commands/ReloadPermissionsCommand.cs new file mode 100644 index 0000000..1e55261 --- /dev/null +++ b/Synapse/Commands/ReloadPermissionsCommand.cs @@ -0,0 +1,34 @@ +using CommandSystem; +using Synapse.Api; +using Synapse.Config; +using System; + +namespace Synapse.Commands +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class ReloadPermissionsCommand : ICommand + { + public string Command { get; } = "reloadpermissions"; + + public string[] Aliases { get; } = new string[] + { + "rp", + "reloadp" + }; + + public string Description { get; } = "A Command to Relaod the Permissions of Synapse"; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string respone) + { + if (!sender.GetPlayer().CheckPermission("sy.reload.permission")) + { + respone = "You have no Permission for Reload Permissions"; + return false; + } + + PermissionReader.ReloadPermission(); + respone = "Permissions Reloaded!"; + return true; + } + } +} diff --git a/Synapse/Config/ConfigManager.cs b/Synapse/Config/ConfigManager.cs index b5017c5..e921beb 100644 --- a/Synapse/Config/ConfigManager.cs +++ b/Synapse/Config/ConfigManager.cs @@ -19,7 +19,7 @@ internal static void ReloadAllConfigs() foreach (var plugin in Synapse.plugins) try { - plugin.InvokeConfigReloadEvent(); + plugin.ReloadConfigs(); } catch (Exception e) { diff --git a/Synapse/Events/Classes/ConsoleCommandEvent.cs b/Synapse/Events/Classes/ConsoleCommandEvent.cs index ffbe4bd..6734fcd 100644 --- a/Synapse/Events/Classes/ConsoleCommandEvent.cs +++ b/Synapse/Events/Classes/ConsoleCommandEvent.cs @@ -9,9 +9,5 @@ public class ConsoleCommandEvent public Player Player { get; internal set; } public string Command { get; internal set; } - - public string ReturnMessage { get; set; } - - public string Color { get; set; } } } \ No newline at end of file diff --git a/Synapse/Events/Classes/KeyPressEvent.cs b/Synapse/Events/Classes/KeyPressEvent.cs new file mode 100644 index 0000000..cc5821c --- /dev/null +++ b/Synapse/Events/Classes/KeyPressEvent.cs @@ -0,0 +1,12 @@ +using Synapse.Api; +using UnityEngine; + +namespace Synapse.Events.Classes +{ + public class KeyPressEvent + { + public Player Player { get; internal set; } + + public KeyCode Key { get; internal set; } + } +} diff --git a/Synapse/Events/Classes/PlayerHealEvent.cs b/Synapse/Events/Classes/PlayerHealEvent.cs new file mode 100644 index 0000000..20a0836 --- /dev/null +++ b/Synapse/Events/Classes/PlayerHealEvent.cs @@ -0,0 +1,15 @@ +using System.Diagnostics.CodeAnalysis; +using Synapse.Api; + +namespace Synapse.Events.Classes +{ + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] + public class PlayerHealEvent + { + public Player Player { get; internal set; } + + public float Amount { get; set; } + + public bool Allow { get; set; } + } +} \ No newline at end of file diff --git a/Synapse/Events/Classes/Scp106CreatePortalEvent.cs b/Synapse/Events/Classes/Scp106CreatePortalEvent.cs new file mode 100644 index 0000000..af46ff4 --- /dev/null +++ b/Synapse/Events/Classes/Scp106CreatePortalEvent.cs @@ -0,0 +1,10 @@ +using Synapse.Api; + +namespace Synapse.Events.Classes +{ + public class Scp106CreatePortalEvent + { + public Player Player { get; internal set; } + public bool Allow { get; set; } + } +} \ No newline at end of file diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index db36cc5..28cd926 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -1,6 +1,4 @@ using System.Linq; -using Synapse.Api; -using Synapse.Api.Enums; using Synapse.Events.Classes; using Synapse.Config; using UnityEngine; @@ -14,7 +12,6 @@ internal class EventHandlers public EventHandlers() { Events.SyncDataEvent += OnSyncData; - Events.RemoteCommandEvent += OnRemoteCommand; Events.DoorInteractEvent += OnDoorInteract; Events.PlayerJoinEvent += OnPlayerJoin; } @@ -47,38 +44,5 @@ private static void OnSyncData(SyncDataEvent ev) !(Vector3.Distance(ev.Player.Position, ev.Player.GetComponent().worldPosition) >= Escape.radius)) ev.Player.Hub.characterClassManager.CmdRegisterEscape(); } - - private static void OnRemoteCommand(RemoteCommandEvent ev) - { - var args = ev.Command.Split(' '); - switch (args[0].ToUpper()) - { - case "RELOADPERMISSION": - ev.Allow = false; - if (!ev.Player.CheckPermission("sy.reload.permission")) - { - ev.Sender.RaMessage("You have no Permission for Reload Permissions", false, - RaCategory.AdminTools); - return; - } - - PermissionReader.ReloadPermission(); - ev.Sender.RaMessage("Permissions Reloaded!", true, RaCategory.ServerConfigs); - return; - - case "RELOADCONFIGS": - ev.Allow = false; - if (!ev.Player.CheckPermission("sy.reload.configs")) - { - ev.Sender.RaMessage("You have no Permission for Reload Configs", false, - RaCategory.AdminTools); - return; - } - - ConfigManager.ReloadAllConfigs(); - ev.Sender.RaMessage("Configs Reloaded!", true, RaCategory.ServerConfigs); - return; - } - } } } \ No newline at end of file diff --git a/Synapse/Events/Patches/EventPatches/MapPatches/GeneratorPatches.cs b/Synapse/Events/Patches/EventPatches/MapPatches/GeneratorPatches.cs index 4c3144a..8f2e7bd 100644 --- a/Synapse/Events/Patches/EventPatches/MapPatches/GeneratorPatches.cs +++ b/Synapse/Events/Patches/EventPatches/MapPatches/GeneratorPatches.cs @@ -15,18 +15,10 @@ public static bool Prefix(Generator079 __instance, GameObject person, PlayerInte { switch (command) { - case PlayerInteract.Generator079Operations.Door: - - - - break; - case PlayerInteract.Generator079Operations.Tablet: if (__instance.isTabletConnected || !__instance.isDoorOpen || __instance._localTime <= 0f || Generator079.mainGenerator.forcedOvercharge) - { return false; - } Inventory component = person.GetComponent(); using (SyncList.SyncListEnumerator enumerator = component.items.GetEnumerator()) { @@ -45,17 +37,16 @@ public static bool Prefix(Generator079 __instance, GameObject person, PlayerInte } } } - break; + return false; case PlayerInteract.Generator079Operations.Cancel: - if (!__instance.isTabletConnected) break; + if (!__instance.isTabletConnected) return false; var allow = true; Events.InvokeGeneratorEjected(person.GetPlayer(), __instance, ref allow); - if (!allow) break; - return true; + return allow; } - return false; + return true; } catch (Exception e) { diff --git a/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerHealPatch.cs b/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerHealPatch.cs new file mode 100644 index 0000000..834619d --- /dev/null +++ b/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerHealPatch.cs @@ -0,0 +1,28 @@ +using System; + using Harmony; +using Synapse; + using Synapse.Api; + + namespace Synapse.Events.Patches +{ + [HarmonyPatch(typeof(PlayerStats), nameof(PlayerStats.HealHPAmount))] + public class PlayerHealPatch + { + public static bool Prefix(PlayerStats __instance, ref float hp) + { + try + { + var player = __instance.GetPlayer(); + + Events.InvokePlayerHealEvent(player, ref hp, out var allow); + + return allow; + } + catch (Exception e) + { + Log.Info($"Player Heal Event Error: {e}"); + return true; + } + } + } +} \ No newline at end of file diff --git a/Synapse/Events/Patches/EventPatches/ScpPatches/Scp106CreatePortalPatch.cs b/Synapse/Events/Patches/EventPatches/ScpPatches/Scp106CreatePortalPatch.cs new file mode 100644 index 0000000..12bc5f6 --- /dev/null +++ b/Synapse/Events/Patches/EventPatches/ScpPatches/Scp106CreatePortalPatch.cs @@ -0,0 +1,16 @@ +using Harmony; +using Synapse.Api; + +namespace Synapse.Events.Patches +{ + [HarmonyPatch(typeof(Scp106PlayerScript), nameof(Scp106PlayerScript.CallCmdMakePortal))] + public class Scp106CreatePortalPatch + { + private static bool Prefix(Scp106PlayerScript __instance) + { + var allow = true; + Events.InvokeScp106CreatePortalEvent(__instance.gameObject.GetPlayer(), ref allow); + return allow; + } + } +} \ No newline at end of file diff --git a/Synapse/Events/Patches/EventPatches/ServerPatches/ConsoleCommandPatch.cs b/Synapse/Events/Patches/EventPatches/ServerPatches/ConsoleCommandPatch.cs index 8f69e6a..40cc6bf 100644 --- a/Synapse/Events/Patches/EventPatches/ServerPatches/ConsoleCommandPatch.cs +++ b/Synapse/Events/Patches/EventPatches/ServerPatches/ConsoleCommandPatch.cs @@ -9,20 +9,13 @@ namespace Synapse.Events.Patches public class ConsoleCommandPatch { // ReSharper disable once InconsistentNaming - public static bool Prefix(QueryProcessor __instance, ref string query, bool encrypted) + public static bool Prefix(QueryProcessor __instance, string query) { try { - Events.InvokeConsoleCommandEvent(__instance.GetPlayer(), query, out var color, - out var returning); + Events.InvokeConsoleCommandEvent(__instance.GetPlayer(), query, out var allow); - if (string.IsNullOrEmpty(color)) - color = "red"; - - if (!string.IsNullOrEmpty(returning)) - __instance.GCT.SendToClient(__instance.connectionToClient, returning, color); - - return false; + return allow; } catch (Exception e) { diff --git a/Synapse/Events/Patches/SynapsePatches/CommandsPatch.cs b/Synapse/Events/Patches/SynapsePatches/CommandsPatch.cs index 71cc69a..806edfa 100644 --- a/Synapse/Events/Patches/SynapsePatches/CommandsPatch.cs +++ b/Synapse/Events/Patches/SynapsePatches/CommandsPatch.cs @@ -1,43 +1,53 @@ using CommandSystem; using CommandSystem.Commands; using Harmony; +using Synapse.Commands; +using System.Linq; namespace Synapse.Events.Patches.SynapsePatches { [HarmonyPatch(typeof(GameConsoleCommandHandler), nameof(GameConsoleCommandHandler.LoadGeneratedCommands))] internal static class GameCommandsPatch { - public static bool Prefix(GameConsoleCommandHandler __instance) + public static void Postfix(GameConsoleCommandHandler __instance) { - __instance.RegisterCommand(new ArgsCommand()); - __instance.RegisterCommand(new BuildInfoCommand()); - __instance.RegisterCommand(ConfigCommand.Create()); - __instance.RegisterCommand(new HelpCommand(__instance)); - return false; + //Synapse Commands + __instance.RegisterCommand(new PluginsCommand()); + __instance.RegisterCommand(new PluginInfoCommand()); } } [HarmonyPatch(typeof(ClientCommandHandler), nameof(ClientCommandHandler.LoadGeneratedCommands))] internal static class ClientCommandPatch { - public static bool Prefix(GameConsoleCommandHandler __instance) + public static void Postfix(GameConsoleCommandHandler __instance) { - __instance.RegisterCommand(new HelpCommand(__instance)); - return false; + //Synapse Commands + __instance.RegisterCommand(new PluginsCommand()); + __instance.RegisterCommand(new PluginInfoCommand()); + __instance.RegisterCommand(new KeyPressCommand()); } } [HarmonyPatch(typeof(RemoteAdminCommandHandler), nameof(RemoteAdminCommandHandler.LoadGeneratedCommands))] internal static class RemoteCommandsPatch { - public static bool Prefix(GameConsoleCommandHandler __instance) + public static void Postfix(GameConsoleCommandHandler __instance) { - __instance.RegisterCommand(new BuildInfoCommand()); - __instance.RegisterCommand(new ChangeNameCommand()); - __instance.RegisterCommand(ConfigCommand.Create()); - __instance.RegisterCommand(new HelpCommand(__instance)); - __instance.RegisterCommand(new IntercomTextCommand()); - return false; + //Synapse Commands + __instance.RegisterCommand(new ReloadConfigsCommand()); + __instance.RegisterCommand(new ReloadPermissionsCommand()); + __instance.RegisterCommand(new PluginsCommand()); + __instance.RegisterCommand(new PluginInfoCommand()); + } + } + + [HarmonyPatch(typeof(RefreshCommandsCommand), nameof(RefreshCommandsCommand.Execute))] + internal static class RefreshCommandsPatch + { + public static void Postfix() + { + Synapse.OnReloadCommands(); } } } diff --git a/Synapse/Events/PlayerEvents.cs b/Synapse/Events/PlayerEvents.cs index 1192f9a..ebb8ad6 100644 --- a/Synapse/Events/PlayerEvents.cs +++ b/Synapse/Events/PlayerEvents.cs @@ -428,5 +428,43 @@ internal static void InvokePlayerTagEvent(Player player, bool show,out bool allo allow = ev.Allow; } + + + public delegate void OnKeyPress(KeyPressEvent ev); + public static event OnKeyPress KeyPressEvent; + internal static void InvokeKeyPressEvent(Player player, KeyCode key) + { + if (KeyPressEvent == null) return; + + var ev = new KeyPressEvent() + { + Player = player, + Key = key + }; + + KeyPressEvent.Invoke(ev); + } + + public delegate void OnPlayerHeal(PlayerHealEvent ev); + + public static event OnPlayerHeal PlayerHealEvent; + internal static void InvokePlayerHealEvent(Player player, ref float amount, out bool allow) + { + allow = true; + if (PlayerHealEvent == null) return; + + var ev = new PlayerHealEvent + { + Player = player, + Amount = amount, + Allow = allow + }; + + PlayerHealEvent.Invoke(ev); + + allow = ev.Allow; + amount = ev.Amount; + + } } } \ No newline at end of file diff --git a/Synapse/Events/ScpEvents.cs b/Synapse/Events/ScpEvents.cs index 504324b..0ad4a4a 100644 --- a/Synapse/Events/ScpEvents.cs +++ b/Synapse/Events/ScpEvents.cs @@ -88,5 +88,22 @@ internal static void InvokeScp079LvlEvent(Player player,ref int newlvl,ref bool newlvl = ev.NewLvl; allow = ev.Allow; } + + public delegate void OnScp106CreatePortal(Scp106CreatePortalEvent ev); + + public static event OnScp106CreatePortal Scp106CreatePortalEvent; + + internal static void InvokeScp106CreatePortalEvent(Player player, ref bool allow) + { + var ev = new Scp106CreatePortalEvent + { + Allow = allow, + Player = player + }; + + Scp106CreatePortalEvent?.Invoke(ev); + + allow = ev.Allow; + } } } \ No newline at end of file diff --git a/Synapse/Events/ServerEvents.cs b/Synapse/Events/ServerEvents.cs index eff5ea9..9143365 100644 --- a/Synapse/Events/ServerEvents.cs +++ b/Synapse/Events/ServerEvents.cs @@ -61,11 +61,9 @@ internal static void InvokeRemoteCommandEvent(CommandSender sender, string comma public delegate void OnConsoleCommand(ConsoleCommandEvent ev); public static event OnConsoleCommand ConsoleCommandEvent; - internal static void InvokeConsoleCommandEvent(Player player, string command, out string color, - out string returning) + internal static void InvokeConsoleCommandEvent(Player player, string command, out bool allow) { - color = "red"; - returning = ""; + allow = true; if (ConsoleCommandEvent == null) return; var ev = new ConsoleCommandEvent @@ -75,9 +73,6 @@ internal static void InvokeConsoleCommandEvent(Player player, string command, ou }; ConsoleCommandEvent.Invoke(ev); - - color = ev.Color; - returning = ev.ReturnMessage; } public delegate void TeamRespawn(TeamRespawnEvent ev); diff --git a/Synapse/Properties/AssemblyInfo.cs b/Synapse/Properties/AssemblyInfo.cs index f1c783e..2528c0b 100644 --- a/Synapse/Properties/AssemblyInfo.cs +++ b/Synapse/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.2")] -[assembly: AssemblyFileVersion("1.1.2")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.0")] +[assembly: AssemblyFileVersion("1.2.0")] \ No newline at end of file diff --git a/Synapse/Synapse.cs b/Synapse/Synapse.cs index ec8b8d8..004e70e 100644 --- a/Synapse/Synapse.cs +++ b/Synapse/Synapse.cs @@ -17,8 +17,8 @@ public static class Synapse { #region Version private const int MajorVersion = 1; - private const int MinorVerion = 1; - private const int Patch = 2; + private const int MinorVerion = 2; + private const int Patch = 0; public static int VersionNumber => MajorVersion * 100 + MinorVerion * 10 + Patch; public static string Version => $"{MajorVersion}.{MinorVerion}.{Patch}"; @@ -50,28 +50,18 @@ public static void LoaderExecutionCode() Log.Error("Synapse failed to Start.Restart the Server"); } } - internal static void Start() + private static void Start() { LoadDependencies(); - //Clears all the Commands so that the base game refresh command will be removed - Server.ClientCommandHandler.ClearCommands(); - Server.GameCoreCommandHandler.ClearCommands(); - Server.RaCommandHandler.ClearCommands(); - - HarmonyPatch(); - //Adding all Vanilla Commands back to the Handler but now with the Harmony Patch which removes the command - Server.ClientCommandHandler.LoadGeneratedCommands(); - Server.GameCoreCommandHandler.LoadGeneratedCommands(); - Server.RaCommandHandler.LoadGeneratedCommands(); - foreach (var plugin in Directory.GetFiles(Files.ServerPluginDirectory)) { if (plugin == "Synapse.dll") continue; if (plugin.EndsWith(".dll")) LoadPlugin(plugin); } - + + HarmonyPatch(); ConfigManager.InitializeConfigs(); ServerConsole.ReloadServerName(); _eventHandler = new EventHandlers(); @@ -85,6 +75,7 @@ internal static void Start() } OnEnable(); + OnReloadCommands(); } @@ -138,7 +129,6 @@ private static void LoadPlugin(string pluginPath) }; p.Assembly = assembly; - p.RegisterCommands(); plugins.Add(p); if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor == MajorVersion * 10 + MinorVerion) Log.Info($"Successfully loaded {p.Details.Name}"); @@ -179,6 +169,26 @@ private static void OnEnable() Log.Error($"Plugin {plugin.Details.Name} threw an exception while enabling {e}"); } } + internal static void OnReloadCommands() + { + Server.ClientCommandHandler.ClearCommands(); + Server.GameCoreCommandHandler.ClearCommands(); + Server.RaCommandHandler.ClearCommands(); + + Server.ClientCommandHandler.LoadGeneratedCommands(); + Server.GameCoreCommandHandler.LoadGeneratedCommands(); + Server.RaCommandHandler.LoadGeneratedCommands(); + + foreach (var plugin in plugins) + try + { + plugin.RegisterCommands(); + } + catch (Exception e) + { + Log.Error($"Plugin {plugin.Details.Name} threw an exception while enabling {e}"); + } + } #endregion } diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index eab4490..acd17e1 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -83,8 +83,16 @@ + + + + + + + + @@ -124,6 +132,7 @@ + @@ -136,6 +145,7 @@ +