Skip to content

Instantly share code, notes, and snippets.

@shmerl
Last active September 5, 2025 05:33
Show Gist options
  • Save shmerl/202332219bebb5e5135ad41140f8f6d5 to your computer and use it in GitHub Desktop.
Save shmerl/202332219bebb5e5135ad41140f8f6d5 to your computer and use it in GitHub Desktop.
For extracting GOG Konami Collector's Series
#!/bin/bash
# Extractor for game ROMs from Konami Collector's Series.
#
# Usage: gog_extract_konami_collectors_series.sh <path_to>/cc.exe
#
# Make sure you have xxd hexdump tool and dd installed.
#
# ROM locations
#
# Note: ROM files didn't change between different GOG builds, but their location has.
#
# For galaxy build GOG v4 - 2025-07-15T17:22:10+0000 (Gen 2) (Build id: 58807482570125138)
# Everything shifted by 5120 bytes less compared to the old builds
#
# Castlevania : 01d170 - 03d16f (0x20000 bytes), starts as: 00010203040506070004a000be0007f01ea5ff29181d0780
# Castlevania II : 03d170 - 07d16f (0x40000 bytes), starts as: e931d8701d00e445b0e34037e475e3207087e492e34291e4
# Castlevania III: 07d170 - 0dd16f (0x60000 bytes), starts as: 80ac4e05b90f80854618690185476000040206a5320aa8b9
# Contra : 0dd170 - 0fd16f (0x20000 bytes), starts as: 00078068800081a9809d9805a9229d8805a9059d5803a540
# Jackal : 0fd180 - 11d17f (0x20000 bytes), starts as: 0001020304050607ad2901c934d009c6eed012a90985ee60
# Super C : 11d180 - 15d17f (0x40000 bytes), starts as: 30a90085728562a900a4cad0020901a4cbd0020902a88884
#
# For galaxy builds GOG v3 - 2021-02-03T06:48:56+0000 (Gen 2) (Build id: 54100975267659913) and older:
#
# Castlevania : 01e570 - 03e56f (0x20000 bytes) starts as: 00010203040506070004a000be0007f01ea5ff29181d0780
# Castlevania II : 03e570 - 07e56f (0x40000 bytes) starts as: e931d8701d00e445b0e34037e475e3207087e492e34291e4
# Castlevania III: 07e570 - 0de56f (0x60000 bytes) starts as: 80ac4e05b90f80854618690185476000040206a5320aa8b9
# Contra : 0de570 - 0fe56f (0x20000 bytes) starts as: 00078068800081a9809d9805a9229d8805a9059d5803a540
# Jackal : 0fe580 - 11e57f (0x20000 bytes) starts as: 0001020304050607ad2901c934d009c6eed012a90985ee60
# Super C : 11e580 - 15e57f (0x40000 bytes) starts as: 30a90085728562a900a4cad0020901a4cbd0020902a88884
# Expected md5sum of the produced functional ROMs:
#
# 1e1e452a83b23701119c70770cea10c9 castlevania.nes
# 4dda679420cc4067510501b238222330 castlevania_ii.nes
# 6284615b9e2125445e909c89df0dd71e castlevania_iii.nes
# 2686c4b168a7e82bdb2c6fb3061fcbfd contra.nes
# 8e29ebef55fcf1197e110b9247c9ec5d jackal.nes
# c951d1d48dc9811562cf46bcad26ca66 super_c.nes
header_hex1='4e45531a080021000000000000000000'
header_hex2='4e45531a081010000000000000000000'
header_hex3='4e45531a101050000000000000000000'
header_hex4='4e45531a081041000000000000000000'
source="$1"
if ! [ -e "$source" ]; then
echo "Error: can't find ${source}!"
exit 1
fi
declare -A roms
# old builds
#roms["castlevania"]="0x1e570:0x20000"
#roms["castlevania_ii"]="0x3e570:0x40000"
#roms["castlevania_iii"]="0x7e570:0x60000"
#roms["contra"]="0xde570:0x20000"
#roms["jackal"]="0xfe580:0x20000"
#roms["super_c"]="0x11e580:0x40000"
# new builds
roms["castlevania"]="0x1d170:0x20000"
roms["castlevania_ii"]="0x3d170:0x40000"
roms["castlevania_iii"]="0x7d170:0x60000"
roms["contra"]="0xdd170:0x20000"
roms["jackal"]="0xfd180:0x20000"
roms["super_c"]="0x11d180:0x40000"
declare -A headers
headers["castlevania"]=$header_hex1
headers["castlevania_ii"]=$header_hex2
headers["castlevania_iii"]=$header_hex3
headers["contra"]=$header_hex1
headers["jackal"]=$header_hex1
headers["super_c"]=$header_hex4
for rom in "${!roms[@]}"; do
offset=${roms[$rom]%%:*}
length=${roms[$rom]##*:}
target="${rom}.nes"
echo "Composing ${target}"
dd if="$source" of="${rom}.tmp" skip=$(($offset))B count=$(($length))B bs=10M
cat <(echo ${headers[$rom]} | xxd --revert --plain) "${rom}.tmp" > "$target"
rm -v "${rom}.tmp"
done
@shmerl
Copy link
Author

shmerl commented Aug 3, 2023

Speeding up dd usage with large block size and byte offest / count (that seems to be a poorly documented dd feature).

@shmerl
Copy link
Author

shmerl commented Sep 5, 2025

GOG uploaded a new build of with different cc.exe. note that you have to use an older build for now.

@shmerl
Copy link
Author

shmerl commented Sep 5, 2025

Updated the script to new build

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