Files
AM2R-Autopatcher-Android/patcher.sh
T

131 lines
3.9 KiB
Bash
Raw Normal View History

2021-11-11 11:26:14 +01:00
#!/bin/bash
2021-11-11 10:29:28 +01:00
2024-03-17 10:27:36 -04:00
# Exit on any error to avoid showing everything was successful even though it wasn't
2021-11-11 10:29:28 +01:00
set -e
2021-08-29 16:00:09 -05:00
VERSION="15_5"
2024-03-17 10:02:29 -04:00
OUTPUT="am2r_${VERSION}"
2024-03-17 10:08:52 -04:00
PATCH_FOLDER="data"
2021-07-14 21:58:44 +02:00
2024-03-17 10:27:36 -04:00
# Cleanup previous directories and files
2024-03-17 10:02:29 -04:00
cleanup_directories() {
2024-03-17 10:27:36 -04:00
local directories=("assets" "AM2RWrapper" "data" "HDR_HQ_in-game_music" "data.zip" "HDR_HQ_in-game_music.zip")
2024-03-17 10:02:29 -04:00
for dir in "${directories[@]}"; do
2024-03-17 10:27:36 -04:00
if [ -d "$dir" ] || [ -f "$dir" ]; then
2024-03-17 10:02:29 -04:00
rm -rf "$dir"
fi
done
}
2021-07-14 21:58:44 +02:00
2024-03-17 10:27:36 -04:00
cleanup_directories
2021-07-14 21:58:44 +02:00
echo "-------------------------------------------"
echo ""
2021-11-11 10:29:28 +01:00
echo "AM2R 1.5.5 Shell Autopatching Utility"
echo "Originally Scripted by Miepee and help from Lojemiru"
echo "Updated by izzy2fancy"
2021-07-14 21:58:44 +02:00
echo ""
echo "-------------------------------------------"
2024-03-17 10:02:29 -04:00
# Install dependencies
# Assuming you're on a Termux environment
2024-02-05 07:03:36 -05:00
yes | pkg install termux-am zip unzip xdelta3
yes | termux-setup-storage
2021-07-14 21:58:44 +02:00
2024-03-17 10:27:36 -04:00
# Check if apkmod is installed, if not install it. I only use this for signing 'cause it's the only way I found this to work
2021-07-15 10:41:44 +02:00
if ! [ -f /data/data/com.termux/files/usr/bin/apkmod ]; then
wget https://raw.githubusercontent.com/Hax4us/Apkmod/master/setup.sh
2022-03-12 18:01:53 +01:00
bash setup.sh
2021-07-15 10:41:44 +02:00
rm -f setup.sh
fi
2024-04-02 17:23:15 -04:00
# Download Data.zip
wget https://github.com/izzy2fancy/AM2R-Autopatcher-Android/releases/download/1.0/data.zip
yes | unzip data.zip -d ./
2024-03-19 16:35:56 -04:00
2024-03-17 10:27:36 -04:00
# Check for AM2R_11.zip in downloads
2024-03-17 09:43:47 -04:00
if [ -f ~/storage/downloads/AM2R_11.zip ]; then
echo "AM2R_11.zip found! Extracting to ${OUTPUT}"
2024-03-17 10:27:36 -04:00
# Extract the content to the am2r_xx folder
2024-03-17 09:43:47 -04:00
unzip -q ~/storage/downloads/AM2R_11.zip -d "${OUTPUT}"
else
2021-07-15 12:02:20 +02:00
echo -e "\033[0;31mAM2R_11 not found. Place AM2R_11.zip (case sensitive) into your Downloads folder and try again."
echo -e "\033[1;37m"
2021-07-14 21:58:44 +02:00
exit -1
fi
echo "Applying Android patch..."
2024-03-17 10:27:36 -04:00
xdelta3 -dfs "${OUTPUT}"/data.win data/droid.xdelta "${OUTPUT}"/game.droid
2021-07-14 21:58:44 +02:00
2024-03-17 10:27:36 -04:00
# Delete unnecessary files
2024-03-17 09:43:47 -04:00
rm "${OUTPUT}"/D3DX9_43.dll "${OUTPUT}"/AM2R.exe "${OUTPUT}"/data.win
2021-07-14 21:58:44 +02:00
2024-03-17 09:43:47 -04:00
if [ -f data/android/AM2R.ini ]; then
cp -p data/android/AM2R.ini "${OUTPUT}"/
2021-11-11 11:12:23 +01:00
fi
2021-07-14 21:58:44 +02:00
# Music
2024-03-17 09:43:47 -04:00
cp data/files_to_copy/*.ogg "${OUTPUT}"/
2021-07-14 21:58:44 +02:00
echo ""
2021-07-15 11:47:58 +02:00
echo -e "\033[0;32mInstall high quality in-game music? Increases filesize by 230 MB and may lag the game\!"
2021-07-15 12:02:20 +02:00
echo -e "\033[1;37m"
2021-07-14 21:58:44 +02:00
echo "[y/n]"
read -n1 INPUT
echo ""
2023-06-04 23:32:41 +02:00
if [ "$INPUT" = "y" ]; then
2021-07-14 21:58:44 +02:00
echo "Downloading HQ music..."
2024-03-17 09:43:47 -04:00
wget https://github.com/izzy2fancy/AM2R-Autopatcher-Android/releases/download/2.0/HDR_HQ_in-game_music.zip
2024-03-17 10:27:36 -04:00
yes | unzip HDR_HQ_in-game_music.zip -d ./
2024-02-05 08:49:49 -05:00
echo "Copying HQ music..."
2024-03-17 09:43:47 -04:00
cp -f HDR_HQ_in-game_music/*.ogg "${OUTPUT}"/
rm -rf HDR_HQ_in-game_music/
2021-07-14 21:58:44 +02:00
fi
2021-07-15 12:02:20 +02:00
echo "Updating lang folder..."
2024-03-17 10:27:36 -04:00
# Remove old lang
2024-03-17 09:43:47 -04:00
rm -R "${OUTPUT}"/lang/
2024-03-17 10:27:36 -04:00
# Install new lang
2024-03-17 09:43:47 -04:00
cp -RTp data/files_to_copy/lang/ "${OUTPUT}"/lang/
2021-07-14 21:58:44 +02:00
2021-07-15 12:02:20 +02:00
echo "Renaming music to lowercase..."
2024-03-17 10:27:36 -04:00
# Zip them without compression and extracting them as all lowercase
# Music needs to be all lowercase
2021-07-14 21:58:44 +02:00
zip -0qr temp.zip "${OUTPUT}"/*.ogg
rm "${OUTPUT}"/*.ogg
unzip -qLL temp.zip
rm temp.zip
echo "Packaging APK..."
2024-03-17 10:27:36 -04:00
# Decompile the apk
2024-03-17 09:43:47 -04:00
apkmod -d -i data/android/AM2RWrapper.apk -o AM2RWrapper
2024-03-17 10:27:36 -04:00
# Copy
2024-03-17 09:43:47 -04:00
mv "${OUTPUT}" assets
2021-07-14 21:58:44 +02:00
cp -Rp assets AM2RWrapper
2024-03-17 10:27:36 -04:00
# Edited yaml thing to not compress ogg's
2024-03-17 09:43:47 -04:00
echo "Editing apktool.yml..."
2021-07-15 11:08:22 +02:00
sed -i "s/doNotCompress:/doNotCompress:\n- ogg/" AM2RWrapper/apktool.yml
2024-03-17 10:27:36 -04:00
# Build
# Check if aapt2 exists, if not use aapt instead
if [ -f /usr/bin/aapt2 ]; then
2024-03-17 10:27:36 -04:00
apkmod -r -i AM2RWrapper -o "AM2R-${VERSION}.apk"
else
2024-03-17 10:27:36 -04:00
apkmod -a -r -i AM2RWrapper -o "AM2R-${VERSION}.apk"
fi
2024-03-17 10:27:36 -04:00
# Sign apk
apkmod -s -i "AM2R-${VERSION}.apk" -o "AM2R-${VERSION}-signed.apk"
2021-07-14 21:58:44 +02:00
2024-03-17 09:43:47 -04:00
# Cleanup
2024-03-17 10:27:36 -04:00
rm -R assets/ AM2RWrapper/ data/ "AM2R-${VERSION}.apk"
2024-03-17 09:43:47 -04:00
# Move signed APK
2024-03-17 10:27:36 -04:00
mv "AM2R-${VERSION}-signed.apk" ~/storage/downloads/AM2R-"${VERSION}"-signed.apk
2021-07-15 10:41:44 +02:00
echo ""
2024-03-17 09:43:47 -04:00
echo -e "\033[0;32mThe operation was completed successfully and the APK can be found in your Downloads folder as \"AM2R-${VERSION}-signed.apk\"."
2021-07-15 11:47:58 +02:00
echo -e "\033[0;32mSee you next mission\!"
2021-07-15 12:02:20 +02:00
echo -e "\033[1;37m"
2024-03-17 09:43:47 -04:00
xdg-open ~/storage/downloads/AM2R-"${VERSION}"-signed.apk