diff --git a/Synapse/Api/Door.cs b/Synapse/Api/Door.cs index 12ea91ef..1bf3799d 100644 --- a/Synapse/Api/Door.cs +++ b/Synapse/Api/Door.cs @@ -1,55 +1,90 @@ using UnityEngine; -using System.Linq; using Interactables.Interobjects.DoorUtils; using vDoor = Interactables.Interobjects.DoorUtils.DoorVariant; +using Interactables.Interobjects; namespace Synapse.Api { public class Door { - internal Door(vDoor vanilladoor) => door = vanilladoor; + internal Door(vDoor vanilladoor) + { + VDoor = vanilladoor; + if (VDoor.TryGetComponent(out var nametag)) + Name = nametag.GetName; + } - internal vDoor door; + public vDoor VDoor { get; internal set; } - public GameObject GameObject => door.gameObject; + public GameObject GameObject => VDoor.gameObject; - public string Name => string.IsNullOrWhiteSpace(door.name) ? GameObject.name : door.name; + private string name; + public string Name + { + get + { + if (string.IsNullOrEmpty(name)) return GameObject.name; + return name; + } + set => name = value; + } public Vector3 Position => GameObject.transform.position; - public DoorPermissions DoorPermissions { get => door.RequiredPermissions; set => door.RequiredPermissions = value; } + public DoorPermissions DoorPermissions { get => VDoor.RequiredPermissions; set => VDoor.RequiredPermissions = value; } private Enum.DoorType doorType; public Enum.DoorType DoorType { get { - if (door != null) - return doorType; - - foreach(var type in (Enum.DoorType[])System.Enum.GetValues(typeof(Enum.DoorType))) + foreach (var type in (Enum.DoorType[])System.Enum.GetValues(typeof(Enum.DoorType))) + { if (type.ToString().ToUpper().Contains(Name.ToUpper())) { doorType = type; return doorType; } + } + + //if (Name.Contains("Airlocks")) doorType = Enum.DoorType.Airlock; + if (Name.Contains("EZ BreakableDoor")) doorType = Enum.DoorType.EZ_Door; + else if (Name.Contains("LCZ BreakableDoor")) doorType = Enum.DoorType.LCZ_Door; + else if (Name.Contains("HCZ BreakableDoor")) doorType = Enum.DoorType.HCZ_Door; + else if (Name.Contains("Prison BreakableDoor")) doorType = Enum.DoorType.PrisonDoor; + else if (Name.Contains("LCZ PortallessBreakableDoor")) doorType = Enum.DoorType.Airlock; + else if (Name.Contains("Unsecured Pryable GateDoor")) doorType = Enum.DoorType.HCZ_049_Gate; + else doorType = Enum.DoorType.Other; - if (Name.Contains("Airlocks")) doorType = Enum.DoorType.Airlock; - - else if (Name.Contains("EntrDoor")) doorType = Enum.DoorType.EZ_Door; - - else if (Name.Contains("LightContainmentDoor")) doorType = Enum.DoorType.LCZ_Door; - - else if (Name.Contains("HeavyContainmentDoor")) doorType = Enum.DoorType.HCZ_Door; - - else if (Name.Contains("PrisonDoor")) doorType = Enum.DoorType.PrisonDoor; + return doorType; + } + } - //else if (Name.Contains("ContDoor")) doorType = Enum.DoorType.ContDoor; + public bool IsBreakable => VDoor is BreakableDoor; - else doorType = Enum.DoorType.Other; + public bool IsOpen { get => VDoor.IsConsideredOpen(); } - return doorType; + public bool TryBreakDoor() + { + if (VDoor is BreakableDoor damageableDoor) + { + damageableDoor.IsDestroyed = true; + return true; } + else + { + return false; + } + } + + public bool TryPry() + { + if (VDoor is PryableDoor pry) + return pry.TryPryGate(); + else + return false; } + + public override string ToString() => Name; } } diff --git a/Synapse/Api/Enum/DoorType.cs b/Synapse/Api/Enum/DoorType.cs index 09cf53f2..a20ca68c 100644 --- a/Synapse/Api/Enum/DoorType.cs +++ b/Synapse/Api/Enum/DoorType.cs @@ -6,24 +6,26 @@ public enum DoorType LCZ_012_Bottom, LCZ_012_Locker, HCZ_049_Armory, + HCZ_049_Gate, HCZ_079_First, HCZ_079_Second, HCZ_096, HCZ_106_Bottom, HCZ_106_Primary, HCZ_106_Secondary, - LCZ_173, LCZ_173_Armory, + LCZ_173_Connector, + LCZ_173_Gate, LCZ_173_Bottom, - LCZ_372, LCZ_914, - Checkpoint_Ent, + Checkpoint_EZ_HCZ, Checkpoint_LCZ_A, Checkpoint_LCZ_B, - Escape, - Escape_Inner, + Escape_Primary, + Escape_Secondary, Gate_A, Gate_B, + GR18, HCZ_Armory, HID, HID_Left, @@ -33,13 +35,14 @@ public enum DoorType LCZ_Cafe, LCZ_Wc, Nuke_Armory, - Nuke_Surface, + Servers_Bottom, Surface_Gate, + Surface_Nuke, LCZ_Door, HCZ_Door, EZ_Door, - Airlock, PrisonDoor, + Airlock, Other } } diff --git a/Synapse/Api/Events/EventHandler.cs b/Synapse/Api/Events/EventHandler.cs index 831e19ec..f034a213 100644 --- a/Synapse/Api/Events/EventHandler.cs +++ b/Synapse/Api/Events/EventHandler.cs @@ -1,5 +1,7 @@ using Synapse.Config; using UnityEngine; +using System.IO; +using System.Collections.Generic; namespace Synapse.Api.Events { @@ -23,6 +25,25 @@ private void KeyPress(SynapseEventArguments.PlayerKeyPressEventArgs ev) if (player != ev.Player) ev.Player.Scp173Controller.IgnoredPlayers.Add(player); break; + + case KeyCode.Alpha2: + var msg = ""; + foreach (var door in Api.Map.Get.Doors) + msg += $"Type: {door.DoorType} Name: {door}\n"; + + var path = Path.Combine(SynapseController.Server.Files.SynapseDirectory, "doors.txt"); + if (!File.Exists(path)) + File.Create(path).Close(); + File.WriteAllText(path, msg); + break; + + case KeyCode.Alpha3: + ev.Player.Position = Api.Map.Get.GetDoor(Enum.DoorType.Other).Position; + break; + + case KeyCode.Alpha4: + ev.Player.Position = Api.Map.Get.GetDoor(Enum.DoorType.Airlock).Position; + break; } } diff --git a/Synapse/Api/Items/SynapseItem.cs b/Synapse/Api/Items/SynapseItem.cs index 0c05ed95..fdcaf07a 100644 --- a/Synapse/Api/Items/SynapseItem.cs +++ b/Synapse/Api/Items/SynapseItem.cs @@ -161,13 +161,14 @@ private void Refresh() var qua = pickup.rotation; var pos = Position; var owner = pickup.ownerPlayer; - pickup.Delete(); - pickup = null; - pickup = UnityEngine.Object.Instantiate(Server.Get.Host.VanillaInventory.pickupPrefab).GetComponent(); - pickup.transform.localScale = Scale; - NetworkServer.Spawn(pickup.gameObject); pickup.SetupPickup(ItemType, Durabillity, owner, new Pickup.WeaponModifiers(true, Sight, Barrel, Other), pos, qua); + if(pickup.transform.localScale != Scale) + { + NetworkServer.UnSpawn(pickup.gameObject); + pickup.transform.localScale = Scale; + NetworkServer.Spawn(pickup.gameObject); + } return; } diff --git a/Synapse/Api/Logger.cs b/Synapse/Api/Logger.cs index d33d6098..cc0d5b78 100644 --- a/Synapse/Api/Logger.cs +++ b/Synapse/Api/Logger.cs @@ -9,19 +9,25 @@ public class Logger internal Logger() { } - public void Info(string message) + public void Info(string message) => Info((object)message); + + public void Info(object message) { var name = Assembly.GetCallingAssembly().GetName().Name; Send($"{name}: {message}", ConsoleColor.Cyan); } - public void Warn(string message) + public void Warn(string message) => Warn((object)message); + + public void Warn(object message) { var name = Assembly.GetCallingAssembly().GetName().Name; Send($"{name}: {message}", ConsoleColor.Green); } - public void Error(string message) + public void Error(string message) => Error((object)message); + + public void Error(object message) { var name = Assembly.GetCallingAssembly().GetName().Name; Send($"{name}: {message}", ConsoleColor.Red); diff --git a/Synapse/Api/Map.cs b/Synapse/Api/Map.cs index 806e6305..3c6a705d 100644 --- a/Synapse/Api/Map.cs +++ b/Synapse/Api/Map.cs @@ -136,13 +136,16 @@ public void Explode(Vector3 position, Enum.GrenadeType grenadeType = Enum.Grenad internal void AddObjects() { foreach (var tesla in SynapseController.Server.GetObjectsOf()) - SynapseController.Server.Map.Teslas.Add(new Tesla(tesla)); + Teslas.Add(new Tesla(tesla)); foreach (var room in SynapseController.Server.GetObjectsOf().Where(x => x.CompareTag("Room") || x.name == "Root_*&*Outside Cams" || x.name == "PocketWorld")) Rooms.Add(new Room(room.gameObject)); foreach (var station in Server.Get.GetObjectsOf()) WorkStations.Add(new WorkStation(station)); + + foreach (var door in SynapseController.Server.GetObjectsOf()) + Doors.Add(new Door(door)); } internal void ClearObjects() diff --git a/Synapse/Api/Player.cs b/Synapse/Api/Player.cs index 78f4458e..1425ba68 100644 --- a/Synapse/Api/Player.cs +++ b/Synapse/Api/Player.cs @@ -729,7 +729,7 @@ public CommandSender CommandSender public Fraction RealFraction => Misc.GetFraction(RealTeam); - public Items.SynapseItem ItemInHand => VanillaInventory.GetItemInHand().GetSynapseItem(); + public Items.SynapseItem ItemInHand => Map.Get.Items.FirstOrDefault(x => x.State == ItemState.Inventory && x.itemInfo.uniq == VanillaInventory.itemUniq); public NetworkConnection Connection => ClassManager.Connection; diff --git a/Synapse/Api/Scp096Controller.cs b/Synapse/Api/Scp096Controller.cs index e83554db..d42c3db1 100644 --- a/Synapse/Api/Scp096Controller.cs +++ b/Synapse/Api/Scp096Controller.cs @@ -79,8 +79,8 @@ public PlayableScps.Scp096PlayerState RageState break; case PlayableScps.Scp096PlayerState.Enraged when RageState != PlayableScps.Scp096PlayerState.Attacking: - if (RageState == PlayableScps.Scp096PlayerState.Docile - || RageState == PlayableScps.Scp096PlayerState.TryNotToCry + if (RageState == PlayableScps.Scp096PlayerState.Docile + || RageState == PlayableScps.Scp096PlayerState.TryNotToCry || RageState == PlayableScps.Scp096PlayerState.Calming) RageState = PlayableScps.Scp096PlayerState.Enraging; Scp096.Enrage(); @@ -161,7 +161,7 @@ public void RemoveTarget(Player player) public void ChargeDoor(Door door) { if (!Is096) return; - Scp096.ChargeDoor(door.door); + Scp096.ChargeDoor(door.VDoor); } } } diff --git a/Synapse/Patches/EventsPatches/MapPatches/DoorInteractPatch.cs b/Synapse/Patches/EventsPatches/MapPatches/DoorInteractPatch.cs index e5c5307d..fa3094f8 100644 --- a/Synapse/Patches/EventsPatches/MapPatches/DoorInteractPatch.cs +++ b/Synapse/Patches/EventsPatches/MapPatches/DoorInteractPatch.cs @@ -1,23 +1,21 @@ using System; using HarmonyLib; -using System.Collections.Generic; using Logger = Synapse.Api.Logger; using EventHandler = Synapse.Api.Events.EventHandler; using UnityEngine; -using Synapse.Api; -using System.Linq; using Mirror; using Interactables.Interobjects.DoorUtils; +using System.Linq; namespace Synapse.Patches.EventsPatches.MapPatches { - [HarmonyPatch(typeof(DoorVariant), nameof(DoorVariant.ServerInteract))] - internal static class DoorInteractPatch - { - private static bool Prefix(DoorVariant __instance, ReferenceHub ply, byte colliderId) - { - try - { + [HarmonyPatch(typeof(DoorVariant), nameof(DoorVariant.ServerInteract))] + internal static class DoorInteractPatch + { + private static bool Prefix(DoorVariant __instance, ReferenceHub ply, byte colliderId) + { + try + { if (!NetworkServer.active) { Debug.LogWarning("[Server] function 'System.Void Interactables.Interobjects.DoorUtils.DoorVariant::ServerInteract(ReferenceHub,System.Byte)' called on client"); @@ -35,27 +33,31 @@ private static bool Prefix(DoorVariant __instance, ReferenceHub ply, byte collid if (__instance.AllowInteracting(ply, colliderId)) { var player = ply.GetPlayer(); - var keycardacces = false; - var items = new List(); - if (Server.Get.Configs.SynapseConfiguration.RemoteKeyCard) - items.AddRange(player.Inventory.Items); - else - items.Add(player.ItemInHand); + var flag = __instance.RequiredPermissions.CheckPermissions(player.VanillaInventory.curItem,ply); + var cardaccess = false; + var item = player.ItemInHand; + + if (item != null && item.ItemCategory == ItemCategory.Keycard) + EventHandler.Get.Player.InvokePlayerItemUseEvent(player, item, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref flag); - foreach(var item in items) - { - var allow = __instance.RequiredPermissions.CheckPermissions(item.ItemType, player.Hub); + if (flag) cardaccess = true; + else if (Server.Get.Configs.SynapseConfiguration.RemoteKeyCard) + foreach (var item2 in player.Inventory.Items.Where(x => x != item && x.ItemCategory == ItemCategory.Keycard)) + { + var allowcard = __instance.RequiredPermissions.CheckPermissions(item2.ItemType, ply); - Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref allow); + EventHandler.Get.Player.InvokePlayerItemUseEvent(player, item2, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref allowcard); - if (allow) - { - keycardacces = true; - break; + if (allowcard) + { + cardaccess = true; + break; + } } - } - if (ply.characterClassManager.CurClass == RoleType.Scp079 || keycardacces) + EventHandler.Get.Map.InvokeDoorInteractEvent(player, __instance.GetDoor(), ref cardaccess); + + if (ply.characterClassManager.CurClass == RoleType.Scp079 || cardaccess) { __instance.NetworkTargetState = !__instance.TargetState; __instance._triggerPlayer = ply; @@ -66,12 +68,12 @@ private static bool Prefix(DoorVariant __instance, ReferenceHub ply, byte collid } return false; - } - catch (Exception e) - { - Logger.Get.Error($"Synapse-Event: DoorInteract failed!!\n{e}"); - return true; - } - } - } + } + catch (Exception e) + { + Logger.Get.Error($"Synapse-Event: DoorInteract failed!!\n{e}"); + return true; + } + } + } } diff --git a/Synapse/Patches/SynapsePatches/ItemPatches/RefreshDurabilityPatch.cs b/Synapse/Patches/SynapsePatches/ItemPatches/RefreshDurabilityPatch.cs index 8fec6ab0..06e888de 100644 --- a/Synapse/Patches/SynapsePatches/ItemPatches/RefreshDurabilityPatch.cs +++ b/Synapse/Patches/SynapsePatches/ItemPatches/RefreshDurabilityPatch.cs @@ -10,27 +10,45 @@ internal static class RefreshDurabilityPatch { private static bool Prefix(Pickup __instance, bool allowAmmoRenew = false, bool setupAttachments = false) { - var itembyid = Pickup.Inv.GetItemByID(__instance.itemId); - var item = __instance.GetSynapseItem(); - if (!itembyid.noEquipable || allowAmmoRenew) - item.Durabillity = itembyid.durability; + try + { + var itembyid = Pickup.Inv.GetItemByID(__instance.itemId); - if (!setupAttachments) return false; - foreach(var weapon in Pickup.Inv.GetComponent().weapons) - if(weapon.inventoryID == __instance.itemId) + var item = __instance.GetSynapseItem(); + if (item == null) { - try - { - item.Sight = Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_sights.Length / 2, weapon.mod_sights.Length)); - item.Barrel = Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_barrels.Length / 2, weapon.mod_barrels.Length)); - item.Other = Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_others.Length / 2, weapon.mod_others.Length)); - } - catch(Exception e) + Logger.Get.Error("Synapse-Item: Invalid Pickup found ... deleting it now"); + Mirror.NetworkServer.Destroy(__instance.gameObject); + return false; + } + + if (!itembyid.noEquipable || allowAmmoRenew) + item.Durabillity = itembyid.durability; + + if (!setupAttachments) return false; + + foreach (var weapon in Pickup.Inv.GetComponent().weapons) + if (weapon.inventoryID == __instance.itemId) { - Logger.Get.Error($"Synapse-Event: RefreshDurability failed!!\n{e}\nStackTrace:\n{e.StackTrace}"); + try + { + item.Sight = Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_sights.Length / 2, weapon.mod_sights.Length)); + item.Barrel = Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_barrels.Length / 2, weapon.mod_barrels.Length)); + item.Other = Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_others.Length / 2, weapon.mod_others.Length)); + + __instance.NetworkweaponMods = new global::Pickup.WeaponModifiers(true, Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_sights.Length / 2, weapon.mod_sights.Length)), Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_barrels.Length / 2, weapon.mod_barrels.Length)), Mathf.Max(0, UnityEngine.Random.Range(-weapon.mod_others.Length / 2, weapon.mod_others.Length))); + } + catch (Exception e) + { + Logger.Get.Error($"Synapse-Event: RefreshDurability failed!!\n{e}\nStackTrace:\n{e.StackTrace}"); + } } - } + } + catch(Exception e) + { + Logger.Get.Error($"Synapse-Item: RefreshDurabillity failed!!\n{e}\nStackTrace:\n{e.StackTrace}"); + } return false; } } diff --git a/Synapse/Patches/SynapsePatches/Wrapper/DoorStartPatch.cs b/Synapse/Patches/SynapsePatches/Wrapper/DoorStartPatch.cs deleted file mode 100644 index ada50afc..00000000 --- a/Synapse/Patches/SynapsePatches/Wrapper/DoorStartPatch.cs +++ /dev/null @@ -1,20 +0,0 @@ -using HarmonyLib; -using Synapse.Api; -using System.Linq; -using Interactables.Interobjects.DoorUtils; - -// ReSharper disable All -namespace Synapse.Patches.SynapsePatches -{ - [HarmonyPatch(typeof(DoorVariant), nameof(DoorVariant.Start))] - internal class DoorStartPatch - { - private static void Postfix(DoorVariant __instance) - { - while (Map.Get.Doors.Select(x => x.GameObject).Contains(null)) - Map.Get.Doors.Remove(Map.Get.Doors.FirstOrDefault(x => x.GameObject == null)); - - SynapseController.Server.Map.Doors.Add(new Api.Door(__instance)); - } - } -} diff --git a/Synapse/Properties/AssemblyInfo.cs b/Synapse/Properties/AssemblyInfo.cs index 3ecb49f8..db94b72f 100644 --- a/Synapse/Properties/AssemblyInfo.cs +++ b/Synapse/Properties/AssemblyInfo.cs @@ -5,5 +5,5 @@ [assembly: AssemblyCompany("Synapse-DevTeam")] [assembly: AssemblyProduct("Synapse")] [assembly: AssemblyCopyright("Copyright © Synapse-DevTeam 2020")] -[assembly: AssemblyVersion("2.4.0.0")] -[assembly: AssemblyFileVersion("2.4.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.4.1.0")] +[assembly: AssemblyFileVersion("2.4.1.0")] \ No newline at end of file diff --git a/Synapse/Synapse.csproj b/Synapse/Synapse.csproj index 5c063d72..f9d88b5e 100644 --- a/Synapse/Synapse.csproj +++ b/Synapse/Synapse.csproj @@ -178,7 +178,6 @@ - @@ -219,6 +218,9 @@ + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + False ..\Refs\UnityEngine.dll diff --git a/Synapse/SynapseController.cs b/Synapse/SynapseController.cs index 79bc3564..a3e2fef3 100644 --- a/Synapse/SynapseController.cs +++ b/Synapse/SynapseController.cs @@ -54,6 +54,6 @@ private void PatchMethods() public const int SynapseMajor = 2; public const int SynapseMinor = 4; - public const int SynapsePatch = 0; - public const string SynapseVersion = "2.4.0"; + public const int SynapsePatch = 1; + public const string SynapseVersion = "2.4.1"; } diff --git a/Synapse/SynapseExtensions.cs b/Synapse/SynapseExtensions.cs index 0f797197..e15ffc9b 100644 --- a/Synapse/SynapseExtensions.cs +++ b/Synapse/SynapseExtensions.cs @@ -55,12 +55,11 @@ public static void RaMessage(this CommandSender sender, string message, bool suc public static Synapse.Api.WorkStation GetWorkStation(this WorkStation station) => Map.Get.WorkStations.FirstOrDefault(x => x.GameObject == station.gameObject); public static Synapse.Api.Items.SynapseItem GetSynapseItem(this Inventory.SyncItemInfo info) => Map.Get.Items.FirstOrDefault(x => x.itemInfo == info); - public static Synapse.Api.Items.SynapseItem GetSynapseItem(this Pickup pickup) => Map.Get.Items.FirstOrDefault(x => x.pickup == pickup); public static bool CanHarmScp(Player player) { - if(player.CustomRole != null && player.CustomRole.GetFriends().Any(x => x == Team.SCP)) + if (player.CustomRole != null && player.CustomRole.GetFriends().Any(x => x == Team.SCP)) { player.GiveTextHint(Server.Get.Configs.SynapseTranslation.GetTranslation("scpteam")); return false; diff --git a/Synapse/packages.config b/Synapse/packages.config index 183b8519..1f32dbab 100644 --- a/Synapse/packages.config +++ b/Synapse/packages.config @@ -2,5 +2,6 @@ + \ No newline at end of file