Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bash script for Linux, mirroring functionality of package/ra2mdlauncher executable. #451

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package/Resources/Allied Theme/ExtrasWindow.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ForeColor=230,230,230
FontIndex=1
TextColorIdle=230,230,230
TextColorHover=255,255,255
UnixURL=ra2md-launcher.sh
URL=ra2mdlauncher.exe

[btnExCancel]
Expand Down
1 change: 1 addition & 0 deletions package/Resources/Soviet Theme/ExtrasWindow.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ForeColor=255,255,0
FontIndex=1
TextColorIdle=255,255,0
TextColorHover=255,255,0
UnixURL=ra2md-launcher.sh
URL=ra2mdlauncher.exe

[btnExCancel]
Expand Down
3 changes: 2 additions & 1 deletion package/Resources/YRLauncherUnix.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh

cd "$(dirname "$0")"
dotnet Resources/BinariesNET8/UniversalGL/clientogl.dll "$@"
chmod +x ra2md-launcher.sh
dotnet Resources/BinariesNET8/UniversalGL/clientogl.dll "$@"
1 change: 1 addition & 0 deletions package/Resources/Yuri Theme/ExtrasWindow.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ForeColor=255,255,0
FontIndex=1
TextColorIdle=255,255,0
TextColorHover=255,255,0
UnixURL=ra2md-launcher.sh
URL=ra2mdlauncher.exe

[btnExCancel]
Expand Down
3 changes: 2 additions & 1 deletion package/YRLauncherUnix.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh

cd "$(dirname "$0")"
dotnet Resources/BinariesNET8/UniversalGL/clientogl.dll "$@"
chmod +x ra2md-launcher.sh
dotnet Resources/BinariesNET8/UniversalGL/clientogl.dll "$@"
95 changes: 95 additions & 0 deletions package/ra2md-launcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion

Suggested change
set -euo pipefail

# This script checks if gamemd.exe is patched and launches the appropriate executable.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# Check if sha1sum is installed
if ! command -v sha1sum &> /dev/null; then
echo "Error: sha1sum is not installed. Please install it to use this script."
exit 1
fi

# Calculate the SHA-1 hash of a given file
calculate_sha1() {
sha1sum "$1" | awk '{ print $1 }'
}

# Get the size of a given file in bytes
get_file_size() {
stat -c%s "$1"
}

# Check if gamemd.exe is patched
is_patched() {
local gamemd_hash=$(calculate_sha1 "$1")
local gamemd_size=$(get_file_size "$1")
local steam_hash_v1="1b57b09d9912023eda3124b959d5f274e9a9bd5f"
local steam_hash_v2="f5ae9d38f1f628f8bc0c27b1be463c3f5c5d811b"
local cncfd_hash="6fdf606f9b08ee4c5813aed373953fa1c822e934"
local origin_hash="3ffb7cc1240164c4fc94d093fe5abe43691940ac"
local uncracked_retail_cd_hash="6314ca9a8254d70d6e38bf436da86b23b5345a91"
local PATCHED_GAMEMD_MINIMUM_SIZE=5000000

echo "Info: SHA-1 hash of gamemd.exe: $gamemd_hash."
echo "Info: Size of gamemd.exe: $gamemd_size bytes."

# Determine by hash
if [[ "$gamemd_hash" == "$steam_hash_v1" || "$gamemd_hash" == "$steam_hash_v2" ]]; then
echo "Info: gamemd.exe is patched."
return 0
elif [[ "$gamemd_hash" == "$cncfd_hash" || "$gamemd_hash" == "$origin_hash" || "$gamemd_hash" == "$uncracked_retail_cd_hash" ]]; then
echo "Info: gamemd.exe is unpatched."
return 1
fi

# If no hash matched, determine by file size.
if (( gamemd_size >= PATCHED_GAMEMD_MINIMUM_SIZE )); then
echo "Info: gamemd.exe is likely patched."
return 0
else
echo "Info: gamemd.exe is likely unpatched."
return 1
fi
}

app_path="$(dirname "$0")"
gamemd_path="$(find "$app_path" -iname "gamemd.exe" -print -quit)"
ra2md_path="$(find "$app_path" -iname "ra2md.exe" -print -quit)"

# Check if gamemd.exe is not found.
if [[ -z "$gamemd_path" ]]; then
echo "Error: gamemd.exe not found."
exit 2
fi

# Determine if gamemd is patched
is_patched "$gamemd_path"
is_patched_status=$?
Comment on lines +78 to +79
Copy link
Member

@SadPencil SadPencil Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion, in response to set -e

Suggested change
is_patched "$gamemd_path"
is_patched_status=$?
is_patched "$gamemd_path" && is_patched_status=0 || is_patched_status=$?


# Launch the appropriate executable
if [[ "$is_patched_status" -eq 0 ]]; then
echo "Info: Launching gamemd.exe."
exec "$gamemd_path" "$@"
else
# Check if ra2md.exe is not found
if [[ -z "$ra2md_path" ]]; then
echo "Warning: ra2md.exe not found."
echo "Info: Launching gamemd.exe anyway."
exec "$gamemd_path" "$@"
else
echo "Info: Launching ra2md.exe"
exec "$ra2md_path" "$@"
fi
fi
1 change: 1 addition & 0 deletions package/versionconfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ qres32.dll
ls800obs.shp
mplsobs.pal
ra2mdlauncher.exe
ra2md-launcher.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it better to make the file name consistent? I mean considering removing the hyphen

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it better to make the file name consistent? I mean considering removing the hyphen

I personally prefer having readable file names. 🤔


; Files (not directories) to be excluded from included files list.
; User-generated (settings etc), temporary and log files should be listed here.
Expand Down