Archive eaglerxrewind (plugin, 1.5.2, 1.8.8, clean)
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
|
||||
plugins {
|
||||
id "java-library"
|
||||
id "com.gradleup.shadow" version "8.3.6"
|
||||
}
|
||||
|
||||
configurations {
|
||||
platformBukkit
|
||||
platformBungee
|
||||
platformVelocity
|
||||
}
|
||||
|
||||
dependencies {
|
||||
platformBukkit project(":rewind_v1_5:rewind_v1_5-platform-bukkit")
|
||||
platformBungee project(":rewind_v1_5:rewind_v1_5-platform-bungee")
|
||||
platformVelocity project(":rewind_v1_5:rewind_v1_5-platform-velocity")
|
||||
compileOnly project(":api")
|
||||
compileOnly(libs.bundles.netty.all)
|
||||
compileOnly(libs.guava)
|
||||
compileOnly(libs.slf4j)
|
||||
}
|
||||
|
||||
tasks.named("shadowJar", com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
|
||||
group "shadow"
|
||||
description "Builds the JAR for all supported platforms"
|
||||
configurations = [
|
||||
project.configurations.runtimeClasspath,
|
||||
project.configurations.platformBukkit,
|
||||
project.configurations.platformBungee,
|
||||
project.configurations.platformVelocity
|
||||
]
|
||||
archiveFileName = "EaglerXRewind.jar"
|
||||
}
|
||||
|
||||
tasks.register("shadowJarBukkit", com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
|
||||
group "shadow"
|
||||
description "Builds the JAR for Bukkit platforms"
|
||||
configurations = [
|
||||
project.configurations.runtimeClasspath,
|
||||
project.configurations.platformBukkit
|
||||
]
|
||||
archiveFileName = "EaglerXRewind-Bukkit.jar"
|
||||
}
|
||||
|
||||
tasks.register("shadowJarBungee", com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
|
||||
group "shadow"
|
||||
description "Builds the JAR for Bungee platforms"
|
||||
configurations = [
|
||||
project.configurations.runtimeClasspath,
|
||||
project.configurations.platformBungee
|
||||
]
|
||||
archiveFileName = "EaglerXRewind-Bungee.jar"
|
||||
}
|
||||
|
||||
tasks.register("shadowJarVelocity", com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
|
||||
group "shadow"
|
||||
description "Builds the JAR for Velocity platforms"
|
||||
configurations = [
|
||||
project.configurations.runtimeClasspath,
|
||||
project.configurations.platformVelocity
|
||||
]
|
||||
archiveFileName = "EaglerXRewind-Velocity.jar"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
plugins {
|
||||
id "java-library"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api project(":rewind_v1_5")
|
||||
compileOnly project(":api-bukkit")
|
||||
compileOnly(libs.paper.api)
|
||||
compileOnly(libs.pluginannotations)
|
||||
annotationProcessor(libs.pluginannotations)
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.bukkit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import eu.hexagonmc.spigot.annotation.meta.DependencyType;
|
||||
import eu.hexagonmc.spigot.annotation.plugin.Dependency;
|
||||
import eu.hexagonmc.spigot.annotation.plugin.Plugin;
|
||||
import eu.hexagonmc.spigot.annotation.plugin.Plugin.Spigot;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindPlatform;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.JavaLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindProtocol;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindVersion;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.EaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IEaglerXRewindProtocol;
|
||||
|
||||
@Plugin(
|
||||
name = PlatformPluginBukkit.PLUGIN_NAME,
|
||||
version = PlatformPluginBukkit.PLUGIN_VERSION,
|
||||
description = PlatformPluginBukkit.PLUGIN_DESC,
|
||||
spigot = @Spigot(
|
||||
authors = {
|
||||
"ayunami2000",
|
||||
"lax1dude"
|
||||
},
|
||||
website = "https://lax1dude.net/eaglerxserver",
|
||||
prefix = "EaglerXRewind-" + RewindVersion.REWIND_VERSION
|
||||
),
|
||||
dependencies = {
|
||||
@Dependency(name = EaglerXServerAPI.PLUGIN_NAME, type = DependencyType.DEPEND)
|
||||
}
|
||||
)
|
||||
public class PlatformPluginBukkit extends JavaPlugin implements IRewindPlatform<Player> {
|
||||
|
||||
public static final String PLUGIN_NAME = "EaglercraftXRewind-" + RewindVersion.REWIND_VERSION_DASHED;
|
||||
public static final String PLUGIN_AUTHOR = RewindVersion.PLUGIN_AUTHOR;
|
||||
public static final String PLUGIN_VERSION = RewindVersion.PLUGIN_VERSION;
|
||||
public static final String PLUGIN_DESC = RewindVersion.PLUGIN_DESC;
|
||||
|
||||
private JavaLogger logger;
|
||||
private IEaglerXRewindProtocol<Player, ?> protocol;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
logger = new JavaLogger(getLogger());
|
||||
protocol = new RewindProtocol<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
EaglerXServerAPI.instance().getEaglerXRewindService().registerLegacyProtocol(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
EaglerXServerAPI.instance().getEaglerXRewindService().unregisterLegacyProtocol(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindLogger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
plugins {
|
||||
id "java-library"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api project(":rewind_v1_5")
|
||||
compileOnly project(":api-bungee")
|
||||
compileOnly(libs.bungeecord.api)
|
||||
compileOnly(libs.pluginannotations)
|
||||
annotationProcessor(libs.pluginannotations)
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.bungee;
|
||||
|
||||
import eu.hexagonmc.spigot.annotation.meta.DependencyType;
|
||||
import eu.hexagonmc.spigot.annotation.plugin.Dependency;
|
||||
import eu.hexagonmc.spigot.annotation.plugin.Plugin.Bungee;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindPlatform;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.JavaLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindProtocol;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindVersion;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bungee.EaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IEaglerXRewindProtocol;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
@eu.hexagonmc.spigot.annotation.plugin.Plugin(
|
||||
name = PlatformPluginBungee.PLUGIN_NAME,
|
||||
version = PlatformPluginBungee.PLUGIN_VERSION,
|
||||
description = PlatformPluginBungee.PLUGIN_DESC,
|
||||
bungee = @Bungee(author = PlatformPluginBungee.PLUGIN_AUTHOR),
|
||||
dependencies = {
|
||||
@Dependency(name = EaglerXServerAPI.PLUGIN_NAME, type = DependencyType.DEPEND)
|
||||
}
|
||||
)
|
||||
public class PlatformPluginBungee extends Plugin implements IRewindPlatform<ProxiedPlayer> {
|
||||
|
||||
public static final String PLUGIN_NAME = "EaglercraftXRewind-" + RewindVersion.REWIND_VERSION_DASHED;
|
||||
public static final String PLUGIN_AUTHOR = RewindVersion.PLUGIN_AUTHOR;
|
||||
public static final String PLUGIN_VERSION = RewindVersion.PLUGIN_VERSION;
|
||||
public static final String PLUGIN_DESC = RewindVersion.PLUGIN_DESC;
|
||||
|
||||
private JavaLogger logger;
|
||||
private IEaglerXRewindProtocol<ProxiedPlayer, ?> protocol;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
logger = new JavaLogger(getLogger());
|
||||
protocol = new RewindProtocol<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
EaglerXServerAPI.instance().getEaglerXRewindService().registerLegacyProtocol(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
EaglerXServerAPI.instance().getEaglerXRewindService().unregisterLegacyProtocol(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindLogger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
plugins {
|
||||
id "java-library"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api project(":rewind_v1_5")
|
||||
compileOnly project(":api-velocity")
|
||||
compileOnly(libs.velocity.api)
|
||||
annotationProcessor(libs.velocity.api)
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.velocity;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.Dependency;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindPlatform;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.SLF4JLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindProtocol;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindVersion;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IEaglerXRewindProtocol;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.EaglerXServerAPI;
|
||||
|
||||
@Plugin(
|
||||
id = PlatformPluginVelocity.PLUGIN_ID,
|
||||
name = PlatformPluginVelocity.PLUGIN_NAME,
|
||||
authors = {
|
||||
"lax1dude",
|
||||
"ayunami2000"
|
||||
},
|
||||
version = PlatformPluginVelocity.PLUGIN_VERSION,
|
||||
description = PlatformPluginVelocity.PLUGIN_DESC,
|
||||
dependencies = {
|
||||
@Dependency(id = EaglerXServerAPI.PLUGIN_ID, optional = false)
|
||||
}
|
||||
)
|
||||
public class PlatformPluginVelocity implements IRewindPlatform<Player> {
|
||||
|
||||
public static final String PLUGIN_ID = "eaglerxrewind-" + RewindVersion.REWIND_VERSION_DASHED;
|
||||
public static final String PLUGIN_NAME = "EaglercraftXRewind-" + RewindVersion.REWIND_VERSION;
|
||||
public static final String PLUGIN_AUTHOR = RewindVersion.PLUGIN_AUTHOR;
|
||||
public static final String PLUGIN_VERSION = RewindVersion.PLUGIN_VERSION;
|
||||
public static final String PLUGIN_DESC = RewindVersion.PLUGIN_DESC;
|
||||
|
||||
private final ProxyServer proxy;
|
||||
private final Logger logger;
|
||||
private final SLF4JLogger rewindLogger;
|
||||
private final IEaglerXRewindProtocol<Player, ?> protocol;
|
||||
|
||||
@Inject
|
||||
public PlatformPluginVelocity(ProxyServer proxyIn, Logger loggerIn, @DataDirectory Path dataDirIn) {
|
||||
proxy = proxyIn;
|
||||
logger = loggerIn;
|
||||
rewindLogger = new SLF4JLogger(loggerIn);
|
||||
protocol = new RewindProtocol<>(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInit(ProxyInitializeEvent e) {
|
||||
EaglerXServerAPI.instance().getEaglerXRewindService().registerLegacyProtocol(protocol);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyShutdown(ProxyShutdownEvent e) {
|
||||
EaglerXServerAPI.instance().getEaglerXRewindService().unregisterLegacyProtocol(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindLogger logger() {
|
||||
return rewindLogger;
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter;
|
||||
|
||||
public interface IRewindLogger {
|
||||
|
||||
void info(String msg);
|
||||
|
||||
void info(String msg, Throwable thrown);
|
||||
|
||||
void warn(String msg);
|
||||
|
||||
void warn(String msg, Throwable thrown);
|
||||
|
||||
void error(String msg);
|
||||
|
||||
void error(String msg, Throwable thrown);
|
||||
|
||||
IRewindSubLogger createSubLogger(String name);
|
||||
|
||||
public interface IRewindSubLogger extends IRewindLogger {
|
||||
|
||||
IRewindLogger getParent();
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter;
|
||||
|
||||
public interface IRewindPlatform<PlayerObject> {
|
||||
|
||||
IRewindLogger logger();
|
||||
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class JavaLogger implements IRewindLogger {
|
||||
|
||||
protected final Logger logger;
|
||||
|
||||
public JavaLogger(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
logger.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Throwable thrown) {
|
||||
logger.log(Level.INFO, msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
logger.warning(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable thrown) {
|
||||
logger.log(Level.WARNING, msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
logger.severe(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable thrown) {
|
||||
logger.log(Level.SEVERE, msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindSubLogger createSubLogger(String name) {
|
||||
return new SubLogger(name, this);
|
||||
}
|
||||
|
||||
public class SubLogger implements IRewindSubLogger {
|
||||
|
||||
private String name;
|
||||
private IRewindLogger parent;
|
||||
|
||||
public SubLogger(String name, IRewindLogger parent) {
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
logger.info("[" + name + "]: " + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Throwable thrown) {
|
||||
logger.log(Level.INFO, "[" + name + "]: " + msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
logger.warning("[" + name + "]: " + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable thrown) {
|
||||
logger.log(Level.WARNING, "[" + name + "]: " + msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
logger.severe("[" + name + "]: " + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable thrown) {
|
||||
logger.log(Level.SEVERE, "[" + name + "]: " + msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindSubLogger createSubLogger(String name) {
|
||||
return new SubLogger(name + "|" + name, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindLogger getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class SLF4JLogger implements IRewindLogger {
|
||||
|
||||
protected final Logger logger;
|
||||
|
||||
public SLF4JLogger(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
logger.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Throwable thrown) {
|
||||
logger.info(msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
logger.warn(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable thrown) {
|
||||
logger.warn(msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
logger.error(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable thrown) {
|
||||
logger.error(msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindSubLogger createSubLogger(String name) {
|
||||
return new SubLogger(name, this);
|
||||
}
|
||||
|
||||
public class SubLogger implements IRewindSubLogger {
|
||||
|
||||
private String name;
|
||||
private IRewindLogger parent;
|
||||
|
||||
public SubLogger(String name, IRewindLogger parent) {
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
logger.info("[{}]: {}", name, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Throwable thrown) {
|
||||
logger.info("[" + name + "]: " + msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
logger.warn("[{}]: {}", name, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable thrown) {
|
||||
logger.warn("[" + name + "]: " + msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
logger.error("[{}]: {}", name, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable thrown) {
|
||||
logger.error("[" + name + "]: " + msg, thrown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindSubLogger createSubLogger(String name) {
|
||||
return new SubLogger(name + "|" + name, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRewindLogger getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream.HackedBufferedInputStream;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream.HackedBufferedOutputStream;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream.HackedDataOutputStream;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream.ReusableGZIPInputStream;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream.ReusableGZIPOutputStream;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IComponentHelper;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerPlayer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.collect.HPPC;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.collect.IntSet;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.collect.ObjectObjectMap;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.INBTContext;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IMessageController;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IOutboundInjector;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalGlobalEAG;
|
||||
|
||||
public class RewindPlayer<PlayerObject> {
|
||||
|
||||
private final RewindProtocol<PlayerObject> rewind;
|
||||
private final IMessageController messageController;
|
||||
private final IOutboundInjector outboundInjector;
|
||||
private final Channel channel;
|
||||
private final IRewindLogger logger;
|
||||
private IEaglerPlayer<PlayerObject> eaglerPlayer;
|
||||
|
||||
private INBTContext nbtContext;
|
||||
private IComponentHelper componentHelper;
|
||||
private TabListTracker tabList;
|
||||
private ObjectObjectMap<UUID, String> voiceGlobalMap;
|
||||
private ObjectObjectMap<String, UUID> voiceGlobalMapInv;
|
||||
private Deflater notDeflater;
|
||||
private Deflater notGZipper;
|
||||
private Inflater ungzipper;
|
||||
private ReusableGZIPInputStream ungzipperStream;
|
||||
private DataInputStream ungzipperStreamOuter;
|
||||
private ReusableGZIPOutputStream gzipperStream;
|
||||
private DataOutputStream gzipperStreamOuter;
|
||||
|
||||
private final IntSet enchWindows;
|
||||
|
||||
private double x = 0;
|
||||
private double y = 0;
|
||||
private double z = 0;
|
||||
private float yaw = 0;
|
||||
private float pitch = 0;
|
||||
private boolean isSneaking = false;
|
||||
|
||||
private byte[] temp1;
|
||||
|
||||
public RewindPlayer(RewindProtocol<PlayerObject> rewind, IMessageController messageController,
|
||||
IOutboundInjector outboundInjector, Channel channel, String logName) {
|
||||
this.rewind = rewind;
|
||||
this.messageController = messageController;
|
||||
this.outboundInjector = outboundInjector;
|
||||
this.channel = channel;
|
||||
this.logger = rewind.logger().createSubLogger(logName);
|
||||
this.enchWindows = rewind.getServerAPI().getHPPC().createIntHashSet();
|
||||
}
|
||||
|
||||
public RewindProtocol<PlayerObject> getRewind() {
|
||||
return rewind;
|
||||
}
|
||||
|
||||
public IRewindLogger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public IEaglerPlayer<PlayerObject> getPlayer() {
|
||||
return eaglerPlayer;
|
||||
}
|
||||
|
||||
public IMessageController getMessageController() {
|
||||
return messageController;
|
||||
}
|
||||
|
||||
public IOutboundInjector getOutboundInjector() {
|
||||
return outboundInjector;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public INBTContext getNBTContext() {
|
||||
if (this.nbtContext == null) {
|
||||
this.nbtContext = rewind.getServerAPI().getNBTHelper().createThreadContext(512);
|
||||
}
|
||||
return this.nbtContext;
|
||||
}
|
||||
|
||||
public IComponentHelper getComponentHelper() {
|
||||
if (this.componentHelper == null) {
|
||||
this.componentHelper = rewind.getServerAPI().getComponentHelper();
|
||||
}
|
||||
return this.componentHelper;
|
||||
}
|
||||
|
||||
public TabListTracker getTabList() {
|
||||
if (this.tabList == null) {
|
||||
this.tabList = new TabListTracker(rewind.getServerAPI().getHPPC());
|
||||
}
|
||||
return this.tabList;
|
||||
}
|
||||
|
||||
public Deflater getNotDeflater() {
|
||||
if (this.notDeflater == null) {
|
||||
// Note: Always use compression level 0, websocket is already compressed!
|
||||
this.notDeflater = new Deflater(0);
|
||||
}
|
||||
return this.notDeflater;
|
||||
}
|
||||
|
||||
public Deflater getNotGZipper() {
|
||||
if (this.notGZipper == null) {
|
||||
this.notGZipper = new Deflater(0, true);
|
||||
}
|
||||
return this.notGZipper;
|
||||
}
|
||||
|
||||
public Inflater getUnGZipper() {
|
||||
if (this.ungzipper == null) {
|
||||
this.ungzipper = new Inflater(true);
|
||||
}
|
||||
return this.ungzipper;
|
||||
}
|
||||
|
||||
public DataInputStream createGZIPInputStream(ByteBuf buf, int limit) throws IOException {
|
||||
if (this.ungzipperStream == null) {
|
||||
this.ungzipperStream = new ReusableGZIPInputStream(getUnGZipper(), getTempBuffer1());
|
||||
this.ungzipperStreamOuter = new DataInputStream(new HackedBufferedInputStream(ungzipperStream, 2048));
|
||||
}
|
||||
this.ungzipperStream.setInput(buf, limit);
|
||||
return this.ungzipperStreamOuter;
|
||||
}
|
||||
|
||||
public DataOutputStream createGZIPOutputStream(ByteBuf buf) {
|
||||
if (this.gzipperStream == null) {
|
||||
this.gzipperStream = new ReusableGZIPOutputStream(getNotGZipper(), getTempBuffer1());
|
||||
this.gzipperStreamOuter = new HackedDataOutputStream(new HackedBufferedOutputStream(gzipperStream, 2048));
|
||||
}
|
||||
this.gzipperStream.setOutput(buf);
|
||||
return this.gzipperStreamOuter;
|
||||
}
|
||||
|
||||
public IntSet getEnchWindows() {
|
||||
return this.enchWindows;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return this.yaw;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
|
||||
public void setPos(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void setLook(float yaw, float pitch) {
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public boolean isSneaking() {
|
||||
return isSneaking;
|
||||
}
|
||||
|
||||
public void setSneaking(boolean sneaking) {
|
||||
this.isSneaking = sneaking;
|
||||
}
|
||||
|
||||
public byte[] getTempBuffer1() {
|
||||
if (this.temp1 == null) {
|
||||
this.temp1 = new byte[1];
|
||||
}
|
||||
return this.temp1;
|
||||
}
|
||||
|
||||
public void releaseVoiceGlobalMap() {
|
||||
voiceGlobalMap = null;
|
||||
voiceGlobalMapInv = null;
|
||||
}
|
||||
|
||||
public void handleVoiceGlobal(Collection<SPacketVoiceSignalGlobalEAG.UserData> userDatas) {
|
||||
IEaglerXServerAPI<?> api = rewind.getServerAPI();
|
||||
HPPC hppc = api.getHPPC();
|
||||
voiceGlobalMap = hppc.createObjectObjectHashMap(userDatas.size());
|
||||
voiceGlobalMapInv = hppc.createObjectObjectHashMap(userDatas.size());
|
||||
for (SPacketVoiceSignalGlobalEAG.UserData userData : userDatas) {
|
||||
UUID uuid = api.intern(new UUID(userData.uuidMost, userData.uuidLeast));
|
||||
String name = userData.username.intern();
|
||||
voiceGlobalMap.put(uuid, name);
|
||||
voiceGlobalMapInv.put(name, uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public String getVoicePlayerByUUID(UUID uuid) {
|
||||
return voiceGlobalMap != null ? voiceGlobalMap.get(uuid) : null;
|
||||
}
|
||||
|
||||
public UUID getVoicePlayerByName(String name) {
|
||||
return voiceGlobalMapInv != null ? voiceGlobalMapInv.get(name) : null;
|
||||
}
|
||||
|
||||
public void handlePlayerCreate(IEaglerPlayer<PlayerObject> eaglerPlayer) {
|
||||
this.eaglerPlayer = eaglerPlayer;
|
||||
}
|
||||
|
||||
public void handlePlayerDestroy() {
|
||||
|
||||
}
|
||||
|
||||
public void releaseNatives() {
|
||||
if (notDeflater != null) {
|
||||
notDeflater.end();
|
||||
}
|
||||
if (notGZipper != null) {
|
||||
notGZipper.end();
|
||||
}
|
||||
if (ungzipper != null) {
|
||||
ungzipper.end();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindPlatform;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec.RewindChannelHandler;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec.RewindHandshakeCodec;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec.RewindMessageHandler;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerConnection;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerPlayer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IEaglerXRewindInitializer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IEaglerXRewindProtocol;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IMessageController;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IOutboundInjector;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IPacket2ClientProtocol;
|
||||
|
||||
public class RewindProtocol<PlayerObject> implements IEaglerXRewindProtocol<PlayerObject, RewindPlayer<PlayerObject>> {
|
||||
|
||||
public static final UUID BRAND_EAGLERXREWIND_1_5_2 = UUID.fromString("65f7ac16-3354-4dfa-bd07-624922fd7962");
|
||||
|
||||
private final IRewindPlatform<PlayerObject> platform;
|
||||
|
||||
private IEaglerXServerAPI<PlayerObject> server;
|
||||
|
||||
public RewindProtocol(IRewindPlatform<PlayerObject> platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public IRewindPlatform<PlayerObject> getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public IEaglerXServerAPI<PlayerObject> getServerAPI() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public IRewindLogger logger() {
|
||||
return platform.logger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRegistered(IEaglerXServerAPI<PlayerObject> server) {
|
||||
// On startup
|
||||
this.server = server;
|
||||
server.getBrandService().registerBrand(BRAND_EAGLERXREWIND_1_5_2, "EaglerXRewind 1.5.2");
|
||||
logger().info("EaglerXRewind protocol for Eaglercraft 1.5.2 has been registered");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUnregistered(IEaglerXServerAPI<PlayerObject> server) {
|
||||
// On shutdown
|
||||
server.getBrandService().unregisterBrand(BRAND_EAGLERXREWIND_1_5_2);
|
||||
logger().info("EaglerXRewind protocol for Eaglercraft 1.5.2 has been unregistered");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConnection(int legacyProtocol,
|
||||
IEaglerXRewindInitializer<RewindPlayer<PlayerObject>> initializer) {
|
||||
IEaglerConnection eaglerConnection = initializer.getConnection();
|
||||
IPacket2ClientProtocol legacyHandshake = initializer.getLegacyHandshake();
|
||||
IMessageController messageController = initializer.requestMessageController();
|
||||
IOutboundInjector outboundInjector = initializer.requestOutboundInjector();
|
||||
|
||||
String realAddr = eaglerConnection.getRealAddress();
|
||||
if (realAddr == null) {
|
||||
realAddr = eaglerConnection.getSocketAddress().toString();
|
||||
}
|
||||
|
||||
RewindPlayer<PlayerObject> attachment = new RewindPlayer<>(this, messageController, outboundInjector,
|
||||
initializer.netty().getChannel(), realAddr + "|" + legacyHandshake.getUsername());
|
||||
initializer.setAttachment(attachment);
|
||||
|
||||
messageController.setOutboundHandler(new RewindMessageHandler(attachment));
|
||||
|
||||
initializer.netty().injectNettyHandlers((new RewindChannelHandler<PlayerObject>(attachment))
|
||||
.setCodec(new RewindHandshakeCodec<>(legacyHandshake)));
|
||||
|
||||
initializer.rewriteInitialHandshakeV2(5, 47, "EaglerXRewind", "1.5.2", false,
|
||||
legacyHandshake.getUsername().getBytes(StandardCharsets.US_ASCII));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCreatePlayer(RewindPlayer<PlayerObject> attachment, IEaglerPlayer<PlayerObject> playerObj) {
|
||||
attachment.handlePlayerCreate(playerObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDestroyPlayer(RewindPlayer<PlayerObject> attachment) {
|
||||
attachment.handlePlayerDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getLegacyProtocols() {
|
||||
return new int[] { 69 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEmulatedEaglerHandshake() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base;
|
||||
|
||||
public class RewindVersion {
|
||||
|
||||
public static final String REWIND_VERSION = "1.5";
|
||||
public static final String REWIND_VERSION_DASHED = "1-5";
|
||||
|
||||
public static final String PLUGIN_BRAND = "EaglercraftXRewind-" + REWIND_VERSION;
|
||||
public static final String PLUGIN_AUTHOR = "ayunami2000";
|
||||
public static final String PLUGIN_VERSION = "1.0.3";
|
||||
public static final String PLUGIN_DESC = "Official Eaglercraft 1.5 compatibility plugin for EaglercraftXServer";
|
||||
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.collect.HPPC;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.collect.ObjectObjectMap;
|
||||
|
||||
public class TabListTracker {
|
||||
|
||||
public static class ListItem {
|
||||
|
||||
public final String playerName;
|
||||
public final UUID playerUUID;
|
||||
public String displayName;
|
||||
public String oldDisplayName;
|
||||
public int pingValue;
|
||||
public int entityId;
|
||||
public boolean dirty;
|
||||
|
||||
public ListItem(String playerName, UUID playerUUID, String displayName, int pingValue) {
|
||||
this.playerName = playerName;
|
||||
this.playerUUID = playerUUID;
|
||||
this.displayName = this.oldDisplayName = displayName;
|
||||
this.pingValue = pingValue;
|
||||
this.dirty = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final ObjectObjectMap<UUID, ListItem> playerUUIDToItem;
|
||||
private final ObjectObjectMap<String, ListItem> playerNameToItem;
|
||||
|
||||
public TabListTracker(HPPC hppc) {
|
||||
this.playerUUIDToItem = hppc.createObjectObjectHashMap(32);
|
||||
this.playerNameToItem = hppc.createObjectObjectHashMap(32);
|
||||
}
|
||||
|
||||
public ListItem getItemByUUID(UUID uuid) {
|
||||
return playerUUIDToItem.get(uuid);
|
||||
}
|
||||
|
||||
public ListItem getItemByName(String name) {
|
||||
return playerNameToItem.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: returns the old item!
|
||||
*/
|
||||
public ListItem handleAddPlayer(String playerName, UUID playerUUID, String displayName, int pingValue,
|
||||
IEaglerXServerAPI<?> interner) {
|
||||
playerName = playerName.intern();
|
||||
playerUUID = interner.intern(playerUUID);
|
||||
ListItem newItem = new ListItem(playerName, playerUUID,
|
||||
playerName.equals(displayName) ? playerName : displayName.intern(), pingValue);
|
||||
ListItem oldItem = playerUUIDToItem.put(playerUUID, newItem);
|
||||
if (oldItem != null) {
|
||||
playerNameToItem.remove(oldItem.playerName);
|
||||
}
|
||||
playerNameToItem.put(playerName, newItem);
|
||||
return oldItem;
|
||||
}
|
||||
|
||||
public ListItem handleSpawnPlayer(UUID playerUUID, int entityId) {
|
||||
ListItem itm = playerUUIDToItem.get(playerUUID);
|
||||
if (itm != null) {
|
||||
itm.entityId = entityId;
|
||||
}
|
||||
return itm;
|
||||
}
|
||||
|
||||
public ListItem handleUpdatePing(UUID playerUUID, int pingValue) {
|
||||
ListItem itm = playerUUIDToItem.get(playerUUID);
|
||||
if (itm != null) {
|
||||
itm.pingValue = pingValue;
|
||||
}
|
||||
return itm;
|
||||
}
|
||||
|
||||
public ListItem handleUpdateDisplayName(UUID playerUUID, String displayName) {
|
||||
ListItem itm = playerUUIDToItem.get(playerUUID);
|
||||
if (itm != null) {
|
||||
if (displayName != null) {
|
||||
displayName = displayName.intern();
|
||||
if (!displayName.equals(itm.displayName)) {
|
||||
itm.displayName = displayName;
|
||||
itm.dirty = true;
|
||||
}
|
||||
} else {
|
||||
displayName = itm.playerName;
|
||||
if (!displayName.equals(itm.displayName)) {
|
||||
itm.displayName = displayName;
|
||||
}
|
||||
}
|
||||
}
|
||||
return itm;
|
||||
}
|
||||
|
||||
public ListItem handleRemovePlayer(UUID pliUuid) {
|
||||
ListItem itm = playerUUIDToItem.remove(pliUuid);
|
||||
if (itm != null) {
|
||||
playerNameToItem.remove(itm.playerName);
|
||||
}
|
||||
return itm;
|
||||
}
|
||||
|
||||
}
|
||||
+853
@@ -0,0 +1,853 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindPlayer;
|
||||
|
||||
public class BufferUtils {
|
||||
|
||||
public static final boolean CHARSEQ_SUPPORT;
|
||||
public static final boolean LITTLE_ENDIAN_SUPPORT;
|
||||
|
||||
static {
|
||||
boolean b = false;
|
||||
try {
|
||||
ByteBuf.class.getMethod("readCharSequence", int.class, Charset.class);
|
||||
b = true;
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
}
|
||||
CHARSEQ_SUPPORT = b;
|
||||
b = false;
|
||||
try {
|
||||
ByteBuf.class.getMethod("readIntLE");
|
||||
b = true;
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
}
|
||||
LITTLE_ENDIAN_SUPPORT = b;
|
||||
}
|
||||
|
||||
public static CharSequence readCharSequence(ByteBuf buffer, int len, Charset charset) {
|
||||
if (CHARSEQ_SUPPORT) {
|
||||
return buffer.readCharSequence(len, charset);
|
||||
} else {
|
||||
byte[] buf = new byte[len];
|
||||
buffer.readBytes(buf);
|
||||
return new String(buf, charset);
|
||||
}
|
||||
}
|
||||
|
||||
public static int writeCharSequence(ByteBuf buffer, CharSequence seq, Charset charset) {
|
||||
if (CHARSEQ_SUPPORT) {
|
||||
return buffer.writeCharSequence(seq, charset);
|
||||
} else {
|
||||
byte[] bytes = seq.toString().getBytes(charset);
|
||||
buffer.writeBytes(bytes);
|
||||
return bytes.length;
|
||||
}
|
||||
}
|
||||
|
||||
public static int readVarInt(ByteBuf buffer) {
|
||||
return readVarInt(buffer, 5);
|
||||
}
|
||||
|
||||
public static int readVarInt(ByteBuf buffer, int maxBytes) {
|
||||
int out = 0;
|
||||
int bytes = 0;
|
||||
byte in;
|
||||
while (true) {
|
||||
in = buffer.readByte();
|
||||
|
||||
out |= (in & 0x7F) << (bytes++ * 7);
|
||||
|
||||
if (bytes > maxBytes) {
|
||||
throw new IndexOutOfBoundsException("VarInt too big (max " + maxBytes + ")");
|
||||
}
|
||||
|
||||
if ((in & 0x80) != 0x80) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public static long readVarLong(ByteBuf buffer, int maxBytes) {
|
||||
long i = 0L;
|
||||
int j = 0;
|
||||
byte b0;
|
||||
while (true) {
|
||||
b0 = buffer.readByte();
|
||||
|
||||
i |= (long) (b0 & 0x7F) << j++ * 7;
|
||||
|
||||
if (j > maxBytes) {
|
||||
throw new IndexOutOfBoundsException("VarLong too big (max " + maxBytes + ")");
|
||||
}
|
||||
|
||||
if ((b0 & 0x80) != 0x80) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public static void writeVarInt(ByteBuf buffer, int input) {
|
||||
while ((input & -128) != 0) {
|
||||
buffer.writeByte(input & 127 | 128);
|
||||
input >>>= 7;
|
||||
}
|
||||
|
||||
buffer.writeByte(input);
|
||||
}
|
||||
|
||||
public static void writeVarLong(ByteBuf buffer, long value) {
|
||||
while ((value & -128L) != 0L) {
|
||||
buffer.writeByte((int) (value & 127L) | 128);
|
||||
value >>>= 7;
|
||||
}
|
||||
|
||||
buffer.writeByte((int) value);
|
||||
}
|
||||
|
||||
public static int varIntLength(int val) {
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
if ((val & -1 << i * 7) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
||||
public static String readLegacyMCString(ByteBuf buffer, int maxLen) {
|
||||
int len = buffer.readUnsignedShort();
|
||||
if (len > maxLen) {
|
||||
throw new IndexOutOfBoundsException("String too long");
|
||||
}
|
||||
char[] chars = new char[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
chars[i] = buffer.readChar();
|
||||
}
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
public static void writeLegacyMCString(ByteBuf buffer, String value, int maxLen) {
|
||||
int len = value.length();
|
||||
if (len > maxLen) {
|
||||
value = value.substring(0, maxLen);
|
||||
len = maxLen;
|
||||
// throw new IndexOutOfBoundsException();
|
||||
}
|
||||
buffer.writeShort(len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
buffer.writeChar(value.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
public static String readMCString(ByteBuf buffer, int maxLen) {
|
||||
int len = readVarInt(buffer);
|
||||
if (len > maxLen * 4) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
CharSequence ret = BufferUtils.readCharSequence(buffer, len, StandardCharsets.UTF_8);
|
||||
if (ret.length() > maxLen) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static void writeMCString(ByteBuf buffer, String value, int maxLen) {
|
||||
if (value.length() > maxLen) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
|
||||
writeVarInt(buffer, bytes.length);
|
||||
buffer.writeBytes(bytes);
|
||||
}
|
||||
|
||||
public static void convertMCString2Legacy(ByteBuf bufferIn, ByteBuf bufferOut, int maxLen) {
|
||||
convertMCString2Legacy(bufferIn, maxLen, bufferOut, maxLen);
|
||||
}
|
||||
|
||||
public static void convertMCString2Legacy(ByteBuf bufferIn, int maxInputLen, ByteBuf bufferOut, int maxLen) {
|
||||
int len = readVarInt(bufferIn, 5);
|
||||
if (maxLen > 32767) {
|
||||
maxLen = 32767;
|
||||
}
|
||||
if (len > maxInputLen * 4) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
int writeLenAt = bufferOut.writerIndex();
|
||||
bufferOut.writeShort(0);
|
||||
int charsRead = 0;
|
||||
int charsWritten = 0;
|
||||
int cnt = 0;
|
||||
while (cnt < len && charsRead <= maxInputLen) {
|
||||
int b = bufferIn.readUnsignedByte();
|
||||
++cnt;
|
||||
if (b < 127) {
|
||||
++charsRead;
|
||||
if (charsWritten < maxLen) {
|
||||
bufferOut.writeChar(b);
|
||||
++charsWritten;
|
||||
}
|
||||
} else {
|
||||
switch ((b >> 4) & 0x7) {
|
||||
case 0b100:
|
||||
case 0b101:
|
||||
if (cnt < len) {
|
||||
int b2 = bufferIn.readUnsignedByte();
|
||||
++cnt;
|
||||
++charsRead;
|
||||
if (charsWritten < maxLen) {
|
||||
bufferOut.writeChar(((b & 0x1F) << 6) | (b2 & 0x3F));
|
||||
++charsWritten;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0b110:
|
||||
if (cnt + 1 < len) {
|
||||
int b2 = bufferIn.readUnsignedByte();
|
||||
int b3 = bufferIn.readUnsignedByte();
|
||||
cnt += 2;
|
||||
++charsRead;
|
||||
if (charsWritten < maxLen) {
|
||||
bufferOut.writeChar(((b & 0x0F) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F));
|
||||
++charsWritten;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0b111:
|
||||
if (cnt + 2 < len) {
|
||||
int b2 = bufferIn.readUnsignedByte();
|
||||
int b3 = bufferIn.readUnsignedByte();
|
||||
int b4 = bufferIn.readUnsignedByte();
|
||||
cnt += 3;
|
||||
++charsRead;
|
||||
int codepoint = (((b & 0x07) << 18) | ((b2 & 0x3F) << 12) | ((b3 & 0x3F) << 6) | (b4 & 0x3F));
|
||||
if (codepoint >= 0xD800 && codepoint <= 0xDFFF) {
|
||||
continue;
|
||||
} else if (codepoint < 0x10000) {
|
||||
if (charsWritten < maxLen) {
|
||||
bufferOut.writeChar(codepoint);
|
||||
++charsWritten;
|
||||
}
|
||||
} else {
|
||||
++charsRead;
|
||||
if (charsWritten + 1 < maxLen) {
|
||||
codepoint -= 0x10000;
|
||||
bufferOut.writeChar(0xD800 | (codepoint >> 10));
|
||||
bufferOut.writeChar(0xDC00 | (codepoint & 0x03FF));
|
||||
charsWritten += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (charsRead > maxInputLen) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
if (charsWritten > 0) {
|
||||
bufferOut.setShort(writeLenAt, charsWritten);
|
||||
}
|
||||
}
|
||||
|
||||
public static void convertLegacyMCString(ByteBuf bufferIn, ByteBuf bufferOut, int maxLen) {
|
||||
int len = bufferIn.readShort();
|
||||
if (len < 0 || len > maxLen) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
int startAt = bufferIn.readerIndex();
|
||||
int utf8Length = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
char c = bufferIn.getChar(startAt + (i << 1));
|
||||
if (c <= 0x7F) {
|
||||
++utf8Length;
|
||||
} else if (c <= 0x07FF) {
|
||||
utf8Length += 2;
|
||||
} else if (c <= 0xD7FF || c > 0xDFFF) {
|
||||
utf8Length += 3;
|
||||
} else {
|
||||
if (i + 1 < len) {
|
||||
char c2 = bufferIn.getChar(startAt + (++i << 1));
|
||||
if (c2 > 0xD7FF && c <= 0xDFFF && ((c & 0xFC00) == 0xD800) && ((c2 & 0xFC00) == 0xDC00)) {
|
||||
utf8Length += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BufferUtils.writeVarInt(bufferOut, utf8Length);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
char c = bufferIn.getChar(startAt + (i << 1));
|
||||
if (c <= 0x7F) {
|
||||
bufferOut.writeByte(c);
|
||||
} else if (c <= 0x07FF) {
|
||||
bufferOut.writeByte(((c >>> 6) & 0x1F) | 0xC0);
|
||||
bufferOut.writeByte((c & 0x3F) | 0x80);
|
||||
} else if (c <= 0xD7FF || c > 0xDFFF) {
|
||||
bufferOut.writeByte(((c >>> 12) & 0x0F) | 0xE0);
|
||||
bufferOut.writeByte(((c >>> 6) & 0x3F) | 0x80);
|
||||
bufferOut.writeByte((c & 0x3F) | 0x80);
|
||||
} else {
|
||||
if (i + 1 < len) {
|
||||
char c2 = bufferIn.getChar(startAt + (++i << 1));
|
||||
if (c2 > 0xD7FF && c <= 0xDFFF && ((c & 0xFC00) == 0xD800) && ((c2 & 0xFC00) == 0xDC00)) {
|
||||
int codepoint = (((c & 0x03FF) << 10) | (c2 & 0x03FF)) + 0x10000;
|
||||
bufferOut.writeByte(((codepoint >>> 18) & 0x07) | 0xF0);
|
||||
bufferOut.writeByte(((codepoint >>> 12) & 0x3F) | 0x80);
|
||||
bufferOut.writeByte(((codepoint >>> 6) & 0x3F) | 0x80);
|
||||
bufferOut.writeByte((codepoint & 0x3F) | 0x80);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bufferIn.readerIndex(startAt + (len << 1));
|
||||
}
|
||||
|
||||
public static void convertSlot2Legacy(ByteBuf buffer, ByteBuf bb, RewindPlayer<?> context) {
|
||||
short blockId = buffer.readShort();
|
||||
blockId = (short) convertItem2Legacy(blockId);
|
||||
bb.writeShort(blockId);
|
||||
if (blockId == -1) {
|
||||
return;
|
||||
}
|
||||
byte itemCount = buffer.readByte();
|
||||
short itemDamage = buffer.readShort();
|
||||
bb.writeByte(itemCount);
|
||||
bb.writeShort(itemDamage);
|
||||
convertNBT2Legacy(buffer, bb, context);
|
||||
}
|
||||
|
||||
public static void convertLegacySlot(ByteBuf buffer, ByteBuf bb, RewindPlayer<?> context) {
|
||||
short blockId = buffer.readShort();
|
||||
bb.writeShort(blockId);
|
||||
if (blockId == -1) {
|
||||
return;
|
||||
}
|
||||
byte itemCount = buffer.readByte();
|
||||
short itemDamage = buffer.readShort();
|
||||
bb.writeByte(itemCount);
|
||||
bb.writeShort(itemDamage);
|
||||
convertLegacyNBT(buffer, bb, context);
|
||||
}
|
||||
|
||||
public static void convertNBT2Legacy(ByteBuf buffer, ByteBuf bb, RewindPlayer<?> context) {
|
||||
if (buffer.readUnsignedByte() == 0) {
|
||||
bb.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
buffer.readerIndex(buffer.readerIndex() - 1);
|
||||
int wi = bb.writerIndex() + 2;
|
||||
bb.ensureWritable(2);
|
||||
bb.writerIndex(wi);
|
||||
|
||||
try (ByteBufInputStream bbis = new ByteBufInputStream(buffer);
|
||||
DataOutputStream dos = context.createGZIPOutputStream(bb)) {
|
||||
|
||||
RewindNBTVisitor.apply(context.getNBTContext(), bbis, dos, context.getComponentHelper());
|
||||
|
||||
dos.close();
|
||||
|
||||
bb.setShort(wi - 2, bb.writerIndex() - wi);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void convertLegacyNBT(ByteBuf buffer, ByteBuf bb, RewindPlayer<?> context) {
|
||||
short len1 = buffer.readShort();
|
||||
if (len1 == -1) {
|
||||
bb.writeByte(0);
|
||||
return;
|
||||
} else if (len1 < 0) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
int oldEnd = buffer.writerIndex();
|
||||
buffer.writerIndex(buffer.readerIndex() + len1);
|
||||
try (DataInputStream gzipIs = context.createGZIPInputStream(buffer, 65535);
|
||||
ByteBufOutputStream dos = new ByteBufOutputStream(bb)) {
|
||||
RewindNBTVisitorReverse.apply(context.getNBTContext(), gzipIs, dos);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
buffer.writerIndex(oldEnd);
|
||||
}
|
||||
|
||||
public static int calcChunkDataSize(final int count, final boolean light, final boolean sendBiomes) {
|
||||
int idlength = count * 2 * 16 * 16 * 16;
|
||||
int blocklightlength = (count * 16 * 16 * 16) / 2;
|
||||
int skylightlength = light ? ((count * 16 * 16 * 16) / 2) : 0;
|
||||
int biomeslength = sendBiomes ? 256 : 0;
|
||||
return idlength + blocklightlength + skylightlength + biomeslength;
|
||||
}
|
||||
|
||||
public static void convertChunk2Legacy(int bitmap, int data18len, ByteBuf data18, ByteBuf bb) {
|
||||
int absInd = data18.readerIndex();
|
||||
int absWInd = bb.writerIndex();
|
||||
int count = Integer.bitCount(bitmap);
|
||||
int guh1 = 8192 * count;
|
||||
int guh = data18len - guh1;
|
||||
int guh2 = count * (4096 + 2048);
|
||||
int count2 = 8192 * count;
|
||||
int count3 = 4096 * count;
|
||||
bb.ensureWritable(guh2 + guh);
|
||||
|
||||
if (LITTLE_ENDIAN_SUPPORT) {
|
||||
for (int i = 0; i < count2; i += 4) {
|
||||
int state = data18.getIntLE(absInd + i);
|
||||
bb.setShortLE(absWInd + (i >> 1),
|
||||
convertType2Legacy((state >>> 4) & 0xFFF) | (convertType2Legacy(state >>> 20) << 8));
|
||||
bb.setByte(absWInd + count3 + (i >> 2), (byte) ((state & 0xF) | (((state >>> 16) & 0xF) << 4)));
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < count2; i += 4) {
|
||||
int stateA = data18.getUnsignedByte(absInd + i) | (data18.getUnsignedByte(absInd + i + 1) << 8);
|
||||
int stateB = data18.getUnsignedByte(absInd + i + 2) | (data18.getUnsignedByte(absInd + i + 3) << 8);
|
||||
bb.setByte(absWInd + (i >> 1), convertType2Legacy(stateA >> 4));
|
||||
bb.setByte(absWInd + (i >> 1) + 1, convertType2Legacy(stateB >> 4));
|
||||
bb.setByte(absWInd + count3 + (i >> 2), (byte) ((stateA & 0xF) | ((stateB & 0xF) << 4)));
|
||||
}
|
||||
}
|
||||
|
||||
if (guh == 256 && data18.readableBytes() - (absInd + guh1) < 256) {
|
||||
bb.setZero(absWInd + guh2, 256);
|
||||
data18.skipBytes(data18len - 256);
|
||||
} else {
|
||||
data18.getBytes(absInd + guh1, bb, absWInd + guh2, guh);
|
||||
data18.skipBytes(data18len);
|
||||
}
|
||||
bb.writerIndex(absWInd + guh2 + guh);
|
||||
}
|
||||
|
||||
public static int sizeEstimateNotDeflated(int srcLen) {
|
||||
return 16 + (srcLen >> 15) * 5 + srcLen;
|
||||
}
|
||||
|
||||
public static int notDeflate(ByteBuf dataIn, ByteBuf dataOut, Deflater notDeflater) {
|
||||
notDeflater.reset();
|
||||
if (dataIn.hasArray()) {
|
||||
byte[] arr = dataIn.array();
|
||||
int arrIndex = dataIn.arrayOffset();
|
||||
notDeflater.setInput(arr, arrIndex + dataIn.readerIndex(), dataIn.readableBytes());
|
||||
} else if (dataIn.nioBufferCount() == 1) {
|
||||
notDeflater.setInput(dataIn.internalNioBuffer(dataIn.readerIndex(), dataIn.readableBytes()));
|
||||
} else {
|
||||
throw new IllegalStateException("Composite buffers not supported! (Input)");
|
||||
}
|
||||
notDeflater.finish();
|
||||
int len;
|
||||
if (dataOut.hasArray()) {
|
||||
byte[] arr = dataOut.array();
|
||||
int arrIndex = dataOut.arrayOffset();
|
||||
len = notDeflater.deflate(arr, arrIndex + dataOut.writerIndex(), dataOut.writableBytes());
|
||||
} else if (dataOut.nioBufferCount() == 1) {
|
||||
len = notDeflater.deflate(dataOut.internalNioBuffer(dataOut.writerIndex(), dataOut.writableBytes()));
|
||||
} else {
|
||||
throw new IllegalStateException("Composite buffers not supported! (Output)");
|
||||
}
|
||||
if ((len == 0 && notDeflater.needsInput()) || !notDeflater.finished()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
dataIn.skipBytes(notDeflater.getTotalIn());
|
||||
dataOut.writerIndex(dataOut.writerIndex() + notDeflater.getTotalOut());
|
||||
return notDeflater.getTotalOut();
|
||||
}
|
||||
|
||||
public static int posX(long position) {
|
||||
return (int) (position >> 38);
|
||||
}
|
||||
|
||||
public static int posY(long position) {
|
||||
return (int) ((position >> 26) & 0xFFF);
|
||||
}
|
||||
|
||||
public static int posZ(long position) {
|
||||
return (int) (position << 38 >> 38);
|
||||
}
|
||||
|
||||
public static long createPosition(int x, int y, int z) {
|
||||
return ((long) (x & 0x3FFFFFF) << 38) | ((long) (y & 0xFFF) << 26) | (z & 0x3FFFFFF);
|
||||
}
|
||||
|
||||
public static String convertMetadata2Legacy(ByteBuf buffer, ByteBuf bb, int entityType, RewindPlayer<?> context) {
|
||||
String playerNameWowie = null;
|
||||
|
||||
if (entityType == -1) {
|
||||
bb.writeByte(0x7F);
|
||||
return null;
|
||||
}
|
||||
while (true) {
|
||||
int item = buffer.readUnsignedByte();
|
||||
if (item == 0x7F) {
|
||||
bb.writeByte(item);
|
||||
break;
|
||||
}
|
||||
int index = item & 0x1F;
|
||||
int type = item >> 5;
|
||||
if (type == 7) {
|
||||
buffer.readFloat();
|
||||
buffer.readFloat();
|
||||
buffer.readFloat();
|
||||
continue;
|
||||
}
|
||||
switch (type) {
|
||||
case 0:
|
||||
remapMeta(entityType, index, type, bb, buffer.readByte());
|
||||
break;
|
||||
case 1:
|
||||
remapMeta(entityType, index, type, bb, buffer.readShort());
|
||||
break;
|
||||
case 2:
|
||||
remapMeta(entityType, index, type, bb, buffer.readInt());
|
||||
break;
|
||||
case 3:
|
||||
remapMeta(entityType, index, type, bb, buffer.readFloat());
|
||||
break;
|
||||
case 4:
|
||||
PlayerNameHolder playerNameHolder = entityType == 300 ? new PlayerNameHolder() : null;
|
||||
remapMeta(entityType, index, type, bb, BufferUtils.readMCString(buffer, 32767), playerNameHolder);
|
||||
if (playerNameHolder != null) {
|
||||
playerNameWowie = playerNameHolder.name;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
ByteBuf tmp = context.getChannel().alloc().buffer();
|
||||
try {
|
||||
BufferUtils.convertSlot2Legacy(buffer, tmp, context);
|
||||
remapMeta(entityType, index, type, bb, tmp);
|
||||
} finally {
|
||||
tmp.release();
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
remapMeta(entityType, index, type, bb,
|
||||
new int[] { buffer.readInt(), buffer.readInt(), buffer.readInt() });
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bb.getByte(bb.writerIndex() - 1) != 0x7F) {
|
||||
bb.writeByte(0x7F);
|
||||
}
|
||||
|
||||
return playerNameWowie;
|
||||
}
|
||||
|
||||
private static final class PlayerNameHolder {
|
||||
public String name;
|
||||
}
|
||||
|
||||
private static void remapMeta(int entityType, int index, int entryType, ByteBuf bb, Object entryValue) {
|
||||
remapMeta(entityType, index, entryType, bb, entryValue, null);
|
||||
}
|
||||
|
||||
private static void remapMeta(int entityType, int index, int entryType, ByteBuf bb, Object entryValue,
|
||||
PlayerNameHolder playerNameHolder) {
|
||||
boolean mobNotObject = entityType >= 100 && entityType <= 300;
|
||||
if (entityType >= 300) {
|
||||
entityType -= 300;
|
||||
} else if (entityType >= 100) {
|
||||
entityType -= 100;
|
||||
}
|
||||
/**
|
||||
* If Object:
|
||||
* 91 = Painting
|
||||
* 92 = Experience orb
|
||||
* 93 = Lightning Bolt
|
||||
* If Mob:
|
||||
* 0 = Player
|
||||
* All else follows wiki.vg
|
||||
*/
|
||||
if (index == 2 && entryType == 4) {
|
||||
index = 5;
|
||||
if (entityType == 0 && playerNameHolder != null) {
|
||||
playerNameHolder.name = (String) entryValue;
|
||||
}
|
||||
} else if (index == 3 && entryType == 0) {
|
||||
index = 6;
|
||||
} else if (index == 7 && entryType == 2) {
|
||||
index = 8;
|
||||
} else if (index == 8 && entryType == 0) {
|
||||
index = 9;
|
||||
} else if (!mobNotObject && entityType != 71 && (index == 9 || index == 15) && entryType == 0) {
|
||||
return;
|
||||
} else if (entityType != 54 && index == 12 && entryType == 0) {
|
||||
entryType = 2;
|
||||
entryValue = (int) (byte) entryValue;
|
||||
} else if (mobNotObject) {
|
||||
if (entityType == 0 && index == 9 && entryType == 0) {
|
||||
index = 10;
|
||||
} else if (entityType == 0
|
||||
&& (((index == 10 || index == 16) && entryType == 0) || (index == 17 && entryType == 3))) {
|
||||
return;
|
||||
} else if (entityType == 0 && index == 18 && entryType == 2) {
|
||||
return;
|
||||
} else if (entityType == 54 && index == 14 && entryType == 0) {
|
||||
return;
|
||||
} else if (entityType == 58 && index == 16 && entryType == 1) {
|
||||
entryType = 0;
|
||||
entryValue = (byte) (short) entryValue;
|
||||
} else if (entityType == 60 || entityType == 94) {
|
||||
return;
|
||||
} else if ((entityType == 63 || entityType == 64) && index == 6 && entryType == 3) {
|
||||
index = 16;
|
||||
entryType = 2;
|
||||
entryValue = (int) (float) entryValue;
|
||||
} else if (entityType == 66 && index == 21 && entryType == 0) {
|
||||
return;
|
||||
} else if (entityType == 95 && (index == 18 || index == 6) && entryType == 3) {
|
||||
index = 18;
|
||||
entryType = 2;
|
||||
entryValue = (int) (float) entryValue;
|
||||
} else if (index == 16 && entryType == 2) {
|
||||
entryType = 0;
|
||||
entryValue = (byte) (int) entryValue;
|
||||
} else if (index == 6 && entryType == 3) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if ((entityType == 1 || entityType == 10 || entityType == 11 || entityType == 12) && index == 19
|
||||
&& entryType == 3) {
|
||||
entryType = 2;
|
||||
entryValue = (int) (float) entryValue;
|
||||
} else if (entityType == 51 && index == 8 && entryType == 2) {
|
||||
return;
|
||||
} else if (entityType == 60 && index == 16 && entryType == 0) {
|
||||
entryValue = (byte) 0;
|
||||
} else if (entityType == 71 && index == 8 && entryType == 5) {
|
||||
index = 2;
|
||||
} else if (entityType == 71 && index == 9 && entryType == 0) {
|
||||
index = 3;
|
||||
entryValue = (byte) (((int) (byte) entryValue) >> 1);
|
||||
} else if (entityType == 77 || entityType == 78 || entityType == 90) {
|
||||
return;
|
||||
} else if (entityType == 10 && index == 20 && entryType == 2) {
|
||||
int id = ((int) entryValue) & 0xFFFF;
|
||||
int data = ((int) entryValue) >> 12;
|
||||
entryValue = (data << 16) | id;
|
||||
}
|
||||
}
|
||||
|
||||
bb.writeByte((entryType << 5) | index);
|
||||
switch (entryType) {
|
||||
case 0:
|
||||
bb.writeByte((byte) entryValue);
|
||||
break;
|
||||
case 1:
|
||||
bb.writeShort((short) entryValue);
|
||||
break;
|
||||
case 2:
|
||||
bb.writeInt((int) entryValue);
|
||||
break;
|
||||
case 3:
|
||||
bb.writeFloat((float) entryValue);
|
||||
break;
|
||||
case 4:
|
||||
BufferUtils.writeLegacyMCString(bb, (String) entryValue, 64);
|
||||
break;
|
||||
case 5:
|
||||
bb.writeBytes((ByteBuf) entryValue);
|
||||
break;
|
||||
case 6:
|
||||
int[] fard = (int[]) entryValue;
|
||||
bb.writeInt(fard[0]);
|
||||
bb.writeInt(fard[1]);
|
||||
bb.writeInt(fard[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static int convertItem2Legacy(int item) {
|
||||
item = convertType2Legacy(item);
|
||||
switch (item) {
|
||||
case 409:
|
||||
return 318;
|
||||
case 410:
|
||||
return 289;
|
||||
case 411:
|
||||
return 365;
|
||||
case 412:
|
||||
case 423:
|
||||
case 424:
|
||||
return 366;
|
||||
case 413:
|
||||
return 282;
|
||||
case 414:
|
||||
return 376;
|
||||
case 415:
|
||||
return 334;
|
||||
case 416:
|
||||
case 420:
|
||||
case 421:
|
||||
return 280;
|
||||
case 425:
|
||||
return 323;
|
||||
case 427:
|
||||
case 428:
|
||||
case 429:
|
||||
case 430:
|
||||
case 431:
|
||||
return 324;
|
||||
case 422:
|
||||
return 328;
|
||||
case 417:
|
||||
case 418:
|
||||
case 419:
|
||||
return 329;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static int convertType2Legacy(int type) {
|
||||
switch (type) {
|
||||
case 165:
|
||||
return 133;
|
||||
case 166:
|
||||
case 95:
|
||||
return 20;
|
||||
case 167:
|
||||
return 96;
|
||||
case 168:
|
||||
return 48;
|
||||
case 169:
|
||||
return 89;
|
||||
case 176:
|
||||
return 63;
|
||||
case 177:
|
||||
return 68;
|
||||
case 179:
|
||||
return 24;
|
||||
case 180:
|
||||
return 128;
|
||||
case 181:
|
||||
return 43;
|
||||
case 182:
|
||||
return 44;
|
||||
case 183:
|
||||
case 184:
|
||||
case 185:
|
||||
case 186:
|
||||
case 187:
|
||||
return 107;
|
||||
case 188:
|
||||
case 189:
|
||||
case 190:
|
||||
case 191:
|
||||
case 192:
|
||||
return 85;
|
||||
case 193:
|
||||
case 194:
|
||||
case 195:
|
||||
case 196:
|
||||
case 197:
|
||||
return 64;
|
||||
case 178:
|
||||
return 151;
|
||||
case 160:
|
||||
return 102;
|
||||
case 161:
|
||||
return 18;
|
||||
case 162:
|
||||
return 17;
|
||||
case 163:
|
||||
case 164:
|
||||
return 53;
|
||||
case 174:
|
||||
return 80;
|
||||
case 175:
|
||||
return 38;
|
||||
case 159:
|
||||
return 82;
|
||||
case 170:
|
||||
return 1;
|
||||
case 171:
|
||||
return 70;
|
||||
case 172:
|
||||
return 82;
|
||||
case 173:
|
||||
return 1;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static byte convertMapColor2Legacy(byte color) {
|
||||
int realColor = (color & 0xFF) >> 2;
|
||||
switch (realColor) {
|
||||
case 14:
|
||||
realColor = 8;
|
||||
break;
|
||||
case 15:
|
||||
case 26:
|
||||
case 34:
|
||||
case 36:
|
||||
realColor = 10;
|
||||
break;
|
||||
case 16:
|
||||
case 17:
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 31:
|
||||
case 32:
|
||||
realColor = 5;
|
||||
break;
|
||||
case 18:
|
||||
case 30:
|
||||
realColor = 2;
|
||||
break;
|
||||
case 19:
|
||||
realColor = 1;
|
||||
break;
|
||||
case 20:
|
||||
case 28:
|
||||
case 35:
|
||||
realColor = 4;
|
||||
break;
|
||||
case 21:
|
||||
case 22:
|
||||
case 29:
|
||||
realColor = 11;
|
||||
break;
|
||||
case 27:
|
||||
case 33:
|
||||
realColor = 7;
|
||||
}
|
||||
return (byte) ((realColor << 2) + (color & 0b11));
|
||||
}
|
||||
|
||||
public static int convertTypeMeta2Legacy(int typeMeta) {
|
||||
int type = typeMeta >> 4;
|
||||
int meta = typeMeta & 15;
|
||||
type = convertType2Legacy(type);
|
||||
return (type << 4) | meta;
|
||||
}
|
||||
|
||||
public static String readASCIIStr(ByteBuf in) {
|
||||
return BufferUtils.readCharSequence(in, in.readUnsignedShort(), StandardCharsets.US_ASCII).toString();
|
||||
}
|
||||
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude, ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageCodec;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.adapter.IRewindLogger;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindPlayer;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindProtocol;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.TabListTracker;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IComponentHelper;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.INBTContext;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IMessageController;
|
||||
|
||||
public class RewindChannelHandler<PlayerObject> extends MessageToMessageCodec<ByteBuf, ByteBuf> {
|
||||
|
||||
protected final RewindPlayer<PlayerObject> player;
|
||||
protected Codec<PlayerObject> encoder;
|
||||
protected Codec<PlayerObject> decoder;
|
||||
|
||||
public static abstract class Codec<PlayerObject> {
|
||||
|
||||
private RewindChannelHandler<PlayerObject> codec;
|
||||
|
||||
protected abstract void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception;
|
||||
|
||||
protected abstract void encode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception;
|
||||
|
||||
protected final RewindChannelHandler<PlayerObject> handler() {
|
||||
return codec;
|
||||
}
|
||||
|
||||
protected final RewindPlayer<PlayerObject> player() {
|
||||
return codec.player;
|
||||
}
|
||||
|
||||
protected final RewindProtocol<PlayerObject> rewind() {
|
||||
return codec.player.getRewind();
|
||||
}
|
||||
|
||||
protected final IRewindLogger logger() {
|
||||
return codec.player.logger();
|
||||
}
|
||||
|
||||
protected final IEaglerXServerAPI<PlayerObject> serverAPI() {
|
||||
return codec.player.getRewind().getServerAPI();
|
||||
}
|
||||
|
||||
protected final INBTContext nbtContext() {
|
||||
return codec.player.getNBTContext();
|
||||
}
|
||||
|
||||
protected final IComponentHelper componentHelper() {
|
||||
return codec.player.getComponentHelper();
|
||||
}
|
||||
|
||||
protected final IMessageController messageController() {
|
||||
return codec.player.getMessageController();
|
||||
}
|
||||
|
||||
protected final TabListTracker tabList() {
|
||||
return codec.player.getTabList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static abstract class Encoder<PlayerObject> extends Codec<PlayerObject> {
|
||||
|
||||
protected final void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static abstract class Decoder<PlayerObject> extends Codec<PlayerObject> {
|
||||
|
||||
protected final void encode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public RewindChannelHandler(RewindPlayer<PlayerObject> player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public RewindChannelHandler<PlayerObject> setEncoder(Codec<PlayerObject> encoder) {
|
||||
encoder.codec = this;
|
||||
this.encoder = encoder;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RewindChannelHandler<PlayerObject> setDecoder(Codec<PlayerObject> decoder) {
|
||||
decoder.codec = this;
|
||||
this.decoder = decoder;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RewindChannelHandler<PlayerObject> setCodec(Codec<PlayerObject> codec) {
|
||||
codec.codec = this;
|
||||
this.encoder = codec;
|
||||
this.decoder = codec;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
||||
decoder.decode(ctx, buf, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
||||
encoder.encode(ctx, buf, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
player.releaseNatives();
|
||||
}
|
||||
|
||||
}
|
||||
+471
@@ -0,0 +1,471 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindProtocol;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.EnumCapabilityType;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IPacket2ClientProtocol;
|
||||
|
||||
public class RewindHandshakeCodec<PlayerObject> extends RewindChannelHandler.Codec<PlayerObject> {
|
||||
|
||||
private static final int CAPABILITIES_MASK = EnumCapabilityType.VOICE.getBit()
|
||||
| EnumCapabilityType.REDIRECT.getBit();
|
||||
private static final int[] CAPABILITIES_VER = new int[] { 1, 1 };
|
||||
|
||||
private static final byte[] REWIND_STR = "rewind".getBytes(StandardCharsets.US_ASCII);
|
||||
private static final byte[] SKIN_V1_STR = "skin_v1".getBytes(StandardCharsets.US_ASCII);
|
||||
private static final byte[] CAPE_V1_STR = "cape_v1".getBytes(StandardCharsets.US_ASCII);
|
||||
private static final byte[] BRAND_UUID_V1_STR = "brand_uuid_v1".getBytes(StandardCharsets.US_ASCII);
|
||||
private static final byte[] ERR = new byte[0];
|
||||
|
||||
protected static final int STATE_STALLING = 0;
|
||||
protected static final int STATE_SENT_HANDSHAKE = 1;
|
||||
protected static final int STATE_SENT_REQUESTED_LOGIN = 2;
|
||||
protected static final int STATE_SENT_RECEIVED_ALLOW_LOGIN = 3;
|
||||
protected static final int STATE_SENT_FINISH_LOGIN = 4;
|
||||
protected static final int STATE_COMPLETED = 5;
|
||||
|
||||
protected int state = STATE_SENT_HANDSHAKE;
|
||||
protected String username;
|
||||
protected byte[] skinData;
|
||||
protected byte[] capeData;
|
||||
protected boolean isV3Kick;
|
||||
|
||||
public RewindHandshakeCodec(IPacket2ClientProtocol firstPacket) {
|
||||
this.username = firstPacket.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
||||
if (state != STATE_COMPLETED) {
|
||||
try {
|
||||
int type = buf.readUnsignedByte();
|
||||
switch (type) {
|
||||
case 0xCD: // Packet205ClientCommand
|
||||
handleClientClientCommand(ctx, buf, out);
|
||||
break;
|
||||
case 0xFA: // Packet250CustomPayload
|
||||
handleClientCustomPayload(ctx, buf);
|
||||
break;
|
||||
default:
|
||||
handleUnexpectedClientPacket(ctx, type);
|
||||
return;
|
||||
}
|
||||
if (buf.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
state = STATE_COMPLETED;
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleClientClientCommand(ChannelHandlerContext ctx, ByteBuf buf, List<Object> output) {
|
||||
if (buf.readUnsignedByte() != 0) {
|
||||
handleUnexpectedClientPacket(ctx, 0xCD);
|
||||
}
|
||||
if (buf.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
if (state == STATE_SENT_RECEIVED_ALLOW_LOGIN) {
|
||||
state = STATE_STALLING;
|
||||
boolean skin = false, cape = false;
|
||||
int total = 1;
|
||||
if (skinData != null && skinData != ERR) {
|
||||
skin = true;
|
||||
++total;
|
||||
}
|
||||
if (capeData != null && capeData != ERR) {
|
||||
cape = true;
|
||||
++total;
|
||||
}
|
||||
ByteBuf packet = ctx.alloc().buffer();
|
||||
try {
|
||||
// PROTOCOL_CLIENT_PROFILE_DATA
|
||||
packet.writeByte(0x07);
|
||||
packet.writeByte(total);
|
||||
if (skin) {
|
||||
packet.writeByte(SKIN_V1_STR.length);
|
||||
packet.writeBytes(SKIN_V1_STR);
|
||||
packet.writeShort(skinData.length);
|
||||
packet.writeBytes(skinData);
|
||||
}
|
||||
if (cape) {
|
||||
packet.writeByte(CAPE_V1_STR.length);
|
||||
packet.writeBytes(CAPE_V1_STR);
|
||||
packet.writeShort(capeData.length);
|
||||
packet.writeBytes(capeData);
|
||||
}
|
||||
packet.writeByte(BRAND_UUID_V1_STR.length);
|
||||
packet.writeBytes(BRAND_UUID_V1_STR);
|
||||
packet.writeShort(16);
|
||||
UUID uuid = RewindProtocol.BRAND_EAGLERXREWIND_1_5_2;
|
||||
packet.writeLong(uuid.getMostSignificantBits());
|
||||
packet.writeLong(uuid.getLeastSignificantBits());
|
||||
output.add(packet.retain());
|
||||
} finally {
|
||||
packet.release();
|
||||
skinData = null;
|
||||
capeData = null;
|
||||
}
|
||||
packet = ctx.alloc().buffer();
|
||||
try {
|
||||
// PROTOCOL_CLIENT_FINISH_LOGIN
|
||||
packet.writeByte(0x08);
|
||||
state = STATE_SENT_FINISH_LOGIN;
|
||||
output.add(packet.retain());
|
||||
} finally {
|
||||
packet.release();
|
||||
}
|
||||
} else {
|
||||
handleUnexpectedClientPacket(ctx, 0xCD);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleClientCustomPayload(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
if (state == STATE_SENT_HANDSHAKE || state == STATE_SENT_REQUESTED_LOGIN
|
||||
|| state == STATE_SENT_RECEIVED_ALLOW_LOGIN) {
|
||||
String channelName = BufferUtils.readLegacyMCString(buf, 20);
|
||||
if ("EAG|MySkin".equals(channelName)) {
|
||||
int len = buf.readShort();
|
||||
if (len > 0 && len < 32767) {
|
||||
ByteBuf buf2 = buf.readSlice(len);
|
||||
if (buf.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
handleEagMySkin(ctx, buf2);
|
||||
}
|
||||
} else if ("EAG|MyCape".equals(channelName)) {
|
||||
int len = buf.readShort();
|
||||
if (len > 0 && len < 32767) {
|
||||
ByteBuf buf2 = buf.readSlice(len);
|
||||
if (buf.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
handleEagMyCape(ctx, buf2);
|
||||
}
|
||||
} else {
|
||||
handleUnexpectedClientPacket(ctx, 0xFA);
|
||||
}
|
||||
} else {
|
||||
handleUnexpectedClientPacket(ctx, 0xFA);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleEagMySkin(ChannelHandlerContext ctx, ByteBuf data) {
|
||||
if (skinData != null) {
|
||||
handleUnexpectedClientPacket(ctx, 0xFA);
|
||||
return;
|
||||
}
|
||||
skinData = SkinPacketUtils.rewriteLegacyHandshakeSkinToV1(data);
|
||||
if (skinData == null) {
|
||||
skinData = ERR;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleEagMyCape(ChannelHandlerContext ctx, ByteBuf data) {
|
||||
if (capeData != null) {
|
||||
handleUnexpectedClientPacket(ctx, 0xFA);
|
||||
return;
|
||||
}
|
||||
capeData = SkinPacketUtils.rewriteLegacyHandshakeCapeToV1(data);
|
||||
if (capeData == null) {
|
||||
capeData = ERR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
||||
if (state != STATE_COMPLETED && buf.readableBytes() >= 1) {
|
||||
try {
|
||||
int type = buf.readUnsignedByte();
|
||||
switch (type) {
|
||||
case 0x02: // PROTOCOL_SERVER_VERISON
|
||||
handleServerVersion(ctx, buf);
|
||||
break;
|
||||
case 0x03: // PROTOCOL_VERISON_MISMATCH
|
||||
handleServerVersionMismatch(ctx, buf);
|
||||
break;
|
||||
case 0x05: // PROTOCOL_SERVER_ALLOW_LOGIN
|
||||
handleServerAllowLogin(ctx, buf, out);
|
||||
break;
|
||||
case 0x06: // PROTOCOL_SERVER_DENY_LOGIN
|
||||
handleServerDenyLogin(ctx, buf);
|
||||
break;
|
||||
case 0x09: // PROTOCOL_SERVER_FINISH_LOGIN
|
||||
handleServerFinishLogin(ctx, buf);
|
||||
break;
|
||||
case 0x0A: // PROTOCOL_SERVER_REDIRECT_TO
|
||||
handleServerRedirectTo(ctx, buf);
|
||||
break;
|
||||
case 0xFF: // PROTOCOL_SERVER_ERROR
|
||||
handleServerError(ctx, buf);
|
||||
break;
|
||||
default:
|
||||
handleUnexpectedServerPacket(ctx, type);
|
||||
break;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
state = STATE_COMPLETED;
|
||||
ctx.close();
|
||||
logger().error("Failed to decode response from backend", ex);
|
||||
}
|
||||
}
|
||||
if (out.isEmpty()) {
|
||||
out.add(Unpooled.EMPTY_BUFFER); // :(
|
||||
}
|
||||
}
|
||||
|
||||
private void kickClient(ChannelHandlerContext ctx) {
|
||||
ByteBuf packet = ctx.alloc().buffer();
|
||||
try {
|
||||
// Packet255KickDisconnect
|
||||
packet.writeByte(0xFF);
|
||||
BufferUtils.writeLegacyMCString(packet, "Internal Error", 256);
|
||||
ctx.writeAndFlush(packet.retain()).addListener(ChannelFutureListener.CLOSE);
|
||||
} finally {
|
||||
packet.release();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleServerVersion(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
if (state == STATE_SENT_HANDSHAKE) {
|
||||
state = STATE_STALLING;
|
||||
int protocolVers = buf.readUnsignedShort();
|
||||
int gameVers = buf.readUnsignedShort();
|
||||
if (protocolVers != 5 || gameVers != 47) {
|
||||
state = STATE_COMPLETED;
|
||||
kickClient(ctx);
|
||||
logger().error(
|
||||
"Backend response does not match the requested protocol: V" + protocolVers + ", mc" + gameVers);
|
||||
return;
|
||||
}
|
||||
isV3Kick = true;
|
||||
ByteBuf packet = ctx.alloc().buffer();
|
||||
try {
|
||||
// PROTOCOL_CLIENT_REQUEST_LOGIN
|
||||
packet.writeByte(0x04);
|
||||
packet.writeByte(username.length());
|
||||
BufferUtils.writeCharSequence(packet, username, StandardCharsets.US_ASCII);
|
||||
packet.writeByte(REWIND_STR.length);
|
||||
packet.writeBytes(REWIND_STR);
|
||||
packet.writeByte(0);
|
||||
packet.writeBoolean(false);
|
||||
packet.writeByte(0);
|
||||
BufferUtils.writeVarInt(packet, CAPABILITIES_MASK);
|
||||
for (int i = 0; i < CAPABILITIES_VER.length; ++i) {
|
||||
BufferUtils.writeVarInt(packet, CAPABILITIES_VER[i]);
|
||||
}
|
||||
packet.writeByte(0);
|
||||
state = STATE_SENT_REQUESTED_LOGIN;
|
||||
ctx.fireChannelRead(packet.retain());
|
||||
} finally {
|
||||
packet.release();
|
||||
}
|
||||
} else {
|
||||
handleUnexpectedServerPacket(ctx, 0x02);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleServerVersionMismatch(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
if (state == STATE_SENT_HANDSHAKE) {
|
||||
state = STATE_COMPLETED;
|
||||
kickClient(ctx);
|
||||
logger().error("Backend responded with PROTOCOL_VERISON_MISMATCH to requested protocol: V5, mc47");
|
||||
} else {
|
||||
handleUnexpectedServerPacket(ctx, 0x03);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleServerAllowLogin(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) {
|
||||
if (state == STATE_SENT_REQUESTED_LOGIN) {
|
||||
state = STATE_STALLING;
|
||||
|
||||
int usernameLen = buf.readUnsignedByte();
|
||||
if (!charSeqEqual(BufferUtils.readCharSequence(buf, usernameLen, StandardCharsets.US_ASCII), username)) {
|
||||
state = STATE_COMPLETED;
|
||||
kickClient(ctx);
|
||||
logger().error("Backend assigned an unexpected username");
|
||||
return;
|
||||
}
|
||||
|
||||
buf.skipBytes(16); // skip uuid
|
||||
|
||||
ByteBuf packet = ctx.alloc().buffer();
|
||||
try {
|
||||
// Packet252SharedKey
|
||||
packet.writeByte(0xFC);
|
||||
packet.writeShort(0);
|
||||
packet.writeShort(0);
|
||||
out.add(packet.retain());
|
||||
state = STATE_SENT_RECEIVED_ALLOW_LOGIN;
|
||||
} finally {
|
||||
packet.release();
|
||||
}
|
||||
} else {
|
||||
handleUnexpectedServerPacket(ctx, 0x05);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean charSeqEqual(CharSequence seq1, String seq2) {
|
||||
int l = seq1.length();
|
||||
if (l != seq2.length()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < l; ++i) {
|
||||
if (seq1.charAt(i) != seq2.charAt(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleServerDenyLogin(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
if (state == STATE_SENT_REQUESTED_LOGIN) {
|
||||
state = STATE_STALLING;
|
||||
int len = buf.readUnsignedShort();
|
||||
String json = BufferUtils.readCharSequence(buf, len, StandardCharsets.UTF_8).toString();
|
||||
if (json.startsWith("{")) {
|
||||
try {
|
||||
json = serverAPI().getComponentHelper().convertJSONToLegacySection(json);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
if (json.length() > 256) {
|
||||
json = json.substring(0, 256);
|
||||
}
|
||||
ByteBuf packet = ctx.alloc().buffer();
|
||||
try {
|
||||
// Packet255KickDisconnect
|
||||
packet.writeByte(0xFF);
|
||||
BufferUtils.writeLegacyMCString(packet, json, 256);
|
||||
state = STATE_COMPLETED;
|
||||
ctx.writeAndFlush(packet.retain()).addListener(ChannelFutureListener.CLOSE);
|
||||
} finally {
|
||||
packet.release();
|
||||
}
|
||||
} else {
|
||||
handleUnexpectedServerPacket(ctx, 0x06);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleServerFinishLogin(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
if (state == STATE_SENT_FINISH_LOGIN) {
|
||||
state = STATE_COMPLETED;
|
||||
enterPlayState();
|
||||
} else {
|
||||
handleUnexpectedServerPacket(ctx, 0x09);
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte[] LEGACY_REDIRECT;
|
||||
|
||||
static {
|
||||
String str = "EAG|Reconnect";
|
||||
int len = str.length();
|
||||
ByteBuf buf = Unpooled.wrappedBuffer(LEGACY_REDIRECT = new byte[15 + len * 2]);
|
||||
buf.writerIndex(0);
|
||||
buf.writeByte(0x01);
|
||||
buf.writeInt(0);
|
||||
buf.writeShort(0);
|
||||
buf.writeByte(0);
|
||||
buf.writeByte(0);
|
||||
buf.writeByte(0xFF);
|
||||
buf.writeByte(0);
|
||||
buf.writeByte(0);
|
||||
buf.writeByte(0xFA);
|
||||
buf.writeShort(len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
buf.writeChar(str.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleServerRedirectTo(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
if (state == STATE_SENT_REQUESTED_LOGIN) {
|
||||
state = STATE_COMPLETED;
|
||||
int len = buf.readUnsignedShort();
|
||||
ByteBuf packet = ctx.alloc().buffer(LEGACY_REDIRECT.length + len + 2);
|
||||
try {
|
||||
packet.writeBytes(LEGACY_REDIRECT);
|
||||
packet.writeBytes(buf, buf.readerIndex() - 2, len + 2);
|
||||
ctx.writeAndFlush(packet.retain()).addListener(ChannelFutureListener.CLOSE);
|
||||
} finally {
|
||||
packet.release();
|
||||
}
|
||||
} else {
|
||||
handleUnexpectedServerPacket(ctx, 0x0A);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleServerError(ChannelHandlerContext ctx, ByteBuf buf) {
|
||||
state = STATE_COMPLETED;
|
||||
int errorCode = buf.readUnsignedByte();
|
||||
int stringLen = isV3Kick ? buf.readUnsignedShort() : buf.readUnsignedByte();
|
||||
String str = BufferUtils.readCharSequence(buf, stringLen, StandardCharsets.UTF_8).toString();
|
||||
if (errorCode == 0x08) {
|
||||
// SERVER_ERROR_CUSTOM_MESSAGE
|
||||
String str2 = str;
|
||||
if (isV3Kick && str2.startsWith("{")) {
|
||||
try {
|
||||
str2 = serverAPI().getComponentHelper().convertJSONToLegacySection(str2);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
ByteBuf packet = ctx.alloc().buffer();
|
||||
try {
|
||||
// Packet255KickDisconnect
|
||||
packet.writeByte(0xFF);
|
||||
BufferUtils.writeLegacyMCString(packet, str2, 256);
|
||||
ctx.writeAndFlush(packet.retain()).addListener(ChannelFutureListener.CLOSE);
|
||||
} finally {
|
||||
packet.release();
|
||||
}
|
||||
} else {
|
||||
kickClient(ctx);
|
||||
}
|
||||
logger().error("Received error code " + errorCode + " from server: \"" + str + "\"");
|
||||
}
|
||||
|
||||
private void handleUnexpectedClientPacket(ChannelHandlerContext ctx, int type) {
|
||||
int oldState = state;
|
||||
state = STATE_COMPLETED;
|
||||
kickClient(ctx);
|
||||
logger().error("Unexpected packet type " + type + " received from client in state " + oldState);
|
||||
}
|
||||
|
||||
private void handleUnexpectedServerPacket(ChannelHandlerContext ctx, int type) {
|
||||
int oldState = state;
|
||||
state = STATE_COMPLETED;
|
||||
kickClient(ctx);
|
||||
logger().error("Unexpected packet type " + type + " received from server in state " + oldState);
|
||||
}
|
||||
|
||||
private void enterPlayState() {
|
||||
handler().setEncoder(new RewindPacketEncoder<>(serverAPI().getHPPC()));
|
||||
handler().setDecoder(new RewindPacketDecoder<>());
|
||||
}
|
||||
|
||||
}
|
||||
+345
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.RewindPlayer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.rewind.IOutboundInjector;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.GameMessageHandler;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.*;
|
||||
|
||||
public class RewindMessageHandler implements GameMessageHandler {
|
||||
|
||||
private final RewindPlayer<?> player;
|
||||
private final IOutboundInjector injector;
|
||||
|
||||
public RewindMessageHandler(RewindPlayer<?> player) {
|
||||
this.player = player;
|
||||
this.injector = player.getOutboundInjector();
|
||||
}
|
||||
|
||||
private ByteBufAllocator alloc() {
|
||||
return player.getChannel().alloc();
|
||||
}
|
||||
|
||||
public void handleServer(SPacketEnableFNAWSkinsEAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
public void handleServer(SPacketUpdateCertEAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
public void handleServer(SPacketVoiceSignalAllowedEAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
// VOICE_SIGNAL_ALLOWED
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|Voice", 255);
|
||||
int lengthAt = buf.writerIndex();
|
||||
buf.writeShort(0);
|
||||
buf.writeByte(0);
|
||||
buf.writeBoolean(packet.allowed);
|
||||
if (!packet.allowed) {
|
||||
player.releaseVoiceGlobalMap();
|
||||
}
|
||||
buf.writeByte(packet.iceServers.length);
|
||||
for (String str : packet.iceServers) {
|
||||
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
|
||||
buf.writeShort(bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
}
|
||||
buf.setShort(lengthAt, buf.writerIndex() - lengthAt - 2);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketVoiceSignalGlobalEAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
player.handleVoiceGlobal(packet.users);
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
// VOICE_SIGNAL_GLOBAL
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|Voice", 255);
|
||||
int lengthAt = buf.writerIndex();
|
||||
buf.writeShort(0);
|
||||
buf.writeByte(5);
|
||||
buf.writeInt(packet.users.size());
|
||||
for (SPacketVoiceSignalGlobalEAG.UserData user : packet.users) {
|
||||
byte[] bytes = user.username.getBytes(StandardCharsets.UTF_8);
|
||||
buf.writeShort(bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
}
|
||||
buf.setShort(lengthAt, buf.writerIndex() - lengthAt - 2);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketVoiceSignalConnectV4EAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
String str = player.getVoicePlayerByUUID(new UUID(packet.uuidMost, packet.uuidLeast));
|
||||
if (str != null) {
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
// VOICE_SIGNAL_CONNECT
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|Voice", 255);
|
||||
int lengthAt = buf.writerIndex();
|
||||
buf.writeShort(0);
|
||||
buf.writeByte(1);
|
||||
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
|
||||
buf.writeShort(bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
buf.writeBoolean(packet.offer);
|
||||
buf.setShort(lengthAt, buf.writerIndex() - lengthAt - 2);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
} else {
|
||||
out.add(Unpooled.EMPTY_BUFFER);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketVoiceSignalConnectAnnounceV4EAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
String str = player.getVoicePlayerByUUID(new UUID(packet.uuidMost, packet.uuidLeast));
|
||||
if (str != null) {
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
// VOICE_SIGNAL_CONNECT
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|Voice", 255);
|
||||
int lengthAt = buf.writerIndex();
|
||||
buf.writeShort(0);
|
||||
buf.writeByte(1);
|
||||
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
|
||||
buf.writeShort(bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
buf.setShort(lengthAt, buf.writerIndex() - lengthAt - 2);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
} else {
|
||||
out.add(Unpooled.EMPTY_BUFFER);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketVoiceSignalDescEAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
String str = player.getVoicePlayerByUUID(new UUID(packet.uuidMost, packet.uuidLeast));
|
||||
if (str != null) {
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
// VOICE_SIGNAL_DESC
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|Voice", 255);
|
||||
int lengthAt = buf.writerIndex();
|
||||
buf.writeShort(0);
|
||||
buf.writeByte(4);
|
||||
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
|
||||
buf.writeShort(bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
int descLen = packet.desc.length;
|
||||
if (descLen > 32750) {
|
||||
throw new IndexOutOfBoundsException("Voice signal packet DESC too long!");
|
||||
}
|
||||
buf.writeShort(descLen);
|
||||
buf.writeBytes(packet.desc);
|
||||
buf.setShort(lengthAt, buf.writerIndex() - lengthAt - 2);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
} else {
|
||||
out.add(Unpooled.EMPTY_BUFFER);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketVoiceSignalICEEAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
String str = player.getVoicePlayerByUUID(new UUID(packet.uuidMost, packet.uuidLeast));
|
||||
if (str != null) {
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
// VOICE_SIGNAL_ICE
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|Voice", 255);
|
||||
int lengthAt = buf.writerIndex();
|
||||
buf.writeShort(0);
|
||||
buf.writeByte(3);
|
||||
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
|
||||
buf.writeShort(bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
int descLen = packet.ice.length;
|
||||
if (descLen > 32750) {
|
||||
throw new IndexOutOfBoundsException("Voice signal packet ICE too long!");
|
||||
}
|
||||
buf.writeShort(descLen);
|
||||
buf.writeBytes(packet.ice);
|
||||
buf.setShort(lengthAt, buf.writerIndex() - lengthAt - 2);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
} else {
|
||||
out.add(Unpooled.EMPTY_BUFFER);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketVoiceSignalDisconnectPeerEAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
String str = player.getVoicePlayerByUUID(new UUID(packet.uuidMost, packet.uuidLeast));
|
||||
if (str != null) {
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
// VOICE_SIGNAL_DISCONNECT
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|Voice", 255);
|
||||
int lengthAt = buf.writerIndex();
|
||||
buf.writeShort(0);
|
||||
buf.writeByte(2);
|
||||
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
|
||||
buf.writeShort(bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
buf.setShort(lengthAt, buf.writerIndex() - lengthAt - 2);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
} else {
|
||||
out.add(Unpooled.EMPTY_BUFFER);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketForceClientSkinPresetV4EAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
public void handleServer(SPacketForceClientSkinCustomV4EAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
public void handleServer(SPacketForceClientCapePresetV4EAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
public void handleServer(SPacketForceClientCapeCustomV4EAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
public void handleServer(SPacketRedirectClientV4EAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|Reconnect", 255);
|
||||
byte[] bytes = packet.redirectURI.getBytes(StandardCharsets.UTF_8);
|
||||
buf.writeShort(bytes.length);
|
||||
buf.writeBytes(bytes);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketInvalidatePlayerCacheV4EAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
public void handleServer(SPacketUnforceClientV4EAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
public void handleServer(SPacketOtherTexturesV5EAG packet) {
|
||||
injector.injectOutbound((out) -> {
|
||||
ByteBuf buf = alloc().buffer();
|
||||
try {
|
||||
buf.writeByte(0xFA);
|
||||
BufferUtils.writeLegacyMCString(buf, "EAG|UserSkin", 255);
|
||||
int lengthAt = buf.writerIndex();
|
||||
buf.writeShort(0);
|
||||
buf.writeShort(packet.requestId);
|
||||
if (packet.skinID >= 0) {
|
||||
buf.writeByte(4); // preset skin
|
||||
if (packet.skinID < 256) {
|
||||
buf.writeByte(SkinPacketUtils.rewritePresetSkinIdToLegacy(packet.skinID));
|
||||
} else {
|
||||
buf.writeByte(0);
|
||||
}
|
||||
} else {
|
||||
int modelId = -packet.skinID - 1;
|
||||
if ((modelId & 0x80) != 0) {
|
||||
modelId = (modelId & 0x7F) == 1 ? 1 : 0;
|
||||
}
|
||||
if (modelId == 0) {
|
||||
buf.writeByte(1);
|
||||
SkinPacketUtils.rewriteCustomSkinToLegacy(packet.customSkin, buf);
|
||||
} else if (modelId == 1) {
|
||||
buf.writeByte(5);
|
||||
SkinPacketUtils.rewriteCustomSkinToLegacy(packet.customSkin, buf);
|
||||
} else {
|
||||
buf.writeByte(4);
|
||||
buf.writeByte(0); // steve
|
||||
}
|
||||
}
|
||||
if (packet.capeID >= 0) {
|
||||
buf.writeByte(2); // preset cape
|
||||
buf.writeByte(0xFF); // skin layer bits, TODO: map to 1.8 entity metadata value?
|
||||
if (packet.capeID < 256) {
|
||||
buf.writeByte(packet.capeID);
|
||||
} else {
|
||||
buf.writeByte(0);
|
||||
}
|
||||
} else {
|
||||
buf.writeByte(0);
|
||||
buf.writeByte(0xFF); // skin layer bits, TODO: map to 1.8 entity metadata value?
|
||||
SkinPacketUtils.rewriteCustomCapeToLegacy(packet.customCape, buf);
|
||||
}
|
||||
buf.setShort(lengthAt, buf.writerIndex() - lengthAt - 2);
|
||||
out.add(buf.retain());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleServer(SPacketClientStateFlagV5EAG packet) {
|
||||
// nope
|
||||
}
|
||||
|
||||
}
|
||||
+255
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (c) 2025 ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IComponentHelper;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.EnumDataType;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.INBTContext;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.INBTValue;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.INBTVisitor;
|
||||
|
||||
public class RewindNBTVisitor implements INBTVisitor {
|
||||
|
||||
public static void apply(INBTContext context, DataInput input, DataOutput output, IComponentHelper componentHelper)
|
||||
throws IOException {
|
||||
context.accept(input, new RewindNBTVisitor(context, context.createWriter(output), componentHelper));
|
||||
}
|
||||
|
||||
private final INBTContext context;
|
||||
private final INBTVisitor parent;
|
||||
private final IComponentHelper componentHelper;
|
||||
|
||||
private RewindNBTVisitor(INBTContext context, INBTVisitor parent, IComponentHelper componentHelper) {
|
||||
this.context = context;
|
||||
this.parent = parent;
|
||||
this.componentHelper = componentHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor parent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitRootTag(EnumDataType tagType) throws IOException {
|
||||
parent().visitRootTag(tagType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTagList(EnumDataType itemType, int length) throws IOException {
|
||||
parent().visitTagList(itemType, length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTag(EnumDataType tagType, INBTValue<String> tagName) throws IOException {
|
||||
if (tagType == EnumDataType.COMPOUND) {
|
||||
String name = tagName.value();
|
||||
switch (name) {
|
||||
case "tag":
|
||||
parent().visitTag(tagType, tagName);
|
||||
return this;
|
||||
case "SpawnData":
|
||||
return INBTVisitor.NOP;
|
||||
case "SkullOwner":
|
||||
return new SkullOwnerTransformer(false);
|
||||
case "Owner":
|
||||
return new SkullOwnerTransformer(true);
|
||||
}
|
||||
} else if (tagType == EnumDataType.LIST) {
|
||||
String name = tagName.value();
|
||||
switch (name) {
|
||||
case "SpawnPotentials":
|
||||
return INBTVisitor.NOP;
|
||||
case "pages":
|
||||
parent().visitTag(tagType, tagName);
|
||||
return new PagesTransformer();
|
||||
case "ench":
|
||||
parent().visitTag(tagType, tagName);
|
||||
return new EnchantmentTransformer();
|
||||
}
|
||||
}
|
||||
parent().visitTag(tagType, tagName);
|
||||
return this;
|
||||
}
|
||||
|
||||
private class PagesTransformer implements INBTVisitor {
|
||||
@Override
|
||||
public INBTVisitor parent() {
|
||||
return RewindNBTVisitor.this;
|
||||
}
|
||||
|
||||
private int w = Integer.MAX_VALUE;
|
||||
private int len = Integer.MAX_VALUE;
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitRootTag(EnumDataType tagType) throws IOException {
|
||||
if (w >= len) {
|
||||
return parent().visitRootTag(tagType);
|
||||
}
|
||||
parent().visitRootTag(tagType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTagList(EnumDataType itemType, int length) throws IOException {
|
||||
if (length != 0 && w == Integer.MAX_VALUE && len == Integer.MAX_VALUE) {
|
||||
len = length;
|
||||
parent().visitTagList(itemType, length);
|
||||
return this;
|
||||
} else {
|
||||
return parent().visitTagList(itemType, length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTag(EnumDataType tagType, INBTValue<String> tagName) throws IOException {
|
||||
if (w >= len) {
|
||||
return parent().visitTag(tagType, tagName);
|
||||
}
|
||||
if (tagType == EnumDataType.STRING) {
|
||||
w++;
|
||||
}
|
||||
parent().visitTag(tagType, tagName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTagString(INBTValue<String> str) throws IOException {
|
||||
String transformedText = str.value();
|
||||
try {
|
||||
transformedText = componentHelper.convertJSONToLegacySection(transformedText);
|
||||
} catch (IllegalArgumentException e) {
|
||||
//
|
||||
}
|
||||
parent().visitTagString(context.wrapValue(transformedText));
|
||||
}
|
||||
}
|
||||
|
||||
private class EnchantmentTransformer implements INBTVisitor {
|
||||
@Override
|
||||
public INBTVisitor parent() {
|
||||
return RewindNBTVisitor.this;
|
||||
}
|
||||
|
||||
private int w = Integer.MAX_VALUE;
|
||||
private int len = Integer.MAX_VALUE;
|
||||
private boolean isId = false;
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitRootTag(EnumDataType tagType) throws IOException {
|
||||
if (w >= len) {
|
||||
return parent().visitRootTag(tagType);
|
||||
}
|
||||
parent().visitRootTag(tagType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTagList(EnumDataType itemType, int length) throws IOException {
|
||||
if (length != 0 && w == Integer.MAX_VALUE && len == Integer.MAX_VALUE) {
|
||||
len = length;
|
||||
parent().visitTagList(itemType, length);
|
||||
return this;
|
||||
} else {
|
||||
return parent().visitTagList(itemType, length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTag(EnumDataType tagType, INBTValue<String> tagName) throws IOException {
|
||||
if (w >= len) {
|
||||
return parent().visitTag(tagType, tagName);
|
||||
}
|
||||
if (tagType == EnumDataType.COMPOUND) {
|
||||
w++;
|
||||
} else if (tagType == EnumDataType.SHORT || tagType == EnumDataType.INT) {
|
||||
isId = "id".equals(tagName.value());
|
||||
}
|
||||
parent().visitTag(tagType, tagName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTagInt(int value) throws IOException {
|
||||
if (isId) {
|
||||
int guh = value & 0xFFFF;
|
||||
if (guh == 8 || guh == 62 || guh == 61) {
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
parent().visitTagInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTagShort(short value) throws IOException {
|
||||
if (isId) {
|
||||
int guh = value & 0xFFFF;
|
||||
if (guh == 8 || guh == 62 || guh == 61) {
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
parent().visitTagShort(value);
|
||||
}
|
||||
}
|
||||
|
||||
private class SkullOwnerTransformer implements INBTVisitor {
|
||||
|
||||
private final boolean notSkull;
|
||||
|
||||
public SkullOwnerTransformer(boolean which) {
|
||||
notSkull = which;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor parent() {
|
||||
return RewindNBTVisitor.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitRootTag(EnumDataType tagType) throws IOException {
|
||||
parent().visitRootTag(tagType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTagList(EnumDataType itemType, int length) throws IOException {
|
||||
parent().visitTagList(itemType, length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTag(EnumDataType tagType, INBTValue<String> tagName) throws IOException {
|
||||
if (tagType == EnumDataType.STRING && "Name".equals(tagName.value())) {
|
||||
return this;
|
||||
}
|
||||
return parent().visitTag(tagType, tagName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTagString(INBTValue<String> str) throws IOException {
|
||||
parent().visitTag(EnumDataType.STRING, context.wrapValue(notSkull ? "ExtraType" : "SkullOwner"))
|
||||
.visitTagString(str);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2025 ayunami2000. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.EnumDataType;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.INBTContext;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.INBTValue;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.nbt.INBTVisitor;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class RewindNBTVisitorReverse implements INBTVisitor {
|
||||
|
||||
public static void apply(INBTContext context, DataInput input, DataOutput output) throws IOException {
|
||||
context.accept(input, new RewindNBTVisitorReverse(context, context.createWriter(output)));
|
||||
}
|
||||
|
||||
private final INBTContext context;
|
||||
private final INBTVisitor parent;
|
||||
|
||||
private RewindNBTVisitorReverse(INBTContext context, INBTVisitor parent) {
|
||||
this.context = context;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor parent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitRootTag(EnumDataType tagType) throws IOException {
|
||||
parent().visitRootTag(tagType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTagList(EnumDataType itemType, int length) throws IOException {
|
||||
parent().visitTagList(itemType, length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTag(EnumDataType tagType, INBTValue<String> tagName) throws IOException {
|
||||
if (tagType == EnumDataType.COMPOUND && "ExtraType".equals(tagName.value())) {
|
||||
tagName.mutate("Owner");
|
||||
} else if (tagType == EnumDataType.LIST && "pages".equals(tagName.value())) {
|
||||
parent().visitTag(tagType, tagName);
|
||||
return new PagesTransformer();
|
||||
}
|
||||
parent().visitTag(tagType, tagName);
|
||||
return this;
|
||||
}
|
||||
|
||||
private class PagesTransformer implements INBTVisitor {
|
||||
@Override
|
||||
public INBTVisitor parent() {
|
||||
return RewindNBTVisitorReverse.this;
|
||||
}
|
||||
|
||||
private int w = Integer.MAX_VALUE;
|
||||
private int len = Integer.MAX_VALUE;
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitRootTag(EnumDataType tagType) throws IOException {
|
||||
if (w >= len) {
|
||||
return parent().visitRootTag(tagType);
|
||||
}
|
||||
parent().visitRootTag(tagType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTagList(EnumDataType itemType, int length) throws IOException {
|
||||
if (length != 0 && w == Integer.MAX_VALUE && len == Integer.MAX_VALUE) {
|
||||
len = length;
|
||||
w = 0;
|
||||
parent().visitTagList(itemType, length);
|
||||
return this;
|
||||
} else {
|
||||
return parent().visitTagList(itemType, length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTVisitor visitTag(EnumDataType tagType, INBTValue<String> tagName) throws IOException {
|
||||
if (w >= len) {
|
||||
return parent().visitTag(tagType, tagName);
|
||||
}
|
||||
if (tagType == EnumDataType.STRING) {
|
||||
w++;
|
||||
}
|
||||
parent().visitTag(tagType, tagName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTagString(INBTValue<String> str) throws IOException {
|
||||
if (w < len) {
|
||||
String transformedText = "\"" + str.value().replaceAll("\\\\", "\\\\").replaceAll("\"", "\\\\\"")
|
||||
+ "\"";
|
||||
str.mutate(transformedText);
|
||||
}
|
||||
parent().visitTagString(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
+490
@@ -0,0 +1,490 @@
|
||||
/*
|
||||
* Copyright (c) 2025 ayunami2000, lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.TabListTracker;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.CPacketGetOtherTexturesV5EAG;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.CPacketVoiceSignalConnectEAG;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.CPacketVoiceSignalDescEAG;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.CPacketVoiceSignalDisconnectPeerV4EAG;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.CPacketVoiceSignalDisconnectV4EAG;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.CPacketVoiceSignalICEEAG;
|
||||
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.CPacketVoiceSignalRequestEAG;
|
||||
|
||||
public class RewindPacketDecoder<PlayerObject> extends RewindChannelHandler.Decoder<PlayerObject> {
|
||||
|
||||
// TODO: rewrite to use individual named methods for each packet
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
|
||||
int pktId = in.readUnsignedByte();
|
||||
ByteBuf bb = null;
|
||||
try {
|
||||
fuck: switch (pktId) {
|
||||
case 0x00:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x00);
|
||||
BufferUtils.writeVarInt(bb, in.readInt());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x03:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x01);
|
||||
BufferUtils.convertLegacyMCString(in, bb, 100);
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x07:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x02);
|
||||
in.readInt();
|
||||
BufferUtils.writeVarInt(bb, in.readInt());
|
||||
BufferUtils.writeVarInt(bb, in.readBoolean() ? 1 : 0);
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x0A:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x03);
|
||||
bb.writeBoolean(in.readBoolean());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x0B:
|
||||
double ppx = in.readDouble();
|
||||
double ppy = in.readDouble();
|
||||
double ppyf = in.readDouble();
|
||||
double ppz = in.readDouble();
|
||||
boolean ong = in.readBoolean();
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
if (ppy == -999.0D && ppyf == -999.0D) {
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x0C);
|
||||
double tmp0 = Math.toRadians(player().getYaw());
|
||||
double tmpc = Math.cos(tmp0);
|
||||
double tmps = Math.sin(tmp0);
|
||||
double tmpx = ppx * tmpc + ppz * tmps;
|
||||
double tmpz = -ppx * tmps + ppz * tmpc;
|
||||
float tmpfx = (float) tmpx * 32.0F;
|
||||
float tmpfz = (float) tmpz * 32.0F;
|
||||
if (tmpfx > 1.0F) {
|
||||
tmpfx = 1.0F;
|
||||
} else if (tmpfx < -1.0F) {
|
||||
tmpfx = -1.0F;
|
||||
}
|
||||
if (tmpfz > 1.0F) {
|
||||
tmpfz = 1.0F;
|
||||
} else if (tmpfz < -1.0F) {
|
||||
tmpfz = -1.0F;
|
||||
}
|
||||
bb.writeFloat(tmpfx);
|
||||
bb.writeFloat(tmpfz);
|
||||
bb.writeByte(player().isSneaking() ? 0x02 : 0x00);
|
||||
break;
|
||||
}
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x04);
|
||||
player().setPos(ppx, ppy, ppz);
|
||||
bb.writeDouble(ppx);
|
||||
bb.writeDouble(ppy);
|
||||
bb.writeDouble(ppz);
|
||||
bb.writeBoolean(ong);
|
||||
break;
|
||||
case 0x0C:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x05);
|
||||
float plyaw = in.readFloat();
|
||||
float plpitch = in.readFloat();
|
||||
ong = in.readBoolean();
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
player().setLook(plyaw, plpitch);
|
||||
bb.writeFloat(plyaw);
|
||||
bb.writeFloat(plpitch);
|
||||
bb.writeBoolean(ong);
|
||||
break;
|
||||
case 0x0D:
|
||||
ppx = in.readDouble();
|
||||
ppy = in.readDouble();
|
||||
ppyf = in.readDouble();
|
||||
ppz = in.readDouble();
|
||||
plyaw = in.readFloat();
|
||||
plpitch = in.readFloat();
|
||||
ong = in.readBoolean();
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
if (ppy == -999.0D && ppyf == -999.0D) {
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x05);
|
||||
player().setLook(plyaw, plpitch);
|
||||
bb.writeFloat(plyaw);
|
||||
bb.writeFloat(plpitch);
|
||||
bb.writeBoolean(ong);
|
||||
out.add(bb);
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x0C);
|
||||
double tmp0 = Math.toRadians(plyaw);
|
||||
double tmpc = Math.cos(tmp0);
|
||||
double tmps = Math.sin(tmp0);
|
||||
double tmpx = ppx * tmpc + ppz * tmps;
|
||||
double tmpz = -ppx * tmps + ppz * tmpc;
|
||||
float tmpfx = (float) tmpx * 32.0F;
|
||||
float tmpfz = (float) tmpz * 32.0F;
|
||||
if (tmpfx > 1.0F) {
|
||||
tmpfx = 1.0F;
|
||||
} else if (tmpfx < -1.0F) {
|
||||
tmpfx = -1.0F;
|
||||
}
|
||||
if (tmpfz > 1.0F) {
|
||||
tmpfz = 1.0F;
|
||||
} else if (tmpfz < -1.0F) {
|
||||
tmpfz = -1.0F;
|
||||
}
|
||||
bb.writeFloat(tmpfx);
|
||||
bb.writeFloat(tmpfz);
|
||||
bb.writeByte(player().isSneaking() ? 0x02 : 0x00);
|
||||
break;
|
||||
}
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x06);
|
||||
player().setPos(ppx, ppy, ppz);
|
||||
player().setLook(plyaw, plpitch);
|
||||
bb.writeDouble(ppx);
|
||||
bb.writeDouble(ppy);
|
||||
bb.writeDouble(ppz);
|
||||
bb.writeFloat(plyaw);
|
||||
bb.writeFloat(plpitch);
|
||||
bb.writeBoolean(ong);
|
||||
break;
|
||||
case 0x0E:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x07);
|
||||
bb.writeByte(in.readByte());
|
||||
bb.writeLong(BufferUtils.createPosition(in.readInt(), in.readUnsignedByte(), in.readInt()));
|
||||
bb.writeByte(in.readByte());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x0F:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x08);
|
||||
bb.writeLong(BufferUtils.createPosition(in.readInt(), in.readUnsignedByte(), in.readInt()));
|
||||
bb.writeByte(in.readUnsignedByte());
|
||||
BufferUtils.convertLegacySlot(in, bb, player());
|
||||
bb.writeByte(in.readByte());
|
||||
bb.writeByte(in.readByte());
|
||||
bb.writeByte(in.readByte());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x10:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x09);
|
||||
bb.writeShort(in.readShort());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x12:
|
||||
if (in.readableBytes() > 5)
|
||||
throw new IndexOutOfBoundsException();
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x0A);
|
||||
break;
|
||||
case 0x13:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x0B);
|
||||
BufferUtils.writeVarInt(bb, in.readInt());
|
||||
int action = in.readUnsignedByte() - 1;
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
BufferUtils.writeVarInt(bb, action);
|
||||
BufferUtils.writeVarInt(bb, 0);
|
||||
if (action == 0) {
|
||||
player().setSneaking(true);
|
||||
} else if (action == 1) {
|
||||
player().setSneaking(false);
|
||||
}
|
||||
break;
|
||||
case 0x65:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x0D);
|
||||
bb.writeByte(in.readByte());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x66:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x0E);
|
||||
byte windowId = in.readByte();
|
||||
short slot = in.readShort();
|
||||
if (player().getEnchWindows().contains((short) windowId) && slot > 0) {
|
||||
++slot;
|
||||
}
|
||||
bb.writeByte(windowId);
|
||||
bb.writeShort(slot);
|
||||
bb.writeByte(in.readByte());
|
||||
bb.writeShort(in.readShort());
|
||||
bb.writeByte(in.readByte());
|
||||
BufferUtils.convertLegacySlot(in, bb, player());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x6A:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x0F);
|
||||
bb.writeByte(in.readByte());
|
||||
bb.writeShort(in.readShort());
|
||||
bb.writeBoolean(in.readBoolean());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x6B:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x10);
|
||||
bb.writeShort(in.readShort());
|
||||
BufferUtils.convertLegacySlot(in, bb, player());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x6C:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x11);
|
||||
bb.writeByte(in.readByte());
|
||||
bb.writeByte(in.readByte());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0x82:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x12);
|
||||
bb.writeLong(BufferUtils.createPosition(in.readInt(), in.readShort(), in.readInt()));
|
||||
for (int ii = 0; ii < 4; ++ii) {
|
||||
BufferUtils.writeMCString(bb, "\"" + BufferUtils.readLegacyMCString(in, 255)
|
||||
.replaceAll("\\\\", "\\\\").replaceAll("\"", "\\\\\"") + "\"", 4095);
|
||||
}
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0xCA:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x13);
|
||||
bb.writeByte(in.readByte());
|
||||
bb.writeFloat(in.readByte());
|
||||
bb.writeFloat(in.readByte());
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0xCB:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x14);
|
||||
BufferUtils.convertLegacyMCString(in, bb, 255);
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
bb.writeBoolean(false);
|
||||
break;
|
||||
case 0xCC:
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x15);
|
||||
BufferUtils.convertLegacyMCString(in, bb, 255);
|
||||
bb.writeByte(16 >> in.readByte());
|
||||
byte guh = in.readByte();
|
||||
bb.writeByte(guh & 3);
|
||||
bb.writeBoolean((guh & 8) != 0);
|
||||
in.readByte();
|
||||
bb.writeByte(in.readBoolean() ? 0xFF : 0xFE);
|
||||
if (in.isReadable())
|
||||
throw new IndexOutOfBoundsException();
|
||||
break;
|
||||
case 0xCD:
|
||||
bb = ctx.alloc().buffer();
|
||||
if (in.readableBytes() > 1)
|
||||
throw new IndexOutOfBoundsException();
|
||||
BufferUtils.writeVarInt(bb, 0x16);
|
||||
BufferUtils.writeVarInt(bb, 0);
|
||||
break;
|
||||
case 0xFA:
|
||||
String name = BufferUtils.readLegacyMCString(in, 255);
|
||||
int pmLen = in.readUnsignedShort();
|
||||
if (in.readableBytes() != pmLen) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
switch (name) {
|
||||
case "MC|AdvCdm":
|
||||
int ri = in.readerIndex();
|
||||
int cmdX = in.readInt();
|
||||
int cmdY = in.readInt();
|
||||
int cmdZ = in.readInt();
|
||||
String cmd = BufferUtils.readLegacyMCString(in, 32767);
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
in.readerIndex(ri);
|
||||
in.writerIndex(ri);
|
||||
in.writeByte(0);
|
||||
in.writeInt(cmdX);
|
||||
in.writeInt(cmdY);
|
||||
in.writeInt(cmdZ);
|
||||
BufferUtils.writeMCString(in, cmd, 32767);
|
||||
in.writeBoolean(true);
|
||||
pmLen = in.writerIndex() - ri;
|
||||
break;
|
||||
case "MC|ItemName":
|
||||
ri = in.readerIndex();
|
||||
bb = ctx.alloc().buffer();
|
||||
in.readBytes(bb, pmLen);
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
in.readerIndex(ri);
|
||||
in.writerIndex(ri);
|
||||
BufferUtils.writeVarInt(in, pmLen);
|
||||
in.writeBytes(bb);
|
||||
bb.release();
|
||||
pmLen = in.writerIndex() - ri;
|
||||
break;
|
||||
case "MC|BEdit":
|
||||
case "MC|BSign":
|
||||
ri = in.readerIndex();
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.convertLegacySlot(in, bb, player());
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
in.readerIndex(ri);
|
||||
in.writerIndex(ri);
|
||||
in.writeBytes(bb);
|
||||
pmLen = bb.writerIndex();
|
||||
bb.release();
|
||||
break;
|
||||
case "EAG|FetchSkin":
|
||||
ri = in.readerIndex();
|
||||
int cookie = in.readUnsignedShort();
|
||||
String username = BufferUtils.readCharSequence(in, pmLen - 2, StandardCharsets.US_ASCII).toString();
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
TabListTracker.ListItem playerItem = tabList().getItemByName(username);
|
||||
if (playerItem != null) {
|
||||
UUID uuid = playerItem.playerUUID;
|
||||
messageController().recieveInboundMessage(new CPacketGetOtherTexturesV5EAG(cookie,
|
||||
uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()));
|
||||
}
|
||||
break fuck;
|
||||
case "EAG|Voice":
|
||||
ri = in.readerIndex();
|
||||
int sig = in.readUnsignedByte();
|
||||
switch (sig) {
|
||||
case 0: // VOICE_SIGNAL_REQUEST
|
||||
String target = BufferUtils.readASCIIStr(in);
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
UUID uuid = player().getVoicePlayerByName(target);
|
||||
if (uuid != null) {
|
||||
messageController().recieveInboundMessage(new CPacketVoiceSignalRequestEAG(
|
||||
uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()));
|
||||
}
|
||||
break;
|
||||
case 1: // VOICE_SIGNAL_CONNECT
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
messageController().recieveInboundMessage(new CPacketVoiceSignalConnectEAG());
|
||||
break;
|
||||
case 2: // VOICE_SIGNAL_DISCONNECT
|
||||
if (in.isReadable()) {
|
||||
target = BufferUtils.readASCIIStr(in);
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
uuid = player().getVoicePlayerByName(target);
|
||||
if (uuid != null) {
|
||||
messageController().recieveInboundMessage(new CPacketVoiceSignalDisconnectPeerV4EAG(
|
||||
uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()));
|
||||
}
|
||||
} else {
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
player().releaseVoiceGlobalMap();
|
||||
messageController().recieveInboundMessage(new CPacketVoiceSignalDisconnectV4EAG());
|
||||
}
|
||||
break;
|
||||
case 3: // VOICE_SIGNAL_ICE
|
||||
uuid = player().getVoicePlayerByName(BufferUtils.readASCIIStr(in));
|
||||
if (uuid != null) {
|
||||
byte[] data = new byte[in.readUnsignedShort()];
|
||||
in.readBytes(data);
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
messageController().recieveInboundMessage(new CPacketVoiceSignalICEEAG(
|
||||
uuid.getMostSignificantBits(), uuid.getLeastSignificantBits(), data));
|
||||
}
|
||||
break;
|
||||
case 4: // VOICE_SIGNAL_DESC
|
||||
uuid = player().getVoicePlayerByName(BufferUtils.readASCIIStr(in));
|
||||
if (uuid != null) {
|
||||
byte[] data = new byte[in.readUnsignedShort()];
|
||||
in.readBytes(data);
|
||||
if (in.isReadable()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
messageController().recieveInboundMessage(new CPacketVoiceSignalDescEAG(
|
||||
uuid.getMostSignificantBits(), uuid.getLeastSignificantBits(), data));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
break fuck;
|
||||
default:
|
||||
//
|
||||
}
|
||||
bb = ctx.alloc().buffer();
|
||||
BufferUtils.writeVarInt(bb, 0x17);
|
||||
BufferUtils.writeMCString(bb, name, 255);
|
||||
bb.writeBytes(in, pmLen);
|
||||
break;
|
||||
case 0xFF:
|
||||
int len = in.readShort();
|
||||
if (in.readableBytes() != len << 1) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown packet: " + pktId);
|
||||
}
|
||||
if (bb != null) {
|
||||
out.add(bb.retain());
|
||||
}
|
||||
} finally {
|
||||
if (bb != null) {
|
||||
bb.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1831
File diff suppressed because it is too large
Load Diff
+131
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class SkinHandshakeConverter {
|
||||
|
||||
static void convertSkinPixels(ByteBuf imageIn, int offsetIn, byte[] imageOut, int offsetOut, int count) {
|
||||
if (BufferUtils.LITTLE_ENDIAN_SUPPORT) {
|
||||
for (int i = 0, j, k, l = count << 2; i < l; i += 4) {
|
||||
j = imageIn.getIntLE(offsetIn + i);
|
||||
k = offsetOut + i;
|
||||
imageOut[k] = (byte) (j >>> 24);
|
||||
imageOut[k + 1] = (byte) j;
|
||||
imageOut[k + 2] = (byte) (j >>> 8);
|
||||
imageOut[k + 3] = (byte) (j >>> 16);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0, j, k, l = count << 2; i < l; i += 4) {
|
||||
j = imageIn.getInt(offsetIn + i);
|
||||
k = offsetOut + i;
|
||||
imageOut[k] = (byte) j;
|
||||
imageOut[k + 1] = (byte) (j >>> 24);
|
||||
imageOut[k + 2] = (byte) (j >>> 16);
|
||||
imageOut[k + 3] = (byte) (j >>> 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void convertSkin64x32To64x64(ByteBuf imageIn, int offsetIn, byte[] imageOut, int offsetOut) {
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 0, 0, 0, 0, 64, 32, 64, 64, false);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 24, 48, 20, 52, 4, 16, 8, 20, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 28, 48, 24, 52, 8, 16, 12, 20, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 20, 52, 16, 64, 8, 20, 12, 32, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 24, 52, 20, 64, 4, 20, 8, 32, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 28, 52, 24, 64, 0, 20, 4, 32, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 32, 52, 28, 64, 12, 20, 16, 32, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 40, 48, 36, 52, 44, 16, 48, 20, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 44, 48, 40, 52, 48, 16, 52, 20, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 36, 52, 32, 64, 48, 20, 52, 32, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 40, 52, 36, 64, 44, 20, 48, 32, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 44, 52, 40, 64, 40, 20, 44, 32, 64, 64);
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, 48, 52, 44, 64, 52, 20, 56, 32, 64, 64);
|
||||
}
|
||||
|
||||
static void copyRawPixels(ByteBuf imageIn, int offsetIn, byte[] imageOut, int offsetOut, int dx1, int dy1, int dx2,
|
||||
int dy2, int sx1, int sy1, int sx2, int sy2, int imgSrcWidth, int imgDstWidth) {
|
||||
if (dx1 > dx2) {
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, sx1, sy1, dx2, dy1, sx2 - sx1, sy2 - sy1, imgSrcWidth,
|
||||
imgDstWidth, true);
|
||||
} else {
|
||||
copyRawPixels(imageIn, offsetIn, imageOut, offsetOut, sx1, sy1, dx1, dy1, sx2 - sx1, sy2 - sy1, imgSrcWidth,
|
||||
imgDstWidth, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyRawPixels(ByteBuf imageIn, int offsetIn, byte[] imageOut, int offsetOut, int srcX, int srcY,
|
||||
int dstX, int dstY, int width, int height, int imgSrcWidth, int imgDstWidth, boolean flip) {
|
||||
if (BufferUtils.LITTLE_ENDIAN_SUPPORT) {
|
||||
int i, j;
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
i = imageIn.getIntLE((((srcY + y) * imgSrcWidth + srcX + x) << 2) + offsetIn);
|
||||
if (flip) {
|
||||
j = (dstY + y) * imgDstWidth + dstX + width - x - 1;
|
||||
} else {
|
||||
j = (dstY + y) * imgDstWidth + dstX + x;
|
||||
}
|
||||
j = (j << 2) + offsetOut;
|
||||
imageOut[j] = (byte) (i >>> 24);
|
||||
imageOut[j + 1] = (byte) i;
|
||||
imageOut[j + 2] = (byte) (i >>> 8);
|
||||
imageOut[j + 3] = (byte) (i >>> 16);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int i, j;
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
i = imageIn.getInt((((srcY + y) * imgSrcWidth + srcX + x) << 2) + offsetIn);
|
||||
if (flip) {
|
||||
j = (dstY + y) * imgDstWidth + dstX + width - x - 1;
|
||||
} else {
|
||||
j = (dstY + y) * imgDstWidth + dstX + x;
|
||||
}
|
||||
j = (j << 2) + offsetOut;
|
||||
imageOut[j] = (byte) i;
|
||||
imageOut[j + 1] = (byte) (i >>> 24);
|
||||
imageOut[j + 2] = (byte) (i >>> 16);
|
||||
imageOut[j + 3] = (byte) (i >>> 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void convertCape32x32RGBAto23x17RGB(ByteBuf imageIn, int inOffset, byte[] skinOut, int outOffset) {
|
||||
int i, j;
|
||||
for (int y = 0; y < 17; ++y) {
|
||||
for (int x = 0; x < 22; ++x) {
|
||||
i = inOffset + ((y * 32 + x) << 2);
|
||||
j = outOffset + ((y * 23 + x) * 3);
|
||||
skinOut[j] = imageIn.getByte(i);
|
||||
skinOut[j + 1] = imageIn.getByte(i + 1);
|
||||
skinOut[j + 2] = imageIn.getByte(i + 2);
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < 11; ++y) {
|
||||
i = inOffset + (((y + 11) * 32 + 22) << 2);
|
||||
j = outOffset + (((y + 6) * 23 + 22) * 3);
|
||||
skinOut[j] = imageIn.getByte(i);
|
||||
skinOut[j + 1] = imageIn.getByte(i + 1);
|
||||
skinOut[j + 2] = imageIn.getByte(i + 2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.api.skins.EnumPresetSkins;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class SkinPacketUtils {
|
||||
|
||||
private static final int SKIN_TYPE_CUSTOM_LEGACY = 0;
|
||||
private static final int SKIN_TYPE_CUSTOM_MODERN_STEVE = 1;
|
||||
private static final int SKIN_TYPE_PRESET = 4;
|
||||
private static final int SKIN_TYPE_CUSTOM_MODERN_ALEX = 5;
|
||||
|
||||
private static final int CAPE_TYPE_CUSTOM = 0;
|
||||
private static final int CAPE_TYPE_PRESET = 2;
|
||||
|
||||
public static byte[] rewriteLegacyHandshakeSkinToV1(ByteBuf data) {
|
||||
try {
|
||||
int id = data.readUnsignedByte();
|
||||
switch (id) {
|
||||
case SKIN_TYPE_CUSTOM_LEGACY:
|
||||
return rewriteLegacyHandshakeLegacySkinToV1(data);
|
||||
case SKIN_TYPE_CUSTOM_MODERN_STEVE:
|
||||
return rewriteLegacyHandshakeModernSkinToV1(data, false);
|
||||
case SKIN_TYPE_PRESET:
|
||||
return rewriteLegacyHandshakePresetSkinToV1(data);
|
||||
case SKIN_TYPE_CUSTOM_MODERN_ALEX:
|
||||
return rewriteLegacyHandshakeModernSkinToV1(data, true);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int[] map15to18PresetSkin = new int[] {
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //skins/01.default_steve.png
|
||||
EnumPresetSkins.DEFAULT_ALEX.getId(), //skins/02.default_alex.png
|
||||
EnumPresetSkins.TENNIS_STEVE.getId(), //skins/03.tennis_steve.png
|
||||
EnumPresetSkins.TENNIS_ALEX.getId(), //skins/04.tennis_alex.png
|
||||
EnumPresetSkins.TUXEDO_STEVE.getId(), //skins/05.tuxedo_steve.png
|
||||
EnumPresetSkins.TUXEDO_ALEX.getId(), //skins/06.tuxedo_alex.png
|
||||
EnumPresetSkins.ATHLETE_STEVE.getId(), //skins/07.athlete_steve.png
|
||||
EnumPresetSkins.ATHLETE_ALEX.getId(), //skins/08.athlete_alex.png
|
||||
EnumPresetSkins.CYCLIST_STEVE.getId(), //skins/09.cyclist_steve.png
|
||||
EnumPresetSkins.CYCLIST_ALEX.getId(), //skins/10.cyclist_alex.png
|
||||
EnumPresetSkins.BOXER_STEVE.getId(), //skins/11.boxer_steve.png
|
||||
EnumPresetSkins.BOXER_ALEX.getId(), //skins/12.boxer_alex.png
|
||||
EnumPresetSkins.PRISONER_STEVE.getId(), //skins/13.prisoner_steve.png
|
||||
EnumPresetSkins.PRISONER_ALEX.getId(), //skins/14.prisoner_alex.png
|
||||
EnumPresetSkins.SCOTTISH_STEVE.getId(), //skins/15.scottish_steve.png
|
||||
EnumPresetSkins.SCOTTISH_ALEX.getId(), //skins/16.scottish_alex.png
|
||||
EnumPresetSkins.DEVELOPER_STEVE.getId(), //skins/17.dev_steve.png
|
||||
EnumPresetSkins.DEVELOPER_ALEX.getId(), //skins/18.dev_alex.png
|
||||
EnumPresetSkins.HEROBRINE.getId(), //skins/19.herobrine.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //mob/enderman.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //mob/skeleton.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //mob/fire.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //skins/20.barney.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //skins/21.slime.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //skins/22.noob.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //skins/23.trump.png
|
||||
EnumPresetSkins.NOTCH.getId(), //skins/24.notch.png
|
||||
EnumPresetSkins.CREEPER.getId(), //skins/25.creeper.png
|
||||
EnumPresetSkins.ZOMBIE.getId(), //skins/26.zombie.png
|
||||
EnumPresetSkins.PIG.getId(), //skins/27.pig.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //skins/28.squid.png
|
||||
EnumPresetSkins.MOOSHROOM.getId(), //skins/29.mooshroom.png
|
||||
EnumPresetSkins.DEFAULT_STEVE.getId(), //mob/villager/villager.png
|
||||
EnumPresetSkins.LONG_ARMS.getId(), //LONG_ARMS
|
||||
EnumPresetSkins.WEIRD_CLIMBER_DUDE.getId(), //WEIRD_CLIMBER_DUDE
|
||||
EnumPresetSkins.LAXATIVE_DUDE.getId(), //LAXATIVE_DUDE
|
||||
EnumPresetSkins.BABY_CHARLES.getId(), //BABY_CHARLES
|
||||
EnumPresetSkins.BABY_WINSTON.getId() //BABY_WINSTON
|
||||
};
|
||||
|
||||
private static final int[] map18to15PresetSkin = invertMap(map15to18PresetSkin);
|
||||
|
||||
private static int[] invertMap(int[] arr) {
|
||||
int max = 0;
|
||||
for (int i = 0; i < arr.length; ++i) {
|
||||
int j = arr[i];
|
||||
if (j > max) {
|
||||
max = j;
|
||||
}
|
||||
}
|
||||
int[] ret = new int[max + 1];
|
||||
for (int i = 0; i < arr.length; ++i) {
|
||||
int j = arr[i];
|
||||
if (j != 0) {
|
||||
ret[j] = i;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static int map(int val, int[] table) {
|
||||
return val >= 0 && val < table.length ? table[val] : 0;
|
||||
}
|
||||
|
||||
private static byte[] rewriteLegacyHandshakePresetSkinToV1(ByteBuf data) {
|
||||
int presetSkin = map(data.readUnsignedByte(), map15to18PresetSkin);
|
||||
return new byte[] { 0x01, (byte) (presetSkin >>> 24), (byte) (presetSkin >>> 16), (byte) (presetSkin >>> 8),
|
||||
(byte) presetSkin };
|
||||
}
|
||||
|
||||
private static byte[] rewriteLegacyHandshakeLegacySkinToV1(ByteBuf data) {
|
||||
byte[] ret = new byte[2 + 16384];
|
||||
ret[0] = 0x02;
|
||||
ret[1] = 0x00;
|
||||
SkinHandshakeConverter.convertSkin64x32To64x64(data, data.readerIndex(), ret, 2);
|
||||
data.skipBytes(8192);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static byte[] rewriteLegacyHandshakeModernSkinToV1(ByteBuf data, boolean b) {
|
||||
byte[] ret = new byte[2 + 16384];
|
||||
ret[0] = 0x02;
|
||||
ret[1] = b ? (byte) 0x01 : (byte) 0x00;
|
||||
SkinHandshakeConverter.convertSkinPixels(data, data.readerIndex(), ret, 2, 4096);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static byte[] rewriteLegacyHandshakeCapeToV1(ByteBuf data) {
|
||||
try {
|
||||
int id = data.readUnsignedByte();
|
||||
data.skipBytes(1); // Skip skin layers, TODO: remap this to 1.8 entity metadata?
|
||||
switch (id) {
|
||||
case CAPE_TYPE_CUSTOM:
|
||||
return rewriteLegacyHandshakeCustomCapeToV1(data);
|
||||
case CAPE_TYPE_PRESET:
|
||||
return rewriteLegacyHandshakePresetCapeToV1(data);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] rewriteLegacyHandshakePresetCapeToV1(ByteBuf data) {
|
||||
return new byte[] { 0x01, 0x00, 0x00, 0x00, data.readByte() };
|
||||
}
|
||||
|
||||
private static byte[] rewriteLegacyHandshakeCustomCapeToV1(ByteBuf data) {
|
||||
byte[] ret = new byte[1 + 1173];
|
||||
ret[0] = 0x02;
|
||||
SkinHandshakeConverter.convertCape32x32RGBAto23x17RGB(data, data.readerIndex(), ret, 1);
|
||||
data.skipBytes(4096);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int rewritePresetSkinIdToLegacy(int id) {
|
||||
if (id >= 0 && id < map18to15PresetSkin.length) {
|
||||
return map18to15PresetSkin[id];
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public static void rewriteCustomSkinToLegacy(byte[] data, ByteBuf dest) {
|
||||
if (BufferUtils.LITTLE_ENDIAN_SUPPORT) {
|
||||
for (int i = 0, j; i < 4096; ++i) {
|
||||
j = i * 3;
|
||||
dest.writeIntLE((data[j] & 0xFF) | ((data[j + 1] & 0xFF) << 8) | ((data[j + 2] & 0x7F) << 17)
|
||||
| ((data[j + 2] & 0x80) != 0 ? 0xFF000000 : 0));
|
||||
}
|
||||
} else {
|
||||
for (int i = 0, j; i < 4096; ++i) {
|
||||
j = i * 3;
|
||||
dest.writeInt(((data[j] & 0xFF) << 24) | ((data[j + 1] & 0xFF) << 16) | ((data[j + 2] & 0x7F) << 9)
|
||||
| ((data[j + 2] & 0x80) != 0 ? 0x000000FF : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void rewriteCustomCapeToLegacy(byte[] data, ByteBuf dest) {
|
||||
int idx = dest.writerIndex();
|
||||
dest.writeZero(4096);
|
||||
int i, j;
|
||||
if (BufferUtils.LITTLE_ENDIAN_SUPPORT) {
|
||||
for (int y = 0; y < 17; ++y) {
|
||||
for (int x = 0; x < 22; ++x) {
|
||||
i = idx + ((y * 32 + x) << 2);
|
||||
j = ((y * 23 + x) * 3);
|
||||
dest.setIntLE(i,
|
||||
0xFF000000 | ((data[j + 2] & 0xFF) << 16) | ((data[j + 1] & 0xFF) << 8) | (data[j] & 0xFF));
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < 11; ++y) {
|
||||
i = idx + (((y + 11) * 32 + 22) << 2);
|
||||
j = (((y + 6) * 23 + 22) * 3);
|
||||
dest.setIntLE(i,
|
||||
0xFF000000 | ((data[j + 2] & 0xFF) << 16) | ((data[j + 1] & 0xFF) << 8) | (data[j] & 0xFF));
|
||||
}
|
||||
} else {
|
||||
for (int y = 0; y < 17; ++y) {
|
||||
for (int x = 0; x < 22; ++x) {
|
||||
i = idx + ((y * 32 + x) << 2);
|
||||
j = ((y * 23 + x) * 3);
|
||||
dest.setInt(i, 0x000000FF | ((data[j + 2] & 0xFF) << 8) | ((data[j + 1] & 0xFF) << 16)
|
||||
| ((data[j] & 0xFF) << 24));
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < 11; ++y) {
|
||||
i = idx + (((y + 11) * 32 + 22) << 2);
|
||||
j = (((y + 6) * 23 + 22) * 3);
|
||||
dest.setInt(i, 0x000000FF | ((data[j + 2] & 0xFF) << 8) | ((data[j + 1] & 0xFF) << 16)
|
||||
| ((data[j] & 0xFF) << 24));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class HackedBufferedInputStream extends BufferedInputStream {
|
||||
|
||||
public HackedBufferedInputStream(InputStream in, int size) {
|
||||
super(in, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
in.close();
|
||||
pos = count;
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class HackedBufferedOutputStream extends BufferedOutputStream {
|
||||
|
||||
public HackedBufferedOutputStream(OutputStream out, int size) {
|
||||
super(out, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.flush();
|
||||
this.out.close();
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class HackedDataOutputStream extends DataOutputStream {
|
||||
|
||||
public HackedDataOutputStream(OutputStream out) {
|
||||
super(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.out.close();
|
||||
}
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Note: Based on OpenJDK
|
||||
*/
|
||||
public class ReusableDeflaterOutputStream extends OutputStream {
|
||||
|
||||
// The amount to write to the output every cycle
|
||||
private static final int BLOCK_SIZE = 512;
|
||||
|
||||
protected Deflater def;
|
||||
protected ByteBuf buf;
|
||||
protected boolean array;
|
||||
private boolean closed = false;
|
||||
private byte[] singleByteBuf;
|
||||
|
||||
public ReusableDeflaterOutputStream(Deflater def, byte[] singleByteBuf) {
|
||||
this.def = def;
|
||||
this.singleByteBuf = singleByteBuf;
|
||||
}
|
||||
|
||||
public void setOutput(ByteBuf buf) {
|
||||
def.reset();
|
||||
this.closed = false;
|
||||
this.array = buf.hasArray();
|
||||
if (!array && buf.nioBufferCount() != 1) {
|
||||
throw new IllegalStateException("Composite buffers not supported! (Output)");
|
||||
}
|
||||
this.buf = buf;
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
singleByteBuf[0] = (byte) (b & 0xff);
|
||||
write(singleByteBuf, 0, 1);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
if (def.finished()) {
|
||||
throw new IOException("write beyond end of stream");
|
||||
}
|
||||
if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
} else if (len == 0) {
|
||||
return;
|
||||
}
|
||||
if (!def.finished()) {
|
||||
def.setInput(b, off, len);
|
||||
while (!def.needsInput()) {
|
||||
deflate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void finish() throws IOException {
|
||||
if (!def.finished()) {
|
||||
def.finish();
|
||||
while (!def.finished()) {
|
||||
deflate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (!closed) {
|
||||
finish();
|
||||
closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void deflate() throws IOException {
|
||||
int writable = buf.writableBytes();
|
||||
if (writable < BLOCK_SIZE) {
|
||||
writable = BLOCK_SIZE;
|
||||
}
|
||||
buf.ensureWritable(writable);
|
||||
int len;
|
||||
int writerIndex = buf.writerIndex();
|
||||
if (array) {
|
||||
len = def.deflate(buf.array(), buf.arrayOffset() + writerIndex, writable);
|
||||
} else {
|
||||
len = def.deflate(buf.internalNioBuffer(writerIndex, writable));
|
||||
}
|
||||
if (len > 0) {
|
||||
buf.writerIndex(writerIndex + len);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec.BufferUtils;
|
||||
|
||||
/**
|
||||
* Note: Based on OpenJDK
|
||||
*/
|
||||
public class ReusableGZIPInputStream extends ReusableInflaterInputStream {
|
||||
|
||||
protected CRC32 crc = new CRC32();
|
||||
|
||||
protected boolean eos;
|
||||
|
||||
private boolean closed = false;
|
||||
|
||||
private int start = 0;
|
||||
private int remaining = -1;
|
||||
|
||||
private void ensureOpen() throws IOException {
|
||||
if (closed) {
|
||||
throw new IOException("Stream closed");
|
||||
}
|
||||
}
|
||||
|
||||
public ReusableGZIPInputStream(Inflater inf, byte[] singleByteBuf) {
|
||||
super(inf, singleByteBuf);
|
||||
}
|
||||
|
||||
public void setInput(ByteBuf dataIn, int limit) throws IOException {
|
||||
closed = false;
|
||||
eos = false;
|
||||
if (BufferUtils.LITTLE_ENDIAN_SUPPORT) {
|
||||
readHeaderLE(dataIn);
|
||||
} else {
|
||||
readHeader(dataIn);
|
||||
}
|
||||
start = dataIn.readerIndex();
|
||||
remaining = limit;
|
||||
super.setInput(dataIn);
|
||||
}
|
||||
|
||||
public int read(byte[] buf, int off, int len) throws IOException {
|
||||
ensureOpen();
|
||||
if (eos) {
|
||||
return -1;
|
||||
}
|
||||
int n = super.read(buf, off, len);
|
||||
if (n == -1) {
|
||||
if (BufferUtils.LITTLE_ENDIAN_SUPPORT) {
|
||||
readTrailerLE();
|
||||
} else {
|
||||
readTrailer();
|
||||
}
|
||||
eos = true;
|
||||
} else {
|
||||
if (remaining >= 0) {
|
||||
if (n > remaining) {
|
||||
throw new IOException("Too many bytes decompressed!");
|
||||
} else {
|
||||
remaining -= n;
|
||||
}
|
||||
}
|
||||
crc.update(buf, off, n);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (!closed) {
|
||||
if (inf.finished()) {
|
||||
if (BufferUtils.LITTLE_ENDIAN_SUPPORT) {
|
||||
readTrailerLE();
|
||||
} else {
|
||||
readTrailer();
|
||||
}
|
||||
eos = true;
|
||||
}
|
||||
buf.readerIndex(start + inf.getTotalIn());
|
||||
super.close();
|
||||
eos = true;
|
||||
closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int GZIP_MAGIC = 0x8b1f;
|
||||
|
||||
/*
|
||||
* File header flags.
|
||||
*/
|
||||
private static final int FTEXT = 1; // Extra text
|
||||
private static final int FHCRC = 2; // Header CRC
|
||||
private static final int FEXTRA = 4; // Extra field
|
||||
private static final int FNAME = 8; // File name
|
||||
private static final int FCOMMENT = 16; // File comment
|
||||
|
||||
private int readHeaderLE(ByteBuf dataIn) throws IOException {
|
||||
int start = dataIn.readerIndex();
|
||||
// Check header magic
|
||||
if (dataIn.readUnsignedShortLE() != GZIP_MAGIC) {
|
||||
throw new ZipException("Not in GZIP format");
|
||||
}
|
||||
// Check compression method
|
||||
if (dataIn.readUnsignedByte() != 8) {
|
||||
throw new ZipException("Unsupported compression method");
|
||||
}
|
||||
// Read flags
|
||||
int flg = dataIn.readUnsignedByte();
|
||||
// Skip MTIME, XFL, and OS fields
|
||||
dataIn.skipBytes(6);
|
||||
int n = 2 + 2 + 6;
|
||||
// Skip optional extra field
|
||||
if ((flg & FEXTRA) == FEXTRA) {
|
||||
int m = dataIn.readUnsignedShortLE();
|
||||
dataIn.skipBytes(m);
|
||||
n += m + 2;
|
||||
}
|
||||
// Skip optional file name
|
||||
if ((flg & FNAME) == FNAME) {
|
||||
do {
|
||||
n++;
|
||||
} while (dataIn.readUnsignedByte() != 0);
|
||||
}
|
||||
// Skip optional file comment
|
||||
if ((flg & FCOMMENT) == FCOMMENT) {
|
||||
do {
|
||||
n++;
|
||||
} while (dataIn.readUnsignedByte() != 0);
|
||||
}
|
||||
// Check optional header CRC
|
||||
if ((flg & FHCRC) == FHCRC) {
|
||||
int v = (int) getByteBufCRC(dataIn, start, dataIn.readerIndex() - start) & 0xffff;
|
||||
if (dataIn.readUnsignedShortLE() != v) {
|
||||
throw new ZipException("Corrupt GZIP header");
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
crc.reset();
|
||||
return n;
|
||||
}
|
||||
|
||||
private int readHeader(ByteBuf dataIn) throws IOException {
|
||||
int start = dataIn.readerIndex();
|
||||
// Check header magic
|
||||
if ((dataIn.readUnsignedByte() | (dataIn.readUnsignedByte() << 8)) != GZIP_MAGIC) {
|
||||
throw new ZipException("Not in GZIP format");
|
||||
}
|
||||
// Check compression method
|
||||
if (dataIn.readUnsignedByte() != 8) {
|
||||
throw new ZipException("Unsupported compression method");
|
||||
}
|
||||
// Read flags
|
||||
int flg = dataIn.readUnsignedByte();
|
||||
// Skip MTIME, XFL, and OS fields
|
||||
dataIn.skipBytes(6);
|
||||
int n = 2 + 2 + 6;
|
||||
// Skip optional extra field
|
||||
if ((flg & FEXTRA) == FEXTRA) {
|
||||
int m = (dataIn.readUnsignedByte() | (dataIn.readUnsignedByte() << 8));
|
||||
dataIn.skipBytes(m);
|
||||
n += m + 2;
|
||||
}
|
||||
// Skip optional file name
|
||||
if ((flg & FNAME) == FNAME) {
|
||||
do {
|
||||
n++;
|
||||
} while (dataIn.readUnsignedByte() != 0);
|
||||
}
|
||||
// Skip optional file comment
|
||||
if ((flg & FCOMMENT) == FCOMMENT) {
|
||||
do {
|
||||
n++;
|
||||
} while (dataIn.readUnsignedByte() != 0);
|
||||
}
|
||||
// Check optional header CRC
|
||||
if ((flg & FHCRC) == FHCRC) {
|
||||
int v = (int) getByteBufCRC(dataIn, start, dataIn.readerIndex() - start) & 0xffff;
|
||||
if ((dataIn.readUnsignedByte() | (dataIn.readUnsignedByte() << 8)) != v) {
|
||||
throw new ZipException("Corrupt GZIP header");
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
crc.reset();
|
||||
return n;
|
||||
}
|
||||
|
||||
private int getByteBufCRC(ByteBuf dataIn, int offset, int len) {
|
||||
crc.reset();
|
||||
if (dataIn.hasArray()) {
|
||||
byte[] arr = dataIn.array();
|
||||
int arrIndex = dataIn.arrayOffset();
|
||||
crc.update(arr, arrIndex + offset, len);
|
||||
} else if (dataIn.nioBufferCount() == 1) {
|
||||
crc.update(dataIn.internalNioBuffer(offset, len));
|
||||
} else {
|
||||
throw new IllegalStateException("Composite buffers not supported! (Input)");
|
||||
}
|
||||
return (int) crc.getValue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads GZIP member trailer and returns true if the eos reached, false if there
|
||||
* are more (concatenated gzip data set)
|
||||
*/
|
||||
private boolean readTrailerLE() throws IOException {
|
||||
ByteBuf in = this.buf;
|
||||
in.readerIndex(start + inf.getTotalIn());
|
||||
// Uses left-to-right evaluation order
|
||||
if ((in.readUnsignedIntLE() != crc.getValue()) ||
|
||||
// rfc1952; ISIZE is the input size modulo 2^32
|
||||
(in.readUnsignedIntLE() != (inf.getBytesWritten() & 0xffffffffL)))
|
||||
throw new ZipException("Corrupt GZIP trailer");
|
||||
start += 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean readTrailer() throws IOException {
|
||||
ByteBuf in = this.buf;
|
||||
in.readerIndex(start + inf.getTotalIn());
|
||||
// Uses left-to-right evaluation order
|
||||
if (((in.readUnsignedByte() | (in.readUnsignedByte() << 8) | (in.readUnsignedByte() << 16)
|
||||
| (in.readUnsignedByte() << 24)) != crc.getValue()) ||
|
||||
// rfc1952; ISIZE is the input size modulo 2^32
|
||||
((in.readUnsignedByte() | (in.readUnsignedByte() << 8) | (in.readUnsignedByte() << 16)
|
||||
| (in.readUnsignedByte() << 24)) != (inf.getBytesWritten() & 0xffffffffL)))
|
||||
throw new ZipException("Corrupt GZIP trailer");
|
||||
start += 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.lax1dude.eaglercraft.backend.rewind_v1_5.base.codec.BufferUtils;
|
||||
|
||||
/**
|
||||
* Note: Based on OpenJDK
|
||||
*/
|
||||
public class ReusableGZIPOutputStream extends ReusableDeflaterOutputStream {
|
||||
|
||||
protected CRC32 crc = new CRC32();
|
||||
|
||||
private static final int GZIP_MAGIC = 0x8b1f;
|
||||
|
||||
// Represents the default "unknown" value for OS header, per RFC-1952
|
||||
private static final byte OS_UNKNOWN = (byte) 255;
|
||||
|
||||
public ReusableGZIPOutputStream(Deflater inf, byte[] singleByteBuf) {
|
||||
super(inf, singleByteBuf);
|
||||
}
|
||||
|
||||
public void setOutput(ByteBuf buf) {
|
||||
super.setOutput(buf);
|
||||
crc.reset();
|
||||
writeHeader();
|
||||
}
|
||||
|
||||
public void write(byte[] buf, int off, int len) throws IOException {
|
||||
super.write(buf, off, len);
|
||||
crc.update(buf, off, len);
|
||||
}
|
||||
|
||||
public void finish() throws IOException {
|
||||
if (!def.finished()) {
|
||||
super.finish();
|
||||
if (BufferUtils.LITTLE_ENDIAN_SUPPORT) {
|
||||
writeTrailerLE();
|
||||
} else {
|
||||
writeTrailer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes GZIP member header.
|
||||
*/
|
||||
private void writeHeader() {
|
||||
this.buf.writeBytes(new byte[] { (byte) GZIP_MAGIC, // Magic number (short)
|
||||
(byte) (GZIP_MAGIC >> 8), // Magic number (short)
|
||||
Deflater.DEFLATED, // Compression method (CM)
|
||||
0, // Flags (FLG)
|
||||
0, // Modification time MTIME (int)
|
||||
0, // Modification time MTIME (int)
|
||||
0, // Modification time MTIME (int)
|
||||
0, // Modification time MTIME (int)
|
||||
0, // Extra flags (XFLG)
|
||||
OS_UNKNOWN // Operating system (OS)
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes GZIP member trailer to a byte array, starting at a given offset.
|
||||
*/
|
||||
private void writeTrailerLE() {
|
||||
this.buf.writeIntLE((int) crc.getValue()); // CRC-32 of uncompr. data
|
||||
this.buf.writeIntLE(def.getTotalIn()); // Number of uncompr. bytes
|
||||
}
|
||||
|
||||
private void writeTrailer() {
|
||||
int i = (int) crc.getValue(); // CRC-32 of uncompr. data
|
||||
this.buf.writeByte(i);
|
||||
this.buf.writeByte(i >>> 8);
|
||||
this.buf.writeByte(i >>> 16);
|
||||
this.buf.writeByte(i >>> 24);
|
||||
i = def.getTotalIn(); // Number of uncompr. bytes
|
||||
this.buf.writeByte(i);
|
||||
this.buf.writeByte(i >>> 8);
|
||||
this.buf.writeByte(i >>> 16);
|
||||
this.buf.writeByte(i >>> 24);
|
||||
}
|
||||
|
||||
}
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (c) 2025 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.lax1dude.eaglercraft.backend.rewind_v1_5.base.zstream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Note: Based on OpenJDK
|
||||
*/
|
||||
public class ReusableInflaterInputStream extends InputStream {
|
||||
|
||||
protected ByteBuf buf;
|
||||
protected Inflater inf;
|
||||
private boolean closed = false;
|
||||
private boolean reachEOF = false;
|
||||
private byte[] singleByteBuf;
|
||||
private ByteBuffer[] extraBuffers;
|
||||
private int extraBufferIndex;
|
||||
|
||||
public ReusableInflaterInputStream(Inflater inf, byte[] singleByteBuf) {
|
||||
this.inf = inf;
|
||||
this.singleByteBuf = singleByteBuf;
|
||||
}
|
||||
|
||||
public void setInput(ByteBuf dataIn) throws IOException {
|
||||
closed = false;
|
||||
reachEOF = false;
|
||||
extraBuffers = null;
|
||||
buf = dataIn;
|
||||
inf.reset();
|
||||
if (dataIn.hasArray()) {
|
||||
byte[] arr = dataIn.array();
|
||||
int arrIndex = dataIn.arrayOffset();
|
||||
inf.setInput(arr, arrIndex + dataIn.readerIndex(), dataIn.readableBytes());
|
||||
} else {
|
||||
int num = dataIn.nioBufferCount();
|
||||
if (num == 1) {
|
||||
inf.setInput(dataIn.internalNioBuffer(dataIn.readerIndex(), dataIn.readableBytes()));
|
||||
} else if (num > 0) {
|
||||
ByteBuffer[] extraBuffers = dataIn.nioBuffers(dataIn.readerIndex(), dataIn.readableBytes());
|
||||
if (extraBuffers != null && extraBuffers.length > 0) {
|
||||
inf.setInput(extraBuffers[0]);
|
||||
this.extraBuffers = extraBuffers;
|
||||
this.extraBufferIndex = 1;
|
||||
} else {
|
||||
inf.setInput(singleByteBuf, 1, 0);
|
||||
}
|
||||
} else {
|
||||
inf.setInput(singleByteBuf, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean feedNextBuffer() {
|
||||
if (extraBuffers != null && extraBufferIndex < extraBuffers.length) {
|
||||
inf.setInput(extraBuffers[extraBufferIndex++]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ensureOpen() throws IOException {
|
||||
if (closed) {
|
||||
throw new IOException("Stream closed");
|
||||
}
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
return read(singleByteBuf, 0, 1) == -1 ? -1 : Byte.toUnsignedInt(singleByteBuf[0]);
|
||||
}
|
||||
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
ensureOpen();
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
} else if (off < 0 || len < 0 || len > b.length - off) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
try {
|
||||
int total = 0;
|
||||
for (int n; total < len; total += n) {
|
||||
if ((n = inf.inflate(b, off + total, len - total)) == 0) {
|
||||
if (inf.finished() || inf.needsDictionary()) {
|
||||
reachEOF = true;
|
||||
if (total == 0) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (inf.needsInput() && !feedNextBuffer()) {
|
||||
throw new ZipException("Input data was not complete");
|
||||
}
|
||||
}
|
||||
}
|
||||
return total;
|
||||
} catch (DataFormatException e) {
|
||||
String s = e.getMessage();
|
||||
throw new ZipException(s != null ? s : "Invalid ZLIB data format");
|
||||
}
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
ensureOpen();
|
||||
if (reachEOF) {
|
||||
return 0;
|
||||
} else if (inf.finished()) {
|
||||
// the end of the compressed data stream has been reached
|
||||
reachEOF = true;
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte[] b = new byte[512];
|
||||
|
||||
public long skip(long n) throws IOException {
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException("negative skip length");
|
||||
}
|
||||
ensureOpen();
|
||||
int max = (int) Math.min(n, Integer.MAX_VALUE);
|
||||
int total = 0;
|
||||
while (total < max) {
|
||||
int len = max - total;
|
||||
if (len > b.length) {
|
||||
len = b.length;
|
||||
}
|
||||
len = read(b, 0, len);
|
||||
if (len == -1) {
|
||||
reachEOF = true;
|
||||
break;
|
||||
}
|
||||
total += len;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
closed = true;
|
||||
buf = null;
|
||||
extraBuffers = null;
|
||||
}
|
||||
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void mark(int readlimit) {
|
||||
}
|
||||
|
||||
public void reset() throws IOException {
|
||||
throw new IOException("mark/reset not supported");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user