Skip to content

Instantly share code, notes, and snippets.

@crcerror
Last active September 21, 2021 15:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crcerror/9e1742e78d50e58d585f3735dd67e855 to your computer and use it in GitHub Desktop.
Save crcerror/9e1742e78d50e58d585f3735dd67e855 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# This file is part of The RetroPie Project
#
# The RetroPie Project is the legal property of its developers, whose names are
# too numerous to list here. Please refer to the COPYRIGHT.md file distributed with this source.
#
# See the LICENSE.md file at the top-level directory of this distribution and
# at https://raw.githubusercontent.com/RetroPie/RetroPie-Setup/master/LICENSE.md
#
rp_module_id="ecwolf"
rp_module_desc="ECWolf - ECWolf is an advanced source port for Wolfenstein 3D, Spear of Destiny, and Super 3D Noah's Ark based off of the Wolf4SDL code base. It also supports mods from .pk3 files."
rp_module_licence="GPL2 https://bitbucket.org/ecwolf/ecwolf/raw/5065aaefe055bff5a8bb8396f7f2ca5f2e2cab27/docs/license-gpl.txt"
rp_module_help="For registered version, replace the shareware files by adding your full Wolf3d 1.4 version game files to $romdir/ports/wolf3d/."
rp_module_section="exp"
rp_module_flags=""
function depends_ecwolf() {
getDepends libsdl2-dev libsdl2-mixer-dev libsdl2-net-dev zlib1g-dev libsdl1.2-dev libsdl-mixer1.2-dev libsdl-net1.2-dev
}
function sources_ecwolf() {
downloadAndExtract "https://bitbucket.org/ecwolf/ecwolf/get/5065aaefe055.zip"
mv ecwolf-ecwolf-5065aaefe055 ecwolf
}
function build_ecwolf() {
cd ecwolf
#### Patch: better use applyPatch??
wget -N -q --show-progress https://raw.githubusercontent.com/crcerror/ECWolf-RPI/master/ecwolf_keyboardpatch.diff
patch -p0 -i ecwolf_keyboardpatch.diff
#### Patch: better use applyPatch??
cmake . -DCMAKE_BUILD_TYPE=Release -DGPL=ON
make
}
function install_ecwolf() {
md_ret_files=(
'ecwolf/ecwolf'
'ecwolf/ecwolf.pk3'
)
}
function game_data_ecwolf() {
if [[ -z $(ls "$romdir/ports/wolf3d") ]]; then
cd "$__tmpdir"
# Get shareware game data of Wolfenstein 3D and Spear of Destiny
downloadAndExtract "http://maniacsvault.net/ecwolf/files/shareware/wolf3d14.zip" "$romdir/ports/wolf3d"
downloadAndExtract "http://maniacsvault.net/ecwolf/files/shareware/soddemo.zip" "$romdir/ports/wolf3d"
fi
}
function _add_games_ecwolf(){
local ecw_bin="$1"
local ext path game
declare -A games=(
['wl1']="Wolfenstein 3D (demo)"
['wl6']="Wolfenstein 3D"
['sod']="Wolfenstein 3D - Spear of Destiny"
['sd1']="Wolfenstein 3D - Spear of Destiny"
['sdm']="Wolfenstein 3D - Spear of Destiny (demo)"
['n3d']="Wolfenstein 3D - Super Noah’s Ark 3D"
['sd2']="Wolfenstein 3D - SoD MP2 - Return to Danger"
['sd3']="Wolfenstein 3D - SoD MP3 - Ultimate Challenge"
)
pushd "$romdir/ports/wolf3d" #Needed for the find command! Do not remove!
for game in "${!games[@]}"; do
ecw=$(find . -iname "*.$game" -print -quit) #-print -quit finish after first hit
[[ -n "$ecw" ]] || continue # try next file extension
ext="${ecw##*.}" # Obtain extension in correct format
path="${ecw%/*}"; path="${path#*/}"
#Adding shell files
addPort "$md_id" "ecwolf" "${games[$game]}" "pushd $romdir/ports/wolf3d; bash %ROM%; popd" "$romdir/ports/wolf3d/${games[$game]}.ecwolf"
#Preparing .ecwolf files
_add_ecwolf_files_ecwolf "$romdir/ports/wolf3d/${games[$game]}.ecwolf" "$path" "$ext" "$ecw_bin"
done
popd
}
function _add_ecwolf_files_ecwolf() {
cat >"$1" <<_EOF_
cd "$2"
"$4" --data $3
wait \$!
_EOF_
}
function add_games_ecwolf() {
_add_games_ecwolf "$md_inst/ecwolf"
}
function configure_ecwolf() {
mkRomDir "ports/wolf3d"
moveConfigDir "$home/.local/share/ecwolf" "$md_conf_root/ecwolf"
moveConfigDir "$home/.config/ecwolf" "$md_conf_root/ecwolf"
# Check if some wolfenstein files are present and upload shareware files
[[ "$md_mode" == "install" ]] && game_data_ecwolf
# Configure present files
[[ "$md_mode" == "install" ]] && add_games_ecwolf
# Change permission of all files in wolf3d dir to std. user
chown -R $user:$user "$romdir/ports/wolf3d"
}
@tpo1990
Copy link

tpo1990 commented Aug 1, 2019

One thing we could make as an improvement to the scriptmodule, is that the scriptmodule will look into the wolf3d roms folder to see if it can find a vswap.wl6 and a vswap.sod file, if not then it will download and install the demo versions of Wolfenstein 3D and Spear of Destiny.

In order for a user to get the full version installed instead of the demo, they will need to put all the necessary .wl6 files into the wolf3d roms folder before installing ECWolf from the scriptmodule.

I just recently did this for Doom Legacy and Zandronum.

Example from my Doom Legacy scriptmodule.

function game_data_doomlegacy() {
    if [[ -f "$romdir/ports/doom/doom.wad" ]]; then
       chown $user:$user "$romdir/ports/doom/doom.wad"
       addPort "$md_id" "doom" "Doom" "DOOMWADDIR=$romdir/ports/doom $md_inst/bin/doomlegacy -iwad %ROM%" "$romdir/ports/doom/doom.wad"
    else wget "$__archive_url/doom1.wad" -O "$romdir/ports/doom/doom1.wad"
       chown $user:$user "$romdir/ports/doom/doom1.wad"
       addPort "$md_id" "doom" "Doom Shareware" "DOOMWADDIR=$romdir/ports/doom $md_inst/bin/doomlegacy -iwad %ROM%" "$romdir/ports/doom/doom1.wad"
    fi
}

One more improvement could be that we make it sure that the config folder will only be wolf3d and not ecwolf-wolf3d and ecwolf-spear3d, so that it shares the same config folder as wolf4sdl and splitwolf. I have already done this for Doom Legacy and Zandronum so that users will have the choice of selecting which source port to use as an emulator for Doom games.

@crcerror
Copy link
Author

crcerror commented Aug 1, 2019

No the [[ -f .... ]] is not flexible enough for Wolfenstein and it's mods.
I think it's better to use more flexible commands like find that can use regex and so on...

find . -iname SEARCHSTRING

is a really powerfull tool.

that it shares the same config folder as wolf4sdl and splitwolf.

This is not needed we can do a proper call to ecwolf binary.... I hope so ;)

EDIT: I'm nearly finished
I think we need the script to "translate" the files otherwise we need a emulator entry for every added port.

@crcerror
Copy link
Author

crcerror commented Aug 1, 2019

@tpo1990

One more improvement could be that we make it sure that the config folder will only be wolf3d and not ecwolf-wolf3d and ecwolf-spear3d, so

Done .... all files run with single config.

The emulator is configured like this now

  1. pushd $romdir/ports/wolf3d
  2. then execute correspondending ecwolf file with bash call
    2.1 changedir to dir were wolf3d files are located
    2.2 execute ecwolf binary with correct file extension (sod, SOD, WL1, wl1.....)
    2.3 wait as long as binary is active
    2.4 go back to ES if emu is finished

@tpo1990
Copy link

tpo1990 commented Aug 2, 2019

I think the reason why it is not flexible enough for ECWolf, is that the binary makes the call of which gamedata to load from (--data) etc. Wolfenstein 3D .wl1 or Spear of Destiny .sdm where the user has to use to choose between them. Also if mods need to be executed the right way it will need to make use of the --file switch. We must make sure that this can be done in a proper way.

For the patch this is what i have at the moment but it might need some adjustment in the code.

function build_ecwolf() {
    cd ecwolf-ecwolf-5065aaefe055
    wget https://raw.githubusercontent.com/crcerror/ECWolf-RPI/master/ecwolf_keyboardpatch.diff
    patch -p0 -i ecwolf_keyboardpatch.diff
    cmake . -DCMAKE_BUILD_TYPE=Release -DGPL=ON
    make
}

@crcerror
Copy link
Author

crcerror commented Aug 2, 2019

I think the reason why it is not flexible enough for ECWolf, is that the binary makes the call of which gamedata to load from (--data)

Yes this is very static here. So the idea is to use helper files like .ecwolf and set them up like bash commands and just treat them like this.
You see there is no really strong change in these ones, just the shebang is missing .... but we force the call with bash

cd datatowolffiles
/opt/retropie/ecwolf/ecwolf --parameters
wait $!

To be true... Wolf4SDL works in a similar way and used a script to determine which version was set. But I think it's better use one "emulator" setting like this

ecwolf="pushd /home/pi/RetroPie/roms/ports/wolf3d; bash %ROM%; popd"
default=ecwolf

The %ROM% will be called as last argument, and this is the .ecwolf file ;)
I think it's more generic and if you want to setup new addons like Astrostein then it's easier to modfiy the ecwolf-files than to "hack" an new setup into the emulators.cfg

What do you think?

EDIT: I use the format like you suggested but it would be better if you make the changes in your REPRO.
EDIT2: about the find -iname this is a regex call and will find all files, independent from upper or lower case, so we do not need to force upper/lowercase extraction
EDIT3: about the find -print -quit this will search for only first hit of file and you can work with stdoutput witout using IFS command

@crcerror
Copy link
Author

crcerror commented Aug 2, 2019

---> Working now!

@tpo1990
Copy link

tpo1990 commented Aug 5, 2019

I think the %ROM% argument is a nice addition to the scriptmodule and to get it to just call the .ecwolf file sounds like it will provide a better use in loading mods or other wolf3d styled games.

One thing that i do want to make sure, is that you will keep the .ecwolf files during reinstalling or updating ECWolf so that you won't lose your configuration for loading the mods. Before i began looking into scriptmodules for RetroPie, i manually created runcommand files for loading other data for source port like Quake3 and when updating or reinstalling the source port it would just remove and make those runcommand files not work anymore. I want to prevent this.

Another thing is that i don't want to leave a mess with many runcommand.sh files. What i do prefer is to make it more streamlined, meaning only one runcommand.sh file per game/port and then be able to select which source port to use as the emulator.
ex. When running Doom or Doom 2 Hell on Earth, you can select either ZDoom or Doom Legacy as the emulator in the runcommand menu just like any other system in RetroPie. I'm not sure if this will be possible for ECWolf, if you want to make use of the .ecwolf files.

It would look like this in the ports section in Emulationstation:

PORTS

  • Doom
  • Doom II: Hell on Earth
  • Final Doom: TNT Evilution
  • Final Doom: Plutonia
  • Quake
  • Quake 2
  • Quake 3 Arena
  • Quake 3 Team Arena
  • Wolfenstein 3D
  • Wolfenstein 3D: Spear of Destiny.

Instead of this mess.

PORTS

  • Doom Legacy Doom
  • ZDoom Doom
  • lr-prboom Doom
  • Doom II: Hell on Earth
  • Final Doom: TNT Evilution
  • Final Doom: Plutonia
  • Darkplaces Quake
  • Tyrquake Quake
  • Quake 2
  • Quake 3 Arena
  • Quake 3 Team Arena
  • Wolfenstein 3D
  • Wolfenstein 3D Demo
  • EC Wolf Wolfenstein 3D
  • Wolfenstein 3D: Spear of Destiny.
  • EC Wolf Spear of Destiny
  • Spear of Destiny Demo

@tpo1990
Copy link

tpo1990 commented Aug 5, 2019

EDIT: I use the format like you suggested but it would be better if you make the changes in your REPRO.
EDIT2: about the find -iname this is a regex call and will find all files, independent from upper or lower case, so we do not need to force upper/lowercase extraction
EDIT3: about the find -print -quit this will search for only first hit of file and you can work with stdoutput witout using IFS command

The find command with the -iname switch is a nice way of making the binary ignore upper/lowercase limitation for the data files. Doesn't Wolf4SDL use this as well?

The more coding we can leave out to minimize the scriptmodule, the better it will be optimized in the end.

I still think there is work to be done in order to keep the scriptmodule within line of the RetroPie projects guidelines for scriptmodules.

Good work, i will test your changes later as i do not have the option to test it out right now on my RPI 3B.

@crcerror
Copy link
Author

crcerror commented Aug 5, 2019

I think there is no easy way to avoid bash script calls.
I usually use dialog bash scripts to avoid a mess in ports sections but I think most people don't like this way.
So I think to create a new file for every discovered mod or episode is a common way in RetroPie because it's more easy to maintain off the regualr usecase. Other things like unifying calls with just one emulators.cfg can be done by the more advanced user.

@tpo1990
Copy link

tpo1990 commented Aug 7, 2019

Apparently not. I'm not sure about what the majority of users in the RetroPie community thinks about dialog bash scripts, as i can not say from personal experience yet.

You're probably right, since other topics about the different ports existing in RetroPie community suggest in adding mods or other levels.

Now on developing ecwolf, i did try out your newly updated ecwolf scriptmodule, but it failed to install caused by the url
of ecwolf source file (ecwolf-ecwolf-5065aaefe055.zip) not existing anymore on the download page of the bitbucket repo.

I tried out a different approach with making the scriptmodule download and compile the ecwolf 1.3.3 release but that means that your patch file fails at applying changes for the keyboard escape fix.

This is the approach of the ecwolf 1.3.3 that i have made into your modified ecwolf scriptmodule and it works but no keyboard escape fix applied.

function sources_ecwolf() {
        downloadAndExtract "http://maniacsvault.net/ecwolf/files/ecwolf/1.x/ecwolf-1.3.3-src.tar.xz" .
}

function build_ecwolf() {
    cd ecwolf-1.3.3-src
    #### Patch: better use applyPatch??
    wget -N -q --show-progress https://raw.githubusercontent.com/crcerror/ECWolf-RPI/master/ecwolf_keyboardpatch.diff
    patch -p0 -i ecwolf_keyboardpatch.diff
    #### Patch: better use applyPatch??
    cmake . -DCMAKE_BUILD_TYPE=Release -DGPL=ON
    make
}

function install_ecwolf() {
    md_ret_files=(
       'ecwolf-1.3.3-src/ecwolf'
       'ecwolf-1.3.3-src/ecwolf.pk3'
    )
}

If you look at the ecwolf bitbucket repo, the download url has changed to ecwolf-ecwolf-8741fe02ce8b. I think the reason why this has happend, is because of nightly builds that gets changed over time breaking the install of the source port.

@tpo1990
Copy link

tpo1990 commented Aug 7, 2019

Because of the nightly build breaking the install, i think it is better to point the url at https://bitbucket.org/ecwolf/ecwolf, so that when every time a new nightly release rolls out, it will not affect the install of the ECWolf.

If we somehow can get the wget or downloadAndExtract from the helpers file to work with the url, we can leave out mercurial and the need for hg clone.

This is from my first ecwolf scriptmodule that i released, still found in my git repo.
``
function sources_ecwolf() {
hg clone https://bitbucket.org/ecwolf/ecwolf
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment