-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync "spawn" command for all entities and restrict "sub" and "spawn" …
…to at least moderator perms
- Loading branch information
1 parent
43fc3c8
commit d1cc4a7
Showing
6 changed files
with
83 additions
and
41 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
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
39 changes: 12 additions & 27 deletions
39
NitroxPatcher/Patches/Dynamic/SpawnConsoleCommand_OnConsoleCommand_Patch.cs
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,39 +1,24 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using HarmonyLib; | ||
using NitroxClient.GameLogic; | ||
using NitroxModel.DataStructures.GameLogic; | ||
using NitroxModel.Helper; | ||
using UnityEngine; | ||
|
||
namespace NitroxPatcher.Patches.Dynamic; | ||
|
||
/// <summary> | ||
/// Prevents local player from using "spawn" command without at least the <see cref="Perms.MODERATOR"/> permissions. | ||
/// </summary> | ||
public sealed partial class SpawnConsoleCommand_OnConsoleCommand_Patch : NitroxPatch, IDynamicPatch | ||
{ | ||
internal static readonly MethodInfo TARGET_METHOD = AccessTools.EnumeratorMoveNext(Reflect.Method((SpawnConsoleCommand t) => t.SpawnAsync(default))); | ||
internal static readonly MethodInfo TARGET_METHOD = Reflect.Method((SpawnConsoleCommand t) => t.OnConsoleCommand_spawn(default)); | ||
|
||
/* | ||
* GameObject gameObject = global::Utils.CreatePrefab(prefabForTechType, maxDist, i > 0); | ||
* -> SpawnConsoleCommand_OnConsoleCommand_Patch.Callback(gameObject); | ||
* LargeWorldEntity.Register(gameObject); | ||
* CrafterLogic.NotifyCraftEnd(gameObject, techType); | ||
* gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); | ||
*/ | ||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) | ||
public static bool Prefix(NotificationCenter.Notification n) | ||
{ | ||
return new CodeMatcher(instructions).MatchStartForward([ | ||
new CodeMatch(OpCodes.Call, Reflect.Method(() => Utils.CreatePrefab(default, default, default))) | ||
]) | ||
.Advance(1) | ||
.Insert([ | ||
new CodeInstruction(OpCodes.Dup), | ||
new CodeInstruction(OpCodes.Call, Reflect.Method(() => Callback(default))) | ||
]) | ||
.InstructionEnumeration(); | ||
} | ||
|
||
public static void Callback(GameObject gameObject) | ||
{ | ||
Resolve<NitroxConsole>().Spawn(gameObject); | ||
if (Resolve<LocalPlayer>().Permissions < Perms.MODERATOR) | ||
{ | ||
Log.InGame(Language.main.Get("Nitrox_MissingPermission").Replace("{PERMISSION}", Perms.MODERATOR.ToString())); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
NitroxPatcher/Patches/Dynamic/SpawnConsoleCommand_SpawnAsync_Patch.cs
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using HarmonyLib; | ||
using NitroxClient.GameLogic; | ||
using NitroxModel.Helper; | ||
using UnityEngine; | ||
|
||
namespace NitroxPatcher.Patches.Dynamic; | ||
|
||
/// <summary> | ||
/// Syncs "spawn" command. | ||
/// </summary> | ||
public sealed partial class SpawnConsoleCommand_SpawnAsync_Patch : NitroxPatch, IDynamicPatch | ||
{ | ||
internal static readonly MethodInfo TARGET_METHOD = AccessTools.EnumeratorMoveNext(Reflect.Method((SpawnConsoleCommand t) => t.SpawnAsync(default))); | ||
|
||
/* | ||
* MODIFIED: | ||
* GameObject gameObject = global::Utils.CreatePrefab(prefabForTechType, maxDist, i > 0); | ||
* SpawnConsoleCommand_OnConsoleCommand_Patch.WrappedCallback(gameObject); <---- INSERTED LINE | ||
* LargeWorldEntity.Register(gameObject); | ||
* CrafterLogic.NotifyCraftEnd(gameObject, techType); | ||
* gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); | ||
*/ | ||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
return new CodeMatcher(instructions).MatchStartForward([ | ||
new CodeMatch(OpCodes.Call, Reflect.Method(() => Utils.CreatePrefab(default, default, default))) | ||
]) | ||
.Advance(1) | ||
.Insert([ | ||
new CodeInstruction(OpCodes.Dup), | ||
new CodeInstruction(OpCodes.Call, Reflect.Method(() => Callback(default))) | ||
]) | ||
.InstructionEnumeration(); | ||
} | ||
|
||
public static void Callback(GameObject gameObject) | ||
{ | ||
Resolve<NitroxConsole>().Spawn(gameObject); | ||
} | ||
} |
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