Skip to content

Commit

Permalink
Some moderate optimizations, new 914 upgrade event
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-119 committed Jan 20, 2020
1 parent 222d307 commit de19397
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 6 deletions.
1 change: 1 addition & 0 deletions EXILED_Events/EXILED_Events.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<Compile Include="EventHandlers.cs" />
<Compile Include="Events.cs" />
<Compile Include="LevenshteinDistance.cs" />
<Compile Include="Patches\914MachineOverride.cs" />
<Compile Include="Patches\AntiFlyOverride.cs" />
<Compile Include="Patches\CheaterReportOverride.cs" />
<Compile Include="Patches\DoorInteractionEvent.cs" />
Expand Down
63 changes: 60 additions & 3 deletions EXILED_Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static void InvokeWaitingForPlayers()
public static void InvokeGrenadeThrown(ref GrenadeManager gm, ref int id, ref bool slow, ref double fuse, ref bool allow)
{
GrenadeThrown grenadeThrown = GrenadeThrownEvent;
if (grenadeThrown == null)
return;
GrenadeThrownEvent ev = new GrenadeThrownEvent()
{
Player = Plugin.GetPlayer(gm.gameObject),
Expand All @@ -33,6 +35,9 @@ public static void InvokeGrenadeThrown(ref GrenadeManager gm, ref int id, ref bo
public delegate void SCP914Upgrade(SCP914UpgradeEvent ev);
public static void InvokeSCP914Upgrade(Scp914.Scp914Machine machine, List<CharacterClassManager> ccms, List<Pickup> pickups, Scp914.Scp914Knob knobSetting)
{
SCP914Upgrade activated = SCP914UpgradeEvent;
if (activated == null)
return;
List<ReferenceHub> players = new List<ReferenceHub>();
foreach (CharacterClassManager ccm in ccms)
{
Expand All @@ -44,8 +49,7 @@ public static void InvokeSCP914Upgrade(Scp914.Scp914Machine machine, List<Charac
{
items.Add(pick.info.itemId);
}

SCP914Upgrade activated = SCP914UpgradeEvent;

SCP914UpgradeEvent ev = new SCP914UpgradeEvent()
{
Machine = machine,
Expand All @@ -61,6 +65,9 @@ public static void InvokeSCP914Upgrade(Scp914.Scp914Machine machine, List<Charac
public static void InvokeSetClass(CharacterClassManager ccm, RoleType id)
{
SetClass setClass = SetClassEvent;
if (setClass == null)
return;

SetClassEvent ev = new SetClassEvent()
{
Player = Plugin.GetPlayer(ccm.gameObject),
Expand All @@ -83,6 +90,9 @@ public static void InvokeSetClass(CharacterClassManager ccm, RoleType id)
public static void InvokePlayerHurt(PlayerStats stats, ref PlayerStats.HitInfo info, GameObject obj)
{
PlayerHurt playerHurt = PlayerHurtEvent;
if (playerHurt == null)
return;

PlayerHurtEvent ev = new PlayerHurtEvent()
{
Attacker = Plugin.GetPlayer(stats.gameObject),
Expand All @@ -98,6 +108,9 @@ public static void InvokePlayerHurt(PlayerStats stats, ref PlayerStats.HitInfo i
public static void InvokeTriggerTesla(GameObject obj, bool hurtRange, ref bool triggerable)
{
TriggerTesla triggerTesla = TriggerTeslaEvent;
if (triggerTesla == null)
return;

TriggerTeslaEvent ev = new TriggerTeslaEvent()
{
Player = Plugin.GetPlayer(obj),
Expand All @@ -112,6 +125,9 @@ public static void InvokeTriggerTesla(GameObject obj, bool hurtRange, ref bool t
public static void InvokePlayerDeath(PlayerStats stats, ref PlayerStats.HitInfo info, GameObject obj)
{
PlayerDeath playerDeath = PlayerDeathEvent;
if (playerDeath == null)
return;

PlayerDeathEvent ev = new PlayerDeathEvent()
{
Killer = Plugin.GetPlayer(stats.gameObject),
Expand All @@ -128,6 +144,9 @@ public static void InvokePlayerDeath(PlayerStats stats, ref PlayerStats.HitInfo
public static void InvokeTeamRespawn(ref bool isChaos, ref int maxRespawn, ref List<GameObject> toRespawn)
{
TeamRespawn teamRespawn = TeamRespawnEvent;
if (teamRespawn == null)
return;

List<ReferenceHub> respawn = new List<ReferenceHub>();
foreach (GameObject obj in toRespawn)
respawn.Add(Plugin.GetPlayer(obj));
Expand All @@ -150,6 +169,9 @@ public static void InvokeTeamRespawn(ref bool isChaos, ref int maxRespawn, ref L
public static void InvokeUseMedicalItem(GameObject obj, ItemType type)
{
UseMedicalItem useMedicalItem = UseMedicalItemEvent;
if (useMedicalItem == null)
return;

MedicalItemEvent ev = new MedicalItemEvent()
{
Player = Plugin.GetPlayer(obj),
Expand All @@ -164,6 +186,9 @@ public static void InvokeUseMedicalItem(GameObject obj, ItemType type)
public static void InvokeScp096Enrage(Scp096PlayerScript script, ref bool allow)
{
Scp096Enrage scp096Enrage = Scp096EnrageEvent;
if (scp096Enrage == null)
return;

Scp096EnrageEvent ev = new Scp096EnrageEvent()
{
Player = Plugin.GetPlayer(script.gameObject),
Expand All @@ -180,6 +205,9 @@ public static void InvokeScp096Enrage(Scp096PlayerScript script, ref bool allow)
public static void InvokeScp096Calm(Scp096PlayerScript script, ref bool allow)
{
Scp096Calm scp096Calm = Scp096CalmEvent;
if (scp096Calm == null)
return;

Scp096CalmEvent ev = new Scp096CalmEvent()
{
Player = Plugin.GetPlayer(script.gameObject),
Expand All @@ -203,6 +231,9 @@ public static void InvokeRoundStart()
public static void InvokePreAuth(ref string userid, ConnectionRequest request, ref bool allow)
{
OnPreAuth preAuthEvent = PreAuthEvent;
if (preAuthEvent == null)
return;

PreauthEvent ev = new PreauthEvent()
{
Allow = allow,
Expand All @@ -228,6 +259,9 @@ public static void InvokeRoundEnd()
public static void InvokeCommand(ref string query, ref CommandSender sender, ref bool allow)
{
OnCommand adminCommandEvent = RemoteAdminCommandEvent;
if (adminCommandEvent == null)
return;

RACommandEvent ev = new RACommandEvent()
{
Allow = allow,
Expand All @@ -246,6 +280,9 @@ public static void InvokeCommand(ref string query, ref CommandSender sender, ref
public static void InvokeCheaterReport(string reporterId, string reportedId, string reportedIp, string reason, int serverId, ref bool allow)
{
OnCheaterReport onCheaterReport = CheaterReportEvent;
if (onCheaterReport == null)
return;

CheaterReportEvent ev = new CheaterReportEvent()
{
Allow = allow,
Expand All @@ -264,6 +301,9 @@ public static void InvokeCheaterReport(string reporterId, string reportedId, str
public static void InvokeWarheadEvent(PlayerInteract interaction, ref string n, ref bool allow)
{
OnWarheadCommand onWarheadCommand = WarheadCommandEvent;
if (onWarheadCommand == null)
return;

WarheadLeverEvent ev = new WarheadLeverEvent()
{
Player = Plugin.GetPlayer(interaction.gameObject),
Expand All @@ -279,6 +319,9 @@ public static void InvokeWarheadEvent(PlayerInteract interaction, ref string n,
public static void InvokeDoorInteract(GameObject player, Door door, ref bool allow)
{
OnDoorInteract onDoorInteract = DoorInteractEvent;
if (onDoorInteract == null)
return;

DoorInteractionEvent ev = new DoorInteractionEvent()
{
Player = Plugin.GetPlayer(player),
Expand All @@ -294,6 +337,9 @@ public static void InvokeDoorInteract(GameObject player, Door door, ref bool all
public static void InvokePlayerJoin(ReferenceHub hub)
{
OnPlayerJoin onPlayerJoin = PlayerJoinEvent;
if (onPlayerJoin == null)
return;

PlayerJoinEvent ev = new PlayerJoinEvent()
{
Player = hub
Expand All @@ -306,6 +352,9 @@ public static void InvokePlayerJoin(ReferenceHub hub)
public static void InvokePlayerLeave(ReferenceHub hub, string userId, GameObject obj)
{
OnPlayerLeave onPlayerLeave = PlayerLeaveEvent;
if (onPlayerLeave == null)
return;

PlayerLeaveEvent ev = new PlayerLeaveEvent()
{
Player = hub
Expand All @@ -314,9 +363,17 @@ public static void InvokePlayerLeave(ReferenceHub hub, string userId, GameObject
}
public static event OnConsoleCommand ConsoleCommandEvent;
public delegate void OnConsoleCommand(ConsoleCommandEvent ev);
public static void InvokeConsoleCommand(ReferenceHub hub, string command, bool encrypted, out string returnMessage, out string color)
public static void InvokeConsoleCommand(GameObject obj, string command, bool encrypted, out string returnMessage, out string color)
{
OnConsoleCommand onConsoleCommand = ConsoleCommandEvent;
if (onConsoleCommand == null)
{
returnMessage = string.Empty;
color = null;
return;
}

ReferenceHub hub = Plugin.GetPlayer(obj);
ConsoleCommandEvent ev = new ConsoleCommandEvent(encrypted)
{
Command = command,
Expand Down
6 changes: 4 additions & 2 deletions EXILED_Events/Patches/GameConsoleQueryOverride.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ public static bool Prefix(RemoteAdmin.QueryProcessor __instance, ref string quer
{
try
{
ReferenceHub hub = ReferenceHub.GetHub(__instance.gameObject);
Events.InvokeConsoleCommand(hub, query, encrypted, out string returnMessage, out string color);
if (EventPlugin.PlayerConsoleCommandPatchDisable)
return true;

Events.InvokeConsoleCommand(__instance.gameObject, query, encrypted, out string returnMessage, out string color);
if (color == null)
color = "white";
if (!string.IsNullOrEmpty(returnMessage))
Expand Down
2 changes: 1 addition & 1 deletion EXILED_Events/Patches/ServerNamePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ServerNamePatch
public static void Postfix()
{
ServerConsole._serverName = ServerConsole._serverName.Replace("<size=1>SM119.0.0</size>", "");
ServerConsole._serverName += " <color=#00000000><size=1>SM119.1.1.0 (EXILED)</size></color>";
ServerConsole._serverName += " <color=#00000000><size=1>SM119.1.2.0 (EXILED)</size></color>";
}
}
}
2 changes: 2 additions & 0 deletions EXILED_Events/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class EventPlugin : Plugin
public static bool WaitingForPlayersPatchDisable;
public static bool WarheadLockPatchDisable;
public static bool GrenadeThrownPatchDisable;
public static bool NineFourteenMachinePatchDisable;
public static bool PlayerConsoleCommandPatchDisable;

private EventHandlers handlers;
//The below variable is used to incriment the name of the harmony instance, otherwise harmony will not work upon a plugin reload.
Expand Down
Binary file not shown.
Binary file modified EXILED_Main/obj/Debug/EXILED_Main.csprojAssemblyReference.cache
Binary file not shown.

0 comments on commit de19397

Please sign in to comment.