From 184f178ea0056bd7ca1ddb37f646cdf98c7631f1 Mon Sep 17 00:00:00 2001 From: GrafDimenzio Date: Tue, 4 Aug 2020 10:12:21 +0200 Subject: [PATCH] fixed GeneratorEvent for Synapse version 1.1.2 --- .../MapPatches/GeneratorPatches.cs | 135 +++++++++--------- Synapse/Properties/AssemblyInfo.cs | 4 +- 2 files changed, 73 insertions(+), 66 deletions(-) diff --git a/Synapse/Events/Patches/EventPatches/MapPatches/GeneratorPatches.cs b/Synapse/Events/Patches/EventPatches/MapPatches/GeneratorPatches.cs index 6e7a023..4c3144a 100644 --- a/Synapse/Events/Patches/EventPatches/MapPatches/GeneratorPatches.cs +++ b/Synapse/Events/Patches/EventPatches/MapPatches/GeneratorPatches.cs @@ -1,68 +1,75 @@ -using Harmony; +using System; +using Harmony; +using Mirror; using Synapse.Api; using UnityEngine; namespace Synapse.Events.Patches { - /* - [HarmonyPatch(typeof(Generator079), nameof(Generator079.Interact))] - public static class GeneratorTabletPatches - { - public static bool Prefix(Generator079 __instance, GameObject person, string command) - { - try - { - var player = person.GetPlayer(); - - if (player == null) - { - Log.Error("GeneratorEventError: a GameObject which is not a Player used a Generator?"); - return false; - } - - if (command.StartsWith("EPS_DOOR")) return true; - - if (command.StartsWith("EPS_TABLET")) - { - if (__instance.isTabletConnected || !__instance.isDoorOpen || __instance._localTime <= 0f || Generator079.mainGenerator.forcedOvercharge) return false; - - var component = person.GetComponent(); - var enumerator = component.items.GetEnumerator(); - while (enumerator.MoveNext()) - { - var syncItemInfo = enumerator.Current; - if (syncItemInfo.id != ItemType.WeaponManagerTablet) continue; - var allow = player.Team != Team.SCP; - Events.InvokeGeneratorInserted(player, __instance, ref allow); - if (!allow) return false; - component.items.Remove(syncItemInfo); - __instance.NetworkisTabletConnected = true; - return false; - } - } - - if (!command.StartsWith("EPS_CANCEL")) return true; + [HarmonyPatch(typeof(Generator079), nameof(Generator079.Interact))] + public static class GeneratorTabletPatches + { + public static bool Prefix(Generator079 __instance, GameObject person, PlayerInteract.Generator079Operations command) + { + try + { + switch (command) { - if (!__instance.isTabletConnected) return false; - var allow = true; - - Events.InvokeGeneratorEjected(player, __instance, ref allow); - return allow; + case PlayerInteract.Generator079Operations.Door: + + + + break; + + case PlayerInteract.Generator079Operations.Tablet: + + if (__instance.isTabletConnected || !__instance.isDoorOpen || __instance._localTime <= 0f || Generator079.mainGenerator.forcedOvercharge) + { + return false; + } + Inventory component = person.GetComponent(); + using (SyncList.SyncListEnumerator enumerator = component.items.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + Inventory.SyncItemInfo syncItemInfo = enumerator.Current; + if (syncItemInfo.id == ItemType.WeaponManagerTablet) + { + var allow2 = true; + Events.InvokeGeneratorInserted(person.GetPlayer(), __instance, ref allow2); + if (!allow2) break; + + component.items.Remove(syncItemInfo); + __instance.NetworkisTabletConnected = true; + break; + } + } + } + break; + + case PlayerInteract.Generator079Operations.Cancel: + if (!__instance.isTabletConnected) break; + + var allow = true; + Events.InvokeGeneratorEjected(person.GetPlayer(), __instance, ref allow); + if (!allow) break; + return true; } - } + return false; + } catch (Exception e) - { + { Log.Error($"GeneratorTablet Event Error: {e}"); return true; - } - } - }*/ - - [HarmonyPatch(typeof(Generator079), nameof(Generator079.OpenClose))] - public static class GeneratorDoorPatches - { - public static bool Prefix(Generator079 __instance, GameObject person) - { + } + } + } + + [HarmonyPatch(typeof(Generator079), nameof(Generator079.OpenClose))] + public static class GeneratorDoorPatches + { + public static bool Prefix(Generator079 __instance, GameObject person) + { var player = person.GetPlayer(); var component = person.GetComponent(); @@ -73,19 +80,19 @@ public static bool Prefix(Generator079 __instance, GameObject person) { var allow = true; if (!__instance.NetworkisDoorOpen) - { + { Events.InvokeGeneratorOpen(player, __instance, ref allow); - } - else - { + } + else + { Events.InvokeGeneratorClose(player, __instance, ref allow); - } + } if (!allow) - { + { __instance.RpcDenied(); return false; - } + } __instance._doorAnimationCooldown = 1.5f; __instance.NetworkisDoorOpen = !__instance.isDoorOpen; @@ -96,7 +103,7 @@ public static bool Prefix(Generator079 __instance, GameObject person) //Unlock The Generator var flag = player.Bypass; var flag2 = player.Team != Team.SCP; - + if (flag2 && component.curItem > ItemType.KeycardJanitor) { var permissions = component.GetItemByID(component.curItem).permissions; @@ -118,5 +125,5 @@ public static bool Prefix(Generator079 __instance, GameObject person) return false; } - } + } } diff --git a/Synapse/Properties/AssemblyInfo.cs b/Synapse/Properties/AssemblyInfo.cs index 936c7cd..f1c783e 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.1.0")] -[assembly: AssemblyFileVersion("1.1.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.1.2")] +[assembly: AssemblyFileVersion("1.1.2")] \ No newline at end of file