Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #110 from SynapseSL/patch
Browse files Browse the repository at this point in the history
Synapse 2.10.1
  • Loading branch information
GrafDimenzio authored Jun 10, 2022
2 parents 7886091 + dfcca31 commit 65bd755
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 69 deletions.
5 changes: 5 additions & 0 deletions Synapse/Api/CustomObjects/SynapseDoorObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public SynapseDoorObject(SpawnableDoorType type, Vector3 position, Quaternion ro
public override GameObject GameObject => Door.GameObject;
public override NetworkIdentity NetworkIdentity => Door.VDoor.netIdentity;
public override ObjectType Type => ObjectType.Door;
public override void Destroy()
{
Map.Get.Doors.Remove(Door);
base.Destroy();
}

public Door Door { get; }
public SpawnableDoorType DoorType { get; }
Expand Down
6 changes: 6 additions & 0 deletions Synapse/Api/CustomObjects/SynapseGeneratorObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ internal SynapseGeneratorObject(SynapseSchematic.GeneratorConfiguration configur
public override GameObject GameObject => Generator.GameObject;
public override NetworkIdentity NetworkIdentity => Generator.generator.netIdentity;
public override ObjectType Type => ObjectType.Generator;
public override void Destroy()
{
//The Generator will add itself on first Start to Map.Generators
Map.Get.Generators.Remove(Generator);
base.Destroy();
}

public Generator Generator { get; }
}
Expand Down
5 changes: 5 additions & 0 deletions Synapse/Api/CustomObjects/SynapseLockerObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ internal SynapseLockerObject(SynapseSchematic.LockerConfiguration configuration)
public override NetworkIdentity NetworkIdentity => Locker.locker.netIdentity;
public override GameObject GameObject => Locker.GameObject;
public override ObjectType Type => ObjectType.Locker;
public override void Destroy()
{
Map.Get.Lockers.Remove(Locker);
base.Destroy();
}

public LockerType LockerType { get; }

Expand Down
5 changes: 5 additions & 0 deletions Synapse/Api/CustomObjects/SynapseRagdollObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public override void ApplyPhysics()
foreach (var rigid in Ragdoll.ragdoll.AllRigidbodies)
rigid.useGravity = true;
}
public override void Destroy()
{
Map.Get.Ragdolls.Remove(Ragdoll);
base.Destroy();
}

public RoleType RoleType => Ragdoll.RoleType;
public DamageType DamageType => Ragdoll.ragdoll.Info.Handler.GetDamageType();
Expand Down
5 changes: 5 additions & 0 deletions Synapse/Api/CustomObjects/SynapseWorkStationObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public SynapseWorkStationObject(Vector3 position, Quaternion rotation, Vector3 s
public override GameObject GameObject => WorkStation.GameObject;
public override NetworkIdentity NetworkIdentity => WorkStation.workStation.netIdentity;
public override ObjectType Type => ObjectType.Workstation;
public override void Destroy()
{
Map.Get.WorkStations.Remove(WorkStation);
base.Destroy();
}


public WorkStation WorkStation { get; }
Expand Down
7 changes: 6 additions & 1 deletion Synapse/Api/Enum/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public enum Effect
/// <summary>
/// Increases movement speed
/// </summary>
/// <remarks>0 = Disabled, each intensity point adds 1% of movement speed (max 355)</remarks>
/// <remarks>0 = Disabled, each intensity point adds 1% of movement speed (max 255)</remarks>
MovementBoost,
/// <summary>
/// Reduces severity of Amnesia, Bleeding, Burned, Concussed, Hemorrhage, Poisoned and SCP-207.
Expand All @@ -158,5 +158,10 @@ public enum Effect
/// </summary>
/// <remarks>0 = Disabled, 1 = Enabled</remarks>
Vitality,
/// <summary>
/// Turns the screen black.
/// </summary>
/// <remarks>0 = Disabled, 1 = Enabled</remarks>
Visuals173Blink
}
}
2 changes: 1 addition & 1 deletion Synapse/Api/Events/ScpEvents.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Synapse.Api.Enum;
using Synapse.Api.Enum;
using Synapse.Api.Events.SynapseEventArguments;
using UnityEngine;

Expand Down
4 changes: 2 additions & 2 deletions Synapse/Api/Events/SynapseEventArguments/ScpEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;

namespace Synapse.Api.Events.SynapseEventArguments
{
Expand Down Expand Up @@ -152,4 +152,4 @@ public class Scp049ReviveEvent : EventHandler.ISynapseEventArgs
public bool Finish { get; internal set; }
public bool Allow { get; set; } = true;
}
}
}
5 changes: 3 additions & 2 deletions Synapse/Api/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ public SynapseItem SpawnGrenade(Vector3 position, Vector3 velocity, float fuseti
var grenadeitem = new SynapseItem(itemtype, position);
grenadeitem.Throwable.Fuse();
grenadeitem.Throwable.FuseTime = fusetime;
if (player != null)
grenadeitem.Throwable.ThrowableItem.PreviousOwner = new Footprinting.Footprint(player.Hub);

if (player == null) player = Server.Get.Host;
grenadeitem.Throwable.ThrowableItem.PreviousOwner = new Footprinting.Footprint(player.Hub);

if(grenadeitem.Throwable.ThrowableItem.TryGetComponent<Rigidbody>(out var rgb))
rgb.velocity = velocity;
Expand Down
6 changes: 4 additions & 2 deletions Synapse/Api/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ public uint GetPreference(ItemType item)

public void ChangeRoleAtPosition(RoleType role)
{
RoleChangeClassIdPatch.ForceLite = true;
LiteRoleSet = true;
Hub.characterClassManager.SetClassIDAdv(role, true, CharacterClassManager.SpawnReason.ForceClass);
RoleChangeClassIdPatch.ForceLite = false;
LiteRoleSet = false;
}

internal bool LiteRoleSet { get; set; } = false;

public void GiveTextHint(string message, float duration = 5f)
{
Hub.hints.Show(new TextHint(message, new HintParameter[]
Expand Down
155 changes: 105 additions & 50 deletions Synapse/Patches/EventsPatches/PlayerPatches/PlayerBasicItemUsePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,67 @@
using HarmonyLib;
using InventorySystem.Items.Usables;
using Mirror;
using Synapse.Api;
using Synapse.Api.Events.SynapseEventArguments;
using UnityEngine;
using Utils.Networking;
using Logger = Synapse.Api.Logger;

namespace Synapse.Patches.EventsPatches.PlayerPatches
{
[HarmonyPatch(typeof(UsableItem), nameof(UsableItem.OnUsingStarted))]
internal static class UsableStartPatch
[HarmonyPatch(typeof(UsableItemsController), nameof(UsableItemsController.ServerReceivedStatus))]
internal static class ReceivedMessagePatch
{
[HarmonyPrefix]
private static bool StartPatch(UsableItem __instance)
private static bool OnMessage(NetworkConnection conn, StatusMessage msg)
{
try
{
var item = __instance.GetSynapseItem();
var player = item.ItemHolder;
var player = conn.GetPlayer();
if (player == null) return false;
if (player.ItemInHand.Serial != msg.ItemSerial) return false;
if (!(player.ItemInHand.ItemBase is UsableItem usable)) return false;
var handler = UsableItemsController.GetHandler(player.Hub);
var allow = true;

Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, ItemInteractState.Initiating, ref allow);

return allow;
var item = player.ItemInHand;
switch (msg.Status)
{
case StatusMessage.StatusType.Start:
if (handler.CurrentUsable.ItemSerial != 0) return false;
if (!usable.CanStartUsing) return false;
var cooldown = UsableItemsController.GetCooldown(msg.ItemSerial, usable, handler);
if (cooldown > 0f)
{
conn.Send(new ItemCooldownMessage(msg.ItemSerial, cooldown));
return false;
}

Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, ItemInteractState.Initiating, ref allow);
if (!allow) return false;

handler.CurrentUsable = new CurrentlyUsedItem(usable, msg.ItemSerial, Time.timeSinceLevelLoad);
handler.CurrentUsable.Item.OnUsingStarted();
new StatusMessage(StatusMessage.StatusType.Start,msg.ItemSerial).SendToAuthenticated();
break;

case StatusMessage.StatusType.Cancel:
if (handler.CurrentUsable.ItemSerial == 0) return false;
if (handler.CurrentUsable.StartTime + handler.CurrentUsable.Item.MaxCancellableTime <=
Time.timeSinceLevelLoad) return false;

Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, ItemInteractState.Stopping, ref allow);
if (!allow) return false;

handler.CurrentUsable.Item.OnUsingCancelled();
handler.CurrentUsable = CurrentlyUsedItem.None;
new StatusMessage(StatusMessage.StatusType.Cancel, msg.ItemSerial).SendToAuthenticated();
break;
}

return false;
}
catch (Exception e)
catch (Exception ex)
{
Logger.Get.Error($"Synapse-Event: PlayerItemUseEvent Start failed!!\n{e}");
Logger.Get.Error($"Synapse-Event: PlayerItemUseEvent Receive Message failed!!\n{ex}");
return true;
}
}
Expand All @@ -34,25 +71,30 @@ private static bool StartPatch(UsableItem __instance)
[HarmonyPatch(typeof(Consumable), nameof(Consumable.ServerOnUsingCompleted))]
internal static class UsableUsingCompletePatch
{
internal static bool ExecuteFinalizingEvent(Consumable consumable)
{
var item = consumable.GetSynapseItem();
var player = item.ItemHolder;
var allow = true;

Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, ItemInteractState.Finalizing, ref allow);

if (!allow)
{
consumable.OnUsingCancelled();
var handler = UsableItemsController.GetHandler(consumable.Owner);
handler.CurrentUsable = CurrentlyUsedItem.None;
NetworkServer.SendToAll(new StatusMessage(StatusMessage.StatusType.Cancel, item.Serial), 0, false);
}
return allow;
}

[HarmonyPrefix]
private static bool CompletePatch(Consumable __instance)
{
try
{
var item = __instance.GetSynapseItem();
var player = item.ItemHolder;
var allow = true;

Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, ItemInteractState.Finalizing, ref allow);

if (!allow)
{
__instance.OnUsingCancelled();
var handler = UsableItemsController.GetHandler(__instance.Owner);
handler.CurrentUsable = CurrentlyUsedItem.None;
NetworkServer.SendToAll(new StatusMessage(StatusMessage.StatusType.Cancel, item.Serial), 0, false);
}
return allow;
return ExecuteFinalizingEvent(__instance);
}
catch (Exception e)
{
Expand All @@ -70,20 +112,7 @@ private static bool CompletePatch(Consumable __instance)
{
try
{
var item = __instance.GetSynapseItem();
var player = item.ItemHolder;
var allow = true;

Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, ItemInteractState.Finalizing, ref allow);

if (!allow)
{
__instance.OnUsingCancelled();
var handler = UsableItemsController.GetHandler(__instance.Owner);
handler.CurrentUsable = CurrentlyUsedItem.None;
NetworkServer.SendToAll(new StatusMessage(StatusMessage.StatusType.Cancel, item.Serial), 0, false);
}
return allow;
return UsableUsingCompletePatch.ExecuteFinalizingEvent(__instance);
}
catch (Exception e)
{
Expand All @@ -93,25 +122,51 @@ private static bool CompletePatch(Consumable __instance)
}
}

[HarmonyPatch(typeof(UsableItem), nameof(UsableItem.OnUsingCancelled))]
internal static class UsableCancelPatch
[HarmonyPatch(typeof(Consumable), nameof(Consumable.EquipUpdate))]
internal static class EquipPatch
{
[HarmonyPrefix]
private static bool CancelPatch(UsableItem __instance)
private static bool OnEquip(Consumable __instance)
{
try
{
var item = __instance.GetSynapseItem();
var player = item.ItemHolder;
var allow = true;
if (__instance.ActivationReady)
{
if(UsableUsingCompletePatch.ExecuteFinalizingEvent(__instance))
__instance.ActivateEffects();
}
return false;
}
catch (Exception ex)
{
Logger.Get.Error($"Synapse-Event: PlayerItemUseEvent Finalizing Equip failed!!\n{ex}");
return true;
}
}
}

Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, ItemInteractState.Stopping, ref allow);
[HarmonyPatch(typeof(Consumable), nameof(Consumable.OnRemoved))]
internal static class RemovedPatch
{
[HarmonyPrefix]
private static bool OnRemove(Consumable __instance,InventorySystem.Items.Pickups.ItemPickupBase pickup)
{
try
{
if(__instance.ActivationReady && UsableUsingCompletePatch.ExecuteFinalizingEvent(__instance))
__instance.ActivateEffects();

if(__instance._alreadyActivated && pickup != null)
pickup.DestroySelf();

if(NetworkServer.active)
UsableItemsController.GetHandler(__instance.Owner).CurrentUsable = CurrentlyUsedItem.None;

return allow;
return false;
}
catch (Exception e)
catch (Exception ex)
{
Logger.Get.Error($"Synapse-Event: PlayerItemUseEvent Cancel failed!!\n{e}");
Logger.Get.Error($"Synapse-Event: PlayerItemUseEvent Finalizing Remove failed!!\n{ex}");
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ private static bool OnPlayerMovementSync(PlayerMovementSync __instance)
{
var player = __instance.GetPlayer();
var args = player.setClassEventArgs;
if (args == null) return false;
if (player.LiteRoleSet) return false;
if (args == null) return true;
var rot = new PlayerMovementSync.PlayerRotation?(new PlayerMovementSync.PlayerRotation(new float?(0f), new float?(args.Rotation)));
Timing.RunCoroutine(__instance.SafelySpawnPlayer(args.Position, rot), Segment.FixedUpdate);
return false;
Expand Down Expand Up @@ -180,7 +181,7 @@ private static bool OnClassChanged(HealthStat __instance)
try
{
var player = __instance.GetPlayer();
if (player.setClassEventArgs == null) return false;
if (player.LiteRoleSet) return false;

player.MaxHealth = player.ClassManager.CurRole.maxHP;
return true;
Expand All @@ -201,7 +202,7 @@ private static bool OnReset(ReferenceHub ply)
{
try
{
if (ply?.GetPlayer()?.setClassEventArgs == null) return false;
if (ply?.GetPlayer().LiteRoleSet == true) return false;
return true;
}
catch(Exception ex)
Expand All @@ -220,7 +221,7 @@ private static bool OnReset(ReferenceHub targetHub)
{
try
{
if (targetHub?.GetPlayer()?.setClassEventArgs == null) return false;
if (targetHub?.GetPlayer()?.LiteRoleSet == true) return false;
return true;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ namespace Synapse.Patches.EventsPatches.PlayerPatches
[HarmonyPatch(typeof(CharacterClassManager), nameof(CharacterClassManager.SetClassIDHook))]
internal static class RoleChangeClassIdPatch
{
internal static bool ForceLite = false;

[HarmonyPrefix]
private static bool SetClass(CharacterClassManager __instance, RoleType id)
{
__instance.SetClassIDAdv(id, ForceLite, CharacterClassManager.SpawnReason.None, true);
var player = __instance.GetPlayer();
__instance.SetClassIDAdv(id, player.LiteRoleSet, CharacterClassManager.SpawnReason.None, true);
return false;
}
}
Expand All @@ -22,7 +21,8 @@ internal static class RoleChangeClassIdPatch2
[HarmonyPrefix]
private static bool SetClass(CharacterClassManager __instance, RoleType id, CharacterClassManager.SpawnReason spawnReason)
{
__instance.SetClassIDAdv(id, RoleChangeClassIdPatch.ForceLite, spawnReason, false);
var player = __instance.GetPlayer();
__instance.SetClassIDAdv(id, player.LiteRoleSet, spawnReason, false);
return false;
}
}
Expand Down
Loading

0 comments on commit 65bd755

Please sign in to comment.