diff --git a/OTAPI.Scripts/Mods/HookCommandProcessing.Server.cs b/OTAPI.Scripts/Mods/HookCommandProcessing.Server.cs index 1f4f61af..cf87d46e 100644 --- a/OTAPI.Scripts/Mods/HookCommandProcessing.Server.cs +++ b/OTAPI.Scripts/Mods/HookCommandProcessing.Server.cs @@ -39,13 +39,18 @@ void HookCommandProcessing(MonoModder modder) var startDedInputCallBack = modder.GetILCursor(() => Terraria.Main.startDedInputCallBack()); var vText = startDedInputCallBack.Body.Variables[0]; +#if TerrariaServer_1450_OrAbove || Terraria__1450_OrAbove || tModLoader_1450_OrAbove +#else var vTextLowered = startDedInputCallBack.Body.Variables[1]; +#endif if (vText.VariableType.FullName != modder.Module.TypeSystem.String.FullName) throw new NotSupportedException("Expected the first variable to be string"); +#if TerrariaServer_1450_OrAbove || Terraria__1450_OrAbove || tModLoader_1450_OrAbove +#else if (vTextLowered.VariableType.FullName != modder.Module.TypeSystem.String.FullName) throw new NotSupportedException("Expected the second variable to be string"); - +#endif var exceptionHandler = startDedInputCallBack.Body.ExceptionHandlers.Single( x => ( x.TryStart.Next.OpCode == OpCodes.Ldstr @@ -62,8 +67,12 @@ void HookCommandProcessing(MonoModder modder) exceptionHandler.TryStart.ReplaceTransfer(newStart, startDedInputCallBack.Method); +#if TerrariaServer_1450_OrAbove || Terraria__1450_OrAbove || tModLoader_1450_OrAbove + startDedInputCallBack.EmitDelegate>(OTAPI.Hooks.Main.InvokeCommandProcess); +#else startDedInputCallBack.Emit(OpCodes.Ldloc, vTextLowered) .EmitDelegate>(OTAPI.Hooks.Main.InvokeCommandProcess); +#endif startDedInputCallBack.Emit(OpCodes.Brfalse, exceptionHandler.TryEnd.Previous); } @@ -92,6 +101,17 @@ public static bool InvokeCommandProcess(string lowered, string raw) CommandProcess?.Invoke(null, args); return args.Result != HookResult.Cancel; } + + public static bool InvokeCommandProcess(string raw) + { + var args = new CommandProcessEventArgs() + { + Lowered = raw.ToLower(), + Command = raw, + }; + CommandProcess?.Invoke(null, args); + return args.Result != HookResult.Cancel; + } } } }