From 3729edce7b22a6481e99065ba4453a6248857e88 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Fri, 14 Aug 2020 15:44:12 +0200 Subject: [PATCH 01/27] i hate this part but i added informations and updated the wiki --- Synapse/Api/Decontamination.cs | 9 +++++ Synapse/Api/Map.cs | 60 +++++++++++++++++++++++++--------- Synapse/Api/Player.cs | 28 ++++++++++++++-- Synapse/Api/Round.cs | 39 +++++++++++++++++++--- Synapse/Api/Server.cs | 52 +++++++++++++++++++++++++++-- Synapse/Api/Warhead.cs | 25 +++++++++++--- 6 files changed, 185 insertions(+), 28 deletions(-) diff --git a/Synapse/Api/Decontamination.cs b/Synapse/Api/Decontamination.cs index 2ed95b2..aa6c3a1 100644 --- a/Synapse/Api/Decontamination.cs +++ b/Synapse/Api/Decontamination.cs @@ -5,8 +5,14 @@ namespace Synapse.Api { public static class Decontamination { + /// + /// Gives you the Decontamination Controller + /// public static DecontaminationController Controller => DecontaminationController.Singleton; + /// + /// Is the Decontamination Countdown disabled? + /// public static bool IsDecontaminationDisabled { get => Controller._disableDecontamination; @@ -21,6 +27,9 @@ public static bool IsDecontaminationDisabled } } + /// + /// Is the Decontamination in Progress? + /// public static bool IsDecontaminationInProgress => Controller._decontaminationBegun; /// diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 5af870c..14aaf92 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -12,6 +12,10 @@ namespace Synapse.Api [SuppressMessage("ReSharper", "UnusedMember.Global")] public static class Map { + private static Broadcast BroadcastComponent => Player.Host.GetComponent(); + + + /// /// Activates/Deactivates the FriendlyFire on the server /// @@ -22,8 +26,6 @@ public static class Map /// public static List Lifts => Server.GetObjectsOf(); - private static Broadcast BroadcastComponent => Player.Host.GetComponent(); - /// /// Gives you a list of all rooms /// @@ -37,6 +39,9 @@ public static IEnumerable Rooms } } + /// + /// Get/Sets the Text of the Intercom + /// public static string IntercomText { get => Server.Host.GetComponent().CustomContent; @@ -175,6 +180,38 @@ public static Vector3 GetRandomSpawnPoint(this RoleType type) public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) => Player.Host.Inventory.SetPickup(itemType, durability, position, rotation, sight, barrel, other); + /// + /// Spawns a Item on the Map with a specific scale + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Vector3 scale, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) + { + var p = Server.Host.Inventory.SetPickup(itemType, -4.656647E+11f, position, Quaternion.identity, 0, 0, 0); + + var gameObject = p.gameObject; + gameObject.transform.localScale = scale; + + NetworkServer.UnSpawn(gameObject); + NetworkServer.Spawn(p.gameObject); + + return p; + } + + /// + /// Spawns a WorkStation on the Map + /// + /// + /// + /// + /// The Workstation public static WorkStation SpawnWorkStation(Vector3 position,Vector3 rotation,Vector3 size) { GameObject bench = @@ -193,6 +230,12 @@ public static WorkStation SpawnWorkStation(Vector3 position,Vector3 rotation,Vec return bench.GetComponent(); } + /// + /// Spawns a Ragdoll on the Map + /// + /// + /// + /// public static void SpawnRagdoll(Vector3 Position,RoleType role,string killer = "World") { Server.Host.GetComponent().SpawnRagdoll( @@ -201,19 +244,6 @@ public static void SpawnRagdoll(Vector3 Position,RoleType role,string killer = " , false, killer, killer, 1); } - public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Vector3 scale, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) - { - var p = Server.Host.Inventory.SetPickup(itemType, -4.656647E+11f, position,Quaternion.identity, 0, 0, 0); - - var gameObject = p.gameObject; - gameObject.transform.localScale = scale; - - NetworkServer.UnSpawn(gameObject); - NetworkServer.Spawn(p.gameObject); - - return p; - } - /// /// Has the group the permission? /// diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index f0f3833..ceebb97 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -102,6 +102,9 @@ public CommandSender CommandSender /// public string NickName { get => NicknameSync.Network_myNickSync; } + /// + /// Get / Set the Displayed Name of the User + /// public string DisplayName { get => NicknameSync.DisplayName; set => NicknameSync.DisplayName = value; } /// @@ -140,13 +143,11 @@ public CommandSender CommandSender /// public bool Bypass { get => ServerRoles.BypassMode; set => Hub.serverRoles.BypassMode = value; } - /// /// Get / Set the Players GodMode /// public bool GodMode { get => ClassManager.GodMode; set => ClassManager.GodMode = value; } - /// /// Modify the size of the Player /// @@ -362,6 +363,9 @@ public Player Cuffer /// public Camera079 Camera { get => Hub.scp079PlayerScript.currentCamera; set => Hub.scp079PlayerScript?.RpcSwitchCamera(value.cameraId, false); } + /// + /// Gives you the Ping of the Player to the Server + /// public int Ping => LiteNetLib4MirrorServer.Peers[Connection.connectionId].Ping; /// @@ -389,8 +393,14 @@ public Player Cuffer /// public bool IsDead => Team == Team.RIP; + /// + /// The Jail object of the Player + /// public Jail Jail => GetComponent(); + /// + /// Gets/Sets the UnitName of the Player + /// public string UnitName { get => ClassManager.NetworkCurUnitName; set => ClassManager.NetworkCurUnitName = value; } /// @@ -516,8 +526,15 @@ 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); + /// + /// Drops the Entire Inventory of the Player + /// public void DropAllItems() => Inventory.ServerDropAll(); + /// + /// Drops a Item from the PlayerInventory + /// + /// public void DropItem(Inventory.SyncItemInfo item) { Inventory.SetPickup(item.id, item.durability, Position, Inventory.camera.transform.rotation, item.modSight, item.modBarrel, item.modOther); @@ -587,6 +604,9 @@ public void SendToServer(ushort port) NetworkWriterPool.Recycle(writer); } + /// + /// Makes the Screen of the Player for the entire Round black + /// public void DimScreen() { var component = RoundSummary.singleton; @@ -602,6 +622,10 @@ public void DimScreen() NetworkWriterPool.Recycle(writer); } + /// + /// Shakes the Screen of the Player like when the Warhead explodes + /// + /// public void ShakeScreen(bool achieve = false) { var component = Warhead.Controller; diff --git a/Synapse/Api/Round.cs b/Synapse/Api/Round.cs index f0a176b..c20c532 100644 --- a/Synapse/Api/Round.cs +++ b/Synapse/Api/Round.cs @@ -9,34 +9,65 @@ public static class Round [Obsolete("Please use RoundLength")] public static TimeSpan RoundLenght => RoundStart.RoundLenght; + /// + /// The time since the Round started + /// public static TimeSpan RoundLength => RoundStart.RoundLenght; + /// + /// The time the Round started + /// public static DateTime StartedTime => DateTime.Now - RoundLength; + /// + /// Is the Round started? + /// public static bool IsStarted => RoundSummary.RoundInProgress(); /// - /// Activates/Deactivates the RoundLock (if the Round can end) + /// Get/Sets if the Round is locked /// public static bool IsLocked{ get => RoundSummary.RoundLock; set => RoundSummary.RoundLock = value; } + /// + /// Get/Sets if the Lobby is locked + /// + public static bool IsLobbyLocked { get => RoundStart.LobbyLock; set => RoundStart.LobbyLock = value; } + + /// + /// The Amount of escaped ClassD`s + /// public static int EscapedDs { get => RoundSummary.escaped_ds; set => RoundSummary.escaped_ds = value; } + /// + /// The Amount of escaped Scientists + /// public static int EscapedScientists { get => RoundSummary.escaped_scientists; set => RoundSummary.escaped_scientists = value; } + /// + /// The Amount of kills by Scps + /// public static int KillsByScps { get => RoundSummary.kills_by_scp; set => RoundSummary.kills_by_scp = value; } + /// + /// The Amount of persons changed into Zombies + /// public static int ChangedIntoZombies { get => RoundSummary.changed_into_zombies; set => RoundSummary.changed_into_zombies = value; } /// - /// Activates/Deactivates the LobbyLock (if the Lobby can continue counting down) + /// Restarts the Round /// - public static bool IsLobbyLocked{ get => RoundStart.LobbyLock; set => RoundStart.LobbyLock = value; } - public static void Restart() => Player.Host.PlayerStats.Roundrestart(); + /// + /// Starts the Round + /// public static void Start() => CharacterClassManager.ForceRoundStart(); + /// + /// Spawns Mtf/Chaos + /// + /// public static void MtfRespawn(bool isCI = false) { var component = Server.Host.GetComponent(); diff --git a/Synapse/Api/Server.cs b/Synapse/Api/Server.cs index 348c126..afed9c8 100644 --- a/Synapse/Api/Server.cs +++ b/Synapse/Api/Server.cs @@ -14,9 +14,14 @@ public static class Server private static Broadcast _broadcast; private static BanPlayer _banPlayer; - + /// + /// Gives you the Player object of the Server + /// public static Player Host => Player.Host; + /// + /// Get/Sets the ServerName + /// public static string Name { get => ServerConsole._serverName; @@ -27,8 +32,14 @@ public static string Name } } + /// + /// Get/Sets the Port of the Server + /// public static ushort Port { get => ServerStatic.ServerPort; set => ServerStatic.ServerPort = value; } + /// + /// SpawnMessage MethodInfo + /// public static MethodInfo SendSpawnMessage { get @@ -41,6 +52,9 @@ public static MethodInfo SendSpawnMessage } } + /// + /// The Broadcast object of the Server + /// public static Broadcast Broadcast { get @@ -52,6 +66,9 @@ public static Broadcast Broadcast } } + /// + /// The BanPlayer object of the Server + /// public static BanPlayer BanPlayer { get @@ -63,17 +80,48 @@ public static BanPlayer BanPlayer } } + /// + /// Gives you the ServerConsole + /// public static ServerConsole Console => ServerConsole.singleton; + /// + /// The RemoteAdmin Command Handler + /// + /// + /// You can use it to register Commands + /// public static RemoteAdminCommandHandler RaCommandHandler => CommandProcessor.RemoteAdminCommandHandler; + /// + /// The ServerConsole Command Handler + /// + /// + /// You can use it to register Commands + /// public static GameConsoleCommandHandler GameCoreCommandHandler => GameCore.Console.singleton.ConsoleCommandHandler; + /// + /// The Client Command Handler + /// + /// + /// You can use it to register Commands + /// public static ClientCommandHandler ClientCommandHandler => QueryProcessor.DotCommandHandler; - + /// + /// Gives you a list of all objects with this Type + /// + /// + /// public static List GetObjectsOf() where TObject : UnityEngine.Object => UnityEngine.Object.FindObjectsOfType().ToList(); + /// + /// Gives you the MethodHash + /// + /// + /// + /// 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 index 4810b14..fd12d13 100644 --- a/Synapse/Api/Warhead.cs +++ b/Synapse/Api/Warhead.cs @@ -5,6 +5,9 @@ public static class Warhead private static AlphaWarheadController _controller; private static AlphaWarheadNukesitePanel _nukeSitePanel; + /// + /// Gives you the Decontamination Controller + /// public static AlphaWarheadController Controller { get @@ -16,6 +19,9 @@ public static AlphaWarheadController Controller } } + /// + /// Gives you the NukesiktePanel + /// public static AlphaWarheadNukesitePanel NukeSitePanel { get @@ -27,8 +33,14 @@ public static AlphaWarheadNukesitePanel NukeSitePanel } } + /// + /// Get / Set the LeverStatus + /// public static bool LeverStatus { get => NukeSitePanel.Networkenabled; set => NukeSitePanel.Networkenabled = value; } + /// + /// The Time to Detonation + /// public static float DetonationTimer { get => Controller.NetworktimeToDetonation; @@ -36,17 +48,17 @@ public static float DetonationTimer } /// - /// Is the nuke detonated? + /// Is the Nuke Detonated? /// public static bool IsNukeDetonated => Controller.detonated; /// - /// Is the nuke in progress? + /// Is the Nuke in Progress? /// public static bool IsNukeInProgress => Controller.inProgress; /// - /// Starts the nuke + /// Starts the Nuke /// public static void StartNuke() { @@ -55,15 +67,18 @@ public static void StartNuke() } /// - /// Stops the nuke + /// Stops the Nuke /// public static void StopNuke() => Controller.CancelDetonation(); /// - /// Detonates the nuke + /// Detonates the Nuke /// public static void DetonateNuke() => Controller.Detonate(); + /// + /// Shakes the Screen for all player like when the Nuke explodes + /// public static void Shake() => Controller.RpcShake(true); } } From a5e00f4b440915dfa72c08735333ee6e3020c21f Mon Sep 17 00:00:00 2001 From: Helight Date: Sun, 16 Aug 2020 18:34:47 +0200 Subject: [PATCH 02/27] Added Tickets --- Synapse/Api/Round.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Synapse/Api/Round.cs b/Synapse/Api/Round.cs index f0a176b..3269a58 100644 --- a/Synapse/Api/Round.cs +++ b/Synapse/Api/Round.cs @@ -20,6 +20,56 @@ public static class Round /// public static bool IsLocked{ get => RoundSummary.RoundLock; set => RoundSummary.RoundLock = value; } + /// + /// Gets or sets the amount of Respawntickets for the MTF-Team + /// Please be careful when settings the amount of the ticket since this method ignores whether or + /// not the ticket amount should be locked to zero or not + /// + public static int MtfTickets + { + get { + RespawnTickets.Singleton._tickets.TryGetValue(SpawnableTeamType.NineTailedFox, out var tickets); + return tickets; + } + + set => RespawnTickets.Singleton._tickets[SpawnableTeamType.NineTailedFox] = value; + } + + /// + /// Gets or sets the amount of Respawntickets for the Chaos-Team + /// Please be careful when settings the amount of the ticket since this method ignores whether or + /// not the ticket amount should be locked to zero or not + /// + public static int ChaosTickets + { + get { + RespawnTickets.Singleton._tickets.TryGetValue(SpawnableTeamType.ChaosInsurgency, out var tickets); + return tickets; + } + + set => RespawnTickets.Singleton._tickets[SpawnableTeamType.ChaosInsurgency] = value; + } + + /// + /// Grants Respawntickets to the MTF-Team + /// + /// The amount of tickets granted + /// Whether or not a existing lock should be ignored + public static void GrantMtfTickets(int tickets, bool overrideLocks = false) + { + RespawnTickets.Singleton.GrantTickets(SpawnableTeamType.NineTailedFox, tickets, overrideLocks); + } + + /// + /// Grants Respawntickets to the Chaos-Team + /// + /// The amount of tickets granted + /// Whether or not a existing lock should be ignored + public static void GrantChaosTickets(int tickets, bool overrideLocks = false) + { + RespawnTickets.Singleton.GrantTickets(SpawnableTeamType.ChaosInsurgency, tickets, overrideLocks); + } + public static int EscapedDs { get => RoundSummary.escaped_ds; set => RoundSummary.escaped_ds = value; } public static int EscapedScientists { get => RoundSummary.escaped_scientists; set => RoundSummary.escaped_scientists = value; } From d8d2ac801e383569a0d4a8935d6126352b223bee Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Fri, 14 Aug 2020 15:44:12 +0200 Subject: [PATCH 03/27] i hate this part but i added informations and updated the wiki --- Synapse/Api/Decontamination.cs | 9 ++++ Synapse/Api/Map.cs | 60 +++++++++++++++++++------- Synapse/Api/Player.cs | 28 +++++++++++- Synapse/Api/Round.cs | 79 +++++++++++++--------------------- Synapse/Api/Server.cs | 52 +++++++++++++++++++++- Synapse/Api/Warhead.cs | 25 ++++++++--- 6 files changed, 180 insertions(+), 73 deletions(-) diff --git a/Synapse/Api/Decontamination.cs b/Synapse/Api/Decontamination.cs index 2ed95b2..aa6c3a1 100644 --- a/Synapse/Api/Decontamination.cs +++ b/Synapse/Api/Decontamination.cs @@ -5,8 +5,14 @@ namespace Synapse.Api { public static class Decontamination { + /// + /// Gives you the Decontamination Controller + /// public static DecontaminationController Controller => DecontaminationController.Singleton; + /// + /// Is the Decontamination Countdown disabled? + /// public static bool IsDecontaminationDisabled { get => Controller._disableDecontamination; @@ -21,6 +27,9 @@ public static bool IsDecontaminationDisabled } } + /// + /// Is the Decontamination in Progress? + /// public static bool IsDecontaminationInProgress => Controller._decontaminationBegun; /// diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 5af870c..14aaf92 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -12,6 +12,10 @@ namespace Synapse.Api [SuppressMessage("ReSharper", "UnusedMember.Global")] public static class Map { + private static Broadcast BroadcastComponent => Player.Host.GetComponent(); + + + /// /// Activates/Deactivates the FriendlyFire on the server /// @@ -22,8 +26,6 @@ public static class Map /// public static List Lifts => Server.GetObjectsOf(); - private static Broadcast BroadcastComponent => Player.Host.GetComponent(); - /// /// Gives you a list of all rooms /// @@ -37,6 +39,9 @@ public static IEnumerable Rooms } } + /// + /// Get/Sets the Text of the Intercom + /// public static string IntercomText { get => Server.Host.GetComponent().CustomContent; @@ -175,6 +180,38 @@ public static Vector3 GetRandomSpawnPoint(this RoleType type) public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) => Player.Host.Inventory.SetPickup(itemType, durability, position, rotation, sight, barrel, other); + /// + /// Spawns a Item on the Map with a specific scale + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Vector3 scale, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) + { + var p = Server.Host.Inventory.SetPickup(itemType, -4.656647E+11f, position, Quaternion.identity, 0, 0, 0); + + var gameObject = p.gameObject; + gameObject.transform.localScale = scale; + + NetworkServer.UnSpawn(gameObject); + NetworkServer.Spawn(p.gameObject); + + return p; + } + + /// + /// Spawns a WorkStation on the Map + /// + /// + /// + /// + /// The Workstation public static WorkStation SpawnWorkStation(Vector3 position,Vector3 rotation,Vector3 size) { GameObject bench = @@ -193,6 +230,12 @@ public static WorkStation SpawnWorkStation(Vector3 position,Vector3 rotation,Vec return bench.GetComponent(); } + /// + /// Spawns a Ragdoll on the Map + /// + /// + /// + /// public static void SpawnRagdoll(Vector3 Position,RoleType role,string killer = "World") { Server.Host.GetComponent().SpawnRagdoll( @@ -201,19 +244,6 @@ public static void SpawnRagdoll(Vector3 Position,RoleType role,string killer = " , false, killer, killer, 1); } - public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Vector3 scale, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0) - { - var p = Server.Host.Inventory.SetPickup(itemType, -4.656647E+11f, position,Quaternion.identity, 0, 0, 0); - - var gameObject = p.gameObject; - gameObject.transform.localScale = scale; - - NetworkServer.UnSpawn(gameObject); - NetworkServer.Spawn(p.gameObject); - - return p; - } - /// /// Has the group the permission? /// diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index f0f3833..ceebb97 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -102,6 +102,9 @@ public CommandSender CommandSender /// public string NickName { get => NicknameSync.Network_myNickSync; } + /// + /// Get / Set the Displayed Name of the User + /// public string DisplayName { get => NicknameSync.DisplayName; set => NicknameSync.DisplayName = value; } /// @@ -140,13 +143,11 @@ public CommandSender CommandSender /// public bool Bypass { get => ServerRoles.BypassMode; set => Hub.serverRoles.BypassMode = value; } - /// /// Get / Set the Players GodMode /// public bool GodMode { get => ClassManager.GodMode; set => ClassManager.GodMode = value; } - /// /// Modify the size of the Player /// @@ -362,6 +363,9 @@ public Player Cuffer /// public Camera079 Camera { get => Hub.scp079PlayerScript.currentCamera; set => Hub.scp079PlayerScript?.RpcSwitchCamera(value.cameraId, false); } + /// + /// Gives you the Ping of the Player to the Server + /// public int Ping => LiteNetLib4MirrorServer.Peers[Connection.connectionId].Ping; /// @@ -389,8 +393,14 @@ public Player Cuffer /// public bool IsDead => Team == Team.RIP; + /// + /// The Jail object of the Player + /// public Jail Jail => GetComponent(); + /// + /// Gets/Sets the UnitName of the Player + /// public string UnitName { get => ClassManager.NetworkCurUnitName; set => ClassManager.NetworkCurUnitName = value; } /// @@ -516,8 +526,15 @@ 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); + /// + /// Drops the Entire Inventory of the Player + /// public void DropAllItems() => Inventory.ServerDropAll(); + /// + /// Drops a Item from the PlayerInventory + /// + /// public void DropItem(Inventory.SyncItemInfo item) { Inventory.SetPickup(item.id, item.durability, Position, Inventory.camera.transform.rotation, item.modSight, item.modBarrel, item.modOther); @@ -587,6 +604,9 @@ public void SendToServer(ushort port) NetworkWriterPool.Recycle(writer); } + /// + /// Makes the Screen of the Player for the entire Round black + /// public void DimScreen() { var component = RoundSummary.singleton; @@ -602,6 +622,10 @@ public void DimScreen() NetworkWriterPool.Recycle(writer); } + /// + /// Shakes the Screen of the Player like when the Warhead explodes + /// + /// public void ShakeScreen(bool achieve = false) { var component = Warhead.Controller; diff --git a/Synapse/Api/Round.cs b/Synapse/Api/Round.cs index 3269a58..c20c532 100644 --- a/Synapse/Api/Round.cs +++ b/Synapse/Api/Round.cs @@ -9,84 +9,65 @@ public static class Round [Obsolete("Please use RoundLength")] public static TimeSpan RoundLenght => RoundStart.RoundLenght; + /// + /// The time since the Round started + /// public static TimeSpan RoundLength => RoundStart.RoundLenght; + /// + /// The time the Round started + /// public static DateTime StartedTime => DateTime.Now - RoundLength; + /// + /// Is the Round started? + /// public static bool IsStarted => RoundSummary.RoundInProgress(); /// - /// Activates/Deactivates the RoundLock (if the Round can end) + /// Get/Sets if the Round is locked /// public static bool IsLocked{ get => RoundSummary.RoundLock; set => RoundSummary.RoundLock = value; } - /// - /// Gets or sets the amount of Respawntickets for the MTF-Team - /// Please be careful when settings the amount of the ticket since this method ignores whether or - /// not the ticket amount should be locked to zero or not - /// - public static int MtfTickets - { - get { - RespawnTickets.Singleton._tickets.TryGetValue(SpawnableTeamType.NineTailedFox, out var tickets); - return tickets; - } - - set => RespawnTickets.Singleton._tickets[SpawnableTeamType.NineTailedFox] = value; - } - /// - /// Gets or sets the amount of Respawntickets for the Chaos-Team - /// Please be careful when settings the amount of the ticket since this method ignores whether or - /// not the ticket amount should be locked to zero or not + /// Get/Sets if the Lobby is locked /// - public static int ChaosTickets - { - get { - RespawnTickets.Singleton._tickets.TryGetValue(SpawnableTeamType.ChaosInsurgency, out var tickets); - return tickets; - } + public static bool IsLobbyLocked { get => RoundStart.LobbyLock; set => RoundStart.LobbyLock = value; } - set => RespawnTickets.Singleton._tickets[SpawnableTeamType.ChaosInsurgency] = value; - } - - /// - /// Grants Respawntickets to the MTF-Team - /// - /// The amount of tickets granted - /// Whether or not a existing lock should be ignored - public static void GrantMtfTickets(int tickets, bool overrideLocks = false) - { - RespawnTickets.Singleton.GrantTickets(SpawnableTeamType.NineTailedFox, tickets, overrideLocks); - } - /// - /// Grants Respawntickets to the Chaos-Team + /// The Amount of escaped ClassD`s /// - /// The amount of tickets granted - /// Whether or not a existing lock should be ignored - public static void GrantChaosTickets(int tickets, bool overrideLocks = false) - { - RespawnTickets.Singleton.GrantTickets(SpawnableTeamType.ChaosInsurgency, tickets, overrideLocks); - } - public static int EscapedDs { get => RoundSummary.escaped_ds; set => RoundSummary.escaped_ds = value; } + /// + /// The Amount of escaped Scientists + /// public static int EscapedScientists { get => RoundSummary.escaped_scientists; set => RoundSummary.escaped_scientists = value; } + /// + /// The Amount of kills by Scps + /// public static int KillsByScps { get => RoundSummary.kills_by_scp; set => RoundSummary.kills_by_scp = value; } + /// + /// The Amount of persons changed into Zombies + /// public static int ChangedIntoZombies { get => RoundSummary.changed_into_zombies; set => RoundSummary.changed_into_zombies = value; } /// - /// Activates/Deactivates the LobbyLock (if the Lobby can continue counting down) + /// Restarts the Round /// - public static bool IsLobbyLocked{ get => RoundStart.LobbyLock; set => RoundStart.LobbyLock = value; } - public static void Restart() => Player.Host.PlayerStats.Roundrestart(); + /// + /// Starts the Round + /// public static void Start() => CharacterClassManager.ForceRoundStart(); + /// + /// Spawns Mtf/Chaos + /// + /// public static void MtfRespawn(bool isCI = false) { var component = Server.Host.GetComponent(); diff --git a/Synapse/Api/Server.cs b/Synapse/Api/Server.cs index 348c126..afed9c8 100644 --- a/Synapse/Api/Server.cs +++ b/Synapse/Api/Server.cs @@ -14,9 +14,14 @@ public static class Server private static Broadcast _broadcast; private static BanPlayer _banPlayer; - + /// + /// Gives you the Player object of the Server + /// public static Player Host => Player.Host; + /// + /// Get/Sets the ServerName + /// public static string Name { get => ServerConsole._serverName; @@ -27,8 +32,14 @@ public static string Name } } + /// + /// Get/Sets the Port of the Server + /// public static ushort Port { get => ServerStatic.ServerPort; set => ServerStatic.ServerPort = value; } + /// + /// SpawnMessage MethodInfo + /// public static MethodInfo SendSpawnMessage { get @@ -41,6 +52,9 @@ public static MethodInfo SendSpawnMessage } } + /// + /// The Broadcast object of the Server + /// public static Broadcast Broadcast { get @@ -52,6 +66,9 @@ public static Broadcast Broadcast } } + /// + /// The BanPlayer object of the Server + /// public static BanPlayer BanPlayer { get @@ -63,17 +80,48 @@ public static BanPlayer BanPlayer } } + /// + /// Gives you the ServerConsole + /// public static ServerConsole Console => ServerConsole.singleton; + /// + /// The RemoteAdmin Command Handler + /// + /// + /// You can use it to register Commands + /// public static RemoteAdminCommandHandler RaCommandHandler => CommandProcessor.RemoteAdminCommandHandler; + /// + /// The ServerConsole Command Handler + /// + /// + /// You can use it to register Commands + /// public static GameConsoleCommandHandler GameCoreCommandHandler => GameCore.Console.singleton.ConsoleCommandHandler; + /// + /// The Client Command Handler + /// + /// + /// You can use it to register Commands + /// public static ClientCommandHandler ClientCommandHandler => QueryProcessor.DotCommandHandler; - + /// + /// Gives you a list of all objects with this Type + /// + /// + /// public static List GetObjectsOf() where TObject : UnityEngine.Object => UnityEngine.Object.FindObjectsOfType().ToList(); + /// + /// Gives you the MethodHash + /// + /// + /// + /// 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 index 4810b14..fd12d13 100644 --- a/Synapse/Api/Warhead.cs +++ b/Synapse/Api/Warhead.cs @@ -5,6 +5,9 @@ public static class Warhead private static AlphaWarheadController _controller; private static AlphaWarheadNukesitePanel _nukeSitePanel; + /// + /// Gives you the Decontamination Controller + /// public static AlphaWarheadController Controller { get @@ -16,6 +19,9 @@ public static AlphaWarheadController Controller } } + /// + /// Gives you the NukesiktePanel + /// public static AlphaWarheadNukesitePanel NukeSitePanel { get @@ -27,8 +33,14 @@ public static AlphaWarheadNukesitePanel NukeSitePanel } } + /// + /// Get / Set the LeverStatus + /// public static bool LeverStatus { get => NukeSitePanel.Networkenabled; set => NukeSitePanel.Networkenabled = value; } + /// + /// The Time to Detonation + /// public static float DetonationTimer { get => Controller.NetworktimeToDetonation; @@ -36,17 +48,17 @@ public static float DetonationTimer } /// - /// Is the nuke detonated? + /// Is the Nuke Detonated? /// public static bool IsNukeDetonated => Controller.detonated; /// - /// Is the nuke in progress? + /// Is the Nuke in Progress? /// public static bool IsNukeInProgress => Controller.inProgress; /// - /// Starts the nuke + /// Starts the Nuke /// public static void StartNuke() { @@ -55,15 +67,18 @@ public static void StartNuke() } /// - /// Stops the nuke + /// Stops the Nuke /// public static void StopNuke() => Controller.CancelDetonation(); /// - /// Detonates the nuke + /// Detonates the Nuke /// public static void DetonateNuke() => Controller.Detonate(); + /// + /// Shakes the Screen for all player like when the Nuke explodes + /// public static void Shake() => Controller.RpcShake(true); } } From 55a26e5b1c49d5273c115e75c03c1a14752eeafd Mon Sep 17 00:00:00 2001 From: Helight Date: Sun, 16 Aug 2020 18:38:21 +0200 Subject: [PATCH 04/27] Added Tickets --- Synapse/Api/Round.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Synapse/Api/Round.cs b/Synapse/Api/Round.cs index c20c532..49af41c 100644 --- a/Synapse/Api/Round.cs +++ b/Synapse/Api/Round.cs @@ -34,6 +34,56 @@ public static class Round /// public static bool IsLobbyLocked { get => RoundStart.LobbyLock; set => RoundStart.LobbyLock = value; } + /// + /// Gets or sets the amount of Respawntickets for the MTF-Team + /// Please be careful when settings the amount of the ticket since this method ignores whether or + /// not the ticket amount should be locked to zero or not + /// + public static int MtfTickets + { + get { + RespawnTickets.Singleton._tickets.TryGetValue(SpawnableTeamType.NineTailedFox, out var tickets); + return tickets; + } + + set => RespawnTickets.Singleton._tickets[SpawnableTeamType.NineTailedFox] = value; + } + + /// + /// Gets or sets the amount of Respawntickets for the Chaos-Team + /// Please be careful when settings the amount of the ticket since this method ignores whether or + /// not the ticket amount should be locked to zero or not + /// + public static int ChaosTickets + { + get { + RespawnTickets.Singleton._tickets.TryGetValue(SpawnableTeamType.ChaosInsurgency, out var tickets); + return tickets; + } + + set => RespawnTickets.Singleton._tickets[SpawnableTeamType.ChaosInsurgency] = value; + } + + /// + /// Grants Respawntickets to the MTF-Team + /// + /// The amount of tickets granted + /// Whether or not a existing lock should be ignored + public static void GrantMtfTickets(int tickets, bool overrideLocks = false) + { + RespawnTickets.Singleton.GrantTickets(SpawnableTeamType.NineTailedFox, tickets, overrideLocks); + } + + /// + /// Grants Respawntickets to the Chaos-Team + /// + /// The amount of tickets granted + /// Whether or not a existing lock should be ignored + public static void GrantChaosTickets(int tickets, bool overrideLocks = false) + { + RespawnTickets.Singleton.GrantTickets(SpawnableTeamType.ChaosInsurgency, tickets, overrideLocks); + } + /// /// The Amount of escaped ClassD`s /// From 486b1be7c4cf5435544072dd85b77a7cb5c2cb94 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 16 Aug 2020 19:48:58 +0200 Subject: [PATCH 05/27] added Server.GetObjectOf<>(),Warhead.OutsidePanel,Warhead.Enabled and fixed NukesitePanel = null bug --- Synapse/Api/Server.cs | 2 ++ Synapse/Api/Warhead.cs | 16 +++++++++++++++- Synapse/Events/EventHandlers.cs | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Synapse/Api/Server.cs b/Synapse/Api/Server.cs index afed9c8..325aee8 100644 --- a/Synapse/Api/Server.cs +++ b/Synapse/Api/Server.cs @@ -116,6 +116,8 @@ public static BanPlayer BanPlayer /// public static List GetObjectsOf() where TObject : UnityEngine.Object => UnityEngine.Object.FindObjectsOfType().ToList(); + public static TObject GetObjectOf() where TObject : UnityEngine.Object => UnityEngine.Object.FindObjectOfType(); + /// /// Gives you the MethodHash /// diff --git a/Synapse/Api/Warhead.cs b/Synapse/Api/Warhead.cs index fd12d13..fae5a6a 100644 --- a/Synapse/Api/Warhead.cs +++ b/Synapse/Api/Warhead.cs @@ -4,6 +4,7 @@ public static class Warhead { private static AlphaWarheadController _controller; private static AlphaWarheadNukesitePanel _nukeSitePanel; + private static AlphaWarheadOutsitePanel _outsidepanel; /// /// Gives you the Decontamination Controller @@ -27,12 +28,25 @@ public static AlphaWarheadNukesitePanel NukeSitePanel get { if (_nukeSitePanel == null) - _nukeSitePanel = Player.Host.GetComponent(); + _nukeSitePanel = Server.GetObjectOf(); return _nukeSitePanel; } } + public static AlphaWarheadOutsitePanel OutsitePanel + { + get + { + if (_outsidepanel == null) + _outsidepanel = Server.GetObjectOf(); + + return _outsidepanel; + } + } + + public static bool Enabled { get => NukeSitePanel.Networkenabled; set => NukeSitePanel.Networkenabled = value; } + /// /// Get / Set the LeverStatus /// diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index 28cd926..e67daba 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -2,6 +2,7 @@ using Synapse.Events.Classes; using Synapse.Config; using UnityEngine; +using Synapse.Api; namespace Synapse.Events { @@ -14,6 +15,13 @@ public EventHandlers() Events.SyncDataEvent += OnSyncData; Events.DoorInteractEvent += OnDoorInteract; Events.PlayerJoinEvent += OnPlayerJoin; + Events.KeyPressEvent += OnKeyPress; + } + + private void OnKeyPress(KeyPressEvent ev) + { + if (ev.Key == KeyCode.Alpha1) + Warhead.Locked = true; } // Methods From 7af06c9b13486dc74c64f4a7af9b458089dba2f2 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 16 Aug 2020 20:04:36 +0200 Subject: [PATCH 06/27] added Player.HideRank (Removed showtag() and hidetag()) --- Synapse/Api/Player.cs | 26 +++++++++++++++----------- Synapse/Events/EventHandlers.cs | 7 ------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index ceebb97..8b5097b 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -343,6 +343,21 @@ public Player Cuffer /// Note: This will not change the permissions public string RankName { get => Rank.BadgeText; set => Hub.serverRoles.SetText(value); } + /// + /// Get/Set if the Rank/Badge of the Player is hidden + /// + public bool HideRank + { + get => string.IsNullOrEmpty(ServerRoles.HiddenBadge); + set + { + if (value) + ClassManager.CmdRequestHideTag(); + else + ClassManager.CallCmdRequestShowTag(false); + } + } + /// /// The Permission of the Player /// @@ -505,17 +520,6 @@ public void InstantBroadcast(ushort time, string message) /// public void SendRAConsoleMessage(string message, bool success = true, RaCategory type = RaCategory.None) => CommandSender.RaMessage(message, success, type); - /// - /// Hides for normal player the RankName the player has - /// - public void HideTag() => ClassManager.CallCmdRequestHideTag(); - - /// - /// Shows everyone the RankName the player has - /// - /// - public void ShowTag(bool global = false) => ClassManager.CallCmdRequestShowTag(global); - /// /// Gives the player a item /// diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index e67daba..ee51c0a 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -15,13 +15,6 @@ public EventHandlers() Events.SyncDataEvent += OnSyncData; Events.DoorInteractEvent += OnDoorInteract; Events.PlayerJoinEvent += OnPlayerJoin; - Events.KeyPressEvent += OnKeyPress; - } - - private void OnKeyPress(KeyPressEvent ev) - { - if (ev.Key == KeyCode.Alpha1) - Warhead.Locked = true; } // Methods From 171bd7252236627121caafb5da382bccf4eb7c4c Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 16 Aug 2020 20:07:23 +0200 Subject: [PATCH 07/27] added Player.ToString() --- Synapse/Api/Player.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 8b5097b..6c1ebde 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -645,5 +645,7 @@ public void ShakeScreen(bool achieve = false) Connection.Send(msg); NetworkWriterPool.Recycle(writer); } + + public override string ToString() => NickName; } } From 9e8cad9b624654e7a8b479f15601155c606d858c Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 16 Aug 2020 20:29:19 +0200 Subject: [PATCH 08/27] added Player.Fraction --- Synapse/Api/Player.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 6c1ebde..e57842c 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -240,6 +240,11 @@ public Team Side } } } + + /// + /// Gives you the Fraction of the Player + /// + public Fraction Fraction => ClassManager.Fraction; /// /// The Room where the player currently is From 9e754de52e27e974a78bac55c3dc456b78e90b25 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 16 Aug 2020 20:33:36 +0200 Subject: [PATCH 09/27] added Player.DeathPosition --- Synapse/Api/Player.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index e57842c..6224cbd 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -185,6 +185,11 @@ public Vector3 Scale /// public Vector2 Rotation { get => MovementSync.RotationSync; set => Hub.playerMovementSync.RotationSync = value; } + /// + /// Get / Set the Last Position the Player died + /// + public Vector3 DeathPosition { get => ClassManager.DeathPosition; set => ClassManager.DeathPosition = value; } + /// /// The health of the player /// From c39835cb419ee0b06e8f5fa94eb797ca5396464c Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sun, 16 Aug 2020 20:36:22 +0200 Subject: [PATCH 10/27] added Player.AliveTime + Player.AuthToken --- Synapse/Api/Player.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 6224cbd..89f289d 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -393,6 +393,16 @@ public bool HideRank /// public int Ping => LiteNetLib4MirrorServer.Peers[Connection.connectionId].Ping; + /// + /// Gives you the AuthToken of the Player + /// + public string AuthToken => ClassManager.AuthToken; + + /// + /// Gives you the time since the Player last died + /// + public float AliveTime => ClassManager.AliveTime; + /// /// The rotation float of the player /// From ab8daecff0b77875d4aa2a3b9c632f377eaefcd6 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 17 Aug 2020 15:35:01 +0200 Subject: [PATCH 11/27] Fixed Player.ChangeRoleAtPosition --- Synapse/Api/Player.cs | 8 ++++++-- .../Patches/SynapsePatches/RolePositionPatch.cs | 17 +++++++++++++++++ Synapse/Synapse.csproj | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Synapse/Events/Patches/SynapsePatches/RolePositionPatch.cs diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 89f289d..a6b99ae 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -9,6 +9,7 @@ using Searching; using Synapse.Api.Enums; using Synapse.Config; +using Synapse.Events.Patches.SynapsePatches; using UnityEngine; namespace Synapse.Api @@ -464,10 +465,13 @@ public bool HideRank /// public void Kill(DamageTypes.DamageType damageType = default) => Hub.playerStats.HurtPlayer(new PlayerStats.HitInfo(-1f, "WORLD", damageType, 0), gameObject); - [Obsolete("Does not work properly")] + /// + /// Changes The Role of the Player without Changing his Items/Position/Health + /// + /// public void ChangeRoleAtPosition(RoleType role) { - //TODO: Fix this shit + RolePositionPatch.Lite = true; Hub.characterClassManager.SetClassIDAdv(role, true); } diff --git a/Synapse/Events/Patches/SynapsePatches/RolePositionPatch.cs b/Synapse/Events/Patches/SynapsePatches/RolePositionPatch.cs new file mode 100644 index 0000000..f9786e0 --- /dev/null +++ b/Synapse/Events/Patches/SynapsePatches/RolePositionPatch.cs @@ -0,0 +1,17 @@ +using Harmony; + +namespace Synapse.Events.Patches.SynapsePatches +{ + [HarmonyPatch(typeof(CharacterClassManager), nameof(CharacterClassManager.SetClassID))] + public static class RolePositionPatch + { + internal static bool Lite = false; + + public static bool Prefix(CharacterClassManager __instance, RoleType id) + { + __instance.SetClassIDAdv(id, Lite, false); + Lite = false; + return false; + } + } +} diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 3e5c4da..2ddb29a 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -95,6 +95,7 @@ + From 8b414135caf59a14e40b4f679b9c3e1b4a1a5817 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Mon, 17 Aug 2020 17:23:32 +0200 Subject: [PATCH 12/27] added Player.CurrentItem --- Synapse/Api/Player.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index a6b99ae..0e216ea 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -294,6 +294,8 @@ public Room Room /// public Inventory.SyncListItemInfo Items { get => Inventory.items; set => Inventory.items = value; } + public Inventory.SyncItemInfo CurrentItem { get => Inventory.GetItemInHand(); } + /// /// The person who cuffed the player /// @@ -303,6 +305,7 @@ public Player Cuffer get => GetPlayer(Handcuffs.CufferId); set { + var handcuff = value.Handcuffs; if (handcuff == null) return; From 9fc1b00455f3f28e4d7aef408fa8f4b14bd6f8e7 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 18 Aug 2020 15:39:32 +0200 Subject: [PATCH 13/27] added Scp096AddTarget Event --- Synapse/Events/Classes/Scp096AddTarget.cs | 15 +++++++ .../EventPatches/ScpPatches/Scp096Target.cs | 45 +++++++++++++++++++ Synapse/Events/ScpEvents.cs | 23 ++++++++-- Synapse/Properties/AssemblyInfo.cs | 4 +- Synapse/Synapse.cs | 4 +- Synapse/Synapse.csproj | 2 + 6 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 Synapse/Events/Classes/Scp096AddTarget.cs create mode 100644 Synapse/Events/Patches/EventPatches/ScpPatches/Scp096Target.cs diff --git a/Synapse/Events/Classes/Scp096AddTarget.cs b/Synapse/Events/Classes/Scp096AddTarget.cs new file mode 100644 index 0000000..8683ff9 --- /dev/null +++ b/Synapse/Events/Classes/Scp096AddTarget.cs @@ -0,0 +1,15 @@ +using Synapse.Api; + +namespace Synapse.Events.Classes +{ + public class Scp096AddTarget + { + public Player Player { get; internal set; } + + public Player ShyGuy { get; internal set; } + + public PlayableScps.Scp096PlayerState RageState { get; internal set; } + + public bool Allow { get; set; } + } +} diff --git a/Synapse/Events/Patches/EventPatches/ScpPatches/Scp096Target.cs b/Synapse/Events/Patches/EventPatches/ScpPatches/Scp096Target.cs new file mode 100644 index 0000000..009b4bc --- /dev/null +++ b/Synapse/Events/Patches/EventPatches/ScpPatches/Scp096Target.cs @@ -0,0 +1,45 @@ +using System; +using Harmony; +using PlayableScps; +using Synapse.Api; + +namespace Synapse.Events.Patches.EventPatches.ScpPatches +{ + [HarmonyPatch(typeof(Scp096), nameof(Scp096.ParseVisionInformation))] + static class Scp096LookPatch + { + public static bool Prefix(Scp096 __instance ,VisionInformation info) + { + try + { + var allow = true; + Events.InvokeScp096AddTarget(info.Source.GetPlayer(), __instance.GetPlayer(), __instance.PlayerState, ref allow); + return allow; + } + catch(Exception e) + { + Log.Info($"Scp096AddTarget Event Error: {e}"); + return true; + } + } + } + + [HarmonyPatch(typeof(Scp096), nameof(Scp096.OnDamage))] + static class Scp096ShootPatch + { + public static bool Prefix(Scp096 __instance, PlayerStats.HitInfo info) + { + try + { + var allow = true; + Events.InvokeScp096AddTarget(info.RHub.GetPlayer(), __instance.GetPlayer(), __instance.PlayerState, ref allow); + return allow; + } + catch (Exception e) + { + Log.Info($"Scp096AddTarget Event Error: {e}"); + return true; + } + } + } +} diff --git a/Synapse/Events/ScpEvents.cs b/Synapse/Events/ScpEvents.cs index 0ad4a4a..a20f4f4 100644 --- a/Synapse/Events/ScpEvents.cs +++ b/Synapse/Events/ScpEvents.cs @@ -8,7 +8,6 @@ public static partial class Events /// A Event which is activated when Scp049 respawns a Player public delegate void OnScp049Recall(Scp049RecallEvent ev); public static event OnScp049Recall Scp049RecallEvent; - internal static void InvokeScp049RecallEvent(Player player, ref Ragdoll ragdoll, ref Player target, ref bool allow, ref RoleType role, ref float lives) { @@ -53,7 +52,6 @@ internal static void InvokePocketDimensionEnterEvent(Player player, ref bool all public delegate void OnScp106Containment(Scp106ContainmentEvent ev); public static event OnScp106Containment Scp106ContainmentEvent; - internal static void InvokeScp106ContainmentEvent(Player player, ref bool allow) { if (Scp106ContainmentEvent == null) return; @@ -90,9 +88,7 @@ internal static void InvokeScp079LvlEvent(Player player,ref int newlvl,ref bool } public delegate void OnScp106CreatePortal(Scp106CreatePortalEvent ev); - public static event OnScp106CreatePortal Scp106CreatePortalEvent; - internal static void InvokeScp106CreatePortalEvent(Player player, ref bool allow) { var ev = new Scp106CreatePortalEvent @@ -105,5 +101,24 @@ internal static void InvokeScp106CreatePortalEvent(Player player, ref bool allow allow = ev.Allow; } + + public delegate void OnScp096AddTarget(Scp096AddTarget ev); + public static event OnScp096AddTarget Scp096AddTarget; + internal static void InvokeScp096AddTarget(Player player,Player shyguy,PlayableScps.Scp096PlayerState state,ref bool allow) + { + if (Scp096AddTarget == null) return; + + var ev = new Scp096AddTarget() + { + Player = player, + ShyGuy = shyguy, + RageState = state, + Allow = allow + }; + + Scp096AddTarget.Invoke(ev); + + allow = ev.Allow; + } } } \ No newline at end of file diff --git a/Synapse/Properties/AssemblyInfo.cs b/Synapse/Properties/AssemblyInfo.cs index 0736dca..48e8c00 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.3.0")] +[assembly: AssemblyFileVersion("1.3.0")] \ No newline at end of file diff --git a/Synapse/Synapse.cs b/Synapse/Synapse.cs index 83f012b..42688fa 100644 --- a/Synapse/Synapse.cs +++ b/Synapse/Synapse.cs @@ -17,8 +17,8 @@ public static class Synapse { #region Version private const int MajorVersion = 1; - private const int MinorVersion = 2; - private const int Patch = 1; + private const int MinorVersion = 3; + private const int Patch = 0; public static int VersionNumber => MajorVersion * 100 + MinorVersion * 10 + Patch; public static string Version => $"{MajorVersion}.{MinorVersion}.{Patch}"; diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 2ddb29a..ad6ee4a 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -89,11 +89,13 @@ + + From 5a5418e074b4518a00faf1ca2afd2c2e8062244d Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 22 Aug 2020 08:25:16 +0200 Subject: [PATCH 14/27] added Dummy Object --- Synapse/Api/Dummy.cs | 94 +++++++++++++++++++++++++++++++++ Synapse/Api/Map.cs | 1 - Synapse/Events/EventHandlers.cs | 47 +++++++++++++++++ Synapse/Synapse.csproj | 1 + 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 Synapse/Api/Dummy.cs diff --git a/Synapse/Api/Dummy.cs b/Synapse/Api/Dummy.cs new file mode 100644 index 0000000..b13196e --- /dev/null +++ b/Synapse/Api/Dummy.cs @@ -0,0 +1,94 @@ +using Mirror; +using RemoteAdmin; +using System.Linq; +using UnityEngine; + +namespace Synapse.Api +{ + public class Dummy + { + private ItemType helditem; + private GameObject gameObject; + + public RoleType Role + { + get => gameObject.GetComponent().CurClass; + set + { + Despawn(); + gameObject.GetComponent().CurClass = value; + Spawn(); + } + } + + public string Name + { + get => gameObject.GetComponent().Network_myNickSync; + set => gameObject.GetComponent().Network_myNickSync = value; + } + + public Vector3 Position + { + get => gameObject.transform.position; + set + { + Despawn(); + gameObject.transform.position = value; + Spawn(); + } + } + + public ItemType HeldItem + { + get => helditem; + set + { + gameObject.GetComponent().SetCurItem(value); + helditem = value; + } + } + + public string BadgeName + { + get => gameObject.GetComponent().MyText; + set => gameObject.GetComponent().SetText(value); + } + + public string BadgeColor + { + get => gameObject.GetComponent().MyColor; + set => gameObject.GetComponent().SetColor(value); + } + + + public Dummy(Vector3 pos, Quaternion rot, RoleType role = RoleType.ClassD, string name = "(null)",string badgetext = "",string badgecolor = "") + { + GameObject obj = + Object.Instantiate( + NetworkManager.singleton.spawnPrefabs.FirstOrDefault(p => p.gameObject.name == "Player")); + + if (obj.GetComponent() == null) + obj.AddComponent(); + + gameObject = obj; + + obj.GetComponent().CurClass = role; + obj.GetComponent().Network_myNickSync = name; + gameObject.GetComponent().MyText = badgetext; + gameObject.GetComponent().MyColor = badgecolor; + obj.transform.localScale = Vector3.one; + obj.transform.position = pos; + obj.GetComponent().NetworkPlayerId = 9999; + obj.GetComponent().PlayerId = 9999; + + NetworkServer.Spawn(obj); + ReferenceHub.Hubs.Remove(obj); + } + + public void Despawn() => NetworkServer.UnSpawn(gameObject); + + public void Spawn() => NetworkServer.Spawn(gameObject); + + public void Destroy() => Object.Destroy(gameObject); + } +} diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 14aaf92..e4d1f32 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -15,7 +15,6 @@ public static class Map private static Broadcast BroadcastComponent => Player.Host.GetComponent(); - /// /// Activates/Deactivates the FriendlyFire on the server /// diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index ee51c0a..c716185 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -3,6 +3,7 @@ using Synapse.Config; using UnityEngine; using Synapse.Api; +using MEC; namespace Synapse.Events { @@ -15,8 +16,54 @@ public EventHandlers() Events.SyncDataEvent += OnSyncData; Events.DoorInteractEvent += OnDoorInteract; Events.PlayerJoinEvent += OnPlayerJoin; + + //KeyPressEvent for Testing many different things easy with a singel Key Press! + #if DEBUG + Events.KeyPressEvent += OnKey; + #endif } + private void OnKey(KeyPressEvent ev) + { + if (ev.Key == KeyCode.Alpha1) + { + var dm = new Dummy(ev.Player.Position, Quaternion.identity, ev.Player.Role, "first","First","yellow"); + dm.Name = "second"; + dm.HeldItem = ItemType.GunLogicer; + var pos = ev.Player.Position; + pos.y += 2; + dm.Position = pos; + dm.Role = RoleType.Scientist; + + Timing.CallDelayed(2f, () => + { + dm.BadgeName = "TestBadge"; + }); + + Timing.CallDelayed(5f, () => + { + dm.BadgeColor = "red"; + }); + + Timing.CallDelayed(10f, () => dm.Destroy()); + } + if (ev.Key == KeyCode.Alpha2) + { + var msg = ""; + foreach (var player in Player.GetAllPlayers()) + msg += $"\n{player}"; + + ev.Player.SendConsoleMessage(msg); + } + if (ev.Key == KeyCode.Alpha3) + { + var msg = ""; + foreach (var player in ReferenceHub.GetAllHubs()) + msg += $"\n{player}"; + + ev.Player.SendConsoleMessage(msg); + } + } // Methods private void OnPlayerJoin(PlayerJoinEvent ev) { diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index ad6ee4a..a54136d 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -70,6 +70,7 @@ + From e5c71711c4b16ae289138c92fa4a75aeb8fcfdfe Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 22 Aug 2020 08:29:33 +0200 Subject: [PATCH 15/27] i knew i forgot something --- Synapse/Api/Dummy.cs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/Synapse/Api/Dummy.cs b/Synapse/Api/Dummy.cs index b13196e..f3fbb46 100644 --- a/Synapse/Api/Dummy.cs +++ b/Synapse/Api/Dummy.cs @@ -10,6 +10,9 @@ public class Dummy private ItemType helditem; private GameObject gameObject; + /// + /// Get / Set the Current Role of the Dummy + /// public RoleType Role { get => gameObject.GetComponent().CurClass; @@ -21,12 +24,19 @@ public RoleType Role } } + /// + /// Get / Set the Current Name of the Dummy + /// public string Name { get => gameObject.GetComponent().Network_myNickSync; set => gameObject.GetComponent().Network_myNickSync = value; } + + /// + /// Get / Set the Current Position of the Dummy + /// public Vector3 Position { get => gameObject.transform.position; @@ -38,6 +48,10 @@ public Vector3 Position } } + + /// + /// Get / Set the Current Item the Dummy is holding + /// public ItemType HeldItem { get => helditem; @@ -48,19 +62,33 @@ public ItemType HeldItem } } + /// + /// Get / Set the BadgeText of the Dummy + /// public string BadgeName { get => gameObject.GetComponent().MyText; set => gameObject.GetComponent().SetText(value); } + /// + /// Get / Set the BadgeCOlor of the Dummy + /// public string BadgeColor { get => gameObject.GetComponent().MyColor; set => gameObject.GetComponent().SetColor(value); } - + /// + /// Creates a New Dummy and Spawn it + /// + /// The Position where the Dummy should spawn + /// The Rotation of the Dummy + /// The Role which the Dummy should be + /// The Name of the Dummy + /// The Displayed BadgeTeyt of the Dummy + /// The Displayed BadgeColor of the Dummy public Dummy(Vector3 pos, Quaternion rot, RoleType role = RoleType.ClassD, string name = "(null)",string badgetext = "",string badgecolor = "") { GameObject obj = @@ -85,10 +113,19 @@ public Dummy(Vector3 pos, Quaternion rot, RoleType role = RoleType.ClassD, strin ReferenceHub.Hubs.Remove(obj); } + /// + /// Despawns the Dummy + /// public void Despawn() => NetworkServer.UnSpawn(gameObject); + /// + /// Spawns the Dummy again after Despawning + /// public void Spawn() => NetworkServer.Spawn(gameObject); + /// + /// Destroys the Object + /// public void Destroy() => Object.Destroy(gameObject); } } From 6c8284d44fb4205fdc434b6084cac7b477f66ef9 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 22 Aug 2020 08:38:00 +0200 Subject: [PATCH 16/27] fixed that new Dummy(Quaternion rot) is not used --- Synapse/Api/Dummy.cs | 1 + Synapse/Events/EventHandlers.cs | 65 +++++++++++++++++---------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Synapse/Api/Dummy.cs b/Synapse/Api/Dummy.cs index f3fbb46..521ff25 100644 --- a/Synapse/Api/Dummy.cs +++ b/Synapse/Api/Dummy.cs @@ -106,6 +106,7 @@ public Dummy(Vector3 pos, Quaternion rot, RoleType role = RoleType.ClassD, strin gameObject.GetComponent().MyColor = badgecolor; obj.transform.localScale = Vector3.one; obj.transform.position = pos; + obj.transform.rotation = rot; obj.GetComponent().NetworkPlayerId = 9999; obj.GetComponent().PlayerId = 9999; diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index c716185..ff96166 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -23,11 +23,40 @@ public EventHandlers() #endif } + // Methods + private void OnPlayerJoin(PlayerJoinEvent ev) + { + ev.Player.Broadcast(SynapseConfigs.JoinMessageDuration, SynapseConfigs.JoinBroadcast); + ev.Player.GiveTextHint(SynapseConfigs.JoinTextHint, SynapseConfigs.JoinMessageDuration); + } + + private static void OnDoorInteract(DoorInteractEvent ev) + { + if (!SynapseConfigs.RemoteKeyCard) return; + if (ev.Allow) return; + + if (!ev.Player.Items.Any()) return; + foreach (var gameItem in ev.Player.Items.Select(item => ev.Player.Inventory.GetItemByID(item.id)).Where(gameitem => gameitem.permissions != null && gameitem.permissions.Length != 0)) + { + ev.Allow = gameItem.permissions.Any(p => + Door.backwardsCompatPermissions.TryGetValue(p, out var flag) && + ev.Door.PermissionLevels.HasPermission(flag)); + } + } + + private static void OnSyncData(SyncDataEvent ev) + { + if (ev.Player.Role != RoleType.ClassD && + ev.Player.Role != RoleType.Scientist && + !(Vector3.Distance(ev.Player.Position, ev.Player.GetComponent().worldPosition) >= Escape.radius)) + ev.Player.Hub.characterClassManager.CmdRegisterEscape(); + } + private void OnKey(KeyPressEvent ev) { if (ev.Key == KeyCode.Alpha1) { - var dm = new Dummy(ev.Player.Position, Quaternion.identity, ev.Player.Role, "first","First","yellow"); + var dm = new Dummy(ev.Player.Position, Quaternion.identity, ev.Player.Role, "first", "First", "yellow"); dm.Name = "second"; dm.HeldItem = ItemType.GunLogicer; var pos = ev.Player.Position; @@ -36,9 +65,9 @@ private void OnKey(KeyPressEvent ev) dm.Role = RoleType.Scientist; Timing.CallDelayed(2f, () => - { - dm.BadgeName = "TestBadge"; - }); + { + dm.BadgeName = "TestBadge"; + }); Timing.CallDelayed(5f, () => { @@ -64,33 +93,5 @@ private void OnKey(KeyPressEvent ev) ev.Player.SendConsoleMessage(msg); } } - // Methods - private void OnPlayerJoin(PlayerJoinEvent ev) - { - ev.Player.Broadcast(SynapseConfigs.JoinMessageDuration, SynapseConfigs.JoinBroadcast); - ev.Player.GiveTextHint(SynapseConfigs.JoinTextHint, SynapseConfigs.JoinMessageDuration); - } - - private static void OnDoorInteract(DoorInteractEvent ev) - { - if (!SynapseConfigs.RemoteKeyCard) return; - if (ev.Allow) return; - - if (!ev.Player.Items.Any()) return; - foreach (var gameItem in ev.Player.Items.Select(item => ev.Player.Inventory.GetItemByID(item.id)).Where(gameitem => gameitem.permissions != null && gameitem.permissions.Length != 0)) - { - ev.Allow = gameItem.permissions.Any(p => - Door.backwardsCompatPermissions.TryGetValue(p, out var flag) && - ev.Door.PermissionLevels.HasPermission(flag)); - } - } - - private static void OnSyncData(SyncDataEvent ev) - { - if (ev.Player.Role != RoleType.ClassD && - ev.Player.Role != RoleType.Scientist && - !(Vector3.Distance(ev.Player.Position, ev.Player.GetComponent().worldPosition) >= Escape.radius)) - ev.Player.Hub.characterClassManager.CmdRegisterEscape(); - } } } \ No newline at end of file From 4a97860d07b0ba79a231452eee1ce037fd8f5e0e Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 22 Aug 2020 08:43:22 +0200 Subject: [PATCH 17/27] added Dummy.Scale --- Synapse/Api/Dummy.cs | 11 ++++++++++- Synapse/Events/EventHandlers.cs | 1 + Synapse/Synapse.csproj | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Synapse/Api/Dummy.cs b/Synapse/Api/Dummy.cs index 521ff25..95fbd8e 100644 --- a/Synapse/Api/Dummy.cs +++ b/Synapse/Api/Dummy.cs @@ -33,7 +33,6 @@ public string Name set => gameObject.GetComponent().Network_myNickSync = value; } - /// /// Get / Set the Current Position of the Dummy /// @@ -48,6 +47,16 @@ public Vector3 Position } } + public Vector3 Scale + { + get => gameObject.transform.localScale; + set + { + Despawn(); + gameObject.transform.localScale = value; + Spawn(); + } + } /// /// Get / Set the Current Item the Dummy is holding diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index ff96166..54f9562 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -66,6 +66,7 @@ private void OnKey(KeyPressEvent ev) Timing.CallDelayed(2f, () => { + dm.Scale = Vector3.one * 2; dm.BadgeName = "TestBadge"; }); diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index a54136d..79a6f3b 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -49,7 +49,7 @@ ..\..\Synapse_Dependencies\Mirror.dll - + ..\..\Synapse_Dependencies\NorthwoodLib.dll From 2a9e64354d9b692c7a1b32803ed465a94988ab8b Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 22 Aug 2020 09:09:51 +0200 Subject: [PATCH 18/27] added MapPoint Object --- Synapse/Api/Dummy.cs | 3 ++ Synapse/Api/Extensions.cs | 8 ++++ Synapse/Api/MapPoint.cs | 91 +++++++++++++++++++++++++++++++++++++++ Synapse/Synapse.csproj | 1 + 4 files changed, 103 insertions(+) create mode 100644 Synapse/Api/MapPoint.cs diff --git a/Synapse/Api/Dummy.cs b/Synapse/Api/Dummy.cs index 95fbd8e..f1b2ef9 100644 --- a/Synapse/Api/Dummy.cs +++ b/Synapse/Api/Dummy.cs @@ -47,6 +47,9 @@ public Vector3 Position } } + /// + /// Get / Set the Scale of the Dummy + /// public Vector3 Scale { get => gameObject.transform.localScale; diff --git a/Synapse/Api/Extensions.cs b/Synapse/Api/Extensions.cs index fec0f08..a7cc53e 100644 --- a/Synapse/Api/Extensions.cs +++ b/Synapse/Api/Extensions.cs @@ -97,5 +97,13 @@ public static Player GetPlayer(this ICommandSender sender) 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; + + public static MapPoint GetMapPoint(this YamlConfig config,string key,MapPoint def = null) + { + if (MapPoint.TryParse(config.GetString(key),out var point)) + return point; + + return def; + } } } \ No newline at end of file diff --git a/Synapse/Api/MapPoint.cs b/Synapse/Api/MapPoint.cs new file mode 100644 index 0000000..8a768df --- /dev/null +++ b/Synapse/Api/MapPoint.cs @@ -0,0 +1,91 @@ +using System; +using System.Linq; +using UnityEngine; + +namespace Synapse.Api +{ + public class MapPoint + { + /// + /// Tries to Parse a string to a MapPoint + /// + /// The string you try to parse + /// The MapPoint you Parse + /// If the Parsing was sucesfully and mapPoint is not null + public static bool TryParse(string mappointstring, out MapPoint mapPoint) + { + try + { + mapPoint = Parse(mappointstring); + return true; + } + catch + { + mapPoint = null; + return false; + } + } + + /// + /// Parses a string to a MapPoint + /// + /// The String you want to Parse + /// The MapPoint which was parsed + public static MapPoint Parse(string mappointstring) => new MapPoint(mappointstring); + + /// + /// Creates a MapPoint + /// + /// The Room the MapPoint is realtive too + /// The Position you want to get the MapPoint of + public MapPoint(Room room, Vector3 position) + { + if (position == null) throw new ArgumentNullException("position", "The Argument position of the Constructor MapPoint(Room room,Vector3 position) is null"); + if (room == null) throw new ArgumentNullException("room", "The Argument Room of the Constructor MapPoint(Room room,Vector3 position) is null"); + + Room = room; + RelativePosition = Room.Transform.InverseTransformPoint(position); + } + + /// + /// Creates a MapPoint + /// + /// The String from which you want to create a MapPoint of + public MapPoint(string mappointstring) + { + string[] args = mappointstring.Split(':'); + if (args.Count() < 4) throw new IndexOutOfRangeException("Parsing of string to MapPoint failed because there was missing informations!He need to look like this: \"Roomname:1,434:-2,346456:1,6554\""); + var room = Map.Rooms.FirstOrDefault(r => r.Name.ToLower() == args[0].ToLower()); + if (room == null) throw new Exception("Parsing of string to MapPoint failed because of the roomname"); + + if (!float.TryParse(args[1], out var x)) throw new Exception("Parsing of string to MapPoint failed because of the Relative x Position!"); + if (!float.TryParse(args[2], out var y)) throw new Exception("Parsing of string to MapPoint failed because of the Relative y Position!"); + if (!float.TryParse(args[3], out var z)) throw new Exception("Parsing of string to MapPoint failed because of the Relative z Position!"); + + Room = room; + RelativePosition = new Vector3(x, y, z); + } + + + /// + /// The Room of which the MapPoint is relative too + /// + public readonly Room Room; + + /// + /// The Relative Position of the MapPoint to the Room + /// + public readonly Vector3 RelativePosition; + + /// + /// The Calculated end Position on the Map + /// + public Vector3 Position { get => Room.Transform.TransformPoint(RelativePosition); } + + /// + /// The MapPoint as a String + /// + /// + public override string ToString() => $"{Room.Name}:{RelativePosition.x}:{RelativePosition.y}:{RelativePosition.z}"; + } +} diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 79a6f3b..a5743a9 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -70,6 +70,7 @@ + From e77404392adc2130029800ebcdc8f1f9ebe74922 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Thu, 27 Aug 2020 14:53:43 +0200 Subject: [PATCH 19/27] added ShootEvent --- Synapse/Events/Classes/ShootEvent.cs | 16 ++++++++ .../EventPatches/PlayerPatches/ShootPatch.cs | 38 +++++++++++++++++++ Synapse/Events/PlayerEvents.cs | 21 ++++++++++ Synapse/Synapse.csproj | 2 + 4 files changed, 77 insertions(+) create mode 100644 Synapse/Events/Classes/ShootEvent.cs create mode 100644 Synapse/Events/Patches/EventPatches/PlayerPatches/ShootPatch.cs diff --git a/Synapse/Events/Classes/ShootEvent.cs b/Synapse/Events/Classes/ShootEvent.cs new file mode 100644 index 0000000..0232a29 --- /dev/null +++ b/Synapse/Events/Classes/ShootEvent.cs @@ -0,0 +1,16 @@ +using Synapse.Api; +using UnityEngine; + +namespace Synapse.Events.Classes +{ + public class ShootEvent + { + public Player Player { get; internal set; } + + public Player Target { get; internal set; } + + public Vector3 TargetPosition { get; set; } + + public bool Allow { get; set; } + } +} diff --git a/Synapse/Events/Patches/EventPatches/PlayerPatches/ShootPatch.cs b/Synapse/Events/Patches/EventPatches/PlayerPatches/ShootPatch.cs new file mode 100644 index 0000000..7fcb08a --- /dev/null +++ b/Synapse/Events/Patches/EventPatches/PlayerPatches/ShootPatch.cs @@ -0,0 +1,38 @@ +using System; +using Harmony; +using Synapse.Api; +using UnityEngine; + +namespace Synapse.Events.Patches.EventPatches.PlayerPatches +{ + [HarmonyPatch(typeof(WeaponManager), nameof(WeaponManager.CallCmdShoot))] + static class ShootPatch + { + private static bool Prefix(WeaponManager __instance, GameObject target, string hitboxType, Vector3 dir, Vector3 sourcePos, Vector3 targetPos) + { + try + { + if (!__instance._iawRateLimit.CanExecute(true)) + return false; + int itemIndex = __instance._hub.inventory.GetItemIndex(); + if (itemIndex < 0 || itemIndex >= __instance._hub.inventory.items.Count || __instance.curWeapon < 0 || + ((__instance._reloadCooldown > 0.0 || __instance._fireCooldown > 0.0) && + !__instance.isLocalPlayer) || + (__instance._hub.inventory.curItem != __instance.weapons[__instance.curWeapon].inventoryID || + __instance._hub.inventory.items[itemIndex].durability <= 0.0)) + return false; + + //Event Invoke + Events.InvokeShootEvent(__instance.GetPlayer(), target.GetPlayer(), ref targetPos, out var allow); + + return allow; + } + catch (Exception e) + { + Log.Error($"Shoot Event Error: {e}"); + + return true; + } + } + } +} diff --git a/Synapse/Events/PlayerEvents.cs b/Synapse/Events/PlayerEvents.cs index e697ed2..e9037af 100644 --- a/Synapse/Events/PlayerEvents.cs +++ b/Synapse/Events/PlayerEvents.cs @@ -492,5 +492,26 @@ internal static void InvokePlayerThrowGrenadeEvent(Player player, ItemType type, time = ev.FuseTime; } + + + public delegate void OnShoot(ShootEvent ev); + public static event OnShoot ShootEvent; + internal static void InvokeShootEvent(Player player,Player target,ref Vector3 targetpos,out bool allow) + { + allow = true; + if (ShootEvent == null) return; + + var ev = new ShootEvent + { + Player = player, + Target = target, + TargetPosition = targetpos + }; + + ShootEvent.Invoke(ev); + + allow = ev.Allow; + targetpos = ev.TargetPosition; + } } } \ No newline at end of file diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index a5743a9..6431c2b 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -91,11 +91,13 @@ + + From a9b2ac0d1099c5c4e1277aeb0ad26ac3f8041050 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Thu, 27 Aug 2020 16:11:12 +0200 Subject: [PATCH 20/27] added litle check --- Synapse/Events/EventHandlers.cs | 37 ++++++++++++++++++- .../EventPatches/PlayerPatches/ShootPatch.cs | 6 ++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index 54f9562..25f62d6 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -4,6 +4,8 @@ using UnityEngine; using Synapse.Api; using MEC; +using Grenades; +using Mirror; namespace Synapse.Events { @@ -17,12 +19,45 @@ public EventHandlers() Events.DoorInteractEvent += OnDoorInteract; Events.PlayerJoinEvent += OnPlayerJoin; - //KeyPressEvent for Testing many different things easy with a singel Key Press! #if DEBUG Events.KeyPressEvent += OnKey; + Events.ShootEvent += OnShoot; #endif } + private void OnShoot(ShootEvent ev) + { + var cam = ev.Player.Hub.PlayerCameraReference; + Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit where, 40f); + if (where.transform.TryGetComponent(out var grenade)) + { + grenade.NetworkfuseTime = 0; + grenade.ServersideExplosion(); + } + + else if (where.transform.TryGetComponent(out var pickup)) + { + if (pickup.itemId == ItemType.GrenadeFrag) + { + var pos = pickup.position; + pickup.position = Vector3.zero; + pickup.Delete(); + + var gm = Server.Host.GetComponent(); + var grenade2 = gm.availableGrenades.FirstOrDefault(g => g.inventoryID == ItemType.GrenadeFrag); + var component = Object.Instantiate(grenade2.grenadeInstance).GetComponent(); + component.InitData(gm, Vector3.zero, Vector3.zero); + component.transform.position = pos; + + + NetworkServer.Spawn(component.gameObject); + + component.NetworkfuseTime = 0f; + component.ServersideExplosion(); + } + } + } + // Methods private void OnPlayerJoin(PlayerJoinEvent ev) { diff --git a/Synapse/Events/Patches/EventPatches/PlayerPatches/ShootPatch.cs b/Synapse/Events/Patches/EventPatches/PlayerPatches/ShootPatch.cs index 7fcb08a..a6694a1 100644 --- a/Synapse/Events/Patches/EventPatches/PlayerPatches/ShootPatch.cs +++ b/Synapse/Events/Patches/EventPatches/PlayerPatches/ShootPatch.cs @@ -22,8 +22,12 @@ private static bool Prefix(WeaponManager __instance, GameObject target, string h __instance._hub.inventory.items[itemIndex].durability <= 0.0)) return false; + Player targetplayer = null; + if (target != null) + targetplayer = target.GetPlayer(); + //Event Invoke - Events.InvokeShootEvent(__instance.GetPlayer(), target.GetPlayer(), ref targetPos, out var allow); + Events.InvokeShootEvent(__instance.gameObject.GetPlayer(), targetplayer, ref targetPos, out var allow); return allow; } From c0879f28dfdbbc9719a4cf1969ae2286d583d7f7 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Thu, 27 Aug 2020 19:56:59 +0200 Subject: [PATCH 21/27] fixed Jail --- Synapse/Api/Jail.cs | 1 + Synapse/Events/EventHandlers.cs | 67 +++++++++++++++++---------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Synapse/Api/Jail.cs b/Synapse/Api/Jail.cs index c8d1810..1a63f76 100644 --- a/Synapse/Api/Jail.cs +++ b/Synapse/Api/Jail.cs @@ -88,6 +88,7 @@ public void UnJail() player.Role = Role; Timing.CallDelayed(0.2f, () => player.Position = Position); player.Health = Health; + player.ClearInventory(); foreach (var item in Items) player.Inventory.items.Add(item); diff --git a/Synapse/Events/EventHandlers.cs b/Synapse/Events/EventHandlers.cs index 25f62d6..07a082c 100644 --- a/Synapse/Events/EventHandlers.cs +++ b/Synapse/Events/EventHandlers.cs @@ -25,39 +25,6 @@ public EventHandlers() #endif } - private void OnShoot(ShootEvent ev) - { - var cam = ev.Player.Hub.PlayerCameraReference; - Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit where, 40f); - if (where.transform.TryGetComponent(out var grenade)) - { - grenade.NetworkfuseTime = 0; - grenade.ServersideExplosion(); - } - - else if (where.transform.TryGetComponent(out var pickup)) - { - if (pickup.itemId == ItemType.GrenadeFrag) - { - var pos = pickup.position; - pickup.position = Vector3.zero; - pickup.Delete(); - - var gm = Server.Host.GetComponent(); - var grenade2 = gm.availableGrenades.FirstOrDefault(g => g.inventoryID == ItemType.GrenadeFrag); - var component = Object.Instantiate(grenade2.grenadeInstance).GetComponent(); - component.InitData(gm, Vector3.zero, Vector3.zero); - component.transform.position = pos; - - - NetworkServer.Spawn(component.gameObject); - - component.NetworkfuseTime = 0f; - component.ServersideExplosion(); - } - } - } - // Methods private void OnPlayerJoin(PlayerJoinEvent ev) { @@ -87,6 +54,7 @@ private static void OnSyncData(SyncDataEvent ev) ev.Player.Hub.characterClassManager.CmdRegisterEscape(); } + //Only Debug Events private void OnKey(KeyPressEvent ev) { if (ev.Key == KeyCode.Alpha1) @@ -129,5 +97,38 @@ private void OnKey(KeyPressEvent ev) ev.Player.SendConsoleMessage(msg); } } + + private void OnShoot(ShootEvent ev) + { + var cam = ev.Player.Hub.PlayerCameraReference; + Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit where, 40f); + if (where.transform.TryGetComponent(out var grenade)) + { + grenade.NetworkfuseTime = 0; + grenade.ServersideExplosion(); + } + + else if (where.transform.TryGetComponent(out var pickup)) + { + if (pickup.itemId == ItemType.GrenadeFrag) + { + var pos = pickup.position; + pickup.position = Vector3.zero; + pickup.Delete(); + + var gm = Server.Host.GetComponent(); + var grenade2 = gm.availableGrenades.FirstOrDefault(g => g.inventoryID == ItemType.GrenadeFrag); + var component = Object.Instantiate(grenade2.grenadeInstance).GetComponent(); + component.InitData(gm, Vector3.zero, Vector3.zero); + component.transform.position = pos; + + + NetworkServer.Spawn(component.gameObject); + + component.NetworkfuseTime = 0f; + component.ServersideExplosion(); + } + } + } } } \ No newline at end of file From 3890003945ee1bff2592d97ad8b267e6c38aa167 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Thu, 27 Aug 2020 20:22:10 +0200 Subject: [PATCH 22/27] added Translation.ReloadTranslations() --- Synapse/Api/Plugin/Translation.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Synapse/Api/Plugin/Translation.cs b/Synapse/Api/Plugin/Translation.cs index c1340f2..64724b4 100644 --- a/Synapse/Api/Plugin/Translation.cs +++ b/Synapse/Api/Plugin/Translation.cs @@ -8,12 +8,15 @@ namespace Synapse.Api.Plugin [SuppressMessage("ReSharper", "UnusedMember.Global")] public class Translation { + private Dictionary _rawtranslation; private Dictionary _translation = new Dictionary(); private string _translationPath; internal Plugin Plugin; public void CreateTranslations(Dictionary translations) { + _rawtranslation = translations; + _translationPath = Path.Combine(Files.ServerConfigDirectory, Plugin.Details.Name + "-translation.txt"); if (!File.Exists(_translationPath)) File.Create(_translationPath).Close(); @@ -50,6 +53,12 @@ public void CreateTranslations(Dictionary translations) _translation = dictionary; } + public void ReloadTranslations() + { + if (_rawtranslation != null) + CreateTranslations(_rawtranslation); + } + public string GetTranslation(string translationName) { try From c79ebc25091c99207f0f79f545752eef4af02cab Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 29 Aug 2020 09:08:24 +0200 Subject: [PATCH 23/27] Splited ScpEvents in multiple files --- Synapse/Events/RoundEvents.cs | 55 +++++++++++++++ Synapse/Events/Scp049Events.cs | 35 ++++++++++ Synapse/Events/Scp079Events.cs | 27 +++++++ Synapse/Events/Scp096Events.cs | 27 +++++++ Synapse/Events/Scp106Events.cs | 57 +++++++++++++++ Synapse/Events/ScpEvents.cs | 124 --------------------------------- Synapse/Events/ServerEvents.cs | 56 --------------- Synapse/Synapse.csproj | 6 +- 8 files changed, 206 insertions(+), 181 deletions(-) create mode 100644 Synapse/Events/RoundEvents.cs create mode 100644 Synapse/Events/Scp049Events.cs create mode 100644 Synapse/Events/Scp079Events.cs create mode 100644 Synapse/Events/Scp096Events.cs create mode 100644 Synapse/Events/Scp106Events.cs delete mode 100644 Synapse/Events/ScpEvents.cs diff --git a/Synapse/Events/RoundEvents.cs b/Synapse/Events/RoundEvents.cs new file mode 100644 index 0000000..5275ef8 --- /dev/null +++ b/Synapse/Events/RoundEvents.cs @@ -0,0 +1,55 @@ +using Synapse.Events.Classes; + +namespace Synapse.Events +{ + public static partial class Events + { + public delegate void OnWaitingForPlayers(); + public static event OnWaitingForPlayers WaitingForPlayersEvent; + internal static void InvokeWaitingForPlayers() => WaitingForPlayersEvent?.Invoke(); + + 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, + ref bool teamChanged) + { + var ev = new CheckRoundEndEvent + { + Allow = allow, + ForceEnd = forceEnd, + LeadingTeam = team + }; + + CheckRoundEndEvent?.Invoke(ev); + + teamChanged = team != ev.LeadingTeam; + team = ev.LeadingTeam; + allow = ev.Allow; + forceEnd = ev.ForceEnd; + } + + public delegate void OnRoundRestart(); + public static event OnRoundRestart RoundRestartEvent; + internal static void InvokeRoundRestart() + { + RoundRestartEvent?.Invoke(); + } + + /// + /// A Event which activate when the Round Ends (not a Restart!) + /// + public delegate void OnRoundEnd(); + public static event OnRoundEnd RoundEndEvent; + internal static void InvokeRoundEndEvent() + { + RoundEndEvent?.Invoke(); + } + + public delegate void OnRoundStart(); + public static event OnRoundStart RoundStartEvent; + internal static void InvokeRoundStart() + { + RoundStartEvent?.Invoke(); + } + } +} diff --git a/Synapse/Events/Scp049Events.cs b/Synapse/Events/Scp049Events.cs new file mode 100644 index 0000000..b21cfe2 --- /dev/null +++ b/Synapse/Events/Scp049Events.cs @@ -0,0 +1,35 @@ +using Synapse.Api; +using Synapse.Events.Classes; + +namespace Synapse.Events +{ + public static partial class Events + { + /// A Event which is activated when Scp049 respawns a Player + public delegate void OnScp049Recall(Scp049RecallEvent ev); + public static event OnScp049Recall Scp049RecallEvent; + internal static void InvokeScp049RecallEvent(Player player, ref Ragdoll ragdoll, ref Player target, + ref bool allow, ref RoleType role, ref float lives) + { + if (Scp049RecallEvent == null) return; + + var ev = new Scp049RecallEvent + { + Allow = allow, + Ragdoll = ragdoll, + Target = target, + RespawnRole = role, + TargetHealth = lives, + Player = player + }; + + Scp049RecallEvent.Invoke(ev); + + ragdoll = ev.Ragdoll; + target = ev.Target; + role = ev.RespawnRole; + lives = ev.TargetHealth; + allow = ev.Allow; + } + } +} \ No newline at end of file diff --git a/Synapse/Events/Scp079Events.cs b/Synapse/Events/Scp079Events.cs new file mode 100644 index 0000000..8021ed5 --- /dev/null +++ b/Synapse/Events/Scp079Events.cs @@ -0,0 +1,27 @@ +using Synapse.Events.Classes; +using Synapse.Api; + +namespace Synapse.Events +{ + public static partial class Events + { + public delegate void OnScp079GainLvl(Scp079GainLvlEvent ev); + public static event OnScp079GainLvl Scp079GainLvlEvent; + internal static void InvokeScp079LvlEvent(Player player, ref int newlvl, ref bool allow) + { + if (Scp079GainLvlEvent == null) return; + + var ev = new Scp079GainLvlEvent + { + Allow = allow, + NewLvl = newlvl, + Player = player + }; + + Scp079GainLvlEvent.Invoke(ev); + + newlvl = ev.NewLvl; + allow = ev.Allow; + } + } +} diff --git a/Synapse/Events/Scp096Events.cs b/Synapse/Events/Scp096Events.cs new file mode 100644 index 0000000..54efcd7 --- /dev/null +++ b/Synapse/Events/Scp096Events.cs @@ -0,0 +1,27 @@ +using Synapse.Events.Classes; +using Synapse.Api; + +namespace Synapse.Events +{ + public static partial class Events + { + public delegate void OnScp096AddTarget(Scp096AddTarget ev); + public static event OnScp096AddTarget Scp096AddTarget; + internal static void InvokeScp096AddTarget(Player player, Player shyguy, PlayableScps.Scp096PlayerState state, ref bool allow) + { + if (Scp096AddTarget == null) return; + + var ev = new Scp096AddTarget() + { + Player = player, + ShyGuy = shyguy, + RageState = state, + Allow = allow + }; + + Scp096AddTarget.Invoke(ev); + + allow = ev.Allow; + } + } +} diff --git a/Synapse/Events/Scp106Events.cs b/Synapse/Events/Scp106Events.cs new file mode 100644 index 0000000..050aa46 --- /dev/null +++ b/Synapse/Events/Scp106Events.cs @@ -0,0 +1,57 @@ +using Synapse.Events.Classes; +using Synapse.Api; + +namespace Synapse.Events +{ + public static partial class Events + { + public delegate void OnScp106Containment(Scp106ContainmentEvent ev); + public static event OnScp106Containment Scp106ContainmentEvent; + internal static void InvokeScp106ContainmentEvent(Player player, ref bool allow) + { + if (Scp106ContainmentEvent == null) return; + + var ev = new Scp106ContainmentEvent + { + Player = player, + Allow = allow + }; + + Scp106ContainmentEvent.Invoke(ev); + + allow = ev.Allow; + } + + public delegate void OnScp106CreatePortal(Scp106CreatePortalEvent ev); + public static event OnScp106CreatePortal Scp106CreatePortalEvent; + internal static void InvokeScp106CreatePortalEvent(Player player, ref bool allow) + { + var ev = new Scp106CreatePortalEvent + { + Allow = allow, + Player = player + }; + + Scp106CreatePortalEvent?.Invoke(ev); + + allow = ev.Allow; + } + + public delegate void OnPocketDimensionEnter(PocketDimensionEvent ev); + public static event OnPocketDimensionEnter PocketDimensionEnterEvent; + internal static void InvokePocketDimensionEnterEvent(Player player, ref bool allow) + { + if (PocketDimensionEnterEvent == null) return; + + var ev = new PocketDimensionEvent + { + Player = player, + Allow = allow + }; + + PocketDimensionEnterEvent.Invoke(ev); + + allow = ev.Allow; + } + } +} diff --git a/Synapse/Events/ScpEvents.cs b/Synapse/Events/ScpEvents.cs deleted file mode 100644 index a20f4f4..0000000 --- a/Synapse/Events/ScpEvents.cs +++ /dev/null @@ -1,124 +0,0 @@ -using Synapse.Api; -using Synapse.Events.Classes; - -namespace Synapse.Events -{ - public static partial class Events - { - /// A Event which is activated when Scp049 respawns a Player - public delegate void OnScp049Recall(Scp049RecallEvent ev); - public static event OnScp049Recall Scp049RecallEvent; - internal static void InvokeScp049RecallEvent(Player player, ref Ragdoll ragdoll, ref Player target, - ref bool allow, ref RoleType role, ref float lives) - { - if (Scp049RecallEvent == null) return; - - var ev = new Scp049RecallEvent - { - Allow = allow, - Ragdoll = ragdoll, - Target = target, - RespawnRole = role, - TargetHealth = lives, - Player = player - }; - - Scp049RecallEvent.Invoke(ev); - - ragdoll = ev.Ragdoll; - target = ev.Target; - role = ev.RespawnRole; - lives = ev.TargetHealth; - allow = ev.Allow; - } - - public delegate void OnPocketDimensionEnter(PocketDimensionEvent ev); - public static event OnPocketDimensionEnter PocketDimensionEnterEvent; - - internal static void InvokePocketDimensionEnterEvent(Player player, ref bool allow) - { - if (PocketDimensionEnterEvent == null) return; - - var ev = new PocketDimensionEvent - { - Player = player, - Allow = allow - }; - - PocketDimensionEnterEvent.Invoke(ev); - - allow = ev.Allow; - } - - public delegate void OnScp106Containment(Scp106ContainmentEvent ev); - public static event OnScp106Containment Scp106ContainmentEvent; - internal static void InvokeScp106ContainmentEvent(Player player, ref bool allow) - { - if (Scp106ContainmentEvent == null) return; - - var ev = new Scp106ContainmentEvent - { - Player = player, - Allow = allow - }; - - Scp106ContainmentEvent.Invoke(ev); - - allow = ev.Allow; - } - - - public delegate void OnScp079GainLvl(Scp079GainLvlEvent ev); - public static event OnScp079GainLvl Scp079GainLvlEvent; - internal static void InvokeScp079LvlEvent(Player player,ref int newlvl,ref bool allow) - { - if (Scp079GainLvlEvent == null) return; - - var ev = new Scp079GainLvlEvent - { - Allow = allow, - NewLvl = newlvl, - Player = player - }; - - Scp079GainLvlEvent.Invoke(ev); - - newlvl = ev.NewLvl; - allow = ev.Allow; - } - - public delegate void OnScp106CreatePortal(Scp106CreatePortalEvent ev); - public static event OnScp106CreatePortal Scp106CreatePortalEvent; - internal static void InvokeScp106CreatePortalEvent(Player player, ref bool allow) - { - var ev = new Scp106CreatePortalEvent - { - Allow = allow, - Player = player - }; - - Scp106CreatePortalEvent?.Invoke(ev); - - allow = ev.Allow; - } - - public delegate void OnScp096AddTarget(Scp096AddTarget ev); - public static event OnScp096AddTarget Scp096AddTarget; - internal static void InvokeScp096AddTarget(Player player,Player shyguy,PlayableScps.Scp096PlayerState state,ref bool allow) - { - if (Scp096AddTarget == null) return; - - var ev = new Scp096AddTarget() - { - Player = player, - ShyGuy = shyguy, - RageState = state, - Allow = allow - }; - - Scp096AddTarget.Invoke(ev); - - allow = ev.Allow; - } - } -} \ No newline at end of file diff --git a/Synapse/Events/ServerEvents.cs b/Synapse/Events/ServerEvents.cs index 9143365..06875c0 100644 --- a/Synapse/Events/ServerEvents.cs +++ b/Synapse/Events/ServerEvents.cs @@ -9,38 +9,10 @@ namespace Synapse.Events [SuppressMessage("ReSharper", "EventNeverSubscribedTo.Global")] public static partial class Events { - public delegate void OnRoundRestart(); - public static event OnRoundRestart RoundRestartEvent; - - internal static void InvokeRoundRestart() - { - RoundRestartEvent?.Invoke(); - } - - /// - /// A Event which activate when the Round Ends (not a Restart!) - /// - public delegate void OnRoundEnd(); - public static event OnRoundEnd RoundEndEvent; - - internal static void InvokeRoundEndEvent() - { - RoundEndEvent?.Invoke(); - } - - public delegate void OnRoundStart(); - public static event OnRoundStart RoundStartEvent; - - internal static void InvokeRoundStart() - { - RoundStartEvent?.Invoke(); - } - /// 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(RemoteCommandEvent ev); public static event OnRemoteCommand RemoteCommandEvent; - internal static void InvokeRemoteCommandEvent(CommandSender sender, string command, ref bool allow) { if (RemoteCommandEvent == null) return; @@ -60,7 +32,6 @@ internal static void InvokeRemoteCommandEvent(CommandSender sender, string comma /// A Event which is activated when a user send a Command in the Remote Admin public delegate void OnConsoleCommand(ConsoleCommandEvent ev); public static event OnConsoleCommand ConsoleCommandEvent; - internal static void InvokeConsoleCommandEvent(Player player, string command, out bool allow) { allow = true; @@ -77,7 +48,6 @@ 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 Respawning.SpawnableTeamType team) { if (TeamRespawnEvent == null) return; @@ -96,7 +66,6 @@ internal static void InvokeTeamRespawnEvent(ref List respawnList, ref Re public delegate void OnPreAuthenticationEvent(PreAuthenticationEvent ev); public static event OnPreAuthenticationEvent PreAuthenticationEvent; - internal static void InvokePreAuthentication(string userId, ConnectionRequest request, ref bool allow) { var ev = new PreAuthenticationEvent @@ -110,30 +79,5 @@ internal static void InvokePreAuthentication(string userId, ConnectionRequest re allow = ev.Allow; } - - public delegate void OnWaitingForPlayers(); - public static event OnWaitingForPlayers WaitingForPlayersEvent; - internal static void InvokeWaitingForPlayers() => WaitingForPlayersEvent?.Invoke(); - - 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, - ref bool teamChanged) - { - var ev = new CheckRoundEndEvent - { - Allow = allow, - ForceEnd = forceEnd, - LeadingTeam = team - }; - - CheckRoundEndEvent?.Invoke(ev); - - teamChanged = team != ev.LeadingTeam; - team = ev.LeadingTeam; - allow = ev.Allow; - forceEnd = ev.ForceEnd; - } } } \ No newline at end of file diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 6431c2b..55da88d 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -91,6 +91,10 @@ + + + + @@ -174,7 +178,7 @@ - + From b494bf7340a70f250c73cc04140790206aaa5d7a Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 29 Aug 2020 09:43:52 +0200 Subject: [PATCH 24/27] added PocketDimensionLeave Event --- .../Events/Classes/PocketDimensionLeave.cs | 13 ++++++++ .../ScpPatches/PocketDimensionLeavePatch.cs | 30 +++++++++++++++++++ Synapse/Events/Scp106Events.cs | 20 +++++++++++++ Synapse/Synapse.csproj | 2 ++ 4 files changed, 65 insertions(+) create mode 100644 Synapse/Events/Classes/PocketDimensionLeave.cs create mode 100644 Synapse/Events/Patches/EventPatches/ScpPatches/PocketDimensionLeavePatch.cs diff --git a/Synapse/Events/Classes/PocketDimensionLeave.cs b/Synapse/Events/Classes/PocketDimensionLeave.cs new file mode 100644 index 0000000..f714c4d --- /dev/null +++ b/Synapse/Events/Classes/PocketDimensionLeave.cs @@ -0,0 +1,13 @@ +using Synapse.Api; + +namespace Synapse.Events.Classes +{ + public class PocketDimensionLeave + { + public Player Player { get; internal set; } + + public PocketDimensionTeleport.PDTeleportType TeleportType { get; set; } + + public bool Allow { get; set; } + } +} diff --git a/Synapse/Events/Patches/EventPatches/ScpPatches/PocketDimensionLeavePatch.cs b/Synapse/Events/Patches/EventPatches/ScpPatches/PocketDimensionLeavePatch.cs new file mode 100644 index 0000000..53c9698 --- /dev/null +++ b/Synapse/Events/Patches/EventPatches/ScpPatches/PocketDimensionLeavePatch.cs @@ -0,0 +1,30 @@ +using System; +using Harmony; +using Mirror; +using Synapse.Api; +using UnityEngine; + +namespace Synapse.Events.Patches.EventPatches.ScpPatches +{ + [HarmonyPatch(typeof(PocketDimensionTeleport), nameof(PocketDimensionTeleport.OnTriggerEnter))] + internal static class PocketDimensionLeavePatch + { + private static bool Prefix(PocketDimensionTeleport __instance, Collider other) + { + try + { + var component = other.GetComponent(); + if (!NetworkServer.active || component == null) return false; + + Events.InvokePocketDimensionLeave(component.GetPlayer(), ref __instance.type, out var allow); + + return allow; + } + catch (Exception e) + { + Log.Error($"PocketDimExit Event Error: {e}"); + return true; + } + } + } +} diff --git a/Synapse/Events/Scp106Events.cs b/Synapse/Events/Scp106Events.cs index 050aa46..7557ad3 100644 --- a/Synapse/Events/Scp106Events.cs +++ b/Synapse/Events/Scp106Events.cs @@ -53,5 +53,25 @@ internal static void InvokePocketDimensionEnterEvent(Player player, ref bool all allow = ev.Allow; } + + public delegate void OnPocketDimensionLeave(PocketDimensionLeave ev); + public static event OnPocketDimensionLeave PocketDimensionLeaveEvent; + internal static void InvokePocketDimensionLeave(Player player, ref PocketDimensionTeleport.PDTeleportType type, out bool allow) + { + allow = true; + if (PocketDimensionLeaveEvent == null) return; + + var ev = new PocketDimensionLeave + { + Allow = true, + Player = player, + TeleportType = type + }; + + PocketDimensionLeaveEvent.Invoke(ev); + + allow = ev.Allow; + type = ev.TeleportType; + } } } diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 55da88d..dacb77b 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -91,6 +91,8 @@ + + From 4726f500b612fe0ec3754236f395a6dc21884507 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 29 Aug 2020 10:10:12 +0200 Subject: [PATCH 25/27] added Scp106Controller --- Synapse/Api/Player.cs | 2 ++ Synapse/Api/Scp106Controller.cs | 25 +++++++++++++++++++ .../PlayerPatches/ComponentsPatch.cs | 2 ++ Synapse/Synapse.csproj | 1 + 4 files changed, 30 insertions(+) create mode 100644 Synapse/Api/Scp106Controller.cs diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 0e216ea..ef8d6ed 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -86,6 +86,8 @@ public static Player GetPlayer(string arg) public HintDisplay HintDisplay => Hub.hints; + public Scp106Controller Scp106Controller => this.GetComponent(); + /// /// The CommandSender objects of the Player /// diff --git a/Synapse/Api/Scp106Controller.cs b/Synapse/Api/Scp106Controller.cs new file mode 100644 index 0000000..7dabb3e --- /dev/null +++ b/Synapse/Api/Scp106Controller.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +namespace Synapse.Api +{ + public class Scp106Controller : MonoBehaviour + { + private Player player => this.GetPlayer(); + private Scp106PlayerScript script => player.ClassManager.Scp106; + + public bool Is106 => player.Role == RoleType.Scp106; + + public Vector3 PortalPosition { get => script.NetworkportalPosition; set => script.SetPortalPosition(value); } + + + public void UsePortal() => script.UseTeleport(); + + public void DeletePortal() => script.DeletePortal(); + + public void CreatePortal() => script.CreatePortalInCurrentPosition(); + + public void Contain() => script.Contain(player.Hub); + + public void CapturePlayer(Player player) => script.CallCmdMovePlayer(player.gameObject, ServerTime.time); + } +} diff --git a/Synapse/Events/Patches/EventPatches/PlayerPatches/ComponentsPatch.cs b/Synapse/Events/Patches/EventPatches/PlayerPatches/ComponentsPatch.cs index adf92ed..2f2999c 100644 --- a/Synapse/Events/Patches/EventPatches/PlayerPatches/ComponentsPatch.cs +++ b/Synapse/Events/Patches/EventPatches/PlayerPatches/ComponentsPatch.cs @@ -13,6 +13,8 @@ public static void Prefix(ReferenceHub __instance) if (__instance.GetComponent() == null) __instance.gameObject.AddComponent(); + if (__instance.GetComponent() == null) __instance.gameObject.AddComponent(); + try { Events.InvokeLoadComponents(__instance.gameObject); diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index dacb77b..69808fe 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -70,6 +70,7 @@ + From 25b753470b5561f8edbd0a1a49c24593c8a78309 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 29 Aug 2020 10:20:45 +0200 Subject: [PATCH 26/27] added Scp079Controller --- Synapse/Api/Player.cs | 5 ----- Synapse/Api/Scp079Controller.cs | 34 +++++++++++++++++++++++++++++++++ Synapse/Synapse.csproj | 1 + 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 Synapse/Api/Scp079Controller.cs diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index ef8d6ed..f5bf20e 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -389,11 +389,6 @@ public bool HideRank /// public bool IsIntercomMuted { get => ClassManager.NetworkIntercomMuted; set => ClassManager.NetworkIntercomMuted = value; } - /// - /// The current camera the player uses (Scp079 only, if not null) - /// - public Camera079 Camera { get => Hub.scp079PlayerScript.currentCamera; set => Hub.scp079PlayerScript?.RpcSwitchCamera(value.cameraId, false); } - /// /// Gives you the Ping of the Player to the Server /// diff --git a/Synapse/Api/Scp079Controller.cs b/Synapse/Api/Scp079Controller.cs new file mode 100644 index 0000000..1c6d6d7 --- /dev/null +++ b/Synapse/Api/Scp079Controller.cs @@ -0,0 +1,34 @@ +using UnityEngine; + +namespace Synapse.Api +{ + public class Scp079Controller : MonoBehaviour + { + private Player player => this.GetPlayer(); + private Scp079PlayerScript script => player.ClassManager.Scp079; + + public bool Is079 => player.Role == RoleType.Scp079; + + public byte Level { get => script.Lvl; set => script.Lvl = value; } + + public string Speaker { get => script.Speaker; set => script.Speaker = value; } + + public float Exp { get => script.Exp; set => script.Exp = value; } + + public float Energy { get => script.Mana; set => script.Mana = value; } + + public float MaxEnergy { get => script.maxMana; set => script.NetworkmaxMana = value; } + + /// + /// The current camera the player uses (Scp079 only, if not null) + /// + public Camera079 Camera { get => script.currentCamera; set => script?.RpcSwitchCamera(value.cameraId, false); } + + + public void GiveExperience(float amount) => script.AddExperience(amount); + + public void ForceLevel(byte levelToForce, bool notifiyUser) => script.ForceLevel(levelToForce, notifiyUser); + + public void UnlockDoors() => script.CmdResetDoors(); + } +} diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 69808fe..5d12914 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -70,6 +70,7 @@ + From f0a56dfa46c1f9f7c11495b60bb38794c5774a67 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Sat, 29 Aug 2020 10:22:17 +0200 Subject: [PATCH 27/27] added Scp079Controller to Player --- Synapse/Api/Player.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index f5bf20e..8137498 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -88,6 +88,8 @@ public static Player GetPlayer(string arg) public Scp106Controller Scp106Controller => this.GetComponent(); + public Scp079Controller Scp079Controller => this.GetComponent(); + /// /// The CommandSender objects of the Player ///