diff --git a/.gitignore b/.gitignore index aacd13c86..de5e97e42 100644 --- a/.gitignore +++ b/.gitignore @@ -84,4 +84,8 @@ logs/ server-icon.png /bin/ run/ -plugins/ \ No newline at end of file +plugins/ + +### Natives stuff ### +natives/mbedtls +natives/zlib-ng \ No newline at end of file diff --git a/native/compile-linux.sh b/native/compile-linux.sh index 5e5354976..4b759df20 100755 --- a/native/compile-linux.sh +++ b/native/compile-linux.sh @@ -1,10 +1,21 @@ #!/bin/bash +if [ ! -d zlib-ng ]; then + echo "Cloning zlib-ng..." + git clone https://github.com/zlib-ng/zlib-ng.git +fi + +echo "Compiling zlib-ng..." +cd zlib-ng +CFLAGS="-fPIC -O3" ./configure --zlib-compat --static +make clean && make +cd .. + # Modify as you need. MBEDTLS_ROOT=mbedtls CFLAGS="-O3 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/ -fPIC -shared" -gcc $CFLAGS -lz src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \ - src/main/c/jni_zlib_common.c -o src/main/resources/linux_x64/velocity-compress.so +gcc $CFLAGS -Izlib-ng src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \ + src/main/c/jni_zlib_common.c zlib-ng/libz.a -o src/main/resources/linux_x64/velocity-compress.so gcc $CFLAGS -I $MBEDTLS_ROOT/include -shared $MBEDTLS_ROOT/library/aes.c $MBEDTLS_ROOT/library/aesni.c \ $MBEDTLS_ROOT/library/platform.c $MBEDTLS_ROOT/library/platform_util.c src/main/c/jni_util.c src/main/c/jni_cipher.c \ -o src/main/resources/linux_x64/velocity-cipher.so \ No newline at end of file diff --git a/native/compile-osx.sh b/native/compile-osx.sh index 3cdbeafd3..0c0f2c2c5 100755 --- a/native/compile-osx.sh +++ b/native/compile-osx.sh @@ -1,12 +1,23 @@ #!/bin/bash +if [ ! -d zlib-ng ]; then + echo "Cloning zlib-ng..." + git clone https://github.com/zlib-ng/zlib-ng.git +fi + +echo "Compiling zlib-ng..." +cd zlib-ng +CFLAGS="-fPIC -O3" ./configure --zlib-compat --static +make clean && make +cd .. + # Modify as you need. MBEDTLS_ROOT=mbedtls export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home CFLAGS="-O3 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin/ -fPIC -shared" -clang $CFLAGS -lz src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \ - src/main/c/jni_zlib_common.c -o src/main/resources/macosx/velocity-compress.dylib +clang $CFLAGS -Izlib-ng src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \ + src/main/c/jni_zlib_common.c zlib-ng/libz.a -o src/main/resources/macosx/velocity-compress.dylib clang $CFLAGS -I $MBEDTLS_ROOT/include -shared $MBEDTLS_ROOT/library/aes.c $MBEDTLS_ROOT/library/aesni.c \ $MBEDTLS_ROOT/library/platform.c $MBEDTLS_ROOT/library/platform_util.c src/main/c/jni_util.c src/main/c/jni_cipher.c \ -o src/main/resources/macosx/velocity-cipher.dylib \ No newline at end of file diff --git a/native/src/main/c/jni_zlib_common.c b/native/src/main/c/jni_zlib_common.c index 20d320311..fa5a0cbab 100644 --- a/native/src/main/c/jni_zlib_common.c +++ b/native/src/main/c/jni_zlib_common.c @@ -8,7 +8,7 @@ void JNICALL check_zlib_free(JNIEnv *env, z_stream *stream, bool deflate) { int ret = deflate ? deflateEnd(stream) : inflateEnd(stream); - char *msg = stream->msg; + const char *msg = stream->msg; free((void*) stream); switch (ret) { diff --git a/native/src/main/c/jni_zlib_deflate.c b/native/src/main/c/jni_zlib_deflate.c index e76ba3053..6e05f7cae 100644 --- a/native/src/main/c/jni_zlib_deflate.c +++ b/native/src/main/c/jni_zlib_deflate.c @@ -33,7 +33,7 @@ Java_com_velocitypowered_natives_compression_NativeZlibDeflate_init(JNIEnv *env, if (ret == Z_OK) { return (jlong) stream; } else { - char *zlib_msg = stream->msg; + const char *zlib_msg = stream->msg; free(stream); switch (ret) { case Z_MEM_ERROR: diff --git a/native/src/main/c/jni_zlib_inflate.c b/native/src/main/c/jni_zlib_inflate.c index 816670e43..64804e160 100644 --- a/native/src/main/c/jni_zlib_inflate.c +++ b/native/src/main/c/jni_zlib_inflate.c @@ -32,7 +32,7 @@ Java_com_velocitypowered_natives_compression_NativeZlibInflate_init(JNIEnv *env, if (ret == Z_OK) { return (jlong) stream; } else { - char *zlib_msg = stream->msg; + const char *zlib_msg = stream->msg; free(stream); switch (ret) { case Z_MEM_ERROR: diff --git a/native/src/main/resources/linux_x64/velocity-compress.so b/native/src/main/resources/linux_x64/velocity-compress.so index 7bd32162d..d4ec11d70 100755 Binary files a/native/src/main/resources/linux_x64/velocity-compress.so and b/native/src/main/resources/linux_x64/velocity-compress.so differ diff --git a/native/src/main/resources/macosx/velocity-compress.dylib b/native/src/main/resources/macosx/velocity-compress.dylib index afe4075d7..3624162a6 100755 Binary files a/native/src/main/resources/macosx/velocity-compress.dylib and b/native/src/main/resources/macosx/velocity-compress.dylib differ