summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 6cca855ae2e71631023b2822b85c8d34b5f4f850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
pkgname=gog-heroes-of-might-and-magic-3-complete-edition
pkgver=2.0.1.17
pkgrel=1
_gamename=${pkgname#gog-}
_gamename_=${_gamename//-/_}
_unpatchedver=2.0.0.16

pkgdesc="Heroes of Might & Magic III and its expansions: Armageddon's Blade and The Shadow of Death (with HD patch)"
arch=("i686" "x86_64")
url="https://www.gog.com/game/heroes_of_might_and_magic_3_complete_edition"
license=("custom")
groups=("games")

source=("setup_homm3_complete_${_unpatchedver}.exe::gogdownloader://${_gamename_}/en1installer1"
        "patch_${_gamename_%_edition}_${pkgver}.exe::gogdownloader://${_gamename_}/en1patch1"
        "https://sites.google.com/site/heroes3hd/files/HoMM3%20HD%20Latest.zip"
        "${_gamename}"
        "${_gamename}-map-editor"
        "${_gamename}-campaign-editor"
        "${pkgname}.install")
sha256sums=('d90bed0fd7e5338045f5f9983fdc7390297025ac1accdbc2f9bbec217a066468'
            '9c6ca90dacc621f0bb333a3f5fb6df8b06af2afee571beea14782c989177ff5a'
            '2b341cd4a0353bb988753ff8c13a8b40cb553dcb494451ed2c1cd6522ab5f4bd'
            '79d941eec1f590cd416b568b1b619ad7ed40230d3ddaf1cc7de1cb97ea9f1f4d'
            'bc5f57dd8fe1c4cb9bc4f144eea686a61ccc19e5020e446796f8f4c79014c8be'
            'f7b58168872ce04bfad2ef151632762d29735f3e165bc5c4cf887df68de62ed2'
            '6c6d7f19bcca181ee5c1c51c9f15e8d12d95e1feabcd676d1a41fc377f050d37')
depends=(wine)

# Register lgogdownloader as a download agent
DLAGENTS+=('gogdownloader::/usr/bin/lgogdownloader --download-file=%u -o %o')

# Must be a version > 2.24 after commit 5c9488f
makedepends=(lgogdownloader-git)

build() {
  export WINEDEBUG=-all
  export WINEPREFIX="$srcdir"/tmp/env
  export XDG_DATA_HOME="$srcdir"/tmp/local

  install -m755 -d "$srcdir"/tmp "$srcdir"/tmp/env "$srcdir"/tmp/local
  msg "Running GOG installer"
  wine "$srcdir"/setup_homm3_complete_${_unpatchedver}.exe /verysilent
  # Unfortunately, /verysilent doesn't prevent the installation is successful
  # messagebox from showing up and blocking. Manual intervention is required
  msg "Installing patches (don't launch game yet)"
  wine "${srcdir}"/patch_${_gamename_%_edition}_${pkgver}.exe /verysilent
  msg "Installing HD patch"
  wine "${srcdir}/HoMM3 HD 3.808f build 10.exe" /verysilent
  msg "Extracting HKEY_LOCAL_MACHINE registry"
  regedit -e ${srcdir}/local_machine.reg "HKEY_LOCAL_MACHINE\Software\New World Computing"
  sed -i 's,C:\\\\GOG Games\\\\Heroes of Might and Magic 3 Complete,Z:\\\\opt\\\\gog\\\\heroes-of-might-and-magic-3-complete-edition,g' local_machine.reg
}

package() {
  # Install registry configuration
  install -Dm644 ${srcdir}/local_machine.reg ${pkgdir}/usr/share/${pkgname}/local_machine.reg

  # Install license
  install -Dm644 "${srcdir}/tmp/env/drive_c/GOG Games/Heroes of Might and Magic 3 Complete/EULA.txt" "${pkgdir}"/usr/share/licenses/$pkgname/LICENSE

  # Install game
  install -m755 -d "${pkgdir}"/opt/gog/
  cp -r "${srcdir}/tmp/env/drive_c/GOG Games/Heroes of Might and Magic 3 Complete" ${pkgdir}/opt/gog/${pkgname#gog-}
  # Remove unneeded files
  rm -rf ${pkgdir}/opt/gog/${pkgname#gog-}/unins*
  rm -rf ${pkgdir}/opt/gog/${pkgname#gog-}/*.lnk
  # Give group write access to Data (to enable h3mmaped.exe)
  chown :games ${pkgdir}/opt/gog/${_gamename#gog-}/Data/*
  chmod g+w ${pkgdir}/opt/gog/${_gamename#gog-}/Data/*
  # Give group write access to HD3 launcher config
  for conf in _HD3_Data/HD3_Launcher.ini _HD3_Data/Settings/sod.ini
  do
    touch ${pkgdir}/opt/gog/${_gamename#gog-}/${conf}
    chown :games ${pkgdir}/opt/gog/${_gamename#gog-}/${conf}
    chmod g+w ${pkgdir}/opt/gog/${_gamename#gog-}/${conf}
  done
  
  # Install .desktop file and icons
  install -Dm644 "${srcdir}/tmp/local/applications/wine/Programs/GOG.com/Heroes of Might and Magic 3 Complete/Heroes of Might and Magic 3 Complete.desktop" ${pkgdir}/usr/share/applications/${_gamename}.desktop
  install -Dm644 "${srcdir}/tmp/local/applications/wine/Programs/GOG.com/Heroes of Might and Magic 3 Complete/Heroes 3 Map Editor.desktop"                  ${pkgdir}/usr/share/applications/${_gamename}-map-editor.desktop
  install -Dm644 "${srcdir}/tmp/local/applications/wine/Programs/GOG.com/Heroes of Might and Magic 3 Complete/Heroes 3 Campaign Editor.desktop"             ${pkgdir}/usr/share/applications/${_gamename}-campaign-editor.desktop
  for res in 16 32 48 256
  do
    install -Dm644 ${srcdir}/tmp/local/icons/hicolor/${res}x${res}/apps/3679_gfw_high.0.png ${pkgdir}/usr/share/icons/hicolor/${res}x${res}/apps/${_gamename}.png
  done
  for res in 16 32 48 64
  do
    install -Dm644 ${srcdir}/tmp/local/icons/hicolor/${res}x${res}/apps/0500_h3maped.0.png ${pkgdir}/usr/share/icons/hicolor/${res}x${res}/apps/${_gamename}-map-editor.png
    install -Dm644 ${srcdir}/tmp/local/icons/hicolor/${res}x${res}/apps/472F_h3ccmped.0.png ${pkgdir}/usr/share/icons/hicolor/${res}x${res}/apps/${_gamename}-campaign-editor.png
  done
  # Edit out wine jumbled entries from .desktop file
  for file in ${_gamename} ${_gamename}-map-editor ${_gamename}-campaign-editor
  do
    sed -i "/^Path=\|^Version=\|^Terminal=\|^Categories/d" ${pkgdir}/usr/share/applications/${file}.desktop
    sed -i "s,^\(Exec=\|Icon=\).*,\1${file}," ${pkgdir}/usr/share/applications/${file}.desktop
    printf "Version=${pkgver}\nTerminal=false\nCategories=Game;\n" >> ${pkgdir}/usr/share/applications/${file}.desktop
  done
  
  # Install startup scripts
  install -m755 -d ${pkgdir}/usr/bin
  for file in ${_gamename} ${_gamename}-map-editor ${_gamename}-campaign-editor
  do
    install -m755 ${srcdir}/${file} ${pkgdir}/usr/bin
  done
}

# vim:set ts=2 sw=2 et: