Skip to content
This repository has been archived by the owner on Sep 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #18 from SynapseSL/development
Browse files Browse the repository at this point in the history
v1.2.1 - Gamepatch
  • Loading branch information
moelrobi authored Aug 14, 2020
2 parents d67476c + a775069 commit 3415ce0
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Synapse/Api/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public Team Side
}
}
}

/// <summary>
/// The Room where the player currently is
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions Synapse/Events/Classes/PlayerThrowGrenadeEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Diagnostics.CodeAnalysis;
using Synapse.Api;

namespace Synapse.Events.Classes
{
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
public class PlayerThrowGrenadeEvent
{
public Player Player { get; internal set; }

public ItemType Grenade { get; internal set; }

public bool Slow { get; set; }

/// <summary>
/// The time before the grenade gets launched. This value can not be higher than the throwingAnimationTime;
/// </summary>
public double FuseTime { get; set; }

public bool Allow { get; set; }
}
}
53 changes: 34 additions & 19 deletions Synapse/Events/Patches/EventPatches/MapPatches/DoorInteractPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,41 @@ public class DoorInteractPatch
{
public static bool Prefix(PlayerInteract __instance, GameObject doorId)
{
var allowTheAccess = true;
Door door = null;
try
{
if (!__instance._playerInteractRateLimit.CanExecute() ||
(__instance._hc.CufferId > 0 && !PlayerInteract.CanDisarmedInteract) || doorId == null ||
__instance._ccm.CurClass == RoleType.None || __instance._ccm.CurClass == RoleType.Spectator ||
!doorId.TryGetComponent(out door) || !((door.Buttons.Count == 0)
? __instance.ChckDis(doorId.transform.position)
: door.Buttons.Any(item => __instance.ChckDis(item.button.transform.position)))) return false;
var allowTheAccess = true;
Door door = null;

if (!__instance._playerInteractRateLimit.CanExecute() || (__instance._hc.CufferId > 0 && !PlayerInteract.CanDisarmedInteract))
{
return false;
}

if (doorId == null)
{
return false;
}

if (__instance._ccm.CurClass == RoleType.None || __instance._ccm.CurClass == RoleType.Spectator)
{
return false;
}

if (!doorId.TryGetComponent(out door))
{
return false;
}


if ((door.Buttons.Count == 0) ? (!__instance.ChckDis(doorId.transform.position)) : Enumerable.All(door.Buttons, item => !__instance.ChckDis(item.button.transform.position)))
{
return false;
}

__instance.OnInteract();

if (__instance._sr.BypassMode) {}
else if (door.PermissionLevels.HasPermission(Door.AccessRequirements.Checkpoints) &&
__instance._ccm.CurRole.team == Team.SCP) {}
else
if (!__instance._sr.BypassMode && !(door.PermissionLevels.HasPermission(Door.AccessRequirements.Checkpoints) &&
__instance._ccm.CurRole.team == Team.SCP))
{
try
{
Expand All @@ -51,20 +69,17 @@ public static bool Prefix(PlayerInteract __instance, GameObject doorId)
}

Events.InvokeDoorInteraction(__instance.gameObject.GetPlayer(), door, ref allowTheAccess);
if(allowTheAccess) door.ChangeState(__instance._sr.BypassMode);

if (allowTheAccess) door.ChangeState(__instance._sr.BypassMode);
else __instance.RpcDenied(doorId);

return false;
}
catch (Exception e)
{
Log.Error($"DoorInteraction Error: {e}");

if(allowTheAccess && door != null)
door.ChangeState(__instance._sr.BypassMode);
else __instance.RpcDenied(doorId);
return false;

return true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using Grenades;
using Harmony;
using Mirror;
using Synapse.Api;

namespace Synapse.Events.Patches
{
[HarmonyPatch(typeof(GrenadeManager), nameof(GrenadeManager.CallCmdThrowGrenade))]
public class PlayerThrowGrenadePatch
{
public static bool Prefix(ref GrenadeManager __instance, ref int id, ref bool slowThrow, ref double time)
{
try
{
var player = __instance.GetPlayer();
if (player == null) return true;
ItemType item;
switch (id)
{
case 0:
item = ItemType.GrenadeFlash;
break;
case 1:
item = ItemType.GrenadeFrag;
break;
case 2:
item = ItemType.SCP018;
break;
default:
Log.Error($"Invalid Grenade ID: {id}");
return true;
}

time -= NetworkTime.time;

Events.InvokeUseItemEvent(player, item, out var useAllow);

if (!useAllow) return false;

Events.InvokePlayerThrowGrenadeEvent(player, item, ref slowThrow, ref time, out var allow);

time += NetworkTime.time;

return allow;

}
catch (Exception e)
{
Log.Error($"Player Throw Grenade Error: {e}");
return true;
}
}
}
}
26 changes: 26 additions & 0 deletions Synapse/Events/PlayerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,5 +466,31 @@ internal static void InvokePlayerHealEvent(Player player, ref float amount, out
amount = ev.Amount;

}

public delegate void OnPlayerThrowGrenade(PlayerThrowGrenadeEvent ev);

public static event OnPlayerThrowGrenade PlayerThrowGrenadeEvent;
internal static void InvokePlayerThrowGrenadeEvent(Player player, ItemType type, ref bool slow, ref double time, out bool allow)
{
allow = true;

if (PlayerThrowGrenadeEvent == null) return;

var ev = new PlayerThrowGrenadeEvent
{
Player = player,
Grenade = type,
Slow = slow,
FuseTime = time,
Allow = allow
};

PlayerThrowGrenadeEvent.Invoke(ev);

allow = ev.Allow;
slow = ev.Slow;
time = ev.FuseTime;

}
}
}
4 changes: 2 additions & 2 deletions Synapse/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.1")]
[assembly: AssemblyFileVersion("1.2.1")]
14 changes: 7 additions & 7 deletions Synapse/Synapse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public static class Synapse
{
#region Version
private const int MajorVersion = 1;
private const int MinorVerion = 2;
private const int Patch = 0;
private const int MinorVersion = 2;
private const int Patch = 1;

public static int VersionNumber => MajorVersion * 100 + MinorVerion * 10 + Patch;
public static string Version => $"{MajorVersion}.{MinorVerion}.{Patch}";
public static int VersionNumber => MajorVersion * 100 + MinorVersion * 10 + Patch;
public static string Version => $"{MajorVersion}.{MinorVersion}.{Patch}";
#endregion

private static bool _isLoaded;
Expand Down Expand Up @@ -124,16 +124,16 @@ private static void LoadPlugin(string pluginPath)
Name = assembly.GetName().Name,
Version = assembly.ImageRuntimeVersion,
SynapseMajor = MajorVersion,
SynapseMinor = MinorVerion,
SynapseMinor = MinorVersion,
SynapsePatch = Patch
};

p.Assembly = assembly;

plugins.Add(p);
if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor == MajorVersion * 10 + MinorVerion) Log.Info($"Successfully loaded {p.Details.Name}");
if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor == MajorVersion * 10 + MinorVersion) Log.Info($"Successfully loaded {p.Details.Name}");

else if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor > MajorVersion * 10 + MinorVerion) Log.Warn($"The Plugin {p.Details.Name} is for the newer Synapse version {p.Details.GetVersionString()} but was succesfully loaded(bugs can occure)");
else if (p.Details.SynapseMajor * 10 + p.Details.SynapseMinor > MajorVersion * 10 + MinorVersion) Log.Warn($"The Plugin {p.Details.Name} is for the newer Synapse version {p.Details.GetVersionString()} but was succesfully loaded(bugs can occure)");

else Log.Warn($"The Plugin {p.Details.Name} is for the older Synapse version {p.Details.GetVersionString()} but was succesfully loaded(bugs can occure)");
}
Expand Down
2 changes: 2 additions & 0 deletions Synapse/Synapse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@
<Compile Include="Commands\ReloadPermissionsCommand.cs" />
<Compile Include="Config\ConfigManager.cs" />
<Compile Include="Events\Classes\KeyPressEvent.cs" />
<Compile Include="Events\Classes\PlayerThrowGrenadeEvent.cs" />
<Compile Include="Events\Classes\Scp106CreatePortalEvent.cs" />
<Compile Include="Events\Patches\EventPatches\MapPatches\TeslaTriggerEvent.cs" />
<Compile Include="Events\Patches\EventPatches\PlayerPatches\PlayerThrowGrenadePatch.cs" />
<Compile Include="Events\Patches\EventPatches\ScpPatches\Scp106CreatePortalPatch.cs" />
<Compile Include="Events\Patches\SynapsePatches\CommandsPatch.cs" />
<Compile Include="Synapse.cs" />
Expand Down

0 comments on commit 3415ce0

Please sign in to comment.