-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPZHook_server
182 lines (157 loc) · 8.38 KB
/
PZHook_server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# ZomboidJavaHook start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh ZomboidJavaHook
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and ZOMBOID_JAVA_HOOK_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
PZ_HOME=$(readlink -f "$(pwd)")
cd "${PZ_HOME}" || exit 1
PZ_HOME=$(pwd)
# Find and Kill all left over processes
pz_pid=$(pgrep -if 'java -Dzomboid.steam')
counter=1
while ! [ -z $pz_pid ]
do
if [ $counter -gt 15 ]; then
break
fi
kill -9 $pz_pid
((counter++))
done
if [ ! -f "$PZ_HOME/ProjectZomboid64" ] && [ ! -f "$PZ_HOME/ProjectZomboid32" ]; then
echo -e "\nERROR: Unable to find Project Zomboid installation directory." \
"Searched in directory '${PZ_HOME}'\n"
exit 1
fi
APP_NAME="PZHook_server"
APP_BASE_NAME=${0##*/}
# path to local game directory where logs, mods and configs are stored
LOCAL_PZ_HOME="${PZ_HOME}/Zomboid"
exportGameJava() {
if "$1/jre64/bin/java" -version >/dev/null 2>&1; then
echo "64-bit java detected in game directory"
export JAVA_CMD="$1/jre64/bin/java"
return 0
elif "${INSTDIR}/jre/bin/java" -client -version >/dev/null 2>&1; then
echo "32-bit java detected game directory"
export JAVA_CMD="$1/jre/bin/java"
return 0
else
echo -e "\nERROR: Couldn't determine 32/64 bit of java in game directory\n"
return 1
fi
}
# Create local game directory if it doesn't exist and set directory permission to a+rwx,g-w,o-w
[ ! -d "${LOCAL_PZ_HOME}" ] && mkdir -m 0755 "${LOCAL_PZ_HOME}"
if [ -n "$JAVA_HOME" ]; then
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
# IBM's JDK on AIX uses strange locations for the executables
JAVA_CMD="$JAVA_HOME/jre/sh/java"
else
JAVA_CMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVA_CMD" ]; then
exportGameJava $PZ_HOME
if [ $? != 0 ]; then
echo -e "\nERROR: JAVA_HOME is set to an invalid directory ($JAVA_HOME) and no Java distribution" \
"found in game directory.\nPlease reinstall Project Zomboid or set the JAVA_HOME variable" \
"to match the location of your Java installation if you want to run the Hook" \
"with a custom Java distribution\n"
exit 1
fi
fi
else
exportGameJava $PZ_HOME
if [ $? != 0 ]; then
JAVA_CMD="java"
which java >/dev/null 2>&1 || echo -e "\nERROR: JAVA_HOME is not set and no 'java' command" \
"could be found in your PATH.\nPlease set the JAVA_HOME variable in your environment" \
"to match the location of your Java installation.\n"
exit 1
fi
fi
# This is the Java version we want
JAVA_TARGET_VERSION="17.0"
# Determine which Java version is used
JAVA_VERSION_INFO=$("$JAVA_CMD" -version 2>&1 | awk -F '"' '/version/ {print $2}')
JAVA_VERSION=$(echo "$JAVA_VERSION_INFO" | cut -d '.' -f -2)
if [ "$JAVA_VERSION" != $JAVA_TARGET_VERSION ]; then
echo -e "\nERROR: JAVA_HOME points to wrong Java version ($JAVA_VERSION)." \
"\nPlease set the JAVA_HOME variable in your environment to match the" \
"location of Java version $JAVA_TARGET_VERSION installation.\n"
exit 1
fi
# Path to Hook jar library directory
LIB_PATH="${PZ_HOME}/java/lib"
CLASSPATH="$PZ_HOME/java/PZHook_server-1.0.jar:$PZ_HOME/java/lib/javacord-3.4.0-shaded.jar:$PZ_HOME/java/lib/javafx-fxml-17.0.2-linux.jar:$PZ_HOME/java/lib/javafx-controls-17.0.2-linux.jar:$PZ_HOME/java/lib/javafx-controls-17.0.2.jar:$PZ_HOME/java/lib/javafx-graphics-17.0.2-linux.jar:$PZ_HOME/java/lib/javafx-graphics-17.0.2-win.jar:$PZ_HOME/java/lib/javafx-graphics-17.0.2-mac.jar:$PZ_HOME/java/lib/javafx-graphics-17.0.2.jar:$PZ_HOME/java/lib/javafx-base-17.0.2-linux.jar:$PZ_HOME/java/lib/javafx-base-17.0.2.jar:$PZ_HOME/java/lib/interceptify-1.2.2.jar:$PZ_HOME/java/lib/yasson-3.0.0-RC2.jar:$PZ_HOME/java/lib/parsson-1.1.0.jar:$PZ_HOME/java/lib/jakarta.json-api-2.1.0.jar:$PZ_HOME/java/lib/jakarta.json.bind-api-3.0.0.jar:$PZ_HOME/java/lib/jaxb-runtime-4.0.0.jar:$PZ_HOME/java/lib/jaxb-core-4.0.0.jar:$PZ_HOME/java/lib/jakarta.xml.bind-api-4.0.0.jar:$PZ_HOME/java/lib/byte-buddy-1.12.10.jar:$PZ_HOME/java/lib/angus-activation-1.0.0.jar:$PZ_HOME/java/lib/jakarta.activation-api-2.1.0.jar:$PZ_HOME/java/lib/txw2-4.0.0.jar:$PZ_HOME/java/lib/istack-commons-runtime-4.1.1.jar:$PZ_HOME/java/*:$PZ_HOME/java/.:$PZ_HOME/java/istack-commons-runtime.jar:$PZ_HOME/java/jassimp.jar:$PZ_HOME/java/javacord-2.0.17-shaded.jar:$PZ_HOME/java/javax.activation-api.jar:$PZ_HOME/java/jaxb-api.jar:$PZ_HOME/java/jaxb-runtime.jar:$PZ_HOME/java/lwjgl.jar:$PZ_HOME/java/lwjgl-natives-linux.jar:$PZ_HOME/java/lwjgl-glfw.jar:$PZ_HOME/java/lwjgl-glfw-natives-linux.jar:$PZ_HOME/java/lwjgl-jemalloc.jar:$PZ_HOME/java/lwjgl-jemalloc-natives-linux.jar:$PZ_HOME/java/lwjgl-opengl.jar:$PZ_HOME/java/lwjgl-opengl-natives-linux.jar:$PZ_HOME/java/lwjgl_util.jar:$PZ_HOME/java/sqlite-jdbc-3.27.2.1.jar:$PZ_HOME/java/trove-3.0.3.jar:$PZ_HOME/java/uncommons-maths-1.2.3.jar:$PZ_HOME/java/commons-compress-1.18.jar"
# Project Zomboid properties
PZ_OPTS="-Dzomboid.steam=1 -Dzomboid.znetlog=1 -Duser.home=${PZ_HOME}"
# Java command-line options
JAVA_OPTS="-XX:+UseZGC -XX:-CreateCoredumpOnCrash \
-XX:-OmitStackTraceInFastThrow -Xms1800m -Xmx4096m -javaagent:./java/PZHook_server-1.0.jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED"
# Java system properties
SYS_PROPS="-Djava.library.path=${PZ_HOME}:${PZ_HOME}/linux64:${PZ_HOME}/natives:${PZ_HOME}/jre64/lib/amd64 -Dorg.lwjgl.librarypath=${PZ_HOME}"
# Add default JVM options here. You can also use JAVA_OPTS and ZOMBOID_JAVA_HOOK_OPTS to pass JVM options to this script.
#DEFAULT_JVM_OPTS='"-Djava.awt.headless=true" "-Xms1800m" "-Xmx4096m""-Djava.library.path=./linux64:./natives:.:jre64/lib/amd64" "-XX:+UseZGC" "-javaagent:./java/ZomboidJavaHook-1.0-Server.jar"'
echo "Launching Zomboid Hook..."
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $PZ_OPTS $JAVA_OPTS $SYS_PROPS -classpath "$CLASSPATH" PZHook_server.Main
# Execute Java command to launch Storm
exec "$JAVA_CMD" "$@"
#echo "testing: " $DEFAULT_JVM_OPTS
#exit 0