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

Commit

Permalink
PlayShoot & Try RepeatingBh & Synapse Event Patch log error
Browse files Browse the repository at this point in the history
  • Loading branch information
warquys committed Jun 13, 2022
1 parent 86264a6 commit ed74a6a
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 88 deletions.
16 changes: 8 additions & 8 deletions Exemple-Plugin/Exemple-Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@
<HintPath>..\packages\Lib.Harmony.2.2.1\lib\net48\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.9.0\lib\net472\Assembly-CSharp.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.9.0\lib\net472\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="LiteDB, Version=5.0.11.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
<HintPath>..\packages\LiteDB.5.0.11\lib\net45\LiteDB.dll</HintPath>
</Reference>
<Reference Include="Mirror, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.9.0\lib\net472\Mirror.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\Mirror.dll</HintPath>
</Reference>
<Reference Include="Synapse, Version=2.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.9.0\lib\net472\Synapse.dll</HintPath>
<Reference Include="Synapse, Version=2.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\Synapse.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -59,13 +59,13 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.9.0\lib\net472\UnityEngine.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.9.0\lib\net472\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SynapseSL.2.9.0\lib\net472\UnityEngine.PhysicsModule.dll</HintPath>
<HintPath>..\packages\SynapseSL.2.10.0\lib\net472\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="YamlDotNet, Version=11.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.11.2.1\lib\net45\YamlDotNet.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion Exemple-Plugin/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<packages>
<package id="Lib.Harmony" version="2.2.1" targetFramework="net48" />
<package id="LiteDB" version="5.0.11" targetFramework="net48" />
<package id="SynapseSL" version="2.9.0" targetFramework="net48" />
<package id="SynapseSL" version="2.10.0" targetFramework="net48" />
<package id="YamlDotNet" version="11.2.1" targetFramework="net48" />
</packages>
18 changes: 14 additions & 4 deletions VT-Api/Core/Behaviour/RepeatingBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ public RepeatingBehaviour() : base() { }
#region Methods
public override void Kill()
{
OnDisable();
base.Kill();
try
{
OnDisable();
base.Kill();
}
catch (Exception e)
{
Synapse.Api.Logger.Get.Error($"Vt-Event: RepeatingBehaviour kill faild!!\n{e}\nStackTrace:\n{e.StackTrace}");
}
}

/// <summary>
Expand Down Expand Up @@ -64,8 +71,11 @@ private void ActionExecute()

private void ActionStop()
{
_Started = false;
CancelInvoke("BehaviourAction");
if (_Started)
{
CancelInvoke("BehaviourAction");
_Started = false;
}
}
#endregion
}
Expand Down
4 changes: 2 additions & 2 deletions VT-Api/Core/Command/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ public class CommandHandler

internal void Init()
{
RegisterVtCommands();
Synapse.Api.Events.EventHandler.Get.Round.WaitingForPlayersEvent += RegisterSubCommand;

RegisterVtCommands();
}

public static CommandHandler Get { get => VtController.Get.Commands; }
Expand Down Expand Up @@ -101,6 +100,7 @@ private void RegisterVtCommands()
{
if (!_firstLoad)
return;
Logger.Get.Info("Register Command");

RegisterSynapseCommand(new CallPower(), false);
}
Expand Down
2 changes: 1 addition & 1 deletion VT-Api/Core/Command/Commands/CallPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace VT_Api.Core.Command.Commands
Description = "Call the power of your role",
Usage = "no argument if you want to call your main power, if not add the id of the power",
Permission = "",
Platforms = new[] { Platform.RemoteAdmin, Platform.ServerConsole },
Platforms = new[] { Platform.ServerConsole },
Arguments = new[] { "(powerId)" }
)]
public class CallPower : ISynapseCommand
Expand Down
26 changes: 26 additions & 0 deletions VT-Api/Core/MapAndRoundManger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Logger = Synapse.Api.Logger;
using SynRagdoll = Synapse.Api.Ragdoll;
using MEC;
using InventorySystem.Items.Firearms;
using Synapse.Api.Enum;

namespace VT_Api.Core
{
Expand Down Expand Up @@ -264,5 +266,29 @@ public void MtfRespawn(bool isCI, List<Player> players, bool useTicket = true) /
RespawnManager.Singleton.RestartSequence();
});
}

public void PlayShoot(ShootSound sound, Vector3 position, byte shootSoundDistance = 25)
{
foreach (var player in Server.Get.Players)
{
var msg = new GunAudioMessage(player, 0, shootSoundDistance, player);
var to = position - player.Position;

if (player.RoleType != RoleType.Spectator && to.sqrMagnitude > 1760f)
{
to.y = 0f;
var num = Vector3.Angle(Vector3.forward, to);
if (Vector3.Dot(to.normalized, Vector3.left) > 0f)
num = 360f - num;

msg.ShooterDirection = (byte)Mathf.RoundToInt(num / 1.44f);
msg.ShooterRealDistance = (byte)Mathf.RoundToInt(Mathf.Min(to.magnitude, 255f));
}

msg.Weapon = (ItemType)sound;

player.Connection.Send(msg);
}
}
}
}
22 changes: 12 additions & 10 deletions VT-Api/Core/Roles/AbstractRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,7 @@ public virtual bool CallPower(byte power, out string message)
[API]
public virtual void Spawning()
{
if (Config != null)
{
if (Config.Health != null)
Player.Health = (float)Config.Health;
Player.MaxHealth = Config.MaxHealth ?? Player.Health;

if (Config.ArtificialHealth != null)
Player.ArtificialHealth = (float)Config.ArtificialHealth;
if (Config.MaxArtificialHealth != null)
Player.MaxArtificialHealth = (int)Config.MaxArtificialHealth;
}
}

/**
Expand Down Expand Up @@ -177,6 +167,18 @@ public sealed override void Spawn()
}

SetDisplayInfo();
if (Config != null)
{
if (Config.Health != null)
Player.Health = (float)Config.Health;
Player.MaxHealth = Config.MaxHealth ?? Player.Health;

if (Config.ArtificialHealth != null)
Player.ArtificialHealth = (float)Config.ArtificialHealth;
if (Config.MaxArtificialHealth != null)
Player.MaxArtificialHealth = (int)Config.MaxArtificialHealth;
}

Spawning();
}

Expand Down
30 changes: 5 additions & 25 deletions VT-Api/Core/VtExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,36 +265,16 @@ public static bool TryPickup(this Player.PlayerAmmoBox ammos, SynapseItem item)

public static void SetDisplayInfoRole(this Player player, string roleName)
{
/*
* TODO Rework This :
*
* Badge "pas touche"
*
* Nickname
* Role (Unit)
* CustomInfo
*
* PowerStatus
*/

// to

/*
*
* NickName
* CustomInfo
*
*
*
*
*/

player.RemoveDisplayInfo(PlayerInfoArea.Role);

if (player.Team == Team.MTF)
{
if (string.IsNullOrWhiteSpace(player.UnitName))
player.DisplayInfo = $"{roleName} ({player.UnitName})";
else
player.DisplayInfo = roleName;

player.RemoveDisplayInfo(PlayerInfoArea.UnitName);
player.DisplayInfo = $"{roleName} ({player.UnitName})";
}
else
{
Expand Down
49 changes: 23 additions & 26 deletions VT-Api/Patches/VtEvent/MapPaches/StoppingWarHeadPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using HarmonyLib;
using Interactables.Interobjects.DoorUtils;
using Mirror;
using Subtitles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Utils.Networking;

namespace VT_Api.Patches.VtEvent.MapPaches
{
Expand All @@ -19,37 +21,32 @@ private static bool NukeCancelButon(AlphaWarheadController __instance, GameObjec
{
try
{
if (!__instance.inProgress)
ServerLogs.AddLog(ServerLogs.Modules.Warhead, "Detonation cancelled.", ServerLogs.ServerLogType.GameEvent);

var flag = __instance.inProgress && __instance.timeToDetonation > 10f && !__instance._isLocked;

VtController.Get.Events.Map.InvokeWarheadStopEvent(disabler?.GetPlayer(), ref flag);

if (!flag)
return false;
if (disabler != null)
{
bool flag = __instance.timeToDetonation > 10.0 && !__instance._isLocked;

VtController.Get.Events.Map.InvokeWarheadStopEvent(disabler.GetPlayer(), ref flag);
if (!flag)
return false;
if (__instance.timeToDetonation <= 15f && disabler != null)
AchievementHandlerBase.ServerAchieve(disabler.GetComponent<NetworkIdentity>().connectionToClient, AchievementName.ThatWasClose);

if (__instance.timeToDetonation <= 15f && disabler != null)
{
AchievementHandlerBase.ServerAchieve(disabler.GetComponent<NetworkIdentity>().connectionToClient, AchievementName.ThatWasClose);
}
for (sbyte b = 0; b < __instance.scenarios_resume.Length; b = (sbyte)(b + 1))
if (__instance.scenarios_resume[b].SumTime() > __instance.timeToDetonation && __instance.scenarios_resume[b].SumTime() < __instance.scenarios_start[AlphaWarheadController._startScenario].SumTime())
__instance.NetworksyncResumeScenario = b;

for (sbyte b = 0; b < __instance.scenarios_resume.Length; b = (sbyte)(b + 1))
__instance.NetworktimeToDetonation = ((AlphaWarheadController._resumeScenario < 0) ? __instance.scenarios_start[AlphaWarheadController._startScenario].SumTime() : __instance.scenarios_resume[AlphaWarheadController._resumeScenario].SumTime()) + (float)__instance.cooldown;
__instance.NetworkinProgress = false;
DoorEventOpenerExtension.TriggerAction(DoorEventOpenerExtension.OpenerEventType.WarheadCancel);
if (NetworkServer.active)
{
__instance._autoDetonate = false;
NetworkUtils.SendToAuthenticated(new SubtitleMessage(new SubtitlePart[1]
{
if (__instance.scenarios_resume[b].SumTime() > __instance.timeToDetonation
&& __instance.scenarios_resume[b].SumTime() < __instance.scenarios_start[AlphaWarheadController._startScenario].SumTime())
{
__instance.NetworksyncResumeScenario = b;
}
}

__instance.NetworktimeToDetonation = ((AlphaWarheadController._resumeScenario < 0) ?
__instance.scenarios_start[AlphaWarheadController._startScenario].SumTime() :
__instance.scenarios_resume[AlphaWarheadController._resumeScenario].SumTime()) + __instance.cooldown;
__instance.NetworkinProgress = false;
DoorEventOpenerExtension.TriggerAction(DoorEventOpenerExtension.OpenerEventType.WarheadCancel);
if (NetworkServer.active)
__instance._autoDetonate = false;
new SubtitlePart(SubtitleType.AlphaWarheadCancelled, null)
}));
}
return false;
}
Expand Down
24 changes: 16 additions & 8 deletions VT-Api/Patches/VtEvent/PlayerPatches/SynapseDamagePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,39 @@ class SynapseDamagePatch
[HarmonyPrefix]
private static bool DamageEventPatch(PlayerEvents __instance, Player victim, Player killer, ref float damage, DamageType type, out bool allow)
{
var ev = new PlayerDamageEventArgs
{
Damage = damage,
};

try
{
var ev = new PlayerDamageEventArgs
{
Damage = damage,
};
ev.SetProperty<Player>("Killer", killer);
ev.SetProperty<Player>("Victim", victim);
ev.SetProperty<float>("Damage", damage);
ev.SetProperty<DamageType>("DamageType", type);

__instance.CallEvent("PlayerDamageEvent", ev);


allow = ev.Allow;
damage = ev.Damage;
}
catch (Exception e)
{
Synapse.Api.Logger.Get.Error($"Synapse-Event: PlayerDamage event failed!!\n{e}");
allow = ev.Allow;

return false;
}
try
{
VtController.Get.Events.Player.InvokePlayerDamagePostEvent(victim, killer, ref damage, type, ref allow);

return false;
}
catch (Exception e)
{
Synapse.Api.Logger.Get.Error($"Vt-Event: PlayerDamagePost failed!!\n{e}\nStackTrace:\n{e.StackTrace}");
allow = true;
return true;
return false;
}
}

Expand Down
14 changes: 11 additions & 3 deletions VT-Api/Patches/VtEvent/PlayerPatches/SynapseDeathPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class SynapseDeathPatch
[HarmonyPrefix]
private static bool DeathEventPatch(PlayerEvents __instance, Player victim, Player killer, DamageType type, out bool allow)
{
var ev = new PlayerDeathEventArgs();
try
{
var ev = new PlayerDeathEventArgs();

ev.Allow = true;
ev.SetProperty<Player>("Killer", killer);
ev.SetProperty<Player>("Victim", victim);
Expand All @@ -30,15 +31,22 @@ private static bool DeathEventPatch(PlayerEvents __instance, Player victim, Play
__instance.CallEvent("PlayerDeathEvent", ev);

allow = ev.Allow;

}
catch (Exception e)
{
allow = ev.Allow;
Logger.Get.Error($"Synapse-Event: PlayerDeath event failed!!\n{e}");
return false;
}
try
{
VtController.Get.Events.Player.InvokePlayerDeathPostEvent(victim, killer, type, ref allow);

return false;
}
catch (Exception e)
{
Synapse.Api.Logger.Get.Error($"Vt-Event: PlayerDamagePost failed!!\n{e}\nStackTrace:\n{e.StackTrace}");
allow = true;
return true;
}
}
Expand Down

0 comments on commit ed74a6a

Please sign in to comment.