Skip to content

Commit 4bb75da

Browse files
committed
3.3.8 - Hook NetMessage.SendPacket into existing SendBytes hook
1 parent 955c99f commit 4bb75da

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

OTAPI.Patcher/OTAPI.Patcher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net9.0</TargetFramework>
6-
<Version>3.3.7</Version>
6+
<Version>3.3.8</Version>
77
<PreserveCompilationContext>true</PreserveCompilationContext>
88
<RuntimeIdentifiers>win;osx;linux;</RuntimeIdentifiers>
99
<Nullable>enable</Nullable>

OTAPI.Scripts/Mods/HookClientSendBytes.Server.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ void HookClientSendBytes(MonoModder modder)
5959
SendData.Remove();
6060
}
6161
}
62+
63+
#if TerrariaServer_1448_OrAbove
64+
var SendPacket = modder.GetILCursor(() => Terraria.NetMessage.SendPacket(default, default));
65+
// find each AsyncSend, replace with OTAPI.Hooks.NetMessage.InvokeSendBytes, and inject arg2 (remoteClient) as well.
66+
while (SendPacket.TryGotoNext(
67+
i => i.OpCode == OpCodes.Callvirt
68+
&& i.Operand is MethodReference methodReference
69+
&& methodReference.Name == "AsyncSend"
70+
))
71+
{
72+
SendPacket.Emit(OpCodes.Ldarg_1); // remoteClient
73+
SendPacket.EmitDelegate(OTAPI.Hooks.NetMessage.InvokeSendBytes);
74+
SendPacket.Remove();
75+
}
76+
#endif
6277
}
6378

6479
namespace OTAPI

0 commit comments

Comments
 (0)