Skip to content

Commit 3bd0c76

Browse files
Merge pull request #158 from ACaiCat/upcoming
Fix HookCommandProcessing not working in v1.4.5
2 parents ec432e2 + bbdc54c commit 3bd0c76

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

OTAPI.Scripts/Mods/HookCommandProcessing.Server.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ void HookCommandProcessing(MonoModder modder)
3939
var startDedInputCallBack = modder.GetILCursor(() => Terraria.Main.startDedInputCallBack());
4040

4141
var vText = startDedInputCallBack.Body.Variables[0];
42+
#if TerrariaServer_1450_OrAbove || Terraria__1450_OrAbove || tModLoader_1450_OrAbove
43+
#else
4244
var vTextLowered = startDedInputCallBack.Body.Variables[1];
45+
#endif
4346

4447
if (vText.VariableType.FullName != modder.Module.TypeSystem.String.FullName)
4548
throw new NotSupportedException("Expected the first variable to be string");
49+
#if TerrariaServer_1450_OrAbove || Terraria__1450_OrAbove || tModLoader_1450_OrAbove
50+
#else
4651
if (vTextLowered.VariableType.FullName != modder.Module.TypeSystem.String.FullName)
4752
throw new NotSupportedException("Expected the second variable to be string");
48-
53+
#endif
4954
var exceptionHandler = startDedInputCallBack.Body.ExceptionHandlers.Single(
5055
x => (
5156
x.TryStart.Next.OpCode == OpCodes.Ldstr
@@ -62,8 +67,12 @@ void HookCommandProcessing(MonoModder modder)
6267

6368
exceptionHandler.TryStart.ReplaceTransfer(newStart, startDedInputCallBack.Method);
6469

70+
#if TerrariaServer_1450_OrAbove || Terraria__1450_OrAbove || tModLoader_1450_OrAbove
71+
startDedInputCallBack.EmitDelegate<Func<string, bool>>(OTAPI.Hooks.Main.InvokeCommandProcess);
72+
#else
6573
startDedInputCallBack.Emit(OpCodes.Ldloc, vTextLowered)
6674
.EmitDelegate<Func<string, string, bool>>(OTAPI.Hooks.Main.InvokeCommandProcess);
75+
#endif
6776
startDedInputCallBack.Emit(OpCodes.Brfalse, exceptionHandler.TryEnd.Previous);
6877
}
6978

@@ -92,6 +101,17 @@ public static bool InvokeCommandProcess(string lowered, string raw)
92101
CommandProcess?.Invoke(null, args);
93102
return args.Result != HookResult.Cancel;
94103
}
104+
105+
public static bool InvokeCommandProcess(string raw)
106+
{
107+
var args = new CommandProcessEventArgs()
108+
{
109+
Lowered = raw.ToLower(),
110+
Command = raw,
111+
};
112+
CommandProcess?.Invoke(null, args);
113+
return args.Result != HookResult.Cancel;
114+
}
95115
}
96116
}
97117
}

0 commit comments

Comments
 (0)