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

Commit

Permalink
update to 11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
GrafDimenzio committed Apr 12, 2022
1 parent ab57c58 commit a0ff7af
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 60 deletions.
Binary file modified Refs/Assembly-CSharp-Publicized.dll
Binary file not shown.
8 changes: 4 additions & 4 deletions Synapse/Api/Dummy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,31 @@ private IEnumerator<float> Update()
var pos = Position + Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
Player.PlayerMovementSync.OverridePosition(pos, null, true);
else wall = true;
break;

case MovementDirection.BackWards:
pos = Position - Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
Player.PlayerMovementSync.OverridePosition(pos, null, true);
else wall = true;
break;

case MovementDirection.Right:
pos = Position + Quaternion.AngleAxis(90, Vector3.up) * Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
Player.PlayerMovementSync.OverridePosition(pos, null, true);
else wall = true;
break;

case MovementDirection.Left:
pos = Position - Quaternion.AngleAxis(90, Vector3.up) * Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
Player.PlayerMovementSync.OverridePosition(pos, null, true);
else wall = true;
break;
}
Expand Down
1 change: 1 addition & 0 deletions Synapse/Api/Enum/ShootSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public enum ShootSound
Revolver = 39,
AK = 40,
Shotgun = 41,
ParticleDisruptor = 47,
}
}
13 changes: 13 additions & 0 deletions Synapse/Api/Events/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ internal EventHandler()
Server.UpdateEvent += OnUpdate;
#if DEBUG
Player.PlayerKeyPressEvent += KeyPress;
Player.PlayerItemUseEvent += Player_PlayerItemUseEvent;
#endif
}

private void Player_PlayerItemUseEvent(SynapseEventArguments.PlayerItemInteractEventArgs ev)
{
if (ev.CurrentItem.ItemType == ItemType.SCP018 && ev.State == SynapseEventArguments.ItemInteractState.Initiating)
ev.Allow = false;

if (ev.CurrentItem.ItemType == ItemType.GrenadeHE && ev.State == SynapseEventArguments.ItemInteractState.Finalizing)
ev.Allow = false;

if (ev.CurrentItem.ItemType == ItemType.GrenadeFlash && ev.State == SynapseEventArguments.ItemInteractState.Stopping)
ev.Allow = false;
}

private void KeyPress(SynapseEventArguments.PlayerKeyPressEventArgs ev)
{
switch (ev.KeyCode)
Expand Down
7 changes: 5 additions & 2 deletions Synapse/Api/Items/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ItemManager
{
public static ItemManager Get => Server.Get.ItemManager;

public const int HighestItem = (int)ItemType.SCP244b;
public const int HighestItem = (int)ItemType.ParticleDisruptor;

private readonly List<CustomItemInformation> customItems = new List<CustomItemInformation>();

Expand Down Expand Up @@ -40,10 +40,13 @@ public string GetName(int id)
public SynapseSchematic GetSchematic(int id)
{
if (id >= 0 && id <= HighestItem)
{
if (!overridenVanillaSchematics.ContainsKey((ItemType)id)) return null;
return overridenVanillaSchematics.FirstOrDefault(x => x.Key == (ItemType)id).Value;
}

var item = customItems.FirstOrDefault(x => x.ID == id);
if (item.SchematicID < 0) return null;
if (item == null || item.SchematicID < 0) return null;
return SchematicHandler.Get.GetSchematic(item.SchematicID);
}

Expand Down
6 changes: 5 additions & 1 deletion Synapse/Api/Nuke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public float CountdownTime

public void InstantPrepare() => WarheadController.InstantPrepare();

public void Shake() => WarheadController.RpcShake(false);
public void Shake()
{
foreach (var player in Server.Get.Players)
WarheadController.TargetRpcShake(player.Connection, true, false);
}

public class NukeInsidePanel
{
Expand Down
27 changes: 12 additions & 15 deletions Synapse/Api/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,7 @@ public void DimScreen()
}

public void ShakeScreen(bool achieve = false)
{
var component = AlphaWarheadController.Host;
var writer = NetworkWriterPool.GetWriter();
writer.WriteBoolean(achieve);
var msg = new RpcMessage
{
netId = component.netId,
componentIndex = component.ComponentIndex,
functionHash = typeof(AlphaWarheadController).FullName.GetStableHashCode() * 503 + "RpcShake".GetStableHashCode(),
payload = writer.ToArraySegment()
};
Connection.Send(msg);
NetworkWriterPool.Recycle(writer);
}
=> AlphaWarheadController.Host.TargetRpcShake(Connection, achieve, GodMode);

public void PlaceBlood(Vector3 pos, int type = 1, float size = 2f)
{
Expand Down Expand Up @@ -525,7 +512,7 @@ public bool GodMode
public Vector3 Position
{
get => PlayerMovementSync.GetRealPosition();
set => PlayerMovementSync.OverridePosition(value, 0f);
set => PlayerMovementSync.OverridePosition(value, PlayerRotation);
}

public Vector2 Rotation
Expand All @@ -534,6 +521,16 @@ public Vector2 Rotation
set => PlayerMovementSync.NetworkRotationSync = value;
}

public PlayerMovementSync.PlayerRotation PlayerRotation
{
get
{
var vec2 = Rotation;
return new PlayerMovementSync.PlayerRotation(vec2.x, vec2.y);
}
set => Rotation = new Vector2(value.x.Value, value.y.Value);
}

public Vector3 DeathPosition
{
get => ClassManager.DeathPosition;
Expand Down
2 changes: 1 addition & 1 deletion Synapse/Api/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static NetworkIdentity GetNetworkIdentity(RoomName room)
if(networkIdentities == null) networkIdentities = GameObject.FindObjectsOfType<NetworkIdentity>().Where(x => x.name.Contains("All")).ToList();
switch (room)
{
case MapGeneration.RoomName.Lcz012:
case MapGeneration.RoomName.Lcz330:
return networkIdentities.FirstOrDefault(x => x.assetId == new System.Guid("17f38aa5-1bc8-8bc4-0ad1-fffcbe4214ae"));

case MapGeneration.RoomName.Hcz939:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ private static bool OnPlayerMovementSync(PlayerMovementSync __instance)
var player = __instance.GetPlayer();
var args = player.setClassEventArgs;
if (args == null) return false;
Timing.RunCoroutine(__instance.SafelySpawnPlayer(args.Position, args.Rotation), Segment.FixedUpdate);
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;
}
catch(Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,63 @@
using HarmonyLib;
using InventorySystem.Items.ThrowableProjectiles;
using Mirror;
using Synapse.Api;
using Synapse.Api.Items;
using Utils.Networking;

namespace Synapse.Patches.EventsPatches.PlayerPatches
{
[HarmonyPatch(typeof(ThrowableNetworkHandler), nameof(ThrowableNetworkHandler.ServerProcessMessages))]
[HarmonyPatch(typeof(ThrowableNetworkHandler), nameof(ThrowableNetworkHandler.ServerProcessRequest))]
internal static class PlayerThrowGrenadePatch
{
[HarmonyPrefix]
private static bool OnThrow(NetworkConnection conn, ThrowableNetworkHandler.ThrowableItemMessage msg)
private static bool OnThrow(NetworkConnection conn, ThrowableNetworkHandler.ThrowableItemRequestMessage msg)
{
try
{
var player = conn.GetPlayer();
if (player == null || player.ItemInHand?.Serial != msg.Serial) return false;
if (!(player.ItemInHand.ItemBase is ThrowableItem throwable)) return false;
var allow = true;

switch (msg.Request)
{
case ThrowableNetworkHandler.RequestType.BeginThrow:
if (throwable.ActivationStopwatch.IsRunning) return false;

Server.Get.Events.Player.InvokeThrowGrenade(player, player.ItemInHand, out var allow);
if (!throwable.AllowHolster) return false;
Server.Get.Events.Player.InvokePlayerItemUseEvent(player, player.ItemInHand, Api.Events.SynapseEventArguments.ItemInteractState.Initiating, ref allow);
if (!allow)
{
var item = player.ItemInHand;
//A Newitem with a new Serial is needed or else the client will try to throw it locally
var newitem = new Synapse.Api.Items.SynapseItem(item.ID);
newitem.Durabillity = item.Durabillity;
newitem.ItemData = item.ItemData;
item.Destroy();
newitem.PickUp(player);
ForceStop(throwable, player);
return false;
}
throwable.ActivationStopwatch.Start();
throwable.ServerProcessInitiation();
break;

case ThrowableNetworkHandler.RequestType.ConfirmThrowWeak:
case ThrowableNetworkHandler.RequestType.ConfirmThrowFullForce:
if (msg.Request - ThrowableNetworkHandler.RequestType.ConfirmThrowWeak > 1) return false;
if (throwable.ActivationStopwatch.Elapsed.TotalSeconds < throwable.MinimalAnimationTime * 0.8f) return false;

allow = true;
Server.Get.Events.Player.InvokeThrowGrenade(player, player.ItemInHand, out allow);
Server.Get.Events.Player.InvokePlayerItemUseEvent(player, player.ItemInHand, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref allow);

if (!allow)
{
var item = player.ItemInHand;
var newitem = new Synapse.Api.Items.SynapseItem(item.ID);
newitem.Durabillity = item.Durabillity;
item.Destroy();
newitem.PickUp(player);
ForceStop(throwable, player);
return false;
}
throwable.ActivationStopwatch.Start();

var pos = player.CameraReference.position;
var rot = player.CameraReference.rotation;
var bounds = player.PlayerMovementSync.Tracer.GenerateBounds(0.1f, false);
bounds.Encapsulate(pos + player.PlayerMovementSync.PlayerVelocity * 0.2f);
player.CameraReference.position = bounds.ClosestPoint(msg.CameraPosition);
player.CameraReference.rotation = msg.CameraRotation;
throwable.ServerThrow(msg.Request == ThrowableNetworkHandler.RequestType.ConfirmThrowFullForce, ThrowableNetworkHandler.GetLimitedVelocity(msg.PlayerVelocity));
player.CameraReference.position = pos;
player.CameraReference.rotation = rot;
break;
return true;

case ThrowableNetworkHandler.RequestType.CancelThrow:
allow = true;
Server.Get.Events.Player.InvokePlayerItemUseEvent(player, player.ItemInHand, Api.Events.SynapseEventArguments.ItemInteractState.Stopping, ref allow);

if (!allow)
{
ForceStop(throwable, player);
return false;
}

return true;
}
return false;
}
Expand All @@ -75,5 +68,22 @@ private static bool OnThrow(NetworkConnection conn, ThrowableNetworkHandler.Thro
return true;
}
}

private static void ForceStop(ThrowableItem throwable, Player player)
{
throwable.CancelStopwatch.Start();
throwable.ThrowStopwatch.Reset();
ReCreateItem(player, player.ItemInHand);
new ThrowableNetworkHandler.ThrowableItemAudioMessage(throwable, ThrowableNetworkHandler.RequestType.CancelThrow).SendToAuthenticated();
}

private static void ReCreateItem(Player player, SynapseItem item)
{
var newitem = new SynapseItem(item.ID);
newitem.Durabillity = item.Durabillity;
newitem.ItemData = item.ItemData;
item.Destroy();
newitem.PickUp(player);
}
}
}
6 changes: 4 additions & 2 deletions Synapse/Patches/SynapsePatches/Dummy/OverridePositionPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Synapse.Patches.SynapsePatches.Dummy
internal static class OverridePositionPatch
{
[HarmonyPrefix]
private static bool OverridePosition(PlayerMovementSync __instance, Vector3 pos, float rot, bool forceGround = false)
private static bool OverridePosition(PlayerMovementSync __instance, Vector3 pos, PlayerMovementSync.PlayerRotation? rot = null, bool forceGround = false)
{
try
{
Expand All @@ -16,7 +16,9 @@ private static bool OverridePosition(PlayerMovementSync __instance, Vector3 pos,
pos = raycastHit.point + Vector3.up * 1.23f * __instance.transform.localScale.y;
}
__instance.ForcePosition(pos);
__instance.TargetSetRotation(__instance.connectionToClient, rot);

if (rot != null)
__instance.ForceRotation(rot.Value);
}
catch { }

Expand Down
4 changes: 2 additions & 2 deletions Synapse/SynapseVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public static class SynapseVersion

public const int Patch = 0;

public const VersionType Type = VersionType.Dev;
public const VersionType Type = VersionType.None;

public const string SubVersion = "1.0";

public const string BasedGameVersion = "11.1.4";
public const string BasedGameVersion = "11.2";

public static bool Debug { get; private set; } = false;

Expand Down

0 comments on commit a0ff7af

Please sign in to comment.