--- /dev/null
+#!/bin/bash
+
+### Description
+#
+# This script replaces broken hardcoded strings in binary files (e.g. maps)
+# with another string given by the user.
+#
+# The input and ouput strings are given by the file passed as first argument,
+# which should be of the form:
+#
+# old string<TAB>new string
+# other old string<TAB>other new string
+# etc.
+#
+# The strings are fixed by binary replacements of their hex code. The hex
+# representation of a string starts with its length on four bytes, but in
+# this script we currently only fix the fourth byte (the others are typically
+# null), which means we support strings up to 255 chars.
+#
+# The binary files to fix are passed as second and optionally more arguments.
+#
+
+### Usage
+#
+# ./Misc/fix-hardcoded-hex-paths.sh [file describing fixes] [maps to fix]
+#
+# e.g.:
+#
+# ./Misc/fix-hardcoded-hex-paths.sh Misc/list-hardcoded-paths-fixes.txt Data/Maps/jendraz*
+#
+
+### Functions
+
+ascii2hex () {
+ local len=$(echo -n $1 | wc -c)
+ if [ $len -gt 255 ]; then echo "This poor script can't handle such long strings. Blame Akien."; exit 1; fi
+ len='\x'$(printf '%02x\n' $len)
+ local hexstring=$(echo -n $1 | xxd -ps | sed 's/[[:xdigit:]]\{2\}/\\x&/g')
+ # Seems xxd will put some separators on long strings
+ return=$len$(echo $hexstring | sed 's/ //g')
+ return
+}
+
+hex2ascii () {
+ local string=$(echo -n $1 | cut -c 4-)
+ return=$(echo $string | sed 's/\x//g' | xxd -r -ps)
+ return
+}
+
+### Script
+
+in_file="$1"
+target_files="${@:2}"
+
+if [ ! -e $in_file ]; then echo "You must pass a valid filename as argument, got $in_file."; exit 1; fi
+
+if [ -z "${target_files}" ]; then echo "You muss pass a list of files as second argument."; exit 1; fi
+
+echo -e "Replacing hardcoded strings as listed in $in_file in the following files:\n\n$target_files\n"
+
+while IFS='' read -r line || [[ -n "$line" ]]; do
+ input=$(echo "$line" | cut -f1)
+ output=$(echo "$line" | cut -f2)
+ echo "Replacing '${input}' by '${output}'."
+
+ ascii2hex "$input"
+ in_hex=$return
+ hex2ascii "$in_hex"
+ if [ "$return" != "$input" ]; then echo "Something went wrong in the conversion of $input back and forth to hex."; fi
+
+ ascii2hex "$output"
+ out_hex=$return
+ hex2ascii "$out_hex"
+ if [ "$return" != "$output" ]; then echo "Something went wrong in the conversion of $output back and forth to hex."; fi
+
+ for target_file in $target_files; do
+ sed -i 's/'${in_hex}'/'${out_hex}'/g' "${target_file}"
+ done
+done < "$in_file"
--- /dev/null
+:Data:Textures:all.png Textures/All.png
+:Data:Textures:armor.png Textures/LeatherArmor.png
+:Data:Textures:blackfur.png Textures/Fur2.jpg
+:Data:Textures:bloodapril.png Textures/BloodApril.png
+:Data:Textures:bloodclover.png Textures/BloodClover.png
+:Data:Textures:bloodjack.png Textures/BloodJack.png
+:Data:Textures:bloodtrixie.png Textures/BloodTrixie.png
+:Data:Textures:clfeng.png Textures/ClFeng.png
+:Data:Textures:clhuo.png Textures/ClHuo.png
+:Data:Textures:clshan.png Textures/ClShan.png
+:Data:Textures:clshui.png Textures/ClShui.png
+:Data:Textures:desertcl.png Textures/DesertCl.png
+:Data:Textures:earwrap.png Textures/EarWrap.png
+:Data:Textures:fancypantscamoarcitc.png Textures/FancyPantsCamoArctic.png
+:Data:Textures:fancypantscamoarctic.png Textures/FancyPantsCamoArctic.png
+:Data:Textures:fancypantscamoartic.png Textures/FancyPantsCamoArctic.png
+:Data:Textures:fancypantscamodesert.png Textures/FancyPantsCamoDesert.png
+:Data:Textures:fancypantscamo.png Textures/FancyPantsCamo.png
+:Data:Textures:fancypants.png Textures/FancyPants.png
+:Data:Textures:femaleshirt.png Textures/ShirtFemale.png
+:Data:Textures:fire.png Textures/Fire.jpg
+:Data:Textures:footwrap.png Textures:FootWrap.png
+:Data:Textures:furbw2.png Textures/FurBW.jpg
+:Data:Textures:furWB2.png Textures/FurBW.jpg
+:Data:Textures:furwhite.png Textures/Fur.jpg
+:Data:Textures:gibottom.png Textures/GiBottom.png
+:Data:Textures:gi.png Textures/Gi.png
+:Data:Textures:giteared.png Textures/GiTeared.png
+:Data:Textures:gitop.png Textures/GiTop.png
+:Data:Textures:headband.png Textures/HeadBand.png
+:Data:Textures:headban.png Textures/HeadBand.png
+:Data:Textures:leatherarmor.png Textures/LeatherArmor.png
+:Data:Textures:leatheraromr.png Textures/LeatherArmor.png
+:Data:Textures:leatherpants.png Textures/LeatherPants.png
+:Data:Textures:leatherwrapright.png Textures/LeatherWristRight.png
+:Data:Textures:leatherwristleft.png Textures/LeatherWristLeft.png
+:Data:Textures:leatherwristlet.png Textures/LeatherWristLeft.png
+:Data:Textures:leatherwristright.png Textures/LeatherWristRight.png
+:Data:Textures:lognsleeve.png Textures/LongSleeve.png
+:Data:Textures:longsleeve .png Textures/LongSleeve.png
+:Data:Textures:longsleeve.png Textures/LongSleeve.png
+:Data:Textures:lonsleeve.png Textures/LongSleeve.png
+:Data:Textures:mask.png Textures/Mask.png
+:Data:Textures:pants.png Textures/Pants.png
+:Data:Textures:shirtfemale.png Textures/ShirtFemale.png
+:Data:Textures:shirt.png Textures/Shirt.png
+:Data:Textures:shirts.png Textures/Shirt.png
+:Data:Textures:shrit.png Textures/Shirt.png
+:Data:Textures:whitefur.png Textures/Fur.jpg
+:Data:Textures:world.png Textures/World.png