Wednesday, January 20, 2021

Case study: Heroes of Might and Magic III on Pi [VCMI]

🕐🕐🕐🕐 Duration: Days
🔧🔧🔧🔧 Difficulty: Difficult
🌟🌟🌟🌟 Interest: Hours of fun

Gals and Guys, it doesn't look like so, but this one is going to be a challenge.

When you try to run Heroes of Might and Magic III (HoMM3) on Raspberry Pi, you will first think it is a success: it starts fine with Box86, it even starts on chroot if you remove sound.

It stops there. You will start a game, play 2 or 3 turns, then it will crashexit, no matter if ran under Box86 or QEMU.

Are there any solutions?

There is only one proved working solution, it is VCMI-arm with its set of libs (some version of Raspberry Pi OS libraries make VCMI crash. It is not a VCMI problem!)

VCMI-arm, the working solution

 

working vcmi on raspberry pi 3B+
VCMI-arm working on PI3B+

 
This solution is very tricky, if you don't know what you are doing, you will end frustrated, thinking you failed, while you actually have a perfectly running build.
 
After compiling, it is possible that your installation gives you the end of battle crash bug. What you have to know is that it is not a VCMI bug. it is an incompatibility between some version of your libraries and VCMI. So, don't give up hope if you get this bug! Instead, work on your /usr/lib/arm-linux-gnueabihf/ installation.

It means that VCMI can work on Raspberry Pi, and after a lot of searching, I finally found out that the set of linux libraries is responsible for bugs happening.
 
 
vcmi library list raspberry pi 3B+
The list of VCMI needed libraries.
Make sure you get a compatible set of them.

 
So this basically means: if you compile your VCMI binaries and get a bug at some point (for example when you win or retreat from a battle), you should first try your VCMI runnable on all your Pi OS before dumping your hard-gained compilation. 

I have been able to figure out that TwisterOS 1.9.0 is the best starting solution to try to get a compiled VCMI-arm working.
 
If you want to avoid compiling at all, you can try my portable installation of VCMI. Keep in mind that it is compiled for Buster and Pi 3B+. It might not work on other systems; but it is always worth trying before you try to compile it yourself.
 
For the runtime libraries, the most secure solution if you are on Raspberry Pi OS 32 bits Buster is to use the libs from my portable VCMI version.

vcmi rid of end of battle bug
No more end-of-battle bug

 

Compiling VCMI on ARM

Keep in mind

  • Don't worry about libraries you are getting while compiling. Compilator uses header files (.h) and leaves static libraries (like libSDL2) as known and supplied by system. You will have to worry about library versions when running the game.
  • It is somewhat advised to compile your binaries on a cloned Buster instead of your main games OS. Installing dependencies, compiling, removing dependencies are a punishment for your OS and there are chances you will regularly have to reinstall your OS if you compile a lot. This can be a pain if you installed a nice theme and like your OS settings.

Check the official website for the general guidelines about compiling VCMI

Compiling VCMI is probably one of the most resource demanding processes in the game playing family on Raspberry Pi.
 
Let's face the figures: on a Raspberry Pi 3B+, duration of the compilation is more or less 3 days. Expect something slightly lower on a Pi 4 (maybe optimized Pi 4 can compile in 1~1.5 days).

You will potentially have memory issues. Make sure you have enough room on your device and check /etc/dphys-swapfile and replace:

CONF_SWAPSIZE=100

By 

CONF_SWAPSIZE=1024

Or more than 1024 if you have enough space on your SD card.

Getting fuzzylite dependency

It is noticeable that VCMI lacks fuzzylite for the time being. Some VCMI sources also need to receive a minizip source:

cd /path/to/vcmi/source/AI
git clone https://github.com/fuzzylite/fuzzylite
mv fuzzylite Fuzzylite
(do not forget that or cmake will fail to find it)
 
You are then ready to:
 
mkdir build
cd build
cmake /path/to/vcmi/source
 
This takes more or less one minute.
 
Before doing "make", a few attention points:
  • Make sure you are doing it from a device with enough space. I would say an external USB key with 10 GB free would be enough.
  • Make sure you increased your /etc/dphys-swapfile/ as much as you can do (see above).
  • It is better to leave xwindow with CTRL+ALT+F1 or CTRL+ALT+Fn+F1 because the stdout will bloat your terminal window and make your window manager freeze.
 
Then:
make -j1
 
make -j1 should take between 1 and 5 days so be patient. make -j2 or more threads will Swap your Pi to the Death.

Do not worry. VCMI final binaries do only 400~600 MB. You can leave all the .o's to the dump.  

Once you started make -j1, you can turn your screen off and start doing something else than tinkering your Pi for a few days. Come back every 4-5 hours to check progress and check if you don't have to restart out of crashing.

Interesting information: you won't lose the work of make by interrupting compilation with Ctrl+C.

Be very patient with CGameState.cpp.o which is the longest object to compile, it takes more or less one whole day to make.

After the battle

Finally, don't forget to create your /home/pi/.local/share/vcmi/ which will hold your HoMM3 data files. use vcmibuilder for that (vcmibuilder --help is a good start)
If you are short of space on your SD card, move the contents to your USB key or your USB external hard drive afterwards and link them to /home/pi/.local/share/vcmi/ with: 
 
sudo mount -B /path/to/your/displaced/heroes/data /home/pi/.local/share/vcmi/

Run your VCMI install through ./vcmiclient or if you linked to portable libs ./start_vcmi_portable.sh
 
Check if it works by starting a game, going to an easy battle, winning it, restarting another game, going to any battle, retreating.

Vcmilauncher

Vcmilauncher doesn't immediately start with the portable installation. You will need to install Qt5. I haven't put Qt5 in portable libraries because it needs a plugin installation and these must be through apt-get install
 
Since vcmilauncher is only a tool, it won't prevent you from playing. I personally do not bloat my lean OS with Qt5.

If you want to set VCMI full screen without installing Qt5, it can be done by modifying /home/pi/.config/vcmi/settings.json 
 
{
"video': {                    
 "fullscreen" : true         
} 
}
 

Freeing SD card space after compilation

Junk all that is not /vcmi-build/bin/ and inside bin, you can safely remove vcmitest 
 
You might want to replace all your -dev downloaded packages by simple runtime libraries, I would advise you to first test the end of battle and if it works, just make a /lib/ directory with the hereabove mentioned libraries. Then you can fully uninstall development libraries. Remember that toying with your libraries might give you the end of battle bug.

Current flaw of VCMI

Currently VCMI is not a perfect HoMM3 rewrite. 

  • There is no high score board on VCMI, bye bye the "black dragon" rank 😢
However, the feeling of 6 rl-months long games with 4000 black dragons is back on our Pi. And that is a great thing!

The dead ideas

Some other tracks can also be used to run HoMM3.
 
Actually HoMM3 runs, so the goal is to make it stop crashing. 
 
It's not exclusively linked to Box86/Wine. Actually Windows 10 shows problems with HoMM3, and it does not seem to get better because it is a problem in HoMM3 itself that is said not supporting multi-cpu.
 
However, running it with taskset -c 0 does not improve the situation, giving the hint that HoMM3 has a problem in memory adressing in top of multi-cpu handling. 

After some research I have noticed that replacing MSS32.DLL in the game directory by another version (newer or older) will sometimes give you a few extra turns before it crashes, sometimes freezes instead of crashing. There must be something wrong with MSS32.DLL but so far, I haven't got any working DLL. 

From these statements, adding any layer (like HD MOD, HotA, or even GL4ES driver) will not solve the crashing problem. It is the same with box86: removing dynarec does not change Heroes of Might and Magic 3 crashing. 

This leaves 2 other solutions open:
- VCMI-x86-linux has not succeeded working yet but might in the future, when ptitSeb will have improved his box86. Stay tuned here. Since you can get a native version working, it would only mean buying time installing binaries directly from repository. Be aware that ARM native version will work better anyways.
- VCMI-x86-windows crashes earlier than VCMI-x86-linux, in chroot and in Box86. It is kinda the last resort to make a double emulated program run when all the others failed. It should not seriously be followed. 

Conclusion

The VCMI route, especially ARM compiled, seems to be the only one to hold promises.

Although much slower and effort demanding, VCMI is the only way to play Heroes of Might and Magic 3 on Raspberry Pi. 
 
Be very cautious on the versions of the libraries you are using to get it to run (they are sometimes different from compilation libraries) or you might think you have lost your time...while you actually have built a working version! 
 
If you have a doubt, use my set of libraries or get the equivalent version for your Linux distribution.

Compiling VCMI is a long and perillous enterprise but have faith in yourself and you will eventually get it working!

The pi gamer

Disclaimer: make sure you own the right to play a game before installing it on your Pi

4 comments:

  1. Thanks a lot for your tutorial and the VCMI build. It works well with retropie on Rpi4.
    I just take some time to understand how to do music works (create a repository Mp3 instead of Music and put into it the music files in OGG format with the extension).
    Nice job, keep going.

    ReplyDelete
    Replies
    1. Hello,
      Thanks for your feedback.
      I would be genuinely interested if you explained to me what made you lose time. Since you are referring to mp3 could it be related to the use of vcmibuilder (which actually prepares vcmi data folder)?

      Delete
  2. I've the official Macintosh version of HoMM III. So I copied my Data folder, Music folder and Maps folder in the vcmi repository but if the sounds were played, I had no music. Tracks for MacOS version are encoded in AIFF and in the vcmi log, I read a line about a music file not found (but it was present in the Music folder with the right name) and that the mp3 file format wasn't correct. So I tried to convert the files in mp3 but it didn't work. So I search on Internet the solution to discover that vcmi read musics file in the Mp3 folder and not the orginal Music folder and that the mp3 format is used only(?) for the windows port of vcmi. For unix/linux (and mac) port, the OGG format is used. I didn't use the vcmibuilder beacause the script only encode in OGG the MP3 files and MacOS files are in AIFF. I do this manually. So now in my vcmi repository on my Retropie, I have :
    - Data
    - Maps
    - Mp3 (with all music files in OGG named .ogg)
    And now all works well with my "Complete" Mac version of Heroes of Might & Magic III (I love this game).

    PS: If it's not understandable, sorry for my bad english.

    ReplyDelete
    Replies
    1. That is indeed annoying that vcmibuilder doesn't work with macos version :-(. Thank you for your comment!

      Delete

Play ET: Legacy on Raspberry Pi [FPS]

🕐🕐 Duration: A few hours 🔧 Difficulty: Easy 🌟🌟🌟🌟 Interest: Hours of fun