Skip to content

Commit

Permalink
fix: use FullReplaySender to drop packets when skipping
Browse files Browse the repository at this point in the history
not sure why, but packets received from ClientPlayNetworking#registerGlobalReceiver are delayed, so skipping was broken
  • Loading branch information
Apehum committed Oct 13, 2024
1 parent f3e4e93 commit 0f222c2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
3 changes: 1 addition & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Voice audio render to AAC format using OpenAL loopback device.
Rendered audio is saved in the same location and the same name (but with .aac extension) as the video.
- Fixed audio playback issues when skipping on the timeline.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.1.1
version=2.1.2

org.gradle.jvmargs=-Xmx4G
kotlin.stdlib.default.dependency=false
2 changes: 1 addition & 1 deletion versions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
if (platform.mcVersion >= 12100) {
modImplementation("maven.modrinth:replaymod:${platform.mcVersionStr}-2.6.17")
} else if (platform.mcVersion == 11605) {
modImplementation("maven.modrinth:replaymod:1.16.4-2.6.15")
modImplementation("maven.modrinth:replaymod:1.16.4-2.6.19")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package su.plo.replayvoice.mixin;

import com.replaymod.replay.FullReplaySender;
import com.replaymod.replay.ReplaySender;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import su.plo.replayvoice.ReplayVoiceAddon;
import xyz.breadloaf.replaymodinterface.ReplayInterface;

@Mixin(value = FullReplaySender.class, remap = false)
public class MixinFullReplaySender {

@Inject(method = "processPacket", at = @At("HEAD"), cancellable = true)
public void processPacket(Packet p, CallbackInfoReturnable<Packet> cir) {
if (!(p instanceof ClientboundCustomPayloadPacket)) return;

ClientboundCustomPayloadPacket packet = (ClientboundCustomPayloadPacket) p;
//#if MC>=12100
//$$ ResourceLocation packetId = packet.payload().type().id();
//#else
ResourceLocation packetId = packet.getIdentifier();
//#endif

if (!packetId.equals(ReplayVoiceAddon.SELF_AUDIO_PACKET) &&
!packetId.equals(ReplayVoiceAddon.SELF_AUDIO_INFO_PACKET) &&
!packetId.equals(ReplayVoiceAddon.SOURCE_AUDIO_PACKET)
) return;

boolean hurrying = false;
ReplaySender replaySender = ReplayInterface.INSTANCE.replayHandler.getReplaySender();
if (replaySender instanceof FullReplaySender) {
FullReplaySender fullReplaySender = (FullReplaySender) replaySender;
hurrying = fullReplaySender.isHurrying();
}

if (!ReplayInterface.INSTANCE.skipping && !hurrying) return;

cir.setReturnValue(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import su.plo.voice.proto.packets.udp.clientbound.SelfAudioInfoPacket;
import su.plo.voice.proto.packets.udp.clientbound.SourceAudioPacket;
import su.plo.voice.proto.packets.udp.serverbound.PlayerAudioPacket;
import xyz.breadloaf.replaymodinterface.ReplayInterface;

import java.security.KeyFactory;
import java.security.KeyPair;
Expand Down Expand Up @@ -62,8 +61,6 @@ public void handleKeyPairPacket(byte[] data) {
}

public void handleSelfAudioPacket(byte[] data) {
if (ReplayInterface.INSTANCE.skipping) return;

PlayerAudioPacket packet;
try {
packet = getPacket(data, PlayerAudioPacket.class);
Expand All @@ -88,8 +85,6 @@ public void handleSelfAudioPacket(byte[] data) {
}

public void handleSelfAudioInfoPacket(byte[] data) {
if (ReplayInterface.INSTANCE.skipping) return;

SelfAudioInfoPacket packet;
try {
packet = getPacket(data, SelfAudioInfoPacket.class);
Expand Down Expand Up @@ -132,8 +127,6 @@ public void handleSelfAudioInfoPacket(byte[] data) {
}

public void handleSourceAudioPacket(byte[] data) {
if (ReplayInterface.INSTANCE.skipping) return;

SourceAudioPacket packet;
try {
packet = getPacket(data, SourceAudioPacket.class);
Expand Down
3 changes: 2 additions & 1 deletion versions/src/main/resources/replayvoice.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinAlOutputDevice",
"MixinProcessTask"
"MixinProcessTask",
"MixinFullReplaySender"
],
"client": [
],
Expand Down

0 comments on commit 0f222c2

Please sign in to comment.