2023-06-19 01:20:28 -07:00
[ -z "$EDITOR" ] && echo '$EDITOR not set' && exit
2023-06-17 00:11:54 -07:00
BROWSER=firefox
2023-06-22 03:15:32 -07:00
# rename this if youre making a fork. or dont. im not multimc
2021-11-24 00:19:56 -08:00
PNAME=mcl
2023-06-17 00:11:54 -07:00
MDIR=~/.$PNAME
2021-11-24 00:19:56 -08:00
CACHE=/tmp/$PNAME\cache
2023-06-22 03:15:32 -07:00
PLAT=''
[ `uname -s` = Linux ] && PLAT=linux
[ `uname -s` = Darwin ] && PLAT=osx
#TODO other unixlikes, figure out m1 support
2023-06-17 00:11:54 -07:00
login() {
$1 'https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=ed8c593c-4c7f-4484-8dc4-d2ce60bf62a4&response_type=code&response_mode=query&scope=XboxLive.signin&redirect_uri=https%3A%2F%2Fmothcompute.lilylenora.net%2Fmcl_auth.php'
echo -n 'opened sign-in link in firefox. paste the output into the file that is about to be opened (press enter to continue):'
read
$EDITOR "$MDIR/account$2"
}
[ "$1" = edit ] && $EDITOR "$MDIR/profile/$2" && exit
[ ! -f "$MDIR/account$2" -o "$1" = 'login' ] && login "$BROWSER" "$2" && echo logged in && exit
[ $(date -d "$(jq -r .exp.mc "$MDIR/account$2")" +%s) -le $(date +%s) ] && if [ $(date -d "$(jq -r .exp.xb "$MDIR/account$2")" +%s) -le $(date +%s) ]; then
login "$BROWSER" "$2"
else
2023-06-22 03:15:32 -07:00
jq -r .tok.xb "$MDIR/account$2"
[ $? = 0 ] && login "$BROWSER" "$2"
2023-06-17 00:11:54 -07:00
curl 'https://mothcompute.lilylenora.net/mcl_auth.php?xb='$(jq -r .tok.xb "$MDIR/account$2")'&u='$(jq -r .xb_usr "$MDIR/account$2")'&e='$(jq -r .exp.xb "$MDIR/account$2") > "$MDIR/swp.account$2"
mv "$MDIR/swp.account$2" "$MDIR/account$2"
fi
user_type=msa
auth_xuid=$(jq -r '.xb_uid' "$MDIR/account$2")
auth_player_name=$(jq -r '.mc_usr' "$MDIR/account$2")
auth_uuid=$(jq -r '.mc_uid' "$MDIR/account$2")
auth_access_token=$(jq -r '.tok.mc' "$MDIR/account$2")
auth_session="token:$auth_access_token:$auth_uuid"
clientid=$(dd if=/dev/random bs=48 count=1 status=none|base64)
2023-06-17 22:14:15 -07:00
mkdir -p "$CACHE" "$MDIR/libs" "$MDIR/assets" "$MDIR/assets/indexes" "$MDIR/assets/objects" "$MDIR/versions" "$CACHE/natives" "$MDIR/profile"
[ ! -f "$MDIR/launcher_profiles.json" ] && echo '{"profiles":{}}' > "$MDIR/launcher_profiles.json"
2023-06-17 00:11:54 -07:00
[ ! -z "$1" -a ! -f "$MDIR/profile/$1" ] && echo -ne "# type 'snapshot', 'release', or a version number. get a list with:\n# curl https://launchermeta.mojang.com/mc/game/version_manifest.json | jq -r '.versions[].id' | less\nVERSION=snapshot\nJAVA8=/usr/lib/jvm/java-8-openjdk/bin/java\nJAVA_LATEST=/bin/java\ngame_directory=~/mclinstance\n# additional jvm arguments\njvm="> "$MDIR/profile/$1" && $EDITOR "$MDIR/profile/$1"
2021-11-24 00:19:56 -08:00
2023-06-19 00:56:51 -07:00
MANIFEST='https://launchermeta.mojang.com/mc/game/version_manifest.json'
[ "$(uname -sm)" = "Linux aarch64" ] && MANIFEST='https://raw.githubusercontent.com/theofficialgman/piston-meta-arm64/main/mc/game/version_manifest.json'
2021-11-24 00:19:56 -08:00
echo fetching version manifest...
2023-06-19 01:20:28 -07:00
wget "$MANIFEST" -qO $CACHE/version_manifest.json
2021-11-24 00:19:56 -08:00
2023-06-17 00:11:54 -07:00
CHANNEL=snapshot
JAVA8=/usr/lib/jvm/java-8-openjdk/bin/java
JAVA_LATEST=/bin/java
game_directory=~/mclinstance
2021-11-24 00:19:56 -08:00
VERSION="$(jq -r .latest.$CHANNEL $CACHE/version_manifest.json)"
2023-06-17 00:11:54 -07:00
jvm=""
2023-06-22 03:15:32 -07:00
export VIRTP=""
2023-06-17 00:11:54 -07:00
[ ! -z "$1" ] && . "$MDIR/profile/$1"
mkdir -p "$game_directory"
2021-11-24 00:19:56 -08:00
2023-06-17 00:11:54 -07:00
[ "$VERSION" = 'snapshot' -o "$VERSION" = 'release' ] && CHANNEL=$VERSION && VERSION="$(jq -r .latest.$CHANNEL $CACHE/version_manifest.json)"
2021-11-24 00:19:56 -08:00
echo ver $VERSION
2023-06-17 22:14:15 -07:00
mkdir -p $MDIR/versions/$VERSION
2021-11-24 00:19:56 -08:00
VERSION_MANIFEST=$(jq ".versions[] | select(.id==\"$VERSION\")" $CACHE/version_manifest.json | jq -r .url)
2023-06-17 22:14:15 -07:00
[ ! -z "$VERSION_MANIFEST" ] && [ ! -f "$MDIR/versions/$VERSION/$(basename $VERSION_MANIFEST)" ] && wget $VERSION_MANIFEST -qO "$MDIR/versions/$VERSION/$(basename $VERSION_MANIFEST)"
VERJSON="$MDIR/versions/$VERSION/$VERSION.json"
IVER=$(jq -r .inheritsFrom "$VERJSON")
2023-06-19 01:20:28 -07:00
[ ! "$IVER" = null ] && spruce merge "$MDIR/versions/$IVER/$IVER.json" "$VERJSON" | spruce json > "$CACHE/$VERSION.json" && export VERJSON="$CACHE/$VERSION.json"
2023-06-17 22:14:15 -07:00
echo json $VERJSON
2021-11-24 00:19:56 -08:00
2023-06-17 00:11:54 -07:00
# get jar file for version TODO unwrapped filename
2023-06-17 22:14:15 -07:00
[ ! -f "$MDIR/versions/$VERSION/$VERSION.jar" ] && wget "$(jq -r .downloads.client.url $VERJSON)" -qO "$MDIR/versions/$VERSION/$VERSION.jar"
2021-11-24 00:19:56 -08:00
2023-06-17 00:11:54 -07:00
# get version assets TODO unwrapped filename
2023-06-17 22:14:15 -07:00
VERSION_ASSETS="$(jq -r .assetIndex.url $VERJSON)"
2023-06-17 00:11:54 -07:00
[ ! -f "$MDIR/assets/indexes/$(basename $VERSION_ASSETS)" ] && wget $VERSION_ASSETS -qO "$MDIR/assets/indexes/$(basename $VERSION_ASSETS)"
2021-11-24 00:19:56 -08:00
2023-06-22 03:15:32 -07:00
export rsrc=''
2023-06-17 00:11:54 -07:00
# download objects TODO unwrapped filename
if [ "$(jq .map_to_resources $MDIR/assets/indexes/$(basename $VERSION_ASSETS))" = true -o "$(jq .virtual $MDIR/assets/indexes/$(basename $VERSION_ASSETS))" = true ]; then
2023-06-22 03:15:32 -07:00
export rsrc=1
2023-06-17 00:11:54 -07:00
[ "$(jq .virtual $MDIR/assets/indexes/$(basename $VERSION_ASSETS))" = true ] && VIRTP=virtual/
OLDIFS="$IFS"
IFS=$'\n'
for OBJ in `jq -r '.objects|to_entries[]|{"value":.value.hash,"key":.key}' "$MDIR/assets/indexes/$(basename $VERSION_ASSETS)"|tr -d '\n'|xargs|sed 's/[}]/\n/g'|sed 's/^.*value: //g;s/, key://g'`; do
echo $OBJ
OBJP="`echo $OBJ | sed 's/^[^ ]* //'`"
OBJH="`echo $OBJ | sed 's/ .*//'`"
eval mkdir -p '$(dirname "$MDIR/resources/$VIRTP$OBJP")'
echo wget "https://resources.download.minecraft.net/$(echo $OBJH | cut -b 1,2)/$OBJH" -qO "$MDIR/resources/$VIRTP$OBJP"
[ ! -f "$MDIR/resources/$VIRTP$OBJP" ] && wget "https://resources.download.minecraft.net/$(echo $OBJH | cut -b 1,2)/$OBJH" -qO "$MDIR/resources/$VIRTP$OBJP"
done
IFS="$OLDIFS"
else
for OBJ in `jq -r .objects[].hash "$MDIR/assets/indexes/$(basename $VERSION_ASSETS)"`; do
mkdir -p "$MDIR/assets/objects/$(echo $OBJ | cut -b 1,2)"
[ ! -f "$MDIR/assets/objects/$(echo $OBJ | cut -b 1,2)/$OBJ" ] && echo wget "https://resources.download.minecraft.net/$(echo $OBJ | cut -b 1,2)/$OBJ" && wget "https://resources.download.minecraft.net/$(echo $OBJ | cut -b 1,2)/$OBJ" -qO "$MDIR/assets/objects/$(echo $OBJ | cut -b 1,2)/$OBJ"
done
fi
echo object download complete
2021-11-24 00:19:56 -08:00
2023-06-18 17:36:20 -07:00
export classpath="$MDIR/versions/$VERSION/$VERSION.jar"
2023-06-17 22:14:15 -07:00
2023-06-22 03:15:32 -07:00
shortdl() {
echo shortdl \"$1\" \"$2\" \"$3\"
CPATH="`echo $1 | sed 's/\./\//g'`/$2/$3/$2-$3"
FCPATH="$MDIR/libraries/$CPATH.jar"
mkdir -p "$(dirname $FCPATH)"
[ ! -f "$FCPATH" ] && wget "https://libraries.minecraft.net/$CPATH.jar" -O "$FCPATH"
classpath="$classpath:$FCPATH"
[ ! -z "$4" ] && eval wget "https://libraries.minecraft.net/$CPATH-$4.jar" -O "$CPATH-$4.jar" && unzip "$CPATH-$4.jar" -d "$CACHE/natives/$VERSION"
}
2023-06-18 17:36:20 -07:00
fetchlib() {
LIBJSON="$1"
for LIBINDEX in `seq 0 $(($(jq '.libraries|length' "$LIBJSON")-1))`; do
2023-06-22 03:15:32 -07:00
echo -n "lib $LIBINDEX "
2023-06-18 17:36:20 -07:00
LIBPATH="$MDIR/libraries/"`jq -r ".libraries[$LIBINDEX].downloads.artifact.path" "$LIBJSON"`
LIBURL=`jq -r ".libraries[$LIBINDEX].downloads.artifact.url" "$LIBJSON"`
LIBNAME=`jq -r ".libraries[$LIBINDEX].name" "$LIBJSON"`
2023-06-17 22:14:15 -07:00
2023-06-22 03:15:32 -07:00
ALLOW=1
PALLOW=1
if [ ! "`jq -r \".libraries[$LIBINDEX].rules\" \"$LIBJSON\"`" = null ]; then
ALLOW=0
for RULEINDEX in `seq 0 $(($(jq '.libraries['$LIBINDEX'].rules|length' "$LIBJSON")-1))`; do
action=`jq -r ".libraries[$LIBINDEX].rules[$RULEINDEX].action" "$LIBJSON"`
os=`jq -r ".libraries[$LIBINDEX].rules[$RULEINDEX].os.name" "$LIBJSON"`
[ "$os" = $PLAT -a "$action" = disallow ] && ALLOW=0 && PALLOW=0
[ "$os" = $PLAT -a "$action" = allow ] && ALLOW=1
[ "$os" = null -a "$action" = allow -a "$PALLOW" = 1 ] && ALLOW=1
done
fi
echo "$ALLOW $LIBNAME"
if [ $ALLOW = 1 ]; then
2021-11-24 00:19:56 -08:00
mkdir -p "$(dirname $LIBPATH)"
2023-06-22 03:15:32 -07:00
[ ! -f "$LIBPATH" ] && [ ! "$LIBURL" = null ] && echo $LIBURL '=>' "$LIBPATH" && wget $LIBURL -qO "$LIBPATH"
2023-06-18 17:36:20 -07:00
QNATIVE=`jq -r .libraries[$LIBINDEX].downloads.classifiers."\"natives-$PLAT\"" "$LIBJSON"`
2023-06-22 03:15:32 -07:00
# TODO linux centric
2023-06-17 00:11:54 -07:00
[ ! "$QNATIVE" = "null" ] &&
echo HAS NATIVE &&
2023-06-22 03:15:32 -07:00
LIBPATH="$MDIR/libraries/"`jq -r .libraries[$LIBINDEX].downloads.classifiers."\"natives-$PLAT\"".path "$LIBJSON"` &&
2023-06-18 17:36:20 -07:00
LIBURL=`jq -r .libraries[$LIBINDEX].downloads.classifiers.'"natives-linux"'.url "$LIBJSON"` &&
2023-06-17 00:11:54 -07:00
mkdir -p "$(dirname $LIBPATH)" &&
echo $LIBURL '=>' "$LIBPATH" &&
[ ! -f "$LIBPATH" ] && wget $LIBURL -qO "$LIBPATH" &&
2023-06-22 03:15:32 -07:00
unzip -o "$LIBPATH" -d "$CACHE/natives/$VERSION"
2023-06-18 17:36:20 -07:00
if [ ! "$LIBURL" = null ]; then
classpath="$classpath:$LIBPATH"
else
2023-06-22 03:15:32 -07:00
QNATIVE=''
[ ! "`jq -r \".libraries[$LIBINDEX].natives\" \"$LIBJSON\"`" = null ] && QNATIVE=`jq -r ".libraries[$LIBINDEX].natives.$PLAT" "$LIBJSON"`
shortdl `echo $LIBNAME | sed 's/:/ /g'` $QNATIVE
fi
2023-06-18 17:36:20 -07:00
fi
2021-11-24 00:19:56 -08:00
done
2023-06-18 17:36:20 -07:00
}
2023-06-22 03:15:32 -07:00
[ ! "$IVER" = null ] && fetchlib "$MDIR/versions/$IVER/$IVER.json"
2023-06-18 17:36:20 -07:00
fetchlib "$MDIR/versions/$VERSION/$VERSION.json"
2021-11-24 00:19:56 -08:00
2023-06-18 17:36:20 -07:00
library_directory="$MDIR/libraries"
classpath_separator=":"
2023-06-17 00:11:54 -07:00
natives_directory=$CACHE/natives/$VERSION
mkdir -p $natives_directory
version_name=$VERSION
assets_root="$MDIR/assets"
game_assets="$MDIR/assets"
[ "$rsrc" = 1 ] && game_assets="$MDIR/resources/$VIRTP"
2023-06-22 03:15:32 -07:00
[ $(date -d $(jq -r ".releaseTime" $VERJSON) +%s) -lt 1382454245 ] && game_assets="$MDIR/resources/$VIRTP"
2023-06-17 00:11:54 -07:00
#game_assets="$assets_root/virtual/pre-1.6" ???
2023-06-17 22:14:15 -07:00
assets_index_name=`jq -r .assetIndex.id "$VERJSON"`
version_type=`jq -r .type "$VERJSON"`
2023-06-17 00:11:54 -07:00
mkdir -p $CACHE/natives/$VERSION $game_directory
for i in `find "$MDIR/libs/$VERSION" | grep natives-$PLAT`; do unzip -o $i -d $CACHE/natives/$VERSION; done
2023-06-18 17:36:20 -07:00
jvm="-Xss1M -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M $jvm "`jq -r .arguments.jvm "$MDIR/versions/$VERSION/$VERSION.json" --indent 1 | grep -E '^ "' | sed 's/,$//' | xargs`
2023-06-22 03:15:32 -07:00
[ ! "$IVER" = null ] && jvm="$jvm "`jq -r .arguments.jvm "$MDIR/versions/$IVER/$IVER.json" --indent 1 | grep -E '^ "' | sed 's/,$//' | xargs`
2023-06-17 00:11:54 -07:00
# TODO determine correct java version for old release versions
JAVAV=$JAVA_LATEST
2023-06-22 03:15:32 -07:00
GAMEARGS=`jq -r .arguments.game "$MDIR/versions/$VERSION/$VERSION.json" --indent 1 | grep -E '^ "' | sed 's/,$//' | xargs`
[ ! "$IVER" = null ] && GAMEARGS="$GAMEARGS "`jq -r .arguments.game "$MDIR/versions/$IVER/$IVER.json" --indent 1 | grep -E '^ "' | sed 's/,$//' | xargs`
2023-06-17 00:11:54 -07:00
setleg() {
2023-06-17 22:14:15 -07:00
echo legacy version detected
2023-06-17 00:11:54 -07:00
JAVAV=$JAVA8
2023-06-22 03:15:32 -07:00
jvm="-Djava.library.path=${natives_directory}:$ -cp $classpath $jvm"
GAMEARGS=''
2023-06-17 00:11:54 -07:00
}
2023-06-22 03:15:32 -07:00
[ $(date -d $(jq -r ".releaseTime" $VERJSON) +%s) -lt 1505723986 ] && setleg
2023-06-17 00:11:54 -07:00
dbrun() {
2023-06-17 22:14:15 -07:00
echo $@ | sed 's/:/\n/g'
2023-06-17 00:11:54 -07:00
$@
}
cd $MDIR
eval dbrun $JAVAV \
$jvm \
2023-06-17 22:14:15 -07:00
`jq -r .mainClass "$VERJSON" --indent 1` \
`jq -r .minecraftArguments "$VERJSON" --indent 1 | sed 's/,$//' | xargs | sed "s/null//g"` \
$GAMEARGS $legacygame