Map Database  •  FAQ  •  RSS  •  Register  •  Login

Decompiled TPR and fixed it up



User avatar

King Karolus

Posts: 1233

Joined: 01 May 2006, 22:00

Location: Finland

Post 23 Dec 2020, 10:55

Decompiled TPR and fixed it up

Well, it's been a long time since I last visited this place. Needless to say I'm quite out of touch with the current state of the KaM community. Nice to see that this place is still alive. I just want to start by thanking T*AnTi-V!RuZz for all his hard work during the past years and wish the new administration team the best of luck!

Anyway, I briefly delved into x86 assembly some years ago and then started decompiling The Peasants Rebellion as a personal curiosity and as an opportunity to learn a bit more about x86 assembly. Initially I did not expect to achieve much at all, but eventually I had managed to decompile large parts of the game logic. Then I figured why not try fixing many of the bugs that were still present in the latest version of the game. To date, I would say that I have managed to figure out about 90% of the game logic. This has allowed me to fix major issues with the original game such as the infamous "drunk soldiers" bug and various bugs plaguing the build-up AI and a lot of less severe bugs. I also added some new features such as windowed mode support.

I do realize that the original game is pretty much obsolete due to the KaM Remake, but I really did this as a personal project to learn assembly and to see if I could fulfill my "childhood dream" of a bug free TPR and figured maybe someone still likes playing the original.

Some of the more notable changes:
- Fixed drunk soldiers bug
- Fixed various issues with the town hall (e.g. sleepy soldiers, buttons not working properly...)
- Fixed build-up AI not working after saving/loading; getting stuck in various situations; minor improvements to build-up logic
- Added windowed mode support (toggleable by pressing Alt+Enter)
- Removed the limit of max 3 construction sites getting their wares delivered
- Fixed various bugs which made archers unable to fire at their target
- Fixed melee soldiers sometimes freezing next to enemies instead of instantly engaging in battle
- The AI now knows how to use town halls and siege workshops
- Expanded statistics to have separate military and economy statistics
- Added battle tutorial to main menu
- Nicer saved game names, no longer plagued with magic numbers
- Serfs no longer drop their current resource when walking over a construction site
- Improved sound effect and music quality; sound mixing rate increased from 22050 Hz to 44100 Hz and music now has a higher bitrate

Here is a pretty complete changelog.

Download (242 mb)

This patch is in English only, but the patch can be applied on top of any language version of the game resulting in an English game.


User avatar

Knights Province Developer

Posts: 3266

Joined: 09 May 2006, 22:00

Location: Russia

KaM Skill Level: Fair

Post 23 Dec 2020, 17:13

Re: Decompiled TPR and fixed it up

Wow! That was unexpected! :-)

Full changelist is jaw-dropping .. how did you do it all by yourself in secrecy?

I'd love to read the story behind it - how you worked on it, figured things out, applied patches and so on.

P.S. Linked this on KaM Remake Discord server:
Knights Province at:
KaM Remake at:
Original MBWR/WR2/AFC/FVR tools at:


User avatar


Posts: 435

Joined: 04 Aug 2013, 19:59

Location: United States

KaM Skill Level: Expert

Post 24 Dec 2020, 17:35

Re: Decompiled TPR and fixed it up

Wow, that's one heck of a patch!

Below are some of the fixes/improvements that caught my attention upon reading the list for the first time (I would have went out of my way to list more, but it's been so long since I played the original TPR that I couldn't possibly enumerate everything wrong with it):

  • Serfs no longer lose the resource they are carrying when walking across a building construction site, known as the "slippery serf hands" bug
  • Fisherman now stops working and an expiration message is sent when a lake runs out of fish
  • Fixed Fish not being fed to soldiers
  • Idle units will now also show starving thoughts when very hungry
  • Fixed potential overflow bug that could cause stuttering attack animations when attacking buildings
  • Fixed creating a barbarian at the town hall counting as creating a warrior
  • Fixed attacking with bowmen sometimes not working when the enemy was moving resulting in the bowmen walking to the destination instead
  • AI bowmen should now be slightly better at using their bowmen to attack instead of walking into their enemy when attacking and when doing "defensive attacking"
  • Better names for saved games, tells which campaign/tutorial or single scenario is in the save
  • Fixed archers being unable to fire at their target sometimes preventing other archers from firing at their target (if an archer in a troop was unable to fire, all archers with a higher index would also be unable to fire)

What would you like to call this? I would like to add it to the KaM speedrun page!


If this thread doesn't bring back TDL to these forums, nothing will! :D
Invasion won: with 0 losses and without save reloads|TSK 20 in 4.47 minutes|Northern Islands I Co-op in 1.71 hours|||NEW! The Official KaM Speedrun Page
What makes me an Expert isn't my skill in of itself but my desire to win big.


User avatar

King Karolus

Posts: 1233

Joined: 01 May 2006, 22:00

Location: Finland

Post 28 Dec 2020, 13:03

Re: Decompiled TPR and fixed it up

Krom wrote:Full changelist is jaw-dropping .. how did you do it all by yourself in secrecy?
I quite surprised myself that decompiling most of the game was even possible. Turns out there is surprisingly little code in the game (at least compared to your average game), which is probably explained by the game being programmed single-handedly by Peter Ohlmann. Initially, I was going to release something much sooner and figured I wouldn't bother mentioning it until I had something worthwhile to release. However, the more I dug into the disassembly the more things I discovered that were worth fixing until I eventually settled on something good enough.

Krom wrote:I'd love to read the story behind it - how you worked on it, figured things out, applied patches and so on.
That's actually a pretty good idea, I'll try writing something about it. Word of warning: my process of applying patches was quite messy but I really wasn't able to find any good information on how to neatly organize a large amount of assembly patches.

cmowla wrote:What would you like to call this?
I decided to call it 1.61 since it is in essence a continuation of the previous unofficial 1.60 patch.



Posts: 1

Joined: 03 Jan 2021, 09:03

KaM Skill Level: Skilled

Post 03 Jan 2021, 10:09

Re: Decompiled TPR and fixed it up

Glad to see the good old KaM still gets some love. :D

Personally I really like the KaM Remake, but I also love to play the single player campaigns and the new battle system balance sadly killed the fun for me a bit, because the "experience" feels completely different now. Due to this + the never ending Corona lockdowns I started a similar project last September and decided to rewrite the original KaM TPR executable in C/C++ with all original dependencies too (DirectDraw, DirectPlay and FMOD). I started to create an IDA database and rewrote routine by routine in C++ starting with the main function. I have never thought that I would be able to load maps with "almost" correct gourad shading and would be able to spawn houses as well as units and groups in only 3 months of developing. I have to admit that the code still looks like an ugly C++-x86 hybrid at the moment though and many classes called "UnkClass<Number>". xD

At the moment I'm working on the path finding algorithm and the main game loop. My goal is to finish the project in the course of 2021 and to fix all the old KaM bugs you already did it seems. My next goals would be then to improve the game with larger maps, a level editor and new textures/units/houses as well as creating a new campaign.

Because you already reverse engineered most stuff and put so much effort in it, you may be interested/willing to team up and work together on this project?


User avatar

Former Site Admin

Posts: 3812

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 13 Feb 2021, 16:43

Re: Decompiled TPR and fixed it up

Impressive work. This deserves a lot of recognition and praise. I am amazed you were undertaking such an ambitious project while off radar.

Cheers Litude. Hope you are well these days. Take care of yourself.
#thunderposting #greentornado


User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

Location: Australia

KaM Skill Level: Skilled

Post 16 Feb 2021, 13:21

Re: Decompiled TPR and fixed it up

Glad to hear you're still around Litude!

That would be an impressive changelog if you had access to the original source code, I'm amazed you achieve that much through disassembly. I'd love to hear the technical details, for example the disassembled code showing one of the bugs and the fix you made.

Take care :)

Return to General Talk

Who is online

Users browsing this forum: No registered users and 7 guests