From e6987a40337fba22d06ef3823ef0e111d7abcb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=B6ller?= Date: Thu, 13 Aug 2020 10:26:04 +0200 Subject: [PATCH 1/8] * ServerNamePatch fix for showing correctly in ServerList * Typofix --- .../Patches/SynapsePatches/ServerNamePatch.cs | 2 +- Synapse/Properties/AssemblyInfo.cs | 4 ++-- Synapse/Synapse.cs | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs b/Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs index dd2f9ea..b661544 100644 --- a/Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs +++ b/Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs @@ -10,7 +10,7 @@ public static void Postfix() { if (!SynapseConfigs.NameTracking) return; - ServerConsole._serverName += $" Synapse-ModLoader {Synapse.Version}"; + ServerConsole._serverName += $" SMSynapse-ModLoader {Synapse.Version}"; } } } \ No newline at end of file diff --git a/Synapse/Properties/AssemblyInfo.cs b/Synapse/Properties/AssemblyInfo.cs index 2528c0b..0736dca 100644 --- a/Synapse/Properties/AssemblyInfo.cs +++ b/Synapse/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0")] -[assembly: AssemblyFileVersion("1.2.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.1")] +[assembly: AssemblyFileVersion("1.2.1")] \ No newline at end of file diff --git a/Synapse/Synapse.cs b/Synapse/Synapse.cs index 004e70e..83f012b 100644 --- a/Synapse/Synapse.cs +++ b/Synapse/Synapse.cs @@ -17,11 +17,11 @@ public static class Synapse { #region Version private const int MajorVersion = 1; - private const int MinorVerion = 2; - private const int Patch = 0; + private const int MinorVersion = 2; + private const int Patch = 1; - public static int VersionNumber => MajorVersion * 100 + MinorVerion * 10 + Patch; - public static string Version => $"{MajorVersion}.{MinorVerion}.{Patch}"; + public static int VersionNumber => MajorVersion * 100 + MinorVersion * 10 + Patch; + public static string Version => $"{MajorVersion}.{MinorVersion}.{Patch}"; #endregion private static bool _isLoaded; @@ -124,16 +124,16 @@ private static void LoadPlugin(string pluginPath) Name = assembly.GetName().Name, Version = assembly.ImageRuntimeVersion, SynapseMajor = MajorVersion, - SynapseMinor = MinorVerion, + SynapseMinor = MinorVersion, SynapsePatch = Patch }; p.Assembly = assembly; plugins.Add(p); - if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor == MajorVersion * 10 + MinorVerion) Log.Info($"Successfully loaded {p.Details.Name}"); + if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor == MajorVersion * 10 + MinorVersion) Log.Info($"Successfully loaded {p.Details.Name}"); - else if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor > MajorVersion * 10 + MinorVerion) Log.Warn($"The Plugin {p.Details.Name} is for the newer Synapse version {p.Details.GetVersionString()} but was succesfully loaded(bugs can occure)"); + else if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor > MajorVersion * 10 + MinorVersion) 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)"); } From e5928c8ba2bf62f907570f1c553225d12a9fdbd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=B6ller?= Date: Thu, 13 Aug 2020 10:35:39 +0200 Subject: [PATCH 2/8] Revert Commit e6987a40337fba22d06ef3823ef0e111d7abcb40 --- Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs | 2 +- Synapse/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs b/Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs index b661544..dd2f9ea 100644 --- a/Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs +++ b/Synapse/Events/Patches/SynapsePatches/ServerNamePatch.cs @@ -10,7 +10,7 @@ public static void Postfix() { if (!SynapseConfigs.NameTracking) return; - ServerConsole._serverName += $" SMSynapse-ModLoader {Synapse.Version}"; + ServerConsole._serverName += $" Synapse-ModLoader {Synapse.Version}"; } } } \ No newline at end of file diff --git a/Synapse/Properties/AssemblyInfo.cs b/Synapse/Properties/AssemblyInfo.cs index 0736dca..2528c0b 100644 --- a/Synapse/Properties/AssemblyInfo.cs +++ b/Synapse/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.1")] -[assembly: AssemblyFileVersion("1.2.1")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.0")] +[assembly: AssemblyFileVersion("1.2.0")] \ No newline at end of file From b851ff48173fc68390e222f6c4d6548a8b62482a Mon Sep 17 00:00:00 2001 From: Helight Date: Thu, 13 Aug 2020 15:57:22 +0200 Subject: [PATCH 3/8] Add GrenadeEvent + Grenade-Use now calls ItemUse --- .../Events/Classes/PlayerThrowGrenadeEvent.cs | 19 +++++++ .../PlayerPatches/PlayerThrowGrenadePatch.cs | 57 +++++++++++++++++++ Synapse/Events/PlayerEvents.cs | 26 +++++++++ 3 files changed, 102 insertions(+) create mode 100644 Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs create mode 100644 Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs diff --git a/Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs b/Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs new file mode 100644 index 0000000..0f87224 --- /dev/null +++ b/Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs @@ -0,0 +1,19 @@ +using System.Diagnostics.CodeAnalysis; +using Synapse.Api; + +namespace Synapse.Events.Classes +{ + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] + public class PlayerThrowGrenadeEvent + { + public Player Player { get; internal set; } + + public ItemType Grenade { get; internal set; } + + public bool Slow { get; set; } + + public double FuseTime { get; set; } + + public bool Allow { get; set; } + } +} \ No newline at end of file diff --git a/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs b/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs new file mode 100644 index 0000000..99f506e --- /dev/null +++ b/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs @@ -0,0 +1,57 @@ +using System; +using Grenades; +using Harmony; +using Mirror; +using Synapse.Api; + +namespace Synapse.Events.Patches +{ + [HarmonyPatch(typeof(GrenadeManager), nameof(GrenadeManager.CallCmdThrowGrenade))] + public class PlayerThrowGrenadePatch + { + public static bool Prefix(ref GrenadeManager __instance, ref int id, ref bool slowThrow, ref double time) + { + try + { + var player = __instance.GetPlayer(); + if (player == null) return true; + ItemType item; + switch (id) + { + case 0: + item = ItemType.GrenadeFlash; + break; + case 1: + item = ItemType.GrenadeFrag; + break; + case 2: + item = ItemType.SCP018; + break; + default: + Log.Error($"Invalid Grenade ID: {id}"); + return true; + } + + time -= NetworkTime.time; + + Events.InvokeUseItemEvent(player, item, out var useAllow); + + if (!useAllow) return false; + + Events.InvokePlayerThrowGrenadeEvent(player, item, ref slowThrow, ref time, out var allow); + + + time += NetworkTime.time; + + + return allow; + + } + catch (Exception e) + { + Log.Error($"Player Throw Grenade Error: {e}"); + return true; + } + } + } +} \ No newline at end of file diff --git a/Synapse/Events/PlayerEvents.cs b/Synapse/Events/PlayerEvents.cs index ebb8ad6..e697ed2 100644 --- a/Synapse/Events/PlayerEvents.cs +++ b/Synapse/Events/PlayerEvents.cs @@ -466,5 +466,31 @@ internal static void InvokePlayerHealEvent(Player player, ref float amount, out amount = ev.Amount; } + + public delegate void OnPlayerThrowGrenade(PlayerThrowGrenadeEvent ev); + + public static event OnPlayerThrowGrenade PlayerThrowGrenadeEvent; + internal static void InvokePlayerThrowGrenadeEvent(Player player, ItemType type, ref bool slow, ref double time, out bool allow) + { + allow = true; + + if (PlayerThrowGrenadeEvent == null) return; + + var ev = new PlayerThrowGrenadeEvent + { + Player = player, + Grenade = type, + Slow = slow, + FuseTime = time, + Allow = allow + }; + + PlayerThrowGrenadeEvent.Invoke(ev); + + allow = ev.Allow; + slow = ev.Slow; + time = ev.FuseTime; + + } } } \ No newline at end of file From d4747b41921b7a6dc5b50ae68c2f7e62593698bf Mon Sep 17 00:00:00 2001 From: Helight Date: Thu, 13 Aug 2020 16:04:28 +0200 Subject: [PATCH 4/8] Add Player#RelativePositon --- Synapse/Api/Player.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index f4d7794..68d188d 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -239,7 +239,7 @@ public Team Side } } } - + /// /// The Room where the player currently is /// @@ -272,6 +272,19 @@ public Room Room set => Position = value.Position; } + /// + /// The position of the player relative to the position of the room he is currently in + /// + public Vector3 RelativePosition + { + get + { + return Position - Room.Position; + } + set => Position = Room.Position + value; + } + + /// /// The NetworkConnection of the player (often used by vanilla methods) /// From fb59c178bbb5380893611924be1ee290a812f1f5 Mon Sep 17 00:00:00 2001 From: Helight Date: Thu, 13 Aug 2020 16:26:01 +0200 Subject: [PATCH 5/8] Add Information --- Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs b/Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs index 0f87224..a81189d 100644 --- a/Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs +++ b/Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs @@ -12,6 +12,9 @@ public class PlayerThrowGrenadeEvent public bool Slow { get; set; } + /// + /// The time before the grenade gets launched. This value can not be higher than the throwingAnimationTime; + /// public double FuseTime { get; set; } public bool Allow { get; set; } From d9d6c6352282043b5d2e59ab1396339429b73bd0 Mon Sep 17 00:00:00 2001 From: Helight Date: Thu, 13 Aug 2020 16:27:29 +0200 Subject: [PATCH 6/8] Remove unnecessary newlines --- .../EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs b/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs index 99f506e..cb07345 100644 --- a/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs +++ b/Synapse/Events/Patches/EventPatches/PlayerPatches/PlayerThrowGrenadePatch.cs @@ -39,11 +39,9 @@ public static bool Prefix(ref GrenadeManager __instance, ref int id, ref bool sl if (!useAllow) return false; Events.InvokePlayerThrowGrenadeEvent(player, item, ref slowThrow, ref time, out var allow); - - + time += NetworkTime.time; - return allow; } From b993fe1d6310885eece13a31fd18948be94949eb Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Fri, 14 Aug 2020 09:25:55 +0200 Subject: [PATCH 7/8] Removed Player.RelativePosition --- Synapse/Api/Player.cs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 68d188d..f0f3833 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -272,19 +272,6 @@ public Room Room set => Position = value.Position; } - /// - /// The position of the player relative to the position of the room he is currently in - /// - public Vector3 RelativePosition - { - get - { - return Position - Room.Position; - } - set => Position = Room.Position + value; - } - - /// /// The NetworkConnection of the player (often used by vanilla methods) /// From a775069ccc8aeddfdadcd313c2af26ee850a694e Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Fri, 14 Aug 2020 10:39:32 +0200 Subject: [PATCH 8/8] fixed door bug --- .../MapPatches/DoorInteractPatch.cs | 53 ++++++++++++------- Synapse/Properties/AssemblyInfo.cs | 4 +- Synapse/Synapse.csproj | 2 + 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Synapse/Events/Patches/EventPatches/MapPatches/DoorInteractPatch.cs b/Synapse/Events/Patches/EventPatches/MapPatches/DoorInteractPatch.cs index 647ec22..d59cad1 100644 --- a/Synapse/Events/Patches/EventPatches/MapPatches/DoorInteractPatch.cs +++ b/Synapse/Events/Patches/EventPatches/MapPatches/DoorInteractPatch.cs @@ -11,23 +11,41 @@ public class DoorInteractPatch { public static bool Prefix(PlayerInteract __instance, GameObject doorId) { - var allowTheAccess = true; - Door door = null; try { - 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) - ? __instance.ChckDis(doorId.transform.position) - : door.Buttons.Any(item => __instance.ChckDis(item.button.transform.position)))) return false; + var allowTheAccess = true; + Door door = null; + + if (!__instance._playerInteractRateLimit.CanExecute() || (__instance._hc.CufferId > 0 && !PlayerInteract.CanDisarmedInteract)) + { + return false; + } + + if (doorId == null) + { + return false; + } + + if (__instance._ccm.CurClass == RoleType.None || __instance._ccm.CurClass == RoleType.Spectator) + { + return false; + } + + if (!doorId.TryGetComponent(out door)) + { + return false; + } + + if ((door.Buttons.Count == 0) ? (!__instance.ChckDis(doorId.transform.position)) : Enumerable.All(door.Buttons, item => !__instance.ChckDis(item.button.transform.position))) + { + return false; + } + __instance.OnInteract(); - if (__instance._sr.BypassMode) {} - else if (door.PermissionLevels.HasPermission(Door.AccessRequirements.Checkpoints) && - __instance._ccm.CurRole.team == Team.SCP) {} - else + if (!__instance._sr.BypassMode && !(door.PermissionLevels.HasPermission(Door.AccessRequirements.Checkpoints) && + __instance._ccm.CurRole.team == Team.SCP)) { try { @@ -51,8 +69,8 @@ public static bool Prefix(PlayerInteract __instance, GameObject doorId) } Events.InvokeDoorInteraction(__instance.gameObject.GetPlayer(), door, ref allowTheAccess); - - if(allowTheAccess) door.ChangeState(__instance._sr.BypassMode); + + if (allowTheAccess) door.ChangeState(__instance._sr.BypassMode); else __instance.RpcDenied(doorId); return false; @@ -60,11 +78,8 @@ public static bool Prefix(PlayerInteract __instance, GameObject doorId) catch (Exception e) { Log.Error($"DoorInteraction Error: {e}"); - - if(allowTheAccess && door != null) - door.ChangeState(__instance._sr.BypassMode); - else __instance.RpcDenied(doorId); - return false; + + return true; } } } diff --git a/Synapse/Properties/AssemblyInfo.cs b/Synapse/Properties/AssemblyInfo.cs index 2528c0b..0736dca 100644 --- a/Synapse/Properties/AssemblyInfo.cs +++ b/Synapse/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0")] -[assembly: AssemblyFileVersion("1.2.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.1")] +[assembly: AssemblyFileVersion("1.2.1")] \ No newline at end of file diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index acd17e1..3e5c4da 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -90,8 +90,10 @@ + +