diff --git a/Exemple-Plugin/Exemple-Plugin.csproj b/Exemple-Plugin/Exemple-Plugin.csproj index 79cb81e..9e4765b 100644 --- a/Exemple-Plugin/Exemple-Plugin.csproj +++ b/Exemple-Plugin/Exemple-Plugin.csproj @@ -35,19 +35,19 @@ ..\packages\Lib.Harmony.2.2.1\lib\net48\0Harmony.dll - ..\packages\SynapseSL.2.9.0\lib\net472\Assembly-CSharp.dll + ..\packages\SynapseSL.2.10.0\lib\net472\Assembly-CSharp.dll - ..\packages\SynapseSL.2.9.0\lib\net472\Assembly-CSharp-firstpass.dll + ..\packages\SynapseSL.2.10.0\lib\net472\Assembly-CSharp-firstpass.dll ..\packages\LiteDB.5.0.11\lib\net45\LiteDB.dll - ..\packages\SynapseSL.2.9.0\lib\net472\Mirror.dll + ..\packages\SynapseSL.2.10.0\lib\net472\Mirror.dll - - ..\packages\SynapseSL.2.9.0\lib\net472\Synapse.dll + + ..\packages\SynapseSL.2.10.0\lib\net472\Synapse.dll @@ -59,13 +59,13 @@ - ..\packages\SynapseSL.2.9.0\lib\net472\UnityEngine.dll + ..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.dll - ..\packages\SynapseSL.2.9.0\lib\net472\UnityEngine.CoreModule.dll + ..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.CoreModule.dll - ..\packages\SynapseSL.2.9.0\lib\net472\UnityEngine.PhysicsModule.dll + ..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.PhysicsModule.dll ..\packages\YamlDotNet.11.2.1\lib\net45\YamlDotNet.dll diff --git a/Exemple-Plugin/packages.config b/Exemple-Plugin/packages.config index 3d5dd8f..27c73f5 100644 --- a/Exemple-Plugin/packages.config +++ b/Exemple-Plugin/packages.config @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/VT-Api/Core/Behaviour/RepeatingBehaviour.cs b/VT-Api/Core/Behaviour/RepeatingBehaviour.cs index 940289b..0332774 100644 --- a/VT-Api/Core/Behaviour/RepeatingBehaviour.cs +++ b/VT-Api/Core/Behaviour/RepeatingBehaviour.cs @@ -27,8 +27,15 @@ public RepeatingBehaviour() : base() { } #region Methods public override void Kill() { - OnDisable(); - base.Kill(); + try + { + OnDisable(); + base.Kill(); + } + catch (Exception e) + { + Synapse.Api.Logger.Get.Error($"Vt-Event: RepeatingBehaviour kill faild!!\n{e}\nStackTrace:\n{e.StackTrace}"); + } } /// @@ -64,8 +71,11 @@ private void ActionExecute() private void ActionStop() { - _Started = false; - CancelInvoke("BehaviourAction"); + if (_Started) + { + CancelInvoke("BehaviourAction"); + _Started = false; + } } #endregion } diff --git a/VT-Api/Core/Command/CommandHandler.cs b/VT-Api/Core/Command/CommandHandler.cs index b2c8e4a..1be781d 100644 --- a/VT-Api/Core/Command/CommandHandler.cs +++ b/VT-Api/Core/Command/CommandHandler.cs @@ -12,9 +12,8 @@ public class CommandHandler internal void Init() { + RegisterVtCommands(); Synapse.Api.Events.EventHandler.Get.Round.WaitingForPlayersEvent += RegisterSubCommand; - - RegisterVtCommands(); } public static CommandHandler Get { get => VtController.Get.Commands; } @@ -101,6 +100,7 @@ private void RegisterVtCommands() { if (!_firstLoad) return; + Logger.Get.Info("Register Command"); RegisterSynapseCommand(new CallPower(), false); } diff --git a/VT-Api/Core/Command/Commands/CallPower.cs b/VT-Api/Core/Command/Commands/CallPower.cs index 892c5ac..7102545 100644 --- a/VT-Api/Core/Command/Commands/CallPower.cs +++ b/VT-Api/Core/Command/Commands/CallPower.cs @@ -14,7 +14,7 @@ namespace VT_Api.Core.Command.Commands Description = "Call the power of your role", Usage = "no argument if you want to call your main power, if not add the id of the power", Permission = "", - Platforms = new[] { Platform.RemoteAdmin, Platform.ServerConsole }, + Platforms = new[] { Platform.ServerConsole }, Arguments = new[] { "(powerId)" } )] public class CallPower : ISynapseCommand diff --git a/VT-Api/Core/MapAndRoundManger.cs b/VT-Api/Core/MapAndRoundManger.cs index 5af1831..0f48c1e 100644 --- a/VT-Api/Core/MapAndRoundManger.cs +++ b/VT-Api/Core/MapAndRoundManger.cs @@ -13,6 +13,8 @@ using Logger = Synapse.Api.Logger; using SynRagdoll = Synapse.Api.Ragdoll; using MEC; +using InventorySystem.Items.Firearms; +using Synapse.Api.Enum; namespace VT_Api.Core { @@ -264,5 +266,29 @@ public void MtfRespawn(bool isCI, List players, bool useTicket = true) / RespawnManager.Singleton.RestartSequence(); }); } + + public void PlayShoot(ShootSound sound, Vector3 position, byte shootSoundDistance = 25) + { + foreach (var player in Server.Get.Players) + { + var msg = new GunAudioMessage(player, 0, shootSoundDistance, player); + var to = position - player.Position; + + if (player.RoleType != RoleType.Spectator && to.sqrMagnitude > 1760f) + { + to.y = 0f; + var num = Vector3.Angle(Vector3.forward, to); + if (Vector3.Dot(to.normalized, Vector3.left) > 0f) + num = 360f - num; + + msg.ShooterDirection = (byte)Mathf.RoundToInt(num / 1.44f); + msg.ShooterRealDistance = (byte)Mathf.RoundToInt(Mathf.Min(to.magnitude, 255f)); + } + + msg.Weapon = (ItemType)sound; + + player.Connection.Send(msg); + } + } } } diff --git a/VT-Api/Core/Roles/AbstractRole.cs b/VT-Api/Core/Roles/AbstractRole.cs index cecf3a5..642eb01 100644 --- a/VT-Api/Core/Roles/AbstractRole.cs +++ b/VT-Api/Core/Roles/AbstractRole.cs @@ -118,17 +118,7 @@ public virtual bool CallPower(byte power, out string message) [API] public virtual void Spawning() { - if (Config != null) - { - if (Config.Health != null) - Player.Health = (float)Config.Health; - Player.MaxHealth = Config.MaxHealth ?? Player.Health; - if (Config.ArtificialHealth != null) - Player.ArtificialHealth = (float)Config.ArtificialHealth; - if (Config.MaxArtificialHealth != null) - Player.MaxArtificialHealth = (int)Config.MaxArtificialHealth; - } } /** @@ -177,6 +167,18 @@ public sealed override void Spawn() } SetDisplayInfo(); + if (Config != null) + { + if (Config.Health != null) + Player.Health = (float)Config.Health; + Player.MaxHealth = Config.MaxHealth ?? Player.Health; + + if (Config.ArtificialHealth != null) + Player.ArtificialHealth = (float)Config.ArtificialHealth; + if (Config.MaxArtificialHealth != null) + Player.MaxArtificialHealth = (int)Config.MaxArtificialHealth; + } + Spawning(); } diff --git a/VT-Api/Core/VtExtensions.cs b/VT-Api/Core/VtExtensions.cs index 036895e..b566675 100644 --- a/VT-Api/Core/VtExtensions.cs +++ b/VT-Api/Core/VtExtensions.cs @@ -265,36 +265,16 @@ public static bool TryPickup(this Player.PlayerAmmoBox ammos, SynapseItem item) public static void SetDisplayInfoRole(this Player player, string roleName) { - /* - * TODO Rework This : - * - * Badge "pas touche" - * - * Nickname - * Role (Unit) - * CustomInfo - * - * PowerStatus - */ - - // to - - /* - * - * NickName - * CustomInfo - * - * - * - * - */ - player.RemoveDisplayInfo(PlayerInfoArea.Role); if (player.Team == Team.MTF) { + if (string.IsNullOrWhiteSpace(player.UnitName)) + player.DisplayInfo = $"{roleName} ({player.UnitName})"; + else + player.DisplayInfo = roleName; + player.RemoveDisplayInfo(PlayerInfoArea.UnitName); - player.DisplayInfo = $"{roleName} ({player.UnitName})"; } else { diff --git a/VT-Api/Patches/VtEvent/MapPaches/StoppingWarHeadPatch.cs b/VT-Api/Patches/VtEvent/MapPaches/StoppingWarHeadPatch.cs index fb13300..a2a28d5 100644 --- a/VT-Api/Patches/VtEvent/MapPaches/StoppingWarHeadPatch.cs +++ b/VT-Api/Patches/VtEvent/MapPaches/StoppingWarHeadPatch.cs @@ -2,12 +2,14 @@ using HarmonyLib; using Interactables.Interobjects.DoorUtils; using Mirror; +using Subtitles; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; +using Utils.Networking; namespace VT_Api.Patches.VtEvent.MapPaches { @@ -19,37 +21,32 @@ private static bool NukeCancelButon(AlphaWarheadController __instance, GameObjec { try { - if (!__instance.inProgress) + ServerLogs.AddLog(ServerLogs.Modules.Warhead, "Detonation cancelled.", ServerLogs.ServerLogType.GameEvent); + + var flag = __instance.inProgress && __instance.timeToDetonation > 10f && !__instance._isLocked; + + VtController.Get.Events.Map.InvokeWarheadStopEvent(disabler?.GetPlayer(), ref flag); + + if (!flag) return false; - if (disabler != null) - { - bool flag = __instance.timeToDetonation > 10.0 && !__instance._isLocked; - VtController.Get.Events.Map.InvokeWarheadStopEvent(disabler.GetPlayer(), ref flag); - if (!flag) - return false; + if (__instance.timeToDetonation <= 15f && disabler != null) + AchievementHandlerBase.ServerAchieve(disabler.GetComponent().connectionToClient, AchievementName.ThatWasClose); - if (__instance.timeToDetonation <= 15f && disabler != null) - { - AchievementHandlerBase.ServerAchieve(disabler.GetComponent().connectionToClient, AchievementName.ThatWasClose); - } + for (sbyte b = 0; b < __instance.scenarios_resume.Length; b = (sbyte)(b + 1)) + if (__instance.scenarios_resume[b].SumTime() > __instance.timeToDetonation && __instance.scenarios_resume[b].SumTime() < __instance.scenarios_start[AlphaWarheadController._startScenario].SumTime()) + __instance.NetworksyncResumeScenario = b; - for (sbyte b = 0; b < __instance.scenarios_resume.Length; b = (sbyte)(b + 1)) + __instance.NetworktimeToDetonation = ((AlphaWarheadController._resumeScenario < 0) ? __instance.scenarios_start[AlphaWarheadController._startScenario].SumTime() : __instance.scenarios_resume[AlphaWarheadController._resumeScenario].SumTime()) + (float)__instance.cooldown; + __instance.NetworkinProgress = false; + DoorEventOpenerExtension.TriggerAction(DoorEventOpenerExtension.OpenerEventType.WarheadCancel); + if (NetworkServer.active) + { + __instance._autoDetonate = false; + NetworkUtils.SendToAuthenticated(new SubtitleMessage(new SubtitlePart[1] { - if (__instance.scenarios_resume[b].SumTime() > __instance.timeToDetonation - && __instance.scenarios_resume[b].SumTime() < __instance.scenarios_start[AlphaWarheadController._startScenario].SumTime()) - { - __instance.NetworksyncResumeScenario = b; - } - } - - __instance.NetworktimeToDetonation = ((AlphaWarheadController._resumeScenario < 0) ? - __instance.scenarios_start[AlphaWarheadController._startScenario].SumTime() : - __instance.scenarios_resume[AlphaWarheadController._resumeScenario].SumTime()) + __instance.cooldown; - __instance.NetworkinProgress = false; - DoorEventOpenerExtension.TriggerAction(DoorEventOpenerExtension.OpenerEventType.WarheadCancel); - if (NetworkServer.active) - __instance._autoDetonate = false; + new SubtitlePart(SubtitleType.AlphaWarheadCancelled, null) + })); } return false; } diff --git a/VT-Api/Patches/VtEvent/PlayerPatches/SynapseDamagePatch.cs b/VT-Api/Patches/VtEvent/PlayerPatches/SynapseDamagePatch.cs index efa1c5f..5f45dbe 100644 --- a/VT-Api/Patches/VtEvent/PlayerPatches/SynapseDamagePatch.cs +++ b/VT-Api/Patches/VtEvent/PlayerPatches/SynapseDamagePatch.cs @@ -19,22 +19,31 @@ class SynapseDamagePatch [HarmonyPrefix] private static bool DamageEventPatch(PlayerEvents __instance, Player victim, Player killer, ref float damage, DamageType type, out bool allow) { + var ev = new PlayerDamageEventArgs + { + Damage = damage, + }; + try { - var ev = new PlayerDamageEventArgs - { - Damage = damage, - }; ev.SetProperty("Killer", killer); ev.SetProperty("Victim", victim); ev.SetProperty("Damage", damage); ev.SetProperty("DamageType", type); __instance.CallEvent("PlayerDamageEvent", ev); - + + allow = ev.Allow; damage = ev.Damage; + } + catch (Exception e) + { + Synapse.Api.Logger.Get.Error($"Synapse-Event: PlayerDamage event failed!!\n{e}"); allow = ev.Allow; - + return false; + } + try + { VtController.Get.Events.Player.InvokePlayerDamagePostEvent(victim, killer, ref damage, type, ref allow); return false; @@ -42,8 +51,7 @@ private static bool DamageEventPatch(PlayerEvents __instance, Player victim, Pla catch (Exception e) { Synapse.Api.Logger.Get.Error($"Vt-Event: PlayerDamagePost failed!!\n{e}\nStackTrace:\n{e.StackTrace}"); - allow = true; - return true; + return false; } } diff --git a/VT-Api/Patches/VtEvent/PlayerPatches/SynapseDeathPatch.cs b/VT-Api/Patches/VtEvent/PlayerPatches/SynapseDeathPatch.cs index 6eaadc0..074dfb6 100644 --- a/VT-Api/Patches/VtEvent/PlayerPatches/SynapseDeathPatch.cs +++ b/VT-Api/Patches/VtEvent/PlayerPatches/SynapseDeathPatch.cs @@ -19,9 +19,10 @@ class SynapseDeathPatch [HarmonyPrefix] private static bool DeathEventPatch(PlayerEvents __instance, Player victim, Player killer, DamageType type, out bool allow) { + var ev = new PlayerDeathEventArgs(); try { - var ev = new PlayerDeathEventArgs(); + ev.Allow = true; ev.SetProperty("Killer", killer); ev.SetProperty("Victim", victim); @@ -30,7 +31,15 @@ private static bool DeathEventPatch(PlayerEvents __instance, Player victim, Play __instance.CallEvent("PlayerDeathEvent", ev); allow = ev.Allow; - + } + catch (Exception e) + { + allow = ev.Allow; + Logger.Get.Error($"Synapse-Event: PlayerDeath event failed!!\n{e}"); + return false; + } + try + { VtController.Get.Events.Player.InvokePlayerDeathPostEvent(victim, killer, type, ref allow); return false; @@ -38,7 +47,6 @@ private static bool DeathEventPatch(PlayerEvents __instance, Player victim, Play catch (Exception e) { Synapse.Api.Logger.Get.Error($"Vt-Event: PlayerDamagePost failed!!\n{e}\nStackTrace:\n{e.StackTrace}"); - allow = true; return true; } }