[
  {
    "path": ".github/workflows/build.yml",
    "content": "# Automatically build the project and run any configured tests for every push\n# and submitted pull request. This can help catch issues that only occur on\n# certain platforms or Java versions, and provides a first line of defence\n# against bad commits.\n\nname: build\non: [pull_request, push]\n\njobs:\n  build:\n    strategy:\n      matrix:\n        # Use these Java versions\n        java: [\n          21,    # Current Java LTS & minimum supported by Minecraft\n        ]\n        # and run on both Linux and Windows\n        os: [ubuntu-24.04]\n    runs-on: ${{ matrix.os }}\n    steps:\n      - name: checkout repository\n        uses: actions/checkout@v4\n        with:\n          fetch-depth: 0\n          submodules: true\n      - name: validate gradle wrapper\n        uses: gradle/actions/wrapper-validation@v4\n      - name: setup jdk ${{ matrix.java }}\n        uses: actions/setup-java@v2\n        with:\n          distribution: 'zulu'\n          java-version: ${{ matrix.java }}\n          java-package: jdk\n      - uses: actions/cache@v4\n        with:\n          path: |\n            ~/.gradle/caches\n            ~/.gradle/wrapper\n            ./.gradle/loom-cache\n          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}\n          restore-keys: |\n            ${{ runner.os }}-gradle-\n      - name: build\n        run: ./gradlew build\n      - name: upload to modrinth and curseforge\n        run: ./gradlew modrinth publishMainPublicationToCurseForge\n        if: github.ref == 'refs/heads/master'\n        env:\n          MODRINTH_TOKEN: ${{ secrets.MODRINTH_UPLOAD_TOKEN }}\n          CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_API_TOKEN }}\n          GITHUB_EVENT_RAW_PATH: ${{ github.event_path }}\n        continue-on-error: true\n      - name: capture build artifacts\n        if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS\n        uses: actions/upload-artifact@v4\n        with:\n          name: Artifacts\n          path: ./**/build/libs/*-all.jar\n"
  },
  {
    "path": ".github/workflows/checkMappings.yml",
    "content": "name: check mappings\non: [pull_request, push]\n\njobs:\n  checkMappings:\n    strategy:\n      matrix:\n        # Use these Java versions\n        java: [\n          21,    # Current Java LTS & minimum supported by Minecraft\n        ]\n        # and run on both Linux and Windows\n        os: [ubuntu-24.04]\n    runs-on: ${{ matrix.os }}\n    steps:\n      - name: checkout repository\n        uses: actions/checkout@v2\n        with:\n          fetch-depth: 0\n          submodules: true\n      - name: validate gradle wrapper\n        uses: gradle/actions/wrapper-validation@v4\n      - name: setup jdk ${{ matrix.java }}\n        uses: actions/setup-java@v2\n        with:\n          distribution: 'zulu'\n          java-version: ${{ matrix.java }}\n          java-package: jdk\n      - uses: actions/cache@v4\n        with:\n          path: |\n            ~/.gradle/caches\n            ~/.gradle/wrapper\n            ./.gradle/loom-cache\n          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}\n          restore-keys: |\n            ${{ runner.os }}-gradle-\n      - name: \"cache mappingsGen\"\n        uses: actions/cache@v4\n        with:\n          path: |\n            ./run-mappingsGen\n          key: ${{ runner.os }}-mappingsGen-${{ hashFiles('./genMappings.sh') }}\n          restore-keys: |\n            ${{ runner.os }}-mappingsGen-\n      - name: generate mappings\n        env:\n          MAPPINGS_GEN_FRESH: true\n        run: ./genMappings.sh\n      - name: fail if mappings changed\n        run: |\n          git update-index --refresh\n          if ! git diff-index --quiet HEAD --; then\n              echo \"Mappings changed, please commit them\"\n              git diff\n              git diff --staged\n              exit 1\n          fi\n"
  },
  {
    "path": ".gitignore",
    "content": "# gradle\n\n.gradle/\nbuild/\nout/\nclasses/\n\n# eclipse\n\n*.launch\n\n# idea\n\n.idea/\n*.iml\n*.ipr\n*.iws\n\n# vscode\n\n.settings/\n.vscode/\nbin/\n.classpath\n.project\n\n# macos\n\n*.DS_Store\n\n# fabric\n\nrun*/\n"
  },
  {
    "path": ".gitmodules",
    "content": "[submodule \"netty-raknet\"]\n\tpath = netty-raknet\n\turl = https://github.com/RelativityMC/netty-raknet.git\n"
  },
  {
    "path": ".run/BungeeCord Server.run.xml",
    "content": "<component name=\"ProjectRunConfigurationManager\">\n  <configuration default=\"false\" name=\"BungeeCord Server\" type=\"Application\" factoryName=\"Application\">\n    <classpathModifications>\n      <entry exclude=\"true\" path=\"$PROJECT_DIR$/bungee/build/classes/java/main\" />\n      <entry exclude=\"true\" path=\"$PROJECT_DIR$/bungee/build/resources/main\" />\n      <entry exclude=\"true\" path=\"$PROJECT_DIR$/common/build/classes/java/main\" />\n      <entry exclude=\"true\" path=\"$PROJECT_DIR$/common/build/resources/main\" />\n    </classpathModifications>\n    <option name=\"MAIN_CLASS_NAME\" value=\"net.md_5.bungee.BungeeCordLauncher\" />\n    <module name=\"raknetify.bungee.main\" />\n    <option name=\"VM_PARAMETERS\" value=\"-Xmx1G -Draknetify.debug=true -Dio.netty.leakDetection.level=advanced\" />\n    <option name=\"WORKING_DIRECTORY\" value=\"$PROJECT_DIR$/run-bungee\" />\n    <method v=\"2\">\n      <option name=\"Make\" enabled=\"true\" />\n      <option name=\"Gradle.BeforeRunTask\" enabled=\"false\" tasks=\"prepareRunBungee\" externalProjectPath=\"$PROJECT_DIR$/bungee\" vmOptions=\"\" scriptParameters=\"\" />\n    </method>\n  </configuration>\n</component>"
  },
  {
    "path": ".run/Velocity Server.run.xml",
    "content": "<component name=\"ProjectRunConfigurationManager\">\n  <configuration default=\"false\" name=\"Velocity Server\" type=\"Application\" factoryName=\"Application\">\n    <option name=\"MAIN_CLASS_NAME\" value=\"com.velocitypowered.proxy.Velocity\" />\n    <module name=\"com.ishland.raknetify.velocity.raknetify.velocity.main\" />\n    <option name=\"VM_PARAMETERS\" value=\"-Xmx1G -Draknetify.debug=true -Dio.netty.leakDetection.level=advanced\" />\n    <option name=\"WORKING_DIRECTORY\" value=\"$PROJECT_DIR$/run-velocity\" />\n    <method v=\"2\">\n      <option name=\"Make\" enabled=\"true\" />\n      <option name=\"Gradle.BeforeRunTask\" enabled=\"false\" tasks=\"prepareRunVelocity\" externalProjectPath=\"$PROJECT_DIR$/velocity\" vmOptions=\"\" scriptParameters=\"\" />\n    </method>\n  </configuration>\n</component>"
  },
  {
    "path": "HEADER.txt",
    "content": "This file is a part of the Raknetify project, licensed under MIT.\n\nCopyright (c) 2022-2025 ishland\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "Jenkinsfile",
    "content": "pipeline {\n    agent { label 'slave' }\n    options { timestamps() }\n    stages {\n        stage('SCM-SKIP') {\n            steps {\n                scmSkip(skipPattern:'.*\\\\[ci skip\\\\].*')\n            }\n        }\n        stage('Build') {\n            tools {\n                jdk \"OpenJDK 21\"\n            }\n            steps {\n                withMaven(\n                    maven: '3',\n                    mavenLocalRepo: '.repository',\n                    publisherStrategy: 'EXPLICIT'\n                ) {\n                    sh 'git fetch --tags'\n                    sh 'git reset --hard'\n                    sh './gradlew clean build'\n                }\n            }\n            post {\n                success {\n                    archiveArtifacts artifacts: \"**/build/libs/*-all.jar\", fingerprint: true\n                }\n                failure {\n                    cleanWs()\n                }\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2022-2025 ishland\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# Raknetify\nA Fabric mod / Velocity plugin / BungeeCord plugin that uses RakNet to improve multiplayer experience significantly\nunder unreliable and rate-limited connections.\n\n# Features\n- Higher reliability and lower latency under unreliable and rate-limited client connections.\n- Uses RakNet's multiple channels with priorities to achieve higher responsiveness. \n- Supports ViaVersion client-side and ViaVersion server-side.\n\n# How to use it?\n\n## Prerequisites\n- Raknetify is designed to work on Minecraft 1.17.1+\n  Note: On proxies such as Velocity and BungeeCord, **unsupported client version** will cause\n  multi-channelling failing to initialize, causing **reduced responsiveness**.  \n- You need to have a UDP port opened at the same port number of your normal server port. \n\n## Installation and usage\n- Download the latest release from \n  [GitHub](https://github.com/RelativityMC/raknetify/releases) \n  [Modrinth (Fabric)](https://modrinth.com/mod/raknetify/versions) \n  [CurseForge (Fabric)](https://www.curseforge.com/minecraft/mc-mods/raknetify/files)\n  [SpigotMC (BungeeCord)](https://www.spigotmc.org/resources/raknetify-bungeecord.102509/)\n  or development builds from [CodeMC](https://ci.codemc.io/job/RelativityMC/job/raknetify/)\n- Install the mod on both client and server. (Installation on backend servers are not needed if using on proxies) \n- Prefix your server address with `raknet;` (or `raknetl;` to use high mtu) and save or connect directly. \n  (e.g. `raknet;example.com`)\n- Enjoy!\n\n"
  },
  {
    "path": "build.gradle",
    "content": "plugins {\n\tid 'fabric-loom' version '1.13-SNAPSHOT' apply false\n\tid 'com.gradleup.shadow' version '9.2.1' apply false\n\tid 'dev.yumi.gradle.licenser' version '2.1.1' apply false\n\tid 'com.modrinth.minotaur' version '2.+' apply false\n\tid 'io.github.themrmilchmann.curseforge-publish' version '0.8.0' apply false\n}\n\nsubprojects {\n\tapply plugin: 'java'\n\tapply plugin: 'java-library'\n\tapply plugin: 'maven-publish'\n\tapply plugin: 'dev.yumi.gradle.licenser'\n\n\tjava {\n        sourceCompatibility = JavaVersion.VERSION_17\n        targetCompatibility = JavaVersion.VERSION_17\n    }\n\n\tversion = project.mod_version + \".\" + getVersionSuffix()\n\n\tlicense {\n\t\trule(rootProject.file('HEADER.txt'))\n\t}\n\n\trepositories {\n\t\tmavenCentral()\n\t\tmaven { url 'https://jitpack.io' }\n\t\tmaven { url 'https://repo.codemc.org/repository/maven-public' }\n\t\tmaven { url 'https://oss.sonatype.org/content/repositories/snapshots' }\n\t}\n\n\t// configure the maven publication\n\tpublishing {\n\t\tpublications {\n\t\t\tmavenJava(MavenPublication) {\n\t\t\t\tfrom components.java\n\t\t\t}\n\t\t}\n\n\t\t// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.\n\t\trepositories {\n\t\t\t// Add repositories to publish to here.\n\t\t\t// Notice: This block does NOT have the same function as the block in the top level.\n\t\t\t// The repositories here will be used for publishing your artifact, not for\n\t\t\t// retrieving dependencies.\n\t\t}\n\t}\n\n\ttasks.withType(AbstractArchiveTask) {\n\t\tpreserveFileTimestamps = false\n\t\treproducibleFileOrder = true\n\t}\n\n\tafterEvaluate {\n\t\tif (it.plugins.hasPlugin(\"com.modrinth.minotaur\")) {\n\t\t\tmodrinth {\n\t\t\t\ttoken = System.getenv(\"MODRINTH_TOKEN\") // This is the default. Remember to have the MODRINTH_TOKEN environment variable set or else this will fail, or set it to whatever you want - just make sure it stays private!\n\t\t\t\tprojectId = \"raknetify\" // This can be the project ID or the slug. Either will work!\n//\t\t\t\tversionNumber = project.version + \"+\" + project.minecraft_version // You don't need to set this manually. Will fail if Modrinth has this version already\n//\t\t\t\tversionName = project.version + \" devbuild for \" + project.minecraft_version\n\t\t\t\tversionType = \"alpha\" // This is the default -- can also be `beta` or `alpha`\n//\t\t\t\tuploadFile = remapShadowJar // With Loom, this MUST be set to `remapJar` instead of `jar`!\n\t\t\t\tgameVersions = [\"1.18\", \"1.18.1\", \"1.18.2\", \"1.19\", \"1.19.1\", \"1.19.2\", \"1.19.3\", \"1.19.4\", \"1.20\", \"1.20.1\", \"1.20.2\", \"1.20.3\", \"1.20.4\", \"1.20.5\", \"1.20.6\", \"1.21\", \"1.21.1\", \"1.21.2\", \"1.21.3\", \"1.21.4\", \"1.21.5\", \"1.21.6\", \"1.21.7\", \"1.21.8\", \"1.21.9\", \"1.21.10\", \"1.21.11\"]\n//\t\t\t\tloaders = [\"fabric\"]\n\t\t\t\tchangelog = com.ishland.buildscript.ParseGItHubActionChangelog.getChangelog()\n\t\t\t}\n\t\t}\n\t}\n\n}\n\nafterEvaluate {\n\tlogger.lifecycle(\"Version String: ${project.mod_version + '.' + getVersionSuffix()}\")\n\tlogger.lifecycle(com.ishland.buildscript.ParseGItHubActionChangelog.getChangelog())\n}\n\nString getVersionSuffix() {\n    def stdout = providers.exec {\n        commandLine 'git', 'describe', '--tags', '--dirty', '--broken'\n    }.standardOutput.asText.get()\n\tstdout = stdout.toString().strip()\n\tdef suffix = \"\"\n\tif (stdout.endsWith(\"-dirty\")) {\n\t\tstdout = stdout.substring(0, stdout.length() - \"-dirty\".length())\n\t\tsuffix = \"-dirty\"\n\t}\n\tif (stdout.indexOf('-') < 0) {\n\t\treturn \"0\" + suffix;\n\t}\n\tdef split = stdout.split('-')\n\treturn split[split.length - 2] + suffix\n}\n"
  },
  {
    "path": "buildSrc/build.gradle",
    "content": "plugins {\n    id 'java'\n}\n\njava {\n    sourceCompatibility = JavaVersion.VERSION_17\n    targetCompatibility = JavaVersion.VERSION_17\n}\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    // https://mvnrepository.com/artifact/com.google.code.gson/gson\n    implementation 'com.google.code.gson:gson:+'\n}\n\n\n"
  },
  {
    "path": "buildSrc/src/main/java/com/ishland/buildscript/ParseGItHubActionChangelog.java",
    "content": "package com.ishland.buildscript;\n\nimport com.google.gson.Gson;\nimport com.google.gson.JsonArray;\nimport com.google.gson.JsonElement;\nimport com.google.gson.JsonObject;\n\nimport java.nio.file.Files;\nimport java.nio.file.Path;\n\npublic class ParseGItHubActionChangelog {\n\n    public static String getChangelog() throws Throwable {\n        final String path = System.getenv(\"GITHUB_EVENT_RAW_PATH\");\n        if (path == null || path.isBlank()) return \"No changelog was specified. \";\n        final JsonObject jsonObject = new Gson().fromJson(Files.readString(Path.of(path)), JsonObject.class);\n\n        StringBuilder builder = new StringBuilder();\n        builder.append(\"This version is uploaded automatically by GitHub Actions.  \\n\\n\")\n                .append(\"Changelog:  \\n\");\n        final JsonArray commits = jsonObject.getAsJsonArray(\"commits\");\n        if (commits.isEmpty()) {\n            builder.append(\"No changes detected. \\n\");\n        } else {\n            for (JsonElement commit : commits) {\n                JsonObject object = commit.getAsJsonObject();\n                builder.append(\"- \");\n                builder.append('[').append(object.get(\"id\").getAsString(), 0, 8).append(']')\n                        .append('(').append(object.get(\"url\").getAsString()).append(')');\n                builder.append(' ');\n                builder.append(object.get(\"message\").getAsString().split(\"\\n\")[0]);\n                builder.append(\" - \");\n                builder.append(object.get(\"author\").getAsJsonObject().get(\"name\").getAsString());\n                builder.append(\"  \").append('\\n');\n            }\n        }\n        return builder.toString();\n    }\n\n}\n"
  },
  {
    "path": "bungee/build.gradle",
    "content": "import java.nio.file.Files\nimport java.nio.file.StandardCopyOption\n\nevaluationDependsOn(\":\")\n\napply plugin: 'com.gradleup.shadow'\napply plugin: 'com.modrinth.minotaur'\n\nbase {\n    archivesName = project.archives_base_name + \"-bungee\"\n}\ngroup = project.maven_group + \".bungee\"\n\nrepositories {\n    ivy {\n        url 'https://ci.md-5.net/job/'\n        patternLayout {\n//            artifact \"[organization]/versions/[module]/builds/[revision]/downloads/[organization]-[module]-[revision](.[ext])\"\n            // https://ci.md-5.net/job/BungeeCord/1636/artifact/bootstrap/target/BungeeCord.jar\n            artifact \"[module]/[revision]/artifact/bootstrap/target/BungeeCord(.[ext])\"\n        }\n        metadataSources {\n            it.artifact()\n        }\n    }\n}\n\nconfigurations {\n    shadowInclude\n}\n\ndependencies {\n    implementation 'bungee:BungeeCord:2000'\n//    implementation \"net.md-5:bungeecord-proxy:1.+\"\n//    compileOnly 'org.projectlombok:lombok:1.18.24' // for bungeecord sources\n\n    shadowInclude implementation(project(\":common\"))\n}\n\nprocessResources {\n    inputs.property \"version\", project.version\n\n    filesMatching(\"bungee.yml\") {\n        expand \"version\": project.version\n    }\n}\n\njar {\n    exclude \"META-INF/LICENSE.txt\"\n    exclude \"META-INF/NOTICE.txt\"\n    from \"LICENSE\"\n}\n\nshadowJar {\n//    dependencies {\n//        exclude(dependency('it.unimi.dsi:fastutil'))\n//    }\n    exclude \"META-INF/LICENSE.txt\"\n    exclude \"META-INF/NOTICE.txt\"\n    minimize()\n    archiveClassifier = \"all\"\n    configurations = [ project.configurations.shadowInclude ]\n    from \"LICENSE\"\n}\n\nassemble.dependsOn(shadowJar)\n\ntasks.withType(AbstractArchiveTask) {\n    preserveFileTimestamps = false\n    reproducibleFileOrder = true\n}\n\nmodrinth {\n    versionNumber = project.version + \"+bungeecord\"\n    versionName = project.version + \" devbuild for BungeeCord\"\n    uploadFile = shadowJar\n    loaders = [\"bungeecord\", \"waterfall\"]\n}\n\ntask(\"prepareRunBungee\", dependsOn: shadowJar) {\n    doFirst {\n        Files.createDirectories(rootProject.projectDir.toPath().resolve(\"run-bungee\").resolve(\"plugins\"))\n        Files.copy(shadowJar.archiveFile.getAsFile().get().toPath(), rootProject.projectDir.toPath().resolve(\"run-bungee\").resolve(\"plugins\").resolve(\"raknetify-bungee-devlaunch.jar\"), StandardCopyOption.REPLACE_EXISTING)\n    }\n}\n"
  },
  {
    "path": "bungee/src/main/java/com/ishland/raknetify/bungee/RaknetifyBungeePlugin.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.bungee;\n\nimport com.ishland.raknetify.bungee.connection.RakNetBungeeConnectionUtil;\nimport com.ishland.raknetify.bungee.init.BungeeRaknetifyServer;\nimport com.ishland.raknetify.common.data.ProtocolMultiChannelMappings;\nimport net.md_5.bungee.api.event.PostLoginEvent;\nimport net.md_5.bungee.api.event.ServerConnectedEvent;\nimport net.md_5.bungee.api.plugin.Listener;\nimport net.md_5.bungee.api.plugin.Plugin;\nimport net.md_5.bungee.event.EventHandler;\n\nimport java.util.logging.Logger;\n\npublic class RaknetifyBungeePlugin extends Plugin implements Listener {\n\n    public static Logger LOGGER;\n    public static RaknetifyBungeePlugin INSTANCE;\n\n    @Override\n    public void onEnable() {\n        super.onEnable();\n\n        INSTANCE = this;\n        LOGGER = this.getLogger();\n\n        ProtocolMultiChannelMappings.init();\n\n        BungeeRaknetifyServer.inject();\n\n        this.getProxy().getPluginManager().registerListener(this, this);\n    }\n\n    @Override\n    public void onDisable() {\n        super.onDisable();\n\n        BungeeRaknetifyServer.disable();\n    }\n\n    @EventHandler\n    public void onPostLogin(PostLoginEvent evt) {\n        RakNetBungeeConnectionUtil.onPlayerLogin(evt);\n    }\n\n    @EventHandler\n    public void handleServerSwitch(ServerConnectedEvent evt) {\n        RakNetBungeeConnectionUtil.handleServerSwitch(evt);\n    }\n\n}\n"
  },
  {
    "path": "bungee/src/main/java/com/ishland/raknetify/bungee/connection/RakNetBungeeClientChannelEventListener.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.bungee.connection;\n\nimport com.google.common.base.Preconditions;\nimport com.ishland.raknetify.bungee.RaknetifyBungeePlugin;\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.common.connection.MultiChannellingEncryption;\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.common.connection.SynchronizationLayer;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPromise;\nimport net.md_5.bungee.EncryptionUtil;\nimport net.md_5.bungee.netty.ChannelWrapper;\nimport net.md_5.bungee.netty.HandlerBoss;\nimport net.md_5.bungee.netty.PipelineUtils;\nimport net.md_5.bungee.protocol.PacketWrapper;\nimport net.md_5.bungee.protocol.Protocol;\nimport net.md_5.bungee.protocol.packet.Commands;\nimport net.md_5.bungee.protocol.packet.EncryptionResponse;\nimport net.md_5.bungee.protocol.packet.FinishConfiguration;\nimport net.md_5.bungee.protocol.packet.Login;\nimport net.md_5.bungee.protocol.packet.Respawn;\nimport net.md_5.bungee.protocol.packet.SetCompression;\nimport net.md_5.bungee.protocol.packet.StartConfiguration;\n\nimport javax.crypto.Cipher;\nimport javax.crypto.SecretKey;\nimport javax.crypto.spec.SecretKeySpec;\nimport java.lang.reflect.Field;\nimport java.security.GeneralSecurityException;\nimport java.util.logging.Level;\n\npublic class RakNetBungeeClientChannelEventListener extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-bungee-event-listener\";\n\n    private SecretKey encryptionKey = null;\n    private boolean needResetCompression = false;\n\n    private Protocol protocol = null;\n    private int protocolVersion = -1;\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        if (this.needResetCompression) {\n            RaknetifyBungeePlugin.LOGGER.info(\"Preventing vanilla compression as streaming compression is enabled\");\n\n//            // note: this may corrupt bungeecords compression state, find a better way to do this\n//            ctx.channel().pipeline().replace(\"compress\", \"compress\", new ChannelDuplexHandler()); // no-op\n//            ctx.channel().pipeline().replace(\"decompress\", \"decompress\", new ChannelDuplexHandler()); // no-op\n\n            final HandlerBoss handlerBoss = ctx.channel().pipeline().get(HandlerBoss.class);\n\n            final Field channelField = HandlerBoss.class.getDeclaredField(\"channel\");\n            channelField.setAccessible(true);\n            final ChannelWrapper channelWrapper = (ChannelWrapper) channelField.get(handlerBoss);\n            Preconditions.checkState(channelWrapper != null, \"channelWrapper is null\");\n            channelWrapper.setCompressionThreshold(-1);\n\n            this.needResetCompression = false;\n        }\n        if (this.encryptionKey != null) {\n            ctx.channel().pipeline().replace(PipelineUtils.DECRYPT_HANDLER, PipelineUtils.DECRYPT_HANDLER, new ChannelDuplexHandler());\n            ctx.channel().pipeline().replace(PipelineUtils.ENCRYPT_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new ChannelDuplexHandler());\n            ctx.channel().pipeline().addBefore(MultiChannelingStreamingCompression.NAME, MultiChannellingEncryption.NAME, new MultiChannellingEncryption(encryptionKey));\n            this.encryptionKey = null;\n        }\n        if (msg instanceof SetCompression) {\n            final MultiChannelingStreamingCompression compression = ctx.channel().pipeline().get(MultiChannelingStreamingCompression.class);\n            if (compression != null && compression.isActive()) {\n                RaknetifyBungeePlugin.LOGGER.info(\"Preventing vanilla compression as streaming compression is enabled\");\n                promise.setSuccess(); // swallow SetCompression packet\n                needResetCompression = true;\n                return;\n            }\n        } else if (msg instanceof Respawn || msg instanceof Login || msg instanceof StartConfiguration || msg instanceof FinishConfiguration) {\n            ctx.write(SynchronizationLayer.SYNC_REQUEST_OBJECT); // sync\n            super.write(ctx, msg, promise);\n            return;\n        } else if (msg instanceof Commands) {\n            ctx.write(RakNetSimpleMultiChannelCodec.SIGNAL_START_MULTICHANNEL);\n            super.write(ctx, msg, promise);\n            return;\n        }\n        super.write(ctx, msg, promise);\n    }\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof PacketWrapper wrapper) {\n            if (wrapper.packet instanceof EncryptionResponse packet) {\n                try {\n                    this.encryptionKey = getSecretUnchecked(packet);\n                } catch (Throwable t) {\n                    RaknetifyBungeePlugin.LOGGER.log(Level.WARNING, \"Failed to decrypt captured encryption secret, the raknetify connection is broken\", t);\n                }\n            }\n        }\n        super.channelRead(ctx, msg);\n    }\n\n    private static SecretKey getSecretUnchecked(EncryptionResponse resp) throws GeneralSecurityException {\n        Cipher cipher = Cipher.getInstance(\"RSA\");\n        cipher.init(Cipher.DECRYPT_MODE, EncryptionUtil.keys.getPrivate());\n        return new SecretKeySpec(cipher.doFinal(resp.getSharedSecret()), \"AES\");\n    }\n\n    public void setProtocol(Protocol protocol, int protocolVersion) {\n        this.protocol = protocol;\n        this.protocolVersion = protocolVersion;\n    }\n\n    @Override\n    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {\n        super.exceptionCaught(ctx, cause);\n        cause.printStackTrace();\n    }\n\n    //    @Override\n//    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {\n//        super.userEventTriggered(ctx, evt);\n//        if (evt == VelocityConnectionEvent.COMPRESSION_ENABLED) {\n//            final MultiChannelingStreamingCompression compression = ctx.channel().pipeline().get(MultiChannelingStreamingCompression.class);\n//            if (compression != null && compression.isActive()) {\n//                RaknetifyVelocityPlugin.LOGGER.info(\"Preventing vanilla compression as streaming compression is enabled\");\n//                ctx.channel().pipeline().replace(Connections.COMPRESSION_ENCODER, Connections.COMPRESSION_ENCODER, new ChannelDuplexHandler()); // no-op\n//                ctx.channel().pipeline().replace(Connections.COMPRESSION_DECODER, Connections.COMPRESSION_DECODER, new ChannelDuplexHandler()); // no-op\n//            }\n//        } else if (evt == VelocityConnectionEvent.COMPRESSION_DISABLED) {\n//            ctx.channel().pipeline().replace(Connections.FRAME_DECODER, Connections.FRAME_DECODER, new ChannelDuplexHandler()); // no-op\n//            ctx.channel().pipeline().replace(Connections.FRAME_ENCODER, Connections.FRAME_ENCODER, new ChannelDuplexHandler()); // no-op\n//        } else if (evt == VelocityConnectionEvent.ENCRYPTION_ENABLED) {\n//            Preconditions.checkState(this.encryptionKey != null, \"EncryptionResponse not received yet or already consumed\");\n//            ctx.channel().pipeline().replace(Connections.CIPHER_ENCODER, Connections.CIPHER_ENCODER, new ChannelDuplexHandler());\n//            ctx.channel().pipeline().replace(Connections.CIPHER_DECODER, Connections.CIPHER_DECODER, new ChannelDuplexHandler());\n//            ctx.channel().pipeline().addAfter(MultiChannelingStreamingCompression.NAME, MultiChannellingEncryption.NAME, new MultiChannellingEncryption(encryptionKey));\n//        }\n//    }\n}\n"
  },
  {
    "path": "bungee/src/main/java/com/ishland/raknetify/bungee/connection/RakNetBungeeConnectionUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.bungee.connection;\n\nimport com.ishland.raknetify.bungee.RaknetifyBungeePlugin;\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.common.connection.RakNetConnectionUtil;\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.common.connection.SynchronizationLayer;\nimport com.ishland.raknetify.common.connection.multichannel.CustomPayloadChannel;\nimport com.ishland.raknetify.common.data.ProtocolMultiChannelMappings;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.handler.codec.haproxy.HAProxyMessageDecoder;\nimport net.md_5.bungee.ServerConnection;\nimport net.md_5.bungee.UserConnection;\nimport net.md_5.bungee.api.event.PostLoginEvent;\nimport net.md_5.bungee.api.event.ServerConnectedEvent;\nimport net.md_5.bungee.netty.ChannelWrapper;\nimport net.md_5.bungee.netty.PipelineUtils;\nimport net.md_5.bungee.protocol.MinecraftEncoder;\nimport net.md_5.bungee.protocol.Protocol;\nimport net.md_5.bungee.protocol.packet.PluginMessage;\nimport network.ycc.raknet.RakNet;\n\nimport java.lang.reflect.Field;\n\nimport static com.ishland.raknetify.common.util.ReflectionUtil.accessible;\n\npublic class RakNetBungeeConnectionUtil {\n\n    private static final Field USER_CONNECTION_CH;\n    private static final Field SERVER_CONNECTION_CH;\n    private static final Field ENCODER_PROTOCOL_VERSION;\n\n    static {\n        try {\n            USER_CONNECTION_CH = accessible(UserConnection.class.getDeclaredField(\"ch\"));\n            SERVER_CONNECTION_CH = accessible(ServerConnection.class.getDeclaredField(\"ch\"));\n            ENCODER_PROTOCOL_VERSION = accessible(MinecraftEncoder.class.getDeclaredField(\"protocolVersion\"));\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n    }\n\n    private RakNetBungeeConnectionUtil() {\n    }\n\n    public static void initChannel(Channel channel) {\n        if (channel.config() instanceof RakNet.Config) {\n            RakNetConnectionUtil.initChannel(channel);\n//            channel.pipeline().addAfter(MultiChannelingStreamingCompression.NAME, MultiChannellingDataCodec.NAME, new MultiChannellingDataCodec(Constants.RAKNET_GAME_PACKET_ID));\n            channel.pipeline().addAfter(MultiChannelingStreamingCompression.NAME, RakNetSimpleMultiChannelCodec.NAME, new RakNetSimpleMultiChannelCodec(Constants.RAKNET_GAME_PACKET_ID));\n        }\n    }\n\n    public static void postInitChannel(Channel channel, boolean isClientSide) {\n        if (channel.config() instanceof RakNet.Config) {\n            channel.pipeline().replace(PipelineUtils.TIMEOUT_HANDLER, PipelineUtils.TIMEOUT_HANDLER, new ChannelDuplexHandler()); // no-op\n            channel.pipeline().replace(PipelineUtils.FRAME_DECODER, PipelineUtils.FRAME_DECODER, new ChannelDuplexHandler()); // no-op\n            channel.pipeline().addBefore(PipelineUtils.FRAME_PREPENDER_AND_COMPRESS, StripFrameHandler.NAME, StripFrameHandler.INSTANCE); // no-op\n            if (channel.pipeline().get(HAProxyMessageDecoder.class) != null)\n                channel.pipeline().remove(HAProxyMessageDecoder.class);\n//            channel.pipeline().replace(PipelineUtils.WRITE_TIMEOUT_HANDLER, PipelineUtils.WRITE_TIMEOUT_HANDLER, new DebugWriteTimeoutHandler(30));\n            channel.pipeline().addBefore(PipelineUtils.BOSS_HANDLER, RakNetBungeeClientChannelEventListener.NAME, new RakNetBungeeClientChannelEventListener());\n//            System.out.println(channel.pipeline().names());\n//            final MultiChannellingPacketCapture handler = new MultiChannellingPacketCapture();\n//            channel.pipeline().addLast(\"raknetify-multi-channel-packet-cature\", handler);\n//            channel.pipeline().get(MultiChannellingDataCodec.class).setCapture(handler);\n        }\n    }\n\n    public static void onPlayerLogin(PostLoginEvent evt) {\n        try {\n            final UserConnection player = (UserConnection) evt.getPlayer();\n            final ChannelWrapper channelWrapper = (ChannelWrapper) USER_CONNECTION_CH.get(player);\n            final Channel channel = channelWrapper.getHandle();\n            if (channel != null && channel.config() instanceof RakNet.Config config) {\n\n                // multi-channel setup\n                final RakNetSimpleMultiChannelCodec multiChannelCodec = channel.pipeline().get(RakNetSimpleMultiChannelCodec.class);\n                if (multiChannelCodec != null) {\n                    final int protocolVersion = (int) ENCODER_PROTOCOL_VERSION.get(channel.pipeline().get(MinecraftEncoder.class));\n                    final ProtocolMultiChannelMappings.VersionMapping versionMapping = ProtocolMultiChannelMappings.INSTANCE.mappings.get(protocolVersion);\n                    if (versionMapping != null) {\n\n                        // handle custom payload separately\n                        final Object directionDataToClient = accessible(Protocol.class.getDeclaredField(\"TO_CLIENT\")).get(Protocol.GAME);\n                        final int pluginMessageId = (int) accessible(Class.forName(\"net.md_5.bungee.protocol.Protocol$DirectionData\").getDeclaredMethod(\"getId\", Class.class, int.class))\n                                .invoke(directionDataToClient, PluginMessage.class, protocolVersion);\n                        if (Constants.DEBUG) RaknetifyBungeePlugin.LOGGER.info(\"PluginMessage packetId=%d at version=%d\".formatted(pluginMessageId, protocolVersion));\n                        multiChannelCodec.addHandler(new CustomPayloadChannel.OverrideHandler(value -> value == pluginMessageId));\n\n                        // packet id -> channel id\n                        multiChannelCodec.addHandler(new RakNetSimpleMultiChannelCodec.PacketIdBasedOverrideHandler(\n                                versionMapping.s2c,\n                                \"protocol version %d\".formatted(protocolVersion)\n                        ));\n                    } else {\n                        RaknetifyBungeePlugin.LOGGER.warning(\"No multi-channel mapping found for protocol version %d, reduced responsiveness is expected\"\n                                .formatted(protocolVersion));\n                    }\n                }\n\n                // ping update setup\n                channel.pipeline().addBefore(PipelineUtils.BOSS_HANDLER, RakNetBungeePingUpdater.NAME, new RakNetBungeePingUpdater(player));\n\n                RaknetifyBungeePlugin.LOGGER.info(String.format(\"Raknetify: %s logged in via RakNet, mtu %d\", player.getName(), config.getMTU()));\n            }\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n    }\n\n    public static void handleServerSwitch(ServerConnectedEvent evt) {\n        try {\n            final UserConnection player = (UserConnection) evt.getPlayer();\n            final Channel playerChannel = ((ChannelWrapper) USER_CONNECTION_CH.get(player)).getHandle();\n\n            if (playerChannel != null && playerChannel.config() instanceof RakNet.Config config) {\n                // this exists because bungeecord sends several packets to reset state before Respawn packet during server switch\n                playerChannel.write(SynchronizationLayer.SYNC_REQUEST_OBJECT);\n\n                // and inject into the server channel\n                final ServerConnection server = (ServerConnection) evt.getServer();\n                final Channel serverChannel = ((ChannelWrapper) SERVER_CONNECTION_CH.get(server)).getHandle();\n                serverChannel.pipeline().addBefore(PipelineUtils.BOSS_HANDLER, RakNetBungeeServerChannelEventListener.NAME, new RakNetBungeeServerChannelEventListener(playerChannel));\n            }\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n    }\n\n}\n"
  },
  {
    "path": "bungee/src/main/java/com/ishland/raknetify/bungee/connection/RakNetBungeePingUpdater.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.bungee.connection;\n\nimport com.google.common.base.Preconditions;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.util.concurrent.ScheduledFuture;\nimport net.md_5.bungee.UserConnection;\nimport net.md_5.bungee.api.connection.ProxiedPlayer;\nimport network.ycc.raknet.RakNet;\nimport network.ycc.raknet.packet.Ping;\n\nimport java.util.Objects;\nimport java.util.concurrent.TimeUnit;\n\npublic class RakNetBungeePingUpdater extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-bungee-ping-updater\";\n\n    private final UserConnection player;\n\n    ScheduledFuture<?> updateTask = null;\n\n    public RakNetBungeePingUpdater(UserConnection player) {\n        this.player = Objects.requireNonNull(player);\n    }\n\n    public void handlerAdded(ChannelHandlerContext ctx) {\n        if (ctx.channel().config() instanceof RakNet.Config config) {\n            updateTask = ctx.channel().eventLoop().scheduleAtFixedRate(\n                    () -> player.setPing((int) ((config.getRTTNanos() + config.getRTTStdDevNanos()) / 1_000_000)),\n                    0, 1000, TimeUnit.MILLISECONDS\n            );\n        }\n    }\n\n    public void handlerRemoved(ChannelHandlerContext ctx) {\n        if (updateTask != null) {\n            updateTask.cancel(false);\n            updateTask = null;\n        }\n    }\n\n}\n"
  },
  {
    "path": "bungee/src/main/java/com/ishland/raknetify/bungee/connection/RakNetBungeeServerChannelEventListener.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.bungee.connection;\n\nimport com.google.common.base.Preconditions;\nimport com.ishland.raknetify.bungee.RaknetifyBungeePlugin;\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.SynchronizationLayer;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport net.md_5.bungee.api.ProxyServer;\nimport net.md_5.bungee.protocol.DefinedPacket;\nimport net.md_5.bungee.protocol.PacketWrapper;\nimport net.md_5.bungee.protocol.packet.KeepAlive;\nimport net.md_5.bungee.protocol.packet.Respawn;\nimport network.ycc.raknet.RakNet;\n\nimport java.util.Map;\nimport java.util.concurrent.TimeUnit;\n\npublic class RakNetBungeeServerChannelEventListener extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-bungee-downstream-event-listener\";\n\n    private final Channel clientChannel;\n\n    public RakNetBungeeServerChannelEventListener(Channel clientChannel) {\n        Preconditions.checkArgument(clientChannel.config() instanceof RakNet.Config);\n        this.clientChannel = clientChannel;\n    }\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof PacketWrapper wrapper) {\n            final DefinedPacket packet = wrapper.packet;\n            if (packet instanceof Respawn) {\n                clientChannel.write(SynchronizationLayer.SYNC_REQUEST_OBJECT);\n            } else if (packet instanceof KeepAlive) {\n                if (Constants.DEBUG) RaknetifyBungeePlugin.LOGGER.info(\"Received downstream keepalive, swallowing it\");\n                final long rttNanos = RakNet.config(clientChannel).getRTTNanos();\n//                ProxyServer.getInstance().getScheduler()\n//                        .schedule(RaknetifyBungeePlugin.INSTANCE, () -> ctx.write(packet), Math.max(rttNanos - 4_000_000, 0), TimeUnit.NANOSECONDS); // reduce delay to aid scheduling overhead\n                ctx.channel().eventLoop().schedule(() -> ctx.writeAndFlush(packet), Math.max(rttNanos - 4_000_000, 0), TimeUnit.NANOSECONDS); // reduce delay to aid scheduling overhead\n                return; // prevent keepalive from being sent to clients\n            }\n        }\n        super.channelRead(ctx, msg);\n    }\n\n    @Override\n    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {\n        super.exceptionCaught(ctx, cause);\n        cause.printStackTrace();\n        for (Map.Entry<String, ChannelHandler> entry : ctx.channel().pipeline().toMap().entrySet()) {\n            System.out.println(\"%s: %s\".formatted(entry.getKey(), entry.getValue().getClass().getName()));\n        }\n    }\n}\n"
  },
  {
    "path": "bungee/src/main/java/com/ishland/raknetify/bungee/connection/StripFrameHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.bungee.connection;\n\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelOutboundHandlerAdapter;\nimport io.netty.channel.ChannelPromise;\nimport net.md_5.bungee.protocol.DefinedPacket;\n\n@ChannelHandler.Sharable\npublic class StripFrameHandler extends ChannelOutboundHandlerAdapter {\n\n    public static final String NAME = \"raknetify-bungee-strip-frame\";\n\n    public static final StripFrameHandler INSTANCE = new StripFrameHandler();\n\n    private StripFrameHandler() {\n    }\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        if (msg instanceof ByteBuf buf) {\n            DefinedPacket.readVarInt(buf);\n            ctx.write(buf.slice(), promise);\n            return;\n        }\n        super.write(ctx, msg, promise);\n    }\n\n}\n"
  },
  {
    "path": "bungee/src/main/java/com/ishland/raknetify/bungee/init/BungeeRaknetifyServer.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.bungee.init;\n\nimport com.ishland.raknetify.bungee.RaknetifyBungeePlugin;\nimport com.ishland.raknetify.bungee.connection.RakNetBungeeConnectionUtil;\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.RakNetConnectionUtil;\nimport com.ishland.raknetify.common.util.NetworkInterfaceListener;\nimport io.netty.bootstrap.ServerBootstrap;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelFuture;\nimport io.netty.channel.ChannelHandler;\nimport io.netty.channel.ChannelInitializer;\nimport io.netty.channel.ChannelOption;\nimport io.netty.channel.EventLoopGroup;\nimport io.netty.channel.FixedRecvByteBufAllocator;\nimport io.netty.channel.ReflectiveChannelFactory;\nimport io.netty.channel.socket.DatagramChannel;\nimport io.netty.util.AttributeKey;\nimport it.unimi.dsi.fastutil.objects.ObjectIterator;\nimport it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;\nimport it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;\nimport net.md_5.bungee.BungeeCord;\nimport net.md_5.bungee.api.ProxyServer;\nimport net.md_5.bungee.api.config.ListenerInfo;\nimport net.md_5.bungee.netty.PipelineUtils;\nimport net.md_5.bungee.query.QueryHandler;\nimport network.ycc.raknet.server.channel.RakNetServerChannel;\n\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Method;\nimport java.net.InetAddress;\nimport java.net.InetSocketAddress;\nimport java.net.NetworkInterface;\nimport java.util.ArrayList;\nimport java.util.Collection;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.concurrent.TimeUnit;\nimport java.util.function.Consumer;\nimport java.util.logging.Level;\nimport java.util.stream.Stream;\n\nimport static com.ishland.raknetify.common.util.ReflectionUtil.accessible;\n\npublic class BungeeRaknetifyServer {\n\n    private static final int portOverride = Integer.getInteger(\"raknetify.bungee.portOverride\", -1);\n\n    private static final Method INIT_CHANNEL;\n    private static final Field BUNGEE_LISTENERS_FIELD;\n\n    private static final Class<?> ACCEPTOR_CLASS;\n\n    static {\n        try {\n            INIT_CHANNEL = accessible(ChannelInitializer.class.getDeclaredMethod(\"initChannel\", Channel.class));\n            BUNGEE_LISTENERS_FIELD = accessible(BungeeCord.class.getDeclaredField(\"listeners\"));\n            ACCEPTOR_CLASS = Class.forName(\"io.netty.bootstrap.ServerBootstrap$ServerBootstrapAcceptor\");\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n    }\n\n    private static final Reference2ReferenceOpenHashMap<Channel, ReferenceOpenHashSet<ChannelFuture>> channels = new Reference2ReferenceOpenHashMap<>();\n    private static final ReferenceOpenHashSet<ChannelFuture> nonWildcardChannels = new ReferenceOpenHashSet<>();\n\n    private static volatile boolean active = false;\n    private static volatile int activeIndex = 0;\n    private static boolean injected = false;\n\n    private static volatile Consumer<NetworkInterfaceListener.InterfaceAddressChangeEvent> listener = null;\n\n    public static void inject() {\n        if (active) return;\n        try {\n            active = true;\n            final BungeeCord instance = (BungeeCord) ProxyServer.getInstance();\n\n//            stopAllQueryPorts();\n\n            final Set<Channel> listeners = (Set<Channel>) BUNGEE_LISTENERS_FIELD.get(instance);\n\n            if (!injected) {\n                BUNGEE_LISTENERS_FIELD.set(instance, new InjectedSet(listeners));\n                injected = true;\n            }\n\n            List<Throwable> errors = new ArrayList<>();\n\n            for (Channel listener : listeners) {\n                try {\n                    injectChannel(instance, listener, true);\n                } catch (Throwable t) {\n                    errors.add(t);\n                }\n            }\n\n            int currentActiveIndex = ++activeIndex;\n            listener = event -> {\n                if (!active) {\n                    NetworkInterfaceListener.removeListener(listener);\n                }\n\n                if (currentActiveIndex != activeIndex) return; // we can't remove ourselves now, is plugin reloaded?\n\n                if (event.added()) {\n                    for (Channel channel : channels.keySet()) {\n                        injectChannel(instance, channel, false);\n                    }\n                } else {\n                    for (ReferenceOpenHashSet<ChannelFuture> futures : channels.values()) {\n                        for (ObjectIterator<ChannelFuture> iterator = futures.iterator(); iterator.hasNext(); ) {\n                            ChannelFuture future = iterator.next();\n                            if (((InetSocketAddress) future.channel().localAddress()).getAddress().equals(event.address())) {\n                                RaknetifyBungeePlugin.LOGGER.info(\"Closing Raknetify server %s\".formatted(future.channel().localAddress()));\n                                future.channel().close();\n                                iterator.remove();\n                            }\n                        }\n                    }\n                }\n            };\n            NetworkInterfaceListener.addListener(event ->\n                    instance.getScheduler().schedule(RaknetifyBungeePlugin.INSTANCE, () -> listener.accept(event), 100, TimeUnit.MILLISECONDS));\n\n            if (!errors.isEmpty()) {\n                final RuntimeException exception = new RuntimeException(\"Failed to start Raknetify server\");\n                errors.forEach(exception::addSuppressed);\n                throw exception;\n            }\n        } catch (Throwable t) {\n            throw new RuntimeException(\"Failed to start Raknetify server\", t);\n        }\n    }\n\n    public static void injectChannel(BungeeCord instance, Channel listener, boolean throwErrors) {\n        try {\n            if (!active) return;\n\n            final boolean hasPortOverride = portOverride > 0 && portOverride < 65535;\n            if (hasPortOverride && !channels.isEmpty()) return; // avoid duplicate listeners\n\n            if (!(listener.localAddress() instanceof InetSocketAddress)) return;\n\n            ChannelInitializer<Channel> initializer = null;\n            ListenerInfo info = null;\n\n            for (String name : listener.pipeline().names()) {\n                final ChannelHandler handler = listener.pipeline().get(name);\n                if (handler instanceof QueryHandler) {\n                    return;\n                }\n                if (handler != null && ACCEPTOR_CLASS.isAssignableFrom(handler.getClass())) {\n                    try {\n                        initializer = (ChannelInitializer<Channel>) accessible(ACCEPTOR_CLASS.getDeclaredField(\"childHandler\")).get(handler);\n                        final Map.Entry<AttributeKey<?>, ?>[] attrs = (Map.Entry<AttributeKey<?>, ?>[])\n                                accessible(ACCEPTOR_CLASS.getDeclaredField(\"childAttrs\")).get(handler);\n                        for (var attr : attrs) {\n                            if (attr.getKey() == PipelineUtils.LISTENER) {\n                                info = (ListenerInfo) attr.getValue();\n                            }\n                        }\n                    } catch (IllegalAccessException | NoSuchFieldException e) {\n                        throw new RuntimeException(e);\n                    }\n                }\n            }\n\n            if (initializer == null) {\n                RaknetifyBungeePlugin.LOGGER.severe(\"Unable to find channel initializer for listener %s\".formatted(listener));\n                return;\n            }\n\n            if (info == null) {\n                RaknetifyBungeePlugin.LOGGER.severe(\"Unable to find listener info for listener %s\".formatted(listener));\n                return;\n            }\n\n            if (listener.getClass().getName().startsWith(\"org.geysermc.geyser.network\")) { // filter out geyser\n                return;\n            }\n\n            if (((InetSocketAddress) info.getSocketAddress()).getAddress().isAnyLocalAddress()) {\n                for (NetworkInterface networkInterface : NetworkInterface.networkInterfaces().toList()) {\n                    final Iterator<InetAddress> iterator = networkInterface.getInetAddresses().asIterator();\n                    while (iterator.hasNext()) {\n                        final InetAddress address = iterator.next();\n                        try {\n                            startServer(instance, listener, initializer, info, address);\n                        } catch (Throwable t) {\n                            RaknetifyBungeePlugin.LOGGER.log(Level.SEVERE, \"Failed to start Raknetify server\", t);\n                        }\n                    }\n                }\n            } else {\n                startServer(instance, listener, initializer, info, null);\n            }\n\n        } catch (Throwable t) {\n            if (throwErrors) throw new RuntimeException(\"Failed to start Raknetify server\", t);\n            else RaknetifyBungeePlugin.LOGGER.log(Level.SEVERE, \"Failed to start Raknetify server\", t);\n        }\n    }\n\n    private static void startServer(BungeeCord instance, Channel listener, ChannelInitializer<Channel> initializer, ListenerInfo info, InetAddress address) throws NoSuchFieldException, IllegalAccessException {\n        if (address != null) {\n            final ReferenceOpenHashSet<ChannelFuture> futures = channels.get(listener);\n            if (futures != null) {\n                for (ChannelFuture future : futures) {\n                    if (((InetSocketAddress) future.channel().localAddress()).getAddress().equals(address))\n                        return; // avoid duplicate\n                }\n            }\n        }\n\n        final boolean hasPortOverride = portOverride > 0 && portOverride < 65535;\n        final ReflectiveChannelFactory<? extends DatagramChannel> factory = new ReflectiveChannelFactory<>(PipelineUtils.getDatagramChannel());\n        final InetAddress actualAddress = address == null ? ((InetSocketAddress) info.getSocketAddress()).getAddress() : address;\n        final ChannelFuture future = new ServerBootstrap()\n                .channelFactory(() -> new RakNetServerChannel(() -> {\n                    final DatagramChannel channel = factory.newChannel();\n                    channel.config().setOption(ChannelOption.IP_TOS, RakNetConnectionUtil.DEFAULT_IP_TOS);\n                    channel.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(Constants.LARGE_MTU + 512).maxMessagesPerRead(128));\n                    return channel;\n                }))\n                .option(ChannelOption.SO_REUSEADDR, true)\n                .childAttr(PipelineUtils.LISTENER, info)\n                .childHandler(new ChannelInitializer<>() {\n                    @Override\n                    protected void initChannel(Channel channel) throws Exception {\n                        RakNetBungeeConnectionUtil.initChannel(channel);\n                        INIT_CHANNEL.invoke(initializer, channel);\n                        RakNetBungeeConnectionUtil.postInitChannel(channel, false);\n                    }\n                })\n                .group(getBossEventLoopGroup(instance), getWorkerEventLoopGroup(instance))\n                .localAddress(hasPortOverride ? new InetSocketAddress(actualAddress, portOverride) : new InetSocketAddress(actualAddress, ((InetSocketAddress) info.getSocketAddress()).getPort()))\n                .bind()\n                .syncUninterruptibly();\n        if (address == null) {\n            nonWildcardChannels.add(future);\n        } else {\n            channels.computeIfAbsent(listener, unused -> new ReferenceOpenHashSet<>()).add(future);\n        }\n\n        RaknetifyBungeePlugin.LOGGER.info(\"Raknetify server started on %s\".formatted(future.channel().localAddress()));\n    }\n\n    public static void stopAll() {\n        if (!active) return;\n        for (ChannelFuture future : Stream.concat(channels.values().stream().flatMap(Collection::stream), nonWildcardChannels.stream()).toList()) {\n            RaknetifyBungeePlugin.LOGGER.info(\"Closing Raknetify server %s\".formatted(future.channel().localAddress()));\n            try {\n                future.channel().close().sync();\n            } catch (InterruptedException e) {\n                RaknetifyBungeePlugin.LOGGER.severe(\"Interrupted whilst closing raknetify server\");\n            }\n        }\n\n        channels.clear();\n        nonWildcardChannels.clear();\n    }\n\n    public static void disable() {\n        if (!active) return;\n        stopAll();\n        active = false;\n    }\n\n    private static EventLoopGroup getBossEventLoopGroup(BungeeCord instance) throws NoSuchFieldException, IllegalAccessException {\n        try {\n            return (EventLoopGroup) accessible(BungeeCord.class.getDeclaredField(\"eventLoops\")).get(instance);\n        } catch (NoSuchFieldException e) { // waterfall: use split boss and worker group\n            //noinspection JavaReflectionMemberAccess\n            return (EventLoopGroup) accessible(BungeeCord.class.getDeclaredField(\"bossEventLoopGroup\")).get(instance);\n        }\n    }\n\n    private static EventLoopGroup getWorkerEventLoopGroup(BungeeCord instance) throws NoSuchFieldException, IllegalAccessException {\n        try {\n            return (EventLoopGroup) accessible(BungeeCord.class.getDeclaredField(\"eventLoops\")).get(instance);\n        } catch (NoSuchFieldException e) { // waterfall: use split boss and worker group\n            //noinspection JavaReflectionMemberAccess\n            return (EventLoopGroup) accessible(BungeeCord.class.getDeclaredField(\"workerEventLoopGroup\")).get(instance);\n        }\n    }\n\n}\n"
  },
  {
    "path": "bungee/src/main/java/com/ishland/raknetify/bungee/init/InjectedSet.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.bungee.init;\n\nimport com.google.common.collect.ForwardingSet;\nimport com.ishland.raknetify.bungee.RaknetifyBungeePlugin;\nimport io.netty.channel.Channel;\nimport net.md_5.bungee.BungeeCord;\nimport net.md_5.bungee.api.ProxyServer;\n\nimport java.util.Set;\nimport java.util.concurrent.TimeUnit;\n\npublic class InjectedSet extends ForwardingSet<Channel> {\n\n    private final Set<Channel> delegate;\n\n    public InjectedSet(Set<Channel> delegate) {\n        this.delegate = delegate;\n    }\n\n    @Override\n    public boolean add(Channel element) {\n        ProxyServer.getInstance().getScheduler().schedule(\n                RaknetifyBungeePlugin.INSTANCE,\n                () -> BungeeRaknetifyServer.injectChannel((BungeeCord) ProxyServer.getInstance(), element, false),\n                100, TimeUnit.MILLISECONDS);\n\n        return super.add(element);\n    }\n\n    @Override\n    public void clear() {\n        BungeeRaknetifyServer.stopAll();\n\n        super.clear();\n    }\n\n    @Override\n    protected Set<Channel> delegate() {\n        return this.delegate;\n    }\n}\n"
  },
  {
    "path": "bungee/src/main/resources/bungee.yml",
    "content": "#\n# This file is a part of the Raknetify project, licensed under MIT.\n#\n# Copyright (c) 2022-2025 ishland\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n# THE SOFTWARE.\n#\n\nname: raknetify\nmain: com.ishland.raknetify.bungee.RaknetifyBungeePlugin\nversion: ${version}\nauthor: ishland\nsoftDepends:\n  - ViaVersion\n"
  },
  {
    "path": "common/build.gradle",
    "content": "dependencies {\n    api(\"com.github.RelativityMC.netty-raknet:netty-raknet-common\") {\n        transitive = false\n    }\n    api(\"com.github.RelativityMC.netty-raknet:netty-raknet-client\")\n    api(\"com.github.RelativityMC.netty-raknet:netty-raknet-server\")\n    api(\"org.apache.commons:commons-math3:3.6.1\")\n\n    //noinspection GradlePackageUpdate\n    compileOnly(\"io.netty:netty-all:4.1.25.Final\")\n\n    compileOnly(\"com.google.code.gson:gson:2.9.0\")\n    compileOnly(\"com.google.guava:guava:31.1-jre\")\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/Constants.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common;\n\npublic class Constants {\n\n    public static final boolean DEBUG = Boolean.getBoolean(\"raknetify.debug\");\n\n    public static final String RAKNET_PREFIX = \"raknet;\";\n    public static final String RAKNET_LARGE_MTU_PREFIX = \"raknetl;\";\n    public static final int RAKNET_PING_PACKET_ID = 0xFA;\n    public static final int RAKNET_GAME_PACKET_ID = 0xFD;\n    public static final int RAKNET_STREAMING_COMPRESSION_PACKET_ID = 0xED;\n    public static final int RAKNET_STREAMING_COMPRESSION_HANDSHAKE_PACKET_ID = 0xEC;\n    public static final int RAKNET_SYNC_PACKET_ID = 0xFC;\n    public static final int RAKNET_METRICS_SYNC_PACKET_ID = 0xFB;\n    public static final int MAX_QUEUED_SIZE = 256 * 1024 * 1024;\n    public static final int DEFAULT_MTU = 1400;\n    public static final int LARGE_MTU = 8192;\n    public static final int MAX_PENDING_FRAME_SETS = 512;\n    public static final int DEFAULT_PENDING_FRAME_SETS = 4;\n    public static final int[] SYNC_IGNORE_CHANNELS = new int[] {1};\n\n    private Constants() {\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/ByteBufCopyDecoder.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelInboundHandlerAdapter;\n\npublic class ByteBufCopyDecoder extends ChannelInboundHandlerAdapter {\n\n    public static final String NAME = \"raknetify-byte-buf-copy-decoder\";\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof ByteBuf buf && !buf.hasMemoryAddress()) {\n            ctx.fireChannelRead(ctx.alloc().directBuffer(buf.readableBytes()).writeBytes(buf));\n            buf.release();\n            return;\n        }\n        super.channelRead(ctx, msg);\n    }\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/FrameDataBlocker.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelInboundHandlerAdapter;\nimport network.ycc.raknet.frame.FrameData;\n\npublic class FrameDataBlocker extends ChannelInboundHandlerAdapter {\n\n    private static final boolean printBlockedFrames = Boolean.getBoolean(\"raknetify.printBlockedFrames\");\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof FrameData data) {\n            if (printBlockedFrames) System.out.println(\"Blocked %s\".formatted(msg));\n            data.release();\n            return;\n        }\n        ctx.fireChannelRead(msg);\n    }\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/MetricsSynchronizationHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport com.ishland.raknetify.common.Constants;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.util.concurrent.ScheduledFuture;\nimport network.ycc.raknet.RakNet;\nimport network.ycc.raknet.frame.FrameData;\nimport network.ycc.raknet.packet.FramedPacket;\n\nimport java.util.concurrent.TimeUnit;\n\npublic class MetricsSynchronizationHandler extends ChannelDuplexHandler {\n\n    // Packet format:\n    // byte: version (currently 0x00)\n    // long: packet sent time (used to filter out old packets)\n    // int: buffer size in bytes\n    // int: burst size\n    // double: error rate\n    // int: tx\n    // int: rx\n\n    private static final byte VERSION = 0x00;\n\n    private ScheduledFuture<?> future;\n    private ChannelHandlerContext ctx;\n\n    @Override\n    public void handlerAdded(ChannelHandlerContext ctx) {\n        this.ctx = ctx;\n        this.future = ctx.channel().eventLoop().scheduleAtFixedRate(this::sendSyncPacket, 200, 200, TimeUnit.MILLISECONDS);\n    }\n\n    @Override\n    public void handlerRemoved(ChannelHandlerContext ctx) {\n        if (future != null) future.cancel(false);\n    }\n\n    private void sendSyncPacket() {\n        if (this.ctx.channel().config() instanceof RakNet.Config config && config.getMetrics() instanceof SimpleMetricsLogger logger){\n            ByteBuf buffer = null;\n           try {\n               buffer = this.ctx.alloc().buffer(1 + 8 + 4 + 4 + 8 + 4 + 4);\n               buffer.writeByte(VERSION);\n               buffer.writeLong(System.currentTimeMillis());\n               buffer.writeInt(logger.getCurrentQueuedBytes());\n               buffer.writeInt((int) (logger.getMeasureBurstTokens() + config.getDefaultPendingFrameSets()));\n               buffer.writeDouble(logger.getMeasureErrorRate());\n               buffer.writeInt(logger.getMeasureTX());\n               buffer.writeInt(logger.getMeasureRX());\n               final FrameData frameData = FrameData.create(this.ctx.alloc(), Constants.RAKNET_METRICS_SYNC_PACKET_ID, buffer);\n               frameData.setReliability(FramedPacket.Reliability.UNRELIABLE);\n               this.ctx.write(frameData);\n           } finally {\n               if (buffer != null) buffer.release();\n           }\n        }\n    }\n\n    private boolean isRemoteSupported = false;\n    private long lastRecv = 0L;\n    private int queuedBytes;\n    private int burst;\n    private double errorRate;\n    private int tx;\n    private int rx;\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof FrameData frameData && frameData.getDataSize() > 0 && frameData.getPacketId() == Constants.RAKNET_METRICS_SYNC_PACKET_ID) {\n            ByteBuf byteBuf = null;\n            try {\n                byteBuf = frameData.createData().skipBytes(1);\n                final byte version = byteBuf.readByte();\n                if (version != VERSION) return;\n\n                final long time = byteBuf.readLong();\n                if (time < this.lastRecv) return;\n                this.lastRecv = time;\n\n                this.isRemoteSupported = true;\n\n                this.queuedBytes = byteBuf.readInt();\n                this.burst = byteBuf.readInt();\n                this.errorRate = byteBuf.readDouble();\n                this.tx = byteBuf.readInt();\n                this.rx = byteBuf.readInt();\n            } finally {\n                if (byteBuf != null) byteBuf.release();\n                frameData.release();\n            }\n            return;\n        }\n        super.channelRead(ctx, msg);\n    }\n\n    public boolean isRemoteSupported() {\n        return this.isRemoteSupported;\n    }\n\n    public int getQueuedBytes() {\n        return queuedBytes;\n    }\n\n    public int getBurst() {\n        return burst;\n    }\n\n    public double getErrorRate() {\n        return errorRate;\n    }\n\n    public int getTX() {\n        return tx;\n    }\n\n    public int getRX() {\n        return rx;\n    }\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/MultiChannelingStreamingCompression.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport com.ishland.raknetify.common.Constants;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPromise;\nimport it.unimi.dsi.fastutil.ints.IntOpenHashSet;\nimport network.ycc.raknet.frame.FrameData;\nimport org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;\n\nimport java.util.concurrent.ScheduledFuture;\nimport java.util.concurrent.TimeUnit;\nimport java.util.zip.Deflater;\nimport java.util.zip.Inflater;\n\npublic class MultiChannelingStreamingCompression extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-multichannel-streaming-compression\";\n\n    public static final long SERVER_HANDSHAKE = 0x40000010;\n    public static final long CHANNEL_START = 0x40000012;\n    private final Inflater[] inflaters = new Inflater[8];\n    private final Deflater[] deflaters = new Deflater[8];\n\n    private final IntOpenHashSet channelsToIgnoreWhenReinit = new IntOpenHashSet();\n\n    private final byte[] inflateBuffer = new byte[256 * 1024];\n    private final byte[] deflateBuffer = new byte[256 * 1024];\n\n    private final int rawPacketId;\n    private final int compressedPacketId;\n\n    private volatile long outBytesRaw = 0L;\n    private volatile long outBytesCompressed = 0L;\n    private volatile long inBytesCompressed = 0L;\n    private volatile long inBytesRaw = 0L;\n\n    private boolean active = false;\n\n    public MultiChannelingStreamingCompression(int rawPacketId, int compressedPacketId) {\n        this.rawPacketId = rawPacketId;\n        this.compressedPacketId = compressedPacketId;\n    }\n\n    private void doServerHandshake(ChannelHandlerContext ctx) {\n        final ByteBuf buf = ctx.alloc().buffer().writeLong(SERVER_HANDSHAKE);\n        try {\n            final FrameData data = FrameData.create(ctx.alloc(), Constants.RAKNET_STREAMING_COMPRESSION_HANDSHAKE_PACKET_ID,\n                    buf);\n            ctx.write(data);\n        } finally {\n            buf.release();\n        }\n    }\n\n    private void doChannelStart(ChannelHandlerContext ctx) {\n        if (!active) return;\n        ByteBuf buf = ctx.alloc().buffer().writeLong(CHANNEL_START);\n        try {\n            for (int i = 0; i < 8; i++) {\n                final FrameData data = FrameData.create(ctx.alloc(), Constants.RAKNET_STREAMING_COMPRESSION_HANDSHAKE_PACKET_ID,\n                        buf);\n                data.setOrderChannel(i);\n                ctx.write(data);\n                initDeflater(i);\n            }\n        } finally {\n            buf.release();\n        }\n    }\n\n    private void initDeflater(int channel) {\n        if (!active) return;\n        if (deflaters[channel] != null) deflaters[channel].end();\n        deflaters[channel] = new Deflater();\n        if (Constants.DEBUG) System.out.println(\"Raknetify: Streaming compression deflater for ch%d is ready\".formatted(channel));\n    }\n\n    private void initInflater(int channel) {\n        if (!active) return;\n        if (inflaters[channel] != null) inflaters[channel].end();\n        inflaters[channel] = new Inflater();\n        if (Constants.DEBUG) System.out.println(\"Raknetify: Streaming compression inflater for ch%d is ready\".formatted(channel));\n    }\n\n    @Override\n    public void channelActive(ChannelHandlerContext ctx) throws Exception {\n        super.channelActive(ctx);\n        doServerHandshake(ctx);\n    }\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof FrameData compressedFrameData) {\n            compressedFrameData.touch();\n            if (compressedFrameData.getPacketId() == Constants.RAKNET_STREAMING_COMPRESSION_HANDSHAKE_PACKET_ID) {\n                final int orderChannel = compressedFrameData.getOrderChannel();\n                ByteBuf payload = null;\n                try {\n                    payload = compressedFrameData.createData().skipBytes(1);\n                    if (payload.readableBytes() == 8) {\n                        final long l = payload.readLong();\n                        if (l == CHANNEL_START) {\n                            initInflater(orderChannel);\n                            return;\n                        } else if (l == SERVER_HANDSHAKE) {\n                            active = true;\n                            doChannelStart(ctx);\n                            return;\n                        }\n                    }\n                } finally {\n                    compressedFrameData.release();\n                    if (payload != null) payload.release();\n                }\n            } else if (compressedFrameData.getPacketId() == compressedPacketId && compressedFrameData.getReliability().isReliable && compressedFrameData.getReliability().isOrdered && !compressedFrameData.getReliability().isSequenced && inflaters[compressedFrameData.getOrderChannel()] != null) {\n                final int orderChannel = compressedFrameData.getOrderChannel();\n                final Inflater inflater = inflaters[orderChannel];\n                final ByteBuf data = compressedFrameData.createData().skipBytes(1);\n\n                ByteBuf out = null;\n                FrameData rawFrameData = null;\n                try {\n                    inflater.setInput(data.nioBuffer());\n\n                    inBytesCompressed += data.readableBytes();\n\n                    out = ctx.alloc().buffer();\n                    {\n                        int inflatedBytes;\n                        while ((inflatedBytes = inflater.inflate(inflateBuffer)) != 0) {\n                            out.writeBytes(inflateBuffer, 0, inflatedBytes);\n                        }\n                    }\n\n                    inBytesRaw += out.writerIndex();\n\n                    rawFrameData = FrameData.create(ctx.alloc(), rawPacketId, out);\n                    rawFrameData.setReliability(compressedFrameData.getReliability());\n                    rawFrameData.setOrderChannel(orderChannel);\n                    ctx.fireChannelRead(rawFrameData);\n                    rawFrameData = null;\n                    return;\n                } finally {\n                    data.release();\n                    compressedFrameData.release();\n                    if (out != null) out.release();\n                    if (rawFrameData != null) rawFrameData.release();\n                }\n            }\n        }\n        super.channelRead(ctx, msg);\n    }\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        if (msg == SynchronizationLayer.SYNC_REQUEST_OBJECT) {\n            super.write(ctx, msg, promise);\n            doChannelStart(ctx);\n            return;\n        } else if (msg instanceof FrameData rawFrameData) {\n            rawFrameData.touch();\n            if (rawFrameData.getPacketId() == rawPacketId && rawFrameData.getReliability().isReliable && rawFrameData.getReliability().isOrdered && !rawFrameData.getReliability().isSequenced && deflaters[rawFrameData.getOrderChannel()] != null) {\n                if (rawFrameData.getDataSize() < 16 + 1) {\n                    outBytesRaw += rawFrameData.getDataSize() - 1;\n                    outBytesCompressed += rawFrameData.getDataSize() - 1;\n                    ctx.write(rawFrameData, promise);\n                    return;\n                }\n\n                final int orderChannel = rawFrameData.getOrderChannel();\n                final Deflater deflater = deflaters[orderChannel];\n                final ByteBuf data = rawFrameData.createData().skipBytes(1);\n\n                ByteBuf out = null;\n                FrameData compressedFrameData = null;\n                try {\n                    deflater.setInput(data.nioBuffer());\n\n                    outBytesRaw += data.readableBytes();\n\n                    out = ctx.alloc().buffer();\n                    {\n                        int deflatedBytes;\n                        while ((deflatedBytes = deflater.deflate(deflateBuffer, 0, deflateBuffer.length, Deflater.SYNC_FLUSH)) != 0) {\n                            out.writeBytes(deflateBuffer, 0, deflatedBytes);\n                        }\n                    }\n\n                    outBytesCompressed += out.writerIndex();\n\n                    compressedFrameData = FrameData.create(ctx.alloc(), compressedPacketId, out);\n                    compressedFrameData.setReliability(rawFrameData.getReliability());\n                    compressedFrameData.setOrderChannel(orderChannel);\n                    ctx.write(compressedFrameData, promise);\n                    compressedFrameData = null;\n                    return;\n                } finally {\n                    data.release();\n                    rawFrameData.release();\n                    if (out != null) out.release();\n                    if (compressedFrameData != null) compressedFrameData.release();\n                }\n            }\n        }\n        super.write(ctx, msg, promise);\n    }\n\n    public long getInBytesCompressed() {\n        return inBytesCompressed;\n    }\n\n    public long getInBytesRaw() {\n        return inBytesRaw;\n    }\n\n    public long getOutBytesCompressed() {\n        return outBytesCompressed;\n    }\n\n    public long getOutBytesRaw() {\n        return outBytesRaw;\n    }\n\n    public boolean isActive() {\n        return active;\n    }\n\n    private ScheduledFuture<?> future;\n\n    public void handlerAdded(ChannelHandlerContext ctx) {\n        this.future = ctx.channel().eventLoop().scheduleAtFixedRate(this::tickMetrics, 1000, 1000, TimeUnit.MILLISECONDS);\n    }\n\n    @Override\n    public void handlerRemoved(ChannelHandlerContext ctx) {\n        if (future != null) future.cancel(false);\n        for (int i = 0; i < 8; i++) {\n            if (inflaters[i] != null) inflaters[i].end();\n            if (deflaters[i] != null) deflaters[i].end();\n        }\n    }\n\n    private long lastInBytesCompressed;\n    private long lastInBytesRaw;\n    private long lastOutBytesRaw;\n    private long lastOutBytesCompressed;\n    private final DescriptiveStatistics inCompressionRatioStats = new DescriptiveStatistics(16);\n    private final DescriptiveStatistics outCompressionRatioStats = new DescriptiveStatistics(16);\n    private volatile double inCompressionRatio;\n    private volatile double outCompressionRatio;\n\n    private void tickMetrics() {\n        long deltaInBytesCompressed = this.inBytesCompressed - this.lastInBytesCompressed;\n        long deltaInBytesRaw = this.inBytesRaw - this.lastInBytesRaw;\n        long deltaOutBytesCompressed = this.outBytesCompressed - this.lastOutBytesCompressed;\n        long deltaOutBytesRaw = this.outBytesRaw - this.lastOutBytesRaw;\n\n        if (deltaInBytesRaw != 0) {\n            double currentInCompressionRatio = deltaInBytesCompressed / (double) deltaInBytesRaw;\n            inCompressionRatioStats.addValue(currentInCompressionRatio);\n        }\n\n        if (deltaOutBytesRaw != 0) {\n            double currentOutCompressionRatio = deltaOutBytesCompressed / (double) deltaOutBytesRaw;\n            outCompressionRatioStats.addValue(currentOutCompressionRatio);\n        }\n\n        this.inCompressionRatio = inCompressionRatioStats.getMean();\n        this.outCompressionRatio = outCompressionRatioStats.getMean();\n\n        this.lastInBytesCompressed = this.inBytesCompressed;\n        this.lastInBytesRaw = this.inBytesRaw;\n        this.lastOutBytesCompressed = this.outBytesCompressed;\n        this.lastOutBytesRaw = this.outBytesRaw;\n\n\n    }\n\n    public double getInCompressionRatio() {\n        return inCompressionRatio;\n    }\n\n    public double getOutCompressionRatio() {\n        return outCompressionRatio;\n    }\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/MultiChannellingEncryption.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPromise;\nimport network.ycc.raknet.frame.FrameData;\n\nimport javax.crypto.Cipher;\nimport javax.crypto.SecretKey;\nimport javax.crypto.spec.IvParameterSpec;\nimport java.security.GeneralSecurityException;\nimport java.util.Objects;\n\npublic class MultiChannellingEncryption extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-multichannel-encryption\";\n\n    private final PacketEncryptionManager decryption;\n    private final PacketEncryptionManager encryption;\n\n    public MultiChannellingEncryption(SecretKey key) throws GeneralSecurityException {\n        Cipher decryption = Cipher.getInstance(\"AES/CFB8/NoPadding\");\n        decryption.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(key.getEncoded()));\n        this.decryption = new PacketEncryptionManager(decryption);\n        Cipher encryption = Cipher.getInstance(\"AES/CFB8/NoPadding\");\n        encryption.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(key.getEncoded()));\n        this.encryption = new PacketEncryptionManager(encryption);\n    }\n\n    public MultiChannellingEncryption(Cipher decryption, Cipher encryption) {\n        this.decryption = new PacketEncryptionManager(Objects.requireNonNull(decryption));\n        this.encryption = new PacketEncryptionManager(Objects.requireNonNull(encryption));\n    }\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        if (msg instanceof FrameData data) {\n            data.touch();\n            final ByteBuf buf = data.createData().skipBytes(1);\n            ByteBuf res = null;\n            FrameData resFrame = null;\n            try {\n                res = ctx.alloc().buffer(data.getDataSize());\n                encryption.doWork(buf, res);\n                resFrame = FrameData.create(ctx.alloc(), data.getPacketId(), res);\n//                res = null;\n                resFrame.setOrderChannel(data.getOrderChannel());\n                resFrame.setReliability(data.getReliability());\n                ctx.write(resFrame, promise);\n                resFrame = null;\n                return;\n            } finally {\n                buf.release();\n                data.release();\n                if (res != null) res.release();\n                if (resFrame != null) resFrame.release();\n            }\n        }\n        super.write(ctx, msg, promise);\n    }\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof FrameData data) {\n            data.touch();\n            final ByteBuf buf = data.createData().skipBytes(1);\n            ByteBuf res = null;\n            FrameData resFrame = null;\n            try {\n                res = ctx.alloc().buffer(data.getDataSize());\n                decryption.doWork(buf, res);\n                resFrame = FrameData.create(ctx.alloc(), data.getPacketId(), res);\n                resFrame.setOrderChannel(data.getOrderChannel());\n                resFrame.setReliability(data.getReliability());\n                ctx.fireChannelRead(resFrame);\n                resFrame = null;\n                return;\n            } finally {\n                buf.release();\n                data.release();\n                if (res != null) res.release();\n                if (resFrame != null) resFrame.release();\n            }\n        }\n        super.channelRead(ctx, msg);\n    }\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/NoFlush.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\n\npublic class NoFlush extends ChannelDuplexHandler {\n\n    @Override\n    public void flush(ChannelHandlerContext ctx) {\n        // no-op\n    }\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/PacketEncryptionManager.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport io.netty.buffer.ByteBuf;\n\nimport javax.crypto.Cipher;\nimport java.security.GeneralSecurityException;\n\n// TODO [VanillaCopy] from fabric\npublic class PacketEncryptionManager {\n    private final Cipher cipher;\n    private byte[] conversionBuffer = new byte[0];\n    private byte[] encryptionBuffer = new byte[0];\n\n    protected PacketEncryptionManager(Cipher cipher) {\n        this.cipher = cipher;\n    }\n\n    private byte[] toByteArray(ByteBuf buf) {\n        int i = buf.readableBytes();\n        if (this.conversionBuffer.length < i) {\n            this.conversionBuffer = new byte[i];\n        }\n\n        buf.readBytes(this.conversionBuffer, 0, i);\n        return this.conversionBuffer;\n    }\n\n    public void doWork(ByteBuf buf, ByteBuf result) throws GeneralSecurityException {\n        int i = buf.readableBytes();\n        byte[] bs = this.toByteArray(buf);\n        int outputSize = this.cipher.getOutputSize(i);\n        if (this.encryptionBuffer.length < outputSize) {\n            this.encryptionBuffer = new byte[outputSize];\n        }\n\n        result.writeBytes(this.encryptionBuffer, 0, this.cipher.doFinal(bs, 0, i, this.encryptionBuffer));\n    }\n}\n\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/RakNetConnectionUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport com.ishland.raknetify.common.Constants;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelInitializer;\nimport io.netty.handler.timeout.ReadTimeoutHandler;\nimport network.ycc.raknet.RakNet;\nimport network.ycc.raknet.client.channel.RakNetClientThreadedChannel;\nimport network.ycc.raknet.frame.Frame;\nimport network.ycc.raknet.pipeline.ReliabilityHandler;\nimport network.ycc.raknet.server.channel.RakNetApplicationChannel;\n\nimport java.lang.reflect.Field;\nimport java.util.Comparator;\nimport java.util.PriorityQueue;\nimport java.util.concurrent.TimeUnit;\n\nimport static com.ishland.raknetify.common.util.ReflectionUtil.accessible;\n\npublic class RakNetConnectionUtil {\n\n    public static final int IP_TOS_LOWDELAY = 0b00010000;\n    public static final int IP_TOS_THROUGHPUT = 0b00001000;\n    public static final int IP_TOS_RELIABILITY = 0b00000100;\n\n    public static final int DEFAULT_IP_TOS = IP_TOS_LOWDELAY | IP_TOS_THROUGHPUT;\n\n    private RakNetConnectionUtil() {\n    }\n\n    private static final Comparator<Frame> cmp =\n            Comparator\n                    .comparingInt((Frame frame) -> frame.getReliability().isReliable ? 1 : 0) // unreliable then reliable\n                    .thenComparingInt(frame -> frame.getReliability().isOrdered ? 1 : 0) // unordered then ordered\n                    .thenComparingInt(Frame::getOrderChannel) // lower channel first\n                    .thenComparingInt(Frame::getOrderIndex); // lower index first\n\n    public static void initChannel(Channel channel) {\n        if (channel.config() instanceof RakNet.Config config) {\n            config.setMaxQueuedBytes(Constants.MAX_QUEUED_SIZE);\n            config.setMaxPendingFrameSets(Constants.MAX_PENDING_FRAME_SETS);\n            config.setRetryDelayNanos(TimeUnit.NANOSECONDS.convert(50, TimeUnit.MILLISECONDS));\n            config.setDefaultPendingFrameSets(Constants.DEFAULT_PENDING_FRAME_SETS);\n            config.setNACKEnabled(false);\n            config.setNoDelayEnabled(false);\n//            config.setIgnoreResendGauge(true);\n\n            initRaknetChannel(channel);\n\n//            channel.pipeline().addLast(\"raknetify-flush-enforcer\", new FlushEnforcer());\n//            channel.pipeline().addLast(\"raknetify-flush-consolidation\", new FlushConsolidationHandler(Integer.MAX_VALUE, true));\n            channel.pipeline().addLast(\"raknetify-no-flush\", new NoFlush());\n            channel.pipeline().addLast(MultiChannelingStreamingCompression.NAME, new MultiChannelingStreamingCompression(Constants.RAKNET_GAME_PACKET_ID, Constants.RAKNET_STREAMING_COMPRESSION_PACKET_ID));\n//            channel.pipeline().addLast(MultiChannellingDataCodec.NAME, new MultiChannellingDataCodec(Constants.RAKNET_GAME_PACKET_ID));\n            channel.pipeline().addLast(\"raknetify-frame-data-blocker\", new FrameDataBlocker());\n        }\n    }\n\n    private static void initRaknetChannel(Channel appChannel) {\n        final Channel channel;\n        final String threadedReadHandlerName;\n        if (appChannel instanceof RakNetApplicationChannel) {\n            channel = appChannel.parent();\n            threadedReadHandlerName = RakNetApplicationChannel.NAME_SERVER_PARENT_THREADED_READ_HANDLER;\n        } else if (appChannel instanceof RakNetClientThreadedChannel) {\n            channel = appChannel.parent();\n            threadedReadHandlerName = RakNetClientThreadedChannel.NAME_CLIENT_PARENT_THREADED_READ_HANDLER;\n        } else {\n            channel = appChannel;\n            threadedReadHandlerName = null;\n        }\n        channel.pipeline().addLast(new ChannelInitializer<>() {\n            @Override\n            protected void initChannel(Channel ch) {\n                final RakNet.Config config = (RakNet.Config) ch.config();\n                final SimpleMetricsLogger simpleMetricsLogger = new SimpleMetricsLogger();\n                config.setMetrics(simpleMetricsLogger);\n                final MetricsSynchronizationHandler metricsSynchronizationHandler = new MetricsSynchronizationHandler();\n                simpleMetricsLogger.setMetricsSynchronizationHandler(metricsSynchronizationHandler);\n                final SynchronizationLayer synchronizationLayer = new SynchronizationLayer(Constants.SYNC_IGNORE_CHANNELS);\n                reInitChannelForOrdering(channel);\n                if (threadedReadHandlerName != null) {\n                    ch.pipeline().addBefore(threadedReadHandlerName, \"raknetify-metrics-sync\", metricsSynchronizationHandler);\n                    ch.pipeline().addBefore(threadedReadHandlerName, \"raknetify-synchronization-layer\", synchronizationLayer);\n                } else {\n                    ch.pipeline().addLast(\"raknetify-metrics-sync\", metricsSynchronizationHandler);\n                    ch.pipeline().addLast(\"raknetify-synchronization-layer\", synchronizationLayer);\n                }\n                ch.pipeline().addFirst(\"raknetify-timeout\", new ReadTimeoutHandler(15));\n            }\n        });\n    }\n\n//    public static void postInitChannel(Channel channel, boolean isClientSide) {\n//        if (channel.config() instanceof RakNet.Config) {\n//            ViaFabricCompatInjector.inject(channel, isClientSide);\n//            channel.pipeline().replace(\"timeout\", \"timeout\", new ChannelDuplexHandler()); // no-op\n//            channel.pipeline().replace(\"splitter\", \"splitter\", new ChannelDuplexHandler()); // no-op\n//            channel.pipeline().replace(\"prepender\", \"prepender\", new ChannelDuplexHandler()); // no-op\n//            final MultiChannellingPacketCapture handler = new MultiChannellingPacketCapture();\n//            channel.pipeline().addLast(\"raknetify-multi-channel-packet-cature\", handler);\n//            channel.pipeline().get(MultiChannellingDataCodec.class).setCapture(handler);\n//        }\n//    }\n\n    @SuppressWarnings(\"unchecked\")\n    private static void reInitChannelForOrdering(Channel channel) {\n        if (channel.config() instanceof RakNet.Config config) {\n            try {\n                final ReliabilityHandler reliabilityHandler = channel.pipeline().get(ReliabilityHandler.class);\n                final Field frameQueueField = accessible(ReliabilityHandler.class.getDeclaredField(\"frameQueue\"));\n                PriorityQueue<Frame> reliabilityHandlerFrameQueue = (PriorityQueue<Frame>) frameQueueField.get(reliabilityHandler);\n\n                final PriorityQueue<Frame> newSet = new PriorityQueue<>(cmp);\n                newSet.addAll(reliabilityHandlerFrameQueue);\n\n                frameQueueField.set(reliabilityHandler, newSet);\n\n            } catch (Throwable t) {\n                System.err.println(\"Raknetify: Error occurred while reinitializing channel ordering\");\n                t.printStackTrace();\n            }\n        }\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/RakNetSimpleMultiChannelCodec.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.util.MathUtil;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPromise;\nimport it.unimi.dsi.fastutil.ints.Int2IntMap;\nimport it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;\nimport it.unimi.dsi.fastutil.ints.IntOpenHashSet;\nimport it.unimi.dsi.fastutil.objects.ObjectArrayList;\nimport network.ycc.raknet.frame.FrameData;\nimport network.ycc.raknet.packet.FramedPacket;\n\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Queue;\n\npublic class RakNetSimpleMultiChannelCodec extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-simple-multi-channel-data-codec\";\n\n    public static final Object SIGNAL_START_MULTICHANNEL = new Object();\n\n    private final int packetId;\n\n    public RakNetSimpleMultiChannelCodec(int packetId) {\n        this.packetId = packetId;\n    }\n\n    private final ObjectArrayList<OverrideHandler> handlers = new ObjectArrayList<>();\n\n    public RakNetSimpleMultiChannelCodec addHandler(OverrideHandler handler) {\n        synchronized (handlers) {\n            handlers.add(handler);\n        }\n        return this;\n    }\n\n    public void removeHandler(OverrideHandler handler) {\n        synchronized (handlers) {\n            handlers.remove(handler);\n        }\n    }\n\n    public <T> T getHandler(Class<T> clazz) {\n        synchronized (handlers) {\n            for (OverrideHandler handler : handlers) {\n                if (clazz.isInstance(handler)) return clazz.cast(handler);\n            }\n        }\n        return null;\n    }\n\n    private boolean isMultichannelEnabled;\n\n    private boolean queuePendingWrites = false;\n    private final Queue<PendingWrite> pendingWrites = new LinkedList<>();\n\n    @Override\n    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {\n        super.handlerRemoved(ctx);\n        for (PendingWrite pendingWrite : pendingWrites) {\n            pendingWrite.promise.setFailure(new IllegalStateException(\"Channel closed\"));\n            pendingWrite.frameData.release();\n        }\n    }\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        if (this.queuePendingWrites && msg instanceof ByteBuf buf) {\n            final FrameData data = encode0(ctx, buf);\n            if (data != null) {\n                pendingWrites.add(new PendingWrite(data, promise));\n            } else {\n                promise.setSuccess();\n            }\n            buf.release();\n            return;\n        }\n\n        if (msg == SIGNAL_START_MULTICHANNEL) {\n            promise.trySuccess();\n            if (this.isMultichannelEnabled) return;\n            if (!this.isMultichannelAvailable()) {\n                System.out.println(\"Raknetify: [MultiChannellingDataCodec] Failed to start multichannel: not available\");\n                return;\n            }\n            final ByteBuf buf = ctx.alloc().buffer(1).writeByte(0);\n            try {\n                final FrameData frameData = FrameData.create(ctx.alloc(), Constants.RAKNET_PING_PACKET_ID, buf);\n                frameData.setOrderChannel(7);\n                this.queuePendingWrites = true;\n                ctx.write(frameData).addListener(future -> {\n                    isMultichannelEnabled = true;\n                    if (Constants.DEBUG) System.out.println(\"Raknetify: [MultiChannellingDataCodec] Started multichannel\");\n                    flushPendingWrites(ctx);\n                });\n            } finally {\n                buf.release();\n            }\n            return;\n        }\n        if (msg == SynchronizationLayer.SYNC_REQUEST_OBJECT) {\n            if (this.isMultichannelEnabled) {\n                if (Constants.DEBUG) System.out.println(\"Raknetify: [MultiChannellingDataCodec] Stopped multichannel\");\n                this.isMultichannelEnabled = false;\n                super.write(ctx, msg, promise);\n            }\n            promise.setSuccess();\n            return; // discard sync request when multichannel is not active\n        }\n\n        if (msg instanceof ByteBuf buf && buf.isReadable()) {\n            try {\n                final FrameData frameData = encode0(ctx, buf);\n                if (frameData != null) {\n                    ctx.write(frameData, promise);\n                } else {\n                    promise.setSuccess();\n                }\n            } finally {\n                buf.release();\n            }\n            return;\n        }\n\n        super.write(ctx, msg, promise);\n    }\n\n    private FrameData encode0(ChannelHandlerContext ctx, ByteBuf buf) {\n        if (buf.isReadable()) {\n            final int packetChannelOverride = getChannelOverride(buf, !isMultichannelEnabled);\n            if (packetChannelOverride == Integer.MIN_VALUE) {\n                return null; // the void\n            }\n            final FrameData frameData = FrameData.create(ctx.alloc(), packetId, buf);\n            if (isMultichannelEnabled) {\n                if (packetChannelOverride >= 0)\n                    frameData.setOrderChannel(packetChannelOverride);\n                else if (packetChannelOverride == -1)\n                    frameData.setReliability(FramedPacket.Reliability.RELIABLE);\n                else if (packetChannelOverride == -2)\n                    frameData.setReliability(FramedPacket.Reliability.UNRELIABLE);\n            }\n            return frameData;\n        }\n        return null;\n    }\n\n    private void flushPendingWrites(ChannelHandlerContext ctx) {\n        this.queuePendingWrites = false;\n        PendingWrite pendingWrite;\n        while ((pendingWrite = this.pendingWrites.poll()) != null) {\n            try {\n                super.write(ctx, pendingWrite.frameData, pendingWrite.promise);\n            } catch (Throwable t) {\n                ctx.fireExceptionCaught(t);\n            }\n        }\n    }\n\n    protected boolean isMultichannelAvailable() {\n        synchronized (handlers) {\n            return !handlers.isEmpty();\n        }\n    }\n\n    protected int getChannelOverride(ByteBuf buf, boolean suppressWarning) {\n        synchronized (handlers) {\n            for (OverrideHandler handler : handlers) {\n                final int override = handler.getChannelOverride(buf, suppressWarning);\n                if (override != 0) return override;\n            }\n        }\n        return 0;\n    }\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof FrameData packet && !packet.isFragment() && packet.getDataSize() > 0) {\n            try {\n                if (packetId == packet.getPacketId()) {\n                    ctx.fireChannelRead(packet.createData().skipBytes(1));\n                } else if (packet.getPacketId() == Constants.RAKNET_PING_PACKET_ID) {\n                    return;\n                } else {\n                    ctx.fireChannelRead(packet.retain());\n                }\n            } finally {\n                packet.release();\n            }\n            return;\n        }\n        super.channelRead(ctx, msg);\n    }\n\n    protected void decode(ChannelHandlerContext ctx, FrameData packet, List<Object> out) {\n        assert !packet.isFragment();\n        if (packet.getDataSize() > 0) {\n            if (packetId == packet.getPacketId()) {\n                out.add(packet.createData().skipBytes(1));\n            } else if (packet.getPacketId() == Constants.RAKNET_PING_PACKET_ID) {\n                return;\n            } else {\n                out.add(packet.retain());\n            }\n        }\n    }\n\n    public interface OverrideHandler {\n        int getChannelOverride(ByteBuf buf, boolean suppressWarning);\n    }\n\n    public static class PacketIdBasedOverrideHandler implements OverrideHandler {\n\n        private final IntOpenHashSet unknownPacketIds = new IntOpenHashSet();\n        private final Int2IntOpenHashMap channelMapping;\n        private final String descriptiveProtocolStatus;\n\n        public PacketIdBasedOverrideHandler(Int2IntMap channelMapping, String descriptiveProtocolStatus) {\n            this.channelMapping = new Int2IntOpenHashMap(channelMapping);\n            this.descriptiveProtocolStatus = descriptiveProtocolStatus;\n        }\n\n        @Override\n        public int getChannelOverride(ByteBuf buf, boolean suppressWarning) {\n            final ByteBuf slice = buf.slice();\n            final int packetId = MathUtil.readVarInt(slice);\n            final int override = this.channelMapping.get(packetId);\n            if (override == Integer.MAX_VALUE) {\n                if (!suppressWarning) {\n                    if (this.unknownPacketIds.add(packetId)) {\n                        System.err.println(\"Raknetify: Unknown packet id %d for %s\".formatted(packetId, descriptiveProtocolStatus));\n                    }\n                }\n                return 7;\n            }\n            return override;\n        }\n    }\n\n    private record PendingWrite(FrameData frameData, ChannelPromise promise) {\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/RaknetifyEventLoops.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport com.google.common.base.Suppliers;\nimport com.google.common.util.concurrent.ThreadFactoryBuilder;\nimport io.netty.channel.DefaultEventLoopGroup;\nimport io.netty.channel.epoll.EpollEventLoopGroup;\nimport io.netty.channel.nio.NioEventLoopGroup;\nimport io.netty.util.concurrent.FastThreadLocalThread;\n\nimport java.util.function.Supplier;\n\npublic class RaknetifyEventLoops {\n\n    public static final Supplier<NioEventLoopGroup> NIO_EVENT_LOOP_GROUP =\n            Suppliers.memoize(() -> new NioEventLoopGroup(\n                            0,\n                            new ThreadFactoryBuilder()\n                                    .setThreadFactory(FastThreadLocalThread::new)\n                                    .setNameFormat(\"Netty Server NIO Raknetify #%d\")\n                                    .setDaemon(true)\n                                    .build()\n                    )\n            );\n\n    public static final Supplier<NioEventLoopGroup> NIO_CLIENT_EVENT_LOOP_GROUP =\n            Suppliers.memoize(() -> new NioEventLoopGroup(\n                            0,\n                            new ThreadFactoryBuilder()\n                                    .setThreadFactory(FastThreadLocalThread::new)\n                                    .setNameFormat(\"Netty Client NIO Raknetify #%d\")\n                                    .setDaemon(true)\n                                    .build()\n                    )\n            );\n\n    public static final Supplier<EpollEventLoopGroup> EPOLL_EVENT_LOOP_GROUP =\n            Suppliers.memoize(() -> new EpollEventLoopGroup(\n                            0,\n                            new ThreadFactoryBuilder()\n                                    .setThreadFactory(FastThreadLocalThread::new)\n                                    .setNameFormat(\"Netty Server Epoll Raknetify  #%d\")\n                                    .setDaemon(true)\n                                    .build()\n                    )\n            );\n\n    public static final Supplier<EpollEventLoopGroup> EPOLL_CLIENT_EVENT_LOOP_GROUP =\n            Suppliers.memoize(() -> new EpollEventLoopGroup(\n                            0,\n                            new ThreadFactoryBuilder()\n                                    .setThreadFactory(FastThreadLocalThread::new)\n                                    .setNameFormat(\"Netty Client Epoll Raknetify  #%d\")\n                                    .setDaemon(true)\n                                    .build()\n                    )\n            );\n\n    public static final Supplier<DefaultEventLoopGroup> DEFAULT_EVENT_LOOP_GROUP =\n            Suppliers.memoize(() -> new DefaultEventLoopGroup(\n                            0,\n                            new ThreadFactoryBuilder()\n                                    .setThreadFactory(FastThreadLocalThread::new)\n                                    .setNameFormat(\"Netty Server App Raknetify #%d\")\n                                    .setDaemon(true)\n                                    .build()\n                    )\n            );\n\n    public static final Supplier<DefaultEventLoopGroup> DEFAULT_CLIENT_EVENT_LOOP_GROUP =\n            Suppliers.memoize(() -> new DefaultEventLoopGroup(\n                            0,\n                            new ThreadFactoryBuilder()\n                                    .setThreadFactory(FastThreadLocalThread::new)\n                                    .setNameFormat(\"Netty Client App Raknetify #%d\")\n                                    .setDaemon(true)\n                                    .build()\n                    )\n            );\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/SimpleMetricsLogger.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport com.ishland.raknetify.common.util.MathUtil;\nimport network.ycc.raknet.RakNet;\nimport org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;\n\n/**\n * This implementation is only designed to be modified single-threaded\n */\n@SuppressWarnings(\"NonAtomicOperationOnVolatileField\")\npublic class SimpleMetricsLogger implements RakNet.MetricsLogger {\n\n    // ========== Loggers ==========\n\n    private volatile long packetsIn = 0L;\n    private volatile long framesIn = 0L;\n    private volatile long framesError = 0L;\n    private volatile long bytesIn = 0L;\n    private volatile long packetsOut = 0L;\n    private volatile long framesOut = 0L;\n    private volatile long bytesOut = 0L;\n    private volatile long bytesRecalled = 0L;\n    private volatile long bytesACKd = 0L;\n    private volatile long bytesNACKd = 0L;\n    private volatile long acksSent = 0L;\n    private volatile long nacksSent = 0L;\n\n    private volatile long measureRTTns = 0L;\n    private volatile long measureRTTnsStdDev = 0L;\n    private volatile long measureBurstTokens = 0L;\n    private volatile int currentQueuedBytes = 0;\n\n    @Override\n    public void packetsIn(int delta) {\n        packetsIn += delta;\n    }\n\n    @Override\n    public void framesIn(int delta) {\n        framesIn += delta;\n    }\n\n    @Override\n    public void frameError(int delta) {\n        framesError += delta;\n    }\n\n    @Override\n    public void bytesIn(int delta) {\n        bytesIn += delta;\n    }\n\n    @Override\n    public void packetsOut(int delta) {\n        packetsOut += delta;\n    }\n\n    @Override\n    public void framesOut(int delta) {\n        framesOut += delta;\n    }\n\n    @Override\n    public void bytesOut(int delta) {\n        bytesOut += delta;\n        tick();\n    }\n\n    @Override\n    public void bytesRecalled(int delta) {\n        bytesRecalled += delta;\n    }\n\n    @Override\n    public void bytesACKd(int delta) {\n        bytesACKd += delta;\n    }\n\n    @Override\n    public void bytesNACKd(int delta) {\n        bytesNACKd += delta;\n    }\n\n    @Override\n    public void acksSent(int delta) {\n        acksSent += delta;\n    }\n\n    @Override\n    public void nacksSent(int delta) {\n        nacksSent += delta;\n    }\n\n    @Override\n    public void measureRTTns(long n) {\n        measureRTTns = n;\n    }\n\n    @Override\n    public void measureRTTnsStdDev(long n) {\n        measureRTTnsStdDev = n;\n        tick();\n    }\n\n    @Override\n    public void measureBurstTokens(int n) {\n        measureBurstTokens = n;\n    }\n\n    @Override\n    public void currentQueuedBytes(int bytes) {\n        currentQueuedBytes = bytes;\n    }\n\n    // ========== Calculations ==========\n\n    private long lastMeasureMillis = System.currentTimeMillis();\n\n    private synchronized void tick() {\n        final long measureMillis = System.currentTimeMillis();\n        final long deltaTime = measureMillis - lastMeasureMillis;\n        if (deltaTime < 990) return; // throttle\n        this.lastMeasureMillis = measureMillis;\n\n        tickErrorRate();\n        tickRXTX(deltaTime);\n    }\n\n    private final DescriptiveStatistics errorStats = new DescriptiveStatistics(16);\n    private long lastBytesTotal = 0L;\n    private long lastBytesRecalled = 0L;\n    private volatile double measureErrorRate = 0.0D;\n\n    private void tickErrorRate() {\n        final long bytesTotal = this.bytesIn + this.bytesOut;\n        final long bytesRecalled = this.bytesRecalled;\n\n        final long bytesTotalDelta = bytesTotal - lastBytesTotal;\n        final long bytesRecalledDelta = bytesRecalled - this.lastBytesRecalled;\n\n        if (bytesTotalDelta != 0) {\n            this.errorStats.addValue(bytesRecalledDelta / (double) bytesTotalDelta);\n            this.measureErrorRate = this.errorStats.getMean();\n        }\n\n        this.lastBytesTotal = bytesTotal;\n        this.lastBytesRecalled = bytesRecalled;\n    }\n\n    private final DescriptiveStatistics rxStats = new DescriptiveStatistics(8);\n    private final DescriptiveStatistics txStats = new DescriptiveStatistics(8);\n    private long lastPacketsIn = 0L;\n    private long lastPacketsOut = 0L;\n    private long lastBytesIn = 0L;\n    private long lastBytesOut = 0L;\n    private volatile int measureRX = 0;\n    private volatile int measureTX = 0;\n    private volatile long measureBytesInRate = 0;\n    private volatile long measureBytesOutRate = 0;\n    private volatile String measureTrafficInFormatted = \"...\";\n    private volatile String measureTrafficOutFormatted = \"...\";\n\n    private void tickRXTX(long deltaTime) {\n\n        final long packetsIn = this.packetsIn;\n        final long packetsOut = this.packetsOut;\n        final long bytesIn = this.bytesIn;\n        final long bytesOut = this.bytesOut;\n\n        final double timeDeltaS = deltaTime / 1000.0;\n\n        this.rxStats.addValue((packetsIn - this.lastPacketsIn) / timeDeltaS);\n        this.txStats.addValue((packetsOut - this.lastPacketsOut) / timeDeltaS);\n\n        this.measureRX = (int) this.rxStats.getMean();\n        this.measureTX = (int) this.txStats.getMean();\n\n        this.measureBytesInRate = (long) ((bytesIn - this.lastBytesIn) / timeDeltaS);\n        this.measureBytesOutRate = (long) ((bytesOut - this.lastBytesOut) / timeDeltaS);\n\n        this.measureTrafficInFormatted = MathUtil.humanReadableByteCountBin(this.measureBytesInRate) + \"/s\";\n        this.measureTrafficOutFormatted = MathUtil.humanReadableByteCountBin(this.measureBytesOutRate) + \"/s\";\n\n        this.lastPacketsIn = packetsIn;\n        this.lastPacketsOut = packetsOut;\n        this.lastBytesIn = bytesIn;\n        this.lastBytesOut = bytesOut;\n    }\n\n    // ========== Getters ==========\n\n    public long getMeasureRTTns() {\n        return measureRTTns;\n    }\n\n    public long getMeasureRTTnsStdDev() {\n        return measureRTTnsStdDev;\n    }\n\n    public double getMeasureErrorRate() {\n        return measureErrorRate;\n    }\n\n    public int getMeasureRX() {\n        return measureRX;\n    }\n\n    public int getMeasureTX() {\n        return measureTX;\n    }\n\n    public int getCurrentQueuedBytes() {\n        return currentQueuedBytes;\n    }\n\n    public long getMeasureBurstTokens() {\n        return measureBurstTokens;\n    }\n\n    public long getMeasureBytesInRate() {\n        return measureBytesInRate;\n    }\n\n    public long getMeasureBytesOutRate() {\n        return measureBytesOutRate;\n    }\n\n    public String getMeasureTrafficInFormatted() {\n        return measureTrafficInFormatted;\n    }\n\n    public String getMeasureTrafficOutFormatted() {\n        return measureTrafficOutFormatted;\n    }\n\n    public long getBytesIn() {\n        return bytesIn;\n    }\n\n    // ========== Misc ==========\n\n    private MetricsSynchronizationHandler metricsSynchronizationHandler;\n\n    public MetricsSynchronizationHandler getMetricsSynchronizationHandler() {\n        return this.metricsSynchronizationHandler;\n    }\n\n    public void setMetricsSynchronizationHandler(MetricsSynchronizationHandler metricsSynchronizationHandler) {\n        this.metricsSynchronizationHandler = metricsSynchronizationHandler;\n    }\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/SynchronizationLayer.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection;\n\nimport com.ishland.raknetify.common.Constants;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPromise;\nimport it.unimi.dsi.fastutil.ints.Int2ObjectMap;\nimport it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;\nimport it.unimi.dsi.fastutil.ints.IntOpenHashSet;\nimport it.unimi.dsi.fastutil.ints.IntSet;\nimport it.unimi.dsi.fastutil.objects.ObjectArrayList;\nimport it.unimi.dsi.fastutil.objects.ObjectIterator;\nimport it.unimi.dsi.fastutil.objects.Reference2ReferenceLinkedOpenHashMap;\nimport it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet;\nimport network.ycc.raknet.frame.Frame;\nimport network.ycc.raknet.frame.FrameData;\nimport network.ycc.raknet.packet.FrameSet;\nimport network.ycc.raknet.packet.FramedPacket;\nimport network.ycc.raknet.pipeline.FrameJoiner;\nimport network.ycc.raknet.pipeline.FrameOrderIn;\nimport network.ycc.raknet.pipeline.FrameOrderOut;\nimport network.ycc.raknet.pipeline.ReliabilityHandler;\nimport org.apache.commons.math3.util.Pair;\n\nimport java.lang.reflect.Array;\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Method;\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.PriorityQueue;\n\nimport static com.ishland.raknetify.common.util.ReflectionUtil.accessible;\n\npublic class SynchronizationLayer extends ChannelDuplexHandler {\n\n    // Request structure:\n    // byte: total channel count `n`\n    // next `n` groups: {\n    // byte: channel index\n    // integer: current orderIndex (or lastOrderIndex, (nextOrderIndex - 1))\n    // }\n    // integer: current seqId (or lastReceivedSeqId, (nextSendSeqId - 1))\n    //\n    // Response callback is handled using reliable transport\n\n    public static final Object SYNC_REQUEST_OBJECT = new Object();\n\n    static final Class<?> CLASS_QUEUE;\n    static final Class<?> CLASS_FRAME_JOINER_BUILDER;\n    static final Field FIELD_QUEUE_LAST_ORDER_INDEX;\n    static final Method METHOD_QUEUE_BUILDER_RELEASE;\n    static final Method METHOD_QUEUE_CLEAR;\n    static final Field FIELD_RELIABILITY_NEXT_SEND_SEQ_ID;\n    static final Field FIELD_RELIABILITY_LAST_RECEIVED_SEQ_ID;\n    static final Field FIELD_RELIABILITY_QUEUED_BYTES;\n    static final Field FIELD_FRAME_JOINER_BUILDER_SAMPLE_PACKET;\n\n    static {\n        try {\n            CLASS_QUEUE = Class.forName(\"network.ycc.raknet.pipeline.FrameOrderIn$OrderedChannelPacketQueue\");\n            CLASS_FRAME_JOINER_BUILDER = Class.forName(\"network.ycc.raknet.pipeline.FrameJoiner$Builder\");\n\n            FIELD_QUEUE_LAST_ORDER_INDEX = accessible(CLASS_QUEUE.getDeclaredField(\"lastOrderIndex\"));\n            FIELD_RELIABILITY_NEXT_SEND_SEQ_ID = accessible(ReliabilityHandler.class.getDeclaredField(\"nextSendSeqId\"));\n            FIELD_RELIABILITY_LAST_RECEIVED_SEQ_ID = accessible(ReliabilityHandler.class.getDeclaredField(\"lastReceivedSeqId\"));\n            FIELD_RELIABILITY_QUEUED_BYTES = accessible(ReliabilityHandler.class.getDeclaredField(\"queuedBytes\"));\n            FIELD_FRAME_JOINER_BUILDER_SAMPLE_PACKET = accessible(CLASS_FRAME_JOINER_BUILDER.getDeclaredField(\"samplePacket\"));\n\n            METHOD_QUEUE_BUILDER_RELEASE = accessible(CLASS_FRAME_JOINER_BUILDER.getDeclaredMethod(\"release\"));\n            METHOD_QUEUE_CLEAR = accessible(CLASS_QUEUE.getDeclaredMethod(\"clear\"));\n\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n    }\n\n    private final IntSet channelToIgnore = new IntOpenHashSet();\n\n    private FrameOrderIn frameOrderIn;\n    private Object[] frameOrderInQueues;\n    private FrameOrderOut frameOrderOut;\n    private int[] frameOrderOutNextOrderIndex;\n    private ReliabilityHandler reliabilityHandler;\n    private PriorityQueue<Frame> reliabilityHandlerFrameQueue;\n    private Int2ObjectMap<FrameSet> reliabilityHandlerPendingFrameSets;\n    private FrameJoiner frameJoiner;\n    private Int2ObjectOpenHashMap<?> frameJoinerPendingPackets;\n    private int channelsLength;\n    private boolean initialized = false;\n\n    public SynchronizationLayer(int... channelsToIgnore) {\n        for (int ch : channelsToIgnore) {\n            channelToIgnore.add(ch);\n        }\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public void channelActive(ChannelHandlerContext ctx) throws Exception {\n        super.channelActive(ctx);\n        initializeIfNecessary(ctx);\n    }\n\n    private void initializeIfNecessary(ChannelHandlerContext ctx) {\n        if (initialized) return;\n        try {\n            this.frameOrderIn = ctx.pipeline().get(FrameOrderIn.class);\n            Object frameOrderInQueueArray = accessible(FrameOrderIn.class.getDeclaredField(\"channels\")).get(this.frameOrderIn);\n            this.frameOrderInQueues = new Object[Array.getLength(frameOrderInQueueArray)];\n            for (int i = 0; i < this.frameOrderInQueues.length; i++) {\n                this.frameOrderInQueues[i] = Array.get(frameOrderInQueueArray, i);\n            }\n\n            this.frameOrderOut = ctx.pipeline().get(FrameOrderOut.class);\n            this.frameOrderOutNextOrderIndex = (int[]) accessible(FrameOrderOut.class.getDeclaredField(\"nextOrderIndex\")).get(this.frameOrderOut);\n\n            this.reliabilityHandler = ctx.pipeline().get(ReliabilityHandler.class);\n            this.reliabilityHandlerFrameQueue = (PriorityQueue<Frame>) accessible(ReliabilityHandler.class.getDeclaredField(\"frameQueue\")).get(this.reliabilityHandler);\n            this.reliabilityHandlerPendingFrameSets = (Int2ObjectMap<FrameSet>) accessible(ReliabilityHandler.class.getDeclaredField(\"pendingFrameSets\")).get(this.reliabilityHandler);\n\n            int originalChannelsLength = this.frameOrderOutNextOrderIndex.length;\n            //noinspection deprecation\n            this.channelsLength = (int) (originalChannelsLength - this.channelToIgnore.stream().filter(value -> value < originalChannelsLength).count());\n\n            this.frameJoiner = ctx.pipeline().get(FrameJoiner.class);\n            this.frameJoinerPendingPackets = (Int2ObjectOpenHashMap<?>) accessible(FrameJoiner.class.getDeclaredField(\"pendingPackets\")).get(this.frameJoiner);\n\n            initialized = true;\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n    }\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        initializeIfNecessary(ctx);\n        if (msg instanceof FrameData packet && packet.getPacketId() == Constants.RAKNET_SYNC_PACKET_ID) {\n            // read\n            {\n                if (Constants.DEBUG) System.out.println(\"Raknetify: Received sync packet\");\n                ctx.fireUserEventTriggered(SYNC_REQUEST_OBJECT);\n                final ByteBuf byteBuf = packet.createData().skipBytes(1);\n                try {\n                    final byte count = byteBuf.readByte();\n                    for (int i = 0; i < count; i++) {\n                        final byte channel = byteBuf.readByte();\n                        final int orderIndex = byteBuf.readInt();\n                        if (Constants.DEBUG)\n                            System.out.println(\"Raknetify: Channel %d: %d -> %d\"\n                                    .formatted(channel,\n                                            (int) FIELD_QUEUE_LAST_ORDER_INDEX.get(frameOrderInQueues[channel]),\n                                            orderIndex\n                                    ));\n                        FIELD_QUEUE_LAST_ORDER_INDEX.set(frameOrderInQueues[channel], orderIndex);\n                        final ObjectIterator<?> iterator = this.frameJoinerPendingPackets.values().iterator();\n                        while (iterator.hasNext()) {\n                            final Object next = iterator.next();\n                            try {\n                                final Frame frame = (Frame) FIELD_FRAME_JOINER_BUILDER_SAMPLE_PACKET.get(next);\n                                if (frame.getReliability().isOrdered && frame.getOrderChannel() == channel) {\n                                    METHOD_QUEUE_BUILDER_RELEASE.invoke(next);\n                                    iterator.remove();\n                                }\n                            } catch (IllegalAccessException e) {\n                                throw new RuntimeException(e);\n                            }\n                        }\n                    }\n                    final int seqId = byteBuf.readInt();\n                    if (Constants.DEBUG)\n                        System.out.println(\"Raknetify: ReliabilityHandler: %d -> %d\".formatted(\n                                (int) FIELD_RELIABILITY_LAST_RECEIVED_SEQ_ID.get(this.reliabilityHandler),\n                                seqId\n                        ));\n                    FIELD_RELIABILITY_LAST_RECEIVED_SEQ_ID.set(this.reliabilityHandler, seqId);\n                } finally {\n                    byteBuf.release();\n                }\n            }\n            return;\n        }\n        ctx.fireChannelRead(msg);\n    }\n\n    private final ReferenceLinkedOpenHashSet<Pair<ChannelPromise, Object>> queue = new ReferenceLinkedOpenHashSet<>();\n    private final ObjectArrayList<Frame> queuedFrames = new ObjectArrayList<>();\n    private boolean isWaitingForResponse = false;\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        initializeIfNecessary(ctx);\n        if (msg == SYNC_REQUEST_OBJECT) {\n            if (isWaitingForResponse) {\n                promise.setSuccess();\n                return;\n            }\n\n            dropSenderPackets();\n\n            final ByteBuf byteBuf = ctx.alloc().buffer(1 + channelsLength * 5 + 4);\n            byteBuf.writeByte(channelsLength);\n            for (int channel = 0, frameOrderOutNextOrderIndexLength = frameOrderOutNextOrderIndex.length; channel < frameOrderOutNextOrderIndexLength; channel++) {\n                if (channelToIgnore.contains(channel)) continue;\n                int orderOutNextOrderIndex = frameOrderOutNextOrderIndex[channel];\n                if (Constants.DEBUG)\n                    System.out.println(\"Raknetify: Writing sync packet: Channel %d: %d\".formatted(channel, orderOutNextOrderIndex - 1));\n                byteBuf.writeByte(channel);\n                byteBuf.writeInt(orderOutNextOrderIndex - 1);\n            }\n            int seqId = (int) FIELD_RELIABILITY_NEXT_SEND_SEQ_ID.get(this.reliabilityHandler); // TODO implementation details (probable lib bug): nextSendSeqId == lastReceivedSeqId\n            if (Constants.DEBUG)\n                System.out.println(\"Raknetify: Writing sync packet: ReliabilityHandler: %d\".formatted(seqId));\n            byteBuf.writeInt(seqId);\n\n            final FrameData frameData = FrameData.create(ctx.alloc(), Constants.RAKNET_SYNC_PACKET_ID, byteBuf);\n            frameData.setReliability(FramedPacket.Reliability.RELIABLE);\n            this.isWaitingForResponse = true;\n            ctx.write(frameData).addListener(future -> this.flushQueue(ctx));\n            byteBuf.release();\n            promise.setSuccess();\n            return;\n        }\n        if (isWaitingForResponse) {\n            this.queue.add(Pair.create(promise, msg));\n            return;\n        }\n        super.write(ctx, msg, promise);\n    }\n\n    private void dropSenderPackets() {\n        int droppedFrames = 0;\n\n        ArrayList<Frame> retainedFrameList = new ArrayList<>();\n\n        //noinspection CollectionAddAllCanBeReplacedWithConstructor\n        retainedFrameList.addAll(this.reliabilityHandlerFrameQueue);\n        this.reliabilityHandlerFrameQueue.clear();\n\n        for (FrameSet frameSet : this.reliabilityHandlerPendingFrameSets.values()) {\n            frameSet.createFrames(retainedFrameList::add);\n            frameSet.release();\n        }\n        this.reliabilityHandlerPendingFrameSets.clear();\n\n        int byteSize = 0;\n        for (Iterator<Frame> iterator = retainedFrameList.iterator(); iterator.hasNext(); ) {\n            Frame frame = iterator.next();\n            if (frame.getReliability().isOrdered && !channelToIgnore.contains(frame.getOrderChannel())) {\n                final ChannelPromise promise1 = frame.getPromise();\n                if (promise1 != null) promise1.trySuccess();\n                iterator.remove();\n                frame.release();\n                droppedFrames++;\n            } else {\n                byteSize += frame.getRoughPacketSize();\n            }\n        }\n        this.queuedFrames.addAll(retainedFrameList);\n\n        if (Constants.DEBUG) System.out.println(\"Raknetify: Dropping %d frames\".formatted(droppedFrames));\n        try {\n            FIELD_RELIABILITY_QUEUED_BYTES.set(this.reliabilityHandler, byteSize);\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n\n        this.reliabilityHandlerPendingFrameSets.clear();\n    }\n\n    private void flushQueue(ChannelHandlerContext ctx) {\n        if (!isWaitingForResponse) {\n            if (Constants.DEBUG) System.out.println(\"Raknetify: Ignoring duplicate call to flushQueue()\");\n            return;\n        }\n        if (!ctx.channel().eventLoop().inEventLoop()) {\n            ctx.channel().eventLoop().execute(() -> flushQueue(ctx));\n            return;\n        }\n\n        this.isWaitingForResponse = false;\n\n        if (Constants.DEBUG) System.out.println(\"Raknetify: Picking up %d queued frames\".formatted(this.queuedFrames.size()));\n        this.reliabilityHandlerFrameQueue.addAll(this.queuedFrames);\n        this.queuedFrames.clear();\n\n        if (Constants.DEBUG) System.out.println(\"Raknetify: Flushing %d queued packets as synchronization finished\".formatted(this.queue.size()));\n        while (!this.queue.isEmpty()) {\n            Pair<ChannelPromise, Object> pair = this.queue.removeFirst();\n            final ChannelPromise promise = pair.getFirst();\n            final Object msg = pair.getSecond();\n            ctx.write(msg, promise);\n        }\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/connection/multichannel/CustomPayloadChannel.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.connection.multichannel;\n\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.common.util.MathUtil;\nimport io.netty.buffer.ByteBuf;\nimport it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;\n\nimport java.util.Objects;\nimport java.util.function.IntPredicate;\n\npublic class CustomPayloadChannel {\n\n    public static final Object2IntOpenHashMap<String> identifier2channel;\n\n    static {\n        // See .fabric.common.connection.RakNetMultiChannel\n\n        identifier2channel = new Object2IntOpenHashMap<>();\n        identifier2channel.defaultReturnValue(0);\n        identifier2channel.put(\"porting_lib:extra_data_entity_spawn\", 2);\n        identifier2channel.put(\"porting_lib:extra_entity_spawn_data\", 2); // https://github.com/Fabricators-of-Create/Porting-Lib/commit/4b0cd845731f89eafd9fb39e13e1a7d87f5e14a4\n    }\n\n    public static class OverrideHandler implements RakNetSimpleMultiChannelCodec.OverrideHandler {\n\n        private final IntPredicate isCustomPayload;\n\n        public OverrideHandler(IntPredicate isCustomPayload) {\n            this.isCustomPayload = Objects.requireNonNull(isCustomPayload);\n        }\n\n        @Override\n        public int getChannelOverride(ByteBuf origBuf, boolean suppressWarning) {\n            ByteBuf buf = origBuf.slice();\n            final int packetId = MathUtil.readVarInt(buf);\n            if (isCustomPayload.test(packetId)) {\n                final String identifier = MathUtil.readString(buf); // we assume modern custom payloads\n                if (Constants.DEBUG) System.out.println(\"Raknetify: Handling custom payload: \" + identifier);\n                return identifier2channel.getInt(identifier);\n            } else {\n                return 0;\n            }\n        }\n\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/data/ProtocolMultiChannelMappings.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.data;\n\nimport com.google.gson.Gson;\nimport it.unimi.dsi.fastutil.ints.Int2IntArrayMap;\nimport it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;\nimport it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\n\npublic class ProtocolMultiChannelMappings {\n\n    public static final ProtocolMultiChannelMappings INSTANCE;\n\n    static {\n        final InputStream resource = ProtocolMultiChannelMappings.class.getClassLoader().getResourceAsStream(\"raknetify-channel-mappings.json\");\n        if (resource == null) {\n            System.err.println(\"Raknetify: Failed to load raknetify channel mappings\");\n            INSTANCE = new ProtocolMultiChannelMappings();\n        } else {\n            ProtocolMultiChannelMappings read = new ProtocolMultiChannelMappings();\n            try (var in = resource;\n                    var reader = new InputStreamReader(resource)) {\n                final Gson gson = new Gson();\n                read = gson.fromJson(reader, ProtocolMultiChannelMappings.class);\n            } catch (IOException e) {\n                System.err.println(\"Raknetify: Failed to load raknetify channel mappings\");\n                e.printStackTrace();\n            }\n            INSTANCE = read;\n        }\n    }\n\n    public static void init() {\n    }\n\n    public Int2ObjectArrayMap<VersionMapping> mappings = new Int2ObjectArrayMap<>();\n\n    public static class VersionMapping {\n        public Int2IntArrayMap s2c = new Int2IntArrayMap();\n        public Int2IntArrayMap c2s = new Int2IntArrayMap();\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/package-info.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common;\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/util/DebugUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.util;\n\nimport com.ishland.raknetify.common.connection.MetricsSynchronizationHandler;\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.common.connection.SimpleMetricsLogger;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelHandler;\nimport network.ycc.raknet.RakNet;\n\npublic class DebugUtil {\n\n    public static String printChannelDetails(Channel channel) {\n        final StringBuilder b = new StringBuilder();\n        b.append(\"Channel details for \").append(channel.toString()).append(' ').append('(').append(channel.getClass().getName()).append(')').append('\\n');\n        b.append(\"Connection: \").append(channel.localAddress()).append(\" <--> \").append(channel.remoteAddress()).append('\\n');\n        b.append(\"Open: \").append(channel.isOpen()).append('\\n');\n        b.append(\"Active: \").append(channel.isActive()).append('\\n');\n        b.append(\"Auto Read: \").append(channel.config().isAutoRead()).append('\\n');\n        if (channel.config() instanceof RakNet.Config config) {\n            b.append(\"MTU: \").append(config.getMTU()).append('\\n');\n            b.append(\"RTT: %.2f/%.2fms\"\n                    .formatted(\n                            config.getRTTNanos() / 1_000_000.0,\n                            config.getRTTStdDevNanos() / 1_000_000.0\n                    )).append('\\n');\n            if (config.getMetrics() instanceof SimpleMetricsLogger logger) {\n                final MetricsSynchronizationHandler sync = logger.getMetricsSynchronizationHandler();\n                if (sync != null && sync.isRemoteSupported()) {\n                    b.append(\"Local Buffer: %.2fMB; Remote buffer: %.2fMB\"\n                            .formatted(\n                                    logger.getCurrentQueuedBytes() / 1024.0 / 1024.0,\n                                    sync.getQueuedBytes() / 1024.0 / 1024.0\n                            )).append('\\n');\n                } else {\n                    b.append(\"Local buffer: %.2fMB\"\n                            .formatted(\n                                    logger.getCurrentQueuedBytes() / 1024.0 / 1024.0\n                            )).append('\\n');\n                }\n\n                b.append(\"Local traffic: I: %s, O: %s\"\n                        .formatted(\n                                logger.getMeasureTrafficInFormatted(),\n                                logger.getMeasureTrafficOutFormatted()\n                        )).append('\\n');\n\n                b.append(\"Local Statistics: ERR: %.4f%%, %d tx, %d rx, Burst: %d\"\n                        .formatted(\n                                logger.getMeasureErrorRate() * 100.0,\n                                logger.getMeasureTX(), logger.getMeasureRX(),\n                                logger.getMeasureBurstTokens() + config.getDefaultPendingFrameSets()\n                        )).append('\\n');\n\n                if (sync != null && sync.isRemoteSupported()) {\n                    b.append(\"Remote Statistics: ERR: %.4f%%, %d tx, %d rx, Burst: %d\"\n                            .formatted(\n                                    sync.getErrorRate() * 100.0,\n                                    sync.getTX(), sync.getRX(),\n                                    sync.getBurst()\n                            )).append('\\n');\n                }\n\n                final MultiChannelingStreamingCompression compression = channel.pipeline().get(MultiChannelingStreamingCompression.class);\n                if (compression != null && compression.isActive()) {\n                    b.append(\"Local Streaming Compression Ratio: I: %.2f%%, O: %.2f%%\"\n                            .formatted(compression.getInCompressionRatio() * 100, compression.getOutCompressionRatio() * 100)).append('\\n');\n                }\n\n            }\n        }\n\n        b.append('\\n');\n        b.append(\"Pipeline: \").append('\\n');\n        for (String name : channel.pipeline().names()) {\n            final ChannelHandler channelHandler = channel.pipeline().get(name);\n            if (channelHandler == null) {\n                b.append(\"\\t\").append(name).append(\": \\t\").append(\"null\").append('\\n');\n            } else {\n                b.append(\"\\t\").append(name).append(\": \\t\").append(channelHandler.toString()).append(\"(\").append(channelHandler.getClass().getName()).append(\")\").append('\\n');\n            }\n        }\n\n        if (channel.parent() != null) {\n            b.append('\\n');\n            b.append(\"Parent: \").append('\\n');\n\n            b.append(printChannelDetails(channel.parent()).replace(\"\\n\", \"\\n\\t\"));\n        }\n\n\n        return b.toString();\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/util/MathUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.util;\n\nimport com.google.common.base.Charsets;\nimport io.netty.buffer.ByteBuf;\n\nimport java.text.CharacterIterator;\nimport java.text.StringCharacterIterator;\n\npublic class MathUtil {\n\n    public static String humanReadableByteCountBin(long bytes) {\n        long absB = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes);\n        if (absB < 1024) {\n            return bytes + \" B\";\n        }\n        long value = absB;\n        CharacterIterator ci = new StringCharacterIterator(\"KMGTPE\");\n        for (int i = 40; i >= 0 && absB > 0xfffccccccccccccL >> i; i -= 10) {\n            value >>= 10;\n            ci.next();\n        }\n        value *= Long.signum(bytes);\n        return String.format(\"%.2f %ciB\", value / 1024.0, ci.current());\n    }\n\n    public static int readVarInt(ByteBuf buf) {\n        // TODO [VanillaCopy]\n        int i = 0;\n        int j = 0;\n\n        byte b;\n        do {\n            b = buf.readByte();\n            i |= (b & 127) << j++ * 7;\n            if (j > 5) {\n                throw new RuntimeException(\"VarInt too big\");\n            }\n        } while ((b & 128) == 128);\n\n        return i;\n    }\n\n    public static String readString(ByteBuf buf) {\n        return readString(buf, Short.MAX_VALUE);\n    }\n\n    public static String readString(ByteBuf buf, int maxLen) {\n        // Copied from BungeeCord\n        int len = readVarInt(buf);\n        if (len > maxLen * 3) {\n            throw new IllegalArgumentException(\"Cannot receive string longer than \" + maxLen * 3 + \" (got \" + len + \" bytes)\");\n        }\n\n        String s = buf.toString(buf.readerIndex(), len, Charsets.UTF_8);\n        buf.readerIndex(buf.readerIndex() + len);\n\n        if (s.length() > maxLen) {\n            throw new IllegalArgumentException(\"Cannot receive string longer than \" + maxLen + \" (got \" + s.length() + \" characters)\");\n        }\n\n        return s;\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/util/NetworkInterfaceListener.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.util;\n\nimport it.unimi.dsi.fastutil.objects.ObjectIterator;\nimport it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;\nimport it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;\nimport it.unimi.dsi.fastutil.objects.ReferenceSet;\nimport it.unimi.dsi.fastutil.objects.ReferenceSets;\n\nimport java.net.InetAddress;\nimport java.net.NetworkInterface;\nimport java.util.List;\nimport java.util.concurrent.Executors;\nimport java.util.concurrent.ScheduledExecutorService;\nimport java.util.concurrent.TimeUnit;\nimport java.util.function.Consumer;\n\npublic class NetworkInterfaceListener {\n\n    private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(\n            r -> {\n                final Thread thread = new Thread(r, \"Raknetify IFListener\");\n                thread.setDaemon(true);\n                thread.setPriority(Thread.NORM_PRIORITY - 1);\n                return thread;\n            }\n    );\n\n    static {\n        scheduler.scheduleAtFixedRate(() -> {\n            try {\n                pollChanges();\n            } catch (Throwable t) {\n                t.printStackTrace();\n            }\n        }, 0, 10, TimeUnit.SECONDS);\n    }\n\n    public static void init() {\n    }\n\n    private static final ObjectOpenHashSet<InetAddress> knownAddresses = new ObjectOpenHashSet<>();\n    private static final ReferenceSet<Consumer<InterfaceAddressChangeEvent>> listeners = ReferenceSets.synchronize(new ReferenceOpenHashSet<>());\n\n    private static void pollChanges() {\n        try {\n            final List<NetworkInterface> networkInterfaces = NetworkInterface.networkInterfaces().toList();\n            ObjectOpenHashSet<InetAddress> currentAddresses = new ObjectOpenHashSet<>();\n            for (NetworkInterface networkInterface : networkInterfaces) {\n                if (networkInterface.isUp()) {\n                    for (InetAddress address : networkInterface.inetAddresses().toList()) {\n                        currentAddresses.add(address);\n                        if (knownAddresses.add(address)) {\n                            listeners.forEach(consumer -> consumer.accept(new InterfaceAddressChangeEvent(true, address)));\n                        }\n                    }\n                }\n            }\n            final ObjectIterator<InetAddress> iterator = knownAddresses.iterator();\n            while (iterator.hasNext()) {\n                final InetAddress address = iterator.next();\n                if (!currentAddresses.contains(address)) {\n                    iterator.remove();\n                    listeners.forEach(consumer -> consumer.accept(new InterfaceAddressChangeEvent(false, address)));\n                }\n            }\n        } catch (Throwable t) {\n            t.printStackTrace();\n        }\n    }\n\n    public static void addListener(Consumer<InterfaceAddressChangeEvent> consumer) {\n        listeners.add(consumer);\n    }\n\n    public static void removeListener(Consumer<InterfaceAddressChangeEvent> consumer) {\n        listeners.remove(consumer);\n    }\n\n    public record InterfaceAddressChangeEvent(boolean added, InetAddress address) {\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/util/PrefixUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.util;\n\nimport com.ishland.raknetify.common.Constants;\n\npublic class PrefixUtil {\n\n    public static Info getInfo(String address) {\n        if (address.startsWith(Constants.RAKNET_PREFIX)) {\n            return new Info(true, address.substring(Constants.RAKNET_PREFIX.length()), false);\n        } else if (address.startsWith(Constants.RAKNET_LARGE_MTU_PREFIX)) {\n            return new Info(true, address.substring(Constants.RAKNET_LARGE_MTU_PREFIX.length()), true);\n        } else {\n            return new Info(false, address, false);\n        }\n    }\n\n    public record Info(boolean useRakNet, String stripped, boolean largeMTU) {\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/util/ReflectionUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.util;\n\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Method;\n\npublic class ReflectionUtil {\n\n    public static Field accessible(Field field) {\n        field.setAccessible(true);\n        return field;\n    }\n\n    public static Method accessible(Method method) {\n        method.setAccessible(true);\n        return method;\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/java/com/ishland/raknetify/common/util/ThreadLocalUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.common.util;\n\npublic class ThreadLocalUtil {\n\n    private ThreadLocalUtil() {\n    }\n\n    private static final ThreadLocal<Boolean> initializingRaknet = ThreadLocal.withInitial(() -> false);\n    private static final ThreadLocal<Boolean> initializingRaknetLargeMTU = ThreadLocal.withInitial(() -> false);\n\n    public static void setInitializingRaknet(boolean value) {\n        initializingRaknet.set(value);\n    }\n\n    public static void setInitializingRaknetLargeMTU(boolean value) {\n        initializingRaknetLargeMTU.set(value);\n    }\n\n    public static boolean isInitializingRaknet() {\n        return initializingRaknet.get();\n    }\n\n    public static boolean isInitializingRaknetLargeMTU() {\n        return initializingRaknetLargeMTU.get();\n    }\n\n}\n"
  },
  {
    "path": "common/src/main/resources/raknetify-channel-mappings.json",
    "content": "{\n  \"mappings\": {\n    \"755\": {\n      \"s2c\": {\n        \"0\": 2,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": 1,\n        \"5\": 4,\n        \"6\": 2,\n        \"7\": -1,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 7,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 1,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 3,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 4,\n        \"26\": -1,\n        \"27\": 2,\n        \"28\": 2,\n        \"29\": 7,\n        \"30\": 2,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": 7,\n        \"35\": 7,\n        \"36\": 4,\n        \"37\": 7,\n        \"38\": 2,\n        \"39\": 4,\n        \"40\": 3,\n        \"41\": 2,\n        \"42\": 2,\n        \"43\": 2,\n        \"44\": 2,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 7,\n        \"48\": -1,\n        \"49\": 3,\n        \"50\": 2,\n        \"51\": 2,\n        \"52\": 2,\n        \"53\": 1,\n        \"54\": 1,\n        \"55\": 1,\n        \"56\": 1,\n        \"57\": 3,\n        \"58\": 2,\n        \"59\": 2,\n        \"60\": -1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 7,\n        \"64\": -1,\n        \"65\": 1,\n        \"66\": 3,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 3,\n        \"71\": 2,\n        \"72\": 3,\n        \"73\": 7,\n        \"74\": 7,\n        \"75\": 2,\n        \"76\": 1,\n        \"77\": 2,\n        \"78\": 2,\n        \"79\": 2,\n        \"80\": 2,\n        \"81\": 1,\n        \"82\": 1,\n        \"83\": 1,\n        \"84\": 2,\n        \"85\": 1,\n        \"86\": 1,\n        \"87\": 1,\n        \"88\": 1,\n        \"89\": 1,\n        \"90\": 1,\n        \"91\": 4,\n        \"92\": 4,\n        \"93\": 4,\n        \"94\": 1,\n        \"95\": 3,\n        \"96\": 2,\n        \"97\": 2,\n        \"98\": 1,\n        \"99\": 2,\n        \"100\": 2,\n        \"101\": 1,\n        \"102\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 3,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 3,\n        \"10\": 3,\n        \"11\": 3,\n        \"12\": 3,\n        \"13\": 2,\n        \"14\": 7,\n        \"15\": -1,\n        \"16\": 1,\n        \"17\": 2,\n        \"18\": 2,\n        \"19\": 2,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 3,\n        \"24\": 3,\n        \"25\": 3,\n        \"26\": 1,\n        \"27\": 1,\n        \"28\": 1,\n        \"29\": -1,\n        \"30\": 3,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": -1,\n        \"35\": 3,\n        \"36\": 3,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 7,\n        \"44\": 2,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2\n      }\n    },\n    \"756\": {\n      \"s2c\": {\n        \"0\": 2,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": 1,\n        \"5\": 4,\n        \"6\": 2,\n        \"7\": -1,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 7,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 1,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 3,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 4,\n        \"26\": -1,\n        \"27\": 2,\n        \"28\": 2,\n        \"29\": 7,\n        \"30\": 2,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": 7,\n        \"35\": 7,\n        \"36\": 4,\n        \"37\": 7,\n        \"38\": 2,\n        \"39\": 4,\n        \"40\": 3,\n        \"41\": 2,\n        \"42\": 2,\n        \"43\": 2,\n        \"44\": 2,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 7,\n        \"48\": -1,\n        \"49\": 3,\n        \"50\": 2,\n        \"51\": 2,\n        \"52\": 2,\n        \"53\": 1,\n        \"54\": 1,\n        \"55\": 1,\n        \"56\": 1,\n        \"57\": 3,\n        \"58\": 2,\n        \"59\": 2,\n        \"60\": -1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 7,\n        \"64\": -1,\n        \"65\": 1,\n        \"66\": 3,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 3,\n        \"71\": 2,\n        \"72\": 3,\n        \"73\": 7,\n        \"74\": 7,\n        \"75\": 2,\n        \"76\": 1,\n        \"77\": 2,\n        \"78\": 2,\n        \"79\": 2,\n        \"80\": 2,\n        \"81\": 1,\n        \"82\": 1,\n        \"83\": 1,\n        \"84\": 2,\n        \"85\": 1,\n        \"86\": 1,\n        \"87\": 1,\n        \"88\": 1,\n        \"89\": 1,\n        \"90\": 1,\n        \"91\": 4,\n        \"92\": 4,\n        \"93\": 4,\n        \"94\": 1,\n        \"95\": 3,\n        \"96\": 2,\n        \"97\": 2,\n        \"98\": 1,\n        \"99\": 2,\n        \"100\": 2,\n        \"101\": 1,\n        \"102\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 3,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 3,\n        \"10\": 3,\n        \"11\": 3,\n        \"12\": 3,\n        \"13\": 2,\n        \"14\": 7,\n        \"15\": -1,\n        \"16\": 1,\n        \"17\": 2,\n        \"18\": 2,\n        \"19\": 2,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 3,\n        \"24\": 3,\n        \"25\": 3,\n        \"26\": 1,\n        \"27\": 1,\n        \"28\": 1,\n        \"29\": -1,\n        \"30\": 3,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": -1,\n        \"35\": 3,\n        \"36\": 3,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 7,\n        \"44\": 2,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2\n      }\n    },\n    \"757\": {\n      \"s2c\": {\n        \"0\": 2,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": 1,\n        \"5\": 4,\n        \"6\": 2,\n        \"7\": -1,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 7,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 1,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 3,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 4,\n        \"26\": -1,\n        \"27\": 2,\n        \"28\": 2,\n        \"29\": 7,\n        \"30\": 2,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": 7,\n        \"35\": 7,\n        \"36\": 4,\n        \"37\": 7,\n        \"38\": 2,\n        \"39\": 4,\n        \"40\": 3,\n        \"41\": 2,\n        \"42\": 2,\n        \"43\": 2,\n        \"44\": 2,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 7,\n        \"48\": -1,\n        \"49\": 3,\n        \"50\": 2,\n        \"51\": 2,\n        \"52\": 2,\n        \"53\": 1,\n        \"54\": 1,\n        \"55\": 1,\n        \"56\": 1,\n        \"57\": 3,\n        \"58\": 2,\n        \"59\": 2,\n        \"60\": -1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 7,\n        \"64\": -1,\n        \"65\": 1,\n        \"66\": 3,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 3,\n        \"71\": 2,\n        \"72\": 3,\n        \"73\": 7,\n        \"74\": 7,\n        \"75\": 2,\n        \"76\": 1,\n        \"77\": 2,\n        \"78\": 2,\n        \"79\": 2,\n        \"80\": 2,\n        \"81\": 1,\n        \"82\": 1,\n        \"83\": 1,\n        \"84\": 2,\n        \"85\": 1,\n        \"86\": 1,\n        \"87\": 7,\n        \"88\": 1,\n        \"89\": 1,\n        \"90\": 1,\n        \"91\": 1,\n        \"92\": 4,\n        \"93\": 4,\n        \"94\": 4,\n        \"95\": 1,\n        \"96\": 3,\n        \"97\": 2,\n        \"98\": 2,\n        \"99\": 1,\n        \"100\": 2,\n        \"101\": 2,\n        \"102\": 1,\n        \"103\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 3,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 3,\n        \"10\": 3,\n        \"11\": 3,\n        \"12\": 3,\n        \"13\": 2,\n        \"14\": 7,\n        \"15\": -1,\n        \"16\": 1,\n        \"17\": 2,\n        \"18\": 2,\n        \"19\": 2,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 3,\n        \"24\": 3,\n        \"25\": 3,\n        \"26\": 1,\n        \"27\": 1,\n        \"28\": 1,\n        \"29\": -1,\n        \"30\": 3,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": -1,\n        \"35\": 3,\n        \"36\": 3,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 7,\n        \"44\": 2,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2\n      }\n    },\n    \"758\": {\n      \"s2c\": {\n        \"0\": 2,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": 1,\n        \"5\": 4,\n        \"6\": 2,\n        \"7\": -1,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 7,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 1,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 3,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 4,\n        \"26\": -1,\n        \"27\": 2,\n        \"28\": 2,\n        \"29\": 7,\n        \"30\": 2,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": 7,\n        \"35\": 7,\n        \"36\": 4,\n        \"37\": 7,\n        \"38\": 2,\n        \"39\": 4,\n        \"40\": 3,\n        \"41\": 2,\n        \"42\": 2,\n        \"43\": 2,\n        \"44\": 2,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 7,\n        \"48\": -1,\n        \"49\": 3,\n        \"50\": 2,\n        \"51\": 2,\n        \"52\": 2,\n        \"53\": 1,\n        \"54\": 1,\n        \"55\": 1,\n        \"56\": 1,\n        \"57\": 3,\n        \"58\": 2,\n        \"59\": 2,\n        \"60\": -1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 7,\n        \"64\": -1,\n        \"65\": 1,\n        \"66\": 3,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 3,\n        \"71\": 2,\n        \"72\": 3,\n        \"73\": 7,\n        \"74\": 7,\n        \"75\": 2,\n        \"76\": 1,\n        \"77\": 2,\n        \"78\": 2,\n        \"79\": 2,\n        \"80\": 2,\n        \"81\": 1,\n        \"82\": 1,\n        \"83\": 1,\n        \"84\": 2,\n        \"85\": 1,\n        \"86\": 1,\n        \"87\": 7,\n        \"88\": 1,\n        \"89\": 1,\n        \"90\": 1,\n        \"91\": 1,\n        \"92\": 4,\n        \"93\": 4,\n        \"94\": 4,\n        \"95\": 1,\n        \"96\": 3,\n        \"97\": 2,\n        \"98\": 2,\n        \"99\": 1,\n        \"100\": 2,\n        \"101\": 2,\n        \"102\": 1,\n        \"103\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 3,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 3,\n        \"10\": 3,\n        \"11\": 3,\n        \"12\": 3,\n        \"13\": 2,\n        \"14\": 7,\n        \"15\": -1,\n        \"16\": 1,\n        \"17\": 2,\n        \"18\": 2,\n        \"19\": 2,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 3,\n        \"24\": 3,\n        \"25\": 3,\n        \"26\": 1,\n        \"27\": 1,\n        \"28\": 1,\n        \"29\": -1,\n        \"30\": 3,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": -1,\n        \"35\": 3,\n        \"36\": 3,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 7,\n        \"44\": 2,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2\n      }\n    },\n    \"759\": {\n      \"s2c\": {\n        \"0\": 2,\n        \"1\": 2,\n        \"2\": 1,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 1,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 3,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 1,\n        \"21\": 3,\n        \"22\": 4,\n        \"23\": -1,\n        \"24\": 2,\n        \"25\": 2,\n        \"26\": 7,\n        \"27\": 2,\n        \"28\": 3,\n        \"29\": 3,\n        \"30\": -1,\n        \"31\": 7,\n        \"32\": 7,\n        \"33\": 4,\n        \"34\": 7,\n        \"35\": 2,\n        \"36\": 4,\n        \"37\": 3,\n        \"38\": 2,\n        \"39\": 2,\n        \"40\": 2,\n        \"41\": 2,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 7,\n        \"45\": -1,\n        \"46\": 3,\n        \"47\": 2,\n        \"48\": 1,\n        \"49\": 2,\n        \"50\": 2,\n        \"51\": 1,\n        \"52\": 1,\n        \"53\": 1,\n        \"54\": 1,\n        \"55\": 3,\n        \"56\": 2,\n        \"57\": 2,\n        \"58\": -1,\n        \"59\": 3,\n        \"60\": 2,\n        \"61\": 7,\n        \"62\": -1,\n        \"63\": 1,\n        \"64\": 1,\n        \"65\": 3,\n        \"66\": 3,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 2,\n        \"71\": 3,\n        \"72\": 7,\n        \"73\": 7,\n        \"74\": 2,\n        \"75\": 1,\n        \"76\": 1,\n        \"77\": 2,\n        \"78\": 2,\n        \"79\": 2,\n        \"80\": 2,\n        \"81\": 1,\n        \"82\": 1,\n        \"83\": 1,\n        \"84\": 2,\n        \"85\": 1,\n        \"86\": 1,\n        \"87\": 7,\n        \"88\": 1,\n        \"89\": 1,\n        \"90\": 1,\n        \"91\": 1,\n        \"92\": 4,\n        \"93\": 4,\n        \"94\": 4,\n        \"95\": 1,\n        \"96\": 1,\n        \"97\": 3,\n        \"98\": 2,\n        \"99\": 2,\n        \"100\": 1,\n        \"101\": 2,\n        \"102\": 2,\n        \"103\": 1,\n        \"104\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 3,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 3,\n        \"12\": 3,\n        \"13\": 3,\n        \"14\": 3,\n        \"15\": 2,\n        \"16\": 7,\n        \"17\": -1,\n        \"18\": 1,\n        \"19\": 2,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 2,\n        \"24\": 2,\n        \"25\": 3,\n        \"26\": 3,\n        \"27\": 3,\n        \"28\": 1,\n        \"29\": 1,\n        \"30\": 1,\n        \"31\": -1,\n        \"32\": 3,\n        \"33\": 3,\n        \"34\": 3,\n        \"35\": -1,\n        \"36\": -1,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 7,\n        \"46\": 2,\n        \"47\": 3,\n        \"48\": 2,\n        \"49\": 2\n      }\n    },\n    \"760\": {\n      \"s2c\": {\n        \"0\": 2,\n        \"1\": 2,\n        \"2\": 1,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 1,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 3,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 1,\n        \"21\": 1,\n        \"22\": 3,\n        \"23\": 4,\n        \"24\": 1,\n        \"25\": -1,\n        \"26\": 2,\n        \"27\": 2,\n        \"28\": 7,\n        \"29\": 2,\n        \"30\": 3,\n        \"31\": 3,\n        \"32\": -1,\n        \"33\": 7,\n        \"34\": 7,\n        \"35\": 4,\n        \"36\": 7,\n        \"37\": 2,\n        \"38\": 4,\n        \"39\": 3,\n        \"40\": 2,\n        \"41\": 2,\n        \"42\": 2,\n        \"43\": 2,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 7,\n        \"47\": -1,\n        \"48\": 3,\n        \"49\": 2,\n        \"50\": 1,\n        \"51\": 1,\n        \"52\": 2,\n        \"53\": 2,\n        \"54\": 1,\n        \"55\": 1,\n        \"56\": 1,\n        \"57\": 1,\n        \"58\": 3,\n        \"59\": 2,\n        \"60\": 2,\n        \"61\": -1,\n        \"62\": 3,\n        \"63\": 2,\n        \"64\": 7,\n        \"65\": -1,\n        \"66\": 1,\n        \"67\": 1,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 3,\n        \"71\": 3,\n        \"72\": 3,\n        \"73\": 2,\n        \"74\": 3,\n        \"75\": 7,\n        \"76\": 7,\n        \"77\": 2,\n        \"78\": 1,\n        \"79\": 1,\n        \"80\": 2,\n        \"81\": 2,\n        \"82\": 2,\n        \"83\": 2,\n        \"84\": 1,\n        \"85\": 1,\n        \"86\": 1,\n        \"87\": 2,\n        \"88\": 1,\n        \"89\": 1,\n        \"90\": 7,\n        \"91\": 1,\n        \"92\": 1,\n        \"93\": 1,\n        \"94\": 1,\n        \"95\": 4,\n        \"96\": 4,\n        \"97\": 4,\n        \"98\": 1,\n        \"99\": 1,\n        \"100\": 3,\n        \"101\": 2,\n        \"102\": 2,\n        \"103\": 1,\n        \"104\": 2,\n        \"105\": 2,\n        \"106\": 1,\n        \"107\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 3,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 3,\n        \"13\": 3,\n        \"14\": 3,\n        \"15\": 3,\n        \"16\": 2,\n        \"17\": 7,\n        \"18\": -1,\n        \"19\": 1,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 2,\n        \"24\": 2,\n        \"25\": 2,\n        \"26\": 3,\n        \"27\": 3,\n        \"28\": 3,\n        \"29\": 1,\n        \"30\": 1,\n        \"31\": 1,\n        \"32\": -1,\n        \"33\": 3,\n        \"34\": 3,\n        \"35\": 3,\n        \"36\": -1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 7,\n        \"47\": 2,\n        \"48\": 3,\n        \"49\": 2,\n        \"50\": 2\n      }\n    },\n    \"761\": {\n      \"s2c\": {\n        \"0\": 2,\n        \"1\": 2,\n        \"2\": 1,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 1,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 3,\n        \"16\": 3,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 1,\n        \"20\": 1,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": -1,\n        \"24\": 1,\n        \"25\": 2,\n        \"26\": 2,\n        \"27\": 7,\n        \"28\": 2,\n        \"29\": 3,\n        \"30\": 3,\n        \"31\": -1,\n        \"32\": 7,\n        \"33\": 7,\n        \"34\": 4,\n        \"35\": 7,\n        \"36\": 2,\n        \"37\": 4,\n        \"38\": 3,\n        \"39\": 2,\n        \"40\": 2,\n        \"41\": 2,\n        \"42\": 2,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 7,\n        \"46\": -1,\n        \"47\": 3,\n        \"48\": 2,\n        \"49\": 1,\n        \"50\": 2,\n        \"51\": 2,\n        \"52\": 1,\n        \"53\": 1,\n        \"54\": 1,\n        \"55\": 1,\n        \"56\": 1,\n        \"57\": 3,\n        \"58\": 2,\n        \"59\": 2,\n        \"60\": -1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 7,\n        \"64\": -1,\n        \"65\": 1,\n        \"66\": 1,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 3,\n        \"71\": 3,\n        \"72\": 2,\n        \"73\": 3,\n        \"74\": 7,\n        \"75\": 7,\n        \"76\": 2,\n        \"77\": 1,\n        \"78\": 2,\n        \"79\": 2,\n        \"80\": 2,\n        \"81\": 2,\n        \"82\": 1,\n        \"83\": 1,\n        \"84\": 1,\n        \"85\": 2,\n        \"86\": 1,\n        \"87\": 1,\n        \"88\": 7,\n        \"89\": 1,\n        \"90\": 1,\n        \"91\": 1,\n        \"92\": 1,\n        \"93\": 4,\n        \"94\": 4,\n        \"95\": 4,\n        \"96\": 1,\n        \"97\": 1,\n        \"98\": 3,\n        \"99\": 2,\n        \"100\": 2,\n        \"101\": 1,\n        \"102\": 2,\n        \"103\": 2,\n        \"104\": 2,\n        \"105\": 1,\n        \"106\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 3,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 3,\n        \"12\": 3,\n        \"13\": 3,\n        \"14\": 3,\n        \"15\": 2,\n        \"16\": 7,\n        \"17\": -1,\n        \"18\": 1,\n        \"19\": 2,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 2,\n        \"24\": 2,\n        \"25\": 3,\n        \"26\": 3,\n        \"27\": 3,\n        \"28\": 1,\n        \"29\": 1,\n        \"30\": 1,\n        \"31\": -1,\n        \"32\": 1,\n        \"33\": 3,\n        \"34\": 3,\n        \"35\": 3,\n        \"36\": -1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 7,\n        \"47\": 2,\n        \"48\": 3,\n        \"49\": 2,\n        \"50\": 2\n      }\n    },\n    \"762\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 1,\n        \"4\": 2,\n        \"5\": -1,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 7,\n        \"11\": 1,\n        \"12\": 1,\n        \"13\": 7,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 1,\n        \"23\": 3,\n        \"24\": 2,\n        \"25\": 1,\n        \"26\": -1,\n        \"27\": 1,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 7,\n        \"31\": 2,\n        \"32\": 3,\n        \"33\": 2,\n        \"34\": 3,\n        \"35\": -1,\n        \"36\": 7,\n        \"37\": 7,\n        \"38\": 4,\n        \"39\": 7,\n        \"40\": 2,\n        \"41\": 4,\n        \"42\": 3,\n        \"43\": 2,\n        \"44\": 2,\n        \"45\": 2,\n        \"46\": 2,\n        \"47\": 3,\n        \"48\": 3,\n        \"49\": 7,\n        \"50\": -1,\n        \"51\": 3,\n        \"52\": 2,\n        \"53\": 1,\n        \"54\": 2,\n        \"55\": 2,\n        \"56\": 1,\n        \"57\": 1,\n        \"58\": 1,\n        \"59\": 1,\n        \"60\": 1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 2,\n        \"64\": -1,\n        \"65\": 3,\n        \"66\": 2,\n        \"67\": 7,\n        \"68\": -1,\n        \"69\": 1,\n        \"70\": 1,\n        \"71\": 3,\n        \"72\": 3,\n        \"73\": 3,\n        \"74\": 3,\n        \"75\": 3,\n        \"76\": 2,\n        \"77\": 3,\n        \"78\": 7,\n        \"79\": 7,\n        \"80\": 2,\n        \"81\": 1,\n        \"82\": 2,\n        \"83\": 2,\n        \"84\": 2,\n        \"85\": 2,\n        \"86\": 1,\n        \"87\": 1,\n        \"88\": 1,\n        \"89\": 2,\n        \"90\": 1,\n        \"91\": 1,\n        \"92\": 7,\n        \"93\": 1,\n        \"94\": 1,\n        \"95\": 1,\n        \"96\": 1,\n        \"97\": 4,\n        \"98\": 4,\n        \"99\": 4,\n        \"100\": 1,\n        \"101\": 1,\n        \"102\": 3,\n        \"103\": 2,\n        \"104\": 2,\n        \"105\": 1,\n        \"106\": 2,\n        \"107\": 2,\n        \"108\": 2,\n        \"109\": 1,\n        \"110\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 3,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 3,\n        \"13\": 3,\n        \"14\": 3,\n        \"15\": 3,\n        \"16\": 2,\n        \"17\": 7,\n        \"18\": -1,\n        \"19\": 1,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 2,\n        \"24\": 2,\n        \"25\": 2,\n        \"26\": 3,\n        \"27\": 3,\n        \"28\": 3,\n        \"29\": 1,\n        \"30\": 1,\n        \"31\": 1,\n        \"32\": -1,\n        \"33\": 3,\n        \"34\": 3,\n        \"35\": 3,\n        \"36\": -1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 7,\n        \"47\": 2,\n        \"48\": 3,\n        \"49\": 2,\n        \"50\": 2\n      }\n    },\n    \"763\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 1,\n        \"4\": 2,\n        \"5\": -1,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 7,\n        \"11\": 1,\n        \"12\": 1,\n        \"13\": 7,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 1,\n        \"23\": 3,\n        \"24\": 2,\n        \"25\": 1,\n        \"26\": -1,\n        \"27\": 1,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 7,\n        \"31\": 2,\n        \"32\": 3,\n        \"33\": 2,\n        \"34\": 3,\n        \"35\": -1,\n        \"36\": 7,\n        \"37\": 7,\n        \"38\": 4,\n        \"39\": 7,\n        \"40\": 2,\n        \"41\": 4,\n        \"42\": 3,\n        \"43\": 2,\n        \"44\": 2,\n        \"45\": 2,\n        \"46\": 2,\n        \"47\": 3,\n        \"48\": 3,\n        \"49\": 7,\n        \"50\": -1,\n        \"51\": 3,\n        \"52\": 2,\n        \"53\": 1,\n        \"54\": 2,\n        \"55\": 2,\n        \"56\": 1,\n        \"57\": 1,\n        \"58\": 1,\n        \"59\": 1,\n        \"60\": 1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 2,\n        \"64\": -1,\n        \"65\": 3,\n        \"66\": 2,\n        \"67\": 7,\n        \"68\": -1,\n        \"69\": 1,\n        \"70\": 1,\n        \"71\": 3,\n        \"72\": 3,\n        \"73\": 3,\n        \"74\": 3,\n        \"75\": 3,\n        \"76\": 2,\n        \"77\": 3,\n        \"78\": 7,\n        \"79\": 7,\n        \"80\": 2,\n        \"81\": 1,\n        \"82\": 2,\n        \"83\": 2,\n        \"84\": 2,\n        \"85\": 2,\n        \"86\": 1,\n        \"87\": 1,\n        \"88\": 1,\n        \"89\": 2,\n        \"90\": 1,\n        \"91\": 1,\n        \"92\": 7,\n        \"93\": 1,\n        \"94\": 1,\n        \"95\": 1,\n        \"96\": 1,\n        \"97\": 4,\n        \"98\": 4,\n        \"99\": 4,\n        \"100\": 1,\n        \"101\": 1,\n        \"102\": 3,\n        \"103\": 2,\n        \"104\": 2,\n        \"105\": 1,\n        \"106\": 2,\n        \"107\": 2,\n        \"108\": 2,\n        \"109\": 1,\n        \"110\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 3,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 3,\n        \"13\": 3,\n        \"14\": 3,\n        \"15\": 3,\n        \"16\": 2,\n        \"17\": 7,\n        \"18\": -1,\n        \"19\": 1,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 2,\n        \"24\": 2,\n        \"25\": 2,\n        \"26\": 3,\n        \"27\": 3,\n        \"28\": 3,\n        \"29\": 1,\n        \"30\": 1,\n        \"31\": 1,\n        \"32\": -1,\n        \"33\": 3,\n        \"34\": 3,\n        \"35\": 3,\n        \"36\": -1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 7,\n        \"47\": 2,\n        \"48\": 3,\n        \"49\": 2,\n        \"50\": 2\n      }\n    },\n    \"764\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 7,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 1,\n        \"27\": -1,\n        \"28\": 1,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 7,\n        \"32\": 2,\n        \"33\": 3,\n        \"34\": 2,\n        \"35\": 3,\n        \"36\": -1,\n        \"37\": 7,\n        \"38\": 7,\n        \"39\": 4,\n        \"40\": 7,\n        \"41\": 2,\n        \"42\": 4,\n        \"43\": 3,\n        \"44\": 2,\n        \"45\": 2,\n        \"46\": 2,\n        \"47\": 2,\n        \"48\": 3,\n        \"49\": 3,\n        \"50\": 7,\n        \"51\": -1,\n        \"52\": -1,\n        \"53\": 3,\n        \"54\": 2,\n        \"55\": 1,\n        \"56\": 2,\n        \"57\": 2,\n        \"58\": 1,\n        \"59\": 1,\n        \"60\": 1,\n        \"61\": 1,\n        \"62\": 1,\n        \"63\": 3,\n        \"64\": 2,\n        \"65\": 2,\n        \"66\": -1,\n        \"67\": 3,\n        \"68\": 2,\n        \"69\": 7,\n        \"70\": -1,\n        \"71\": 1,\n        \"72\": 1,\n        \"73\": 3,\n        \"74\": 3,\n        \"75\": 3,\n        \"76\": 3,\n        \"77\": 3,\n        \"78\": 2,\n        \"79\": 3,\n        \"80\": 7,\n        \"81\": 7,\n        \"82\": 2,\n        \"83\": 1,\n        \"84\": 2,\n        \"85\": 2,\n        \"86\": 2,\n        \"87\": 2,\n        \"88\": 1,\n        \"89\": 1,\n        \"90\": 1,\n        \"91\": 2,\n        \"92\": 1,\n        \"93\": 1,\n        \"94\": 7,\n        \"95\": 1,\n        \"96\": 1,\n        \"97\": 1,\n        \"98\": 1,\n        \"99\": 4,\n        \"100\": 4,\n        \"101\": 0,\n        \"102\": 4,\n        \"103\": 1,\n        \"104\": 1,\n        \"105\": 3,\n        \"106\": 2,\n        \"107\": 2,\n        \"108\": 1,\n        \"109\": 2,\n        \"110\": 2,\n        \"111\": 1,\n        \"112\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 7,\n        \"8\": 3,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 0,\n        \"12\": 1,\n        \"13\": 1,\n        \"14\": 3,\n        \"15\": 3,\n        \"16\": 3,\n        \"17\": 3,\n        \"18\": 2,\n        \"19\": 7,\n        \"20\": -1,\n        \"21\": 1,\n        \"22\": 2,\n        \"23\": 2,\n        \"24\": 2,\n        \"25\": 2,\n        \"26\": 2,\n        \"27\": 2,\n        \"28\": 3,\n        \"29\": -1,\n        \"30\": 3,\n        \"31\": 3,\n        \"32\": 1,\n        \"33\": 1,\n        \"34\": 1,\n        \"35\": -1,\n        \"36\": 3,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": -1,\n        \"40\": -1,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 3,\n        \"48\": 3,\n        \"49\": 7,\n        \"50\": 2,\n        \"51\": 3,\n        \"52\": 2,\n        \"53\": 2\n      }\n    },\n    \"765\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 7,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 1,\n        \"27\": -1,\n        \"28\": 1,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 7,\n        \"32\": 2,\n        \"33\": 3,\n        \"34\": 2,\n        \"35\": 3,\n        \"36\": -1,\n        \"37\": 7,\n        \"38\": 7,\n        \"39\": 4,\n        \"40\": 7,\n        \"41\": 2,\n        \"42\": 4,\n        \"43\": 3,\n        \"44\": 2,\n        \"45\": 2,\n        \"46\": 2,\n        \"47\": 2,\n        \"48\": 3,\n        \"49\": 3,\n        \"50\": 7,\n        \"51\": -1,\n        \"52\": -1,\n        \"53\": 3,\n        \"54\": 2,\n        \"55\": 1,\n        \"56\": 2,\n        \"57\": 2,\n        \"58\": 1,\n        \"59\": 1,\n        \"60\": 1,\n        \"61\": 1,\n        \"62\": 1,\n        \"63\": 3,\n        \"64\": 2,\n        \"65\": 2,\n        \"66\": 1,\n        \"67\": -1,\n        \"68\": -1,\n        \"69\": 3,\n        \"70\": 2,\n        \"71\": 7,\n        \"72\": -1,\n        \"73\": 1,\n        \"74\": 1,\n        \"75\": 3,\n        \"76\": 3,\n        \"77\": 3,\n        \"78\": 3,\n        \"79\": 3,\n        \"80\": 2,\n        \"81\": 3,\n        \"82\": 7,\n        \"83\": 7,\n        \"84\": 2,\n        \"85\": 1,\n        \"86\": 2,\n        \"87\": 2,\n        \"88\": 2,\n        \"89\": 2,\n        \"90\": 1,\n        \"91\": 1,\n        \"92\": 1,\n        \"93\": 2,\n        \"94\": 1,\n        \"95\": 1,\n        \"96\": 7,\n        \"97\": 1,\n        \"98\": 1,\n        \"99\": 1,\n        \"100\": 1,\n        \"101\": 4,\n        \"102\": 4,\n        \"103\": 0,\n        \"104\": 4,\n        \"105\": 1,\n        \"106\": 1,\n        \"107\": 3,\n        \"108\": 2,\n        \"109\": 2,\n        \"110\": 3,\n        \"111\": 3,\n        \"112\": 1,\n        \"113\": 2,\n        \"114\": 2,\n        \"115\": 1,\n        \"116\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 7,\n        \"8\": 3,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 0,\n        \"12\": 1,\n        \"13\": 1,\n        \"14\": 3,\n        \"15\": 3,\n        \"16\": 3,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 2,\n        \"20\": 7,\n        \"21\": -1,\n        \"22\": 1,\n        \"23\": 2,\n        \"24\": 2,\n        \"25\": 2,\n        \"26\": 2,\n        \"27\": 2,\n        \"28\": 2,\n        \"29\": 3,\n        \"30\": -1,\n        \"31\": 3,\n        \"32\": 3,\n        \"33\": 1,\n        \"34\": 1,\n        \"35\": 1,\n        \"36\": -1,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": -1,\n        \"41\": -1,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 3,\n        \"48\": 3,\n        \"49\": 3,\n        \"50\": 7,\n        \"51\": 2,\n        \"52\": 3,\n        \"53\": 2,\n        \"54\": 2\n      }\n    },\n    \"766\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 7,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 1,\n        \"25\": 3,\n        \"26\": 2,\n        \"27\": 1,\n        \"28\": 1,\n        \"29\": -1,\n        \"30\": 1,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 7,\n        \"34\": 2,\n        \"35\": 3,\n        \"36\": 2,\n        \"37\": 3,\n        \"38\": -1,\n        \"39\": 7,\n        \"40\": 7,\n        \"41\": 4,\n        \"42\": 7,\n        \"43\": 2,\n        \"44\": 4,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2,\n        \"48\": 2,\n        \"49\": 2,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 7,\n        \"53\": -1,\n        \"54\": -1,\n        \"55\": 3,\n        \"56\": 2,\n        \"57\": 1,\n        \"58\": 2,\n        \"59\": 2,\n        \"60\": 1,\n        \"61\": 1,\n        \"62\": 1,\n        \"63\": 1,\n        \"64\": 1,\n        \"65\": 3,\n        \"66\": 2,\n        \"67\": 2,\n        \"68\": 1,\n        \"69\": -1,\n        \"70\": -1,\n        \"71\": 3,\n        \"72\": 2,\n        \"73\": 7,\n        \"74\": -1,\n        \"75\": 1,\n        \"76\": 1,\n        \"77\": 3,\n        \"78\": 3,\n        \"79\": 3,\n        \"80\": 3,\n        \"81\": 3,\n        \"82\": 2,\n        \"83\": 3,\n        \"84\": 7,\n        \"85\": 7,\n        \"86\": 2,\n        \"87\": 1,\n        \"88\": 2,\n        \"89\": 2,\n        \"90\": 2,\n        \"91\": 2,\n        \"92\": 1,\n        \"93\": 1,\n        \"94\": 1,\n        \"95\": 2,\n        \"96\": 1,\n        \"97\": 1,\n        \"98\": 7,\n        \"99\": 1,\n        \"100\": 1,\n        \"101\": 1,\n        \"102\": 1,\n        \"103\": 4,\n        \"104\": 4,\n        \"105\": 0,\n        \"106\": 4,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 1,\n        \"110\": 3,\n        \"111\": 2,\n        \"112\": 2,\n        \"113\": 3,\n        \"114\": 3,\n        \"115\": 0,\n        \"116\": 1,\n        \"117\": 2,\n        \"118\": 2,\n        \"119\": 1,\n        \"120\": 1,\n        \"121\": 2\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 7,\n        \"9\": 3,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 0,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 3,\n        \"16\": 3,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 1,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 2,\n        \"23\": 7,\n        \"24\": -1,\n        \"25\": 1,\n        \"26\": 2,\n        \"27\": 2,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": 3,\n        \"35\": 3,\n        \"36\": 1,\n        \"37\": 1,\n        \"38\": 1,\n        \"39\": -1,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": -1,\n        \"44\": -1,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 3,\n        \"48\": 3,\n        \"49\": 3,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 7,\n        \"54\": 2,\n        \"55\": 3,\n        \"56\": 2,\n        \"57\": 2\n      }\n    },\n    \"767\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 7,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 1,\n        \"25\": 3,\n        \"26\": 2,\n        \"27\": 1,\n        \"28\": 1,\n        \"29\": -1,\n        \"30\": 1,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 7,\n        \"34\": 2,\n        \"35\": 3,\n        \"36\": 2,\n        \"37\": 3,\n        \"38\": -1,\n        \"39\": 7,\n        \"40\": 7,\n        \"41\": 4,\n        \"42\": 7,\n        \"43\": 2,\n        \"44\": 4,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2,\n        \"48\": 2,\n        \"49\": 2,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 7,\n        \"53\": -1,\n        \"54\": -1,\n        \"55\": 3,\n        \"56\": 2,\n        \"57\": 1,\n        \"58\": 2,\n        \"59\": 2,\n        \"60\": 1,\n        \"61\": 1,\n        \"62\": 1,\n        \"63\": 1,\n        \"64\": 1,\n        \"65\": 3,\n        \"66\": 2,\n        \"67\": 2,\n        \"68\": 1,\n        \"69\": -1,\n        \"70\": -1,\n        \"71\": 3,\n        \"72\": 2,\n        \"73\": 7,\n        \"74\": -1,\n        \"75\": 1,\n        \"76\": 1,\n        \"77\": 3,\n        \"78\": 3,\n        \"79\": 3,\n        \"80\": 3,\n        \"81\": 3,\n        \"82\": 2,\n        \"83\": 3,\n        \"84\": 7,\n        \"85\": 7,\n        \"86\": 2,\n        \"87\": 1,\n        \"88\": 2,\n        \"89\": 2,\n        \"90\": 2,\n        \"91\": 2,\n        \"92\": 1,\n        \"93\": 1,\n        \"94\": 1,\n        \"95\": 2,\n        \"96\": 1,\n        \"97\": 1,\n        \"98\": 7,\n        \"99\": 1,\n        \"100\": 1,\n        \"101\": 1,\n        \"102\": 1,\n        \"103\": 4,\n        \"104\": 4,\n        \"105\": 0,\n        \"106\": 4,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 1,\n        \"110\": 3,\n        \"111\": 2,\n        \"112\": 2,\n        \"113\": 3,\n        \"114\": 3,\n        \"115\": 0,\n        \"116\": 1,\n        \"117\": 2,\n        \"118\": 2,\n        \"119\": 1,\n        \"120\": 1,\n        \"121\": 2,\n        \"122\": -1,\n        \"123\": -1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 7,\n        \"9\": 3,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 0,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 3,\n        \"16\": 3,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 1,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 2,\n        \"23\": 7,\n        \"24\": -1,\n        \"25\": 1,\n        \"26\": 2,\n        \"27\": 2,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 3,\n        \"33\": -1,\n        \"34\": 3,\n        \"35\": 3,\n        \"36\": 1,\n        \"37\": 1,\n        \"38\": 1,\n        \"39\": -1,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": -1,\n        \"44\": -1,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 3,\n        \"48\": 3,\n        \"49\": 3,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 7,\n        \"54\": 2,\n        \"55\": 3,\n        \"56\": 2,\n        \"57\": 2\n      }\n    },\n    \"768\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 7,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 1,\n        \"25\": 3,\n        \"26\": 2,\n        \"27\": 1,\n        \"28\": 1,\n        \"29\": -1,\n        \"30\": 1,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 7,\n        \"35\": 2,\n        \"36\": 3,\n        \"37\": 2,\n        \"38\": 3,\n        \"39\": -1,\n        \"40\": 7,\n        \"41\": 7,\n        \"42\": 4,\n        \"43\": 7,\n        \"44\": 2,\n        \"45\": 4,\n        \"46\": 3,\n        \"47\": 2,\n        \"48\": 2,\n        \"49\": 2,\n        \"50\": 2,\n        \"51\": 2,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 7,\n        \"55\": -1,\n        \"56\": -1,\n        \"57\": 3,\n        \"58\": 2,\n        \"59\": 1,\n        \"60\": 2,\n        \"61\": 2,\n        \"62\": 1,\n        \"63\": 1,\n        \"64\": 1,\n        \"65\": 1,\n        \"66\": 1,\n        \"67\": 2,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 3,\n        \"71\": 2,\n        \"72\": 2,\n        \"73\": 1,\n        \"74\": -1,\n        \"75\": -1,\n        \"76\": 3,\n        \"77\": 2,\n        \"78\": 7,\n        \"79\": -1,\n        \"80\": 1,\n        \"81\": 1,\n        \"82\": 3,\n        \"83\": 3,\n        \"84\": 3,\n        \"85\": 3,\n        \"86\": 3,\n        \"87\": 2,\n        \"88\": 7,\n        \"89\": 7,\n        \"90\": 3,\n        \"91\": 2,\n        \"92\": 1,\n        \"93\": 2,\n        \"94\": 2,\n        \"95\": 2,\n        \"96\": 2,\n        \"97\": 1,\n        \"98\": 1,\n        \"99\": 3,\n        \"100\": 1,\n        \"101\": 2,\n        \"102\": 3,\n        \"103\": 1,\n        \"104\": 1,\n        \"105\": 7,\n        \"106\": 1,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 1,\n        \"110\": 4,\n        \"111\": 4,\n        \"112\": 0,\n        \"113\": 4,\n        \"114\": 1,\n        \"115\": 1,\n        \"116\": 1,\n        \"117\": 3,\n        \"118\": 2,\n        \"119\": 2,\n        \"120\": 3,\n        \"121\": 3,\n        \"122\": 0,\n        \"123\": 1,\n        \"124\": 2,\n        \"125\": 2,\n        \"126\": 1,\n        \"127\": 1,\n        \"128\": 2,\n        \"129\": -1,\n        \"130\": -1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 3,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 7,\n        \"10\": 3,\n        \"11\": 2,\n        \"12\": 1,\n        \"13\": 1,\n        \"14\": 0,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 1,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 3,\n        \"23\": 3,\n        \"24\": 2,\n        \"25\": 7,\n        \"26\": -1,\n        \"27\": 1,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 3,\n        \"35\": -1,\n        \"36\": 3,\n        \"37\": 3,\n        \"38\": 1,\n        \"39\": 1,\n        \"40\": 1,\n        \"41\": -1,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": -1,\n        \"46\": -1,\n        \"47\": 3,\n        \"48\": 3,\n        \"49\": 3,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 3,\n        \"55\": 7,\n        \"56\": 2,\n        \"57\": 3,\n        \"58\": 2,\n        \"59\": 2\n      }\n    },\n    \"769\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 2,\n        \"4\": -1,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 7,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 1,\n        \"25\": 3,\n        \"26\": 2,\n        \"27\": 1,\n        \"28\": 1,\n        \"29\": -1,\n        \"30\": 1,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 7,\n        \"35\": 2,\n        \"36\": 3,\n        \"37\": 2,\n        \"38\": 3,\n        \"39\": -1,\n        \"40\": 7,\n        \"41\": 7,\n        \"42\": 4,\n        \"43\": 7,\n        \"44\": 2,\n        \"45\": 4,\n        \"46\": 3,\n        \"47\": 2,\n        \"48\": 2,\n        \"49\": 2,\n        \"50\": 2,\n        \"51\": 2,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 7,\n        \"55\": -1,\n        \"56\": -1,\n        \"57\": 3,\n        \"58\": 2,\n        \"59\": 1,\n        \"60\": 2,\n        \"61\": 2,\n        \"62\": 1,\n        \"63\": 1,\n        \"64\": 1,\n        \"65\": 1,\n        \"66\": 1,\n        \"67\": 2,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 3,\n        \"71\": 2,\n        \"72\": 2,\n        \"73\": 1,\n        \"74\": -1,\n        \"75\": -1,\n        \"76\": 3,\n        \"77\": 2,\n        \"78\": 7,\n        \"79\": -1,\n        \"80\": 1,\n        \"81\": 1,\n        \"82\": 3,\n        \"83\": 3,\n        \"84\": 3,\n        \"85\": 3,\n        \"86\": 3,\n        \"87\": 2,\n        \"88\": 7,\n        \"89\": 7,\n        \"90\": 3,\n        \"91\": 2,\n        \"92\": 1,\n        \"93\": 2,\n        \"94\": 2,\n        \"95\": 2,\n        \"96\": 2,\n        \"97\": 1,\n        \"98\": 1,\n        \"99\": 3,\n        \"100\": 1,\n        \"101\": 2,\n        \"102\": 3,\n        \"103\": 1,\n        \"104\": 1,\n        \"105\": 7,\n        \"106\": 1,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 1,\n        \"110\": 4,\n        \"111\": 4,\n        \"112\": 0,\n        \"113\": 4,\n        \"114\": 1,\n        \"115\": 1,\n        \"116\": 1,\n        \"117\": 3,\n        \"118\": 2,\n        \"119\": 2,\n        \"120\": 3,\n        \"121\": 3,\n        \"122\": 0,\n        \"123\": 1,\n        \"124\": 2,\n        \"125\": 2,\n        \"126\": 1,\n        \"127\": 1,\n        \"128\": 2,\n        \"129\": -1,\n        \"130\": -1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 3,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 7,\n        \"10\": 3,\n        \"11\": 2,\n        \"12\": 1,\n        \"13\": 1,\n        \"14\": 0,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 1,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 3,\n        \"23\": 3,\n        \"24\": 2,\n        \"25\": 7,\n        \"26\": -1,\n        \"27\": 1,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 1,\n        \"35\": 1,\n        \"36\": -1,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": 1,\n        \"40\": 1,\n        \"41\": 1,\n        \"42\": 7,\n        \"43\": -1,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": -1,\n        \"48\": -1,\n        \"49\": 3,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 3,\n        \"55\": 3,\n        \"56\": 3,\n        \"57\": 7,\n        \"58\": 2,\n        \"59\": 3,\n        \"60\": 2,\n        \"61\": 2\n      }\n    },\n    \"770\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": -1,\n        \"4\": 7,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 1,\n        \"27\": 1,\n        \"28\": -1,\n        \"29\": 1,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 7,\n        \"34\": 2,\n        \"35\": 3,\n        \"36\": 2,\n        \"37\": 3,\n        \"38\": -1,\n        \"39\": 7,\n        \"40\": 7,\n        \"41\": 4,\n        \"42\": 7,\n        \"43\": 2,\n        \"44\": 4,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2,\n        \"48\": 2,\n        \"49\": 2,\n        \"50\": 2,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 7,\n        \"54\": -1,\n        \"55\": -1,\n        \"56\": 3,\n        \"57\": 2,\n        \"58\": 1,\n        \"59\": 2,\n        \"60\": 2,\n        \"61\": 1,\n        \"62\": 1,\n        \"63\": 1,\n        \"64\": 1,\n        \"65\": 1,\n        \"66\": 2,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 2,\n        \"71\": 2,\n        \"72\": 1,\n        \"73\": -1,\n        \"74\": -1,\n        \"75\": 3,\n        \"76\": 2,\n        \"77\": 7,\n        \"78\": -1,\n        \"79\": 1,\n        \"80\": 1,\n        \"81\": 3,\n        \"82\": 3,\n        \"83\": 3,\n        \"84\": 3,\n        \"85\": 3,\n        \"86\": 2,\n        \"87\": 7,\n        \"88\": 7,\n        \"89\": 3,\n        \"90\": 2,\n        \"91\": 1,\n        \"92\": 2,\n        \"93\": 2,\n        \"94\": 2,\n        \"95\": 2,\n        \"96\": 1,\n        \"97\": 1,\n        \"98\": 3,\n        \"99\": 1,\n        \"100\": 2,\n        \"101\": 3,\n        \"102\": 1,\n        \"103\": 1,\n        \"104\": 7,\n        \"105\": 1,\n        \"106\": 1,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 4,\n        \"110\": 4,\n        \"111\": 0,\n        \"112\": 4,\n        \"113\": 1,\n        \"114\": 1,\n        \"115\": 1,\n        \"116\": 3,\n        \"117\": 2,\n        \"118\": 2,\n        \"119\": 7,\n        \"120\": 3,\n        \"121\": 3,\n        \"122\": 0,\n        \"123\": 1,\n        \"124\": 2,\n        \"125\": 2,\n        \"126\": 1,\n        \"127\": 1,\n        \"128\": 2,\n        \"129\": -1,\n        \"130\": -1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 3,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 7,\n        \"10\": 3,\n        \"11\": 2,\n        \"12\": 1,\n        \"13\": 1,\n        \"14\": 0,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 1,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 3,\n        \"23\": 3,\n        \"24\": 2,\n        \"25\": 7,\n        \"26\": -1,\n        \"27\": 1,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 1,\n        \"35\": 1,\n        \"36\": -1,\n        \"37\": 3,\n        \"38\": 3,\n        \"39\": 1,\n        \"40\": 1,\n        \"41\": 1,\n        \"42\": 7,\n        \"43\": -1,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": -1,\n        \"48\": -1,\n        \"49\": 3,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 3,\n        \"55\": 3,\n        \"56\": 3,\n        \"57\": 3,\n        \"58\": 7,\n        \"59\": 2,\n        \"60\": 3,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 2\n      }\n    },\n    \"771\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": -1,\n        \"4\": 7,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 1,\n        \"27\": 1,\n        \"28\": -1,\n        \"29\": 1,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 7,\n        \"34\": 2,\n        \"35\": 3,\n        \"36\": 2,\n        \"37\": 3,\n        \"38\": -1,\n        \"39\": 7,\n        \"40\": 7,\n        \"41\": 4,\n        \"42\": 7,\n        \"43\": 2,\n        \"44\": 4,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2,\n        \"48\": 2,\n        \"49\": 2,\n        \"50\": 2,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 7,\n        \"54\": -1,\n        \"55\": -1,\n        \"56\": 3,\n        \"57\": 2,\n        \"58\": 1,\n        \"59\": 2,\n        \"60\": 2,\n        \"61\": 1,\n        \"62\": 1,\n        \"63\": 1,\n        \"64\": 1,\n        \"65\": 1,\n        \"66\": 2,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 2,\n        \"71\": 2,\n        \"72\": 1,\n        \"73\": -1,\n        \"74\": -1,\n        \"75\": 3,\n        \"76\": 2,\n        \"77\": 7,\n        \"78\": -1,\n        \"79\": 1,\n        \"80\": 1,\n        \"81\": 3,\n        \"82\": 3,\n        \"83\": 3,\n        \"84\": 3,\n        \"85\": 3,\n        \"86\": 2,\n        \"87\": 7,\n        \"88\": 7,\n        \"89\": 3,\n        \"90\": 2,\n        \"91\": 1,\n        \"92\": 2,\n        \"93\": 2,\n        \"94\": 2,\n        \"95\": 2,\n        \"96\": 1,\n        \"97\": 1,\n        \"98\": 3,\n        \"99\": 1,\n        \"100\": 2,\n        \"101\": 3,\n        \"102\": 1,\n        \"103\": 1,\n        \"104\": 7,\n        \"105\": 1,\n        \"106\": 1,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 4,\n        \"110\": 4,\n        \"111\": 0,\n        \"112\": 4,\n        \"113\": 1,\n        \"114\": 1,\n        \"115\": 1,\n        \"116\": 3,\n        \"117\": 2,\n        \"118\": 2,\n        \"119\": 7,\n        \"120\": 3,\n        \"121\": 3,\n        \"122\": 0,\n        \"123\": 1,\n        \"124\": 2,\n        \"125\": 2,\n        \"126\": 1,\n        \"127\": 1,\n        \"128\": 2,\n        \"129\": -1,\n        \"130\": -1,\n        \"131\": 1,\n        \"132\": 1,\n        \"133\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 3,\n        \"3\": 1,\n        \"4\": 2,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 7,\n        \"11\": 3,\n        \"12\": 2,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 0,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 1,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 3,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 7,\n        \"27\": -1,\n        \"28\": 1,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 2,\n        \"35\": 1,\n        \"36\": 1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 1,\n        \"41\": 1,\n        \"42\": 1,\n        \"43\": 7,\n        \"44\": -1,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 3,\n        \"48\": -1,\n        \"49\": -1,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 3,\n        \"55\": 3,\n        \"56\": 3,\n        \"57\": 3,\n        \"58\": 3,\n        \"59\": 7,\n        \"60\": 2,\n        \"61\": 3,\n        \"62\": 3,\n        \"63\": 2,\n        \"64\": 2,\n        \"65\": 1\n      }\n    },\n    \"772\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": -1,\n        \"4\": 7,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 1,\n        \"27\": 1,\n        \"28\": -1,\n        \"29\": 1,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 7,\n        \"34\": 2,\n        \"35\": 3,\n        \"36\": 2,\n        \"37\": 3,\n        \"38\": -1,\n        \"39\": 7,\n        \"40\": 7,\n        \"41\": 4,\n        \"42\": 7,\n        \"43\": 2,\n        \"44\": 4,\n        \"45\": 3,\n        \"46\": 2,\n        \"47\": 2,\n        \"48\": 2,\n        \"49\": 2,\n        \"50\": 2,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 7,\n        \"54\": -1,\n        \"55\": -1,\n        \"56\": 3,\n        \"57\": 2,\n        \"58\": 1,\n        \"59\": 2,\n        \"60\": 2,\n        \"61\": 1,\n        \"62\": 1,\n        \"63\": 1,\n        \"64\": 1,\n        \"65\": 1,\n        \"66\": 2,\n        \"67\": 3,\n        \"68\": 3,\n        \"69\": 3,\n        \"70\": 2,\n        \"71\": 2,\n        \"72\": 1,\n        \"73\": -1,\n        \"74\": -1,\n        \"75\": 3,\n        \"76\": 2,\n        \"77\": 7,\n        \"78\": -1,\n        \"79\": 1,\n        \"80\": 1,\n        \"81\": 3,\n        \"82\": 3,\n        \"83\": 3,\n        \"84\": 3,\n        \"85\": 3,\n        \"86\": 2,\n        \"87\": 7,\n        \"88\": 7,\n        \"89\": 3,\n        \"90\": 2,\n        \"91\": 1,\n        \"92\": 2,\n        \"93\": 2,\n        \"94\": 2,\n        \"95\": 2,\n        \"96\": 1,\n        \"97\": 1,\n        \"98\": 3,\n        \"99\": 1,\n        \"100\": 2,\n        \"101\": 3,\n        \"102\": 1,\n        \"103\": 1,\n        \"104\": 7,\n        \"105\": 1,\n        \"106\": 1,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 4,\n        \"110\": 4,\n        \"111\": 0,\n        \"112\": 4,\n        \"113\": 1,\n        \"114\": 1,\n        \"115\": 1,\n        \"116\": 3,\n        \"117\": 2,\n        \"118\": 2,\n        \"119\": 7,\n        \"120\": 3,\n        \"121\": 3,\n        \"122\": 0,\n        \"123\": 1,\n        \"124\": 2,\n        \"125\": 2,\n        \"126\": 1,\n        \"127\": 1,\n        \"128\": 2,\n        \"129\": -1,\n        \"130\": -1,\n        \"131\": 1,\n        \"132\": 1,\n        \"133\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 3,\n        \"3\": 1,\n        \"4\": 2,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 7,\n        \"11\": 3,\n        \"12\": 2,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 0,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 1,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 3,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 7,\n        \"27\": -1,\n        \"28\": 1,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 2,\n        \"35\": 1,\n        \"36\": 1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 1,\n        \"41\": 1,\n        \"42\": 1,\n        \"43\": 7,\n        \"44\": -1,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 3,\n        \"48\": -1,\n        \"49\": -1,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 3,\n        \"55\": 3,\n        \"56\": 3,\n        \"57\": 3,\n        \"58\": 3,\n        \"59\": 7,\n        \"60\": 2,\n        \"61\": 3,\n        \"62\": 3,\n        \"63\": 2,\n        \"64\": 2,\n        \"65\": 1\n      }\n    },\n    \"773\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": -1,\n        \"4\": 7,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 7,\n        \"27\": 7,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 1,\n        \"31\": 1,\n        \"32\": -1,\n        \"33\": 1,\n        \"34\": 2,\n        \"35\": 2,\n        \"36\": 2,\n        \"37\": 7,\n        \"38\": 2,\n        \"39\": 7,\n        \"40\": 3,\n        \"41\": 2,\n        \"42\": 3,\n        \"43\": -1,\n        \"44\": 7,\n        \"45\": 7,\n        \"46\": 4,\n        \"47\": 7,\n        \"48\": 2,\n        \"49\": 4,\n        \"50\": 3,\n        \"51\": 2,\n        \"52\": 2,\n        \"53\": 2,\n        \"54\": 2,\n        \"55\": 2,\n        \"56\": 3,\n        \"57\": 3,\n        \"58\": 7,\n        \"59\": -1,\n        \"60\": -1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 1,\n        \"64\": 2,\n        \"65\": 2,\n        \"66\": 1,\n        \"67\": 1,\n        \"68\": 1,\n        \"69\": 1,\n        \"70\": 1,\n        \"71\": 2,\n        \"72\": 3,\n        \"73\": 3,\n        \"74\": 3,\n        \"75\": 2,\n        \"76\": 2,\n        \"77\": 1,\n        \"78\": -1,\n        \"79\": -1,\n        \"80\": 3,\n        \"81\": 2,\n        \"82\": 7,\n        \"83\": -1,\n        \"84\": 1,\n        \"85\": 1,\n        \"86\": 3,\n        \"87\": 3,\n        \"88\": 3,\n        \"89\": 3,\n        \"90\": 3,\n        \"91\": 2,\n        \"92\": 7,\n        \"93\": 7,\n        \"94\": 3,\n        \"95\": 2,\n        \"96\": 1,\n        \"97\": 2,\n        \"98\": 2,\n        \"99\": 2,\n        \"100\": 2,\n        \"101\": 1,\n        \"102\": 1,\n        \"103\": 3,\n        \"104\": 1,\n        \"105\": 2,\n        \"106\": 3,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 7,\n        \"110\": 1,\n        \"111\": 1,\n        \"112\": 1,\n        \"113\": 1,\n        \"114\": 4,\n        \"115\": 4,\n        \"116\": 0,\n        \"117\": 4,\n        \"118\": 1,\n        \"119\": 1,\n        \"120\": 1,\n        \"121\": 3,\n        \"122\": 2,\n        \"123\": 2,\n        \"124\": 7,\n        \"125\": 3,\n        \"126\": 3,\n        \"127\": 0,\n        \"128\": 1,\n        \"129\": 2,\n        \"130\": 2,\n        \"131\": 1,\n        \"132\": 1,\n        \"133\": 2,\n        \"134\": -1,\n        \"135\": -1,\n        \"136\": 1,\n        \"137\": 1,\n        \"138\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 3,\n        \"3\": 1,\n        \"4\": 2,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 7,\n        \"11\": 3,\n        \"12\": 2,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 0,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 1,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 3,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 7,\n        \"27\": -1,\n        \"28\": 1,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 2,\n        \"35\": 1,\n        \"36\": 1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 1,\n        \"41\": 1,\n        \"42\": 1,\n        \"43\": 7,\n        \"44\": -1,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 3,\n        \"48\": -1,\n        \"49\": -1,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 3,\n        \"55\": 3,\n        \"56\": 3,\n        \"57\": 3,\n        \"58\": 3,\n        \"59\": 7,\n        \"60\": 2,\n        \"61\": 3,\n        \"62\": 3,\n        \"63\": 2,\n        \"64\": 2,\n        \"65\": 1\n      }\n    },\n    \"774\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": -1,\n        \"4\": 7,\n        \"5\": 7,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 7,\n        \"12\": 7,\n        \"13\": 7,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 1,\n        \"23\": 1,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 7,\n        \"27\": 7,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 1,\n        \"31\": 1,\n        \"32\": -1,\n        \"33\": 1,\n        \"34\": 2,\n        \"35\": 2,\n        \"36\": 2,\n        \"37\": 7,\n        \"38\": 2,\n        \"39\": 7,\n        \"40\": 3,\n        \"41\": 2,\n        \"42\": 3,\n        \"43\": -1,\n        \"44\": 7,\n        \"45\": 7,\n        \"46\": 4,\n        \"47\": 7,\n        \"48\": 2,\n        \"49\": 4,\n        \"50\": 3,\n        \"51\": 2,\n        \"52\": 2,\n        \"53\": 2,\n        \"54\": 2,\n        \"55\": 2,\n        \"56\": 3,\n        \"57\": 3,\n        \"58\": 7,\n        \"59\": -1,\n        \"60\": -1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 1,\n        \"64\": 2,\n        \"65\": 2,\n        \"66\": 1,\n        \"67\": 1,\n        \"68\": 1,\n        \"69\": 1,\n        \"70\": 1,\n        \"71\": 2,\n        \"72\": 3,\n        \"73\": 3,\n        \"74\": 3,\n        \"75\": 2,\n        \"76\": 2,\n        \"77\": 1,\n        \"78\": -1,\n        \"79\": -1,\n        \"80\": 3,\n        \"81\": 2,\n        \"82\": 7,\n        \"83\": -1,\n        \"84\": 1,\n        \"85\": 1,\n        \"86\": 3,\n        \"87\": 3,\n        \"88\": 3,\n        \"89\": 3,\n        \"90\": 3,\n        \"91\": 2,\n        \"92\": 7,\n        \"93\": 7,\n        \"94\": 3,\n        \"95\": 2,\n        \"96\": 1,\n        \"97\": 2,\n        \"98\": 2,\n        \"99\": 2,\n        \"100\": 2,\n        \"101\": 1,\n        \"102\": 1,\n        \"103\": 3,\n        \"104\": 1,\n        \"105\": 2,\n        \"106\": 3,\n        \"107\": 1,\n        \"108\": 1,\n        \"109\": 7,\n        \"110\": 1,\n        \"111\": 1,\n        \"112\": 1,\n        \"113\": 1,\n        \"114\": 4,\n        \"115\": 4,\n        \"116\": 0,\n        \"117\": 4,\n        \"118\": 1,\n        \"119\": 1,\n        \"120\": 1,\n        \"121\": 3,\n        \"122\": 2,\n        \"123\": 2,\n        \"124\": 7,\n        \"125\": 3,\n        \"126\": 3,\n        \"127\": 0,\n        \"128\": 1,\n        \"129\": 2,\n        \"130\": 2,\n        \"131\": 1,\n        \"132\": 1,\n        \"133\": 2,\n        \"134\": -1,\n        \"135\": -1,\n        \"136\": 1,\n        \"137\": 1,\n        \"138\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 3,\n        \"3\": 1,\n        \"4\": 2,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 1,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 7,\n        \"11\": 3,\n        \"12\": 2,\n        \"13\": 1,\n        \"14\": 1,\n        \"15\": 0,\n        \"16\": 1,\n        \"17\": 1,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 1,\n        \"21\": 3,\n        \"22\": 1,\n        \"23\": 3,\n        \"24\": 3,\n        \"25\": 2,\n        \"26\": 7,\n        \"27\": -1,\n        \"28\": 1,\n        \"29\": 2,\n        \"30\": 2,\n        \"31\": 2,\n        \"32\": 2,\n        \"33\": 2,\n        \"34\": 2,\n        \"35\": 1,\n        \"36\": 1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 1,\n        \"41\": 1,\n        \"42\": 1,\n        \"43\": 7,\n        \"44\": -1,\n        \"45\": 3,\n        \"46\": 3,\n        \"47\": 3,\n        \"48\": -1,\n        \"49\": -1,\n        \"50\": 3,\n        \"51\": 3,\n        \"52\": 3,\n        \"53\": 3,\n        \"54\": 3,\n        \"55\": 3,\n        \"56\": 3,\n        \"57\": 3,\n        \"58\": 3,\n        \"59\": 7,\n        \"60\": 2,\n        \"61\": 3,\n        \"62\": 3,\n        \"63\": 2,\n        \"64\": 2,\n        \"65\": 1\n      }\n    },\n    \"1073741953\": {\n      \"s2c\": {\n        \"0\": -2147483648,\n        \"1\": 2,\n        \"2\": 2,\n        \"3\": 1,\n        \"4\": 2,\n        \"5\": -1,\n        \"6\": 7,\n        \"7\": 7,\n        \"8\": 7,\n        \"9\": 7,\n        \"10\": 7,\n        \"11\": 1,\n        \"12\": 1,\n        \"13\": 7,\n        \"14\": 1,\n        \"15\": 1,\n        \"16\": 1,\n        \"17\": 3,\n        \"18\": 3,\n        \"19\": 3,\n        \"20\": 3,\n        \"21\": 1,\n        \"22\": 1,\n        \"23\": 3,\n        \"24\": 2,\n        \"25\": 1,\n        \"26\": -1,\n        \"27\": 1,\n        \"28\": 2,\n        \"29\": 2,\n        \"30\": 7,\n        \"31\": 2,\n        \"32\": 3,\n        \"33\": 2,\n        \"34\": 3,\n        \"35\": -1,\n        \"36\": 7,\n        \"37\": 7,\n        \"38\": 4,\n        \"39\": 7,\n        \"40\": 2,\n        \"41\": 4,\n        \"42\": 3,\n        \"43\": 2,\n        \"44\": 2,\n        \"45\": 2,\n        \"46\": 2,\n        \"47\": 3,\n        \"48\": 3,\n        \"49\": 7,\n        \"50\": -1,\n        \"51\": 3,\n        \"52\": 2,\n        \"53\": 1,\n        \"54\": 2,\n        \"55\": 2,\n        \"56\": 1,\n        \"57\": 1,\n        \"58\": 1,\n        \"59\": 1,\n        \"60\": 1,\n        \"61\": 3,\n        \"62\": 2,\n        \"63\": 2,\n        \"64\": -1,\n        \"65\": 3,\n        \"66\": 2,\n        \"67\": 7,\n        \"68\": -1,\n        \"69\": 1,\n        \"70\": 1,\n        \"71\": 3,\n        \"72\": 3,\n        \"73\": 3,\n        \"74\": 3,\n        \"75\": 3,\n        \"76\": 2,\n        \"77\": 3,\n        \"78\": 7,\n        \"79\": 7,\n        \"80\": 2,\n        \"81\": 1,\n        \"82\": 2,\n        \"83\": 2,\n        \"84\": 2,\n        \"85\": 2,\n        \"86\": 1,\n        \"87\": 1,\n        \"88\": 1,\n        \"89\": 2,\n        \"90\": 1,\n        \"91\": 1,\n        \"92\": 7,\n        \"93\": 1,\n        \"94\": 1,\n        \"95\": 1,\n        \"96\": 1,\n        \"97\": 4,\n        \"98\": 4,\n        \"99\": 4,\n        \"100\": 1,\n        \"101\": 1,\n        \"102\": 3,\n        \"103\": 2,\n        \"104\": 2,\n        \"105\": 1,\n        \"106\": 2,\n        \"107\": 2,\n        \"108\": 2,\n        \"109\": 1,\n        \"110\": 1,\n        \"111\": 1,\n        \"112\": 1,\n        \"113\": 1,\n        \"114\": 1,\n        \"115\": 1,\n        \"116\": 1\n      },\n      \"c2s\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 1,\n        \"3\": 1,\n        \"4\": 1,\n        \"5\": 1,\n        \"6\": 1,\n        \"7\": 3,\n        \"8\": 1,\n        \"9\": 1,\n        \"10\": 1,\n        \"11\": 1,\n        \"12\": 3,\n        \"13\": 3,\n        \"14\": 3,\n        \"15\": 3,\n        \"16\": 2,\n        \"17\": 7,\n        \"18\": -1,\n        \"19\": 1,\n        \"20\": 2,\n        \"21\": 2,\n        \"22\": 2,\n        \"23\": 2,\n        \"24\": 2,\n        \"25\": 2,\n        \"26\": 3,\n        \"27\": 3,\n        \"28\": 3,\n        \"29\": 1,\n        \"30\": 1,\n        \"31\": 1,\n        \"32\": -1,\n        \"33\": 3,\n        \"34\": 3,\n        \"35\": 3,\n        \"36\": -1,\n        \"37\": -1,\n        \"38\": 3,\n        \"39\": 3,\n        \"40\": 3,\n        \"41\": 3,\n        \"42\": 3,\n        \"43\": 3,\n        \"44\": 3,\n        \"45\": 3,\n        \"46\": 7,\n        \"47\": 2,\n        \"48\": 3,\n        \"49\": 2,\n        \"50\": 2,\n        \"51\": 1,\n        \"52\": 2\n      }\n    }\n  }\n}"
  },
  {
    "path": "fabric/build.gradle",
    "content": "evaluationDependsOn(\":\")\n\napply plugin: 'fabric-loom'\napply plugin: 'com.gradleup.shadow'\napply plugin: 'com.modrinth.minotaur'\napply plugin: 'io.github.themrmilchmann.curseforge-publish'\n\nbase {\n    archivesName = project.archives_base_name + \"-fabric\"\n}\ngroup = project.maven_group + \".fabric\"\n\nconfigurations {\n\tshadowInclude\n}\n\ndependencies {\n\t// To change the versions see the gradle.properties file\n\tminecraft \"com.mojang:minecraft:${project.minecraft_version}\"\n\tmappings \"net.fabricmc:yarn:${project.yarn_mappings}:v2\"\n\tmodImplementation \"net.fabricmc:fabric-loader:${project.loader_version}\"\n\n\tshadowInclude implementation(project(\":common\"))\n\n\t// Fabric API. This is technically optional, but you probably want it anyway.\n//\tmodImplementation \"net.fabricmc.fabric-api:fabric-api:${project.fabric_version}\"\n}\n\nprocessResources {\n\tinputs.property \"version\", project.version\n\n\tfilesMatching(\"fabric.mod.json\") {\n\t\texpand \"version\": project.version\n\t}\n}\n\ntasks.withType(JavaCompile).configureEach {\n\t// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.\n\tit.options.release = 17\n}\n\njava {\n\t// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the \"build\" task\n\t// if it is present.\n\t// If you remove this line, sources will not be generated.\n\twithSourcesJar()\n}\n\nloom {\n\taccessWidenerPath = file(\"src/main/resources/raknetify-fabric.accesswidener\")\n\truns {\n\t\tserver {\n\t\t\tvmArgs \"-Draknetify.debug=true\", \"-Dio.netty.leakDetection.level=advanced\"\n\t\t\tideConfigGenerated(true)\n\t\t}\n\t\tclient {\n\t\t\tvmArgs \"-Draknetify.debug=true\", \"-Dio.netty.leakDetection.level=advanced\"\n\t\t\tideConfigGenerated(true)\n\t\t}\n\t}\n    mixin {\n        useLegacyMixinAp = true\n    }\n}\n\njar {\n\texclude \"META-INF/LICENSE.txt\"\n\texclude \"META-INF/NOTICE.txt\"\n\tfrom \"../LICENSE\"\n}\n\nshadowJar {\n\tdependencies {\n\t\texclude(dependency('it.unimi.dsi:fastutil'))\n\t}\n\texclude \"META-INF/LICENSE.txt\"\n\texclude \"META-INF/NOTICE.txt\"\n\tminimize()\n\tarchiveClassifier = \"all-dev\"\n\tconfigurations = [ project.configurations.shadowInclude ]\n\tfrom \"../LICENSE\"\n}\n\n//noinspection UnnecessaryQualifiedReference\ntask(\"remapShadowJar\", type: net.fabricmc.loom.task.RemapJarTask, dependsOn: shadowJar) {\n\tinput = shadowJar.archiveFile\n\tarchiveFileName = shadowJar.archiveFileName.get().replaceAll(\"-dev\\\\.jar\\$\", \".jar\")\n\taddNestedDependencies = true\n}\n\nassemble.dependsOn(remapShadowJar)\n\nafterEvaluate {\n\tmigrateMappings.configure {\n\t\toutputDir = project.file(\"build/remappedSrc\")\n\t\tdoLast {\n\t\t\tcopy {\n\t\t\t\tfrom project.file(\"build/remappedSrc\")\n\t\t\t\tinto project.file(\"src/main/java\")\n\t\t\t}\n\t\t}\n\t}\n}\n\ntasks.withType(AbstractArchiveTask) {\n\tpreserveFileTimestamps = false\n\treproducibleFileOrder = true\n}\n\nmodrinth {\n\tversionNumber = project.version\n\tversionName = project.version + \" devbuild\"\n\tuploadFile = remapShadowJar\n\tloaders = [\"fabric\", \"quilt\"]\n}\n\ncurseforge {\n    apiToken = System.getenv(\"CURSEFORGE_TOKEN\")\n    publications {\n        register(\"main\") {\n            projectId = \"631457\"\n\n            gameVersion(\"minecraft-1-18\", \"1-18\")\n            gameVersion(\"minecraft-1-18\", \"1-18-1\")\n            gameVersion(\"minecraft-1-18\", \"1-18-2\")\n            gameVersion(\"minecraft-1-19\", \"1-19\")\n            gameVersion(\"minecraft-1-19\", \"1-19-1\")\n            gameVersion(\"minecraft-1-19\", \"1-19-2\")\n            gameVersion(\"minecraft-1-19\", \"1-19-3\")\n            gameVersion(\"minecraft-1-19\", \"1-19-4\")\n            gameVersion(\"minecraft-1-20\", \"1-20\")\n            gameVersion(\"minecraft-1-20\", \"1-20-1\")\n            gameVersion(\"minecraft-1-20\", \"1-20-2\")\n            gameVersion(\"minecraft-1-20\", \"1-20-3\")\n            gameVersion(\"minecraft-1-20\", \"1-20-4\")\n            gameVersion(\"minecraft-1-20\", \"1-20-5\")\n            gameVersion(\"minecraft-1-20\", \"1-20-6\")\n            gameVersion(\"minecraft-1-21\", \"1-21\")\n            gameVersion(\"minecraft-1-21\", \"1-21-1\")\n            gameVersion(\"minecraft-1-21\", \"1-21-2\")\n            gameVersion(\"minecraft-1-21\", \"1-21-3\")\n            gameVersion(\"minecraft-1-21\", \"1-21-4\")\n            gameVersion(\"minecraft-1-21\", \"1-21-5\")\n            gameVersion(\"minecraft-1-21\", \"1-21-6\")\n            gameVersion(\"minecraft-1-21\", \"1-21-7\")\n            gameVersion(\"minecraft-1-21\", \"1-21-8\")\n            gameVersion(\"minecraft-1-21\", \"1-21-9\")\n            gameVersion(\"minecraft-1-21\", \"1-21-10\")\n            gameVersion(\"minecraft-1-21\", \"1-21-11\")\n            gameVersion(\"modloader\", \"fabric\")\n            gameVersion(\"java\", \"java-22\")\n            gameVersion(\"java\", \"java-21\")\n            gameVersion(\"java\", \"java-20\")\n            gameVersion(\"java\", \"java-19\")\n            gameVersion(\"java\", \"java-18\")\n            gameVersion(\"java\", \"java-17\")\n            gameVersion(\"environment\", \"server\")\n            gameVersion(\"environment\", \"client\")\n\n            artifacts.register(\"main\") {\n                from(remapShadowJar)\n\n                displayName = project.version + \" devbuild\"\n                releaseType = io.github.themrmilchmann.gradle.publish.curseforge.ReleaseType.ALPHA\n\n                changelog {\n                    format = io.github.themrmilchmann.gradle.publish.curseforge.ChangelogFormat.MARKDOWN\n                    from(com.ishland.buildscript.ParseGItHubActionChangelog.getChangelog())\n                }\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/RaknetifyFabric.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric;\n\nimport com.google.gson.Gson;\nimport com.google.gson.GsonBuilder;\nimport com.ishland.raknetify.common.data.ProtocolMultiChannelMappings;\nimport com.ishland.raknetify.fabric.common.client.DebugHudUtil1_21_9;\nimport com.ishland.raknetify.fabric.common.connection.RakNetMultiChannel;\nimport com.ishland.raknetify.common.util.NetworkInterfaceListener;\nimport com.ishland.raknetify.fabric.common.util.FieldSignatureParser;\nimport com.ishland.raknetify.fabric.common.util.MultiVersionUtil;\nimport com.ishland.raknetify.fabric.mixin.RaknetifyFabricMixinPlugin;\nimport com.ishland.raknetify.fabric.mixin.access.INetworkState1_20_4;\nimport com.ishland.raknetify.fabric.mixin.access.INetworkStateInternalPacketHandler;\nimport com.ishland.raknetify.fabric.mixin.access.IPacketCodecDispatcher;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.util.ResourceLeakDetector;\nimport io.netty.util.internal.SystemPropertyUtil;\nimport it.unimi.dsi.fastutil.ints.AbstractInt2ObjectMap;\nimport it.unimi.dsi.fastutil.ints.Int2IntArrayMap;\nimport it.unimi.dsi.fastutil.ints.Int2IntMap;\nimport it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;\nimport it.unimi.dsi.fastutil.ints.Int2ObjectMap;\nimport it.unimi.dsi.fastutil.objects.Object2IntMap;\nimport it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;\nimport net.fabricmc.api.EnvType;\nimport net.fabricmc.api.ModInitializer;\nimport net.fabricmc.loader.api.FabricLoader;\nimport net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;\nimport net.minecraft.SharedConstants;\nimport net.minecraft.network.NetworkPhase;\nimport net.minecraft.network.NetworkSide;\nimport net.minecraft.network.RegistryByteBuf;\nimport net.minecraft.network.listener.ClientPlayPacketListener;\nimport net.minecraft.network.listener.ServerPlayPacketListener;\nimport net.minecraft.network.packet.CommonPackets;\nimport net.minecraft.network.packet.CookiePackets;\nimport net.minecraft.network.packet.Packet;\nimport net.minecraft.network.packet.PacketType;\nimport net.minecraft.network.packet.PingPackets;\nimport net.minecraft.network.packet.PlayPackets;\nimport net.minecraft.network.state.NetworkState;\nimport net.minecraft.network.state.PlayStateFactories;\nimport org.objectweb.asm.Type;\nimport org.objectweb.asm.tree.FieldNode;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.spongepowered.asm.mixin.MixinEnvironment;\nimport org.spongepowered.asm.service.MixinService;\n\nimport java.io.IOException;\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Method;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\nimport java.nio.file.StandardOpenOption;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Locale;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.stream.Collectors;\nimport java.util.stream.Stream;\n\npublic class RaknetifyFabric implements ModInitializer, PreLaunchEntrypoint {\n\n    private static final boolean SAVE_CHANNEL_MAPPINGS = Boolean.getBoolean(\"raknetify.saveChannelMappings\");\n    private static final boolean EXIT_AFTER_SAVE_CHANNEL_MAPPINGS = Boolean.getBoolean(\"raknetify.saveChannelMappings.exit\");\n\n    @Override\n    public void onPreLaunch() {\n    }\n\n    @Override\n    public void onInitialize() {\n        MultiVersionUtil.init();\n\n        if (FabricLoader.getInstance().isDevelopmentEnvironment())\n            auditMixins();\n\n        handleMappings();\n\n        if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && RaknetifyFabricMixinPlugin.AFTER_1_21_8) {\n            DebugHudUtil1_21_9.init();\n        }\n\n        // If new property name is present, use it\n        String levelStr = SystemPropertyUtil.get(\"io.netty.leakDetection.level\", ResourceLeakDetector.Level.SIMPLE.name());\n        ResourceLeakDetector.Level level = ResourceLeakDetector.Level.SIMPLE;\n        try {\n            level = ResourceLeakDetector.Level.valueOf(levelStr.trim().toUpperCase(Locale.ENGLISH));\n        } catch (IllegalArgumentException ignored) {\n        }\n        System.out.println(\"Raknetify: Using leak detector level %s\".formatted(level));\n        ResourceLeakDetector.setLevel(level);\n    }\n\n    private static void handleMappings() {\n        RakNetMultiChannel.init();\n//        RakNetMultiChannel.iterateKnownPackets();\n        NetworkInterfaceListener.init();\n\n        Int2IntArrayMap s2c = new Int2IntArrayMap();\n        Int2IntArrayMap c2s = new Int2IntArrayMap();\n        if (!RaknetifyFabricMixinPlugin.AFTER_1_20_4) {\n            for (Map.Entry<NetworkSide, ?> entry : ((INetworkState1_20_4) (Object) NetworkPhase.PLAY).getPacketHandlers().entrySet()) {\n                final Object value = entry.getValue();\n                final Object2IntMap<Class<? extends Packet<?>>> packetIds = getPacketIdsFromPacketHandler(value);\n                for (Object2IntMap.Entry<Class<? extends Packet<?>>> type : packetIds.object2IntEntrySet()) {\n                    if (entry.getKey() == NetworkSide.CLIENTBOUND)\n                        s2c.put(type.getIntValue(), RakNetMultiChannel.getPacketChannelOverride(type.getKey(), false));\n                    else if (entry.getKey() == NetworkSide.SERVERBOUND)\n                        c2s.put(type.getIntValue(), RakNetMultiChannel.getPacketChannelOverride(type.getKey(), false));\n                }\n            }\n        } else {\n            final List<PacketType<Packet<? super ServerPlayPacketListener>>> c2sPacketTypes;\n            final List<PacketType<Packet<? super ServerPlayPacketListener>>> s2cPacketTypes;\n            if (!RaknetifyFabricMixinPlugin.AFTER_1_21_4) {\n                try {\n                    c2sPacketTypes = ((IPacketCodecDispatcher<ByteBuf, Packet<? super ServerPlayPacketListener>, PacketType<Packet<? super ServerPlayPacketListener>>>)\n                            ((NetworkState<ServerPlayPacketListener>) MultiVersionUtil.NetworkState$Factory$bind1_20_5.invoke(MultiVersionUtil.PlayStateFactories$C2S1_20_5.get(), RegistryByteBuf.makeFactory(null))).codec()).getPacketTypes()\n                            .stream().map(byteBufPacketPacketTypePacketType -> byteBufPacketPacketTypePacketType.id()).toList();\n                } catch (Throwable e) {\n                    throw new RuntimeException(e);\n                }\n                try {\n                    s2cPacketTypes = ((IPacketCodecDispatcher<ByteBuf, Packet<? super ServerPlayPacketListener>, PacketType<Packet<? super ServerPlayPacketListener>>>)\n                            ((NetworkState<ClientPlayPacketListener>) MultiVersionUtil.NetworkState$Factory$bind1_20_5.invoke(MultiVersionUtil.PlayStateFactories$S2C1_20_5.get(), RegistryByteBuf.makeFactory(null))).codec()).getPacketTypes()\n                            .stream().map(byteBufPacketPacketTypePacketType -> byteBufPacketPacketTypePacketType.id()).toList();\n                } catch (Throwable e) {\n                    throw new RuntimeException(e);\n                }\n            } else {\n                c2sPacketTypes = ((IPacketCodecDispatcher<ByteBuf, Packet<? super ServerPlayPacketListener>, PacketType<Packet<? super ServerPlayPacketListener>>>)\n                        PlayStateFactories.C2S.bind(RegistryByteBuf.makeFactory(null), null).codec()).getPacketTypes()\n                        .stream().map(byteBufPacketPacketTypePacketType -> byteBufPacketPacketTypePacketType.id()).toList();\n                s2cPacketTypes = ((IPacketCodecDispatcher<ByteBuf, Packet<? super ServerPlayPacketListener>, PacketType<Packet<? super ServerPlayPacketListener>>>)\n                        PlayStateFactories.S2C.bind(RegistryByteBuf.makeFactory(null)).codec()).getPacketTypes()\n                        .stream().map(byteBufPacketPacketTypePacketType -> byteBufPacketPacketTypePacketType.id()).toList();\n            }\n\n            record FieldNodeClazzPair(FieldNode fieldNode, Class<?> clazz) {\n            }\n\n            Map<PacketType<?>, Class<?>> vanillaPacketTypes = new Object2ObjectOpenHashMap<>();\n            for (FieldNodeClazzPair fieldNodeClazzPair : Stream.of(PlayPackets.class, CommonPackets.class, CookiePackets.class, PingPackets.class)\n                    .flatMap(clazz -> {\n                        try {\n                            return MixinService.getService().getBytecodeProvider().getClassNode(Type.getInternalName(clazz)).fields.stream()\n                                    .map(fieldNode -> new FieldNodeClazzPair(fieldNode, clazz));\n                        } catch (ClassNotFoundException | IOException e) {\n                            throw new RuntimeException(e);\n                        }\n                    })\n                    .toList()) {\n                final FieldNode field = fieldNodeClazzPair.fieldNode();\n                final List<Type> parameterGenerics = FieldSignatureParser.parse(field.signature);\n                for (Type type : parameterGenerics) {\n                    try {\n                        final Class<?> clazz = Class.forName(type.getClassName());\n                        if (Packet.class.isAssignableFrom(clazz)) {\n                            final PacketType<?> actualType;\n                            try {\n                                actualType = (PacketType<?>) fieldNodeClazzPair.clazz().getField(field.name).get(null);\n                            } catch (IllegalAccessException | NoSuchFieldException e) {\n                                throw new RuntimeException(e);\n                            }\n                            vanillaPacketTypes.put(actualType, clazz);\n                        }\n                    } catch (ClassNotFoundException ignored) {\n                    }\n                }\n            }\n\n            for (int i = 0, s2cPacketTypesSize = s2cPacketTypes.size(); i < s2cPacketTypesSize; i++) {\n                PacketType<Packet<? super ServerPlayPacketListener>> s2cPacketType = s2cPacketTypes.get(i);\n                final Class<?> clazz = vanillaPacketTypes.get(s2cPacketType);\n                if (clazz == null) {\n                    System.out.println(\"Skipping unmapped packet type: \" + s2cPacketType);\n                    continue;\n                }\n                s2c.put(i, RakNetMultiChannel.getPacketChannelOverride(clazz, false));\n//                System.out.println(\"Mapped packet type: \" + s2cPacketType + \" to channel \" + RakNetMultiChannel.getPacketChannelOverride(clazz));\n            }\n\n            for (int i = 0, c2sPacketTypesSize = c2sPacketTypes.size(); i < c2sPacketTypesSize; i++) {\n                PacketType<Packet<? super ServerPlayPacketListener>> c2sPacketType = c2sPacketTypes.get(i);\n                final Class<?> clazz = vanillaPacketTypes.get(c2sPacketType);\n                if (clazz == null) {\n                    System.out.println(\"Skipping unmapped packet type: \" + c2sPacketType);\n                    continue;\n                }\n                c2s.put(i, RakNetMultiChannel.getPacketChannelOverride(clazz, false));\n//                System.out.println(\"Mapped packet type: \" + c2sPacketType + \" to channel \" + RakNetMultiChannel.getPacketChannelOverride(clazz));\n            }\n        }\n\n        if (SAVE_CHANNEL_MAPPINGS) {\n            auditMixins();\n            final Gson gson = new GsonBuilder()\n                    .setPrettyPrinting()\n                    .create();\n            ProtocolMultiChannelMappings mappings = new ProtocolMultiChannelMappings();\n            Path path = Path.of(\"channelMappings.json\");\n            try {\n                mappings = gson.fromJson(Files.readString(path), ProtocolMultiChannelMappings.class);\n            } catch (IOException e) {\n                System.out.println(\"Error reading previously generated mappings: \" + e.toString());\n            }\n            final ProtocolMultiChannelMappings.VersionMapping versionMapping = new ProtocolMultiChannelMappings.VersionMapping();\n            versionMapping.c2s = c2s;\n            versionMapping.s2c = s2c;\n            mappings.mappings.put(SharedConstants.getProtocolVersion(), versionMapping);\n\n            // reproducible mappings\n            mappings.mappings = mappings.mappings.int2ObjectEntrySet()\n                    .stream()\n                    .map(entry -> {\n                        final ProtocolMultiChannelMappings.VersionMapping value = entry.getValue();\n                        value.s2c = value.s2c.int2IntEntrySet().stream()\n                                .sorted(Comparator.comparingInt(Int2IntMap.Entry::getIntKey))\n                                .collect(Collectors.toMap(Int2IntMap.Entry::getIntKey, Int2IntMap.Entry::getIntValue, (o, o2) -> {\n                                    throw new RuntimeException(\"Unresolvable conflicts\");\n                                }, Int2IntArrayMap::new));\n                        value.c2s = value.c2s.int2IntEntrySet().stream()\n                                .sorted(Comparator.comparingInt(Int2IntMap.Entry::getIntKey))\n                                .collect(Collectors.toMap(Int2IntMap.Entry::getIntKey, Int2IntMap.Entry::getIntValue, (o, o2) -> {\n                                    throw new RuntimeException(\"Unresolvable conflicts\");\n                                }, Int2IntArrayMap::new));\n                        return new AbstractInt2ObjectMap.BasicEntry<>(\n                                entry.getIntKey(),\n                                value\n                        );\n                    })\n                    .sorted(Comparator.comparingInt(Int2ObjectMap.Entry::getIntKey))\n                    .collect(Collectors.toMap(Int2ObjectMap.Entry::getIntKey, Int2ObjectMap.Entry::getValue, (o, o2) -> {\n                        throw new RuntimeException(\"Unresolvable conflicts\");\n                    }, Int2ObjectArrayMap::new));\n\n            try {\n                Files.writeString(path, gson.toJson(mappings), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);\n            } catch (IOException e) {\n                System.out.println(\"Error writing generated mappings: \" + e.toString());\n            }\n            if (EXIT_AFTER_SAVE_CHANNEL_MAPPINGS) System.exit(0);\n        }\n    }\n\n    public static Object2IntMap<Class<? extends Packet<?>>> getPacketIdsFromPacketHandler(Object value) {\n        Object2IntMap<Class<? extends Packet<?>>> packetIds;\n        if (value instanceof INetworkStateInternalPacketHandler) {\n            packetIds = ((INetworkStateInternalPacketHandler) value).getPacketIds();\n        } else if (MultiVersionUtil.clazzNetworkStatePacketHandler.isInstance(value)) {\n            packetIds = ((INetworkStateInternalPacketHandler) MultiVersionUtil.NetworkStatePacketHandler$backingHandler1_20_2.get(value)).getPacketIds();\n        } else {\n            throw new IllegalStateException(\"Unknown packet handler type: \" + value.getClass());\n        }\n        return packetIds;\n    }\n\n    private static void auditMixins() {\n        Logger auditLogger = LoggerFactory.getLogger(\"Raknetify Mixin Audit\");\n        try {\n            final Class<?> transformerClazz = Class.forName(\"org.spongepowered.asm.mixin.transformer.MixinTransformer\");\n            if (transformerClazz.isInstance(MixinEnvironment.getCurrentEnvironment().getActiveTransformer())) {\n                final Field processorField = transformerClazz.getDeclaredField(\"processor\");\n                processorField.setAccessible(true);\n                final Object processor = processorField.get(MixinEnvironment.getCurrentEnvironment().getActiveTransformer());\n                final Class<?> processorClazz = Class.forName(\"org.spongepowered.asm.mixin.transformer.MixinProcessor\");\n                final Field configsField = processorClazz.getDeclaredField(\"configs\");\n                configsField.setAccessible(true);\n                final List<?> configs = (List<?>) configsField.get(processor);\n                final Class<?> configClazz = Class.forName(\"org.spongepowered.asm.mixin.transformer.MixinConfig\");\n                final Method getUnhandledTargetsMethod = configClazz.getDeclaredMethod(\"getUnhandledTargets\");\n                getUnhandledTargetsMethod.setAccessible(true);\n                Set<String> unhandled = new HashSet<>();\n                for (Object config : configs) {\n                    final Set<String> unhandledTargets = (Set<String>) getUnhandledTargetsMethod.invoke(config);\n                    unhandled.addAll(unhandledTargets);\n                }\n                for (String s : unhandled) {\n                    auditLogger.info(\"Loading class {}\", s);\n                    MixinService.getService().getClassProvider().findClass(s, false);\n                }\n                for (Object config : configs) {\n                    for (String unhandledTarget : (Set<String>) getUnhandledTargetsMethod.invoke(config)) {\n                        auditLogger.error(\"{} is already classloaded\", unhandledTarget);\n                    }\n                }\n            }\n        } catch (Throwable t) {\n            throw new RuntimeException(\"Failed to audit mixins\", t);\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/client/DebugHudUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.client;\n\nimport com.ishland.raknetify.common.connection.MetricsSynchronizationHandler;\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.common.connection.SimpleMetricsLogger;\nimport com.ishland.raknetify.fabric.common.util.MultiVersionUtil;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport io.netty.channel.Channel;\nimport net.minecraft.client.MinecraftClient;\nimport net.minecraft.client.network.ClientPlayNetworkHandler;\nimport net.minecraft.network.ClientConnection;\nimport network.ycc.raknet.RakNet;\n\nimport java.util.function.Consumer;\n\npublic class DebugHudUtil {\n\n    public static void getDebugString(Consumer<String> consumer) {\n        final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();\n        if (networkHandler != null) {\n            final ClientConnection connection = (ClientConnection) MultiVersionUtil.ClientPlayNetworkHandler$connection.get(networkHandler);\n            final Channel channel = ((IClientConnection) connection).getChannel();\n            if (channel != null) {\n                if (channel.config() instanceof RakNet.Config config) {\n                    if (config.getMetrics() instanceof SimpleMetricsLogger logger) {\n                        consumer.accept(\n                                \"[Raknetify] A: true, MTU: %d, RTT: %.2f/%.2fms\"\n                                        .formatted(config.getMTU(),\n                                                logger.getMeasureRTTns() / 1_000_000.0,\n                                                logger.getMeasureRTTnsStdDev() / 1_000_000.0\n                                        ));\n                        final MetricsSynchronizationHandler serverSync = logger.getMetricsSynchronizationHandler();\n                        if (serverSync != null && serverSync.isRemoteSupported()) {\n                            consumer.accept(\n                                    \"[Raknetify] C: BUF: %.2fMB; S: BUF: %.2fMB\"\n                                            .formatted(\n                                                    logger.getCurrentQueuedBytes() / 1024.0 / 1024.0,\n                                                    serverSync.getQueuedBytes() / 1024.0 / 1024.0\n                                            ));\n                        } else {\n                            consumer.accept(\n                                    \"[Raknetify] C: BUF: %.2fMB\"\n                                            .formatted(\n                                                    logger.getCurrentQueuedBytes() / 1024.0 / 1024.0\n                                            ));\n                        }\n\n                        consumer.accept(\n                                \"[Raknetify] C: I: %s, O: %s\"\n                                        .formatted(\n                                                logger.getMeasureTrafficInFormatted(),\n                                                logger.getMeasureTrafficOutFormatted()\n                                        ));\n\n                        consumer.accept(\n                                \"[Raknetify] C: ERR: %.4f%%, %d tx, %d rx, BST: %d\"\n                                        .formatted(\n                                                logger.getMeasureErrorRate() * 100.0,\n                                                logger.getMeasureTX(), logger.getMeasureRX(),\n                                                logger.getMeasureBurstTokens() + config.getDefaultPendingFrameSets()\n                                        ));\n                        if (serverSync != null && serverSync.isRemoteSupported()) {\n                            consumer.accept(\n                                    \"[Raknetify] S: ERR: %.4f%%, %d tx, %d rx, BST: %d\"\n                                            .formatted(\n                                                    serverSync.getErrorRate() * 100.0,\n                                                    serverSync.getTX(), serverSync.getRX(),\n                                                    serverSync.getBurst()\n                                            ));\n                        }\n                    } else {\n                        consumer.accept(\n                                \"[Raknetify] A: true, MTU: %d\"\n                                        .formatted(config.getMTU())\n                        );\n                    }\n\n                    final MultiChannelingStreamingCompression compression = channel.pipeline().get(MultiChannelingStreamingCompression.class);\n                    if (compression != null && compression.isActive()) {\n                        consumer.accept(\n                                \"[Raknetify] CRatio: I: %.2f%%, O: %.2f%%\"\n                                        .formatted(compression.getInCompressionRatio() * 100, compression.getOutCompressionRatio() * 100)\n                        );\n                    }\n\n                    return;\n                }\n            }\n        }\n        consumer.accept(\"[Raknetify] A: false\");\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/client/DebugHudUtil1_21_9.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.client;\n\nimport com.ishland.raknetify.fabric.mixin.access.IDebugHudEntries;\nimport net.minecraft.client.gui.hud.debug.DebugHudEntry;\nimport net.minecraft.client.gui.hud.debug.DebugHudLines;\nimport net.minecraft.util.Identifier;\nimport net.minecraft.world.World;\nimport net.minecraft.world.chunk.WorldChunk;\nimport org.jetbrains.annotations.Nullable;\n\nimport java.util.concurrent.atomic.AtomicBoolean;\n\npublic class DebugHudUtil1_21_9 {\n\n    private static final AtomicBoolean initialized = new AtomicBoolean(false);\n\n    public static void init() {\n        if (!initialized.compareAndSet(false, true)) return;\n\n        Identifier identifier = Identifier.of(\"raknetify\", \"raknetify_debug_info\");\n        IDebugHudEntries.invokeRegister(identifier, new DebugHudEntry() {\n            @Override\n            public void render(DebugHudLines lines, @Nullable World world, @Nullable WorldChunk clientChunk, @Nullable WorldChunk chunk) {\n                DebugHudUtil.getDebugString(s -> lines.addLineToSection(identifier, s));\n            }\n\n            @Override\n            public boolean canShow(boolean reducedDebugInfo) {\n                return true;\n            }\n        });\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/compat/package-info.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.compat;\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/compat/viafabric/ViaFabricCompatInjector.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.compat.viafabric;\n\nimport com.google.common.base.Preconditions;\nimport com.ishland.raknetify.fabric.mixin.RaknetifyFabricMixinPlugin;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelPipeline;\nimport io.netty.handler.codec.MessageToMessageDecoder;\nimport io.netty.handler.codec.MessageToMessageEncoder;\nimport net.fabricmc.loader.api.FabricLoader;\n\nimport java.lang.reflect.Constructor;\n\npublic class ViaFabricCompatInjector {\n\n    public static void inject(Channel channel, boolean isClientSide) {\n        Preconditions.checkNotNull(channel);\n        if (FabricLoader.getInstance().isModLoaded(\"viafabric\")) {\n            try {\n                final Class<?> userConnectionImplClass = Class.forName(\"com.viaversion.viaversion.connection.UserConnectionImpl\");\n                final Constructor<?> userConnectionImplConstructor = userConnectionImplClass.getConstructor(Channel.class, boolean.class);\n                final Object user = userConnectionImplConstructor.newInstance(channel, isClientSide);\n\n                final Class<?> userConnectionClass = Class.forName(\"com.viaversion.viaversion.api.connection.UserConnection\");\n\n                final Class<?> protocolPipelineImplClass = Class.forName(\"com.viaversion.viaversion.protocol.ProtocolPipelineImpl\");\n                Object protocolPipeline = protocolPipelineImplClass.getConstructor(userConnectionClass).newInstance(user);\n\n                if (RaknetifyFabricMixinPlugin.AFTER_1_20_2) {\n                    Class<?> protocolPipelineClass = Class.forName(\"com.viaversion.viaversion.api.protocol.ProtocolPipeline\");\n                    Class<?> protocolClass = Class.forName(\"com.viaversion.viaversion.api.protocol.Protocol\");\n                    if ((boolean) userConnectionClass.getMethod(\"isClientSide\").invoke(user)) {\n                        Class<?> hostnameParserProtocolClass = Class.forName(\"com.viaversion.fabric.common.protocol.HostnameParserProtocol\");\n                        Object hostnameParserProtocolInstance = hostnameParserProtocolClass.getField(\"INSTANCE\").get(null);\n                        protocolPipelineClass.getMethod(\"add\", protocolClass).invoke(protocolPipeline, hostnameParserProtocolInstance);\n                    }\n                }\n\n                final Class<?> commonTransformerClass = Class.forName(\"com.viaversion.fabric.common.handler.CommonTransformer\");\n                final String handlerEncoderName = (String) commonTransformerClass.getField(\"HANDLER_ENCODER_NAME\").get(null);\n                final String handlerDecoderName = (String) commonTransformerClass.getField(\"HANDLER_DECODER_NAME\").get(null);\n\n                @SuppressWarnings(\"unchecked\") final Class<? extends MessageToMessageEncoder<ByteBuf>> fabricEncodeHandlerClass = (Class<? extends MessageToMessageEncoder<ByteBuf>>) Class.forName(\"com.viaversion.fabric.common.handler.FabricEncodeHandler\");\n                final MessageToMessageEncoder<ByteBuf> fabricEncodeHandler = fabricEncodeHandlerClass.getConstructor(userConnectionClass).newInstance(user);\n\n                @SuppressWarnings(\"unchecked\") final Class<? extends MessageToMessageDecoder<ByteBuf>> fabricDecodeHandlerClass = (Class<? extends MessageToMessageDecoder<ByteBuf>>) Class.forName(\"com.viaversion.fabric.common.handler.FabricDecodeHandler\");\n                final MessageToMessageDecoder<ByteBuf> fabricDecodeHandler = fabricDecodeHandlerClass.getConstructor(userConnectionClass).newInstance(user);\n\n                channel.pipeline().addBefore(determineEncoderName(channel.pipeline()), handlerEncoderName, fabricEncodeHandler);\n                channel.pipeline().addBefore(determineDecoderName(channel.pipeline()), handlerDecoderName, fabricDecodeHandler);\n            } catch (Throwable t) {\n                //noinspection RedundantStringFormatCall\n                System.err.println(String.format(\"Raknetify: Could not inject ViaVersion compatibility into RakNet channel %s: %s\", channel, t));\n                t.printStackTrace();\n            }\n        }\n    }\n\n    private static String determineEncoderName(ChannelPipeline pipeline) {\n        if (pipeline.get(\"encoder\") != null) return \"encoder\";\n        if (pipeline.get(\"outbound_config\") != null) return \"outbound_config\";\n        throw new UnsupportedOperationException();\n    }\n\n    private static String determineDecoderName(ChannelPipeline pipeline) {\n        if (pipeline.get(\"decoder\") != null) return \"decoder\";\n        if (pipeline.get(\"inbound_config\") != null) return \"inbound_config\";\n        throw new UnsupportedOperationException();\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/connection/MultiChannellingPacketCapture.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.connection;\n\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.common.connection.multichannel.CustomPayloadChannel;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelOutboundHandlerAdapter;\nimport io.netty.channel.ChannelPromise;\nimport net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket;\nimport net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;\n\n@ChannelHandler.Sharable\npublic class MultiChannellingPacketCapture extends ChannelOutboundHandlerAdapter {\n\n    private Class<?> packetClass = null;\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        this.packetClass = msg.getClass();\n        try {\n            ctx.write(msg, promise);\n        } finally {\n            this.packetClass = null;\n        }\n    }\n\n    public Class<?> getPacketClass() {\n        return this.packetClass;\n    }\n\n    public void setPacketClass(Class<?> packetClass) {\n        this.packetClass = packetClass;\n    }\n\n    public RakNetSimpleMultiChannelCodec.OverrideHandler getCaptureBasedHandler() {\n        return new CaptureBasedHandler();\n    }\n\n    public RakNetSimpleMultiChannelCodec.OverrideHandler getCustomPayloadHandler() {\n        return new CustomPayloadChannel.OverrideHandler(value -> packetClass == CustomPayloadS2CPacket.class || packetClass == CustomPayloadC2SPacket.class);\n    }\n\n    private class CaptureBasedHandler implements RakNetSimpleMultiChannelCodec.OverrideHandler {\n\n        @Override\n        public int getChannelOverride(ByteBuf buf, boolean suppressWarning) {\n            return RakNetMultiChannel.getPacketChannelOverride(packetClass, suppressWarning);\n        }\n\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/connection/RakNetClientConnectionUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.connection;\n\nimport com.ishland.raknetify.common.util.ThreadLocalUtil;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport io.netty.channel.ChannelFuture;\nimport net.minecraft.network.ClientConnection;\n\nimport java.net.InetSocketAddress;\n\npublic class RakNetClientConnectionUtil {\n\n    private RakNetClientConnectionUtil() {\n    }\n\n    public static ClientConnection connect(InetSocketAddress address, boolean useEpoll, boolean largeMTU, Operation<ClientConnection> original, boolean hasPerformanceLog) {\n        System.out.println(\"aaa\");\n        try {\n            ThreadLocalUtil.setInitializingRaknet(true);\n            ThreadLocalUtil.setInitializingRaknetLargeMTU(largeMTU);\n            if (hasPerformanceLog) {\n                return original.call(address, useEpoll, null);\n            } else {\n                return original.call(address, useEpoll);\n            }\n        } finally {\n            ThreadLocalUtil.setInitializingRaknet(false);\n            ThreadLocalUtil.setInitializingRaknetLargeMTU(false);\n        }\n    }\n\n    public static ClientConnection connect(InetSocketAddress address, Object backend, boolean largeMTU, Operation<ClientConnection> original) {\n        System.out.println(\"aaa\");\n        try {\n            ThreadLocalUtil.setInitializingRaknet(true);\n            ThreadLocalUtil.setInitializingRaknetLargeMTU(largeMTU);\n            return original.call(address, backend, null);\n        } finally {\n            ThreadLocalUtil.setInitializingRaknet(false);\n            ThreadLocalUtil.setInitializingRaknetLargeMTU(false);\n        }\n    }\n\n    public static ChannelFuture connect(InetSocketAddress address, boolean useEpoll, boolean largeMTU, Operation<ChannelFuture> original, ClientConnection connection) {\n        System.out.println(\"aaaa\");\n        try {\n            ThreadLocalUtil.setInitializingRaknet(true);\n            ThreadLocalUtil.setInitializingRaknetLargeMTU(largeMTU);\n            return original.call(address, useEpoll, connection);\n        } finally {\n            ThreadLocalUtil.setInitializingRaknet(false);\n            ThreadLocalUtil.setInitializingRaknetLargeMTU(false);\n        }\n    }\n\n    public static ChannelFuture connect(InetSocketAddress address, Object backend, boolean largeMTU, Operation<ChannelFuture> original, ClientConnection connection) {\n        System.out.println(\"aaaa\");\n        try {\n            ThreadLocalUtil.setInitializingRaknet(true);\n            ThreadLocalUtil.setInitializingRaknetLargeMTU(largeMTU);\n            return original.call(address, backend, connection);\n        } finally {\n            ThreadLocalUtil.setInitializingRaknet(false);\n            ThreadLocalUtil.setInitializingRaknetLargeMTU(false);\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/connection/RakNetCompressionCompatibilityHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.connection;\n\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPromise;\nimport net.minecraft.network.packet.s2c.login.LoginCompressionS2CPacket;\n\npublic class RakNetCompressionCompatibilityHandler extends ChannelDuplexHandler {\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        if (msg instanceof LoginCompressionS2CPacket) {\n            promise.trySuccess();\n            ctx.write(msg);\n            ctx.pipeline().remove(this);\n            return;\n        }\n        super.write(ctx, msg, promise);\n    }\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/connection/RakNetFabricChannelEventListener.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.connection;\n\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.common.connection.SynchronizationLayer;\nimport com.ishland.raknetify.fabric.mixin.RaknetifyFabricMixinPlugin;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPromise;\nimport net.minecraft.network.handler.NetworkStateTransitions;\nimport net.minecraft.network.packet.c2s.play.AcknowledgeReconfigurationC2SPacket;\nimport net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;\nimport net.minecraft.network.packet.s2c.play.EnterReconfigurationS2CPacket;\nimport net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;\nimport net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;\n\npublic class RakNetFabricChannelEventListener extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-fabric-event-listener\";\n\n    private static final boolean isReconfigurationSupported;\n\n    static {\n        boolean isReconfigurationSupported0;\n        try {\n            EnterReconfigurationS2CPacket.class.getName();\n            isReconfigurationSupported0 = true;\n        } catch (NoClassDefFoundError e) {\n            isReconfigurationSupported0 = false;\n        }\n        isReconfigurationSupported = isReconfigurationSupported0;\n    }\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        if (msg instanceof PlayerRespawnS2CPacket || msg instanceof GameJoinS2CPacket) {\n            ctx.write(SynchronizationLayer.SYNC_REQUEST_OBJECT);\n        }\n        if (isReconfigurationSupported) {\n            if (msg instanceof EnterReconfigurationS2CPacket || msg instanceof AcknowledgeReconfigurationC2SPacket) {\n                ctx.write(SynchronizationLayer.SYNC_REQUEST_OBJECT);\n            }\n        }\n        if (msg instanceof CommandTreeS2CPacket) {\n            ctx.write(RakNetSimpleMultiChannelCodec.SIGNAL_START_MULTICHANNEL);\n        }\n        if (RaknetifyFabricMixinPlugin.AFTER_1_20_5) {\n            if (msg instanceof NetworkStateTransitions.DecoderTransitioner || msg instanceof NetworkStateTransitions.EncoderTransitioner) {\n                ctx.write(RakNetNetworkTransitionUtil.handleTransition(msg), promise);\n                return;\n            }\n        }\n        super.write(ctx, msg, promise);\n    }\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/connection/RakNetFabricConnectionUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.connection;\n\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.common.connection.RakNetConnectionUtil;\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.fabric.common.compat.viafabric.ViaFabricCompatInjector;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPipeline;\nimport io.netty.channel.epoll.EpollDatagramChannel;\nimport io.netty.channel.epoll.EpollSocketChannel;\nimport io.netty.channel.kqueue.KQueueDatagramChannel;\nimport io.netty.channel.kqueue.KQueueSocketChannel;\nimport io.netty.channel.socket.DatagramChannel;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioDatagramChannel;\nimport io.netty.channel.socket.nio.NioSocketChannel;\nimport network.ycc.raknet.RakNet;\n\npublic class RakNetFabricConnectionUtil {\n\n    public static final String NAME_RAKNETIFY_MULTI_CHANNEL_PACKET_CATURE = \"raknetify-multi-channel-packet-cature\";\n\n    private RakNetFabricConnectionUtil() {\n    }\n\n    public static void initChannel(Channel channel) {\n        if (channel.config() instanceof RakNet.Config) {\n            RakNetConnectionUtil.initChannel(channel);\n            channel.pipeline().addAfter(MultiChannelingStreamingCompression.NAME, RakNetSimpleMultiChannelCodec.NAME, new RakNetSimpleMultiChannelCodec(Constants.RAKNET_GAME_PACKET_ID));\n        }\n    }\n\n    public static void postInitChannel(Channel channel, boolean isClientSide) {\n        if (channel.config() instanceof RakNet.Config) {\n            ViaFabricCompatInjector.inject(channel, isClientSide);\n            channel.pipeline().replace(\"timeout\", \"timeout\", new ChannelDuplexHandler()); // no-op\n            channel.pipeline().replace(\"splitter\", \"splitter\", new ChannelDuplexHandler()); // no-op\n            channel.pipeline().replace(\"prepender\", \"prepender\", new ChannelDuplexHandler()); // no-op\n            final MultiChannellingPacketCapture handler = new MultiChannellingPacketCapture();\n            channel.pipeline().addLast(NAME_RAKNETIFY_MULTI_CHANNEL_PACKET_CATURE, handler);\n            onPipelineReorder(channel.pipeline());\n            channel.pipeline().get(RakNetSimpleMultiChannelCodec.class)\n                    .addHandler(handler.getCustomPayloadHandler())\n                    .addHandler(handler.getCaptureBasedHandler());\n            channel.pipeline().addLast(\"raknetify-handle-compression-compatibility\", new RakNetCompressionCompatibilityHandler());\n            channel.pipeline().addBefore(\"packet_handler\", RakNetFabricChannelEventListener.NAME, new RakNetFabricChannelEventListener());\n        }\n    }\n\n    static void onPipelineReorder(ChannelPipeline pipeline) {\n        if (pipeline.get(\"encoder\") == null) {\n//            System.out.println(\"Reordering failed: no encoder\");\n            return;\n        }\n//        System.out.println(\"Reordering\");\n        ChannelHandler handler = pipeline.remove(RakNetFabricConnectionUtil.NAME_RAKNETIFY_MULTI_CHANNEL_PACKET_CATURE);\n        if (handler != null) {\n            pipeline.addAfter(\"encoder\", RakNetFabricConnectionUtil.NAME_RAKNETIFY_MULTI_CHANNEL_PACKET_CATURE, handler);\n        }\n    }\n\n    public static DatagramChannel fromSocketChannel(Class<? extends SocketChannel> clazz) {\n        if (clazz == NioSocketChannel.class) {\n            return new NioDatagramChannel();\n        } else if (clazz == EpollSocketChannel.class) {\n            return new EpollDatagramChannel();\n        } else if (clazz == KQueueSocketChannel.class) {\n            return new KQueueDatagramChannel();\n        } else {\n            throw new UnsupportedOperationException(clazz.getName());\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/connection/RakNetMultiChannel.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.connection;\n\nimport com.google.common.collect.Sets;\nimport it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;\nimport net.fabricmc.loader.api.FabricLoader;\nimport net.fabricmc.loader.api.MappingResolver;\n\nimport java.util.HashSet;\nimport java.util.Set;\n\npublic class RakNetMultiChannel {\n\n    private RakNetMultiChannel() {\n    }\n\n    private static Set<Class<?>> createClassSet(String[] classNames) {\n        final MappingResolver mappingResolver = FabricLoader.getInstance().getMappingResolver();\n        final boolean isIntermediaryNamespace = mappingResolver.getCurrentRuntimeNamespace().equals(\"intermediary\");\n        final HashSet<Class<?>> classHashSet = new HashSet<>();\n        for (String className : classNames) {\n            final String intermediary = mappingResolver.mapClassName(\"intermediary\", className.replace('/', '.'));\n            if (!isIntermediaryNamespace && intermediary.equals(className))\n                //noinspection RedundantStringFormatCall\n                System.err.println(\"Raknetify: Warning: Failed to remap %s for raknet multi-channel\".formatted(intermediary));\n            try {\n                classHashSet.add(Class.forName(intermediary, false, RakNetMultiChannel.class.getClassLoader()));\n            } catch (ClassNotFoundException e) {\n                if (Boolean.getBoolean(\"raknetify.printNotFoundClasses\")) {\n                    //noinspection RedundantStringFormatCall\n                    System.out.println(\"Raknetify: Warning: %s not found for raknet multi-channel\".formatted(intermediary));\n                }\n            }\n        }\n        return classHashSet; // no read-only wrapper for performance\n    }\n\n    private static final Set<Class<?>> unordered = createClassSet(new String[]{\n            \"net/minecraft/class_2670\", // KeepAliveS2C\n            \"net/minecraft/class_2827\", // KeepAliveC2S\n            \"net/minecraft/class_2661\", // DisconnectS2C\n            \"net/minecraft/class_6373\", // PlayPingS2C\n            \"net/minecraft/class_6374\", // PlayPongC2S\n\n            \"net/minecraft/class_2720\", // ResourcePackSendS2C\n            \"net/minecraft/class_2856\", // ResourcePackStatusC2S\n            \"net/minecraft/class_9053\", // ResourcePackRemoveS2CPacket\n\n            \"net/minecraft/class_2617\", // StatisticsS2C\n            \"net/minecraft/class_2859\", // AdvancementTabC2S\n            \"net/minecraft/class_2729\", // SelectAdvancementTabS2C\n\n            \"net/minecraft/class_2935\", // QueryPingC2SPacket\n            \"net/minecraft/class_2923\", // PingResultS2CPacket\n\n            \"net/minecraft/class_9814\", // CustomReportDetailsS2CPacket\n            \"net/minecraft/class_9815\", // ServerLinksS2CPacket\n    });\n\n    private static final Set<Class<?>> channel0 = createClassSet(new String[]{\n            \"net/minecraft/class_8588\", // EnterReconfigurationS2CPacket\n            \"net/minecraft/class_8591\", // AcknowledgeReconfigurationC2SPacket\n\n            \"net/minecraft/class_9151\", // ServerTransferS2CPacket\n    });\n\n    // Primarily used for interactions independent to world\n    private static final Set<Class<?>> channel1 = createClassSet(new String[]{\n            \"net/minecraft/class_2629\", // BossBarS2C\n            \"net/minecraft/class_5888\", // ClearTitleS2C\n            \"net/minecraft/class_5903\", // SubtitleS2C\n            \"net/minecraft/class_5904\", // TitleS2C\n            \"net/minecraft/class_5905\", // TitleFadeS2C\n            \"net/minecraft/class_5892\", // DeathMessageS2C\n            \"net/minecraft/class_2635\", // GameMessageS2CPacket\n            \"net/minecraft/class_7439\", // GameMessageS2CPacket\n            \"net/minecraft/class_7827\", // ProfilelessChatMessageS2CPacket\n            \"net/minecraft/class_7519\", // ChatPreviewStateChangeS2CPacket\n            \"net/minecraft/class_7438\", // ChatMessageS2CPacket\n            \"net/minecraft/class_7494\", // ChatPreviewS2CPacket\n            \"net/minecraft/class_7618\", // MOJMAP: ClientboundPlayerChatHeaderPacket\n            \"net/minecraft/class_7597\", // ChatSuggestionsS2CPacket\n            \"net/minecraft/class_7617\", // MOJMAP: ClientboundDeleteChatPacket\n            \"net/minecraft/class_7861\", // MOJMAP: ServerboundChatSessionUpdatePacket\n            \"net/minecraft/class_7640\", // UMMAPPED: chat related anyways\n            \"net/minecraft/class_7495\", // ServerMetadataS2CPacket\n            \"net/minecraft/class_5894\", // OverlayMessageS2C\n            \"net/minecraft/class_2748\", // ExperienceBarUpdateS2C\n            \"net/minecraft/class_2749\", // HealthUpdateS2C\n            \"net/minecraft/class_2656\", // CooldownUpdateS2CPacket\n            \"net/minecraft/class_2736\", // ScoreboardDisplayS2C\n            \"net/minecraft/class_2751\", // ScoreboardDisplayObjectiveUpdateS2C\n            \"net/minecraft/class_2757\", // ScoreboardPlayerUpdateS2C\n            \"net/minecraft/class_9006\", // ScoreboardScoreResetS2CPacket\n            \"net/minecraft/class_2779\", // AdvancementUpdateS2CPacket\n            \"net/minecraft/class_2641\", // CommandTreeS2C\n            \"net/minecraft/class_2639\", // CommandSuggestionsS2C\n\n            \"net/minecraft/class_2805\", // RequestCommandCompletionsC2S\n            \"net/minecraft/class_7472\", // CommandExecutionC2SPacket\n            \"net/minecraft/class_9449\", // ChatCommandSignedC2SPacket\n            \"net/minecraft/class_7496\", // RequestChatPreviewC2SPacket\n            \"net/minecraft/class_2811\", // ButtonClickC2S\n            \"net/minecraft/class_2797\", // ChatMessageC2S\n            \"net/minecraft/class_2813\", // ClickSlotC2S\n            \"net/minecraft/class_2848\", // ClientCommandC2S\n            \"net/minecraft/class_2803\", // ClientSettingsC2S\n            \"net/minecraft/class_2803\", // ClientStatusC2S\n            \"net/minecraft/class_4210\", // UpdateDifficultyC2S\n            \"net/minecraft/class_4211\", // UpdateDifficultyLockC2S\n            \"net/minecraft/class_2708\", // PlayerPositionLookS2C\n\n            \"net/minecraft/class_2846\", // PlayerActionC2S\n            \"net/minecraft/class_2851\", // PlayerInputC2S\n\n            // hard to categorize\n            \"net/minecraft/class_10370\", // PickItemFromBlockC2SPacket\n            \"net/minecraft/class_10371\", // PickItemFromEntityC2SPacket\n\n            \"net/minecraft/class_2707\", // LookAtS2C\n\n            \"net/minecraft/class_2761\", // WorldTimeUpdateS2C\n            \"net/minecraft/class_2632\", // DifficultyS2C\n            \"net/minecraft/class_5900\", // TeamS2C\n\n            \"net/minecraft/class_2788\", // SynchronizeRecipesS2C\n            \"net/minecraft/class_2790\", // SynchronizeTagsS2C\n\n            \"net/minecraft/class_2703\", // PlayerListS2C\n            \"net/minecraft/class_2772\", // PlayerListHeaderS2C\n            \"net/minecraft/class_7828\", // PlayerRemoveS2CPacket (actually only remove from list)\n            \"net/minecraft/class_2613\", // PlayerSpawnS2C\n\n            // 1.16.5\n            \"net/minecraft/class_2755\", // TeamS2CPacket\n            \"net/minecraft/class_2762\", // TitleS2CPacket\n\n            // 23w13a_or_b\n            \"net/minecraft/class_8258\", // ServerboundVoteCastPacket\n            \"net/minecraft/class_8483\", // ClientboundVoteStartPacket\n            \"net/minecraft/class_8478\", // ClientboundBulkVoteInfoPacket\n            \"net/minecraft/class_8482\", // ClientboundVoteProgressInfoPacket\n            \"net/minecraft/class_8481\", // ClientboundVoteFinishPacket\n            \"net/minecraft/class_8479\", // ClientboundRuleUpdatePacket\n            \"net/minecraft/class_8480\", // ClientboundVoteCastResultPacket\n\n            \"net/minecraft/class_9088\", // CookieRequestS2CPacket\n            \"net/minecraft/class_9150\", // StoreCookieS2CPacket\n            \"net/minecraft/class_9091\", // CookieResponseC2SPacket\n            \"net/minecraft/class_9178\", // DebugSampleS2CPacket\n            \"net/minecraft/class_9179\", // DebugSampleSubscriptionC2SPacket\n\n            \"net/minecraft/class_11173\", // WaypointS2CPacket\n            \"net/minecraft/class_11406\", // ClearDialogS2CPacket\n            \"net/minecraft/class_11407\", // ShowDialogS2CPacket\n            \"net/minecraft/class_11411\", // CustomClickActionC2SPacket\n    });\n\n    // Entities related stuff\n    private static final Set<Class<?>> channel2 = createClassSet(new String[]{\n            \"net/minecraft/class_5890\", // EndCombatS2C\n            \"net/minecraft/class_5891\", // EnterCombatS2C\n            \"net/minecraft/class_2716\", // EntitiesDestroyS2C\n            \"net/minecraft/class_2604\", // EntitySpawnS2C\n            \"net/minecraft/class_2616\", // EntityAnimationS2C\n            \"net/minecraft/class_2663\", // EntityStatusS2C\n            \"net/minecraft/class_2684$class_2685\", // EntityPacketS2C$MoveRelative\n            \"net/minecraft/class_2684$class_2687\", // EntityPacketS2C$Rotate\n            \"net/minecraft/class_2684$class_2686\", // EntityPacketS2C$RotateAndMoveRelative\n            \"net/minecraft/class_2726\", // EntitySetHeadYawS2C\n            \"net/minecraft/class_2739\", // EntityTrackerUpdateS2C\n            \"net/minecraft/class_2740\", // EntityAttachS2C\n            \"net/minecraft/class_2743\", // EntityVelocityUpdateS2C\n            \"net/minecraft/class_2744\", // EntityEquipmentUpdateS2C\n            \"net/minecraft/class_2752\", // EntityPassengerSetS2C\n            \"net/minecraft/class_2777\", // EntityPositionS2C\n            \"net/minecraft/class_10264\", // EntityPositionSyncS2CPacket\n            \"net/minecraft/class_2781\", // EntityAttributesS2C\n            \"net/minecraft/class_2783\", // EntityStatusEffectS2C\n            \"net/minecraft/class_2718\", // RemoveEntityStatusEffectS2C\n            \"net/minecraft/class_2610\", // MobSpawnS2C\n            \"net/minecraft/class_2612\", // PaintingSpawnS2C\n            \"net/minecraft/class_2606\", // ExperienceOrbSpawnS2CPacket\n            \"net/minecraft/class_8043\", // HurtAnimation (mojmap)\n            \"net/minecraft/class_8143\", // EntityDamageS2C\n            \"net/minecraft/class_9833\", // MoveMinecartAlongTrackS2CPacket\n\n            \"net/minecraft/class_2885\", // PlayerInteractBlockC2S\n            \"net/minecraft/class_2886\", // PlayerInteractItemC2S\n            \"net/minecraft/class_2824\", // PlayerInteractEntityC2S\n            \"net/minecraft/class_2828\", // PlayerMoveC2S\n            \"net/minecraft/class_2828$class_5911\", // PlayerMoveC2SPacket$OnGroundOnly\n            \"net/minecraft/class_2828$class_2829\", // PlayerMoveC2SPacket$PositionAndOnGround\n            \"net/minecraft/class_2828$class_2830\", // PlayerMoveC2SPacket$Full\n            \"net/minecraft/class_2828$class_2831\", // PlayerMoveC2SPacket$LookAndOnGround\n            \"net/minecraft/class_9836\", // ClientTickEndC2SPacket: used to track movement on vanilla server\n            \"net/minecraft/class_11410\", // ChangeGameModeC2SPacket\n\n            \"net/minecraft/class_2664\", // ExplosionS2C\n            \"net/minecraft/class_2678\", // GameJoinS2C\n            \"net/minecraft/class_7832\", // FeaturesS2CPacket\n            \"net/minecraft/class_2668\", // GameStateChangeS2C\n            \"net/minecraft/class_2759\", // PlayerSpawnPositionS2CPacket\n            \"net/minecraft/class_2775\", // ItemPickupAnimationS2C\n            \"net/minecraft/class_2696\", // PlayerAbilitiesS2C\n            \"net/minecraft/class_2734\", // SetCameraEntityS2C\n            \"net/minecraft/class_2692\", // VehicleMoveS2C\n\n            \"net/minecraft/class_2836\", // BoatPaddleStateC2S\n            \"net/minecraft/class_2833\", // VehicleMoveC2S\n            \"net/minecraft/class_2879\", // HandSwingC2S\n            \"net/minecraft/class_10265\", // PlayerRotationS2CPaket\n\n            // 1.16.5\n            \"net/minecraft/class_2684\", // EntityS2CPacket\n            \"net/minecraft/class_2698\", // CombatEventS2CPacket\n\n            // 23w13a_or_b\n            \"net/minecraft/class_8484\", // ServerboundCrashVehiclePacket\n\n            // 1.20.5\n            \"net/minecraft/class_9632\", // ProjectilePowerS2CPacket\n\n            \"net/minecraft/class_11984\", // EntityValueDebugS2CPacket\n            \"net/minecraft/class_11985\", // EventDebugS2CPacket\n    });\n\n    // Primarily used for interactions dependent to world\n    private static final Set<Class<?>> channel3 = createClassSet(new String[]{\n            \"net/minecraft/class_2884\", // SpectatorTeleportC2S\n            \"net/minecraft/class_2793\", // TeleportConfirmC2S\n\n            \"net/minecraft/class_2795\", // QueryBlockNbtC2S\n            \"net/minecraft/class_2822\", // QueryEntityNbtC2S\n            \"net/minecraft/class_2774\", // NbtQueryResponseS2C\n\n            \"net/minecraft/class_2645\", // CloseScreenS2C\n            \"net/minecraft/class_2648\", // OpenHorseScreenS2C\n            \"net/minecraft/class_3944\", // OpenScreenS2C\n            \"net/minecraft/class_2651\", // ScreenHandlerPropertyUpdateS2C\n            \"net/minecraft/class_2653\", // ScreenHandlerSlotUpdateS2C\n            \"net/minecraft/class_3895\", // OpenWrittenBookS2C\n            \"net/minecraft/class_2649\", // InventoryS2C\n            \"net/minecraft/class_2713\", // UnlockRecipesS2C\n            \"net/minecraft/class_2735\", // UpdateSelectedSlotS2C\n            \"net/minecraft/class_3943\", // SetTradeOffersS2C\n            \"net/minecraft/class_10266\", // RecipeBookAddS2CPacket\n            \"net/minecraft/class_10268\", // RecipeBookRemoveS2CPacket\n            \"net/minecraft/class_10269\", // RecipeBookSettingsS2CPacket\n\n            \"net/minecraft/class_2820\", // BookUpdateC2S\n            \"net/minecraft/class_2853\", // RecipeBookDataC2S\n            \"net/minecraft/class_5427\", // RecipeCategoryOptionsC2S\n            \"net/minecraft/class_2855\", // RenameItemC2S\n            \"net/minecraft/class_2815\", // CloseHandledScreenC2S\n            \"net/minecraft/class_2873\", // CreativeInventoryActionC2S\n            \"net/minecraft/class_2840\", // CraftRequestC2S\n            \"net/minecraft/class_2838\", // PickFromInventoryC2S\n            \"net/minecraft/class_2863\", // SelectMerchantTradeC2S\n            \"net/minecraft/class_2866\", // UpdateBeaconC2S\n            \"net/minecraft/class_2870\", // UpdateCommandBlockC2S\n            \"net/minecraft/class_2871\", // UpdateCommandBlockMinecartC2S\n            \"net/minecraft/class_10615\", // SetTestBlockC2SPacket\n            \"net/minecraft/class_10616\", // TestInstanceBlockActionC2SPacket\n            \"net/minecraft/class_3753\", // UpdateJigsawC2S\n            \"net/minecraft/class_2842\", // UpdatePlayerAbilitiesC2S\n            \"net/minecraft/class_2868\", // UpdateSelectedSlotC2S\n            \"net/minecraft/class_2875\", // UpdateStructureBlockC2S\n            \"net/minecraft/class_2695\", // CraftFailedResponseS2CPacket\n            \"net/minecraft/class_8875\", // SlotChangedStateC2SPacket\n            \"net/minecraft/class_9834\", // SetCursorItemS2CPacket\n            \"net/minecraft/class_9835\", // SetPlayerInventoryS2CPacket\n            \"net/minecraft/class_9837\", // BundleItemSelectedC2SPacket\n\n            \"net/minecraft/class_5889\", // WorldBorderInitializeS2C\n            \"net/minecraft/class_5895\", // WorldBorderCenterChangedS2C\n            \"net/minecraft/class_5896\", // WorldBorderInterpolateSizeS2C\n            \"net/minecraft/class_5897\", // WorldBorderSizeChangedS2C\n            \"net/minecraft/class_5898\", // WorldBorderWarningTimeChangedS2C\n            \"net/minecraft/class_5899\", // WorldBorderWarningBlockChangedS2C\n\n            \"net/minecraft/class_2799\", // ClientStatusC2SPacket\n            \"net/minecraft/class_2724\", // PlayerRespawnS2CPacket\n\n            \"net/minecraft/class_2817\", // CustomPayloadC2SPacket\n            \"net/minecraft/class_2658\", // CustomPayloadS2CPacket\n\n            \"net/minecraft/class_8914\", // TickStepS2CPacket\n            \"net/minecraft/class_8913\", // UpdateTickRateS2CPacket\n\n            // 1.16.5\n            \"net/minecraft/class_2809\", // ConfirmScreenActionC2SPacket\n            \"net/minecraft/class_2644\", // ConfirmScreenActionS2CPacket\n            \"net/minecraft/class_2730\", // WorldBorderS2CPacket\n\n    });\n\n    // Primarily for packets not very critical to interactions\n    private static final Set<Class<?>> channel4 = createClassSet(new String[]{\n            \"net/minecraft/class_2683\", // MapUpdateS2C\n            \"net/minecraft/class_2660\", // PlaySoundIdS2C\n            \"net/minecraft/class_2765\", // PlaySoundFromEntityS2C\n            \"net/minecraft/class_2767\", // PlaySoundS2C\n            \"net/minecraft/class_2770\", // StopSoundS2C\n\n            \"net/minecraft/class_2675\", // ParticleS2C\n            \"net/minecraft/class_5747\", // VibrationS2C\n    });\n\n    // Used for worlds\n    private static final Set<Class<?>> channel7 = createClassSet(new String[]{\n            \"net/minecraft/class_5194\", // JigsawGeneratingC2S\n            \"net/minecraft/class_2693\", // SignEditorOpenS2C\n            \"net/minecraft/class_2877\", // UpdateSignC2S\n\n            \"net/minecraft/class_2623\", // BlockEventS2CPacket\n            \"net/minecraft/class_4282\", // ChunkRenderDistanceCenterS2CPacket\n            \"net/minecraft/class_4273\", // ChunkLoadDistanceS2CPacket\n            \"net/minecraft/class_6682\", // SimulationDistanceS2C\n            \"net/minecraft/class_2666\", // UnloadChunkS2CPacket\n            \"net/minecraft/class_2626\", // BlockUpdateS2CPacket\n            \"net/minecraft/class_2637\", // ChunkDeltaUpdateS2CPacket\n            \"net/minecraft/class_2673\", // WorldEventS2CPacket\n            \"net/minecraft/class_2620\", // BlockBreakingProgressS2CPacket\n            \"net/minecraft/class_2672\", // ChunkDataS2CPacket\n            \"net/minecraft/class_2622\", // BlockEntityUpdateS2CPacket\n            \"net/minecraft/class_2676\", // LightUpdateS2CPacket\n            \"net/minecraft/class_8212\", // BiomeUpdateS2CPacket\n            \"net/minecraft/class_8738\", // ChunkSentS2CPacket\n            \"net/minecraft/class_8739\", // StartChunkSendS2CPacket\n            \"net/minecraft/class_8590\", // AcknowledgeChunksC2SPacket\n            \"net/minecraft/class_4463\", // PlayerActionResponseS2C\n\n            \"net/minecraft/class_10387\", // PlayerLoadedC2SPacket\n\n            \"net/minecraft/class_10614\", // TestInstanceBlockStatusS2CPacket\n\n            \"net/minecraft/class_11982\", // BlockValueDebugS2CPacket\n            \"net/minecraft/class_11983\", // ChunkValueDebugS2CPacket\n            \"net/minecraft/class_11986\", // GameTestHighlightPosS2CPacket\n\n    });\n\n    private static final Set<Class<?>> unreliable = createClassSet(new String[]{\n    });\n\n    private static final Set<Class<?>> theVoid = createClassSet(new String[]{\n            \"net/minecraft/class_8037\", // BundleDelimiterPacket\n            \"net/minecraft/class_9093\", // BundleDelimiterS2CPacket\n    });\n\n    private static final Object2IntOpenHashMap<Class<?>> classToChannelIdOverride = new Object2IntOpenHashMap<>();\n\n    static {\n        classToChannelIdOverride.defaultReturnValue(Integer.MAX_VALUE);\n        unordered.forEach(clazz -> classToChannelIdOverride.put(clazz, -1));\n        channel0.forEach(clazz -> classToChannelIdOverride.put(clazz, 0));\n        channel1.forEach(clazz -> classToChannelIdOverride.put(clazz, 1));\n        channel2.forEach(clazz -> classToChannelIdOverride.put(clazz, 2));\n        channel3.forEach(clazz -> classToChannelIdOverride.put(clazz, 3));\n        channel4.forEach(clazz -> classToChannelIdOverride.put(clazz, 4));\n        channel7.forEach(clazz -> classToChannelIdOverride.put(clazz, 7));\n        unreliable.forEach(clazz -> classToChannelIdOverride.put(clazz, -2));\n        theVoid.forEach(clazz -> classToChannelIdOverride.put(clazz, Integer.MIN_VALUE));\n    }\n\n//    private static final ThreadLocal<Class<?>> currentPacketClass = new ThreadLocal<>();\n//\n//    public static void setCurrentPacketClass(Class<?> clazz) {\n//        Preconditions.checkNotNull(clazz, \"clazz\");\n//        if (currentPacketClass.get() != null) throw new IllegalStateException(\"Already set\");\n//        currentPacketClass.set(clazz);\n//    }\n//\n//    public static void clearCurrentPacketClass(Class<?> clazz) {\n//        Preconditions.checkNotNull(clazz);\n//        final Class<?> threadLocalClazz = currentPacketClass.get();\n//        if (threadLocalClazz == null) throw new IllegalArgumentException(\"Not set\");\n//        if (threadLocalClazz != clazz) throw new IllegalArgumentException(\"Mismatch\");\n//        currentPacketClass.set(null);\n//    }\n\n    private static final Set<Class<?>> foundUnknownClasses = Sets.newConcurrentHashSet();\n\n    public static int getPacketChannelOverride(Class<?> clazz, boolean suppressWarning) {\n        if (clazz == null) {\n            System.err.println(\"Raknetify: Warning: Tried to send packet without setting packet class\");\n            return 0;\n        }\n        int channelOverride = classToChannelIdOverride.getInt(clazz);\n        if (channelOverride == Integer.MAX_VALUE) {\n            if (!suppressWarning) {\n                if (foundUnknownClasses.add(clazz)) {\n                    final MappingResolver mappingResolver = FabricLoader.getInstance().getMappingResolver();\n                    final String intermediary = mappingResolver.unmapClassName(\"intermediary\", clazz.getName());\n                    System.err.println(\"Raknetify: Warning: unknown packet type %s (%s) for raknet multi-channel\".formatted(intermediary.replace('.', '/'), clazz.getName()));\n                }\n            }\n            channelOverride = 7;\n        }\n        return channelOverride;\n    }\n\n    public static void init() {\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/connection/RakNetNetworkTransitionUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.connection;\n\nimport net.minecraft.network.handler.NetworkStateTransitions;\n\npublic class RakNetNetworkTransitionUtil {\n\n    static Object handleTransition(Object msg) {\n        if (msg instanceof NetworkStateTransitions.DecoderTransitioner transitioner) {\n            return transitioner.andThen(context -> RakNetFabricConnectionUtil.onPipelineReorder(context.pipeline()));\n        } else if (msg instanceof NetworkStateTransitions.EncoderTransitioner transitioner) {\n            return transitioner.andThen(context -> RakNetFabricConnectionUtil.onPipelineReorder(context.pipeline()));\n        }\n        return msg;\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/connection/encryption/PacketEncryptionManagerInterface.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.connection.encryption;\n\nimport io.netty.channel.ChannelHandlerContext;\n\npublic interface PacketEncryptionManagerInterface {\n\n    void setContext(ChannelHandlerContext ctx);\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/package-info.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common;\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/quirks/ClientHungerManager.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.quirks;\n\nimport com.ishland.raknetify.fabric.common.util.MultiVersionUtil;\nimport com.ishland.raknetify.fabric.mixin.RaknetifyFabricMixinPlugin;\nimport net.minecraft.component.type.FoodComponent;\nimport net.minecraft.entity.player.HungerManager;\nimport net.minecraft.nbt.NbtCompound;\nimport net.minecraft.storage.NbtReadView;\n\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Modifier;\n\npublic class ClientHungerManager extends HungerManager {\n\n    public static ClientHungerManager from(HungerManager hungerManager) {\n        ClientHungerManager clientHungerManager = new ClientHungerManager();\n        if (RaknetifyFabricMixinPlugin.AFTER_1_21_5) {\n            for (Field field : HungerManager.class.getFields()) {\n                if ((field.getModifiers() & Modifier.STATIC) == 0 && (field.getModifiers() & Modifier.FINAL) == 0) {\n                    if (!field.trySetAccessible()) {\n                        System.err.println(\"Failed to set field \" + field.getName() + \" accessible in HungerManager\");\n                        continue;\n                    }\n                    try {\n                        Object value = field.get(hungerManager);\n                        field.set(clientHungerManager, value);\n                    } catch (Throwable e) {\n                        System.err.println(\"Failed to copy field \" + field.getName() + \" from HungerManager to ClientHungerManager\");\n                        e.printStackTrace();\n                    }\n                }\n            }\n        } else {\n            NbtCompound compound = new NbtCompound();\n            try {\n                MultiVersionUtil.HungerManager$writeNbt1_21_5.invoke(hungerManager, compound);\n            } catch (Throwable e) {\n                throw new RuntimeException(e);\n            }\n            try {\n                MultiVersionUtil.HungerManager$readNbt1_21_5.invoke(clientHungerManager, compound);\n            } catch (Throwable e) {\n                throw new RuntimeException(e);\n            }\n        }\n        return clientHungerManager;\n    }\n\n    public void add(int food, float saturationModifier) {\n        // nop\n    }\n\n    public void eat(FoodComponent foodComponent) {\n        // nop\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/util/FieldSignatureParser.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.util;\n\nimport org.objectweb.asm.Type;\nimport org.objectweb.asm.signature.SignatureReader;\nimport org.objectweb.asm.signature.SignatureVisitor;\nimport org.spongepowered.asm.util.asm.ASM;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class FieldSignatureParser extends SignatureVisitor {\n\n    private final List<Type> results = new ArrayList<>();\n\n    private FieldSignatureParser() {\n        super(ASM.API_VERSION);\n    }\n\n    public static List<Type> parse(String signature) {\n        if (signature == null || signature.isEmpty()) {\n            return List.of();\n        }\n        FieldSignatureParser parser = new FieldSignatureParser();\n        new SignatureReader(signature).acceptType(parser);\n        return parser.results;\n    }\n\n    @Override\n    public void visitClassType(String name) {\n        results.add(Type.getObjectType(name));\n    }\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/util/LegacySupportUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.util;\n\nimport com.ishland.raknetify.fabric.mixin.RaknetifyFabricMixinPlugin;\nimport net.minecraft.entity.Entity;\nimport net.minecraft.world.World;\n\npublic class LegacySupportUtil {\n\n    public static World getEntityWorld(Entity entity) {\n        if (RaknetifyFabricMixinPlugin.AFTER_1_21_8) {\n            return entity.getEntityWorld();\n        } else {\n            try {\n                return (World) MultiVersionUtil.Entity$getEntity1_21_8.invokeExact(entity);\n            } catch (Throwable e) {\n                throw new RuntimeException(e);\n            }\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/util/MultiVersionUtil.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.util;\n\nimport com.google.common.collect.ImmutableList;\nimport net.fabricmc.api.EnvType;\nimport net.fabricmc.loader.api.FabricLoader;\nimport net.fabricmc.loader.api.MappingResolver;\nimport net.minecraft.client.network.ClientPlayNetworkHandler;\nimport net.minecraft.entity.Entity;\nimport net.minecraft.entity.player.HungerManager;\nimport net.minecraft.nbt.NbtCompound;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.state.NetworkState;\nimport net.minecraft.server.network.ServerPlayNetworkHandler;\nimport net.minecraft.server.network.ServerPlayerEntity;\nimport org.spongepowered.asm.mixin.transformer.meta.MixinMerged;\n\nimport java.lang.annotation.Annotation;\nimport java.lang.invoke.MethodHandle;\nimport java.lang.invoke.MethodHandles;\nimport java.lang.invoke.VarHandle;\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Method;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.function.Function;\n\npublic class MultiVersionUtil {\n\n    private static final String INTERMEDIARY = \"intermediary\";\n    private static final String CLASSNAME_ServerPlayNetworkHandler = \"net.minecraft.class_3244\";\n    private static final String CLASSNAME_NetworkStatePacketHandler = \"net.minecraft.class_2539$class_8698\";\n    private static final String CLASSNAME_NetworkState$InternalPacketHandler = \"net.minecraft.class_2539$class_4532\";\n    private static final String CLASSNAME_NetworkState$Factory = \"net.minecraft.class_9127$class_9128\";\n    private static final String CLASSNAME_ContextAwareNetworkStateFactory = \"net.minecraft.class_10947\";\n    private static final String CLASSNAME_PlayStateFactories = \"net.minecraft.class_9095\";\n    private static final String CLASSNAME_HungerManager = \"net.minecraft.class_1702\";\n    private static final String CLASSNAME_Entity = \"net.minecraft.class_1297\";\n\n    public static final VarHandle ServerPlayNetworkHandler$connection;\n    public static final VarHandle ClientPlayNetworkHandler$connection;\n    public static final VarHandle ServerPlayerEntity$pingMillis1_20_1;\n    public static final Class<?> clazzNetworkStatePacketHandler;\n    public static final VarHandle NetworkStatePacketHandler$backingHandler1_20_2;\n    public static final MethodHandle NetworkState$Factory$bind1_20_5;\n    public static final Class<?> clazzPlayStateFactories;\n    public static final VarHandle PlayStateFactories$C2S1_20_5;\n    public static final VarHandle PlayStateFactories$S2C1_20_5;\n    public static final MethodHandle HungerManager$writeNbt1_21_5;\n    public static final MethodHandle HungerManager$readNbt1_21_5;\n    public static final MethodHandle Entity$getEntity1_21_8;\n\n    static {\n        try {\n            final MappingResolver resolver = FabricLoader.getInstance().getMappingResolver();\n\n            {\n                final List<Field> connFields = tryLocateFields(ServerPlayNetworkHandler.class, ClientConnection.class, false);\n                if (connFields.size() != 1) {\n                    throw new IllegalStateException(\"Ambiguous fields for ClientConnection in ServerPlayNetworkHandler: found \" + Arrays.toString(connFields.toArray()));\n                }\n                if (connFields.isEmpty()) {\n                    throw new IllegalStateException(\"Cannot find field for ClientConnection in ServerPlayNetworkHandler\");\n                }\n                final Field connField = connFields.get(0);\n                connField.setAccessible(true);\n                ServerPlayNetworkHandler$connection = MethodHandles\n                        .privateLookupIn(ServerPlayNetworkHandler.class, MethodHandles.lookup())\n                        .unreflectVarHandle(connField);\n            }\n\n            if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {\n                final List<Field> connFields = tryLocateFields(ClientPlayNetworkHandler.class, ClientConnection.class, false);\n                if (connFields.size() != 1) {\n                    throw new IllegalStateException(\"Ambiguous fields for ClientConnection in ClientPlayNetworkHandler: found \" + Arrays.toString(connFields.toArray()));\n                }\n                if (connFields.isEmpty()) {\n                    throw new IllegalStateException(\"Cannot find field for ClientConnection in ClientPlayNetworkHandler\");\n                }\n                final Field connField = connFields.get(0);\n                connField.setAccessible(true);\n                ClientPlayNetworkHandler$connection = MethodHandles\n                        .privateLookupIn(ClientPlayNetworkHandler.class, MethodHandles.lookup())\n                        .unreflectVarHandle(connField);\n            } else {\n                ClientPlayNetworkHandler$connection = null;\n            }\n\n            {\n                final Field pingMillis1_20_1 = getOrNull(() -> ServerPlayerEntity.class.getDeclaredField(resolver.mapFieldName(INTERMEDIARY, \"net.minecraft.class_3222\", \"field_13967\", \"I\")), NoSuchFieldException.class);\n                if (pingMillis1_20_1 != null) {\n                    pingMillis1_20_1.setAccessible(true);\n                    ServerPlayerEntity$pingMillis1_20_1 = MethodHandles\n                            .privateLookupIn(ServerPlayerEntity.class, MethodHandles.lookup())\n                            .unreflectVarHandle(pingMillis1_20_1);\n                } else {\n                    ServerPlayerEntity$pingMillis1_20_1 = null;\n                }\n            }\n\n            {\n                clazzNetworkStatePacketHandler = getOrNull(() -> Class.forName(resolver.mapClassName(INTERMEDIARY, CLASSNAME_NetworkStatePacketHandler)), ClassNotFoundException.class);\n                if (clazzNetworkStatePacketHandler != null) {\n                    final Field backingHandler1_20_2 = getOrNull(() -> clazzNetworkStatePacketHandler.getDeclaredField(resolver.mapFieldName(INTERMEDIARY, CLASSNAME_NetworkStatePacketHandler, \"field_45674\", \"L\" + resolver.mapClassName(INTERMEDIARY, CLASSNAME_NetworkState$InternalPacketHandler) + \";\")), NoSuchFieldException.class);\n                    if (backingHandler1_20_2 != null) {\n                        backingHandler1_20_2.setAccessible(true);\n                        NetworkStatePacketHandler$backingHandler1_20_2 = MethodHandles\n                                .privateLookupIn(clazzNetworkStatePacketHandler, MethodHandles.lookup())\n                                .unreflectVarHandle(backingHandler1_20_2);\n                    } else {\n                        NetworkStatePacketHandler$backingHandler1_20_2 = null;\n                    }\n                } else {\n                    NetworkStatePacketHandler$backingHandler1_20_2 = null;\n                }\n            }\n\n            {\n                Method factoryBind = getOrNull(() -> NetworkState.Unbound.class.getDeclaredMethod(\"bind\" /* actually not obfuscated in 1.20.6 */, Function.class), NoSuchMethodException.class, NoClassDefFoundError.class);\n                if (factoryBind == null) {\n                    factoryBind = getOrNull(() -> NetworkState.Unbound.class.getDeclaredMethod(resolver.mapMethodName(INTERMEDIARY, CLASSNAME_NetworkState$Factory, \"method_61107\", \"(Ljava/util/function/Function;)Lnet/minecraft/class_9127;\"), Function.class), NoSuchMethodException.class, NoClassDefFoundError.class);\n                }\n                if (factoryBind != null) {\n                    factoryBind.setAccessible(true);\n                    NetworkState$Factory$bind1_20_5 = MethodHandles\n                            .privateLookupIn(NetworkState.Unbound.class, MethodHandles.lookup())\n                            .unreflect(factoryBind);\n                } else {\n                    NetworkState$Factory$bind1_20_5 = null;\n                }\n            }\n\n            clazzPlayStateFactories = getOrNull(() -> Class.forName(resolver.mapClassName(INTERMEDIARY, CLASSNAME_PlayStateFactories), false, MultiVersionUtil.class.getClassLoader()), ClassNotFoundException.class);\n\n            {\n                if (clazzPlayStateFactories != null) {\n                    final Field playStateFactoriesC2S1_20_5 = getOrNull(() -> clazzPlayStateFactories.getDeclaredField(resolver.mapFieldName(INTERMEDIARY, CLASSNAME_PlayStateFactories, \"field_48172\", \"L\" + CLASSNAME_NetworkState$Factory.replace('.', '/') + \";\")), NoSuchFieldException.class);\n                    if (playStateFactoriesC2S1_20_5 != null) {\n                        playStateFactoriesC2S1_20_5.setAccessible(true);\n                        PlayStateFactories$C2S1_20_5 = MethodHandles\n                                .privateLookupIn(clazzPlayStateFactories, MethodHandles.lookup())\n                                .unreflectVarHandle(playStateFactoriesC2S1_20_5);\n                    } else {\n                        PlayStateFactories$C2S1_20_5 = null;\n                    }\n                } else {\n                    PlayStateFactories$C2S1_20_5 = null;\n                }\n            }\n\n            {\n                if (clazzPlayStateFactories != null) {\n                    final Field playStateFactoriesS2C1_20_5 = getOrNull(() -> clazzPlayStateFactories.getDeclaredField(resolver.mapFieldName(INTERMEDIARY, CLASSNAME_PlayStateFactories, \"field_48173\", \"L\" + CLASSNAME_NetworkState$Factory.replace('.', '/') + \";\")), NoSuchFieldException.class);\n                    if (playStateFactoriesS2C1_20_5 != null) {\n                        playStateFactoriesS2C1_20_5.setAccessible(true);\n                        PlayStateFactories$S2C1_20_5 = MethodHandles\n                                .privateLookupIn(clazzPlayStateFactories, MethodHandles.lookup())\n                                .unreflectVarHandle(playStateFactoriesS2C1_20_5);\n                    } else {\n                        PlayStateFactories$S2C1_20_5 = null;\n                    }\n                } else {\n                    PlayStateFactories$S2C1_20_5 = null;\n                }\n            }\n\n            {\n                final Method writeNbt1_21_5 = getOrNull(() -> HungerManager.class.getDeclaredMethod(resolver.mapMethodName(INTERMEDIARY, CLASSNAME_HungerManager, \"method_7582\", \"(Lnet/minecraft/class_2487;)V\"), NbtCompound.class), NoSuchMethodException.class);\n                if (writeNbt1_21_5 != null) {\n                    writeNbt1_21_5.setAccessible(true);\n                    HungerManager$writeNbt1_21_5 = MethodHandles\n                            .privateLookupIn(HungerManager.class, MethodHandles.lookup())\n                            .unreflect(writeNbt1_21_5);\n                } else {\n                    HungerManager$writeNbt1_21_5 = null;\n                }\n            }\n\n            {\n                final Method readNbt1_21_5 = getOrNull(() -> HungerManager.class.getDeclaredMethod(resolver.mapMethodName(INTERMEDIARY, CLASSNAME_HungerManager, \"method_7584\", \"(Lnet/minecraft/class_2487;)V\"), NbtCompound.class), NoSuchMethodException.class);\n                if (readNbt1_21_5 != null) {\n                    readNbt1_21_5.setAccessible(true);\n                    HungerManager$readNbt1_21_5 = MethodHandles\n                            .privateLookupIn(HungerManager.class, MethodHandles.lookup())\n                            .unreflect(readNbt1_21_5);\n                } else {\n                    HungerManager$readNbt1_21_5 = null;\n                }\n            }\n\n            {\n                final Method getEntity1_21_8 = getOrNull(() -> Entity.class.getDeclaredMethod(resolver.mapFieldName(INTERMEDIARY, CLASSNAME_Entity, \"method_37908\", \"()Lnet/minecraft/class_1937;\")), NoSuchMethodException.class);\n                if (getEntity1_21_8 != null) {\n                    getEntity1_21_8.setAccessible(true);\n                    Entity$getEntity1_21_8 = MethodHandles\n                            .privateLookupIn(Entity.class, MethodHandles.lookup())\n                            .unreflect(getEntity1_21_8);\n                } else {\n                    Entity$getEntity1_21_8 = null;\n                }\n            }\n\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n    }\n\n    private static List<Field> tryLocateFields(Class<?> clazz, Class<?> fieldType, boolean includeMixinMerged) {\n        final ImmutableList.Builder<Field> builder = ImmutableList.builder();\n        final Class<?> superclass = clazz.getSuperclass();\n        if (superclass != null) {\n            builder.addAll(tryLocateFields(superclass, fieldType, includeMixinMerged));\n        }\n        __outerloop:\n        for (Field field : clazz.getDeclaredFields()) {\n            if (!includeMixinMerged) {\n                for (Annotation annotation : field.getDeclaredAnnotations()) {\n                    if (annotation.annotationType() == MixinMerged.class) {\n                        continue __outerloop;\n                    }\n                }\n            }\n\n            if (field.getType() == fieldType) {\n                builder.add(field);\n            }\n        }\n        return builder.build();\n    }\n\n    public static void init() {\n    }\n\n    public static Class<?> tryLocateClass(String name) {\n        try {\n            return Class.forName(name);\n        } catch (ClassNotFoundException e) {\n            return null;\n        }\n    }\n\n    private static <T> T getOrNull(SupplierThrowable<T> supplier, Class<? extends Throwable>... catchExceptions) {\n        try {\n            return supplier.get();\n        } catch (Throwable t) {\n            for (Class<? extends Throwable> catchException : catchExceptions) {\n                if (catchException.isInstance(t)) {\n                    return null;\n                }\n            }\n\n            throw new RuntimeException(t);\n        }\n    }\n\n    private interface SupplierThrowable<T> {\n        T get() throws Throwable;\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/common/util/NetworkStates.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.common.util;\n\nimport net.minecraft.network.NetworkPhase;\n\npublic class NetworkStates {\n\n    public static String getName(NetworkPhase state) {\n        return switch (state) {\n            case HANDSHAKING -> \"HANDSHAKING\";\n            case PLAY -> \"PLAY\";\n            case STATUS -> \"STATUS\";\n            case LOGIN -> \"LOGIN\";\n            default -> state.toString();\n        };\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/RaknetifyFabricMixinPlugin.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin;\n\nimport com.llamalad7.mixinextras.MixinExtrasBootstrap;\nimport net.fabricmc.api.EnvType;\nimport net.fabricmc.loader.api.FabricLoader;\nimport net.fabricmc.loader.api.VersionParsingException;\nimport net.fabricmc.loader.api.metadata.version.VersionPredicate;\nimport org.objectweb.asm.tree.ClassNode;\nimport org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;\nimport org.spongepowered.asm.mixin.extensibility.IMixinInfo;\n\nimport java.util.List;\nimport java.util.Set;\n\npublic class RaknetifyFabricMixinPlugin implements IMixinConfigPlugin {\n\n    public static final boolean AFTER_1_20_1;\n    public static final boolean AFTER_1_20_2;\n    public static final boolean AFTER_1_20_4;\n    public static final boolean AFTER_1_20_5;\n    public static final boolean AFTER_1_21_4;\n    public static final boolean AFTER_1_21_5;\n    public static final boolean AFTER_1_21_8;\n    public static final boolean AFTER_1_21_10;\n\n    static {\n        try {\n            AFTER_1_20_1 = VersionPredicate.parse(\">1.20.1\").test(FabricLoader.getInstance().getModContainer(\"minecraft\").get().getMetadata().getVersion());\n            AFTER_1_20_2 = VersionPredicate.parse(\">1.20.2\").test(FabricLoader.getInstance().getModContainer(\"minecraft\").get().getMetadata().getVersion());\n            AFTER_1_20_4 = VersionPredicate.parse(\">1.20.4\").test(FabricLoader.getInstance().getModContainer(\"minecraft\").get().getMetadata().getVersion());\n            AFTER_1_20_5 = VersionPredicate.parse(\">1.20.5\").test(FabricLoader.getInstance().getModContainer(\"minecraft\").get().getMetadata().getVersion());\n            AFTER_1_21_4 = VersionPredicate.parse(\">1.21.4\").test(FabricLoader.getInstance().getModContainer(\"minecraft\").get().getMetadata().getVersion());\n            AFTER_1_21_5 = VersionPredicate.parse(\">1.21.5\").test(FabricLoader.getInstance().getModContainer(\"minecraft\").get().getMetadata().getVersion());\n            AFTER_1_21_8 = VersionPredicate.parse(\">1.21.8\").test(FabricLoader.getInstance().getModContainer(\"minecraft\").get().getMetadata().getVersion());\n            AFTER_1_21_10 = VersionPredicate.parse(\">1.21.10\").test(FabricLoader.getInstance().getModContainer(\"minecraft\").get().getMetadata().getVersion());\n        } catch (VersionParsingException e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n\n    @Override\n    public void onLoad(String mixinPackage) {\n        System.setProperty(\"raknetserver.maxPacketLoss\", String.valueOf(Integer.MAX_VALUE));\n        MixinExtrasBootstrap.init();\n    }\n\n    @Override\n    public String getRefMapperConfig() {\n        return null;\n    }\n\n    @Override\n    public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {\n        if (mixinClassName.startsWith(\"com.ishland.raknetify.fabric.mixin.client.\")) {\n            if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {\n                if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.client.MixinMultiplayerServerListPinger1_20_2\"))\n                    return AFTER_1_20_1 && !AFTER_1_20_4;\n                if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.client.MixinMultiplayerServerListPinger1_20_5\"))\n                    return AFTER_1_20_4 && !AFTER_1_21_10;\n                if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.client.MixinMultiplayerServerListPinger1_21_11\"))\n                    return AFTER_1_21_10;\n                if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.client.hud.MixinDebugHud1_21_8\"))\n                    return !AFTER_1_21_8;\n                return true;\n            } else {\n                return false;\n            }\n        }\n        if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.server.MixinServerPlayNetworkHandler1_20_1\"))\n            return !AFTER_1_20_1;\n        if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.server.MixinServerCommonNetworkHandler\"))\n            return AFTER_1_20_1;\n        if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.server.MixinPlayerManager1_20_2\"))\n            return AFTER_1_20_1;\n        if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.common.MixinClientConnection1_20_2\"))\n            return AFTER_1_20_1;\n        if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.server.MixinPlayerManager1_20_1\"))\n            return !AFTER_1_20_1;\n        if (mixinClassName.equals(\"com.ishland.raknetify.fabric.mixin.access.INetworkState1_20_4\"))\n            return !AFTER_1_20_4;\n        return true;\n    }\n\n    @Override\n    public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {\n\n    }\n\n    @Override\n    public List<String> getMixins() {\n        return null;\n    }\n\n    @Override\n    public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {\n\n    }\n\n    @Override\n    public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {\n\n    }\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/IClientConnection.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport io.netty.channel.Channel;\nimport net.minecraft.network.ClientConnection;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.gen.Accessor;\n\n@Mixin(ClientConnection.class)\npublic interface IClientConnection {\n\n    @Accessor\n    Channel getChannel();\n\n    @Accessor\n    void setEncrypted(boolean encrypted);\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/IClientPlayNetworkHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport net.minecraft.client.network.ClientPlayNetworkHandler;\nimport net.minecraft.network.ClientConnection;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.gen.Accessor;\n\n@Mixin(ClientPlayNetworkHandler.class)\npublic interface IClientPlayNetworkHandler {\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/IDebugHudEntries.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport net.minecraft.client.gui.hud.debug.DebugHudEntries;\nimport net.minecraft.client.gui.hud.debug.DebugHudEntry;\nimport net.minecraft.util.Identifier;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.gen.Invoker;\n\n@Mixin(DebugHudEntries.class)\npublic interface IDebugHudEntries {\n\n    @Invoker\n    static Identifier invokeRegister(Identifier id, DebugHudEntry entry) {\n        throw new AbstractMethodError();\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/INetworkState1_20_4.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport net.minecraft.network.NetworkPhase;\nimport net.minecraft.network.NetworkSide;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Pseudo;\nimport org.spongepowered.asm.mixin.gen.Accessor;\n\nimport java.util.Map;\n\n@Pseudo\n@Mixin(targets = \"net/minecraft/class_2539\")\npublic interface INetworkState1_20_4 {\n\n    @Dynamic\n    @Accessor(value = \"field_20595\", remap = false)\n    Map<NetworkSide, ?> getPacketHandlers();\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/INetworkStateInternalPacketHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport it.unimi.dsi.fastutil.objects.Object2IntMap;\nimport net.minecraft.network.NetworkPhase;\nimport net.minecraft.network.packet.Packet;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.gen.Accessor;\n\n@Mixin(targets = \"net/minecraft/class_2539$class_4532\")\npublic interface INetworkStateInternalPacketHandler {\n\n    @Accessor(value = \"field_20596\")\n    Object2IntMap<Class<? extends Packet<?>>> getPacketIds();\n    \n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/IPacketCodecDispatcher.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport io.netty.buffer.ByteBuf;\nimport net.minecraft.network.handler.PacketCodecDispatcher;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.gen.Accessor;\n\nimport java.util.List;\n\n@Mixin(PacketCodecDispatcher.class)\npublic interface IPacketCodecDispatcher<B extends ByteBuf, V, T> {\n\n    @Accessor\n    List<PacketCodecDispatcher.PacketType<B, V, T>> getPacketTypes();\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/IPacketCodecDispatcherPacketType.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport net.minecraft.network.handler.PacketCodecDispatcher;\nimport org.spongepowered.asm.mixin.Mixin;\n\n@Mixin(PacketCodecDispatcher.PacketType.class)\npublic interface IPacketCodecDispatcherPacketType {\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/IPacketEncryptionManager.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelHandlerContext;\nimport net.minecraft.network.encryption.PacketEncryptionManager;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.gen.Invoker;\n\nimport javax.crypto.ShortBufferException;\n\n@Mixin(PacketEncryptionManager.class)\npublic interface IPacketEncryptionManager {\n\n    @Invoker\n    ByteBuf invokeDecrypt(ChannelHandlerContext context, ByteBuf buf) throws ShortBufferException;\n\n    @Invoker\n    void invokeEncrypt(ByteBuf buf, ByteBuf result) throws ShortBufferException;\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/IServerPlayNetworkHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport net.minecraft.server.network.ServerPlayNetworkHandler;\nimport org.spongepowered.asm.mixin.Mixin;\n\n@Mixin(ServerPlayNetworkHandler.class)\npublic interface IServerPlayNetworkHandler {\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/access/IWorld.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.access;\n\nimport net.minecraft.world.World;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.gen.Accessor;\n\n@Mixin(World.class)\npublic interface IWorld {\n\n    @Accessor(\"isClient\")\n    boolean raknetify$isClient();\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/client/MixinClientPlayNetworkHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.client;\n\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.fabric.common.util.MultiVersionUtil;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport io.netty.channel.Channel;\nimport net.minecraft.client.network.ClientPlayNetworkHandler;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(ClientPlayNetworkHandler.class)\npublic class MixinClientPlayNetworkHandler {\n\n    @Inject(method = \"onGameJoin\", at = @At(\"RETURN\"))\n    private void postGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) {\n        final Channel channel = ((IClientConnection) MultiVersionUtil.ClientPlayNetworkHandler$connection.get((ClientPlayNetworkHandler) (Object) this)).getChannel();\n        if (channel == null) {\n            //noinspection RedundantStringFormatCall\n            System.err.println(\"Raknetify: Warning: %s don't have valid channel when logged in, not sending sync packet\".formatted(this));\n            return;\n        }\n        channel.eventLoop().execute(() -> channel.write(RakNetSimpleMultiChannelCodec.SIGNAL_START_MULTICHANNEL));\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/client/MixinConnectionScreen1.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.client;\n\nimport com.ishland.raknetify.fabric.common.connection.RakNetClientConnectionUtil;\nimport com.ishland.raknetify.common.util.PrefixUtil;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;\nimport io.netty.channel.ChannelFuture;\nimport net.minecraft.client.network.ServerAddress;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.NetworkingBackend;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Mutable;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.Unique;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Coerce;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.net.InetSocketAddress;\n\n@Mixin(targets = \"net/minecraft/client/gui/screen/multiplayer/ConnectScreen$1\")\npublic class MixinConnectionScreen1 extends Thread {\n\n    @Mutable\n    @Shadow\n    @Final\n    ServerAddress field_33737;\n\n    @Unique\n    private boolean isRaknet = false;\n\n    @Unique\n    private boolean raknetLargeMTU = false;\n\n    @Inject(method = \"<init>*\", at = @At(\"RETURN\"), remap = false)\n    private void onInit(CallbackInfo ci) {\n        final PrefixUtil.Info info = PrefixUtil.getInfo(this.field_33737.getAddress());\n        if (info.useRakNet()) {\n            this.isRaknet = true;\n            this.raknetLargeMTU = info.largeMTU();\n            this.field_33737 = new ServerAddress(info.stripped(), this.field_33737.getPort());\n        }\n    }\n\n    @Dynamic\n    @WrapOperation(method = \"run()V\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/ClientConnection;method_10753(Ljava/net/InetSocketAddress;Z)Lnet/minecraft/network/ClientConnection;\"), require = 0)\n    private ClientConnection connectRaknet(InetSocketAddress address, boolean useEpoll, Operation<ClientConnection> original) {\n        return this.isRaknet ? RakNetClientConnectionUtil.connect(address, useEpoll, this.raknetLargeMTU, original, false) : original.call(address, useEpoll);\n    }\n\n    @Dynamic\n    @WrapOperation(method = \"run()V\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/ClientConnection;method_52271(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;\"), require = 0)\n    private ChannelFuture connectRaknet(InetSocketAddress address, boolean useEpoll, ClientConnection connection, Operation<ChannelFuture> original) {\n        return this.isRaknet ? RakNetClientConnectionUtil.connect(address, useEpoll, this.raknetLargeMTU, original, connection) : original.call(address, useEpoll, connection);\n    }\n\n    @WrapOperation(method = \"run()V\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/ClientConnection;connect(Ljava/net/InetSocketAddress;Lnet/minecraft/network/NetworkingBackend;Lnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;\"), require = 0)\n    private ChannelFuture connectRaknet(InetSocketAddress address, @Coerce Object backend, ClientConnection connection, Operation<ChannelFuture> original) {\n        return this.isRaknet ? RakNetClientConnectionUtil.connect(address, backend, this.raknetLargeMTU, original, connection) : original.call(address, backend, connection);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/client/MixinMultiplayerServerListPinger.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.client;\n\nimport com.ishland.raknetify.fabric.common.connection.RakNetClientConnectionUtil;\nimport com.ishland.raknetify.common.util.PrefixUtil;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;\nimport net.minecraft.client.network.MultiplayerServerListPinger;\nimport net.minecraft.client.network.ServerAddress;\nimport net.minecraft.client.network.ServerInfo;\nimport net.minecraft.network.ClientConnection;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Redirect;\n\nimport java.net.InetSocketAddress;\n\n@Mixin(MultiplayerServerListPinger.class)\npublic abstract class MixinMultiplayerServerListPinger {\n\n    @Dynamic\n    @WrapOperation(method = {\"add\", \"method_3003\"}, at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/client/network/ServerAddress;parse(Ljava/lang/String;)Lnet/minecraft/client/network/ServerAddress;\"))\n    private ServerAddress modifyRaknetAddress(String address, Operation<ServerAddress> original) {\n        final PrefixUtil.Info info = PrefixUtil.getInfo(address);\n        return original.call(info.stripped());\n    }\n\n    @Dynamic\n    @WrapOperation(method = {\"add\", \"method_3003\"}, at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/ClientConnection;method_10753(Ljava/net/InetSocketAddress;Z)Lnet/minecraft/network/ClientConnection;\"), require = 0)\n    private ClientConnection redirectConnect(InetSocketAddress address, boolean useEpoll, Operation<ClientConnection> original, ServerInfo entry, Runnable runnable) {\n        final PrefixUtil.Info info = PrefixUtil.getInfo(entry.address);\n        return info.useRakNet() ? RakNetClientConnectionUtil.connect(address, useEpoll, info.largeMTU(), original, false) : original.call(address, useEpoll);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/client/MixinMultiplayerServerListPinger1.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.client;\n\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport com.llamalad7.mixinextras.injector.v2.WrapWithCondition;\nimport io.netty.channel.Channel;\nimport net.minecraft.client.network.MultiplayerServerListPinger;\nimport net.minecraft.client.network.ServerAddress;\nimport net.minecraft.client.network.ServerInfo;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.NetworkingBackend;\nimport net.minecraft.network.listener.ClientQueryPacketListener;\nimport network.ycc.raknet.RakNet;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.Redirect;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.net.InetSocketAddress;\n\n@Mixin(targets = \"net/minecraft/client/network/MultiplayerServerListPinger$1\")\npublic abstract class MixinMultiplayerServerListPinger1 implements ClientQueryPacketListener {\n\n    @Shadow\n    @Final\n    ClientConnection field_3774; // synthetic\n\n    @Shadow\n    @Final\n    ServerInfo field_3776; // synthetic\n\n    @Inject(method = \"onResponse(Lnet/minecraft/network/packet/s2c/query/QueryResponseS2CPacket;)V\", at = @At(\"RETURN\"))\n    private void setPingImmediately(CallbackInfo ci) {\n        final Channel channel = ((IClientConnection) field_3774).getChannel();\n        if (channel.config() instanceof RakNet.Config config) {\n            field_3776.ping = config.getRTTNanos() / 1_000_000;\n        }\n    }\n\n    @Dynamic\n    @WrapWithCondition(method = {\"method_10839(Lnet/minecraft/class_2561;)V\", \"onDisconnected\"}, at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/client/network/MultiplayerServerListPinger;method_3001(Ljava/net/InetSocketAddress;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;)V\"), require = 0)\n    private boolean noPingRaknet(MultiplayerServerListPinger instance, InetSocketAddress socketAddress, ServerAddress address, ServerInfo serverInfo) {\n        final Channel channel = ((IClientConnection) field_3774).getChannel();\n        return !(channel.config() instanceof RakNet.Config);\n    }\n\n    @WrapWithCondition(method = \"onDisconnected\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/client/network/MultiplayerServerListPinger;ping(Ljava/net/InetSocketAddress;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;Lnet/minecraft/network/NetworkingBackend;)V\"), require = 0)\n    private boolean noPingRaknet(MultiplayerServerListPinger instance, InetSocketAddress socketAddress, ServerAddress address, ServerInfo serverInfo, NetworkingBackend backend) {\n        final Channel channel = ((IClientConnection) field_3774).getChannel();\n        return !(channel.config() instanceof RakNet.Config);\n    }\n\n    @Dynamic\n    @WrapWithCondition(method = \"method_10839(Lnet/minecraft/class_2561;)V\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/client/network/MultiplayerServerListPinger;method_3001(Ljava/net/InetSocketAddress;Lnet/minecraft/client/network/ServerInfo;)V\"), require = 0)\n    private boolean noPingRaknet(MultiplayerServerListPinger instance, InetSocketAddress address, ServerInfo info) {\n        final Channel channel = ((IClientConnection) field_3774).getChannel();\n        return !(channel.config() instanceof RakNet.Config);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/client/MixinMultiplayerServerListPinger1_20_2.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.client;\n\nimport com.ishland.raknetify.common.util.PrefixUtil;\nimport com.ishland.raknetify.fabric.common.connection.RakNetClientConnectionUtil;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;\nimport net.minecraft.client.network.MultiplayerServerListPinger;\nimport net.minecraft.client.network.ServerInfo;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.util.profiler.log.DebugSampleLog;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\n\nimport java.net.InetSocketAddress;\n\n@Mixin(MultiplayerServerListPinger.class)\npublic class MixinMultiplayerServerListPinger1_20_2 {\n\n    @Dynamic\n    @WrapOperation(method = {\"add\", \"method_3003\"}, at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/ClientConnection;method_10753(Ljava/net/InetSocketAddress;ZLnet/minecraft/class_8743;)Lnet/minecraft/network/ClientConnection;\"))\n    private ClientConnection redirectConnect(InetSocketAddress address, boolean useEpoll, DebugSampleLog log, Operation<ClientConnection> original, ServerInfo entry, Runnable runnable) {\n        final PrefixUtil.Info info = PrefixUtil.getInfo(entry.address);\n        return info.useRakNet() ? RakNetClientConnectionUtil.connect(address, useEpoll, info.largeMTU(), original, true) : original.call(address, useEpoll, null);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/client/MixinMultiplayerServerListPinger1_20_5.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.client;\n\nimport com.ishland.raknetify.common.util.PrefixUtil;\nimport com.ishland.raknetify.fabric.common.connection.RakNetClientConnectionUtil;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;\nimport net.minecraft.client.network.MultiplayerServerListPinger;\nimport net.minecraft.client.network.ServerInfo;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.util.profiler.MultiValueDebugSampleLogImpl;\nimport net.minecraft.util.profiler.log.DebugSampleLog;\nimport net.minecraft.util.profiler.log.MultiValueDebugSampleLog;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\n\nimport java.net.InetSocketAddress;\n\n@Mixin(MultiplayerServerListPinger.class)\npublic class MixinMultiplayerServerListPinger1_20_5 {\n\n    @Dynamic\n    @WrapOperation(method = {\"add\", \"method_3003\"}, at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/ClientConnection;method_10753(Ljava/net/InetSocketAddress;ZLnet/minecraft/util/profiler/MultiValueDebugSampleLogImpl;)Lnet/minecraft/network/ClientConnection;\"))\n    private ClientConnection redirectConnect(InetSocketAddress address, boolean useEpoll, MultiValueDebugSampleLogImpl log, Operation<ClientConnection> original, ServerInfo entry, Runnable runnable) {\n        final PrefixUtil.Info info = PrefixUtil.getInfo(entry.address);\n        return info.useRakNet() ? RakNetClientConnectionUtil.connect(address, useEpoll, info.largeMTU(), original, true) : original.call(address, useEpoll, null);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/client/MixinMultiplayerServerListPinger1_21_11.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.client;\n\nimport com.ishland.raknetify.common.util.PrefixUtil;\nimport com.ishland.raknetify.fabric.common.connection.RakNetClientConnectionUtil;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;\nimport net.minecraft.client.network.MultiplayerServerListPinger;\nimport net.minecraft.client.network.ServerInfo;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.NetworkingBackend;\nimport net.minecraft.util.profiler.MultiValueDebugSampleLogImpl;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\n\nimport java.net.InetSocketAddress;\n\n@Mixin(MultiplayerServerListPinger.class)\npublic class MixinMultiplayerServerListPinger1_21_11 {\n\n    @WrapOperation(method = \"add\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/ClientConnection;connect(Ljava/net/InetSocketAddress;Lnet/minecraft/network/NetworkingBackend;Lnet/minecraft/util/profiler/MultiValueDebugSampleLogImpl;)Lnet/minecraft/network/ClientConnection;\"))\n    private ClientConnection redirectConnect(InetSocketAddress address, NetworkingBackend backend, MultiValueDebugSampleLogImpl packetSizeLog, Operation<ClientConnection> original, ServerInfo entry) {\n        final PrefixUtil.Info info = PrefixUtil.getInfo(entry.address);\n        return info.useRakNet() ? RakNetClientConnectionUtil.connect(address, backend, info.largeMTU(), original) : original.call(address, backend, null);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/client/hud/MixinDebugHud1_21_8.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.client.hud;\n\nimport com.ishland.raknetify.fabric.common.client.DebugHudUtil;\nimport net.minecraft.client.gui.hud.DebugHud;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;\n\nimport java.util.List;\n\n@Mixin(DebugHud.class)\npublic class MixinDebugHud1_21_8 {\n\n    @Dynamic\n    @Inject(method = \"method_1835\", at = @At(\"RETURN\"))\n    private void getLeftText(CallbackInfoReturnable<List<String>> cir) {\n        DebugHudUtil.getDebugString(cir.getReturnValue()::add);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/MixinCCConnect.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common;\n\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.RakNetConnectionUtil;\nimport com.ishland.raknetify.common.connection.RaknetifyEventLoops;\nimport com.ishland.raknetify.common.util.ThreadLocalUtil;\nimport com.ishland.raknetify.fabric.common.connection.RakNetFabricConnectionUtil;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;\nimport com.llamalad7.mixinextras.sugar.Share;\nimport com.llamalad7.mixinextras.sugar.ref.LocalRef;\nimport io.netty.bootstrap.AbstractBootstrap;\nimport io.netty.bootstrap.Bootstrap;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelOption;\nimport io.netty.channel.EventLoopGroup;\nimport io.netty.channel.FixedRecvByteBufAllocator;\nimport io.netty.channel.ReflectiveChannelFactory;\nimport io.netty.channel.epoll.Epoll;\nimport io.netty.channel.epoll.EpollDatagramChannel;\nimport io.netty.channel.socket.DatagramChannel;\nimport io.netty.channel.socket.SocketChannel;\nimport io.netty.channel.socket.nio.NioDatagramChannel;\nimport net.minecraft.network.ClientConnection;\nimport network.ycc.raknet.RakNet;\nimport network.ycc.raknet.client.channel.RakNetClientThreadedChannel;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\n\nimport java.net.InetSocketAddress;\n\n@Mixin(ClientConnection.class)\npublic class MixinCCConnect {\n\n    @Dynamic(\"method_10753, method_52271 for compat\")\n    @WrapOperation(method = {\"connect(Ljava/net/InetSocketAddress;Lnet/minecraft/network/NetworkingBackend;Lnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;\", \"method_52271(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;\", \"method_10753(Ljava/net/InetSocketAddress;Z)Lnet/minecraft/network/ClientConnection;\", \"method_10753\"}, at = @At(value = \"INVOKE\", target = \"Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;\", remap = false), require = 1)\n    private static AbstractBootstrap<Bootstrap, Channel> redirectGroup(Bootstrap instance, EventLoopGroup eventLoopGroup, Operation<AbstractBootstrap<Bootstrap, Channel>> original, InetSocketAddress address, @Share(\"raknetify$eventLoop\") LocalRef<EventLoopGroup> raknetify$eventLoop) {\n        raknetify$eventLoop.set(eventLoopGroup);\n        return ThreadLocalUtil.isInitializingRaknet()\n                ? original.call(instance, RaknetifyEventLoops.DEFAULT_CLIENT_EVENT_LOOP_GROUP.get())\n                : original.call(instance, eventLoopGroup);\n    }\n\n    @Dynamic(\"method_10753, method_52271 for compat\")\n    @WrapOperation(method = {\"connect(Ljava/net/InetSocketAddress;Lnet/minecraft/network/NetworkingBackend;Lnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;\", \"method_52271(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;\", \"method_10753(Ljava/net/InetSocketAddress;Z)Lnet/minecraft/network/ClientConnection;\", \"method_10753\"}, at = @At(value = \"INVOKE\", target = \"Lio/netty/bootstrap/Bootstrap;channel(Ljava/lang/Class;)Lio/netty/bootstrap/AbstractBootstrap;\", remap = false), require = 1)\n    private static AbstractBootstrap<Bootstrap, Channel> redirectChannel(Bootstrap instance, Class<? extends SocketChannel> aClass, Operation<AbstractBootstrap<Bootstrap, Channel>> original, InetSocketAddress address, @Share(\"raknetify$eventLoop\") LocalRef<EventLoopGroup> raknetify$eventLoop) {\n        EventLoopGroup eventLoopGroup = raknetify$eventLoop.get();\n        return ThreadLocalUtil.isInitializingRaknet()\n                ? instance.channelFactory(() -> {\n                    final boolean initializingRaknetLargeMTU = ThreadLocalUtil.isInitializingRaknetLargeMTU();\n                    final RakNetClientThreadedChannel channel = new RakNetClientThreadedChannel(() -> {\n                        final DatagramChannel channel1 = RakNetFabricConnectionUtil.fromSocketChannel(aClass);\n                        channel1.config().setOption(ChannelOption.IP_TOS, RakNetConnectionUtil.DEFAULT_IP_TOS);\n                        if (initializingRaknetLargeMTU)\n                            channel1.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(Constants.LARGE_MTU + 512).maxMessagesPerRead(128));\n                        else\n                            channel1.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(Constants.DEFAULT_MTU + 512).maxMessagesPerRead(128));\n                        return channel1;\n                    });\n                    RakNet.config(channel).setMTU(initializingRaknetLargeMTU ? Constants.LARGE_MTU : Constants.DEFAULT_MTU);\n                    channel.setProvidedParentEventLoop(eventLoopGroup.next());\n                    return channel;\n                })\n                : original.call(instance, aClass);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/MixinClientConnection.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common;\n\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.util.DebugUtil;\nimport com.ishland.raknetify.fabric.common.util.NetworkStates;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelFuture;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.util.AttributeKey;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.NetworkPhase;\nimport net.minecraft.network.NetworkSide;\nimport net.minecraft.network.listener.PacketListener;\nimport org.jetbrains.annotations.Nullable;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.Unique;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.Redirect;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.net.SocketAddress;\nimport java.nio.channels.ClosedChannelException;\n\n@Mixin(ClientConnection.class)\npublic abstract class MixinClientConnection {\n\n    @Shadow\n    private Channel channel;\n\n    @Shadow public abstract SocketAddress getAddress();\n\n    @Shadow private SocketAddress address;\n\n    @Shadow public abstract NetworkSide getSide();\n\n    @Shadow private volatile @Nullable PacketListener packetListener;\n    @Unique\n    private volatile boolean isClosing = false;\n\n    @Redirect(method = {\"disconnect(Lnet/minecraft/text/Text;)V\", \"disconnect(Lnet/minecraft/network/DisconnectionInfo;)V\"}, at = @At(value = \"INVOKE\", target = \"Lio/netty/channel/ChannelFuture;awaitUninterruptibly()Lio/netty/channel/ChannelFuture;\", remap = false), require = 1)\n    private ChannelFuture noDisconnectWait(ChannelFuture instance) {\n        isClosing = true;\n//        if (instance.channel().eventLoop().inEventLoop()) {\n//            return instance; // no-op\n//        } else {\n//            return instance.awaitUninterruptibly();\n//        }\n        return instance;\n    }\n\n    @Redirect(method = \"*\", at = @At(value = \"INVOKE\", target = \"Lio/netty/channel/Channel;isOpen()Z\", remap = false))\n    private boolean redirectIsOpen(Channel instance) {\n        return this.channel != null && (this.channel.isOpen() && !this.isClosing);\n    }\n\n//    @Inject(method = \"channelActive\", at = @At(\"HEAD\"))\n//    private void onChannelActive(ChannelHandlerContext ctx, CallbackInfo ci) {\n//        final Channel channel = ctx.channel();\n//        if (channel.config() instanceof RakNet.Config config) {\n//            if (this.side == NetworkSide.SERVERBOUND) {\n//                System.out.println(String.format(\"RakNet connection from %s, mtu %d\", channel.remoteAddress(), config.getMTU()));\n//            } else if (this.side == NetworkSide.CLIENTBOUND) {\n//                System.out.println(String.format(\"RakNet conncted to %s, mtu %d\", channel.remoteAddress(), config.getMTU()));\n//            }\n//        }\n//    }\n\n    @Inject(method = \"exceptionCaught\", at = @At(\"HEAD\"))\n    private void onExceptionCaught(ChannelHandlerContext context, Throwable ex, CallbackInfo ci) {\n        if (ex instanceof ClosedChannelException) return;\n        if (Constants.DEBUG) {\n            System.err.println(\"Exception caught for connection %s\".formatted(this.channel));\n            for (String s : DebugUtil.printChannelDetails(this.channel).split(\"\\n\")) {\n                System.err.println(\"  \" + s);\n            }\n            ex.printStackTrace();\n        } else {\n            final NetworkPhase state;\n            Object handler = this.channel.attr(AttributeKey.valueOf(\"protocol\")).get(); // pre-1.20.2\n            if (handler != null) {\n                if (handler instanceof NetworkPhase state1) {\n                    state = state1;\n                } else {\n                    System.err.println(\"Unknown handler type: \" + handler.getClass().getName());\n                    state = null;\n                }\n            } else {\n                final PacketListener packetListener1 = this.packetListener;\n                state = packetListener1 != null ? packetListener1.getPhase() : null;\n            }\n            if (state != null && state != NetworkPhase.HANDSHAKING) {\n                System.err.println(String.format(\"%s %s %s\", this.address, NetworkStates.getName(state), ex.toString()));\n            }\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/MixinClientConnection1.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common;\n\nimport com.ishland.raknetify.fabric.common.connection.RakNetFabricConnectionUtil;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelInitializer;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(targets = \"net/minecraft/network/ClientConnection$1\")\npublic abstract class MixinClientConnection1 extends ChannelInitializer<Channel> {\n\n    @Inject(method = \"initChannel(Lio/netty/channel/Channel;)V\", at = @At(\"HEAD\"))\n    private void onChannelInit(Channel channel, CallbackInfo ci) {\n        RakNetFabricConnectionUtil.initChannel(channel);\n    }\n\n    @Inject(method = \"initChannel(Lio/netty/channel/Channel;)V\", at = @At(\"RETURN\"))\n    private void postChannelInit(Channel channel, CallbackInfo ci) {\n        RakNetFabricConnectionUtil.postInitChannel(channel, true);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/MixinClientConnection1_20_2.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common;\n\nimport com.ishland.raknetify.common.connection.SimpleMetricsLogger;\nimport io.netty.channel.Channel;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.handler.PacketSizeLogger;\nimport network.ycc.raknet.RakNet;\nimport org.jetbrains.annotations.Nullable;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.Unique;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(ClientConnection.class)\npublic class MixinClientConnection1_20_2 {\n\n    @Shadow private Channel channel;\n    @Shadow private @Nullable PacketSizeLogger packetSizeLogger;\n\n    @Unique\n    private long raknetify$lastBytesIn = 0L;\n\n    @Inject(method = \"tick\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/handler/PacketSizeLogger;push()V\"))\n    private void onPacketLoggerPush(CallbackInfo ci) {\n        PacketSizeLogger logger = this.packetSizeLogger;\n        if (logger != null && this.channel.config() instanceof RakNet.Config config && config.getMetrics() instanceof SimpleMetricsLogger simpleMetricsLogger) {\n            long bytesIn = simpleMetricsLogger.getBytesIn();\n            logger.increment((int) (bytesIn - this.raknetify$lastBytesIn));\n            this.raknetify$lastBytesIn = bytesIn;\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/MixinServerAddress.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common;\n\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.util.PrefixUtil;\nimport com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport net.minecraft.client.network.ServerAddress;\nimport org.spongepowered.asm.mixin.Mixin;\n\n@Mixin(ServerAddress.class)\npublic class MixinServerAddress {\n\n    @WrapMethod(method = \"parse\")\n    private static ServerAddress wrapParsing(String address, Operation<ServerAddress> original) {\n        PrefixUtil.Info info = PrefixUtil.getInfo(address);\n        if (info.useRakNet()) {\n            ServerAddress addr = original.call(info.stripped());\n            return new ServerAddress(\n                    (info.largeMTU() ? Constants.RAKNET_LARGE_MTU_PREFIX : Constants.RAKNET_PREFIX) + addr.getAddress(),\n                    addr.getPort()\n            );\n        } else {\n            return original.call(address);\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/encryption/MixinClientConnection.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common.encryption;\n\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.common.connection.MultiChannellingEncryption;\nimport io.netty.channel.Channel;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.encryption.PacketDecryptor;\nimport net.minecraft.network.encryption.PacketEncryptionManager;\nimport net.minecraft.network.encryption.PacketEncryptor;\nimport network.ycc.raknet.RakNet;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Overwrite;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport javax.crypto.Cipher;\n\n@Mixin(ClientConnection.class)\npublic class MixinClientConnection {\n\n    @Shadow\n    private boolean encrypted;\n\n    @Shadow\n    private Channel channel;\n\n    @Inject(method = \"setupEncryption\", at = @At(\"HEAD\"), cancellable = true)\n    public void beforeSetupEncryption(Cipher decryptionCipher, Cipher encryptionCipher, CallbackInfo ci) {\n        if (this.channel.config() instanceof RakNet.Config) {\n            ci.cancel();\n            this.encrypted = true;\n            try {\n                this.channel.pipeline().remove(\"decrypt\");\n                this.channel.pipeline().remove(\"encrypt\");\n            } catch (Throwable ignored) {\n            }\n            try {\n                this.channel.pipeline().remove(MultiChannellingEncryption.NAME);\n            } catch (Throwable ignored) {\n            }\n            this.channel.pipeline().addBefore(MultiChannelingStreamingCompression.NAME, MultiChannellingEncryption.NAME,\n                    new MultiChannellingEncryption(decryptionCipher, encryptionCipher));\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/encryption/MixinPacketDecryptor.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common.encryption;\n\nimport com.ishland.raknetify.fabric.common.connection.encryption.PacketEncryptionManagerInterface;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelHandlerContext;\nimport net.minecraft.network.encryption.PacketDecryptor;\nimport net.minecraft.network.encryption.PacketEncryptionManager;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.util.List;\n\n@Mixin(PacketDecryptor.class)\npublic class MixinPacketDecryptor {\n\n    @Shadow @Final private PacketEncryptionManager manager;\n\n    @Inject(method = \"decode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Ljava/util/List;)V\", at = @At(\"HEAD\"))\n    private void preDecrypt(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> list, CallbackInfo ci) {\n        ((PacketEncryptionManagerInterface) this.manager).setContext(ctx);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/encryption/MixinPacketEncryptionManager.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common.encryption;\n\nimport com.ishland.raknetify.fabric.common.connection.encryption.PacketEncryptionManagerInterface;\nimport io.netty.channel.ChannelHandlerContext;\nimport net.minecraft.network.encryption.PacketEncryptionManager;\nimport network.ycc.raknet.RakNet;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Unique;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Redirect;\n\nimport javax.crypto.BadPaddingException;\nimport javax.crypto.Cipher;\nimport javax.crypto.IllegalBlockSizeException;\nimport javax.crypto.ShortBufferException;\n\n@Mixin(PacketEncryptionManager.class)\npublic class MixinPacketEncryptionManager implements PacketEncryptionManagerInterface {\n\n    @Unique\n    private ChannelHandlerContext ctx;\n\n    @Override\n    public void setContext(ChannelHandlerContext ctx) {\n        this.ctx = ctx;\n    }\n\n    @Redirect(method = \"decrypt\", at = @At(value = \"INVOKE\", target = \"Ljavax/crypto/Cipher;update([BII[BI)I\"))\n    private int redirectDecrypt(Cipher instance, byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {\n        if (ctx.channel().config() instanceof RakNet.Config) {\n            return instance.doFinal(input, inputOffset, inputLen, output, outputOffset);\n        } else {\n            return instance.update(input, inputOffset, inputLen, output, outputOffset);\n        }\n    }\n\n    @Redirect(method = \"encrypt\", at = @At(value = \"INVOKE\", target = \"Ljavax/crypto/Cipher;update([BII[B)I\"))\n    private int redirectEncrypt(Cipher instance, byte[] input, int inputOffset, int inputLen, byte[] output) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {\n        if (ctx.channel().config() instanceof RakNet.Config) {\n            return instance.doFinal(input, inputOffset, inputLen, output);\n        } else {\n            return instance.update(input, inputOffset, inputLen, output);\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/encryption/MixinPacketEncryptor.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common.encryption;\n\nimport com.ishland.raknetify.fabric.common.connection.encryption.PacketEncryptionManagerInterface;\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelHandlerContext;\nimport net.minecraft.network.encryption.PacketEncryptionManager;\nimport net.minecraft.network.encryption.PacketEncryptor;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(PacketEncryptor.class)\npublic class MixinPacketEncryptor {\n\n    @Shadow @Final private PacketEncryptionManager manager;\n\n    @Inject(method = \"encode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Lio/netty/buffer/ByteBuf;)V\", at = @At(\"HEAD\"))\n    private void preEncrypt(ChannelHandlerContext ctx, ByteBuf byteBuf, ByteBuf byteBuf2, CallbackInfo ci) {\n        ((PacketEncryptionManagerInterface) this.manager).setContext(ctx);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/quirks/MixinPlayerEntity.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common.quirks;\n\nimport com.ishland.raknetify.fabric.common.quirks.ClientHungerManager;\nimport com.ishland.raknetify.fabric.common.util.LegacySupportUtil;\nimport com.ishland.raknetify.fabric.mixin.access.IWorld;\nimport net.minecraft.entity.EntityType;\nimport net.minecraft.entity.LivingEntity;\nimport net.minecraft.entity.player.HungerManager;\nimport net.minecraft.entity.player.PlayerEntity;\nimport net.minecraft.world.World;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(PlayerEntity.class)\npublic abstract class MixinPlayerEntity extends LivingEntity {\n\n    @Shadow protected HungerManager hungerManager;\n\n    protected MixinPlayerEntity(EntityType<? extends LivingEntity> entityType, World world) {\n        super(entityType, world);\n    }\n\n    @Inject(method = \"<init>\", at = @At(\"RETURN\"), remap = false)\n    private void replaceHungerManager(CallbackInfo ci) {\n        if (((IWorld) LegacySupportUtil.getEntityWorld(this)).raknetify$isClient()) {\n            this.hungerManager = ClientHungerManager.from(this.hungerManager);\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/common/quirks/MixinSampleSubscriptionTracker.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.common.quirks;\n\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Pseudo;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.util.Queue;\n\n@Pseudo\n@Mixin(targets = \"net.minecraft.class_9188\")\npublic class MixinSampleSubscriptionTracker {\n\n    @Shadow(aliases = \"field_48812\") @Final private Queue<?> pendingQueue;\n\n    @Dynamic\n    @Inject(method = \"method_56654\", at = @At(\"RETURN\"))\n    private void cleanQueue(CallbackInfo ci) {\n        this.pendingQueue.clear();\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/compat/fabricapi/MixinServerLoginNetworkAddon.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.compat.fabricapi;\n\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.server.MinecraftServer;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Pseudo;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.Redirect;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.lang.reflect.Method;\n\n@Pseudo\n@Mixin(targets = \"net.fabricmc.fabric.impl.networking.server.ServerLoginNetworkAddon\")\npublic class MixinServerLoginNetworkAddon {\n\n    @Shadow\n    @Final\n    private ClientConnection connection;\n\n    @Dynamic(\"Pseudo\")\n    @Redirect(method = \"sendCompressionPacket()V\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/server/MinecraftServer;getNetworkCompressionThreshold()I\"))\n    private int stopCompressionIfStreamingCompressionExists(MinecraftServer server) {\n        final MultiChannelingStreamingCompression compression = ((IClientConnection) this.connection).getChannel().pipeline().get(MultiChannelingStreamingCompression.class);\n        if (compression != null && compression.isActive()) {\n            System.out.println(\"Raknetify: Preventing vanilla compression as streaming compression is enabled\");\n            return -1;\n        }\n        return server.getNetworkCompressionThreshold();\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/compat/krypton/MixinServerLoginNetworkHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.compat.krypton;\n\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport io.netty.channel.ChannelHandler;\nimport io.netty.channel.ChannelPipeline;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.encryption.NetworkEncryptionException;\nimport net.minecraft.network.encryption.NetworkEncryptionUtils;\nimport net.minecraft.network.packet.c2s.login.LoginKeyC2SPacket;\nimport net.minecraft.server.MinecraftServer;\nimport net.minecraft.server.network.ServerLoginNetworkHandler;\nimport network.ycc.raknet.RakNet;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport javax.crypto.Cipher;\nimport javax.crypto.SecretKey;\nimport java.security.PrivateKey;\n\n@Mixin(ServerLoginNetworkHandler.class)\npublic class MixinServerLoginNetworkHandler {\n\n    @Shadow\n    @Final\n    public ClientConnection connection;\n\n    @Shadow @Final private MinecraftServer server;\n\n    @Shadow @Final private byte[] nonce;\n\n    @Inject(method = \"onKey\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/network/ClientConnection;setupEncryption(Ljavax/crypto/Cipher;Ljavax/crypto/Cipher;)V\", shift = At.Shift.AFTER))\n    private void afterSetupEncryption(LoginKeyC2SPacket packet, CallbackInfo ci) throws NetworkEncryptionException {\n        final ChannelPipeline pipeline = ((IClientConnection) this.connection).getChannel().pipeline();\n        if (((IClientConnection) this.connection).getChannel().config() instanceof RakNet.Config) {\n            final ChannelHandler decrypt = pipeline.get(\"decrypt\");\n            final ChannelHandler encrypt = pipeline.get(\"encrypt\");\n            if (decrypt != null && (decrypt.getClass().getName().equals(\"me.steinborn.krypton.mod.shared.network.pipeline.MinecraftCipherDecoder\")) &&\n                    encrypt != null && (encrypt.getClass().getName().equals(\"me.steinborn.krypton.mod.shared.network.pipeline.MinecraftCipherEncoder\"))) {\n                System.out.println(\"Raknetify: Krypton detected, applying compatibility\");\n\n                pipeline.remove(\"decrypt\");\n                pipeline.remove(\"encrypt\");\n\n                // TODO [VanillaCopy]\n                PrivateKey privateKey = this.server.getKeyPair().getPrivate();\n\n                SecretKey secretKey = packet.decryptSecretKey(privateKey);\n                Cipher cipher = NetworkEncryptionUtils.cipherFromKey(2, secretKey);\n                Cipher cipher2 = NetworkEncryptionUtils.cipherFromKey(1, secretKey);\n\n                ((IClientConnection) this.connection).setEncrypted(false);\n                this.connection.setupEncryption(cipher, cipher2);\n            }\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/compat/package-info.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.compat;\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/compat/qsl/MixinServerLoginNetworkAddon.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.compat.qsl;\n\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.server.MinecraftServer;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Pseudo;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.Redirect;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.lang.reflect.Method;\n\n@Pseudo\n@Mixin(targets = \"org.quiltmc.qsl.networking.impl.server.ServerLoginNetworkAddon\")\npublic class MixinServerLoginNetworkAddon {\n\n    @Shadow\n    @Final\n    private ClientConnection connection;\n\n    @Dynamic(\"Pseudo\")\n    @Redirect(method = \"sendCompressionPacket()V\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/server/MinecraftServer;getNetworkCompressionThreshold()I\"))\n    private int stopCompressionIfStreamingCompressionExists(MinecraftServer server) {\n        final MultiChannelingStreamingCompression compression = ((IClientConnection) this.connection).getChannel().pipeline().get(MultiChannelingStreamingCompression.class);\n        if (compression != null && compression.isActive()) {\n            System.out.println(\"Raknetify: Preventing vanilla compression as streaming compression is enabled\");\n            return -1;\n        }\n        return server.getNetworkCompressionThreshold();\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/package-info.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin;\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/server/MixinPlayerManager1_20_1.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.server;\n\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport io.netty.channel.Channel;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.server.PlayerManager;\nimport net.minecraft.server.network.ServerPlayerEntity;\nimport network.ycc.raknet.RakNet;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.Surrogate;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(PlayerManager.class)\npublic class MixinPlayerManager1_20_1 {\n\n    @Dynamic\n    @Inject(method = {\"onPlayerConnect\", \"method_12975\"}, at = @At(\"HEAD\"), require = 0)\n    private void onJoin(ClientConnection connection, ServerPlayerEntity player, int latency, CallbackInfo ci) {\n        if (((IClientConnection) connection).getChannel().config() instanceof RakNet.Config config) {\n            System.out.println(String.format(\"Raknetify: %s logged in via RakNet, mtu %d\", player.getName().getString(), config.getMTU()));\n        }\n    }\n\n    @Surrogate\n    private void onJoin(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {\n        if (((IClientConnection) connection).getChannel().config() instanceof RakNet.Config config) {\n            System.out.println(String.format(\"Raknetify: %s logged in via RakNet, mtu %d\", player.getName().getString(), config.getMTU()));\n        }\n    }\n\n    @Dynamic\n    @Inject(method = {\"onPlayerConnect\", \"method_12975\"}, at = @At(\"RETURN\"), require = 0)\n    private void postJoin(ClientConnection connection, ServerPlayerEntity player, int latency, CallbackInfo ci) {\n        final Channel channel = ((IClientConnection) connection).getChannel();\n        if (channel == null) {\n            //noinspection RedundantStringFormatCall\n            System.err.println(\"Raknetify: Warning: %s don't have valid channel when logged in, not sending sync packet\".formatted(this));\n            return;\n        }\n        channel.write(RakNetSimpleMultiChannelCodec.SIGNAL_START_MULTICHANNEL);\n    }\n\n    @Surrogate\n    private void postJoin(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {\n        final Channel channel = ((IClientConnection) connection).getChannel();\n        if (channel == null) {\n            //noinspection RedundantStringFormatCall\n            System.err.println(\"Raknetify: Warning: %s don't have valid channel when logged in, not sending sync packet\".formatted(this));\n            return;\n        }\n        channel.write(RakNetSimpleMultiChannelCodec.SIGNAL_START_MULTICHANNEL);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/server/MixinPlayerManager1_20_2.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.server;\n\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport io.netty.channel.Channel;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.server.PlayerManager;\nimport net.minecraft.server.network.ConnectedClientData;\nimport net.minecraft.server.network.ServerPlayerEntity;\nimport network.ycc.raknet.RakNet;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.Surrogate;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(PlayerManager.class)\npublic class MixinPlayerManager1_20_2 {\n\n    @Inject(method = \"onPlayerConnect\", at = @At(\"HEAD\"))\n    private void onJoin(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {\n        if (((IClientConnection) connection).getChannel().config() instanceof RakNet.Config config) {\n            System.out.println(String.format(\"Raknetify: %s logged in via RakNet, mtu %d\", player.getName().getString(), config.getMTU()));\n        }\n    }\n\n    @Inject(method = \"onPlayerConnect\", at = @At(\"RETURN\"))\n    private void postJoin(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {\n        final Channel channel = ((IClientConnection) connection).getChannel();\n        if (channel == null) {\n            //noinspection RedundantStringFormatCall\n            System.err.println(\"Raknetify: Warning: %s don't have valid channel when logged in, not sending sync packet\".formatted(this));\n            return;\n        }\n        channel.write(RakNetSimpleMultiChannelCodec.SIGNAL_START_MULTICHANNEL);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/server/MixinServerCommonNetworkHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.server;\n\nimport com.ishland.raknetify.fabric.common.util.MultiVersionUtil;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport com.llamalad7.mixinextras.injector.ModifyExpressionValue;\nimport com.llamalad7.mixinextras.injector.WrapWithCondition;\nimport io.netty.channel.Channel;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.network.listener.ServerCommonPacketListener;\nimport net.minecraft.server.network.ServerCommonNetworkHandler;\nimport net.minecraft.server.network.ServerPlayNetworkHandler;\nimport net.minecraft.text.Text;\nimport net.minecraft.util.Util;\nimport network.ycc.raknet.RakNet;\nimport org.objectweb.asm.Opcodes;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(ServerCommonNetworkHandler.class)\npublic abstract class MixinServerCommonNetworkHandler implements ServerCommonPacketListener {\n\n    @Shadow @Final protected ClientConnection connection;\n\n    @Shadow private int latency;\n\n    @ModifyExpressionValue(method = \"baseTick\", at = @At(value = \"FIELD\", target = \"Lnet/minecraft/server/network/ServerCommonNetworkHandler;lastKeepAliveTime:J\", opcode = Opcodes.GETFIELD))\n    private long disableKeepAlive(long original) {\n        if (!(((IClientConnection) this.connection).getChannel().config() instanceof RakNet.Config)) {\n            return original;\n        }\n        return Util.getMeasuringTimeMs();\n    }\n\n    @WrapWithCondition(method = \"onKeepAlive\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/server/network/ServerCommonNetworkHandler;disconnect(Lnet/minecraft/text/Text;)V\"))\n    private boolean stopTimeoutPlayersOnKeepAlive(ServerCommonNetworkHandler instance, Text reason) {\n        return !(((IClientConnection) MultiVersionUtil.ServerPlayNetworkHandler$connection.get((ServerCommonNetworkHandler) (Object) this)).getChannel().config() instanceof RakNet.Config);\n    }\n\n    @WrapWithCondition(method = \"onKeepAlive\", at = @At(value = \"FIELD\", target = \"Lnet/minecraft/server/network/ServerCommonNetworkHandler;latency:I\", opcode = Opcodes.PUTFIELD))\n    private boolean redirectPingStoring(ServerCommonNetworkHandler instance, int value) {\n        return !(((IClientConnection) MultiVersionUtil.ServerPlayNetworkHandler$connection.get((ServerCommonNetworkHandler) (Object) this)).getChannel().config() instanceof RakNet.Config);\n    }\n\n    @Inject(method = \"baseTick\", at = @At(\"HEAD\"))\n    private void onTick(CallbackInfo ci) {\n        final Channel channel = ((IClientConnection) MultiVersionUtil.ServerPlayNetworkHandler$connection.get((ServerCommonNetworkHandler) (Object) this)).getChannel();\n        if (channel != null && channel.config() instanceof RakNet.Config config) {\n            this.latency = (int) ((config.getRTTNanos() + config.getRTTStdDevNanos()) / 1_000_000);\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/server/MixinServerLoginNetworkHandler.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.server;\n\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport net.minecraft.network.ClientConnection;\nimport net.minecraft.server.MinecraftServer;\nimport net.minecraft.server.network.ServerLoginNetworkHandler;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.Redirect;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.lang.reflect.Method;\n\n@Mixin(value = ServerLoginNetworkHandler.class, priority = 900)\npublic class MixinServerLoginNetworkHandler {\n\n    @Shadow @Final public ClientConnection connection;\n\n    @Shadow @Final private MinecraftServer server;\n\n    @Dynamic\n    @Redirect(method = {\"method_14384()V\", \"tickVerify\"}, at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/server/MinecraftServer;getNetworkCompressionThreshold()I\"), require = 1)\n    private int stopCompressionIfStreamingCompressionExists(MinecraftServer server) {\n        final MultiChannelingStreamingCompression compression = ((IClientConnection) this.connection).getChannel().pipeline().get(MultiChannelingStreamingCompression.class);\n        if (compression != null && compression.isActive()) {\n            System.out.println(\"Raknetify: Preventing vanilla compression as streaming compression is enabled\");\n            return -1;\n        }\n        return server.getNetworkCompressionThreshold();\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/server/MixinServerNetworkIo.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.server;\n\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.RakNetConnectionUtil;\nimport com.ishland.raknetify.common.connection.RaknetifyEventLoops;\nimport com.ishland.raknetify.common.util.ThreadLocalUtil;\nimport com.ishland.raknetify.common.util.NetworkInterfaceListener;\nimport com.llamalad7.mixinextras.injector.wrapoperation.Operation;\nimport com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;\nimport io.netty.bootstrap.AbstractBootstrap;\nimport io.netty.bootstrap.ServerBootstrap;\nimport io.netty.channel.ChannelFuture;\nimport io.netty.channel.ChannelOption;\nimport io.netty.channel.EventLoopGroup;\nimport io.netty.channel.FixedRecvByteBufAllocator;\nimport io.netty.channel.ServerChannel;\nimport io.netty.channel.epoll.Epoll;\nimport io.netty.channel.epoll.EpollDatagramChannel;\nimport io.netty.channel.socket.DatagramChannel;\nimport io.netty.channel.socket.ServerSocketChannel;\nimport io.netty.channel.socket.nio.NioDatagramChannel;\nimport net.minecraft.server.MinecraftServer;\nimport net.minecraft.server.ServerNetworkIo;\nimport network.ycc.raknet.server.channel.RakNetServerChannel;\nimport org.jetbrains.annotations.Nullable;\nimport org.spongepowered.asm.mixin.Final;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.Unique;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\nimport java.io.IOException;\nimport java.net.InetAddress;\nimport java.net.InetSocketAddress;\nimport java.net.NetworkInterface;\nimport java.net.SocketAddress;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.function.Consumer;\n\n@Mixin(ServerNetworkIo.class)\npublic abstract class MixinServerNetworkIo {\n\n    @Unique\n    private static final int raknetify$portOverride = Integer.getInteger(\"raknetify.fabric.portOverride\", -1);\n\n    @Shadow\n    @Final\n    private MinecraftServer server;\n\n    @Shadow\n    public abstract void bind(@Nullable InetAddress address, int port) throws IOException;\n\n    @Shadow\n    public volatile boolean active;\n\n    @Shadow\n    @Final\n    private List<ChannelFuture> channels;\n    @Unique\n    private Consumer<NetworkInterfaceListener.InterfaceAddressChangeEvent> raknetify$eventListener = null;\n\n    @Inject(method = \"bind\", at = @At(\"HEAD\"))\n    private void bindUdp(InetAddress address, int port, CallbackInfo ci) throws IOException {\n        if (!ThreadLocalUtil.isInitializingRaknet()) {\n            try {\n                ThreadLocalUtil.setInitializingRaknet(true);\n                final boolean hasPortOverride = raknetify$portOverride > 0 && raknetify$portOverride < 65535;\n                if (address == null) {\n                    for (NetworkInterface networkInterface : NetworkInterface.networkInterfaces().toList()) {\n                        final Iterator<InetAddress> iterator = networkInterface.getInetAddresses().asIterator();\n                        while (iterator.hasNext()) {\n                            final InetAddress inetAddress = iterator.next();\n                            System.out.println(\"Starting raknetify server on %s\".formatted(inetAddress));\n                            try {\n                                bind(inetAddress, hasPortOverride ? raknetify$portOverride : port);\n                            } catch (IOException t) {\n                                System.out.println(\"**** FAILED TO BIND TO PORT! %s\".formatted(t.getMessage()));\n                            }\n                        }\n                    }\n\n                    if (this.raknetify$eventListener == null) {\n                        this.raknetify$eventListener = event -> {\n                            if (!this.active) {\n                                NetworkInterfaceListener.removeListener(this.raknetify$eventListener);\n                                return;\n                            }\n                            try {\n                                ThreadLocalUtil.setInitializingRaknet(true);\n                                final InetAddress inetAddress = event.address();\n                                if (event.added()) {\n                                    System.out.println(\"Starting raknetify server on %s\".formatted(inetAddress));\n                                    try {\n                                        bind(inetAddress, hasPortOverride ? raknetify$portOverride : port);\n                                    } catch (IOException t) {\n                                        System.out.println(\"**** FAILED TO BIND TO PORT! %s\".formatted(t.getMessage()));\n                                    } catch (Throwable t) {\n                                        t.printStackTrace();\n                                    }\n                                } else {\n                                    synchronized (this.channels) {\n                                        for (Iterator<ChannelFuture> iter = this.channels.iterator(); iter.hasNext(); ) {\n                                            ChannelFuture channel = iter.next();\n                                            final SocketAddress socketAddress = channel.channel().localAddress();\n                                            if (socketAddress instanceof InetSocketAddress channelAddress) {\n                                                if (inetAddress.equals(channelAddress.getAddress())) {\n                                                    System.out.println(\"Stopping raknetify server on %s\".formatted(inetAddress));\n                                                    channel.channel().close();\n                                                    iter.remove();\n                                                }\n                                            }\n                                        }\n                                    }\n                                }\n                            } catch (Throwable e) {\n                                e.printStackTrace();\n                            } finally {\n                                ThreadLocalUtil.setInitializingRaknet(false);\n                            }\n                        };\n                        NetworkInterfaceListener.addListener(event -> this.server.submit(() -> raknetify$eventListener.accept(event)));\n                    }\n                } else {\n                    System.out.println(\"Starting raknetify server on %s\".formatted(address));\n                    bind(address, hasPortOverride ? raknetify$portOverride : port);\n                }\n            } finally {\n                ThreadLocalUtil.setInitializingRaknet(false);\n            }\n        }\n    }\n\n    @WrapOperation(method = \"bind\", at = @At(value = \"INVOKE\", target = \"Lio/netty/bootstrap/ServerBootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/ServerBootstrap;\", remap = false))\n    private ServerBootstrap redirectGroup(ServerBootstrap instance, EventLoopGroup group, Operation<ServerBootstrap> original) {\n        final boolean useEpoll = Epoll.isAvailable() && this.server.isUsingNativeTransport();\n        return ThreadLocalUtil.isInitializingRaknet()\n                ? original.call(instance, useEpoll ? RaknetifyEventLoops.EPOLL_EVENT_LOOP_GROUP.get() : RaknetifyEventLoops.NIO_EVENT_LOOP_GROUP.get())\n                : original.call(instance, group);\n    }\n\n    @WrapOperation(method = \"bind\", at = @At(value = \"INVOKE\", target = \"Lio/netty/bootstrap/ServerBootstrap;channel(Ljava/lang/Class;)Lio/netty/bootstrap/AbstractBootstrap;\", remap = false))\n    private AbstractBootstrap<ServerBootstrap, ServerChannel> redirectChannel(ServerBootstrap instance, Class<? extends ServerSocketChannel> aClass, Operation<AbstractBootstrap<ServerBootstrap, ServerChannel>> original) {\n        final boolean useEpoll = Epoll.isAvailable() && this.server.isUsingNativeTransport();\n        return ThreadLocalUtil.isInitializingRaknet()\n                ? instance.channelFactory(() -> {\n            RakNetServerChannel channel = new RakNetServerChannel(() -> {\n                final DatagramChannel channel1 = useEpoll ? new EpollDatagramChannel() : new NioDatagramChannel();\n                channel1.config().setOption(ChannelOption.SO_REUSEADDR, true);\n                channel1.config().setOption(ChannelOption.IP_TOS, RakNetConnectionUtil.DEFAULT_IP_TOS);\n                channel1.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(Constants.LARGE_MTU + 512).maxMessagesPerRead(128));\n                return channel1;\n            });\n            channel.setProvidedApplicationEventLoop(RaknetifyEventLoops.DEFAULT_EVENT_LOOP_GROUP.get().next());\n            return channel;\n        })\n                : original.call(instance, aClass);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/server/MixinServerNetworkIo1.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.server;\n\nimport com.ishland.raknetify.fabric.common.connection.RakNetFabricConnectionUtil;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelInitializer;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(targets = \"net/minecraft/server/ServerNetworkIo$1\")\npublic abstract class MixinServerNetworkIo1 extends ChannelInitializer<Channel> {\n\n    @Inject(method = \"initChannel(Lio/netty/channel/Channel;)V\", at = @At(\"HEAD\"))\n    private void onChannelInit(Channel channel, CallbackInfo ci) {\n        RakNetFabricConnectionUtil.initChannel(channel);\n    }\n\n    @Inject(method = \"initChannel(Lio/netty/channel/Channel;)V\", at = @At(\"RETURN\"))\n    private void postChannelInit(Channel channel, CallbackInfo ci) {\n        RakNetFabricConnectionUtil.postInitChannel(channel, false);\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/java/com/ishland/raknetify/fabric/mixin/server/MixinServerPlayNetworkHandler1_20_1.java",
    "content": "/*\n * This file is a part of the Raknetify project, licensed under MIT.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\npackage com.ishland.raknetify.fabric.mixin.server;\n\nimport com.ishland.raknetify.fabric.common.util.MultiVersionUtil;\nimport com.ishland.raknetify.fabric.mixin.access.IClientConnection;\nimport com.llamalad7.mixinextras.injector.ModifyExpressionValue;\nimport com.llamalad7.mixinextras.injector.WrapWithCondition;\nimport io.netty.channel.Channel;\nimport net.minecraft.server.network.ServerCommonNetworkHandler;\nimport net.minecraft.server.network.ServerPlayNetworkHandler;\nimport net.minecraft.server.network.ServerPlayerEntity;\nimport net.minecraft.text.Text;\nimport net.minecraft.util.Util;\nimport network.ycc.raknet.RakNet;\nimport org.objectweb.asm.Opcodes;\nimport org.spongepowered.asm.mixin.Dynamic;\nimport org.spongepowered.asm.mixin.Mixin;\nimport org.spongepowered.asm.mixin.Shadow;\nimport org.spongepowered.asm.mixin.injection.At;\nimport org.spongepowered.asm.mixin.injection.Inject;\nimport org.spongepowered.asm.mixin.injection.Redirect;\nimport org.spongepowered.asm.mixin.injection.callback.CallbackInfo;\n\n@Mixin(ServerPlayNetworkHandler.class)\npublic class MixinServerPlayNetworkHandler1_20_1 {\n\n    @Shadow public ServerPlayerEntity player;\n\n    @Dynamic\n    @ModifyExpressionValue(method = \"tick\", at = @At(value = \"FIELD\", target = \"Lnet/minecraft/server/network/ServerPlayNetworkHandler;field_14136:J\", opcode = Opcodes.GETFIELD))\n    private long disableKeepAlive(long original) {\n        if (!(((IClientConnection) MultiVersionUtil.ServerPlayNetworkHandler$connection.get((ServerPlayNetworkHandler) (Object) this)).getChannel().config() instanceof RakNet.Config)) {\n            return original;\n        }\n        return Util.getMeasuringTimeMs();\n    }\n\n    @Dynamic\n    @WrapWithCondition(method = \"method_12082\", at = @At(value = \"INVOKE\", target = \"Lnet/minecraft/server/network/ServerPlayNetworkHandler;method_14367(Lnet/minecraft/text/Text;)V\"))\n    private boolean stopTimeoutPlayersOnKeepAlive(ServerPlayNetworkHandler instance, Text reason) {\n        return !(((IClientConnection) MultiVersionUtil.ServerPlayNetworkHandler$connection.get((ServerPlayNetworkHandler) (Object) this)).getChannel().config() instanceof RakNet.Config);\n    }\n\n    @Dynamic\n    @WrapWithCondition(method = \"method_12082\", at = @At(value = \"FIELD\", target = \"Lnet/minecraft/server/network/ServerPlayerEntity;field_13967:I\", opcode = Opcodes.PUTFIELD))\n    private boolean redirectPingStoring(ServerPlayerEntity instance, int value) {\n        return !(((IClientConnection) MultiVersionUtil.ServerPlayNetworkHandler$connection.get((ServerPlayNetworkHandler) (Object) this)).getChannel().config() instanceof RakNet.Config);\n    }\n\n    @Inject(method = \"tick\", at = @At(\"HEAD\"))\n    private void onTick(CallbackInfo ci) {\n        final Channel channel = ((IClientConnection) MultiVersionUtil.ServerPlayNetworkHandler$connection.get((ServerPlayNetworkHandler) (Object) this)).getChannel();\n        if (channel != null && channel.config() instanceof RakNet.Config config) {\n            assert MultiVersionUtil.ServerPlayerEntity$pingMillis1_20_1 != null;\n            MultiVersionUtil.ServerPlayerEntity$pingMillis1_20_1.set(this.player, (int) ((config.getRTTNanos() + config.getRTTStdDevNanos()) / 1_000_000));\n        }\n    }\n\n}\n"
  },
  {
    "path": "fabric/src/main/resources/fabric.mod.json",
    "content": "{\n  \"schemaVersion\": 1,\n  \"id\": \"raknetify\",\n  \"version\": \"${version}\",\n\n  \"name\": \"Raknetify (Fabric)\",\n  \"description\": \"A Fabric mod that allows using RakNet as Minecraft networking backend. \",\n  \"authors\": [\n    \"ishland\"\n  ],\n  \"contact\": {\n  },\n\n  \"license\": \"MIT\",\n\n  \"environment\": \"*\",\n  \"entrypoints\": {\n    \"main\": [\n      \"com.ishland.raknetify.fabric.RaknetifyFabric\"\n    ],\n    \"preLaunch\": [\n      \"com.ishland.raknetify.fabric.RaknetifyFabric\"\n    ]\n  },\n\n  \"accessWidener\" : \"raknetify-fabric.accesswidener\",\n\n  \"mixins\": [\n    \"raknetify-fabric.mixins.json\"\n  ],\n\n  \"depends\": {\n    \"fabricloader\": \">=0.15.2\",\n    \"java\": \">=17\"\n  },\n  \"suggests\": {\n  }\n}\n"
  },
  {
    "path": "fabric/src/main/resources/raknetify-fabric.accesswidener",
    "content": "accessWidener v1 named\n\naccessible    class    net/minecraft/network/handler/PacketCodecDispatcher$PacketType\n\naccessible    method    net/minecraft/network/encryption/PacketEncryptionManager    <init>                   (Ljavax/crypto/Cipher;)V\naccessible    method    net/minecraft/client/network/MultiplayerServerListPinger    createPlayerCountText    (II)Lnet/minecraft/text/Text;\n"
  },
  {
    "path": "fabric/src/main/resources/raknetify-fabric.mixins.json",
    "content": "{\n  \"required\": true,\n  \"minVersion\": \"0.8\",\n  \"package\": \"com.ishland.raknetify.fabric.mixin\",\n  \"plugin\": \"com.ishland.raknetify.fabric.mixin.RaknetifyFabricMixinPlugin\",\n  \"compatibilityLevel\": \"JAVA_16\",\n  \"mixinPriority\": 1010,\n  \"mixins\": [\n    \"access.IClientConnection\",\n    \"access.INetworkState1_20_4\",\n    \"access.INetworkStateInternalPacketHandler\",\n    \"access.IPacketCodecDispatcher\",\n    \"access.IPacketCodecDispatcherPacketType\",\n    \"access.IPacketEncryptionManager\",\n    \"access.IServerPlayNetworkHandler\",\n    \"access.IWorld\",\n    \"client.MixinClientPlayNetworkHandler\",\n    \"client.MixinConnectionScreen1\",\n    \"client.MixinMultiplayerServerListPinger\",\n    \"client.MixinMultiplayerServerListPinger1\",\n    \"client.hud.MixinDebugHud1_21_8\",\n    \"common.MixinCCConnect\",\n    \"common.MixinClientConnection\",\n    \"common.MixinClientConnection1\",\n    \"common.MixinClientConnection1_20_2\",\n    \"common.encryption.MixinClientConnection\",\n    \"common.encryption.MixinPacketDecryptor\",\n    \"common.encryption.MixinPacketEncryptionManager\",\n    \"common.encryption.MixinPacketEncryptor\",\n    \"common.quirks.MixinPlayerEntity\",\n    \"common.quirks.MixinSampleSubscriptionTracker\",\n    \"compat.fabricapi.MixinServerLoginNetworkAddon\",\n    \"compat.krypton.MixinServerLoginNetworkHandler\",\n    \"compat.qsl.MixinServerLoginNetworkAddon\",\n    \"server.MixinPlayerManager1_20_1\",\n    \"server.MixinPlayerManager1_20_2\",\n    \"server.MixinServerCommonNetworkHandler\",\n    \"server.MixinServerLoginNetworkHandler\",\n    \"server.MixinServerNetworkIo\",\n    \"server.MixinServerNetworkIo1\",\n    \"server.MixinServerPlayNetworkHandler1_20_1\"\n  ],\n  \"injectors\": {\n    \"defaultRequire\": 1\n  },\n  \"client\": [\n    \"access.IClientPlayNetworkHandler\",\n    \"access.IDebugHudEntries\",\n    \"client.MixinMultiplayerServerListPinger1_20_2\",\n    \"client.MixinMultiplayerServerListPinger1_20_5\",\n    \"client.MixinMultiplayerServerListPinger1_21_11\",\n    \"common.MixinServerAddress\"\n  ]\n}\n"
  },
  {
    "path": "genMappings.sh",
    "content": "#!/bin/bash\n\nloader_version=0.18.4\ninstaller_version=1.1.1\n\n#declare -a vers\nif [[ -z \"$@\" ]]; then\n  vers=\"1.17 1.17.1 1.18.1 1.18.2 1.19 1.19.2 1.19.3 1.19.4 23w13a_or_b 1.20.1 1.20.2 1.20.4 1.20.6 1.21.1 1.21.3 1.21.4 1.21.5 1.21.6 1.21.8 1.21.10 1.21.11\"\nelse\n  vers=$@\nfi\n\necho $vers\n\n./gradlew clean build || exit 1\n\nmkdir run-mappingsGen || true\ncd run-mappingsGen  || exit 1\nrm -r mods\nmkdir mods\ncp ../fabric/build/libs/raknetify-*-all.jar mods/\nrm channelMappings.json || true\nif [[ -z \"${MAPPINGS_GEN_FRESH}\" ]]; then\n  cp ../common/src/main/resources/raknetify-channel-mappings.json channelMappings.json\nfi\n\nfor version in $vers\ndo\n  if [ -e fabric-server-mc\"$version\".jar ]; then\n    echo \"Using existing fabric-server-mc$version.jar\"\n  else\n    wget -O fabric-server-mc\"$version\".jar https://meta.fabricmc.net/v2/versions/loader/\"$version\"/$loader_version/$installer_version/server/jar || exit 1\n  fi\n\n  sleep 1\n\n  java -Draknetify.saveChannelMappings=true -Draknetify.saveChannelMappings.exit=true -jar fabric-server-mc\"$version\".jar || exit 1\ndone\n\ncp channelMappings.json ../common/src/main/resources/raknetify-channel-mappings.json\n"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "distributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-9.1.0-all.zip\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\n"
  },
  {
    "path": "gradle.properties",
    "content": "# Done to increase the memory available to gradle.\norg.gradle.jvmargs=-Xmx4G\norg.gradle.parallel=true\n\ngradle-curseforge-publish.interop.fabric-loom=false\ngradle-curseforge-publish.interop.forge-gradle=false\ngradle-curseforge-publish.interop.neoforged=false\ngradle-curseforge-publish.interop.neogradle=false\n\n# Fabric Properties\n# check these on https://fabricmc.net/develop\n#\n# Also don't forget to gen mappings in genMappings.sh\nminecraft_version=1.21.11\nyarn_mappings=1.21.11+build.1\nloader_version=0.17.2\n\n# Mod Properties\nmod_version = 0.1.0+alpha.5\nmaven_group = com.ishland.raknetify\narchives_base_name = raknetify\n\n# Dependencies\n#fabric_version=0.44.0+1.18\n#mixinextras_version=0.1.1\n"
  },
  {
    "path": "gradlew",
    "content": "#!/bin/sh\n\n#\n# Copyright  2015-2021 the original authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\n##############################################################################\n#\n#   Gradle start up script for POSIX generated by Gradle.\n#\n#   Important for running:\n#\n#   (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is\n#       noncompliant, but you have some other compliant shell such as ksh or\n#       bash, then to run this script, type that shell name before the whole\n#       command line, like:\n#\n#           ksh Gradle\n#\n#       Busybox and similar reduced shells will NOT work, because this script\n#       requires all of these POSIX shell features:\n#         * functions;\n#         * expansions $var, ${var}, ${var:-default}, ${var+SET},\n#           ${var#prefix}, ${var%suffix}, and $( cmd );\n#         * compound commands having a testable exit status, especially case;\n#         * various built-in commands including command, set, and ulimit.\n#\n#   Important for patching:\n#\n#   (2) This script targets any POSIX shell, so it avoids extensions provided\n#       by Bash, Ksh, etc; in particular arrays are avoided.\n#\n#       The \"traditional\" practice of packing multiple parameters into a\n#       space-separated string is a well documented source of bugs and security\n#       problems, so this is (mostly) avoided, by progressively accumulating\n#       options in \"$@\", and eventually passing that to Java.\n#\n#       Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,\n#       and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;\n#       see the in-line comments for details.\n#\n#       There are tweaks for specific operating systems such as AIX, CygWin,\n#       Darwin, MinGW, and NonStop.\n#\n#   (3) This script is generated from the Groovy template\n#       https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt\n#       within the Gradle project.\n#\n#       You can find Gradle at https://github.com/gradle/gradle/.\n#\n##############################################################################\n\n# Attempt to set APP_HOME\n\n# Resolve links: $0 may be a link\napp_path=$0\n\n# Need this for daisy-chained symlinks.\nwhile\n    APP_HOME=${app_path%\"${app_path##*/}\"}  # leaves a trailing /; empty if no leading path\n    [ -h \"$app_path\" ]\ndo\n    ls=$( ls -ld \"$app_path\" )\n    link=${ls#*' -> '}\n    case $link in             #(\n      /*)   app_path=$link ;; #(\n      *)    app_path=$APP_HOME$link ;;\n    esac\ndone\n\nAPP_HOME=$( cd \"${APP_HOME:-./}\" && pwd -P ) || exit\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=${0##*/}\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS='\"-Xmx64m\" \"-Xms64m\"'\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=maximum\n\nwarn () {\n    echo \"$*\"\n} >&2\n\ndie () {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n} >&2\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\nnonstop=false\ncase \"$( uname )\" in                #(\n  CYGWIN* )         cygwin=true  ;; #(\n  Darwin* )         darwin=true  ;; #(\n  MSYS* | MINGW* )  msys=true    ;; #(\n  NONSTOP* )        nonstop=true ;;\nesac\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=$JAVA_HOME/jre/sh/java\n    else\n        JAVACMD=$JAVA_HOME/bin/java\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=java\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif ! \"$cygwin\" && ! \"$darwin\" && ! \"$nonstop\" ; then\n    case $MAX_FD in #(\n      max*)\n        MAX_FD=$( ulimit -H -n ) ||\n            warn \"Could not query maximum file descriptor limit\"\n    esac\n    case $MAX_FD in  #(\n      '' | soft) :;; #(\n      *)\n        ulimit -n \"$MAX_FD\" ||\n            warn \"Could not set maximum file descriptor limit to $MAX_FD\"\n    esac\nfi\n\n# Collect all arguments for the java command, stacking in reverse order:\n#   * args from the command line\n#   * the main class name\n#   * -classpath\n#   * -D...appname settings\n#   * --module-path (only if needed)\n#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.\n\n# For Cygwin or MSYS, switch paths to Windows format before running java\nif \"$cygwin\" || \"$msys\" ; then\n    APP_HOME=$( cygpath --path --mixed \"$APP_HOME\" )\n    CLASSPATH=$( cygpath --path --mixed \"$CLASSPATH\" )\n\n    JAVACMD=$( cygpath --unix \"$JAVACMD\" )\n\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    for arg do\n        if\n            case $arg in                                #(\n              -*)   false ;;                            # don't mess with options #(\n              /?*)  t=${arg#/} t=/${t%%/*}              # looks like a POSIX filepath\n                    [ -e \"$t\" ] ;;                      #(\n              *)    false ;;\n            esac\n        then\n            arg=$( cygpath --path --ignore --mixed \"$arg\" )\n        fi\n        # Roll the args list around exactly as many times as the number of\n        # args, so each arg winds up back in the position where it started, but\n        # possibly modified.\n        #\n        # NB: a `for` loop captures its iteration list before it begins, so\n        # changing the positional parameters here affects neither the number of\n        # iterations, nor the values presented in `arg`.\n        shift                   # remove old arg\n        set -- \"$@\" \"$arg\"      # push replacement arg\n    done\nfi\n\n# Collect all arguments for the java command;\n#   * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of\n#     shell script including quotes and variable substitutions, so put them in\n#     double quotes to make sure that they get re-expanded; and\n#   * put everything else in single quotes, so that it's not re-expanded.\n\nset -- \\\n        \"-Dorg.gradle.appname=$APP_BASE_NAME\" \\\n        -classpath \"$CLASSPATH\" \\\n        org.gradle.wrapper.GradleWrapperMain \\\n        \"$@\"\n\n# Use \"xargs\" to parse quoted args.\n#\n# With -n1 it outputs one arg per line, with the quotes and backslashes removed.\n#\n# In Bash we could simply go:\n#\n#   readarray ARGS < <( xargs -n1 <<<\"$var\" ) &&\n#   set -- \"${ARGS[@]}\" \"$@\"\n#\n# but POSIX shell has neither arrays nor command substitution, so instead we\n# post-process each arg (as a line of input to sed) to backslash-escape any\n# character that might be a shell metacharacter, then use eval to reverse\n# that process (while maintaining the separation between arguments), and wrap\n# the whole thing up as a single \"set\" statement.\n#\n# This will of course break if any of these variables contains a newline or\n# an unmatched quote.\n#\n\neval \"set -- $(\n        printf '%s\\n' \"$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS\" |\n        xargs -n1 |\n        sed ' s~[^-[:alnum:]+,./:=@_]~\\\\&~g; ' |\n        tr '\\n' ' '\n    )\" '\"$@\"'\n\nexec \"$JAVACMD\" \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@rem\n@rem Copyright 2015 the original author or authors.\n@rem\n@rem Licensed under the Apache License, Version 2.0 (the \"License\");\n@rem you may not use this file except in compliance with the License.\n@rem You may obtain a copy of the License at\n@rem\n@rem      https://www.apache.org/licenses/LICENSE-2.0\n@rem\n@rem Unless required by applicable law or agreed to in writing, software\n@rem distributed under the License is distributed on an \"AS IS\" BASIS,\n@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n@rem See the License for the specific language governing permissions and\n@rem limitations under the License.\n@rem\n\n@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem  Gradle startup script for Windows\n@rem\n@rem ##########################################################################\n\n@rem Set local scope for the variables with windows NT shell\nif \"%OS%\"==\"Windows_NT\" setlocal\n\nset DIRNAME=%~dp0\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\nset APP_BASE_NAME=%~n0\nset APP_HOME=%DIRNAME%\n\n@rem Resolve any \".\" and \"..\" in APP_HOME to make it shorter.\nfor %%i in (\"%APP_HOME%\") do set APP_HOME=%%~fi\n\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nset DEFAULT_JVM_OPTS=\"-Xmx64m\" \"-Xms64m\"\n\n@rem Find java.exe\nif defined JAVA_HOME goto findJavaFromJavaHome\n\nset JAVA_EXE=java.exe\n%JAVA_EXE% -version >NUL 2>&1\nif \"%ERRORLEVEL%\" == \"0\" goto execute\n\necho.\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\necho.\necho Please set the JAVA_HOME variable in your environment to match the\necho location of your Java installation.\n\ngoto fail\n\n:findJavaFromJavaHome\nset JAVA_HOME=%JAVA_HOME:\"=%\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\n\nif exist \"%JAVA_EXE%\" goto execute\n\necho.\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\necho.\necho Please set the JAVA_HOME variable in your environment to match the\necho location of your Java installation.\n\ngoto fail\n\n:execute\n@rem Setup the command line\n\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\n\n\n@rem Execute Gradle\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %*\n\n:end\n@rem End local scope for the variables with windows NT shell\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\n\n:fail\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\nrem the _cmd.exe /c_ return code!\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\nexit /b 1\n\n:mainEnd\nif \"%OS%\"==\"Windows_NT\" endlocal\n\n:omega\n"
  },
  {
    "path": "jitpack.yml",
    "content": "before_install:\n  - source \"$HOME/.sdkman/bin/sdkman-init.sh\"\n  - sdk update\n  - sdk install java 17.0.2-zulu\n  - sdk use java 17.0.2-zulu\n"
  },
  {
    "path": "modrinth_license.txt",
    "content": "Licensing\n\nRaknetify for fabric and BungeeCord is licensed under the MIT license,\nyou can find the license in the LICENSE file\n\nRaknetify for Velocity is licensed under the GNU General Public License v3.0,\nyou can find the license in the velocity/LICENSE file\n"
  },
  {
    "path": "settings.gradle",
    "content": "pluginManagement {\n    repositories {\n        maven {\n            name = 'Fabric'\n            url = 'https://maven.fabricmc.net/'\n        }\n        mavenCentral()\n        gradlePluginPortal()\n    }\n}\n\nrootProject.name = \"raknetify\"\n\nincludeBuild('netty-raknet') {\n    dependencySubstitution {\n        substitute module(\"com.github.RelativityMC.netty-raknet:netty-raknet-common\") using project(\":netty-raknet-common\")\n        substitute module(\"com.github.RelativityMC.netty-raknet:netty-raknet-client\") using project(\":netty-raknet-client\")\n        substitute module(\"com.github.RelativityMC.netty-raknet:netty-raknet-server\") using project(\":netty-raknet-server\")\n    }\n}\n\ninclude \"fabric\"\ninclude \"velocity\"\ninclude \"bungee\"\ninclude \"common\"\n"
  },
  {
    "path": "velocity/HEADER.txt",
    "content": "This file is a part of the Velocity implementation of the Raknetify\nproject, licensed under GPLv3.\n\nCopyright (c) 2022-2025 ishland\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see <http://www.gnu.org/licenses/>.\n"
  },
  {
    "path": "velocity/LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "velocity/build.gradle",
    "content": "import java.nio.file.Files\nimport java.nio.file.Paths\nimport java.nio.file.StandardCopyOption\n\nevaluationDependsOn(\":\")\n\napply plugin: 'com.gradleup.shadow'\napply plugin: 'com.modrinth.minotaur'\n\nafterEvaluate {\n    license {\n        rule(project.file('HEADER.txt'))\n    }\n}\n\nbase {\n    archivesName = project.archives_base_name + \"-velocity\"\n}\ngroup = project.maven_group + \".velocity\"\n\nrepositories {\n    maven {\n        name 'papermc'\n        url 'https://repo.papermc.io/repository/maven-public/'\n    }\n    ivy {\n        url 'https://api.papermc.io/v2/projects/'\n        patternLayout {\n            artifact \"[organization]/versions/[module]/builds/[revision]/downloads/[organization]-[module]-[revision](.[ext])\"\n        }\n        metadataSources {\n            it.artifact()\n        }\n    }\n}\n\nconfigurations {\n    shadowInclude\n}\n\ndependencies {\n//    api 'com.velocitypowered:velocity-api:3.1.1'\n//    annotationProcessor 'com.velocitypowered:velocity-api:3.1.1'\n\n    implementation 'velocity:3.4.0-SNAPSHOT:540'\n//    annotationProcessor 'velocity:3.1.2-SNAPSHOT:139'\n\n    shadowInclude implementation(project(\":common\"))\n\n    // copied here to workaround incomplete fastutil in velocity\n    api(\"com.github.RelativityMC.netty-raknet:netty-raknet-common\") {\n        transitive = false\n    }\n    api(\"com.github.RelativityMC.netty-raknet:netty-raknet-client\")\n    api(\"com.github.RelativityMC.netty-raknet:netty-raknet-server\")\n}\n\nprocessResources {\n    inputs.property \"version\", project.version\n\n    filesMatching(\"velocity-plugin.json\") {\n        expand \"version\": project.version\n    }\n}\n\njar {\n    exclude \"META-INF/LICENSE.txt\"\n    exclude \"META-INF/NOTICE.txt\"\n    from \"LICENSE\"\n}\n\nshadowJar {\n    dependencies {\n//        exclude(dependency('it.unimi.dsi:fastutil'))\n    }\n    exclude \"META-INF/LICENSE.txt\"\n    exclude \"META-INF/NOTICE.txt\"\n    minimize()\n    archiveClassifier = \"all\"\n    configurations = [ project.configurations.shadowInclude ]\n    from \"LICENSE\"\n}\n\nassemble.dependsOn(shadowJar)\n\ntasks.withType(AbstractArchiveTask) {\n    preserveFileTimestamps = false\n    reproducibleFileOrder = true\n}\n\nmodrinth {\n    versionNumber = project.version + \"+velocity\"\n    versionName = project.version + \" devbuild for Velocity\"\n    uploadFile = shadowJar\n    loaders = [\"velocity\"]\n}\n\ntask(\"prepareRunVelocity\", dependsOn: shadowJar) {\n    doFirst {\n        Files.createDirectories(rootProject.projectDir.toPath().resolve(\"run-velocity\").resolve(\"plugins\"))\n        Files.copy(shadowJar.archiveFile.getAsFile().get().toPath(), rootProject.projectDir.toPath().resolve(\"run-velocity\").resolve(\"plugins\").resolve(\"raknetify-velocity-devlaunch.jar\"), StandardCopyOption.REPLACE_EXISTING)\n    }\n}\n"
  },
  {
    "path": "velocity/src/main/java/com/ishland/raknetify/velocity/RaknetifyVelocityLaunchWrapper.java",
    "content": "/*\n * This file is a part of the Velocity implementation of the Raknetify\n * project, licensed under GPLv3.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\npackage com.ishland.raknetify.velocity;\n\nimport com.ishland.raknetify.common.data.ProtocolMultiChannelMappings;\nimport com.ishland.raknetify.velocity.connection.RakNetVelocityConnectionUtil;\nimport com.ishland.raknetify.velocity.init.VelocityPacketRegistryInjector;\nimport com.ishland.raknetify.velocity.init.VelocityRaknetifyServer;\nimport com.velocitypowered.api.event.PostOrder;\nimport com.velocitypowered.api.event.connection.LoginEvent;\nimport com.velocitypowered.api.event.player.ServerPostConnectEvent;\nimport com.velocitypowered.api.event.proxy.ListenerBoundEvent;\nimport com.velocitypowered.api.event.proxy.ListenerCloseEvent;\n\nimport static com.ishland.raknetify.velocity.RaknetifyVelocityPlugin.INSTANCE;\nimport static com.ishland.raknetify.velocity.RaknetifyVelocityPlugin.LOGGER;\nimport static com.ishland.raknetify.velocity.RaknetifyVelocityPlugin.PROXY;\n\npublic class RaknetifyVelocityLaunchWrapper {\n\n    public static void launch() {\n        if (!isCompatible()) {\n            Runnable runnable = () -> {\n                LOGGER.error(\"This version of Raknetify is NOT compatible with your version of Velocity\");\n                LOGGER.error(\"Please update your Velocity at https://papermc.io/downloads#Velocity\");\n            };\n            runnable.run();\n            PROXY.getEventManager().register(INSTANCE, ListenerBoundEvent.class, PostOrder.LAST, ignored -> runnable.run());\n            return;\n        }\n\n        ProtocolMultiChannelMappings.init();\n        VelocityPacketRegistryInjector.inject();\n\n        PROXY.getEventManager().register(INSTANCE, LoginEvent.class, PostOrder.LAST, RakNetVelocityConnectionUtil::onPlayerLogin);\n        PROXY.getEventManager().register(INSTANCE, ListenerBoundEvent.class, PostOrder.LAST, VelocityRaknetifyServer::start);\n        PROXY.getEventManager().register(INSTANCE, ListenerCloseEvent.class, PostOrder.LAST, VelocityRaknetifyServer::stop);\n        PROXY.getEventManager().register(INSTANCE, ServerPostConnectEvent.class, PostOrder.LAST, RakNetVelocityConnectionUtil::onServerSwitch);\n    }\n\n    private static boolean isCompatible() {\n        try {\n            Class.forName(\"com.velocitypowered.proxy.crypto.EncryptionUtils\");\n            Class.forName(\"com.velocitypowered.proxy.protocol.packet.PluginMessagePacket\");\n            return true;\n        } catch (ClassNotFoundException e) {\n            return false;\n        }\n    }\n\n}\n"
  },
  {
    "path": "velocity/src/main/java/com/ishland/raknetify/velocity/RaknetifyVelocityPlugin.java",
    "content": "/*\n * This file is a part of the Velocity implementation of the Raknetify\n * project, licensed under GPLv3.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\npackage com.ishland.raknetify.velocity;\n\nimport com.google.common.base.Preconditions;\nimport com.google.inject.Inject;\nimport com.velocitypowered.api.event.Subscribe;\nimport com.velocitypowered.api.event.proxy.ProxyInitializeEvent;\nimport com.velocitypowered.api.plugin.Plugin;\nimport com.velocitypowered.api.proxy.ProxyServer;\nimport org.slf4j.Logger;\n\nimport java.lang.reflect.InvocationTargetException;\nimport java.net.URL;\nimport java.net.URLClassLoader;\nimport java.net.URLStreamHandlerFactory;\nimport java.security.CodeSource;\nimport java.util.ArrayList;\nimport java.util.regex.Pattern;\n\n@Plugin(\n        id = \"raknetify\"\n)\npublic class RaknetifyVelocityPlugin {\n\n    private static final ArrayList<Pattern> excludeRegex = new ArrayList<>();\n\n    static {\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.*Int2ObjectLinked*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.*Int2ObjectSorted*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.*Int2ObjectAVL*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.*Int2ObjectRB*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.*Int2ObjectArray*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.IntList*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.AbstractIntList*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.IntSorted*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.AbstractIntSorted*\"));\n        excludeRegex.add(Pattern.compile(\"it.unimi.dsi.fastutil.ints.IntRB*\"));\n    }\n\n    private static boolean isExcluded(String name) {\n        for (Pattern regex : excludeRegex) {\n            if (regex.matcher(name).find()) return true;\n        }\n        return false;\n    }\n\n    public static ProxyServer PROXY;\n    public static Logger LOGGER;\n    public static RaknetifyVelocityPlugin INSTANCE;\n\n    public static URLClassLoader WRAPPER;\n\n    @Inject\n    private ProxyServer proxy;\n    @Inject\n    private Logger logger;\n\n    @Subscribe\n    public void onProxyInit(ProxyInitializeEvent e) {\n        INSTANCE = this;\n        PROXY = this.proxy;\n        LOGGER = this.logger;\n\n        final CodeSource codeSource = RaknetifyVelocityPlugin.class.getProtectionDomain().getCodeSource();\n        if (codeSource != null && !isDevLaunch()) {\n            try {\n                LOGGER.info(\"Bootstrapping raknetify in wrapped environment\");\n                final URLClassLoader urlClassLoader = new RaknetifyURLClassLoader(\"raknetify wrapper\", new URL[]{codeSource.getLocation()}, RaknetifyVelocityPlugin.class.getClassLoader());\n                final Class<?> launchWrapper = urlClassLoader.loadClass(\"com.ishland.raknetify.velocity.RaknetifyVelocityLaunchWrapper\");\n                Preconditions.checkState(launchWrapper.getClassLoader() == urlClassLoader, \"Not launched in wrapper\");\n                WRAPPER = urlClassLoader;\n                launchWrapper.getMethod(\"launch\").invoke(null);\n                return;\n            } catch (Throwable t) {\n                LOGGER.error(\"Error bootstrapping raknetify inside wrapped environment, running in normal environment instead\", t);\n            }\n        }\n\n        try {\n            Class.forName(\"com.ishland.raknetify.velocity.RaknetifyVelocityLaunchWrapper\").getMethod(\"launch\").invoke(null);\n        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException ex) {\n            throw new RuntimeException(ex);\n        }\n    }\n\n    private static boolean isDevLaunch() {\n        try {\n            ClassLoader.getSystemClassLoader().loadClass(\"com.ishland.raknetify.velocity.RaknetifyVelocityPlugin\");\n            return true;\n        } catch (ClassNotFoundException e) {\n            return false;\n        }\n    }\n\n    private static class RaknetifyURLClassLoader extends URLClassLoader {\n\n        public RaknetifyURLClassLoader(URL[] urls, ClassLoader parent) {\n            super(urls, parent);\n        }\n\n        public RaknetifyURLClassLoader(URL[] urls) {\n            super(urls);\n        }\n\n        public RaknetifyURLClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {\n            super(urls, parent, factory);\n        }\n\n        public RaknetifyURLClassLoader(String name, URL[] urls, ClassLoader parent) {\n            super(name, urls, parent);\n        }\n\n        public RaknetifyURLClassLoader(String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {\n            super(name, urls, parent, factory);\n        }\n\n        @Override\n        protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {\n            if (!(name.startsWith(\"com.ishland.raknetify\") && !name.equals(\"com.ishland.raknetify.velocity.RaknetifyVelocityPlugin\"))\n                    && !name.startsWith(\"network.ycc.raknet\")\n                    && !isExcluded(name)) {\n                try {\n                    return Class.forName(name, true, this.getParent());\n                } catch (ClassNotFoundException | NoClassDefFoundError e) {\n                    // ignored, try our own loader\n                }\n            }\n\n            synchronized (getClassLoadingLock(name)) {\n                try {\n                    final Class<?> clazz = this.findClass(name);\n                    if (resolve) this.resolveClass(clazz);\n                    return clazz;\n                } catch (ClassNotFoundException e1) {\n                    // then fail here, there's nothing more we can do\n                    throw new ClassNotFoundException(name, e1);\n                }\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "velocity/src/main/java/com/ishland/raknetify/velocity/connection/RakNetVelocityChannelEventListener.java",
    "content": "/*\n * This file is a part of the Velocity implementation of the Raknetify\n * project, licensed under GPLv3.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\npackage com.ishland.raknetify.velocity.connection;\n\nimport com.google.common.base.Preconditions;\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.common.connection.MultiChannellingEncryption;\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.common.connection.SynchronizationLayer;\nimport com.ishland.raknetify.velocity.RaknetifyVelocityPlugin;\nimport com.velocitypowered.proxy.VelocityServer;\nimport com.velocitypowered.proxy.connection.MinecraftConnection;\nimport com.velocitypowered.proxy.crypto.EncryptionUtils;\nimport com.velocitypowered.proxy.network.Connections;\nimport com.velocitypowered.proxy.protocol.VelocityConnectionEvent;\nimport com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;\nimport com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket;\nimport com.velocitypowered.proxy.protocol.packet.JoinGamePacket;\nimport com.velocitypowered.proxy.protocol.packet.RespawnPacket;\nimport com.velocitypowered.proxy.protocol.packet.SetCompressionPacket;\nimport com.velocitypowered.proxy.protocol.packet.config.FinishedUpdatePacket;\nimport com.velocitypowered.proxy.protocol.packet.config.StartUpdatePacket;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.channel.ChannelPromise;\n\nimport javax.crypto.SecretKey;\nimport javax.crypto.spec.SecretKeySpec;\n\npublic class RakNetVelocityChannelEventListener extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-velocity-event-listener\";\n\n    private SecretKey encryptionKey = null;\n\n    @Override\n    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {\n        if (msg instanceof SetCompressionPacket) {\n            final MultiChannelingStreamingCompression compression = ctx.channel().pipeline().get(MultiChannelingStreamingCompression.class);\n            if (compression != null && compression.isActive()) {\n                RaknetifyVelocityPlugin.LOGGER.info(\"Preventing vanilla compression as streaming compression is enabled\");\n                promise.setSuccess(); // swallow SetCompression packet\n                return;\n            }\n        } else if (msg instanceof RespawnPacket || msg instanceof JoinGamePacket || msg instanceof StartUpdatePacket || msg instanceof FinishedUpdatePacket) {\n            ctx.write(SynchronizationLayer.SYNC_REQUEST_OBJECT); // sync\n            super.write(ctx, msg, promise);\n            return;\n        } else if (msg instanceof AvailableCommandsPacket) {\n            ctx.write(RakNetSimpleMultiChannelCodec.SIGNAL_START_MULTICHANNEL);\n            super.write(ctx, msg, promise);\n            return;\n        }\n        super.write(ctx, msg, promise);\n    }\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof EncryptionResponsePacket packet) {\n            try {\n                byte[] secret = EncryptionUtils.decryptRsa(((VelocityServer) RaknetifyVelocityPlugin.PROXY).getServerKeyPair(), packet.getSharedSecret());\n                this.encryptionKey = new SecretKeySpec(secret, \"AES\");\n            } catch (Throwable t) {\n                RaknetifyVelocityPlugin.LOGGER.warn(\"Failed to decrypt captured encryption secret, the raknetify connection is broken\", t);\n            }\n        }\n        super.channelRead(ctx, msg);\n    }\n\n    @Override\n    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {\n        super.userEventTriggered(ctx, evt);\n        if (evt == VelocityConnectionEvent.COMPRESSION_ENABLED) {\n            final MultiChannelingStreamingCompression compression = ctx.channel().pipeline().get(MultiChannelingStreamingCompression.class);\n            if (compression != null && compression.isActive()) {\n                RaknetifyVelocityPlugin.LOGGER.info(\"Preventing vanilla compression as streaming compression is enabled\");\n                ctx.channel().pipeline().replace(Connections.COMPRESSION_ENCODER, Connections.COMPRESSION_ENCODER, new ChannelDuplexHandler()); // no-op\n                ctx.channel().pipeline().replace(Connections.COMPRESSION_DECODER, Connections.COMPRESSION_DECODER, new ChannelDuplexHandler()); // no-op\n\n                // sync velocity compression state\n                final MinecraftConnection minecraftConnection = ctx.channel().pipeline().get(MinecraftConnection.class);\n                if (minecraftConnection != null) {\n                    minecraftConnection.setCompressionThreshold(-1);\n                } else {\n                    RaknetifyVelocityPlugin.LOGGER.warn(\"Unable to sync compression state with velocity\");\n                }\n            }\n        } else if (evt == VelocityConnectionEvent.COMPRESSION_DISABLED) {\n            ctx.channel().pipeline().replace(Connections.FRAME_DECODER, Connections.FRAME_DECODER, new ChannelDuplexHandler()); // no-op\n            ctx.channel().pipeline().replace(Connections.FRAME_ENCODER, Connections.FRAME_ENCODER, new ChannelDuplexHandler()); // no-op\n        } else if (evt == VelocityConnectionEvent.ENCRYPTION_ENABLED) {\n            Preconditions.checkState(this.encryptionKey != null, \"EncryptionResponse not received yet or already consumed\");\n            ctx.channel().pipeline().replace(Connections.CIPHER_ENCODER, Connections.CIPHER_ENCODER, new ChannelDuplexHandler());\n            ctx.channel().pipeline().replace(Connections.CIPHER_DECODER, Connections.CIPHER_DECODER, new ChannelDuplexHandler());\n            ctx.channel().pipeline().addBefore(MultiChannelingStreamingCompression.NAME, MultiChannellingEncryption.NAME, new MultiChannellingEncryption(encryptionKey));\n        }\n    }\n}\n"
  },
  {
    "path": "velocity/src/main/java/com/ishland/raknetify/velocity/connection/RakNetVelocityConnectionUtil.java",
    "content": "/*\n * This file is a part of the Velocity implementation of the Raknetify\n * project, licensed under GPLv3.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\npackage com.ishland.raknetify.velocity.connection;\n\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.ByteBufCopyDecoder;\nimport com.ishland.raknetify.common.connection.MultiChannelingStreamingCompression;\nimport com.ishland.raknetify.common.connection.RakNetConnectionUtil;\nimport com.ishland.raknetify.common.connection.RakNetSimpleMultiChannelCodec;\nimport com.ishland.raknetify.common.connection.multichannel.CustomPayloadChannel;\nimport com.ishland.raknetify.common.data.ProtocolMultiChannelMappings;\nimport com.ishland.raknetify.velocity.RaknetifyVelocityPlugin;\nimport com.velocitypowered.api.event.connection.LoginEvent;\nimport com.velocitypowered.api.event.player.ServerPostConnectEvent;\nimport com.velocitypowered.api.network.ProtocolVersion;\nimport com.velocitypowered.proxy.connection.MinecraftConnection;\nimport com.velocitypowered.proxy.connection.backend.VelocityServerConnection;\nimport com.velocitypowered.proxy.connection.client.ConnectedPlayer;\nimport com.velocitypowered.proxy.network.Connections;\nimport com.velocitypowered.proxy.protocol.ProtocolUtils;\nimport com.velocitypowered.proxy.protocol.StateRegistry;\nimport com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.handler.codec.haproxy.HAProxyMessageDecoder;\nimport network.ycc.raknet.RakNet;\n\nimport java.util.Arrays;\nimport java.util.Collections;\n\npublic class RakNetVelocityConnectionUtil {\n\n    private RakNetVelocityConnectionUtil() {\n    }\n\n    public static void initChannel(Channel channel) {\n        if (channel.config() instanceof RakNet.Config) {\n            RakNetConnectionUtil.initChannel(channel);\n//            channel.pipeline().addAfter(MultiChannelingStreamingCompression.NAME, MultiChannellingDataCodec.NAME, new MultiChannellingDataCodec(Constants.RAKNET_GAME_PACKET_ID));\n            channel.pipeline().addAfter(MultiChannelingStreamingCompression.NAME, RakNetSimpleMultiChannelCodec.NAME, new RakNetSimpleMultiChannelCodec(Constants.RAKNET_GAME_PACKET_ID));\n            channel.pipeline().addAfter(RakNetSimpleMultiChannelCodec.NAME, ByteBufCopyDecoder.NAME, new ByteBufCopyDecoder());\n        }\n    }\n\n    public static void postInitChannel(Channel channel, boolean isClientSide) {\n        if (channel.config() instanceof RakNet.Config) {\n            channel.pipeline().replace(Connections.READ_TIMEOUT, Connections.READ_TIMEOUT, new ChannelDuplexHandler()); // no-op\n            channel.pipeline().replace(Connections.FRAME_DECODER, Connections.FRAME_DECODER, new ChannelDuplexHandler()); // no-op\n            channel.pipeline().replace(Connections.FRAME_ENCODER, Connections.FRAME_ENCODER, new ChannelDuplexHandler()); // no-op\n            if (channel.pipeline().get(HAProxyMessageDecoder.class) != null)\n                channel.pipeline().remove(HAProxyMessageDecoder.class);\n            channel.pipeline().addBefore(Connections.HANDLER, RakNetVelocityChannelEventListener.NAME, new RakNetVelocityChannelEventListener());\n//            System.out.println(channel.pipeline().names());\n//            final MultiChannellingPacketCapture handler = new MultiChannellingPacketCapture();\n//            channel.pipeline().addLast(\"raknetify-multi-channel-packet-cature\", handler);\n//            channel.pipeline().get(MultiChannellingDataCodec.class).setCapture(handler);\n        }\n    }\n\n    public static void onPlayerLogin(LoginEvent evt) {\n        final ConnectedPlayer player = (ConnectedPlayer) evt.getPlayer();\n        final Channel channel = player.getConnection().getChannel();\n        if (channel != null && channel.config() instanceof RakNet.Config config) {\n            final RakNetSimpleMultiChannelCodec multiChannelCodec = channel.pipeline().get(RakNetSimpleMultiChannelCodec.class);\n            if (multiChannelCodec != null) {\n                final ProtocolVersion protocolVersion = player.getProtocolVersion();\n                final ProtocolMultiChannelMappings.VersionMapping versionMapping = ProtocolMultiChannelMappings.INSTANCE.mappings.get(protocolVersion.getProtocol());\n                if (versionMapping != null) {\n\n                    // handle custom payload separately\n                    final int pluginMessageId = StateRegistry.PLAY.getProtocolRegistry(ProtocolUtils.Direction.CLIENTBOUND, protocolVersion).getPacketId(new PluginMessagePacket());\n                    if (Constants.DEBUG) RaknetifyVelocityPlugin.LOGGER.info(\"PluginMessage packetId=%d at version=%d\".formatted(pluginMessageId, protocolVersion.getProtocol()));\n                    multiChannelCodec.addHandler(new CustomPayloadChannel.OverrideHandler(value -> value == pluginMessageId));\n\n                    // packet id -> channel id\n                    multiChannelCodec.addHandler(new RakNetSimpleMultiChannelCodec.PacketIdBasedOverrideHandler(\n                            versionMapping.s2c,\n                            \"%s (%d)\".formatted(protocolVersion.getVersionIntroducedIn(), protocolVersion.getProtocol())\n                    ));\n                } else {\n                    RaknetifyVelocityPlugin.LOGGER.warn(\"No multi-channel mappings for protocol version {} ({})\", protocolVersion.getProtocol(), Arrays.toString(protocolVersion.getVersionsSupportedBy().toArray(String[]::new)));\n                }\n            }\n\n            channel.pipeline().addBefore(Connections.HANDLER, RakNetVelocityPingUpdater.NAME, new RakNetVelocityPingUpdater(player));\n\n            RaknetifyVelocityPlugin.LOGGER.info(String.format(\"Raknetify: %s logged in via RakNet, mtu %d\", evt.getPlayer().getGameProfile().getName(), config.getMTU()));\n        }\n    }\n\n    public static void onServerSwitch(ServerPostConnectEvent evt) {\n        final ConnectedPlayer player = (ConnectedPlayer) evt.getPlayer();\n        final VelocityServerConnection connectedServer = player.getConnectedServer();\n        if (connectedServer == null) {\n            RaknetifyVelocityPlugin.LOGGER.warn(\"No connected server for player ({}) after server switch?\", player);\n            return;\n        }\n        final MinecraftConnection serverConnection = connectedServer.getConnection();\n        if (serverConnection == null) {\n            RaknetifyVelocityPlugin.LOGGER.warn(\"Connected server ({}) have no underlying connection?\", connectedServer);\n            return;\n        }\n        final Channel channel = player.getConnection().getChannel();\n        if (channel.config() instanceof RakNet.Config) {\n            serverConnection.getChannel().pipeline().addBefore(Connections.HANDLER, RakNetVelocityServerChannelEventListener.NAME, new RakNetVelocityServerChannelEventListener(channel));\n        }\n    }\n\n}\n"
  },
  {
    "path": "velocity/src/main/java/com/ishland/raknetify/velocity/connection/RakNetVelocityPingUpdater.java",
    "content": "/*\n * This file is a part of the Velocity implementation of the Raknetify\n * project, licensed under GPLv3.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\npackage com.ishland.raknetify.velocity.connection;\n\nimport com.ishland.raknetify.common.util.ReflectionUtil;\nimport com.velocitypowered.proxy.connection.client.ConnectedPlayer;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.util.concurrent.ScheduledFuture;\nimport network.ycc.raknet.RakNet;\n\nimport java.lang.reflect.InvocationTargetException;\nimport java.lang.reflect.Method;\nimport java.util.Objects;\nimport java.util.concurrent.TimeUnit;\n\npublic class RakNetVelocityPingUpdater extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-velocity-ping-updater\";\n\n    private static final Method PLAYER_SET_PING;\n\n    static {\n        try {\n            PLAYER_SET_PING = ReflectionUtil.accessible(ConnectedPlayer.class.getDeclaredMethod(\"setPing\", long.class));\n        } catch (NoSuchMethodException e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n    private final ConnectedPlayer player;\n\n    ScheduledFuture<?> updateTask = null;\n\n    public RakNetVelocityPingUpdater(ConnectedPlayer player) {\n        this.player = Objects.requireNonNull(player);\n    }\n\n    public void handlerAdded(ChannelHandlerContext ctx) {\n        if (ctx.channel().config() instanceof RakNet.Config config) {\n            updateTask = ctx.channel().eventLoop().scheduleAtFixedRate(\n                    () -> {\n                        try {\n                            PLAYER_SET_PING.invoke(player, ((config.getRTTNanos() + config.getRTTStdDevNanos()) / 1_000_000));\n                        } catch (IllegalAccessException | InvocationTargetException e) {\n                            throw new RuntimeException(e);\n                        }\n                    },\n                    0, 1000, TimeUnit.MILLISECONDS\n            );\n        }\n    }\n\n    public void handlerRemoved(ChannelHandlerContext ctx) {\n        if (updateTask != null) {\n            updateTask.cancel(false);\n            updateTask = null;\n        }\n    }\n\n}\n"
  },
  {
    "path": "velocity/src/main/java/com/ishland/raknetify/velocity/connection/RakNetVelocityServerChannelEventListener.java",
    "content": "/*\n * This file is a part of the Velocity implementation of the Raknetify\n * project, licensed under GPLv3.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\npackage com.ishland.raknetify.velocity.connection;\n\nimport com.google.common.base.Preconditions;\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.velocity.RaknetifyVelocityPlugin;\nimport com.velocitypowered.proxy.protocol.packet.KeepAlivePacket;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelDuplexHandler;\nimport io.netty.channel.ChannelHandler;\nimport io.netty.channel.ChannelHandlerContext;\nimport network.ycc.raknet.RakNet;\n\nimport java.util.Map;\nimport java.util.concurrent.TimeUnit;\n\npublic class RakNetVelocityServerChannelEventListener extends ChannelDuplexHandler {\n\n    public static final String NAME = \"raknetify-bungee-downstream-event-listener\";\n\n    private final Channel clientChannel;\n\n    public RakNetVelocityServerChannelEventListener(Channel clientChannel) {\n        Preconditions.checkArgument(clientChannel.config() instanceof RakNet.Config);\n        this.clientChannel = clientChannel;\n    }\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {\n        if (msg instanceof KeepAlivePacket) {\n            if (Constants.DEBUG) RaknetifyVelocityPlugin.LOGGER.info(\"Received downstream keepalive, swallowing it\");\n            final long rttNanos = RakNet.config(clientChannel).getRTTNanos();\n//            RaknetifyVelocityPlugin.PROXY.getScheduler().buildTask(RaknetifyVelocityPlugin.INSTANCE, () -> ctx.write(msg))\n//                    .delay(Math.max(rttNanos - 4_000_000, 0), TimeUnit.NANOSECONDS) // reduce delay to aid scheduling overhead\n//                    .clearRepeat()\n//                    .schedule();\n            ctx.channel().eventLoop().schedule(() -> ctx.writeAndFlush(msg), Math.max(rttNanos - 4_000_000, 0), TimeUnit.NANOSECONDS); // reduce delay to aid scheduling overhead\n            return; // prevent keepalive from being sent to clients\n        }\n        super.channelRead(ctx, msg);\n    }\n\n    @Override\n    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {\n        super.exceptionCaught(ctx, cause);\n        cause.printStackTrace();\n        for (Map.Entry<String, ChannelHandler> entry : ctx.channel().pipeline().toMap().entrySet()) {\n            System.out.println(\"%s: %s\".formatted(entry.getKey(), entry.getValue().getClass().getName()));\n        }\n    }\n}\n"
  },
  {
    "path": "velocity/src/main/java/com/ishland/raknetify/velocity/init/VelocityPacketRegistryInjector.java",
    "content": "/*\n * This file is a part of the Velocity implementation of the Raknetify\n * project, licensed under GPLv3.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\npackage com.ishland.raknetify.velocity.init;\n\nimport com.velocitypowered.api.network.ProtocolVersion;\nimport com.velocitypowered.proxy.protocol.MinecraftPacket;\nimport com.velocitypowered.proxy.protocol.StateRegistry;\nimport com.velocitypowered.proxy.protocol.packet.RespawnPacket;\nimport io.netty.util.collection.IntObjectMap;\nimport it.unimi.dsi.fastutil.objects.Object2IntMap;\n\nimport java.util.Map;\nimport java.util.function.Supplier;\n\nimport static com.ishland.raknetify.common.util.ReflectionUtil.accessible;\n\npublic class VelocityPacketRegistryInjector {\n\n    public static void inject() {\n        try {\n            final StateRegistry.PacketRegistry registry = (StateRegistry.PacketRegistry)\n                    accessible(StateRegistry.class.getDeclaredField(\"clientbound\")).get(StateRegistry.PLAY);\n            final var versions = (Map<ProtocolVersion, StateRegistry.PacketRegistry.ProtocolRegistry>)\n                    accessible(StateRegistry.PacketRegistry.class.getDeclaredField(\"versions\")).get(registry);\n            for (StateRegistry.PacketRegistry.ProtocolRegistry value : versions.values()) {\n                final var packetClassToId = (Object2IntMap<Class<? extends MinecraftPacket>>)\n                        accessible(StateRegistry.PacketRegistry.ProtocolRegistry.class.getDeclaredField(\"packetClassToId\")).get(value);\n                final var packetIdToSupplier = (IntObjectMap<Supplier<? extends MinecraftPacket>>)\n                        accessible(StateRegistry.PacketRegistry.ProtocolRegistry.class.getDeclaredField(\"packetIdToSupplier\")).get(value);\n                if (packetClassToId.containsKey(RespawnPacket.class)) {\n                    final int packetId = packetClassToId.getInt(RespawnPacket.class);\n                    if (!packetIdToSupplier.containsKey(packetId)) {\n                        packetIdToSupplier.put(packetId, RespawnPacket::new); // make respawn packet no longer encodeOnly\n                    }\n                }\n            }\n        } catch (Throwable t) {\n            throw new RuntimeException(\"Failed to inject velocity packet registry\", t);\n        }\n    }\n\n}\n"
  },
  {
    "path": "velocity/src/main/java/com/ishland/raknetify/velocity/init/VelocityRaknetifyServer.java",
    "content": "/*\n * This file is a part of the Velocity implementation of the Raknetify\n * project, licensed under GPLv3.\n *\n * Copyright (c) 2022-2025 ishland\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\npackage com.ishland.raknetify.velocity.init;\n\nimport com.google.common.base.Preconditions;\nimport com.ishland.raknetify.common.Constants;\nimport com.ishland.raknetify.common.connection.RakNetConnectionUtil;\nimport com.ishland.raknetify.common.util.NetworkInterfaceListener;\nimport com.ishland.raknetify.velocity.RaknetifyVelocityPlugin;\nimport com.ishland.raknetify.velocity.connection.RakNetVelocityConnectionUtil;\nimport com.velocitypowered.api.event.proxy.ListenerBoundEvent;\nimport com.velocitypowered.api.event.proxy.ListenerCloseEvent;\nimport com.velocitypowered.api.network.ListenerType;\nimport com.velocitypowered.proxy.VelocityServer;\nimport com.velocitypowered.proxy.network.ConnectionManager;\nimport io.netty.bootstrap.ServerBootstrap;\nimport io.netty.channel.Channel;\nimport io.netty.channel.ChannelFactory;\nimport io.netty.channel.ChannelFuture;\nimport io.netty.channel.ChannelInitializer;\nimport io.netty.channel.ChannelOption;\nimport io.netty.channel.EventLoopGroup;\nimport io.netty.channel.FixedRecvByteBufAllocator;\nimport io.netty.channel.socket.DatagramChannel;\nimport it.unimi.dsi.fastutil.objects.ObjectIterator;\nimport it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;\nimport network.ycc.raknet.server.channel.RakNetServerChannel;\n\nimport java.io.IOException;\nimport java.lang.reflect.Method;\nimport java.net.InetAddress;\nimport java.net.InetSocketAddress;\nimport java.net.NetworkInterface;\nimport java.util.concurrent.TimeUnit;\n\nimport static com.ishland.raknetify.common.util.ReflectionUtil.accessible;\n\npublic class VelocityRaknetifyServer {\n\n    private static final int portOverride = Integer.getInteger(\"raknetify.velocity.portOverride\", -1);\n\n    private static final Method INIT_CHANNEL;\n\n    static {\n        try {\n            INIT_CHANNEL = accessible(ChannelInitializer.class.getDeclaredMethod(\"initChannel\", Channel.class));\n        } catch (Throwable t) {\n            throw new RuntimeException(t);\n        }\n    }\n\n    private static final ReferenceOpenHashSet<ChannelFuture> channels = new ReferenceOpenHashSet<>();\n    private static volatile InetSocketAddress currentServerAddress = null;\n    private static volatile boolean active = false;\n\n    static {\n        NetworkInterfaceListener.addListener(event -> {\n            RaknetifyVelocityPlugin.PROXY.getScheduler()\n                    .buildTask(RaknetifyVelocityPlugin.INSTANCE, () -> {\n                        if (!active) return;\n                        final InetSocketAddress address = currentServerAddress;\n                        if (address != null && address.getAddress().isAnyLocalAddress()) {\n                            if (event.added()) {\n                                startServer(new InetSocketAddress(event.address(), address.getPort()));\n                            } else {\n                                synchronized (channels) {\n                                    final ObjectIterator<ChannelFuture> iterator = channels.iterator();\n                                    while (iterator.hasNext()) {\n                                        final ChannelFuture future = iterator.next();\n                                        if (((InetSocketAddress) future.channel().localAddress()).getAddress().equals(event.address())) {\n                                            closeServer(future);\n                                            iterator.remove();\n                                        }\n                                    }\n                                }\n                            }\n                        }\n                    })\n                    .delay(100, TimeUnit.MILLISECONDS)\n                    .schedule();\n        });\n    }\n\n    public static void start(ListenerBoundEvent evt) {\n        if (evt.getListenerType() != ListenerType.MINECRAFT) return;\n        Preconditions.checkArgument(RaknetifyVelocityPlugin.PROXY instanceof VelocityServer);\n        Preconditions.checkState(channels.isEmpty(), \"Raknetify Server is already running\");\n        final InetSocketAddress address = evt.getAddress();\n        currentServerAddress = address;\n        active = true;\n\n        if (address.getAddress().isAnyLocalAddress()) {\n            try {\n                for (NetworkInterface networkInterface : NetworkInterface.networkInterfaces().toList()) {\n                    for (InetAddress inetAddress : networkInterface.inetAddresses().toList()) {\n                        try {\n                            startServer(new InetSocketAddress(inetAddress, address.getPort()));\n                        } catch (Throwable t) {\n                            RaknetifyVelocityPlugin.LOGGER.error(\"Failed to start raknetify server\", t);\n                        }\n                    }\n                }\n            } catch (Throwable t) {\n                throw new RuntimeException(\"Failed to start raknetify server\", t);\n            }\n        } else {\n            startServer(address);\n        }\n    }\n\n    private static void startServer(InetSocketAddress address) {\n        try {\n            final ConnectionManager cm = (ConnectionManager) accessible(VelocityServer.class.getDeclaredField(\"cm\")).get(RaknetifyVelocityPlugin.PROXY);\n            final Object transportType = accessible(ConnectionManager.class.getDeclaredField(\"transportType\")).get(cm);\n            final ChannelFactory<? extends DatagramChannel> datagramChannelFactory =\n                    (ChannelFactory<? extends DatagramChannel>) accessible(Class.forName(\"com.velocitypowered.proxy.network.TransportType\").getDeclaredField(\"datagramChannelFactory\")).get(transportType);\n            final EventLoopGroup bossGroup = (EventLoopGroup) accessible(ConnectionManager.class.getDeclaredField(\"bossGroup\")).get(cm);\n            final EventLoopGroup workerGroup = (EventLoopGroup) accessible(ConnectionManager.class.getDeclaredField(\"workerGroup\")).get(cm);\n\n            final boolean hasPortOverride = portOverride > 0 && portOverride < 65535;\n            InetSocketAddress actualAddress = hasPortOverride ? new InetSocketAddress(address.getAddress(), portOverride) : address;\n\n            synchronized (channels) {\n                for (ChannelFuture future : channels) {\n                    if (future.channel().localAddress().equals(actualAddress)) return;\n                }\n\n                ChannelFuture future = new ServerBootstrap()\n                        .channelFactory(() -> new RakNetServerChannel(() -> {\n                            final DatagramChannel channel = datagramChannelFactory.newChannel();\n                            channel.config().setOption(ChannelOption.IP_TOS, RakNetConnectionUtil.DEFAULT_IP_TOS);\n                            channel.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(Constants.LARGE_MTU + 512).maxMessagesPerRead(128));\n                            return channel;\n                        }))\n                        .group(bossGroup, workerGroup)\n                        .childHandler(new ChannelInitializer<>() {\n                            @Override\n                            protected void initChannel(Channel channel) throws Exception {\n                                RakNetVelocityConnectionUtil.initChannel(channel);\n                                INIT_CHANNEL.invoke(cm.serverChannelInitializer.get(), channel);\n                                RakNetVelocityConnectionUtil.postInitChannel(channel, false);\n                            }\n                        })\n                        .localAddress(actualAddress)\n                        .bind()\n                        .syncUninterruptibly();\n\n                RaknetifyVelocityPlugin.LOGGER.info(\"Raknetify server started on {}\", future.channel().localAddress());\n                channels.add(future);\n            }\n\n        } catch (Throwable t) {\n            if (t instanceof IOException) {\n                RaknetifyVelocityPlugin.LOGGER.error(\"Raknetify server failed to start on {}: {}\", address, t.getMessage());\n                return;\n            }\n            throw new RuntimeException(\"Failed to start Raknetify server\", t);\n        }\n    }\n\n    public static void stop(ListenerCloseEvent evt) {\n        if (evt.getListenerType() != ListenerType.MINECRAFT) return;\n        Preconditions.checkArgument(RaknetifyVelocityPlugin.PROXY instanceof VelocityServer);\n        Preconditions.checkState(!channels.isEmpty(), \"Raknetify Server is not running\");\n        synchronized (channels) {\n            active = false;\n            for (ChannelFuture channel : channels) {\n                closeServer(channel);\n            }\n\n            channels.clear();\n        }\n    }\n\n    private static void closeServer(ChannelFuture channel) {\n        RaknetifyVelocityPlugin.LOGGER.info(\"Closing Raknetify server {}\", channel.channel().localAddress());\n        try {\n            channel.channel().close().sync();\n        } catch (InterruptedException e) {\n            RaknetifyVelocityPlugin.LOGGER.error(\"Interrupted whilst closing raknetify server\");\n        }\n    }\n\n}\n"
  },
  {
    "path": "velocity/src/main/resources/velocity-plugin.json",
    "content": "{\n  \"id\": \"raknetify\",\n  \"name\": \"Raknetify (Velocity)\",\n  \"version\": \"${version}\",\n  \"description\": \"A Velocity plugin that allows using RakNet as Minecraft networking backend. \",\n  \"authors\": [\"ishland\"],\n  \"dependencies\": [],\n  \"main\": \"com.ishland.raknetify.velocity.RaknetifyVelocityPlugin\"\n}"
  }
]