From bbc774f1d591040bb839e3a680a1a8d81c39ca13 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 5 Jul 2020 17:10:49 +0200 Subject: [PATCH 01/46] Fixed bug that A User wit ha Server Group which has no Permission group cant get the User/Northwood Group --- Synapse/Permissions/PermissionReader.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Synapse/Permissions/PermissionReader.cs b/Synapse/Permissions/PermissionReader.cs index 7238bc9..f00527c 100644 --- a/Synapse/Permissions/PermissionReader.cs +++ b/Synapse/Permissions/PermissionReader.cs @@ -98,8 +98,9 @@ internal static bool CheckPermission(Player player, string permission) if (!_permissionsConfig.Groups.TryGetValue(groupName, out group)) { - Log.Error("Could not get permission value."); - return false; + Log.Info($"TheServerGroup: {groupName} has no Permission Group!"); + if (player.Hub.serverRoles.Staff || player.UserId.EndsWith("@northwood")) group = GetNwGroup(); + else group = GetDefaultGroup(); } } else From 7115da02a722cad4bc045d2596d51b8b44a7e500 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 6 Jul 2020 10:07:57 +0200 Subject: [PATCH 02/46] fixed Pickup bug --- Synapse/Events/Patches/PickUpItemPatch.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Synapse/Events/Patches/PickUpItemPatch.cs b/Synapse/Events/Patches/PickUpItemPatch.cs index 337acd4..2a59d08 100644 --- a/Synapse/Events/Patches/PickUpItemPatch.cs +++ b/Synapse/Events/Patches/PickUpItemPatch.cs @@ -28,8 +28,10 @@ public static bool Prefix(SearchCoordinator __instance) } } } - - __instance.SessionPipe.Invalidate(); + else + { + __instance.SessionPipe.Invalidate(); + } return false; } From ea82765d1e89740bea826a07b859b037b782d3d1 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 6 Jul 2020 10:46:52 +0200 Subject: [PATCH 03/46] fixed RemoteKeycard --- Synapse/Events/EventHandlers.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index 84a48e7..ced672b 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -43,11 +43,14 @@ private static void OnDoorInteract(ref DoorInteractEvent ev) if (ev.Allow) return; if (!ev.Player.Items.Any()) return; - var itemPerms = ev.Player.Inventory.GetItemByID(ev.Player.Inventory.curItem).permissions; - var door = ev.Door; - ev.Allow = itemPerms.Any(p => - door.backwardsCompatPermissions.TryGetValue(p, out var flag) && - door.PermissionLevels.HasPermission(flag)); + foreach (var item in ev.Player.Items) + { + var itemPerms = ev.Player.Inventory.GetItemByID(item.id).permissions; + var door = ev.Door; + ev.Allow = itemPerms.Any(p => + door.backwardsCompatPermissions.TryGetValue(p, out var flag) && + door.PermissionLevels.HasPermission(flag)); + } } private static void OnSyncData(ref SyncDataEvent ev) From b810c12e2a18bc8afb67440897e7a3629fbd3c8e Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 6 Jul 2020 14:42:56 +0200 Subject: [PATCH 04/46] fixed bug that \n Writes a new Line in the translation.txt --- Synapse/Translation.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Synapse/Translation.cs b/Synapse/Translation.cs index d468393..752d287 100644 --- a/Synapse/Translation.cs +++ b/Synapse/Translation.cs @@ -22,8 +22,10 @@ public void CreateTranslations(Dictionary translations) var newlines = new List(); var position = 0; - foreach (var pair in translations.ToList()) + foreach (var rawpair in translations.ToList()) { + var pair = new KeyValuePair(rawpair.Key,rawpair.Value.Replace("\n", "\\n")); + if (lines.Length > position) { if (string.IsNullOrEmpty(lines[position])) @@ -55,7 +57,7 @@ public string GetTranslation(string translationName) try { var trans = _translation.FirstOrDefault(x => x.Key == translationName).Value; - return trans; + return trans.Replace("\\n","\n"); } catch { From 5dca289ae178932b6dcf8ae663e862855fd31d05 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 6 Jul 2020 15:28:47 +0200 Subject: [PATCH 05/46] Removed PluginManager.ReadFile --- Synapse/PluginManager.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/Synapse/PluginManager.cs b/Synapse/PluginManager.cs index d8d90b6..589318b 100644 --- a/Synapse/PluginManager.cs +++ b/Synapse/PluginManager.cs @@ -6,6 +6,7 @@ using MEC; using Synapse.Events.Patches; using Synapse.Permissions; +using SynapseModLoader; namespace Synapse { @@ -124,7 +125,7 @@ private static void LoadPlugin(string pluginPath) Log.Info($"Loading {pluginPath}"); try { - var file = ReadFile(pluginPath); + var file = ModLoader.ReadFile(pluginPath); var assembly = Assembly.Load(file); foreach (var type in assembly.GetTypes()) @@ -192,19 +193,5 @@ private static void HarmonyPatch() Log.Error($"PatchError: {e}"); } } - - private static byte[] ReadFile(string path) - { - var fileStream = File.Open(path, FileMode.Open); - byte[] result; - using (var memoryStream = new MemoryStream()) - { - fileStream.CopyTo(memoryStream); - result = memoryStream.ToArray(); - } - - fileStream.Close(); - return result; - } } } \ No newline at end of file From 479ba6674cf9a03394abeb89d36aa8c3e31a6814 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 7 Jul 2020 08:32:38 +0200 Subject: [PATCH 06/46] added Player.hurt() --- Synapse/Api/Player.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 19f0e9d..ac2adc4 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -505,5 +505,14 @@ public void RaLogout() Hub.serverRoles.RemoteAdminMode = ServerRoles.AccessMode.LocalAccess; Hub.serverRoles.TargetCloseRemoteAdmin(Connection); } + + /// + /// Gives the Player Damage + /// + /// + /// + /// + public void Hurt(int amount, DamageTypes.DamageType damagetype = default,Player attacker = null) => + PlayerStats.HurtPlayer(new PlayerStats.HitInfo(amount, attacker == null ? "WORLD" : attacker.NickName, damagetype, attacker == null ? PlayerId : attacker.PlayerId), attacker == null ? gameObject : attacker.gameObject); } } From 0a9b42a3c900192ad4bab78717710fcc1f67ebed Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 7 Jul 2020 10:51:48 +0200 Subject: [PATCH 07/46] fixed UseItemClass --- Synapse/Api/Player.cs | 2 +- Synapse/Events/Classes/UseItemEvent.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index ac2adc4..f560079 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -507,7 +507,7 @@ public void RaLogout() } /// - /// Gives the Player Damage + /// Hurts the Player /// /// /// diff --git a/Synapse/Events/Classes/UseItemEvent.cs b/Synapse/Events/Classes/UseItemEvent.cs index 44f9f28..8c0ee14 100644 --- a/Synapse/Events/Classes/UseItemEvent.cs +++ b/Synapse/Events/Classes/UseItemEvent.cs @@ -6,6 +6,6 @@ public class UseItemEvent { public Player Player { get; internal set; } - public bool Allow { get; internal set; } + public bool Allow { get; set; } } } From 21d4a5f52f31173af4a3cd2ded13793f1c23a4bc Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 7 Jul 2020 14:22:35 +0200 Subject: [PATCH 08/46] added Speaking Scp Config --- Synapse/Configs.cs | 6 +++++- Synapse/Events/Patches/SpeakPatch.cs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Synapse/Configs.cs b/Synapse/Configs.cs index e67e117..4a2588e 100644 --- a/Synapse/Configs.cs +++ b/Synapse/Configs.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; namespace Synapse { @@ -10,6 +11,7 @@ internal static class Configs internal static string JoinBroadcast; internal static string JoinTextHint; internal static ushort JoinMessageDuration; + internal static List Speaking_Scps; // Methods internal static void ReloadConfig() @@ -19,6 +21,8 @@ internal static void ReloadConfig() JoinBroadcast = Plugin.Config.GetString("synapse_join_broadcast", ""); JoinTextHint = Plugin.Config.GetString("synapse_join_texthint", ""); JoinMessageDuration = Plugin.Config.GetUShort("synapse_join_duration",5); + Speaking_Scps = Plugin.Config.GetIntList("synapse_speakingscps"); + if (Speaking_Scps == null) Speaking_Scps = new List { 16, 17 }; } } } diff --git a/Synapse/Events/Patches/SpeakPatch.cs b/Synapse/Events/Patches/SpeakPatch.cs index 6ceba47..d1899b2 100644 --- a/Synapse/Events/Patches/SpeakPatch.cs +++ b/Synapse/Events/Patches/SpeakPatch.cs @@ -1,6 +1,7 @@ using System; using Assets._Scripts.Dissonance; using Harmony; +using Synapse.Api; namespace Synapse.Events.Patches { @@ -18,6 +19,8 @@ public static bool Prefix(DissonanceUserSetup __instance, bool value) var scpchat = __instance.SCPChat; var spectator = __instance.SpectatorChat; + scp939 = Configs.Speaking_Scps.Contains((int)__instance.GetPlayer().Role); + Events.InvokeSpeakEvent(__instance, ref intercom, ref radio, ref scp939, ref scpchat, ref spectator); __instance.SCPChat = scpchat; From c660c49f0059b9ca0fbc5c9a319e8406ae825dca Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 7 Jul 2020 14:31:37 +0200 Subject: [PATCH 09/46] added ev.Item to UseItemEvent --- Synapse/Configs.cs | 1 - Synapse/Events/Classes/UseItemEvent.cs | 2 ++ Synapse/Events/Patches/UseItemPatch.cs | 2 +- Synapse/Events/PlayerEvents.cs | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Synapse/Configs.cs b/Synapse/Configs.cs index 4a2588e..488c2eb 100644 --- a/Synapse/Configs.cs +++ b/Synapse/Configs.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.IO; namespace Synapse { diff --git a/Synapse/Events/Classes/UseItemEvent.cs b/Synapse/Events/Classes/UseItemEvent.cs index 8c0ee14..a2ad937 100644 --- a/Synapse/Events/Classes/UseItemEvent.cs +++ b/Synapse/Events/Classes/UseItemEvent.cs @@ -6,6 +6,8 @@ public class UseItemEvent { public Player Player { get; internal set; } + public ItemType Item { get; internal set; } + public bool Allow { get; set; } } } diff --git a/Synapse/Events/Patches/UseItemPatch.cs b/Synapse/Events/Patches/UseItemPatch.cs index 824b3bb..a961590 100644 --- a/Synapse/Events/Patches/UseItemPatch.cs +++ b/Synapse/Events/Patches/UseItemPatch.cs @@ -11,7 +11,7 @@ public static bool Prefix(ConsumableAndWearableItems __instance) { try { - Events.InvokeUseItemEvent(__instance.GetPlayer(),out bool allow); + Events.InvokeUseItemEvent(__instance.GetPlayer(), __instance._hub.inventory.curItem,out bool allow); return allow; } catch (Exception e) diff --git a/Synapse/Events/PlayerEvents.cs b/Synapse/Events/PlayerEvents.cs index 44e0c52..9c53d3f 100644 --- a/Synapse/Events/PlayerEvents.cs +++ b/Synapse/Events/PlayerEvents.cs @@ -359,7 +359,7 @@ internal static void InvokeGeneratorClose(Player player, Generator079 generator, public delegate void OnUseItem(ref UseItemEvent ev); public static event OnUseItem UseItemEvent; - internal static void InvokeUseItemEvent(Player player, out bool allow) + internal static void InvokeUseItemEvent(Player player,ItemType item, out bool allow) { allow = true; if (UseItemEvent == null) return; @@ -367,6 +367,7 @@ internal static void InvokeUseItemEvent(Player player, out bool allow) var ev = new UseItemEvent { Player = player, + Item = item, Allow = true }; From b2c21703a7de0a1696677a42fce11416593fcc23 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 7 Jul 2020 15:23:06 +0200 Subject: [PATCH 10/46] fixed ServerName --- Synapse/Events/Patches/ServerNamePatch.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Synapse/Events/Patches/ServerNamePatch.cs b/Synapse/Events/Patches/ServerNamePatch.cs index 8308a8b..80097b2 100644 --- a/Synapse/Events/Patches/ServerNamePatch.cs +++ b/Synapse/Events/Patches/ServerNamePatch.cs @@ -8,7 +8,7 @@ public static class ServerNamePatch public static void Postfix() { ServerConsole._serverName = ServerConsole._serverName.Replace("SM119.0.0", ""); - ServerConsole._serverName += " SMSynapse-ModLoader v.1.0-beta"; + ServerConsole._serverName += " SMSynapse-ModLoader v.1.1-beta"; } } } \ No newline at end of file From a97ed7a3fa53a4aaa50fd7b38b671650fc2dea60 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Wed, 8 Jul 2020 12:42:35 +0200 Subject: [PATCH 11/46] added synapse_nametracking config --- Synapse/Configs.cs | 2 ++ Synapse/Events/Patches/ServerNamePatch.cs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Synapse/Configs.cs b/Synapse/Configs.cs index 488c2eb..dc41469 100644 --- a/Synapse/Configs.cs +++ b/Synapse/Configs.cs @@ -11,6 +11,7 @@ internal static class Configs internal static string JoinTextHint; internal static ushort JoinMessageDuration; internal static List Speaking_Scps; + internal static bool Nametracking; // Methods internal static void ReloadConfig() @@ -22,6 +23,7 @@ internal static void ReloadConfig() JoinMessageDuration = Plugin.Config.GetUShort("synapse_join_duration",5); Speaking_Scps = Plugin.Config.GetIntList("synapse_speakingscps"); if (Speaking_Scps == null) Speaking_Scps = new List { 16, 17 }; + Nametracking = Plugin.Config.GetBool("synapse_nametracking",true); } } } diff --git a/Synapse/Events/Patches/ServerNamePatch.cs b/Synapse/Events/Patches/ServerNamePatch.cs index 80097b2..68ce230 100644 --- a/Synapse/Events/Patches/ServerNamePatch.cs +++ b/Synapse/Events/Patches/ServerNamePatch.cs @@ -7,7 +7,8 @@ public static class ServerNamePatch { public static void Postfix() { - ServerConsole._serverName = ServerConsole._serverName.Replace("SM119.0.0", ""); + if (!Configs.Nametracking) return; + ServerConsole._serverName += " SMSynapse-ModLoader v.1.1-beta"; } } From 121b3a5d8094b231e341c4c8ea0140790b632c67 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Wed, 8 Jul 2020 13:54:50 +0200 Subject: [PATCH 12/46] added startup config file for changing Synapse Installtion Directory --- Synapse/PluginManager.cs | 11 ++++++-- SynapseModLoader/ModLoader.cs | 48 ++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Synapse/PluginManager.cs b/Synapse/PluginManager.cs index 589318b..f3c2f80 100644 --- a/Synapse/PluginManager.cs +++ b/Synapse/PluginManager.cs @@ -16,8 +16,15 @@ public static class PluginManager private static readonly List LoadedDependencies = new List(); private static readonly List Plugins = new List(); - private static string SynapseDirectory { get; } = - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Synapse"); + private static string StartupFile { get; } = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ReferenceHub)).CodeBase).Replace("file:\\", "").Replace("\\SCPSL_Data\\Managed", "\\SynapseStart-config.yml"); + private static string SynapseDirectory + { + get + { + var Config = new YamlConfig(StartupFile); + return Config.GetString("synapse_installation", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Synapse")); + } + } internal static string MainPluginDirectory { get; } = Path.Combine(SynapseDirectory, "Plugins"); internal static string DependenciesDirectory { get; } = Path.Combine(SynapseDirectory, "dependencies"); diff --git a/SynapseModLoader/ModLoader.cs b/SynapseModLoader/ModLoader.cs index 1c1427b..86e99c7 100644 --- a/SynapseModLoader/ModLoader.cs +++ b/SynapseModLoader/ModLoader.cs @@ -1,4 +1,5 @@ -using System; +using GameCore; +using System; using System.IO; using System.Linq; using System.Reflection; @@ -34,24 +35,41 @@ public static void LoadModSystem() return; } ServerConsole.AddLog("Synapse Mod-Loader is now initialising.. :)", ConsoleColor.Blue); - var text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Synapse"); - if (!Directory.Exists(text)) - { - Directory.CreateDirectory(text); - } - if (!File.Exists(Path.Combine(text, "Synapse.dll"))) + + try { - ServerConsole.AddLog("Error while loading Synapse! The Synapse.dll is missing!", ConsoleColor.Red); - return; + var startupfile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "").Replace("\\SCPSL_Data\\Managed", "\\SynapseStart-config.yml"); + if (!File.Exists(startupfile)) + { + ServerConsole.AddLog($"Synapse Mod-Loader Start file is missing ... creating: {startupfile}", ConsoleColor.Blue); + File.Create(startupfile).Close(); + File.WriteAllLines(startupfile, new string[] { "synapse_installation: default" }); + } + var Config = new YamlConfig(startupfile); + + var text = Config.GetString("synapse_installation", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Synapse")); + if (!Directory.Exists(text)) + { + Directory.CreateDirectory(text); + } + if (!File.Exists(Path.Combine(text, "Synapse.dll"))) + { + ServerConsole.AddLog("Error while loading Synapse! The Synapse.dll is missing!", ConsoleColor.Red); + return; + } + var methodInfo = Assembly.Load(ReadFile(Path.Combine(text, "Synapse.dll"))).GetTypes() + .SelectMany(p => p.GetMethods()).FirstOrDefault(f => f.Name == "LoaderExecutionCode"); + if (!(methodInfo != null)) + { + return; + } + methodInfo.Invoke(null, null); + _loaded = true; } - var methodInfo = Assembly.Load(ReadFile(Path.Combine(text, "Synapse.dll"))).GetTypes() - .SelectMany(p => p.GetMethods()).FirstOrDefault(f => f.Name == "LoaderExecutionCode"); - if (!(methodInfo != null)) + catch (Exception e) { - return; + ServerConsole.AddLog($"Synapse Mod-Loader startup Error: {e}", ConsoleColor.Red); } - methodInfo.Invoke(null, null); - _loaded = true; } private static bool _loaded; From ccee6aff266260ad111880ac506750a95e0fefa8 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Wed, 8 Jul 2020 14:47:14 +0200 Subject: [PATCH 13/46] fixed startup config bug for Linux --- Synapse/Events/Patches/ServerNamePatch.cs | 2 +- Synapse/PluginManager.cs | 2 +- SynapseModLoader/ModLoader.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Synapse/Events/Patches/ServerNamePatch.cs b/Synapse/Events/Patches/ServerNamePatch.cs index 68ce230..25d650b 100644 --- a/Synapse/Events/Patches/ServerNamePatch.cs +++ b/Synapse/Events/Patches/ServerNamePatch.cs @@ -9,7 +9,7 @@ public static void Postfix() { if (!Configs.Nametracking) return; - ServerConsole._serverName += " SMSynapse-ModLoader v.1.1-beta"; + ServerConsole._serverName += " SMSynapse-ModLoader v.1.2-beta"; } } } \ No newline at end of file diff --git a/Synapse/PluginManager.cs b/Synapse/PluginManager.cs index f3c2f80..88b998e 100644 --- a/Synapse/PluginManager.cs +++ b/Synapse/PluginManager.cs @@ -16,7 +16,7 @@ public static class PluginManager private static readonly List LoadedDependencies = new List(); private static readonly List Plugins = new List(); - private static string StartupFile { get; } = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ReferenceHub)).CodeBase).Replace("file:\\", "").Replace("\\SCPSL_Data\\Managed", "\\SynapseStart-config.yml"); + private static string StartupFile { get; } = Assembly.GetAssembly(typeof(ReferenceHub)).Location.Replace($"SCPSL_Data{Path.DirectorySeparatorChar}Managed{Path.DirectorySeparatorChar}Assembly-CSharp.dll", "SynapseStart-config.yml"); private static string SynapseDirectory { get diff --git a/SynapseModLoader/ModLoader.cs b/SynapseModLoader/ModLoader.cs index 86e99c7..aeb1e6c 100644 --- a/SynapseModLoader/ModLoader.cs +++ b/SynapseModLoader/ModLoader.cs @@ -38,7 +38,7 @@ public static void LoadModSystem() try { - var startupfile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "").Replace("\\SCPSL_Data\\Managed", "\\SynapseStart-config.yml"); + var startupfile = Assembly.GetExecutingAssembly().Location.Replace($"SCPSL_Data{Path.DirectorySeparatorChar}Managed{Path.DirectorySeparatorChar}Assembly-CSharp.dll", "SynapseStart-config.yml"); if (!File.Exists(startupfile)) { ServerConsole.AddLog($"Synapse Mod-Loader Start file is missing ... creating: {startupfile}", ConsoleColor.Blue); From 94184cd61adc53bd50b2d0fa7b82ae7d67d2b264 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Wed, 8 Jul 2020 15:46:07 +0200 Subject: [PATCH 14/46] added const string version to MainLoader --- Synapse/Events/Patches/ServerNamePatch.cs | 2 +- Synapse/MainLoader.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Synapse/Events/Patches/ServerNamePatch.cs b/Synapse/Events/Patches/ServerNamePatch.cs index 25d650b..5fd3d6a 100644 --- a/Synapse/Events/Patches/ServerNamePatch.cs +++ b/Synapse/Events/Patches/ServerNamePatch.cs @@ -9,7 +9,7 @@ public static void Postfix() { if (!Configs.Nametracking) return; - ServerConsole._serverName += " SMSynapse-ModLoader v.1.2-beta"; + ServerConsole._serverName += $" SMSynapse-ModLoader {MainLoader.version}"; } } } \ No newline at end of file diff --git a/Synapse/MainLoader.cs b/Synapse/MainLoader.cs index 5d99043..ef0ec64 100644 --- a/Synapse/MainLoader.cs +++ b/Synapse/MainLoader.cs @@ -7,11 +7,12 @@ namespace Synapse [SuppressMessage("ReSharper", "UnusedType.Global")] public class MainLoader { + public const string version = "v.1.2-Beta"; /// This method is called by the Scp Server in the assembly-csharp // ReSharper disable once UnusedMember.Global public static void LoaderExecutionCode() { - Log.Info("Now starting Synapse Version v.0.1.0 alpha"); + Log.Info($"Now starting Synapse Version {version}"); Log.Info("Created by Dimenzio and SirRoob"); Log.Info("Checking Files"); From fe1f1647ab377507aa4e8a37d468e8dc2c4fcca0 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Wed, 8 Jul 2020 17:34:45 +0200 Subject: [PATCH 15/46] added PlayerSetGroup Event --- Synapse/Api/Player.cs | 2 +- Synapse/Events/Classes/PlayerSetGroupEvent.cs | 19 ++++++++++++++ Synapse/Events/Patches/PlayerSetGroupPatch.cs | 25 ++++++++++++++++++ Synapse/Events/PlayerEvents.cs | 26 +++++++++++++++++++ Synapse/Synapse.csproj | 2 ++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 Synapse/Events/Classes/PlayerSetGroupEvent.cs create mode 100644 Synapse/Events/Patches/PlayerSetGroupPatch.cs diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index f560079..af394c5 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -289,7 +289,7 @@ public Player Cuffer /// /// The UserGroup the player is in /// - public UserGroup Rank { get => ServerRoles.Group; set => ServerRoles.SetGroup(value, false); } + public UserGroup Rank { get => ServerRoles.Group; set => ServerRoles.SetGroup(value, value.Permissions > 0UL,true); } /// /// The name of the group the user has diff --git a/Synapse/Events/Classes/PlayerSetGroupEvent.cs b/Synapse/Events/Classes/PlayerSetGroupEvent.cs new file mode 100644 index 0000000..648a1a5 --- /dev/null +++ b/Synapse/Events/Classes/PlayerSetGroupEvent.cs @@ -0,0 +1,19 @@ +using Synapse.Api; + +namespace Synapse.Events.Classes +{ + public class PlayerSetGroupEvent + { + public Player Player { get; internal set; } + + public bool ByAdmin { get; internal set; } + + public UserGroup Group { get; set; } + + public bool RaAcces { get; set; } + + public bool Showtag { get; set; } + + public bool Allow { get; set; } + } +} diff --git a/Synapse/Events/Patches/PlayerSetGroupPatch.cs b/Synapse/Events/Patches/PlayerSetGroupPatch.cs new file mode 100644 index 0000000..92fcb4a --- /dev/null +++ b/Synapse/Events/Patches/PlayerSetGroupPatch.cs @@ -0,0 +1,25 @@ +using System; +using Harmony; +using Synapse.Api; + +namespace Synapse.Events.Patches +{ + [HarmonyPatch(typeof(ServerRoles), nameof(ServerRoles.SetGroup))] + public static class PlayerSetGroupPatch + { + public static bool Prefix(ServerRoles __instance, ref UserGroup group, ref bool ovr, bool byAdmin, ref bool disp) + { + try + { + Events.InvokePlayerSetGroupEvent(__instance.GetPlayer(), byAdmin, ref group, ref ovr, ref disp, out bool allow); + + return allow; + } + catch(Exception e) + { + Log.Error($"PlayerSetGroup Event Error: {e}"); + return true; + } + } + } +} diff --git a/Synapse/Events/PlayerEvents.cs b/Synapse/Events/PlayerEvents.cs index 9c53d3f..2cb91c4 100644 --- a/Synapse/Events/PlayerEvents.cs +++ b/Synapse/Events/PlayerEvents.cs @@ -412,5 +412,31 @@ internal static void InvokePlayerSetClassEvent(Player player, ref RoleType type, items = ev.Items; type = ev.Role; } + + + public delegate void OnPlayerSetGroup(ref PlayerSetGroupEvent ev); + public static event OnPlayerSetGroup PlayerSetGroupEvent; + internal static void InvokePlayerSetGroupEvent(Player player, bool byAdmin, ref UserGroup group, ref bool ovr, ref bool disp, out bool allow) + { + allow = true; + if (PlayerSetGroupEvent == null) return; + + var ev = new PlayerSetGroupEvent + { + Player = player, + ByAdmin = byAdmin, + Group = group, + RaAcces = ovr, + Showtag = disp, + Allow = true + }; + + PlayerSetGroupEvent.Invoke(ref ev); + + group = ev.Group; + ovr = ev.RaAcces; + disp = ev.Showtag; + allow = ev.Allow; + } } } \ No newline at end of file diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index eeb12e6..1951c13 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -72,12 +72,14 @@ + + From 841e94ed640c287d2b361063722cf20165b431ee Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Wed, 8 Jul 2020 17:40:20 +0200 Subject: [PATCH 16/46] added a check that you cant deactivate global Permissions --- Synapse/Events/Patches/PlayerSetGroupPatch.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Synapse/Events/Patches/PlayerSetGroupPatch.cs b/Synapse/Events/Patches/PlayerSetGroupPatch.cs index 92fcb4a..f83f95c 100644 --- a/Synapse/Events/Patches/PlayerSetGroupPatch.cs +++ b/Synapse/Events/Patches/PlayerSetGroupPatch.cs @@ -13,6 +13,8 @@ public static bool Prefix(ServerRoles __instance, ref UserGroup group, ref bool { Events.InvokePlayerSetGroupEvent(__instance.GetPlayer(), byAdmin, ref group, ref ovr, ref disp, out bool allow); + if (__instance._globalPerms > 0UL) return true; + return allow; } catch(Exception e) From 64e088fbfe8f365dcfc55dda2899c9e62eb6844f Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Thu, 9 Jul 2020 08:55:42 +0200 Subject: [PATCH 17/46] changed Translation.GetTranslation() --- Synapse/Translation.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Synapse/Translation.cs b/Synapse/Translation.cs index 752d287..47a8602 100644 --- a/Synapse/Translation.cs +++ b/Synapse/Translation.cs @@ -57,11 +57,12 @@ public string GetTranslation(string translationName) try { var trans = _translation.FirstOrDefault(x => x.Key == translationName).Value; - return trans.Replace("\\n","\n"); + if (trans == null) return "Plugin requested a not created Translation!"; + return trans.Replace("\\n", "\n"); } catch { - return "Invalid Translations Name"; + return "Plugin requested a not created Translation!"; } } } From b876e4de14705074506d759f17edbad95fedf9e1 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 11 Jul 2020 10:14:38 +0200 Subject: [PATCH 18/46] removed all ref from the Events and removed unnecessary delegates --- Synapse/Events/EventHandlers.cs | 8 ++-- Synapse/Events/MapEvents.cs | 8 ++-- Synapse/Events/PlayerEvents.cs | 82 ++++++++++++++++----------------- Synapse/Events/ScpEvents.cs | 16 +++---- Synapse/Events/ServerEvents.cs | 20 ++++---- 5 files changed, 65 insertions(+), 69 deletions(-) diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index ced672b..dfdaa03 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -31,13 +31,13 @@ public EventHandlers() } // Methods - private void OnPlayerJoin(ref PlayerJoinEvent ev) + private void OnPlayerJoin(PlayerJoinEvent ev) { ev.Player.Broadcast(Configs.JoinMessageDuration,Configs.JoinBroadcast); ev.Player.GiveTextHint(Configs.JoinTextHint, Configs.JoinMessageDuration); } - private static void OnDoorInteract(ref DoorInteractEvent ev) + private static void OnDoorInteract(DoorInteractEvent ev) { if (!Configs.RemoteKeyCard) return; if (ev.Allow) return; @@ -53,7 +53,7 @@ private static void OnDoorInteract(ref DoorInteractEvent ev) } } - private static void OnSyncData(ref SyncDataEvent ev) + private static void OnSyncData(SyncDataEvent ev) { if (ev.Player.Role != RoleType.ClassD && ev.Player.Role != RoleType.Scientist && @@ -61,7 +61,7 @@ private static void OnSyncData(ref SyncDataEvent ev) ev.Player.Hub.characterClassManager.CmdRegisterEscape(); } - private static void OnRemoteCommand(ref RemoteCommandEvent ev) + private static void OnRemoteCommand(RemoteCommandEvent ev) { var args = ev.Command.Split(' '); switch (args[0].ToUpper()) diff --git a/Synapse/Events/MapEvents.cs b/Synapse/Events/MapEvents.cs index 23ff2b0..6811ff3 100644 --- a/Synapse/Events/MapEvents.cs +++ b/Synapse/Events/MapEvents.cs @@ -8,7 +8,7 @@ namespace Synapse.Events public static partial class Events { // DoorInteractEvent - public delegate void OnDoorInteract(ref DoorInteractEvent ev); + public delegate void OnDoorInteract(DoorInteractEvent ev); public static event OnDoorInteract DoorInteractEvent; @@ -23,12 +23,12 @@ internal static void InvokeDoorInteraction(Player player, Door door, ref bool al Door = door }; - DoorInteractEvent.Invoke(ref ev); + DoorInteractEvent.Invoke(ev); allow = ev.Allow; } //TeslaTriggerEvent - public delegate void OnTriggerTesla(ref TeslaTriggerEvent ev); + public delegate void OnTriggerTesla(TeslaTriggerEvent ev); public static event OnTriggerTesla TeslaTriggerEvent; internal static void InvokeTeslaTrigger(Player player, bool inRange, ref bool activated) @@ -42,7 +42,7 @@ internal static void InvokeTeslaTrigger(Player player, bool inRange, ref bool ac Triggerable = activated }; - TeslaTriggerEvent?.Invoke(ref ev); + TeslaTriggerEvent?.Invoke(ev); activated = ev.Triggerable; } diff --git a/Synapse/Events/PlayerEvents.cs b/Synapse/Events/PlayerEvents.cs index 2cb91c4..9224274 100644 --- a/Synapse/Events/PlayerEvents.cs +++ b/Synapse/Events/PlayerEvents.cs @@ -12,7 +12,7 @@ public static partial class Events { /// A Event which is activated when a User Joins the Server /// It need to hook ref PlayerJoinEvent ev - public delegate void OnPlayerJoin(ref PlayerJoinEvent ev); + public delegate void OnPlayerJoin(PlayerJoinEvent ev); public static event OnPlayerJoin PlayerJoinEvent; internal static void InvokePlayerJoinEvent(Player player, ref string nick) @@ -24,13 +24,13 @@ internal static void InvokePlayerJoinEvent(Player player, ref string nick) Nick = nick }; - PlayerJoinEvent.Invoke(ref ev); + PlayerJoinEvent.Invoke(ev); nick = ev.Nick; } /// A Event which is activated when a user press any voice HotKey - public delegate void OnSpeak(ref PlayerSpeakEvent ev); + public delegate void OnSpeak(PlayerSpeakEvent ev); public static event OnSpeak SpeakEvent; internal static void InvokeSpeakEvent(DissonanceUserSetup dissonance, ref bool intercom, ref bool radio, @@ -49,7 +49,7 @@ internal static void InvokeSpeakEvent(DissonanceUserSetup dissonance, ref bool i Player = dissonance.gameObject.GetPlayer() }; - SpeakEvent.Invoke(ref ev); + SpeakEvent.Invoke(ev); intercom = ev.IntercomTalk; radio = ev.RadioTalk; @@ -76,7 +76,7 @@ internal static void InvokePlayerLeaveEvent(Player player) } // PlayerBanEvent - public delegate void OnPlayerBanEvent(ref PlayerBanEvent ev); + public delegate void OnPlayerBanEvent(PlayerBanEvent ev); public static event OnPlayerBanEvent PlayerBanEvent; internal static void InvokePlayerBanEvent(Player player, int duration, ref bool allow, @@ -92,7 +92,7 @@ internal static void InvokePlayerBanEvent(Player player, int duration, ref bool BannedPlayer = player }; - PlayerBanEvent.Invoke(ref ev); + PlayerBanEvent.Invoke(ev); allow = ev.Allowed; } @@ -116,7 +116,7 @@ internal static void InvokePlayerDieEvent(Player player, Player killer, PlayerSt } //PlayerHurtEvent - public delegate void OnPlayerHurt(ref PlayerHurtEvent ev); + public delegate void OnPlayerHurt(PlayerHurtEvent ev); public static event OnPlayerHurt PlayerHurtEvent; internal static void InvokePlayerHurtEvent(Player player, Player attacker, @@ -131,13 +131,13 @@ internal static void InvokePlayerHurtEvent(Player player, Player attacker, Info = info }; - PlayerHurtEvent.Invoke(ref ev); + PlayerHurtEvent.Invoke(ev); info = ev.Info; } //PlayerCuffedEvent - public delegate void OnPlayerCuffed(ref PlayerCuffedEvent ev); + public delegate void OnPlayerCuffed(PlayerCuffedEvent ev); public static event OnPlayerCuffed PlayerCuffedEvent; internal static void InvokePlayerCuffedEvent(Player cuffed, Player target, ref bool allow) @@ -151,13 +151,13 @@ internal static void InvokePlayerCuffedEvent(Player cuffed, Player target, ref b Allow = allow }; - PlayerCuffedEvent.Invoke(ref ev); + PlayerCuffedEvent.Invoke(ev); allow = ev.Allow; } //PlayerEscapeEvent - public delegate void OnPlayerEscape(ref PlayerEscapeEvent ev); + public delegate void OnPlayerEscape(PlayerEscapeEvent ev); public static event OnPlayerEscape PlayerEscapeEvent; internal static void InvokePlayerEscapeEvent(Player player, ref bool allow, ref RoleType spawnRole, @@ -174,14 +174,14 @@ internal static void InvokePlayerEscapeEvent(Player player, ref bool allow, ref IsCuffed = isCuffed }; - PlayerEscapeEvent.Invoke(ref ev); + PlayerEscapeEvent.Invoke(ev); allow = ev.Allow; spawnRole = ev.SpawnRole; } //SyncDataEvent - public delegate void OnSyncDataEvent(ref SyncDataEvent ev); + public delegate void OnSyncDataEvent(SyncDataEvent ev); public static event OnSyncDataEvent SyncDataEvent; internal static void InvokeSyncDataEvent(Player player, ref bool allow, ref Vector2 speed, int state) @@ -196,14 +196,14 @@ internal static void InvokeSyncDataEvent(Player player, ref bool allow, ref Vect State = state }; - SyncDataEvent.Invoke(ref ev); + SyncDataEvent.Invoke(ev); allow = ev.Allow; speed = ev.Speed; } //PlayerReloadEvent - public delegate void OnPlayerReload(ref PlayerReloadEvent ev); + public delegate void OnPlayerReload(PlayerReloadEvent ev); public static event OnPlayerReload PlayerReloadEvent; internal static void InvokePlayerReloadEvent(Player player, ref bool allow, Inventory.SyncItemInfo syncItem) @@ -217,13 +217,13 @@ internal static void InvokePlayerReloadEvent(Player player, ref bool allow, Inve InventorySlot = syncItem }; - PlayerReloadEvent.Invoke(ref ev); + PlayerReloadEvent.Invoke(ev); allow = ev.Allow; } //FemurEnterEvent - public delegate void OnFemurEnter(ref FemurEnterEvent ev); + public delegate void OnFemurEnter(FemurEnterEvent ev); public static event OnFemurEnter FemurEnterEvent; internal static void InvokeFemurEnterEvent(Player player,ref bool allow,ref bool closeFemur) @@ -237,13 +237,13 @@ internal static void InvokeFemurEnterEvent(Player player,ref bool allow,ref bool CloseFemur = closeFemur }; - FemurEnterEvent.Invoke(ref ev); + FemurEnterEvent.Invoke(ev); allow = ev.Allow; closeFemur = ev.CloseFemur; } //DroppedItemEvent - public delegate void OnDropItem(ref DropItemEvent ev); + public delegate void OnDropItem(DropItemEvent ev); public static event OnDropItem DropItemEvent; internal static void InvokeDropItem(Player player, ref Inventory.SyncItemInfo item, ref bool allow) @@ -257,7 +257,7 @@ internal static void InvokeDropItem(Player player, ref Inventory.SyncItemInfo it Allow = allow }; - DropItemEvent.Invoke(ref ev); + DropItemEvent.Invoke(ev); allow = ev.Allow; item = ev.Item; @@ -267,8 +267,8 @@ internal static void InvokeDropItem(Player player, ref Inventory.SyncItemInfo it public static event OnLoadComponents LoadComponentsEvent; internal static void InvokeLoadComponents(GameObject player) => LoadComponentsEvent?.Invoke(new LoadComponentsEvent { Player = player }); - public delegate void OnGeneratorInserted(ref GeneratorEvent ev); - public static event OnGeneratorInserted GeneratorInsertedEvent; + public delegate void OnGenerator(GeneratorEvent ev); + public static event OnGenerator GeneratorInsertedEvent; internal static void InvokeGeneratorInserted(Player player, Generator079 generator, ref bool allow) { if (GeneratorInsertedEvent == null) return; @@ -280,13 +280,12 @@ internal static void InvokeGeneratorInserted(Player player, Generator079 generat Player = player }; - GeneratorInsertedEvent.Invoke(ref ev); + GeneratorInsertedEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnGeneratorEjected(ref GeneratorEvent ev); - public static event OnGeneratorEjected GeneratorEjectedEvent; + public static event OnGenerator GeneratorEjectedEvent; internal static void InvokeGeneratorEjected(Player player, Generator079 generator, ref bool allow) { if (GeneratorEjectedEvent == null) return; @@ -298,13 +297,12 @@ internal static void InvokeGeneratorEjected(Player player, Generator079 generato Player = player }; - GeneratorEjectedEvent.Invoke(ref ev); + GeneratorEjectedEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnGeneratorUnlock(ref GeneratorEvent ev); - public static event OnGeneratorUnlock GeneratorUnlockEvent; + public static event OnGenerator GeneratorUnlockEvent; internal static void InvokeGeneratorUnlock(Player player,Generator079 generator, ref bool allow) { if (GeneratorUnlockEvent == null) return; @@ -316,13 +314,12 @@ internal static void InvokeGeneratorUnlock(Player player,Generator079 generator, Player = player }; - GeneratorUnlockEvent.Invoke(ref ev); + GeneratorUnlockEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnGeneratorOpen(ref GeneratorEvent ev); - public static event OnGeneratorOpen GeneratorOpenEvent; + public static event OnGenerator GeneratorOpenEvent; internal static void InvokeGeneratorOpen(Player player, Generator079 generator, ref bool allow) { if (GeneratorOpenEvent == null) return; @@ -334,13 +331,12 @@ internal static void InvokeGeneratorOpen(Player player, Generator079 generator, Player = player }; - GeneratorOpenEvent.Invoke(ref ev); + GeneratorOpenEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnGeneratorClose(ref GeneratorEvent ev); - public static event OnGeneratorClose GeneratorCloseEvent; + public static event OnGenerator GeneratorCloseEvent; internal static void InvokeGeneratorClose(Player player, Generator079 generator, ref bool allow) { if (GeneratorCloseEvent == null) return; @@ -352,12 +348,12 @@ internal static void InvokeGeneratorClose(Player player, Generator079 generator, Player = player }; - GeneratorCloseEvent.Invoke(ref ev); + GeneratorCloseEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnUseItem(ref UseItemEvent ev); + public delegate void OnUseItem(UseItemEvent ev); public static event OnUseItem UseItemEvent; internal static void InvokeUseItemEvent(Player player,ItemType item, out bool allow) { @@ -371,12 +367,12 @@ internal static void InvokeUseItemEvent(Player player,ItemType item, out bool al Allow = true }; - UseItemEvent.Invoke(ref ev); + UseItemEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnPickupItem(ref PickupItemEvent ev); + public delegate void OnPickupItem(PickupItemEvent ev); public static event OnPickupItem PickupItemEvent; internal static void InvokePickupItemEvent(Player player, Pickup pickup, ref bool allow) { @@ -389,12 +385,12 @@ internal static void InvokePickupItemEvent(Player player, Pickup pickup, ref boo Player = player }; - PickupItemEvent.Invoke(ref ev); + PickupItemEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnSetPlayerClass(ref PlayerSetClassEvent ev); + public delegate void OnSetPlayerClass(PlayerSetClassEvent ev); public static event OnSetPlayerClass PlayerSetClassEvent; @@ -407,14 +403,14 @@ internal static void InvokePlayerSetClassEvent(Player player, ref RoleType type, Role = type }; - PlayerSetClassEvent?.Invoke(ref ev); + PlayerSetClassEvent?.Invoke(ev); items = ev.Items; type = ev.Role; } - public delegate void OnPlayerSetGroup(ref PlayerSetGroupEvent ev); + public delegate void OnPlayerSetGroup(PlayerSetGroupEvent ev); public static event OnPlayerSetGroup PlayerSetGroupEvent; internal static void InvokePlayerSetGroupEvent(Player player, bool byAdmin, ref UserGroup group, ref bool ovr, ref bool disp, out bool allow) { @@ -431,7 +427,7 @@ internal static void InvokePlayerSetGroupEvent(Player player, bool byAdmin, ref Allow = true }; - PlayerSetGroupEvent.Invoke(ref ev); + PlayerSetGroupEvent.Invoke(ev); group = ev.Group; ovr = ev.RaAcces; diff --git a/Synapse/Events/ScpEvents.cs b/Synapse/Events/ScpEvents.cs index 6023b21..504324b 100644 --- a/Synapse/Events/ScpEvents.cs +++ b/Synapse/Events/ScpEvents.cs @@ -6,7 +6,7 @@ namespace Synapse.Events public static partial class Events { /// A Event which is activated when Scp049 respawns a Player - public delegate void OnScp049Recall(ref Scp049RecallEvent ev); + public delegate void OnScp049Recall(Scp049RecallEvent ev); public static event OnScp049Recall Scp049RecallEvent; internal static void InvokeScp049RecallEvent(Player player, ref Ragdoll ragdoll, ref Player target, @@ -24,7 +24,7 @@ internal static void InvokeScp049RecallEvent(Player player, ref Ragdoll ragdoll, Player = player }; - Scp049RecallEvent.Invoke(ref ev); + Scp049RecallEvent.Invoke(ev); ragdoll = ev.Ragdoll; target = ev.Target; @@ -33,7 +33,7 @@ internal static void InvokeScp049RecallEvent(Player player, ref Ragdoll ragdoll, allow = ev.Allow; } - public delegate void OnPocketDimensionEnter(ref PocketDimensionEvent ev); + public delegate void OnPocketDimensionEnter(PocketDimensionEvent ev); public static event OnPocketDimensionEnter PocketDimensionEnterEvent; internal static void InvokePocketDimensionEnterEvent(Player player, ref bool allow) @@ -46,12 +46,12 @@ internal static void InvokePocketDimensionEnterEvent(Player player, ref bool all Allow = allow }; - PocketDimensionEnterEvent.Invoke(ref ev); + PocketDimensionEnterEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnScp106Containment(ref Scp106ContainmentEvent ev); + public delegate void OnScp106Containment(Scp106ContainmentEvent ev); public static event OnScp106Containment Scp106ContainmentEvent; internal static void InvokeScp106ContainmentEvent(Player player, ref bool allow) @@ -64,13 +64,13 @@ internal static void InvokeScp106ContainmentEvent(Player player, ref bool allow) Allow = allow }; - Scp106ContainmentEvent.Invoke(ref ev); + Scp106ContainmentEvent.Invoke(ev); allow = ev.Allow; } - public delegate void OnScp079GainLvl(ref Scp079GainLvlEvent ev); + public delegate void OnScp079GainLvl(Scp079GainLvlEvent ev); public static event OnScp079GainLvl Scp079GainLvlEvent; internal static void InvokeScp079LvlEvent(Player player,ref int newlvl,ref bool allow) { @@ -83,7 +83,7 @@ internal static void InvokeScp079LvlEvent(Player player,ref int newlvl,ref bool Player = player }; - Scp079GainLvlEvent.Invoke(ref ev); + Scp079GainLvlEvent.Invoke(ev); newlvl = ev.NewLvl; allow = ev.Allow; diff --git a/Synapse/Events/ServerEvents.cs b/Synapse/Events/ServerEvents.cs index d716a86..d2d6758 100644 --- a/Synapse/Events/ServerEvents.cs +++ b/Synapse/Events/ServerEvents.cs @@ -38,7 +38,7 @@ internal static void InvokeRoundStart() /// A Event which is activated when a user send a Command in the Remote Admin /// It need to hook ref RemoteCommandEvent ev - public delegate void OnRemoteCommand(ref RemoteCommandEvent ev); + public delegate void OnRemoteCommand(RemoteCommandEvent ev); public static event OnRemoteCommand RemoteCommandEvent; internal static void InvokeRemoteCommandEvent(CommandSender sender, string command, ref bool allow) @@ -52,13 +52,13 @@ internal static void InvokeRemoteCommandEvent(CommandSender sender, string comma Command = command }; - RemoteCommandEvent.Invoke(ref ev); + RemoteCommandEvent.Invoke(ev); allow = ev.Allow; } /// A Event which is activated when a user send a Command in the Remote Admin - public delegate void OnConsoleCommand(ref ConsoleCommandEvent ev); + public delegate void OnConsoleCommand(ConsoleCommandEvent ev); public static event OnConsoleCommand ConsoleCommandEvent; internal static void InvokeConsoleCommandEvent(Player player, string command, out string color, @@ -74,13 +74,13 @@ internal static void InvokeConsoleCommandEvent(Player player, string command, ou Player = player }; - ConsoleCommandEvent.Invoke(ref ev); + ConsoleCommandEvent.Invoke(ev); color = ev.Color; returning = ev.ReturnMessage; } - public delegate void TeamRespawn(ref TeamRespawnEvent ev); + public delegate void TeamRespawn(TeamRespawnEvent ev); public static event TeamRespawn TeamRespawnEvent; internal static void InvokeTeamRespawnEvent(ref List respawnList, ref bool isChaos, ref bool allow ,ref bool useTickets) @@ -95,7 +95,7 @@ internal static void InvokeTeamRespawnEvent(ref List respawnList, ref bo UseTickets = useTickets }; - TeamRespawnEvent.Invoke(ref ev); + TeamRespawnEvent.Invoke(ev); respawnList = ev.RespawnList; isChaos = ev.IsChaos; @@ -103,7 +103,7 @@ internal static void InvokeTeamRespawnEvent(ref List respawnList, ref bo useTickets = ev.UseTickets; } - public delegate void OnPreAuthenticationEvent(ref PreAuthenticationEvent ev); + public delegate void OnPreAuthenticationEvent(PreAuthenticationEvent ev); public static event OnPreAuthenticationEvent PreAuthenticationEvent; internal static void InvokePreAuthentication(string userId, ConnectionRequest request, ref bool allow) @@ -115,7 +115,7 @@ internal static void InvokePreAuthentication(string userId, ConnectionRequest re UserId = userId }; - PreAuthenticationEvent?.Invoke(ref ev); + PreAuthenticationEvent?.Invoke(ev); allow = ev.Allow; } @@ -124,7 +124,7 @@ internal static void InvokePreAuthentication(string userId, ConnectionRequest re public static event OnWaitingForPlayers WaitingForPlayersEvent; internal static void InvokeWaitingForPlayers() => WaitingForPlayersEvent?.Invoke(); - public delegate void OnCheckRoundEnd(ref CheckRoundEndEvent ev); + public delegate void OnCheckRoundEnd(CheckRoundEndEvent ev); public static event OnCheckRoundEnd CheckRoundEndEvent; public static void InvokeCheckRoundEnd(ref bool forceEnd, ref bool allow, ref RoundSummary.LeadingTeam team, @@ -137,7 +137,7 @@ public static void InvokeCheckRoundEnd(ref bool forceEnd, ref bool allow, ref Ro LeadingTeam = team }; - CheckRoundEndEvent?.Invoke(ref ev); + CheckRoundEndEvent?.Invoke(ev); teamChanged = team != ev.LeadingTeam; team = ev.LeadingTeam; From ab288251f53778daaa6e0fe13f1b24565da8528a Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 11 Jul 2020 19:18:48 +0200 Subject: [PATCH 19/46] added Player.SendToServer --- Synapse/Api/Player.cs | 22 ++++++++++++++++++++++ Synapse/Api/PlayerExtensions.cs | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index af394c5..7a2ec91 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -514,5 +514,27 @@ public void RaLogout() /// public void Hurt(int amount, DamageTypes.DamageType damagetype = default,Player attacker = null) => PlayerStats.HurtPlayer(new PlayerStats.HitInfo(amount, attacker == null ? "WORLD" : attacker.NickName, damagetype, attacker == null ? PlayerId : attacker.PlayerId), attacker == null ? gameObject : attacker.gameObject); + + /// + /// Sends the Player to a Server in the same network with this Port (such a server must exist or he will be disconnected) + /// + /// The Player you wants to send + /// The Port of the Server the Player should be send to + public void SendToServer(Player player, ushort port) + { + PlayerStats component = Server.PlayerStats; + NetworkWriter writer = NetworkWriterPool.GetWriter(); + writer.WriteSingle(1f); + writer.WriteUInt16(port); + RpcMessage msg = new RpcMessage + { + netId = component.netId, + componentIndex = component.ComponentIndex, + functionHash = PlayerExtensions.GetMethodHash(typeof(PlayerStats), "RpcRoundrestartRedirect"), + payload = writer.ToArraySegment() + }; + player.Connection.Send(msg, 0); + NetworkWriterPool.Recycle(writer); + } } } diff --git a/Synapse/Api/PlayerExtensions.cs b/Synapse/Api/PlayerExtensions.cs index 332c4d1..df75dbb 100644 --- a/Synapse/Api/PlayerExtensions.cs +++ b/Synapse/Api/PlayerExtensions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; @@ -25,6 +26,8 @@ public static MethodInfo SendSpawnMessage } } + internal static int GetMethodHash(Type invokeClass, string methodName) => invokeClass.FullName.GetStableHashCode() * 503 + methodName.GetStableHashCode(); + /// Gives a player a message in the RemoteAdmin /// The User who you send the Message /// The Message you want to send From 6facc362e76268fea4025a9c33f36f6709bc8632 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 11 Jul 2020 19:21:27 +0200 Subject: [PATCH 20/46] Removed my stupid mistake --- Synapse/Api/Player.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 7a2ec91..70c4852 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -520,7 +520,7 @@ public void Hurt(int amount, DamageTypes.DamageType damagetype = default,Player /// /// The Player you wants to send /// The Port of the Server the Player should be send to - public void SendToServer(Player player, ushort port) + public void SendToServer(ushort port) { PlayerStats component = Server.PlayerStats; NetworkWriter writer = NetworkWriterPool.GetWriter(); @@ -533,7 +533,7 @@ public void SendToServer(Player player, ushort port) functionHash = PlayerExtensions.GetMethodHash(typeof(PlayerStats), "RpcRoundrestartRedirect"), payload = writer.ToArraySegment() }; - player.Connection.Send(msg, 0); + Connection.Send(msg, 0); NetworkWriterPool.Recycle(writer); } } From ea8da1290135b517f1923cdb288cef35f4da0296 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 11 Jul 2020 21:08:03 +0200 Subject: [PATCH 21/46] added PlayerExtensions.GetAllPlayers(this Team team) --- Synapse/Api/Player.cs | 1 - Synapse/Api/PlayerExtensions.cs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 70c4852..6b39405 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -518,7 +518,6 @@ public void Hurt(int amount, DamageTypes.DamageType damagetype = default,Player /// /// Sends the Player to a Server in the same network with this Port (such a server must exist or he will be disconnected) /// - /// The Player you wants to send /// The Port of the Server the Player should be send to public void SendToServer(ushort port) { diff --git a/Synapse/Api/PlayerExtensions.cs b/Synapse/Api/PlayerExtensions.cs index df75dbb..89fd40c 100644 --- a/Synapse/Api/PlayerExtensions.cs +++ b/Synapse/Api/PlayerExtensions.cs @@ -83,6 +83,8 @@ public static IEnumerable GetAllPlayers() /// public static IEnumerable GetAllPlayers(this RoleType role) => GetAllPlayers().Where(x => x.Role == role); + public static IEnumerable GetAllPlayers(this Team team) => GetAllPlayers().Where(x => x.Team == team); + /// /// Gives you the player object /// From 36f719bedfaadc9e5918b6f8c49dd208a92e3f4b Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 12 Jul 2020 11:23:55 +0200 Subject: [PATCH 22/46] added Player.Permission --- Synapse/Api/Player.cs | 5 +++++ Synapse/Api/PlayerExtensions.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 6b39405..39cc7d4 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -308,6 +308,11 @@ public Player Cuffer /// Note: This will not change the permissions public string RankName { get => Rank.BadgeText; set => Hub.serverRoles.SetText(value); } + /// + /// The Permission of the Player + /// + public ulong Permission { get => ServerRoles.Permissions; set => ServerRoles.Permissions = value; } + /// /// Is the player muted /// diff --git a/Synapse/Api/PlayerExtensions.cs b/Synapse/Api/PlayerExtensions.cs index 89fd40c..aa64430 100644 --- a/Synapse/Api/PlayerExtensions.cs +++ b/Synapse/Api/PlayerExtensions.cs @@ -83,6 +83,11 @@ public static IEnumerable GetAllPlayers() /// public static IEnumerable GetAllPlayers(this RoleType role) => GetAllPlayers().Where(x => x.Role == role); + /// + /// Gives all players on the server in this Team + /// + /// + /// public static IEnumerable GetAllPlayers(this Team team) => GetAllPlayers().Where(x => x.Team == team); /// From 604684215d867c4b918cc80a5d6fcfa8def72c10 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 12 Jul 2020 12:24:18 +0200 Subject: [PATCH 23/46] Removed PlayerSetgroup Event it isnt working --- Synapse/Events/Classes/PlayerSetGroupEvent.cs | 19 ------------- Synapse/Events/Patches/PlayerSetGroupPatch.cs | 27 ------------------- Synapse/Events/PlayerEvents.cs | 26 ------------------ Synapse/Synapse.csproj | 2 -- 4 files changed, 74 deletions(-) delete mode 100644 Synapse/Events/Classes/PlayerSetGroupEvent.cs delete mode 100644 Synapse/Events/Patches/PlayerSetGroupPatch.cs diff --git a/Synapse/Events/Classes/PlayerSetGroupEvent.cs b/Synapse/Events/Classes/PlayerSetGroupEvent.cs deleted file mode 100644 index 648a1a5..0000000 --- a/Synapse/Events/Classes/PlayerSetGroupEvent.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Synapse.Api; - -namespace Synapse.Events.Classes -{ - public class PlayerSetGroupEvent - { - public Player Player { get; internal set; } - - public bool ByAdmin { get; internal set; } - - public UserGroup Group { get; set; } - - public bool RaAcces { get; set; } - - public bool Showtag { get; set; } - - public bool Allow { get; set; } - } -} diff --git a/Synapse/Events/Patches/PlayerSetGroupPatch.cs b/Synapse/Events/Patches/PlayerSetGroupPatch.cs deleted file mode 100644 index f83f95c..0000000 --- a/Synapse/Events/Patches/PlayerSetGroupPatch.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Harmony; -using Synapse.Api; - -namespace Synapse.Events.Patches -{ - [HarmonyPatch(typeof(ServerRoles), nameof(ServerRoles.SetGroup))] - public static class PlayerSetGroupPatch - { - public static bool Prefix(ServerRoles __instance, ref UserGroup group, ref bool ovr, bool byAdmin, ref bool disp) - { - try - { - Events.InvokePlayerSetGroupEvent(__instance.GetPlayer(), byAdmin, ref group, ref ovr, ref disp, out bool allow); - - if (__instance._globalPerms > 0UL) return true; - - return allow; - } - catch(Exception e) - { - Log.Error($"PlayerSetGroup Event Error: {e}"); - return true; - } - } - } -} diff --git a/Synapse/Events/PlayerEvents.cs b/Synapse/Events/PlayerEvents.cs index 9224274..38d0477 100644 --- a/Synapse/Events/PlayerEvents.cs +++ b/Synapse/Events/PlayerEvents.cs @@ -408,31 +408,5 @@ internal static void InvokePlayerSetClassEvent(Player player, ref RoleType type, items = ev.Items; type = ev.Role; } - - - public delegate void OnPlayerSetGroup(PlayerSetGroupEvent ev); - public static event OnPlayerSetGroup PlayerSetGroupEvent; - internal static void InvokePlayerSetGroupEvent(Player player, bool byAdmin, ref UserGroup group, ref bool ovr, ref bool disp, out bool allow) - { - allow = true; - if (PlayerSetGroupEvent == null) return; - - var ev = new PlayerSetGroupEvent - { - Player = player, - ByAdmin = byAdmin, - Group = group, - RaAcces = ovr, - Showtag = disp, - Allow = true - }; - - PlayerSetGroupEvent.Invoke(ev); - - group = ev.Group; - ovr = ev.RaAcces; - disp = ev.Showtag; - allow = ev.Allow; - } } } \ No newline at end of file diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 1951c13..eeb12e6 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -72,14 +72,12 @@ - - From a2cac892d0156214115c238310c5178a9b37b3bc Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 12 Jul 2020 12:40:16 +0200 Subject: [PATCH 24/46] fixed NullException in Player.Rank --- Synapse/Api/Player.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 39cc7d4..6c07997 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -289,7 +289,7 @@ public Player Cuffer /// /// The UserGroup the player is in /// - public UserGroup Rank { get => ServerRoles.Group; set => ServerRoles.SetGroup(value, value.Permissions > 0UL,true); } + public UserGroup Rank { get => ServerRoles.Group; set => ServerRoles.SetGroup(value, value != null ? value.Permissions > 0UL : false,true); } /// /// The name of the group the user has From 4da8bff3e1922cc2ae31f5384a97cb63720668aa Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 12 Jul 2020 13:28:23 +0200 Subject: [PATCH 25/46] bug fixes --- Synapse/Api/Player.cs | 8 +++----- Synapse/Permissions/PermissionReader.cs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 6c07997..5cbf502 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -494,10 +494,9 @@ public void InstantBroadcast(ushort time, string message) /// public void RaLogin() { - Hub.serverRoles.RemoteAdmin = true; - Hub.serverRoles.Permissions = Hub.serverRoles.Group.Permissions; - Hub.serverRoles.RemoteAdminMode = ServerRoles.AccessMode.PasswordOverride; - Hub.serverRoles.TargetOpenRemoteAdmin(Connection, false); + ServerRoles.RemoteAdmin = true; + ServerRoles.RemoteAdminMode = ServerRoles.AccessMode.PasswordOverride; + ServerRoles.TargetOpenRemoteAdmin(Connection, false); } /// @@ -506,7 +505,6 @@ public void RaLogin() public void RaLogout() { Hub.serverRoles.RemoteAdmin = false; - Hub.serverRoles.Permissions = 0UL; Hub.serverRoles.RemoteAdminMode = ServerRoles.AccessMode.LocalAccess; Hub.serverRoles.TargetCloseRemoteAdmin(Connection); } diff --git a/Synapse/Permissions/PermissionReader.cs b/Synapse/Permissions/PermissionReader.cs index f00527c..eb4f066 100644 --- a/Synapse/Permissions/PermissionReader.cs +++ b/Synapse/Permissions/PermissionReader.cs @@ -83,7 +83,7 @@ internal static bool CheckPermission(Player player, string permission) if (userGroup != null) { var groupName = ServerStatic.GetPermissionsHandler()._groups - .FirstOrDefault(g => g.Value == player.Hub.serverRoles.Group).Key; + .FirstOrDefault(g => g.Value == player.Rank).Key; if (_permissionsConfig == null) { Log.Error("Permission config is null."); From 712c776547a60c95d6b7107c65679959ce48528b Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 12 Jul 2020 15:14:42 +0200 Subject: [PATCH 26/46] added PlayerTagEvent --- Synapse/Events/Classes/PlayerTagEvent.cs | 13 ++++++++ Synapse/Events/Patches/TagPatch.cs | 42 ++++++++++++++++++++++++ Synapse/Events/PlayerEvents.cs | 20 +++++++++++ Synapse/MainLoader.cs | 2 +- Synapse/Synapse.csproj | 2 ++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 Synapse/Events/Classes/PlayerTagEvent.cs create mode 100644 Synapse/Events/Patches/TagPatch.cs diff --git a/Synapse/Events/Classes/PlayerTagEvent.cs b/Synapse/Events/Classes/PlayerTagEvent.cs new file mode 100644 index 0000000..412fb0f --- /dev/null +++ b/Synapse/Events/Classes/PlayerTagEvent.cs @@ -0,0 +1,13 @@ +using Synapse.Api; + +namespace Synapse.Events.Classes +{ + public class PlayerTagEvent + { + public Player Player { get; internal set; } + + public bool ShowTag { get; internal set; } + + public bool Allow { get; set; } + } +} diff --git a/Synapse/Events/Patches/TagPatch.cs b/Synapse/Events/Patches/TagPatch.cs new file mode 100644 index 0000000..1b74072 --- /dev/null +++ b/Synapse/Events/Patches/TagPatch.cs @@ -0,0 +1,42 @@ +using System; +using Harmony; +using Synapse.Api; + +namespace Synapse.Events.Patches +{ + [HarmonyPatch(typeof(CharacterClassManager), nameof(CharacterClassManager.CallCmdRequestShowTag))] + public static class ShowTag + { + public static bool Prefix(CharacterClassManager __instance) + { + try + { + Events.InvokePlayerTagEvent(__instance.GetPlayer(), true, out bool allow); + return allow; + } + catch (Exception e) + { + Log.Error($"PlayerTagEvent Error: {e}"); + return true; + } + } + } + + [HarmonyPatch(typeof(CharacterClassManager), nameof(CharacterClassManager.CallCmdRequestHideTag))] + public static class HideTag + { + public static bool Prefix(CharacterClassManager __instance) + { + try + { + Events.InvokePlayerTagEvent(__instance.GetPlayer(), false, out bool allow); + return allow; + } + catch(Exception e) + { + Log.Error($"PlayerTagEvent Error: {e}"); + return true; + } + } + } +} diff --git a/Synapse/Events/PlayerEvents.cs b/Synapse/Events/PlayerEvents.cs index 38d0477..1192f9a 100644 --- a/Synapse/Events/PlayerEvents.cs +++ b/Synapse/Events/PlayerEvents.cs @@ -408,5 +408,25 @@ internal static void InvokePlayerSetClassEvent(Player player, ref RoleType type, items = ev.Items; type = ev.Role; } + + + public delegate void OnPlayerTag(PlayerTagEvent ev); + public static event OnPlayerTag PlayerTagEvent; + internal static void InvokePlayerTagEvent(Player player, bool show,out bool allow) + { + allow = true; + if (PlayerTagEvent == null) return; + + var ev = new PlayerTagEvent + { + Player = player, + ShowTag = show, + Allow = true + }; + + PlayerTagEvent.Invoke(ev); + + allow = ev.Allow; + } } } \ No newline at end of file diff --git a/Synapse/MainLoader.cs b/Synapse/MainLoader.cs index ef0ec64..6ef3ec4 100644 --- a/Synapse/MainLoader.cs +++ b/Synapse/MainLoader.cs @@ -7,7 +7,7 @@ namespace Synapse [SuppressMessage("ReSharper", "UnusedType.Global")] public class MainLoader { - public const string version = "v.1.2-Beta"; + public const string version = "v.1.3-Beta"; /// This method is called by the Scp Server in the assembly-csharp // ReSharper disable once UnusedMember.Global public static void LoaderExecutionCode() diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index eeb12e6..6e64010 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -72,12 +72,14 @@ + + From 2d9e3dcdc78df1d9e8a50e2d17ff7f97b9caf585 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 13 Jul 2020 16:08:54 +0200 Subject: [PATCH 27/46] update to Scopo XXI --- Synapse/Api/Map.cs | 2 +- Synapse/Events/Classes/TeamRespawnEvent.cs | 6 +- Synapse/Events/Patches/CheckRoundEndPatch.cs | 2 +- Synapse/Events/Patches/PlayerEscapePatch.cs | 8 +- Synapse/Events/Patches/TeamRespawnPatch.cs | 178 ++++++++++--------- Synapse/Events/ServerEvents.cs | 10 +- 6 files changed, 106 insertions(+), 100 deletions(-) diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 9c1f79c..fa9227b 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -182,7 +182,7 @@ public static Vector3 GetRandomSpawnPoint(this RoleType type) /// /// /// - public static void CassieMessage(string msg, bool makeHold, bool makeNoise) => Player.Server.GetComponent().RpcPlayCustomAnnouncement(msg, makeHold, makeNoise); + public static void CassieMessage(string msg, bool makeHold, bool makeNoise) => Respawning.RespawnEffectsController.PlayCassieAnnouncement(msg, makeHold, makeNoise); /// /// Starts the Decontamination diff --git a/Synapse/Events/Classes/TeamRespawnEvent.cs b/Synapse/Events/Classes/TeamRespawnEvent.cs index d82509a..1e53e28 100644 --- a/Synapse/Events/Classes/TeamRespawnEvent.cs +++ b/Synapse/Events/Classes/TeamRespawnEvent.cs @@ -5,12 +5,8 @@ namespace Synapse.Events.Classes { public class TeamRespawnEvent { - public bool IsChaos { get; set; } + public Respawning.SpawnableTeamType Team { get; set; } public List RespawnList { get; set; } - - public bool Allow { get; set; } - - public bool UseTickets { get; set; } } } diff --git a/Synapse/Events/Patches/CheckRoundEndPatch.cs b/Synapse/Events/Patches/CheckRoundEndPatch.cs index d4f32b7..cf47e59 100644 --- a/Synapse/Events/Patches/CheckRoundEndPatch.cs +++ b/Synapse/Events/Patches/CheckRoundEndPatch.cs @@ -115,7 +115,7 @@ public static IEnumerator ProcessServerSide(RoundSummary instance) roundSummary._roundEnded = true; } - else if (mtfSum == 0 && PlayerManager.localPlayer.GetComponent().MtfRespawnTickets == 0) + else if (mtfSum == 0 && Respawning.RespawnTickets.Singleton.GetAvailableTickets(Respawning.SpawnableTeamType.NineTailedFox) == 0) { roundSummary._roundEnded = true; } diff --git a/Synapse/Events/Patches/PlayerEscapePatch.cs b/Synapse/Events/Patches/PlayerEscapePatch.cs index f499689..f3784ac 100644 --- a/Synapse/Events/Patches/PlayerEscapePatch.cs +++ b/Synapse/Events/Patches/PlayerEscapePatch.cs @@ -52,7 +52,7 @@ public static bool Prefix(CharacterClassManager __instance) } //TeamCheck - var component3 = PlayerManager.localPlayer.GetComponent(); + Respawning.RespawnTickets singleton = Respawning.RespawnTickets.Singleton; var team = __instance.CurRole.team; switch (team) { @@ -79,13 +79,11 @@ public static bool Prefix(CharacterClassManager __instance) { case Team.MTF: RoundSummary.escaped_scientists++; - component3.MtfRespawnTickets += - ConfigFile.ServerConfig.GetInt("respawn_tickets_mtf_scientist_count", 1); + singleton.GrantTickets(Respawning.SpawnableTeamType.NineTailedFox, GameCore.ConfigFile.ServerConfig.GetInt("respawn_tickets_mtf_classd_cuffed_count", 1), false); break; case Team.CHI: RoundSummary.escaped_ds++; - component3.ChaosRespawnTickets += - ConfigFile.ServerConfig.GetInt("respawn_tickets_ci_scientist_cuffed_count", 2); + singleton.GrantTickets(Respawning.SpawnableTeamType.ChaosInsurgency, GameCore.ConfigFile.ServerConfig.GetInt("respawn_tickets_ci_classd_count", 1), false); break; } diff --git a/Synapse/Events/Patches/TeamRespawnPatch.cs b/Synapse/Events/Patches/TeamRespawnPatch.cs index 81bcce0..acd8a15 100644 --- a/Synapse/Events/Patches/TeamRespawnPatch.cs +++ b/Synapse/Events/Patches/TeamRespawnPatch.cs @@ -1,98 +1,114 @@ using System; using System.Collections.Generic; using System.Linq; -using GameCore; using Harmony; +using Respawning; using Synapse.Api; using UnityEngine; namespace Synapse.Events.Patches { - [HarmonyPatch(typeof(MTFRespawn), nameof(MTFRespawn.RespawnDeadPlayers))] + [HarmonyPatch(typeof(RespawnManager), nameof(RespawnManager.Spawn))] public static class TeamRespawnPatch { - public static bool Prefix(MTFRespawn __instance) + public static bool Prefix(Respawning.RespawnManager __instance) { try { - var num = 0; - var enumerable = PlayerManager.players.Where(item => - item.GetComponent().CurClass == RoleType.Spectator && - !item.GetComponent().OverwatchEnabled); - - if (__instance.priorityMTFRespawn) - enumerable = enumerable.OrderBy(item => item.GetComponent().DeathTime); - - var num2 = __instance.nextWaveIsCI ? __instance.maxCIRespawnAmount : __instance.maxMTFRespawnAmount; - if (ConfigFile.ServerConfig.GetBool("respawn_tickets_enable", true)) - { - if (__instance.NextWaveRespawnTickets == 0) - { - if (__instance.nextWaveIsCI) - { - __instance._ciDisabled = true; - return false; - } - - RoundSummary.singleton.ForceEnd(); - return false; - } - - num2 = Mathf.Min(num2, __instance.NextWaveRespawnTickets); - } - - var list = enumerable.Take(num2).ToList(); - - //Event - var allow = true; - var useTickets = true; - - var respawnList = list.Select(player => player.GetPlayer()).ToList(); - - Events.InvokeTeamRespawnEvent(ref respawnList,ref __instance.nextWaveIsCI,ref allow,ref useTickets); - - if (!allow) return false; - list.Clear(); - list.AddRange(respawnList.Select(hub => hub.gameObject)); - - if (useTickets) __instance.NextWaveRespawnTickets -= num2 - list.Count; - - if (ConfigFile.ServerConfig.GetBool("use_crypto_rng")) - list.ShuffleListSecure(); - else - list.ShuffleList(); - - __instance.playersToNTF.Clear(); - if (__instance.nextWaveIsCI && AlphaWarheadController.Host.detonated) __instance.nextWaveIsCI = false; - foreach (var gameObject in list.Where(gameObject => !(gameObject == null))) - { - num++; - if (__instance.nextWaveIsCI) - { - __instance.GetComponent() - .SetPlayersClass(RoleType.ChaosInsurgency, gameObject); - ServerLogs.AddLog(ServerLogs.Modules.ClassChange, - gameObject.GetComponent().MyNick + " (" + - gameObject.GetComponent().UserId + - ") respawned as Chaos Insurgency agent.", ServerLogs.ServerLogType.GameEvent); - } - else - { - __instance.playersToNTF.Add(gameObject); - } - } - - if (num > 0) - { - ServerLogs.AddLog(ServerLogs.Modules.ClassChange, - (__instance.nextWaveIsCI ? "Chaos Insurgency" : "MTF") + " respawned!", - ServerLogs.ServerLogType.GameEvent); - if (__instance.nextWaveIsCI) __instance.Invoke("CmdDelayCIAnnounc", 1f); - } - - __instance.SummonNTF(); - - return false; + if (!RespawnWaveGenerator.SpawnableTeams.TryGetValue(__instance.NextKnownTeam, out SpawnableTeam spawnableTeam) || __instance.NextKnownTeam == SpawnableTeamType.None) + { + ServerConsole.AddLog("Fatal error. Team '" + __instance.NextKnownTeam.ToString() + "' is undefined.", (ConsoleColor)12); + return false; + } + List list = Enumerable.ToList(Enumerable.Where(ReferenceHub.GetAllHubs().Values, (ReferenceHub item) => item.characterClassManager.CurClass == RoleType.Spectator && !item.serverRoles.OverwatchEnabled)); + if (__instance._prioritySpawn) + { + list = Enumerable.ToList(Enumerable.OrderBy(list, (ReferenceHub item) => item.characterClassManager.DeathTime)); + } + else + { + list.ShuffleList(); + } + RespawnTickets singleton = RespawnTickets.Singleton; + int num = singleton.GetAvailableTickets(__instance.NextKnownTeam); + if (num == 0) + { + num = singleton.DefaultTeamAmount; + RespawnTickets.Singleton.GrantTickets(singleton.DefaultTeam, singleton.DefaultTeamAmount, true); + } + int num2 = Mathf.Min(num, spawnableTeam.MaxWaveSize); + while (list.Count > num2) + { + list.RemoveAt(list.Count - 1); + } + list.ShuffleList(); + List list2 = ListPool.Rent(); + + var Playerlist = new List(); + foreach (ReferenceHub hub in list) + Playerlist.Add(hub.GetPlayer()); + + Events.InvokeTeamRespawnEvent(ref Playerlist,ref __instance.NextKnownTeam); + + if (__instance.NextKnownTeam == SpawnableTeamType.None) + return false; + + foreach (var player in Playerlist) + { + try + { + RoleType classid = spawnableTeam.ClassQueue[Mathf.Min(list2.Count, spawnableTeam.ClassQueue.Length - 1)]; + player.ClassManager.SetPlayersClass(classid, player.gameObject, false, false); + list2.Add(player.Hub); + ServerLogs.AddLog(ServerLogs.Modules.ClassChange, string.Concat(new string[] + { + "Player ", + player.Hub.LoggedNameFromRefHub(), + " respawned as ", + classid.ToString(), + "." + }), ServerLogs.ServerLogType.GameEvent, false); + } + catch (Exception ex) + { + if (player != null) + { + ServerLogs.AddLog(ServerLogs.Modules.ClassChange, "Player " + player.Hub.LoggedNameFromRefHub() + " couldn't be spawned. Err msg: " + ex.Message, ServerLogs.ServerLogType.GameEvent, false); + } + else + { + ServerLogs.AddLog(ServerLogs.Modules.ClassChange, "Couldn't spawn a player - target's ReferenceHub is null.", ServerLogs.ServerLogType.GameEvent, false); + } + } + } + if (list2.Count > 0) + { + ServerLogs.AddLog(ServerLogs.Modules.ClassChange, string.Concat(new object[] + { + "RespawnManager has successfully spawned ", + list2.Count, + " players as ", + __instance.NextKnownTeam.ToString(), + "!" + }), ServerLogs.ServerLogType.GameEvent, false); + RespawnTickets.Singleton.GrantTickets(__instance.NextKnownTeam, -list2.Count * spawnableTeam.TicketRespawnCost, false); + Respawning.NamingRules.UnitNamingRule unitNamingRule; + if (Respawning.NamingRules.UnitNamingRules.TryGetNamingRule(__instance.NextKnownTeam, out unitNamingRule)) + { + string text; + unitNamingRule.GenerateNew(__instance.NextKnownTeam, out text); + foreach (ReferenceHub referenceHub2 in list2) + { + referenceHub2.characterClassManager.NetworkCurSpawnableTeamType = (byte)__instance.NextKnownTeam; + referenceHub2.characterClassManager.NetworkCurUnitName = text; + } + unitNamingRule.PlayEntranceAnnouncement(text); + } + RespawnEffectsController.ExecuteAllEffects(RespawnEffectsController.EffectType.UponRespawn, __instance.NextKnownTeam); + } + __instance.NextKnownTeam = SpawnableTeamType.None; + + return false; } catch (Exception e) { diff --git a/Synapse/Events/ServerEvents.cs b/Synapse/Events/ServerEvents.cs index d2d6758..6b5926d 100644 --- a/Synapse/Events/ServerEvents.cs +++ b/Synapse/Events/ServerEvents.cs @@ -83,24 +83,20 @@ internal static void InvokeConsoleCommandEvent(Player player, string command, ou public delegate void TeamRespawn(TeamRespawnEvent ev); public static event TeamRespawn TeamRespawnEvent; - internal static void InvokeTeamRespawnEvent(ref List respawnList, ref bool isChaos, ref bool allow ,ref bool useTickets) + internal static void InvokeTeamRespawnEvent(ref List respawnList, ref Respawning.SpawnableTeamType team) { if (TeamRespawnEvent == null) return; var ev = new TeamRespawnEvent { - Allow = allow, - IsChaos = isChaos, RespawnList = respawnList, - UseTickets = useTickets + Team = team }; TeamRespawnEvent.Invoke(ev); + team = ev.Team; respawnList = ev.RespawnList; - isChaos = ev.IsChaos; - allow = ev.Allow; - useTickets = ev.UseTickets; } public delegate void OnPreAuthenticationEvent(PreAuthenticationEvent ev); From 44814c887c1169683ef15a65452e249801aad882 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Fri, 17 Jul 2020 14:39:27 +0200 Subject: [PATCH 28/46] added much stuff to the api --- Synapse/Api/Decontamination.cs | 31 +++++++++ .../{PlayerExtensions.cs => Extensions.cs} | 54 +-------------- Synapse/Api/Map.cs | 56 +-------------- Synapse/Api/Player.cs | 58 +++++++++++++--- Synapse/Api/Round.cs | 36 ++++++++++ Synapse/Api/Server.cs | 67 ++++++++++++++++++ Synapse/Api/Warhead.cs | 69 +++++++++++++++++++ Synapse/Events/Classes/RemoteCommandEvent.cs | 4 +- Synapse/Events/Patches/PlayerBanPatch.cs | 2 +- Synapse/Events/Patches/PlayerDamagePatch.cs | 2 +- Synapse/MainLoader.cs | 2 +- Synapse/Synapse.csproj | 6 +- 12 files changed, 265 insertions(+), 122 deletions(-) create mode 100644 Synapse/Api/Decontamination.cs rename Synapse/Api/{PlayerExtensions.cs => Extensions.cs} (59%) create mode 100644 Synapse/Api/Round.cs create mode 100644 Synapse/Api/Server.cs create mode 100644 Synapse/Api/Warhead.cs diff --git a/Synapse/Api/Decontamination.cs b/Synapse/Api/Decontamination.cs new file mode 100644 index 0000000..7c0d4ad --- /dev/null +++ b/Synapse/Api/Decontamination.cs @@ -0,0 +1,31 @@ +using LightContainmentZoneDecontamination; +using Mirror; + +namespace Synapse.Api +{ + public static class Decontamination + { + public static DecontaminationController Controller { get => DecontaminationController.Singleton; } + + public static bool IsDecontaminationDisabled + { + get => Controller._disableDecontamination; + set + { + if (value) + { + Controller._stopUpdating = false; + Controller.RoundStartTime = NetworkTime.time; + } + Controller._disableDecontamination = value; + } + } + + public static bool IsDecontaminationInProgress => Controller._decontaminationBegun; + + /// + /// Starts the Decontamination + /// + public static void StartDecontamination() => Controller.FinishDecontamination(); + } +} diff --git a/Synapse/Api/PlayerExtensions.cs b/Synapse/Api/Extensions.cs similarity index 59% rename from Synapse/Api/PlayerExtensions.cs rename to Synapse/Api/Extensions.cs index aa64430..e94f0c3 100644 --- a/Synapse/Api/PlayerExtensions.cs +++ b/Synapse/Api/Extensions.cs @@ -11,23 +11,8 @@ namespace Synapse.Api { [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] [SuppressMessage("ReSharper", "UnusedMember.Global")] - public static class PlayerExtensions + public static class Extensions { - private static MethodInfo _sendSpawnMessage; - public static MethodInfo SendSpawnMessage - { - get - { - if (_sendSpawnMessage == null) - _sendSpawnMessage = typeof(NetworkServer).GetMethod("SendSpawnMessage",BindingFlags.Instance | BindingFlags.InvokeMethod - | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public); - - return _sendSpawnMessage; - } - } - - internal static int GetMethodHash(Type invokeClass, string methodName) => invokeClass.FullName.GetStableHashCode() * 503 + methodName.GetStableHashCode(); - /// Gives a player a message in the RemoteAdmin /// The User who you send the Message /// The Message you want to send @@ -67,28 +52,18 @@ public static void RaMessage(this CommandSender sender, string message, bool suc sender.RaReply($"{Assembly.GetCallingAssembly().GetName().Name}#" + message, success, true, category); } - /// - /// Gives all players on the server - /// - public static IEnumerable GetAllPlayers() - { - return (from gameObject in PlayerManager.players - where gameObject != PlayerManager.localPlayer && gameObject != null - select gameObject.GetPlayer()).ToList(); - } - /// /// Gives all players on the server with this Role /// /// - public static IEnumerable GetAllPlayers(this RoleType role) => GetAllPlayers().Where(x => x.Role == role); + public static IEnumerable GetAllPlayers(this RoleType role) => Player.GetAllPlayers().Where(x => x.Role == role); /// /// Gives all players on the server in this Team /// /// /// - public static IEnumerable GetAllPlayers(this Team team) => GetAllPlayers().Where(x => x.Team == team); + public static IEnumerable GetAllPlayers(this Team team) => Player.GetAllPlayers().Where(x => x.Team == team); /// /// Gives you the player object @@ -104,28 +79,5 @@ public static IEnumerable GetAllPlayers() /// Gives you the player object /// public static Player GetPlayer(this GameObject gameObject) => gameObject.GetComponent(); - - /// - /// Gives you the player object - /// - public static Player GetPlayer(int id) => GetAllPlayers().FirstOrDefault(p => p.PlayerId == id); - - /// - /// Gives you the player object - /// - public static Player GetPlayer(string arg) - { - if (short.TryParse(arg, out var playerId)) - return GetPlayer(playerId); - - if (!arg.EndsWith("@steam") && !arg.EndsWith("@discord") && !arg.EndsWith("@northwood") && - !arg.EndsWith("@patreon")) - return GetAllPlayers().FirstOrDefault(p => p.NickName.ToLower().Contains(arg.ToLower())); - foreach (var player in GetAllPlayers()) - if (player.UserId == arg) - return player; - - return GetAllPlayers().FirstOrDefault(p => p.NickName.ToLower().Contains(arg.ToLower())); - } } } \ No newline at end of file diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index fa9227b..6a92a96 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -12,21 +12,6 @@ namespace Synapse.Api [SuppressMessage("ReSharper", "UnusedMember.Global")] public static class Map { - /// - /// Gives you the WarheadController. - /// - public static AlphaWarheadController WarheadController => Player.Server.GetComponent(); - - /// - /// Activates/Deactivates the RoundLock (if the Round can end) - /// - public static bool RoundLock { get => RoundSummary.RoundLock; set => RoundSummary.RoundLock = value; } - - /// - /// Activates/Deactivates the LobbyLock (if the Lobby can continue counting down) - /// - public static bool LobbyLock { get => GameCore.RoundStart.LobbyLock; set => GameCore.RoundStart.LobbyLock = value; } - /// /// Activates/Deactivates the FriendlyFire on the server /// @@ -37,7 +22,7 @@ public static class Map /// public static List Lifts => Object.FindObjectsOfType().ToList(); - private static Broadcast BroadcastComponent => Player.Server.GetComponent(); + private static Broadcast BroadcastComponent => Player.Host.GetComponent(); private static List _rooms = new List(); @@ -57,18 +42,6 @@ public static List Rooms } } - /// - /// Is the nuke detonated? - /// - public static bool IsNukeDetonated => - WarheadController.detonated; - - /// - /// Is the nuke in progress? - /// - public static bool IsNukeInProgress => - WarheadController.inProgress; - /// /// How many generators are activated? /// @@ -184,37 +157,12 @@ public static Vector3 GetRandomSpawnPoint(this RoleType type) /// public static void CassieMessage(string msg, bool makeHold, bool makeNoise) => Respawning.RespawnEffectsController.PlayCassieAnnouncement(msg, makeHold, makeNoise); - /// - /// Starts the Decontamination - /// - public static void StartDecontamination() => DecontaminationController.Singleton.FinishDecontamination(); - - - /// - /// Starts the nuke - /// - public static void StartNuke() - { - var alpha = PlayerManager.localPlayer.GetComponent(); - alpha.InstantPrepare(); - alpha.StartDetonation(); - } /// /// Spawns a Item on the Map /// public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) - => Player.Server.Inventory.SetPickup(itemType, durability, position, rotation, sight, barrel, other); - - /// - /// Stops the nuke - /// - public static void StopNuke() => WarheadController.CancelDetonation(); - - /// - /// Detonates the nuke - /// - public static void DetonateNuke() => WarheadController.Detonate(); + => Player.Host.Inventory.SetPickup(itemType, durability, position, rotation, sight, barrel, other); /// /// Has the group the permission? diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 5cbf502..b803112 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using Dissonance; using Hints; using Mirror; using RemoteAdmin; @@ -16,7 +18,37 @@ namespace Synapse.Api // ReSharper disable once ClassNeverInstantiated.Global public class Player : MonoBehaviour { - public static Player Server => PlayerManager.localPlayer.GetPlayer(); + public static Player Host => PlayerManager.localPlayer.GetPlayer(); + + public static IEnumerable GetAllPlayers() + { + return (from gameObject in PlayerManager.players + where gameObject != PlayerManager.localPlayer && gameObject != null + select gameObject.GetPlayer()).ToList(); + } + + /// + /// Gives you the player object + /// + public static Player GetPlayer(int id) => Player.GetAllPlayers().FirstOrDefault(p => p.PlayerId == id); + + /// + /// Gives you the player object + /// + public static Player GetPlayer(string arg) + { + if (short.TryParse(arg, out var playerId)) + return GetPlayer(playerId); + + if (!arg.EndsWith("@steam") && !arg.EndsWith("@discord") && !arg.EndsWith("@northwood") && + !arg.EndsWith("@patreon")) + return Player.GetAllPlayers().FirstOrDefault(p => p.NickName.ToLower().Contains(arg.ToLower())); + foreach (var player in Player.GetAllPlayers()) + if (player.UserId == arg) + return player; + + return Player.GetAllPlayers().FirstOrDefault(p => p.NickName.ToLower().Contains(arg.ToLower())); + } public ReferenceHub Hub => GetComponent(); @@ -60,7 +92,7 @@ public CommandSender CommandSender { get { - if (this == Server) return ServerConsole._scs; + if (this == Host) return ServerConsole._scs; else return QueryProcessor._sender; } } @@ -125,8 +157,8 @@ public Vector3 Scale { Hub.transform.localScale = value; - foreach (var player in PlayerExtensions.GetAllPlayers()) - PlayerExtensions.SendSpawnMessage?.Invoke(null, new object[] { Hub.GetComponent(), player.Connection }); + foreach (var player in GetAllPlayers()) + Server.SendSpawnMessage?.Invoke(null, new object[] { Hub.GetComponent(), player.Connection }); } catch (Exception e) { @@ -254,7 +286,7 @@ public Room CurRoom /// maybe be null, if set to null, uncuffed public Player Cuffer { - get => PlayerExtensions.GetPlayer(Handcuffs.CufferId); + get => GetPlayer(Handcuffs.CufferId); set { var handcuff = value.Handcuffs; @@ -323,8 +355,6 @@ public Player Cuffer /// public bool IsIntercomMuted { get => ClassManager.NetworkIntercomMuted; set => ClassManager.NetworkIntercomMuted = value; } - //TODO: Find a way to make this possible again: public bool FriendlyFire { get => Hub.weaponManager.NetworkfriendlyFire; set => Hub.weaponManager.NetworkfriendlyFire = value; } - /// /// The current camera the player uses (Scp079 only, if not null) /// @@ -371,7 +401,7 @@ public Player Cuffer /// /// /// - public void Ban(int duration, string reason, string issuer = "Plugin") => Server.GetComponent().BanUser(gameObject, duration, reason, issuer); + public void Ban(int duration, string reason, string issuer = "Plugin") => Host.GetComponent().BanUser(gameObject, duration, reason, issuer); /// /// Kills a player @@ -393,7 +423,7 @@ public void ChangeRoleAtPosition(RoleType role) /// public bool CheckPermission(string permission) { - if (this == Server) return true; + if (this == Host) return true; try { return PermissionReader.CheckPermission(this, permission); @@ -476,6 +506,12 @@ 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 DropItem(Inventory.SyncItemInfo item) + { + Inventory.SetPickup(item.id, item.durability, Position, Inventory.camera.transform.rotation, item.modSight, item.modBarrel, item.modOther); + Items.Remove(item); + } + /// /// Clears the players Inventory /// @@ -524,7 +560,7 @@ public void Hurt(int amount, DamageTypes.DamageType damagetype = default,Player /// The Port of the Server the Player should be send to public void SendToServer(ushort port) { - PlayerStats component = Server.PlayerStats; + PlayerStats component = Host.PlayerStats; NetworkWriter writer = NetworkWriterPool.GetWriter(); writer.WriteSingle(1f); writer.WriteUInt16(port); @@ -532,7 +568,7 @@ public void SendToServer(ushort port) { netId = component.netId, componentIndex = component.ComponentIndex, - functionHash = PlayerExtensions.GetMethodHash(typeof(PlayerStats), "RpcRoundrestartRedirect"), + functionHash = Server.GetMethodHash(typeof(PlayerStats), "RpcRoundrestartRedirect"), payload = writer.ToArraySegment() }; Connection.Send(msg, 0); diff --git a/Synapse/Api/Round.cs b/Synapse/Api/Round.cs new file mode 100644 index 0000000..45422d7 --- /dev/null +++ b/Synapse/Api/Round.cs @@ -0,0 +1,36 @@ +using GameCore; +using System; + +namespace Synapse.Api +{ + public static class Round + { + public static TimeSpan RoundLenght => RoundStart.RoundLenght; + + public static DateTime StartedTime => DateTime.Now - RoundLenght; + + public static bool IsStarted => RoundSummary.RoundInProgress(); + + /// + /// Activates/Deactivates the RoundLock (if the Round can end) + /// + public static bool IsLocked{ get => RoundSummary.RoundLock; set => RoundSummary.RoundLock = value; } + + public static int Escaped_Ds { get => RoundSummary.escaped_ds; set => RoundSummary.escaped_ds = value; } + + public static int Escaped_Scientists { get => RoundSummary.escaped_scientists; set => RoundSummary.escaped_scientists = value; } + + public static int Kills_by_Scps { get => RoundSummary.kills_by_scp; set => RoundSummary.kills_by_scp = value; } + + public static int Changed_into_Zombies { get => RoundSummary.changed_into_zombies; set => RoundSummary.changed_into_zombies = value; } + + /// + /// Activates/Deactivates the LobbyLock (if the Lobby can continue counting down) + /// + public static bool IsLobbyLocked{ get => GameCore.RoundStart.LobbyLock; set => GameCore.RoundStart.LobbyLock = value; } + + public static void Restart() => Player.Host.PlayerStats.Roundrestart(); + + public static void Start() => CharacterClassManager.ForceRoundStart(); + } +} diff --git a/Synapse/Api/Server.cs b/Synapse/Api/Server.cs new file mode 100644 index 0000000..67e5d6c --- /dev/null +++ b/Synapse/Api/Server.cs @@ -0,0 +1,67 @@ +using Mirror; +using System; +using System.Reflection; + +namespace Synapse.Api +{ + public static class Server + { + private static MethodInfo _sendSpawnMessage; + private static Broadcast broadcast; + private static BanPlayer banPlayer; + + + public static Player Host => Player.Host; + + public static string Name + { + get => ServerConsole._serverName; + set + { + ServerConsole._serverName = value; + ServerConsole.singleton.RefreshServerName(); + } + } + + public static ushort Port { get => ServerStatic.ServerPort; set => ServerStatic.ServerPort = value; } + + public static MethodInfo SendSpawnMessage + { + get + { + if (_sendSpawnMessage == null) + _sendSpawnMessage = typeof(NetworkServer).GetMethod("SendSpawnMessage", BindingFlags.Instance | BindingFlags.InvokeMethod + | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public); + + return _sendSpawnMessage; + } + } + + public static Broadcast Broadcast + { + get + { + if (broadcast == null) + broadcast = Host.GetComponent(); + + return broadcast; + } + } + + public static BanPlayer BanPlayer + { + get + { + if (banPlayer == null) + banPlayer = Host.GetComponent(); + + return banPlayer; + } + } + + public static ServerConsole Console => ServerConsole.singleton; + + + public static int GetMethodHash(Type invokeClass, string methodName) => invokeClass.FullName.GetStableHashCode() * 503 + methodName.GetStableHashCode(); + } +} diff --git a/Synapse/Api/Warhead.cs b/Synapse/Api/Warhead.cs new file mode 100644 index 0000000..4cb9fba --- /dev/null +++ b/Synapse/Api/Warhead.cs @@ -0,0 +1,69 @@ +namespace Synapse.Api +{ + public static class Warhead + { + private static AlphaWarheadController controller; + private static AlphaWarheadNukesitePanel nukesitePanel; + + public static AlphaWarheadController Controller + { + get + { + if (controller == null) + controller = Player.Host.GetComponent(); + + return controller; + } + } + + public static AlphaWarheadNukesitePanel NukesitePanel + { + get + { + if (nukesitePanel == null) + nukesitePanel = Player.Host.GetComponent(); + + return nukesitePanel; + } + } + + public static bool LeverStatus { get => NukesitePanel.Networkenabled; set => NukesitePanel.Networkenabled = value; } + + public static float DetonationTimer + { + get => Controller.NetworktimeToDetonation; + set => Controller.NetworktimeToDetonation = value; + } + + /// + /// Is the nuke detonated? + /// + public static bool IsNukeDetonated => Controller.detonated; + + /// + /// Is the nuke in progress? + /// + public static bool IsNukeInProgress => Controller.inProgress; + + /// + /// Starts the nuke + /// + public static void StartNuke() + { + Controller.InstantPrepare(); + Controller.StartDetonation(); + } + + /// + /// Stops the nuke + /// + public static void StopNuke() => Controller.CancelDetonation(); + + /// + /// Detonates the nuke + /// + public static void DetonateNuke() => Controller.Detonate(); + + public static void Shake() => Controller.RpcShake(true); + } +} diff --git a/Synapse/Events/Classes/RemoteCommandEvent.cs b/Synapse/Events/Classes/RemoteCommandEvent.cs index 84924c0..dc1c3e0 100644 --- a/Synapse/Events/Classes/RemoteCommandEvent.cs +++ b/Synapse/Events/Classes/RemoteCommandEvent.cs @@ -8,8 +8,8 @@ public class RemoteCommandEvent : EventArgs public CommandSender Sender { get; internal set; } public Player Player => Sender.SenderId == "SERVER CONSOLE" || Sender.SenderId == "GAME CONSOLE" - ? Player.Server - : PlayerExtensions.GetPlayer(Sender.SenderId); + ? Player.Host + : Player.GetPlayer(Sender.SenderId); public bool Allow { get; set; } diff --git a/Synapse/Events/Patches/PlayerBanPatch.cs b/Synapse/Events/Patches/PlayerBanPatch.cs index 10f3fb2..3bc5b1e 100644 --- a/Synapse/Events/Patches/PlayerBanPatch.cs +++ b/Synapse/Events/Patches/PlayerBanPatch.cs @@ -15,7 +15,7 @@ public static bool Prefix(GameObject user, int duration, string reason, string i try { var player = user.GetPlayer(); - var banIssuer = PlayerExtensions.GetPlayer(issuer); + var banIssuer = Player.GetPlayer(issuer); var allow = true; Events.InvokePlayerBanEvent(player, duration, ref allow, reason, banIssuer); diff --git a/Synapse/Events/Patches/PlayerDamagePatch.cs b/Synapse/Events/Patches/PlayerDamagePatch.cs index 15d96fb..fd99663 100644 --- a/Synapse/Events/Patches/PlayerDamagePatch.cs +++ b/Synapse/Events/Patches/PlayerDamagePatch.cs @@ -17,7 +17,7 @@ public static void Prefix(PlayerStats __instance, ref PlayerStats.HitInfo info, var killer = __instance.GetPlayer(); if (info.GetDamageType() == DamageTypes.Grenade) - killer = PlayerExtensions.GetPlayer(info.PlayerId); + killer = Player.GetPlayer(info.PlayerId); var player = go.GetPlayer(); diff --git a/Synapse/MainLoader.cs b/Synapse/MainLoader.cs index 6ef3ec4..492f523 100644 --- a/Synapse/MainLoader.cs +++ b/Synapse/MainLoader.cs @@ -7,7 +7,7 @@ namespace Synapse [SuppressMessage("ReSharper", "UnusedType.Global")] public class MainLoader { - public const string version = "v.1.3-Beta"; + public const string version = "v.1.4-Beta"; /// This method is called by the Scp Server in the assembly-csharp // ReSharper disable once UnusedMember.Global public static void LoaderExecutionCode() diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 6e64010..155cf47 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -64,12 +64,16 @@ + + + + - + From 69381251bb12712ffba45c2af6ab213807e60201 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 13:58:31 +0200 Subject: [PATCH 29/46] added Player.UnitName --- Synapse/Api/Player.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index b803112..b80c2a4 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -387,6 +387,7 @@ public Player Cuffer public Jail Jail => GetComponent(); + public string UnitName { get => ClassManager.NetworkCurUnitName; set => ClassManager.NetworkCurUnitName = value; } //Methods /// From 20a1986e35e3ff5a389f17109550ab77937e87e4 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 16:20:29 +0200 Subject: [PATCH 30/46] moved some classes and renamed Namespaces + added PluginDetails --- Synapse/Api/Map.cs | 3 +-- Synapse/Api/Player.cs | 3 +-- Synapse/{ => Api/Plugin}/Plugin.cs | 6 ++--- Synapse/Api/Plugin/PluginDetails.cs | 14 +++++++++++ Synapse/{ => Api/Plugin}/Translation.cs | 4 +-- Synapse/Api/Round.cs | 8 ++++++ .../PermissionReader.cs | 2 +- .../{Configs.cs => Configs/SynapseConfigs.cs} | 7 +++--- Synapse/Events/EventHandlers.cs | 8 +++--- Synapse/Events/Patches/FemurEnterPatch.cs | 3 ++- Synapse/Events/Patches/ServerNamePatch.cs | 3 ++- Synapse/Events/Patches/SpeakPatch.cs | 3 ++- Synapse/PluginManager.cs | 25 +++++++++++++------ Synapse/Synapse.csproj | 9 ++++--- 14 files changed, 67 insertions(+), 31 deletions(-) rename Synapse/{ => Api/Plugin}/Plugin.cs (94%) create mode 100644 Synapse/Api/Plugin/PluginDetails.cs rename Synapse/{ => Api/Plugin}/Translation.cs (96%) rename Synapse/{Permissions => Configs}/PermissionReader.cs (99%) rename Synapse/{Configs.cs => Configs/SynapseConfigs.cs} (89%) diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 6a92a96..a201a2c 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -1,5 +1,4 @@ -using LightContainmentZoneDecontamination; -using Synapse.Permissions; +using Synapse.Configs; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index b80c2a4..fc24729 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -2,13 +2,12 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using Dissonance; using Hints; using Mirror; using RemoteAdmin; using Searching; using Synapse.Api.Enums; -using Synapse.Permissions; +using Synapse.Configs; using UnityEngine; namespace Synapse.Api diff --git a/Synapse/Plugin.cs b/Synapse/Api/Plugin/Plugin.cs similarity index 94% rename from Synapse/Plugin.cs rename to Synapse/Api/Plugin/Plugin.cs index f4918c4..374334e 100644 --- a/Synapse/Plugin.cs +++ b/Synapse/Api/Plugin/Plugin.cs @@ -1,6 +1,6 @@ using System.IO; -namespace Synapse +namespace Synapse.Api.Plugin { public abstract class Plugin { @@ -17,6 +17,8 @@ public abstract class Plugin // ReSharper disable once UnusedAutoPropertyAccessor.Global public Translation Translation { get; internal set; } + public PluginDetails Details { get; internal set; } + private string _ownPluginFolder; /// @@ -36,8 +38,6 @@ public string OwnPluginFolder internal set => _ownPluginFolder = value; } - public abstract string GetName { get; } - /// The Method ist always activated when the Server starts /// You can use it to hook Events public abstract void OnEnable(); diff --git a/Synapse/Api/Plugin/PluginDetails.cs b/Synapse/Api/Plugin/PluginDetails.cs new file mode 100644 index 0000000..dcc15b1 --- /dev/null +++ b/Synapse/Api/Plugin/PluginDetails.cs @@ -0,0 +1,14 @@ +using System; + +namespace Synapse.Api.Plugin +{ + public class PluginDetails : Attribute + { + public int SynapseMajor; + public int SynapseMinor; + public string Name; + public string Author; + public string Description; + public string Version; + } +} diff --git a/Synapse/Translation.cs b/Synapse/Api/Plugin/Translation.cs similarity index 96% rename from Synapse/Translation.cs rename to Synapse/Api/Plugin/Translation.cs index 47a8602..8b00739 100644 --- a/Synapse/Translation.cs +++ b/Synapse/Api/Plugin/Translation.cs @@ -3,7 +3,7 @@ using System.IO; using System.Linq; -namespace Synapse +namespace Synapse.Api.Plugin { [SuppressMessage("ReSharper", "UnusedMember.Global")] public class Translation @@ -14,7 +14,7 @@ public class Translation public void CreateTranslations(Dictionary translations) { - _translationPath = Path.Combine(PluginManager.ServerConfigDirectory, Plugin.GetName + "-translation.txt"); + _translationPath = Path.Combine(PluginManager.ServerConfigDirectory, Plugin.Details.Name + "-translation.txt"); if (!File.Exists(_translationPath)) File.Create(_translationPath).Close(); var dictionary = new Dictionary(); diff --git a/Synapse/Api/Round.cs b/Synapse/Api/Round.cs index 45422d7..7c991a6 100644 --- a/Synapse/Api/Round.cs +++ b/Synapse/Api/Round.cs @@ -1,4 +1,5 @@ using GameCore; +using Respawning; using System; namespace Synapse.Api @@ -32,5 +33,12 @@ public static class Round public static void Restart() => Player.Host.PlayerStats.Roundrestart(); public static void Start() => CharacterClassManager.ForceRoundStart(); + + public static void MTFRespawn(bool isCI = false) + { + var component = Server.Host.GetComponent(); + component.NextKnownTeam = isCI ? SpawnableTeamType.ChaosInsurgency : SpawnableTeamType.NineTailedFox; + component.Spawn(); + } } } diff --git a/Synapse/Permissions/PermissionReader.cs b/Synapse/Configs/PermissionReader.cs similarity index 99% rename from Synapse/Permissions/PermissionReader.cs rename to Synapse/Configs/PermissionReader.cs index eb4f066..f08f1a3 100644 --- a/Synapse/Permissions/PermissionReader.cs +++ b/Synapse/Configs/PermissionReader.cs @@ -7,7 +7,7 @@ // ReSharper disable All -namespace Synapse.Permissions +namespace Synapse.Configs { public static class PermissionReader { diff --git a/Synapse/Configs.cs b/Synapse/Configs/SynapseConfigs.cs similarity index 89% rename from Synapse/Configs.cs rename to Synapse/Configs/SynapseConfigs.cs index dc41469..96d6dcc 100644 --- a/Synapse/Configs.cs +++ b/Synapse/Configs/SynapseConfigs.cs @@ -1,8 +1,9 @@ -using System.Collections.Generic; +using Synapse.Api.Plugin; +using System.Collections.Generic; -namespace Synapse +namespace Synapse.Configs { - internal static class Configs + internal static class SynapseConfigs { // Configs internal static int RequiredForFemur; diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index dfdaa03..9af3075 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -4,7 +4,7 @@ using Synapse.Api; using Synapse.Api.Enums; using Synapse.Events.Classes; -using Synapse.Permissions; +using Synapse.Configs; using UnityEngine; namespace Synapse.Events @@ -33,13 +33,13 @@ public EventHandlers() // Methods private void OnPlayerJoin(PlayerJoinEvent ev) { - ev.Player.Broadcast(Configs.JoinMessageDuration,Configs.JoinBroadcast); - ev.Player.GiveTextHint(Configs.JoinTextHint, Configs.JoinMessageDuration); + ev.Player.Broadcast(SynapseConfigs.JoinMessageDuration, SynapseConfigs.JoinBroadcast); + ev.Player.GiveTextHint(SynapseConfigs.JoinTextHint, SynapseConfigs.JoinMessageDuration); } private static void OnDoorInteract(DoorInteractEvent ev) { - if (!Configs.RemoteKeyCard) return; + if (!SynapseConfigs.RemoteKeyCard) return; if (ev.Allow) return; if (!ev.Player.Items.Any()) return; diff --git a/Synapse/Events/Patches/FemurEnterPatch.cs b/Synapse/Events/Patches/FemurEnterPatch.cs index ab9e314..a129b9c 100644 --- a/Synapse/Events/Patches/FemurEnterPatch.cs +++ b/Synapse/Events/Patches/FemurEnterPatch.cs @@ -2,6 +2,7 @@ using Harmony; using Mirror; using Synapse.Api; +using Synapse.Configs; using UnityEngine; namespace Synapse.Events.Patches @@ -27,7 +28,7 @@ public static bool Prefix(CharacterClassManager __instance) if (component.CurClass == RoleType.Spectator || component.GodMode) continue; var allow = component.CurRole.team != Team.SCP; - var closeFemur = FemurBrokePeople + 1 >= Configs.RequiredForFemur; + var closeFemur = FemurBrokePeople + 1 >= SynapseConfigs.RequiredForFemur; var player = __instance.GetPlayer(); Events.InvokeFemurEnterEvent(player, ref allow, ref closeFemur); diff --git a/Synapse/Events/Patches/ServerNamePatch.cs b/Synapse/Events/Patches/ServerNamePatch.cs index 5fd3d6a..2721641 100644 --- a/Synapse/Events/Patches/ServerNamePatch.cs +++ b/Synapse/Events/Patches/ServerNamePatch.cs @@ -1,4 +1,5 @@ using Harmony; +using Synapse.Configs; namespace Synapse.Events.Patches { @@ -7,7 +8,7 @@ public static class ServerNamePatch { public static void Postfix() { - if (!Configs.Nametracking) return; + if (!SynapseConfigs.Nametracking) return; ServerConsole._serverName += $" SMSynapse-ModLoader {MainLoader.version}"; } diff --git a/Synapse/Events/Patches/SpeakPatch.cs b/Synapse/Events/Patches/SpeakPatch.cs index d1899b2..d259c5e 100644 --- a/Synapse/Events/Patches/SpeakPatch.cs +++ b/Synapse/Events/Patches/SpeakPatch.cs @@ -2,6 +2,7 @@ using Assets._Scripts.Dissonance; using Harmony; using Synapse.Api; +using Synapse.Configs; namespace Synapse.Events.Patches { @@ -19,7 +20,7 @@ public static bool Prefix(DissonanceUserSetup __instance, bool value) var scpchat = __instance.SCPChat; var spectator = __instance.SpectatorChat; - scp939 = Configs.Speaking_Scps.Contains((int)__instance.GetPlayer().Role); + scp939 = SynapseConfigs.Speaking_Scps.Contains((int)__instance.GetPlayer().Role); Events.InvokeSpeakEvent(__instance, ref intercom, ref radio, ref scp939, ref scpchat, ref spectator); diff --git a/Synapse/PluginManager.cs b/Synapse/PluginManager.cs index 88b998e..e286ce5 100644 --- a/Synapse/PluginManager.cs +++ b/Synapse/PluginManager.cs @@ -5,8 +5,9 @@ using System.Reflection; using MEC; using Synapse.Events.Patches; -using Synapse.Permissions; +using Synapse.Configs; using SynapseModLoader; +using Synapse.Api.Plugin; namespace Synapse { @@ -87,7 +88,7 @@ private static void LoadPlugins() private static void LoadSynapse() { - Configs.ReloadConfig(); + SynapseConfigs.ReloadConfig(); HarmonyPatch(); _eventHandler = new Events.EventHandlers(); @@ -147,8 +148,18 @@ private static void LoadPlugin(string pluginPath) if (!(plugin is Plugin p)) continue; + p.Details = Attribute.GetCustomAttribute(assembly, type) as PluginDetails; + if (p.Details == null) + p.Details = new PluginDetails() + { + Author = "?", + Description = "?", + Name = "?", + Version = "?", + }; + Plugins.Add(p); - Log.Info($"Successfully loaded {p.GetName}"); + Log.Info($"Successfully loaded {p.Details.Name}"); } } catch (Exception e) @@ -163,19 +174,19 @@ private static void OnEnable() try { plugin.Translation = new Translation {Plugin = plugin}; - plugin.OwnPluginFolder = Path.Combine(ServerPluginDirectory, plugin.GetName); + plugin.OwnPluginFolder = Path.Combine(ServerPluginDirectory, plugin.Details.Name); plugin.OnEnable(); } catch (Exception e) { - Log.Error($"Plugin {plugin.GetName} threw an exception while enabling {e}"); + Log.Error($"Plugin {plugin.Details.Name} threw an exception while enabling {e}"); } } internal static void OnConfigReload() { Plugin.Config = new YamlConfig(ServerConfigFile); - Configs.ReloadConfig(); + SynapseConfigs.ReloadConfig(); foreach (var plugin in Plugins) try @@ -184,7 +195,7 @@ internal static void OnConfigReload() } catch (Exception e) { - Log.Error($"Plugin {plugin.GetName} threw an exception while reloading {e}"); + Log.Error($"Plugin {plugin.Details.Name} threw an exception while reloading {e}"); } } diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 155cf47..2fbf42f 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -64,6 +64,7 @@ + @@ -90,8 +91,8 @@ - - + + @@ -146,8 +147,8 @@ - - + + From 64e506c18df125accec158cfc2747876bd6c15bc Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 16:33:36 +0200 Subject: [PATCH 31/46] Renamed PluginManager and removed unneccesary code from EventHandlers --- Synapse/Api/Plugin/Translation.cs | 2 +- Synapse/Configs/PermissionReader.cs | 2 +- Synapse/Events/EventHandlers.cs | 43 ++----------------- Synapse/MainLoader.cs | 14 +++--- Synapse/Synapse.csproj | 2 +- .../{PluginManager.cs => SynapseManager.cs} | 2 +- 6 files changed, 14 insertions(+), 51 deletions(-) rename Synapse/{PluginManager.cs => SynapseManager.cs} (99%) diff --git a/Synapse/Api/Plugin/Translation.cs b/Synapse/Api/Plugin/Translation.cs index 8b00739..1f44cad 100644 --- a/Synapse/Api/Plugin/Translation.cs +++ b/Synapse/Api/Plugin/Translation.cs @@ -14,7 +14,7 @@ public class Translation public void CreateTranslations(Dictionary translations) { - _translationPath = Path.Combine(PluginManager.ServerConfigDirectory, Plugin.Details.Name + "-translation.txt"); + _translationPath = Path.Combine(SynapseManager.ServerConfigDirectory, Plugin.Details.Name + "-translation.txt"); if (!File.Exists(_translationPath)) File.Create(_translationPath).Close(); var dictionary = new Dictionary(); diff --git a/Synapse/Configs/PermissionReader.cs b/Synapse/Configs/PermissionReader.cs index f08f1a3..352ac59 100644 --- a/Synapse/Configs/PermissionReader.cs +++ b/Synapse/Configs/PermissionReader.cs @@ -15,7 +15,7 @@ public static class PermissionReader private static Yml _permissionsConfig; private static readonly string PermissionPath = - Path.Combine(PluginManager.ServerConfigDirectory, "permissions.yml"); + Path.Combine(SynapseManager.ServerConfigDirectory, "permissions.yml"); // Methods internal static void Init() diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index 9af3075..29df7bf 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -12,20 +12,11 @@ namespace Synapse.Events // ReSharper disable once UnusedType.Global internal class EventHandlers { - // Variables - private bool _roundInProgress; - - // ReSharper disable once NotAccessedField.Local - private int _roundTime; - // Constructor public EventHandlers() { Events.SyncDataEvent += OnSyncData; Events.RemoteCommandEvent += OnRemoteCommand; - Events.RoundStartEvent += OnRoundStart; - Events.RoundEndEvent += OnRoundEnd; - Events.RoundRestartEvent += OnRoundRestart; Events.DoorInteractEvent += OnDoorInteract; Events.PlayerJoinEvent += OnPlayerJoin; } @@ -46,10 +37,9 @@ private static void OnDoorInteract(DoorInteractEvent ev) foreach (var item in ev.Player.Items) { var itemPerms = ev.Player.Inventory.GetItemByID(item.id).permissions; - var door = ev.Door; ev.Allow = itemPerms.Any(p => - door.backwardsCompatPermissions.TryGetValue(p, out var flag) && - door.PermissionLevels.HasPermission(flag)); + ev.Door.backwardsCompatPermissions.TryGetValue(p, out var flag) && + ev.Door.PermissionLevels.HasPermission(flag)); } } @@ -88,37 +78,10 @@ private static void OnRemoteCommand(RemoteCommandEvent ev) return; } - PluginManager.OnConfigReload(); + SynapseManager.OnConfigReload(); ev.Sender.RaMessage("Configs Reloaded!", true, RaCategory.ServerConfigs); return; } } - - private void OnRoundStart() - { - Timing.RunCoroutine(RoundTime()); - _roundInProgress = true; - } - - private void OnRoundEnd() - { - _roundInProgress = false; - } - - private void OnRoundRestart() - { - _roundInProgress = false; - Map.Rooms.Clear(); - } - - private IEnumerator RoundTime() - { - for (;;) - { - yield return Timing.WaitForSeconds(1f); - _roundTime++; - if (!_roundInProgress) break; - } - } } } \ No newline at end of file diff --git a/Synapse/MainLoader.cs b/Synapse/MainLoader.cs index 492f523..573f3d9 100644 --- a/Synapse/MainLoader.cs +++ b/Synapse/MainLoader.cs @@ -17,19 +17,19 @@ public static void LoaderExecutionCode() Log.Info("Checking Files"); - if (!Directory.Exists(PluginManager.MainConfigDirectory)) - Directory.CreateDirectory(PluginManager.MainConfigDirectory); + if (!Directory.Exists(SynapseManager.MainConfigDirectory)) + Directory.CreateDirectory(SynapseManager.MainConfigDirectory); - if (!Directory.Exists(PluginManager.MainPluginDirectory)) - Directory.CreateDirectory(PluginManager.MainPluginDirectory); + if (!Directory.Exists(SynapseManager.MainPluginDirectory)) + Directory.CreateDirectory(SynapseManager.MainPluginDirectory); - if (!Directory.Exists(PluginManager.DependenciesDirectory)) - Directory.CreateDirectory(PluginManager.DependenciesDirectory); + if (!Directory.Exists(SynapseManager.DependenciesDirectory)) + Directory.CreateDirectory(SynapseManager.DependenciesDirectory); CustomNetworkManager.Modded = true; try { - Timing.RunCoroutine(PluginManager.StartSynapse()); + Timing.RunCoroutine(SynapseManager.StartSynapse()); } catch { diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 2fbf42f..c2bbe1a 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -150,7 +150,7 @@ - + diff --git a/Synapse/PluginManager.cs b/Synapse/SynapseManager.cs similarity index 99% rename from Synapse/PluginManager.cs rename to Synapse/SynapseManager.cs index e286ce5..f5ec07e 100644 --- a/Synapse/PluginManager.cs +++ b/Synapse/SynapseManager.cs @@ -11,7 +11,7 @@ namespace Synapse { - public static class PluginManager + public static class SynapseManager { // Variables private static readonly List LoadedDependencies = new List(); From 6fc6c06f4a60f4662d3946aa235f6ca31bed073c Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 18:06:58 +0200 Subject: [PATCH 32/46] fixed mistake that throw a Error with every Plugin --- Synapse/SynapseManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Synapse/SynapseManager.cs b/Synapse/SynapseManager.cs index f5ec07e..0504a7f 100644 --- a/Synapse/SynapseManager.cs +++ b/Synapse/SynapseManager.cs @@ -148,7 +148,7 @@ private static void LoadPlugin(string pluginPath) if (!(plugin is Plugin p)) continue; - p.Details = Attribute.GetCustomAttribute(assembly, type) as PluginDetails; + p.Details = type.GetCustomAttribute(); if (p.Details == null) p.Details = new PluginDetails() { From 9f76c28c0bfd51227923ff980d938af1f0e65f6e Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 18:51:33 +0200 Subject: [PATCH 33/46] changed Info message --- Synapse/SynapseManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Synapse/SynapseManager.cs b/Synapse/SynapseManager.cs index 0504a7f..f3445e4 100644 --- a/Synapse/SynapseManager.cs +++ b/Synapse/SynapseManager.cs @@ -119,7 +119,7 @@ private static void LoadDependencies() var assembly = Assembly.LoadFrom(dll); LoadedDependencies.Add(assembly); - Log.Info($"Successfully loaded {dll}"); + Log.Info($"Successfully loaded {assembly.GetName().Name}"); } } From 5754a78589b59b735ce75229f43b40030468b821 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 18:55:27 +0200 Subject: [PATCH 34/46] added GetAllPlayers(this RoleType[] roles) --- Synapse/Api/Extensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Synapse/Api/Extensions.cs b/Synapse/Api/Extensions.cs index e94f0c3..5b6f5d8 100644 --- a/Synapse/Api/Extensions.cs +++ b/Synapse/Api/Extensions.cs @@ -58,6 +58,9 @@ public static void RaMessage(this CommandSender sender, string message, bool suc /// public static IEnumerable GetAllPlayers(this RoleType role) => Player.GetAllPlayers().Where(x => x.Role == role); + + public static IEnumerable GetAllPlayers(this RoleType[] roles) => Player.GetAllPlayers().Where(x => roles.Any(r => x.Role == r)); + /// /// Gives all players on the server in this Team /// From 1d33c3fd4cbd1586db69d93ac136f856eb416ba4 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 18:58:05 +0200 Subject: [PATCH 35/46] added GetAllPlayers(this Team[] roles) --- Synapse/Api/Extensions.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Synapse/Api/Extensions.cs b/Synapse/Api/Extensions.cs index 5b6f5d8..58c4bbf 100644 --- a/Synapse/Api/Extensions.cs +++ b/Synapse/Api/Extensions.cs @@ -61,6 +61,8 @@ public static void RaMessage(this CommandSender sender, string message, bool suc public static IEnumerable GetAllPlayers(this RoleType[] roles) => Player.GetAllPlayers().Where(x => roles.Any(r => x.Role == r)); + public static IEnumerable GetAllPlayers(this Team[] roles) => Player.GetAllPlayers().Where(x => roles.Any(t => x.Team == t)); + /// /// Gives all players on the server in this Team /// From 081c7c303e013bfbbc3fb63c3d3667726699d383 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 18:59:04 +0200 Subject: [PATCH 36/46] fixed it to GetAllPlayers(this Team[] teams) --- Synapse/Api/Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Synapse/Api/Extensions.cs b/Synapse/Api/Extensions.cs index 58c4bbf..64309ba 100644 --- a/Synapse/Api/Extensions.cs +++ b/Synapse/Api/Extensions.cs @@ -61,7 +61,7 @@ public static void RaMessage(this CommandSender sender, string message, bool suc public static IEnumerable GetAllPlayers(this RoleType[] roles) => Player.GetAllPlayers().Where(x => roles.Any(r => x.Role == r)); - public static IEnumerable GetAllPlayers(this Team[] roles) => Player.GetAllPlayers().Where(x => roles.Any(t => x.Team == t)); + public static IEnumerable GetAllPlayers(this Team[] teams) => Player.GetAllPlayers().Where(x => teams.Any(t => x.Team == t)); /// /// Gives all players on the server in this Team From 4cd59c623139e96d5d2770337b80eadf27824563 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 18 Jul 2020 22:18:05 +0200 Subject: [PATCH 37/46] . --- Synapse/SynapseManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Synapse/SynapseManager.cs b/Synapse/SynapseManager.cs index f3445e4..82a62e0 100644 --- a/Synapse/SynapseManager.cs +++ b/Synapse/SynapseManager.cs @@ -106,7 +106,7 @@ private static void LoadSynapse() private static void LoadDependencies() - { + { Log.Info("Loading Dependencies..."); var depends = Directory.GetFiles(DependenciesDirectory); From 3dad45e5cadd337d0cbaa5286827cb00f422c262 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 20 Jul 2020 08:16:56 +0200 Subject: [PATCH 38/46] added SynapsePatch to PluginDetails --- Synapse/Api/Plugin/PluginDetails.cs | 1 + Synapse/MainLoader.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Synapse/Api/Plugin/PluginDetails.cs b/Synapse/Api/Plugin/PluginDetails.cs index dcc15b1..677e0b5 100644 --- a/Synapse/Api/Plugin/PluginDetails.cs +++ b/Synapse/Api/Plugin/PluginDetails.cs @@ -6,6 +6,7 @@ public class PluginDetails : Attribute { public int SynapseMajor; public int SynapseMinor; + public int SynapsePatch; public string Name; public string Author; public string Description; diff --git a/Synapse/MainLoader.cs b/Synapse/MainLoader.cs index 573f3d9..2e346c2 100644 --- a/Synapse/MainLoader.cs +++ b/Synapse/MainLoader.cs @@ -7,7 +7,7 @@ namespace Synapse [SuppressMessage("ReSharper", "UnusedType.Global")] public class MainLoader { - public const string version = "v.1.4-Beta"; + public const string version = "v.0.5.0-Beta"; /// This method is called by the Scp Server in the assembly-csharp // ReSharper disable once UnusedMember.Global public static void LoaderExecutionCode() From 5294f0a97912b2a6d48c349678541e1e1552a52a Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 20 Jul 2020 08:18:37 +0200 Subject: [PATCH 39/46] update to ptb 23 --- Synapse/Events/Patches/DoorInteractPatch.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Synapse/Events/Patches/DoorInteractPatch.cs b/Synapse/Events/Patches/DoorInteractPatch.cs index d408c13..9cf892f 100644 --- a/Synapse/Events/Patches/DoorInteractPatch.cs +++ b/Synapse/Events/Patches/DoorInteractPatch.cs @@ -18,9 +18,9 @@ public static bool Prefix(PlayerInteract __instance, GameObject doorId) if (!__instance._playerInteractRateLimit.CanExecute() || (__instance._hc.CufferId > 0 && !PlayerInteract.CanDisarmedInteract) || doorId == null || __instance._ccm.CurClass == RoleType.None || __instance._ccm.CurClass == RoleType.Spectator || - !doorId.TryGetComponent(out door) || !((door.buttons.Count == 0) + !doorId.TryGetComponent(out door) || !((door.Buttons.Count == 0) ? __instance.ChckDis(doorId.transform.position) - : door.buttons.Any(item => __instance.ChckDis(item.transform.position)))) return false; + : door.Buttons.Any(item => __instance.ChckDis(item.button.transform.position)))) return false; __instance.OnInteract(); From b88e7abe8c19c97cc6727e6516591eef503f7d26 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 20 Jul 2020 15:51:49 +0200 Subject: [PATCH 40/46] fixed Rooms bug --- Synapse/Api/Map.cs | 7 +------ Synapse/MainLoader.cs | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index a201a2c..6f15972 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -23,8 +23,6 @@ public static class Map private static Broadcast BroadcastComponent => Player.Host.GetComponent(); - private static List _rooms = new List(); - /// /// Gives you a list of all rooms /// @@ -32,12 +30,9 @@ public static List Rooms { get { - if (_rooms == null || _rooms.Count == 0) - _rooms = Object.FindObjectsOfType().Where(transform => transform.CompareTag("Room")) + return Object.FindObjectsOfType().Where(transform => transform.CompareTag("Room")) .Select(obj => new Room {Name = obj.name, Position = obj.position, Transform = obj.transform}) .ToList(); - - return _rooms; } } diff --git a/Synapse/MainLoader.cs b/Synapse/MainLoader.cs index 2e346c2..acba2d3 100644 --- a/Synapse/MainLoader.cs +++ b/Synapse/MainLoader.cs @@ -7,7 +7,7 @@ namespace Synapse [SuppressMessage("ReSharper", "UnusedType.Global")] public class MainLoader { - public const string version = "v.0.5.0-Beta"; + public const string version = "v.0.4.2-Beta"; /// This method is called by the Scp Server in the assembly-csharp // ReSharper disable once UnusedMember.Global public static void LoaderExecutionCode() From f550fe2aee40fed07a8068e9586663431118fc0f Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 21 Jul 2020 09:37:21 +0200 Subject: [PATCH 41/46] Rework of SynapseManager and added Synapse.Version --- Synapse/Api/Extensions.cs | 5 + Synapse/{ => Api}/Log.cs | 0 Synapse/Api/Map.cs | 2 +- Synapse/Api/Player.cs | 2 +- Synapse/Api/Plugin/Translation.cs | 2 +- Synapse/Api/Room.cs | 11 +- Synapse/Config/ConfigManager.cs | 30 ++ .../{Configs => Config}/PermissionReader.cs | 11 +- Synapse/{Configs => Config}/SynapseConfigs.cs | 2 +- Synapse/Events/EventHandlers.cs | 8 +- Synapse/Events/Patches/FemurEnterPatch.cs | 2 +- Synapse/Events/Patches/PlayerBanPatch.cs | 2 +- Synapse/Events/Patches/ServerNamePatch.cs | 4 +- Synapse/Events/Patches/SpeakPatch.cs | 2 +- Synapse/MainLoader.cs | 40 --- Synapse/Synapse.cs | 269 ++++++++++++++++++ Synapse/Synapse.csproj | 10 +- Synapse/SynapseManager.cs | 215 -------------- 18 files changed, 335 insertions(+), 282 deletions(-) rename Synapse/{ => Api}/Log.cs (100%) create mode 100644 Synapse/Config/ConfigManager.cs rename Synapse/{Configs => Config}/PermissionReader.cs (91%) rename Synapse/{Configs => Config}/SynapseConfigs.cs (97%) delete mode 100644 Synapse/MainLoader.cs create mode 100644 Synapse/Synapse.cs delete mode 100644 Synapse/SynapseManager.cs diff --git a/Synapse/Api/Extensions.cs b/Synapse/Api/Extensions.cs index 64309ba..b7d0fdd 100644 --- a/Synapse/Api/Extensions.cs +++ b/Synapse/Api/Extensions.cs @@ -5,6 +5,7 @@ using System.Reflection; using Mirror; using Synapse.Api.Enums; +using Synapse.Api.Plugin; using UnityEngine; namespace Synapse.Api @@ -84,5 +85,9 @@ public static void RaMessage(this CommandSender sender, string message, bool suc /// Gives you the player object /// public static Player GetPlayer(this GameObject gameObject) => gameObject.GetComponent(); + + public static string GetVersionString(this PluginDetails details) => $"{details.SynapseMajor}.{details.SynapseMinor}.{details.SynapsePatch}"; + + public static int GetVersionNumber(this PluginDetails details) => details.SynapseMajor * 100 + details.SynapseMinor * 10 + details.SynapsePatch; } } \ No newline at end of file diff --git a/Synapse/Log.cs b/Synapse/Api/Log.cs similarity index 100% rename from Synapse/Log.cs rename to Synapse/Api/Log.cs diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 6f15972..0df934a 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -1,4 +1,4 @@ -using Synapse.Configs; +using Synapse.Config; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index fc24729..d0af7be 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -7,7 +7,7 @@ using RemoteAdmin; using Searching; using Synapse.Api.Enums; -using Synapse.Configs; +using Synapse.Config; using UnityEngine; namespace Synapse.Api diff --git a/Synapse/Api/Plugin/Translation.cs b/Synapse/Api/Plugin/Translation.cs index 1f44cad..3068f73 100644 --- a/Synapse/Api/Plugin/Translation.cs +++ b/Synapse/Api/Plugin/Translation.cs @@ -14,7 +14,7 @@ public class Translation public void CreateTranslations(Dictionary translations) { - _translationPath = Path.Combine(SynapseManager.ServerConfigDirectory, Plugin.Details.Name + "-translation.txt"); + _translationPath = Path.Combine(Files.ServerConfigDirectory, Plugin.Details.Name + "-translation.txt"); if (!File.Exists(_translationPath)) File.Create(_translationPath).Close(); var dictionary = new Dictionary(); diff --git a/Synapse/Api/Room.cs b/Synapse/Api/Room.cs index 0fcec88..9cc502e 100644 --- a/Synapse/Api/Room.cs +++ b/Synapse/Api/Room.cs @@ -5,11 +5,20 @@ namespace Synapse.Api { public class Room { + private string name; private ZoneType _zone = ZoneType.Unspecified; /// /// The name of the room /// - public string Name { get; set; } + public string Name + { + get => name; + set + { + if (value == "Root_*&*Outside Cams") name = "Outside"; + else name = value; + } + } // ReSharper disable once UnusedAutoPropertyAccessor.Global /// diff --git a/Synapse/Config/ConfigManager.cs b/Synapse/Config/ConfigManager.cs new file mode 100644 index 0000000..f60e89e --- /dev/null +++ b/Synapse/Config/ConfigManager.cs @@ -0,0 +1,30 @@ +using System; +using Synapse.Api.Plugin; + +namespace Synapse.Config +{ + public static class ConfigManager + { + internal static void InitializeConfigs() + { + Plugin.Config = new YamlConfig(Files.ServerConfigFile); + SynapseConfigs.ReloadConfig(); + } + + internal static void ReloadAllConfigs() + { + SynapseConfigs.ReloadConfig(); + Plugin.Config = new YamlConfig(Files.ServerConfigFile); + + foreach (var plugin in Synapse.plugins) + try + { + plugin.InvokeConfigReloadEvent(); + } + catch (Exception e) + { + Log.Error($"Plugin {plugin.Details.Name} threw an exception while reloading {e}"); + } + } + } +} diff --git a/Synapse/Configs/PermissionReader.cs b/Synapse/Config/PermissionReader.cs similarity index 91% rename from Synapse/Configs/PermissionReader.cs rename to Synapse/Config/PermissionReader.cs index 352ac59..cde22f2 100644 --- a/Synapse/Configs/PermissionReader.cs +++ b/Synapse/Config/PermissionReader.cs @@ -7,28 +7,25 @@ // ReSharper disable All -namespace Synapse.Configs +namespace Synapse.Config { public static class PermissionReader { // Variables private static Yml _permissionsConfig; - private static readonly string PermissionPath = - Path.Combine(SynapseManager.ServerConfigDirectory, "permissions.yml"); - // Methods internal static void Init() { - if (!File.Exists(PermissionPath)) - File.WriteAllText(PermissionPath, "groups:\n user:\n default: true\n permissions:\n - plugin.permission\n northwood:\n northwood: true\n permissions:\n - plugin.permission\n owner:\n permissions:\n - .*"); + if (!File.Exists(Files.PermissionFile)) + File.WriteAllText(Files.PermissionFile, "groups:\n user:\n default: true\n permissions:\n - plugin.permission\n northwood:\n northwood: true\n permissions:\n - plugin.permission\n owner:\n permissions:\n - .*"); ReloadPermission(); } internal static void ReloadPermission() { - var yml = File.ReadAllText(PermissionPath); + var yml = File.ReadAllText(Files.PermissionFile); var deserializer = new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance) .Build(); diff --git a/Synapse/Configs/SynapseConfigs.cs b/Synapse/Config/SynapseConfigs.cs similarity index 97% rename from Synapse/Configs/SynapseConfigs.cs rename to Synapse/Config/SynapseConfigs.cs index 96d6dcc..f2a3f12 100644 --- a/Synapse/Configs/SynapseConfigs.cs +++ b/Synapse/Config/SynapseConfigs.cs @@ -1,7 +1,7 @@ using Synapse.Api.Plugin; using System.Collections.Generic; -namespace Synapse.Configs +namespace Synapse.Config { internal static class SynapseConfigs { diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index 29df7bf..6b54387 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -1,10 +1,8 @@ -using System.Collections.Generic; -using System.Linq; -using MEC; +using System.Linq; using Synapse.Api; using Synapse.Api.Enums; using Synapse.Events.Classes; -using Synapse.Configs; +using Synapse.Config; using UnityEngine; namespace Synapse.Events @@ -78,7 +76,7 @@ private static void OnRemoteCommand(RemoteCommandEvent ev) return; } - SynapseManager.OnConfigReload(); + ConfigManager.ReloadAllConfigs(); ev.Sender.RaMessage("Configs Reloaded!", true, RaCategory.ServerConfigs); return; } diff --git a/Synapse/Events/Patches/FemurEnterPatch.cs b/Synapse/Events/Patches/FemurEnterPatch.cs index a129b9c..393cf23 100644 --- a/Synapse/Events/Patches/FemurEnterPatch.cs +++ b/Synapse/Events/Patches/FemurEnterPatch.cs @@ -2,7 +2,7 @@ using Harmony; using Mirror; using Synapse.Api; -using Synapse.Configs; +using Synapse.Config; using UnityEngine; namespace Synapse.Events.Patches diff --git a/Synapse/Events/Patches/PlayerBanPatch.cs b/Synapse/Events/Patches/PlayerBanPatch.cs index 3bc5b1e..e97cd73 100644 --- a/Synapse/Events/Patches/PlayerBanPatch.cs +++ b/Synapse/Events/Patches/PlayerBanPatch.cs @@ -1,7 +1,7 @@ using System; +using Synapse.Api; using GameCore; using Harmony; -using Synapse.Api; using UnityEngine; namespace Synapse.Events.Patches diff --git a/Synapse/Events/Patches/ServerNamePatch.cs b/Synapse/Events/Patches/ServerNamePatch.cs index 2721641..f22eefb 100644 --- a/Synapse/Events/Patches/ServerNamePatch.cs +++ b/Synapse/Events/Patches/ServerNamePatch.cs @@ -1,5 +1,5 @@ using Harmony; -using Synapse.Configs; +using Synapse.Config; namespace Synapse.Events.Patches { @@ -10,7 +10,7 @@ public static void Postfix() { if (!SynapseConfigs.Nametracking) return; - ServerConsole._serverName += $" SMSynapse-ModLoader {MainLoader.version}"; + ServerConsole._serverName += $" SMSynapse-ModLoader {Synapse.Version}"; } } } \ No newline at end of file diff --git a/Synapse/Events/Patches/SpeakPatch.cs b/Synapse/Events/Patches/SpeakPatch.cs index d259c5e..a91f746 100644 --- a/Synapse/Events/Patches/SpeakPatch.cs +++ b/Synapse/Events/Patches/SpeakPatch.cs @@ -2,7 +2,7 @@ using Assets._Scripts.Dissonance; using Harmony; using Synapse.Api; -using Synapse.Configs; +using Synapse.Config; namespace Synapse.Events.Patches { diff --git a/Synapse/MainLoader.cs b/Synapse/MainLoader.cs deleted file mode 100644 index acba2d3..0000000 --- a/Synapse/MainLoader.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using System.IO; -using MEC; - -namespace Synapse -{ - [SuppressMessage("ReSharper", "UnusedType.Global")] - public class MainLoader - { - public const string version = "v.0.4.2-Beta"; - /// This method is called by the Scp Server in the assembly-csharp - // ReSharper disable once UnusedMember.Global - public static void LoaderExecutionCode() - { - Log.Info($"Now starting Synapse Version {version}"); - Log.Info("Created by Dimenzio and SirRoob"); - - Log.Info("Checking Files"); - - if (!Directory.Exists(SynapseManager.MainConfigDirectory)) - Directory.CreateDirectory(SynapseManager.MainConfigDirectory); - - if (!Directory.Exists(SynapseManager.MainPluginDirectory)) - Directory.CreateDirectory(SynapseManager.MainPluginDirectory); - - if (!Directory.Exists(SynapseManager.DependenciesDirectory)) - Directory.CreateDirectory(SynapseManager.DependenciesDirectory); - - CustomNetworkManager.Modded = true; - try - { - Timing.RunCoroutine(SynapseManager.StartSynapse()); - } - catch - { - Log.Error("PluginManager failed to Start restart the Server"); - } - } - } -} \ No newline at end of file diff --git a/Synapse/Synapse.cs b/Synapse/Synapse.cs new file mode 100644 index 0000000..9bfafe3 --- /dev/null +++ b/Synapse/Synapse.cs @@ -0,0 +1,269 @@ +using MEC; +using Synapse.Api; +using Synapse.Api.Plugin; +using Synapse.Config; +using Synapse.Events; +using Synapse.Events.Patches; +using SynapseModLoader; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace Synapse +{ + public static class Synapse + { + #region Version + private const int MajorVersion = 0; + private const int MinorVerion = 5; + private const int Patch = 0; + + public static int VersionNumber => MajorVersion * 100 + MinorVerion * 10 + Patch; + public static string Version => $"{MajorVersion}.{MinorVerion}.{Patch}"; + #endregion + + private static bool isLoaded = false; + private static readonly List LoadedDependencies = new List(); + internal static readonly List plugins = new List(); //TODO: Rework Config System and make this private + private static EventHandlers _eventHandler; + public static List Plugins => plugins.Select(obj => obj.Details).ToList(); + + + public static void LoaderExecutionCode() + { + if (isLoaded) return; + + Log.Info($"Now starting Synapse Version {Synapse.Version}"); + Log.Info("Created by Dimenzio and SirRoob"); + + CustomNetworkManager.Modded = true; + + try + { + Timing.CallDelayed(0.5f, () => Synapse.Start()); + isLoaded = true; + } + catch + { + Log.Error("Synapse failed to Start.Restart the Server"); + } + } + internal static void Start() + { + LoadDependencies(); + + foreach (var plugin in Directory.GetFiles(Files.ServerPluginDirectory)) + { + if (plugin.EndsWith("Synapse.dll")) continue; + + if (plugin.EndsWith(".dll")) LoadPlugin(plugin); + } + + + ConfigManager.InitializeConfigs(); + HarmonyPatch(); + ServerConsole.ReloadServerName(); + _eventHandler = new Events.EventHandlers(); + try + { + PermissionReader.Init(); + } + catch (Exception e) + { + Log.Error($"Your Permission in invalid: {e}"); + } + + OnEnable(); + } + + + #region Methods to do everything what Synapse needs + private static void LoadDependencies() + { + Log.Info("Loading Dependencies..."); + var depends = Directory.GetFiles(Files.DependenciesDirectory); + + foreach (var dll in depends) + { + if (!dll.EndsWith(".dll")) continue; + + if (LoadedDependencies.Any(x => x.Location == dll)) + return; + + var assembly = Assembly.LoadFrom(dll); + LoadedDependencies.Add(assembly); + Log.Info($"Successfully loaded {assembly.GetName().Name}"); + } + } + private static void LoadPlugin(string pluginPath) + { + Log.Info($"Loading {pluginPath}"); + try + { + var file = ModLoader.ReadFile(pluginPath); + var assembly = Assembly.Load(file); + + foreach (var type in assembly.GetTypes()) + { + if (type.IsAbstract) continue; + + if (type.FullName == null) continue; + + if (!typeof(Plugin).IsAssignableFrom(type)) continue; + + var plugin = Activator.CreateInstance(type); + + if (!(plugin is Plugin p)) continue; + + p.Details = type.GetCustomAttribute(); + if (p.Details == null) + p.Details = new PluginDetails() + { + Author = "Unknown", + Description = "No Description", + Name = assembly.GetName().Name, + Version = assembly.ImageRuntimeVersion, + SynapseMajor = MajorVersion, + SynapseMinor = MinorVerion, + SynapsePatch = Patch + }; + + plugins.Add(p); + if (p.Details.GetVersionNumber() == VersionNumber) Log.Info($"Successfully loaded {p.Details.Name}"); + + else if (p.Details.GetVersionNumber() > VersionNumber) Log.Warn($"The Plugin {p.Details.Name} is for the newer Synapse version {p.Details.GetVersionString()} but was succesfully loaded(bugs can occure)"); + + else Log.Warn($"The Plugin {p.Details.Name} is for the older Synapse version {p.Details.GetVersionString()} but was succesfully loaded(bugs can occure)"); + } + } + catch (Exception e) + { + Log.Error($"Error while initializing {pluginPath}: {e}"); + } + } + private static void HarmonyPatch() + { + try + { + var patchHandler = new PatchHandler(); + patchHandler.PatchMethods(); + } + catch (Exception e) + { + Log.Error($"PatchError: {e}"); + } + } + private static void OnEnable() + { + foreach (var plugin in plugins) + try + { + plugin.Translation = new Translation { Plugin = plugin }; + plugin.OwnPluginFolder = Path.Combine(Files.ServerPluginDirectory, plugin.Details.Name); + plugin.OnEnable(); + } + catch (Exception e) + { + Log.Error($"Plugin {plugin.Details.Name} threw an exception while enabling {e}"); + } + } + #endregion + } + + internal static class Files + { + //Synapse Directory + private static string StartupFile => Assembly.GetAssembly(typeof(ReferenceHub)).Location.Replace($"SCPSL_Data{Path.DirectorySeparatorChar}Managed{Path.DirectorySeparatorChar}Assembly-CSharp.dll", "SynapseStart-config.yml"); + internal static string SynapseDirectory => new YamlConfig(StartupFile).GetString("synapse_installation", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Synapse")); + + //Directory-Structure + internal static string DependenciesDirectory + { + get + { + var path = Path.Combine(SynapseDirectory, "dependencies"); + + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + return path; + } + } + internal static string MainPluginDirectory + { + get + { + var path = Path.Combine(SynapseDirectory, "Plugins"); + + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + return path; + } + } + internal static string MainConfigDirectory + { + get + { + var path = Path.Combine(SynapseDirectory, "ServerConfigs"); + + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + return path; + } + } + internal static string ServerPluginDirectory + { + get + { + var path = Path.Combine(MainPluginDirectory, $"Server-{ServerStatic.ServerPort}"); + + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + return path; + } + } + internal static string ServerConfigDirectory + { + get + { + var path = Path.Combine(MainConfigDirectory, $"Server-{ServerStatic.ServerPort}"); + + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + return path; + } + } + + //Files + internal static string ServerConfigFile + { + get + { + var path = Path.Combine(ServerConfigDirectory, "server-config.yml"); + + if (!File.Exists(path)) + File.Create(path).Close(); + + return path; + } + } + internal static string PermissionFile + { + get + { + var path = Path.Combine(Files.ServerConfigDirectory, "permissions.yml"); + + if (!File.Exists(path)) + File.Create(path).Close(); + + return path; + } + } + } +} diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index c2bbe1a..bb77340 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -77,6 +77,8 @@ + + @@ -92,7 +94,7 @@ - + @@ -147,11 +149,9 @@ - + - - - + diff --git a/Synapse/SynapseManager.cs b/Synapse/SynapseManager.cs deleted file mode 100644 index 82a62e0..0000000 --- a/Synapse/SynapseManager.cs +++ /dev/null @@ -1,215 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using MEC; -using Synapse.Events.Patches; -using Synapse.Configs; -using SynapseModLoader; -using Synapse.Api.Plugin; - -namespace Synapse -{ - public static class SynapseManager - { - // Variables - private static readonly List LoadedDependencies = new List(); - private static readonly List Plugins = new List(); - - private static string StartupFile { get; } = Assembly.GetAssembly(typeof(ReferenceHub)).Location.Replace($"SCPSL_Data{Path.DirectorySeparatorChar}Managed{Path.DirectorySeparatorChar}Assembly-CSharp.dll", "SynapseStart-config.yml"); - private static string SynapseDirectory - { - get - { - var Config = new YamlConfig(StartupFile); - return Config.GetString("synapse_installation", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Synapse")); - } - } - - internal static string MainPluginDirectory { get; } = Path.Combine(SynapseDirectory, "Plugins"); - internal static string DependenciesDirectory { get; } = Path.Combine(SynapseDirectory, "dependencies"); - internal static string MainConfigDirectory { get; } = Path.Combine(SynapseDirectory, "ServerConfigs"); - private static string ServerPluginDirectory { get; set; } - internal static string ServerConfigDirectory { get; private set; } - private static string ServerConfigFile { get; set; } - - // ReSharper disable once NotAccessedField.Local - private static Events.EventHandlers _eventHandler; - - // Methods - internal static IEnumerator StartSynapse() - { - yield return Timing.WaitForSeconds(0.5f); - try - { - Files(); - - LoadPlugins(); - - LoadSynapse(); - } - catch (Exception e) - { - Log.Error($"Synapse could not Start : {e}"); - } - } - - private static void Files() - { - ServerPluginDirectory = Path.Combine(MainPluginDirectory, $"Server-{ServerStatic.ServerPort}"); - if (!Directory.Exists(ServerPluginDirectory)) - Directory.CreateDirectory(ServerPluginDirectory); - - ServerConfigDirectory = Path.Combine(MainConfigDirectory, $"Server-{ServerStatic.ServerPort}"); - if (!Directory.Exists(ServerConfigDirectory)) - Directory.CreateDirectory(ServerConfigDirectory); - - ServerConfigFile = Path.Combine(ServerConfigDirectory, "server-config.yml"); - if (!File.Exists(ServerConfigFile)) - File.Create(ServerConfigFile).Close(); - } - - private static void LoadPlugins() - { - LoadDependencies(); - - var plugins = Directory.GetFiles(ServerPluginDirectory); - - foreach (var plugin in plugins) - { - if (plugin.EndsWith("Synapse.dll")) continue; - - if (plugin.EndsWith(".dll")) LoadPlugin(plugin); - } - Plugin.Config = new YamlConfig(ServerConfigFile); - OnEnable(); - } - - private static void LoadSynapse() - { - SynapseConfigs.ReloadConfig(); - HarmonyPatch(); - _eventHandler = new Events.EventHandlers(); - - ServerConsole.ReloadServerName(); - - try - { - PermissionReader.Init(); - } - catch (Exception e) - { - Log.Error($"Your Permission in invalid: {e}"); - } - } - - - private static void LoadDependencies() - { - Log.Info("Loading Dependencies..."); - var depends = Directory.GetFiles(DependenciesDirectory); - - foreach (var dll in depends) - { - if (!dll.EndsWith(".dll")) continue; - - if (IsLoaded(dll)) - return; - - var assembly = Assembly.LoadFrom(dll); - LoadedDependencies.Add(assembly); - Log.Info($"Successfully loaded {assembly.GetName().Name}"); - } - } - - private static bool IsLoaded(string path) - { - return LoadedDependencies.Any(assembly => assembly.Location == path); - } - - private static void LoadPlugin(string pluginPath) - { - Log.Info($"Loading {pluginPath}"); - try - { - var file = ModLoader.ReadFile(pluginPath); - var assembly = Assembly.Load(file); - - foreach (var type in assembly.GetTypes()) - { - if (type.IsAbstract) continue; - - if (type.FullName == null) continue; - - if (!typeof(Plugin).IsAssignableFrom(type)) continue; - - var plugin = Activator.CreateInstance(type); - - if (!(plugin is Plugin p)) continue; - - p.Details = type.GetCustomAttribute(); - if (p.Details == null) - p.Details = new PluginDetails() - { - Author = "?", - Description = "?", - Name = "?", - Version = "?", - }; - - Plugins.Add(p); - Log.Info($"Successfully loaded {p.Details.Name}"); - } - } - catch (Exception e) - { - Log.Error($"Error while initializing {pluginPath}: {e}"); - } - } - - private static void OnEnable() - { - foreach (var plugin in Plugins) - try - { - plugin.Translation = new Translation {Plugin = plugin}; - plugin.OwnPluginFolder = Path.Combine(ServerPluginDirectory, plugin.Details.Name); - plugin.OnEnable(); - } - catch (Exception e) - { - Log.Error($"Plugin {plugin.Details.Name} threw an exception while enabling {e}"); - } - } - - internal static void OnConfigReload() - { - Plugin.Config = new YamlConfig(ServerConfigFile); - SynapseConfigs.ReloadConfig(); - - foreach (var plugin in Plugins) - try - { - plugin.InvokeConfigReloadEvent(); - } - catch (Exception e) - { - Log.Error($"Plugin {plugin.Details.Name} threw an exception while reloading {e}"); - } - } - - private static void HarmonyPatch() - { - try - { - var patchHandler = new PatchHandler(); - patchHandler.PatchMethods(); - } - catch (Exception e) - { - Log.Error($"PatchError: {e}"); - } - } - } -} \ No newline at end of file From 6902fc2fb9a7e81cf38873f64066ad8f69693436 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 21 Jul 2020 09:52:02 +0200 Subject: [PATCH 42/46] changed Player.CurRoom to Room --- Synapse/Api/Player.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index d0af7be..139f187 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -240,7 +240,7 @@ public Team Side /// /// The Room where the player currently is /// - public Room CurRoom + public Room Room { get { From ee3ed710988a39fe4377741d833bf58ec10ad844 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 21 Jul 2020 10:11:13 +0200 Subject: [PATCH 43/46] fixed Room Surface bug that in Player.Room the Surface is a Room and in Map.Rooms it is not --- Synapse/Api/Map.cs | 2 +- Synapse/Api/Player.cs | 2 +- Synapse/Api/Room.cs | 11 +---------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 0df934a..fb561bd 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -30,7 +30,7 @@ public static List Rooms { get { - return Object.FindObjectsOfType().Where(transform => transform.CompareTag("Room")) + return Object.FindObjectsOfType().Where(transform => transform.CompareTag("Room") || transform.name == "Root_*&*Outside Cams") .Select(obj => new Room {Name = obj.name, Position = obj.position, Transform = obj.transform}) .ToList(); } diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 139f187..7a4b35a 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -247,7 +247,7 @@ public Room Room var playerPos = Position; var end = playerPos - new Vector3(0f, 10f, 0f); var flag = Physics.Linecast(playerPos, end, out var rayCastHit, -84058629); - + if (!flag || rayCastHit.transform == null) return null; diff --git a/Synapse/Api/Room.cs b/Synapse/Api/Room.cs index 9cc502e..0fcec88 100644 --- a/Synapse/Api/Room.cs +++ b/Synapse/Api/Room.cs @@ -5,20 +5,11 @@ namespace Synapse.Api { public class Room { - private string name; private ZoneType _zone = ZoneType.Unspecified; /// /// The name of the room /// - public string Name - { - get => name; - set - { - if (value == "Root_*&*Outside Cams") name = "Outside"; - else name = value; - } - } + public string Name { get; set; } // ReSharper disable once UnusedAutoPropertyAccessor.Global /// From 2092494fd4e4383b4495176b3758b3a57c2d965f Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 21 Jul 2020 12:24:49 +0200 Subject: [PATCH 44/46] permission bug fixed --- Synapse/Config/PermissionReader.cs | 3 --- Synapse/Synapse.cs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Synapse/Config/PermissionReader.cs b/Synapse/Config/PermissionReader.cs index cde22f2..05ba04d 100644 --- a/Synapse/Config/PermissionReader.cs +++ b/Synapse/Config/PermissionReader.cs @@ -17,9 +17,6 @@ public static class PermissionReader // Methods internal static void Init() { - if (!File.Exists(Files.PermissionFile)) - File.WriteAllText(Files.PermissionFile, "groups:\n user:\n default: true\n permissions:\n - plugin.permission\n northwood:\n northwood: true\n permissions:\n - plugin.permission\n owner:\n permissions:\n - .*"); - ReloadPermission(); } diff --git a/Synapse/Synapse.cs b/Synapse/Synapse.cs index 9bfafe3..5068500 100644 --- a/Synapse/Synapse.cs +++ b/Synapse/Synapse.cs @@ -260,7 +260,7 @@ internal static string PermissionFile var path = Path.Combine(Files.ServerConfigDirectory, "permissions.yml"); if (!File.Exists(path)) - File.Create(path).Close(); + File.WriteAllText(path, "groups:\n user:\n default: true\n permissions:\n - plugin.permission\n northwood:\n northwood: true\n permissions:\n - plugin.permission\n owner:\n permissions:\n - .*"); return path; } From 25ff3d02ea925f2ff7138a0198912d31a854d9fa Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Thu, 23 Jul 2020 15:20:32 +0200 Subject: [PATCH 45/46] fixed bug that plugins named PluginNameSynapse.dll doesnt load --- Synapse/Synapse.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Synapse/Synapse.cs b/Synapse/Synapse.cs index 5068500..493cc71 100644 --- a/Synapse/Synapse.cs +++ b/Synapse/Synapse.cs @@ -56,7 +56,7 @@ internal static void Start() foreach (var plugin in Directory.GetFiles(Files.ServerPluginDirectory)) { - if (plugin.EndsWith("Synapse.dll")) continue; + if (plugin == "Synapse.dll") continue; if (plugin.EndsWith(".dll")) LoadPlugin(plugin); } From f3772de93a99279619177063211a4b7d6abfb89d Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Fri, 24 Jul 2020 18:48:20 +0200 Subject: [PATCH 46/46] update to v1.0.0 --- Synapse/Synapse.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Synapse/Synapse.cs b/Synapse/Synapse.cs index 493cc71..179ef7b 100644 --- a/Synapse/Synapse.cs +++ b/Synapse/Synapse.cs @@ -16,8 +16,8 @@ namespace Synapse public static class Synapse { #region Version - private const int MajorVersion = 0; - private const int MinorVerion = 5; + private const int MajorVersion = 1; + private const int MinorVerion = 0; private const int Patch = 0; public static int VersionNumber => MajorVersion * 100 + MinorVerion * 10 + Patch;