-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Using transpiler is GigaChad - Remove all Prefix and Postfix - No change for user (if you find a change with this commit it's a bug)
- Loading branch information
Showing
4 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,65 @@ | ||
using CommandSystem; | ||
using CommandSystem.Commands.RemoteAdmin.MutingAndIntercom; | ||
using Exiled.API.Features; | ||
using HarmonyLib; | ||
using NorthwoodLib.Pools; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection.Emit; | ||
|
||
using static HarmonyLib.AccessTools; | ||
|
||
namespace FacilityManagement.Patches | ||
{ | ||
[HarmonyPatch(typeof(IntercomTextCommand), nameof(IntercomTextCommand.Execute))] | ||
public static class IntercomTextCommandFix | ||
{ | ||
public static bool Prefix(ref bool __result, ArraySegment<string> arguments, ICommandSender sender, out string response) | ||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
if (!sender.CheckPermission(PlayerPermissions.Broadcasting, out response)) | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Shared.Rent(instructions); | ||
|
||
// Fix useless check from NW skillissue | ||
const int offset = 2; | ||
int index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ret) + offset; | ||
|
||
newInstructions.RemoveRange(index, 16); | ||
|
||
newInstructions.Insert(index, new(OpCodes.Pop)); | ||
|
||
// Facility Management Fix | ||
|
||
index = newInstructions.FindIndex(instruction => instruction.opcode == OpCodes.Ldloc_0); | ||
|
||
// remove component.CustomContent = null; | ||
newInstructions.RemoveRange(index, 4); | ||
|
||
// Add FacilityManagement.Singleton.CustomText = null; | ||
newInstructions.InsertRange(index, new CodeInstruction[] | ||
{ | ||
__result = false; | ||
return false; | ||
} | ||
new(OpCodes.Ldsfld, Field(typeof(FacilityManagement),nameof(FacilityManagement.Singleton))), | ||
new(OpCodes.Ldnull), | ||
new(OpCodes.Stfld, Field(typeof(FacilityManagement),nameof(FacilityManagement.Singleton.CustomText))), | ||
}); | ||
|
||
|
||
|
||
string text = string.Join(" ", arguments); | ||
if (string.IsNullOrEmpty(text.Trim())) | ||
index = newInstructions.FindLastIndex(instruction => instruction.opcode == OpCodes.Ldloc_0); | ||
|
||
// remove component.CustomContent = text; | ||
newInstructions.RemoveRange(index, 4); | ||
|
||
// Add FacilityManagement.Singleton.CustomText = text; | ||
newInstructions.InsertRange(index, new CodeInstruction[] | ||
{ | ||
ServerLogs.AddLog(ServerLogs.Modules.Administrative, sender.LogName + " cleared the intercom text.", ServerLogs.ServerLogType.RemoteAdminActivity_GameChanging, false); | ||
response = "Reset intercom text."; | ||
FacilityManagement.Singleton.CustomText = null; | ||
__result = true; | ||
return false; | ||
} | ||
ServerLogs.AddLog(ServerLogs.Modules.Administrative, sender.LogName + " set the intercom text to \"" + text + "\".", ServerLogs.ServerLogType.RemoteAdminActivity_GameChanging, false); | ||
response = "Set intercom text to: " + text; | ||
FacilityManagement.Singleton.CustomText = text; | ||
__result = true; | ||
return false; | ||
new(OpCodes.Ldsfld, Field(typeof(FacilityManagement),nameof(FacilityManagement.Singleton))), | ||
new(OpCodes.Ldloc_0), | ||
new(OpCodes.Stfld, Field(typeof(FacilityManagement),nameof(FacilityManagement.Singleton.CustomText))), | ||
}); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Shared.Return(newInstructions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,56 @@ | ||
using HarmonyLib; | ||
using Exiled.Events.EventArgs; | ||
using HarmonyLib; | ||
using LightContainmentZoneDecontamination; | ||
using NorthwoodLib.Pools; | ||
using System.Collections.Generic; | ||
using System.Reflection.Emit; | ||
using static HarmonyLib.AccessTools; | ||
|
||
namespace FacilityManagement.Patches | ||
{ | ||
#pragma warning disable IDE0060 // Supprimer le paramètre inutilisé | ||
|
||
[HarmonyPatch(typeof(Exiled.API.Features.Intercom), nameof(Exiled.API.Features.Intercom.DisplayText), MethodType.Setter)] | ||
public static class CommandIntercomTextSetterFix | ||
{ | ||
public static void Prefix(ref string value) => FacilityManagement.Singleton.CustomText = value; | ||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Shared.Rent(); | ||
|
||
newInstructions.AddRange(new CodeInstruction[] | ||
{ | ||
new(OpCodes.Ldsfld, Field(typeof(FacilityManagement),nameof(FacilityManagement.Singleton))), | ||
new(OpCodes.Ldarg_0), | ||
new(OpCodes.Ldind_Ref), | ||
new(OpCodes.Stfld, Field(typeof(FacilityManagement),nameof(FacilityManagement.Singleton.CustomText))), | ||
new(OpCodes.Ret), | ||
}); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Shared.Return(newInstructions); | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(Exiled.API.Features.Intercom), nameof(Exiled.API.Features.Intercom.DisplayText), MethodType.Getter)] | ||
public static class CommandIntercomTextGetterFix | ||
{ | ||
public static void Prefix(ref string __result) => __result = FacilityManagement.Singleton.CustomText; | ||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
{ | ||
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Shared.Rent(instructions); | ||
|
||
newInstructions.AddRange(new CodeInstruction[] | ||
{ | ||
new(OpCodes.Ldsfld, Field(typeof(FacilityManagement),nameof(FacilityManagement.Singleton))), | ||
new(OpCodes.Ldfld, Field(typeof(FacilityManagement),nameof(FacilityManagement.Singleton.CustomText))), | ||
new(OpCodes.Ret), | ||
}); | ||
|
||
for (int z = 0; z < newInstructions.Count; z++) | ||
yield return newInstructions[z]; | ||
|
||
ListPool<CodeInstruction>.Shared.Return(newInstructions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters