Skip to content

Commit

Permalink
Fix #41
Browse files Browse the repository at this point in the history
  • Loading branch information
LunNova committed Jun 23, 2017
1 parent 85b39f3 commit 10d2011
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public void injectData(Map<String, Object> data) {
Log.info("TickProfiler v@MOD_VERSION@ coremod injectData called, loading patches");

ModPatcher.loadPatches(CoreMod.class.getResourceAsStream("/entityhook.xml"));
// TODO: Not implemented
// ModPatcher.loadPatches(CoreMod.class.getResourceAsStream("/packethook.xml"));
ModPatcher.loadPatches(CoreMod.class.getResourceAsStream("/packethook.xml"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.val;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.SPacketCustomPayload;
import org.minimallycorrect.modpatcher.api.UsedByPatch;
import org.minimallycorrect.tickprofiler.util.TableFormatter;

Expand Down Expand Up @@ -71,7 +72,14 @@ public static void record(final Packet packet, PacketBuffer buffer) {
if (!running.get()) {
return;
}
String id = packet.getClass().getSimpleName();
String id;

if (packet instanceof SPacketCustomPayload) {
id = ((SPacketCustomPayload) packet).getChannelName();
} else {
id = packet.getClass().getName();
id = id.substring(id.lastIndexOf('.') + 1);
}
int size = buffer.readableBytes();
getAtomicInteger(id, count).getAndIncrement();
getAtomicInteger(id, PacketProfiler.size).addAndGet(size);
Expand Down
14 changes: 6 additions & 8 deletions src/main/resources/packethook.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<patchGroups>
<minecraft>
<!-- TODO: update packet profiling for 1.8.9
<class id="net.minecraft.util.MessageSerializer">
<class id="net.minecraft.network.play.server.SPacketCustomPayload">
<addMethod code="public String ^method:SPacketCustomPayload/getChannel^() { return this.^field:SPacketCustomPayload/channel^; }"/>
</class>
<class id="net.minecraft.network.NettyPacketEncoder">
<replaceMethodCall method="^method:Packet/writePacketData^"
code="$_ = $0.^method:Packet/writePacketData^($PacketProfileriler.record($0, $1);">
encode
code="{$_ = $proceed($$);org.minimallycorrect.tickprofiler.minecraft.profiling.PacketProfiler.record($0, $1);}">
encode(Lio/netty/channel/ChannelHandlerContext;L^class:Packet^;Lio/netty/buffer/ByteBuf;)V
</replaceMethodCall>
<insertCodeBefore coTickProfileriler.handlePacket($1);">
scheduleOutboundPacket
</insertCodeBefore>
</class>
-->
</minecraft>
</patchGroups>

0 comments on commit 10d2011

Please sign in to comment.