Page 1 of 1

Decompiled TPR and fixed it up

PostPosted: 23 Dec 2020, 10:55
by Litude
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.

Re: Decompiled TPR and fixed it up

PostPosted: 23 Dec 2020, 17:13
by Krom
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: https://discord.gg/UkkYceR

Re: Decompiled TPR and fixed it up

PostPosted: 24 Dec 2020, 17:35
by cmowla
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!

P.S.,

If this thread doesn't bring back TDL to these forums, nothing will! :D

Re: Decompiled TPR and fixed it up

PostPosted: 28 Dec 2020, 13:03
by Litude
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.
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.
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.

Re: Decompiled TPR and fixed it up

PostPosted: 03 Jan 2021, 10:09
by Philymaster93
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?

Re: Decompiled TPR and fixed it up

PostPosted: 13 Feb 2021, 16:43
by Ben
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.

Re: Decompiled TPR and fixed it up

PostPosted: 16 Feb 2021, 13:21
by Lewin
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 :)

Re: Decompiled TPR and fixed it up

PostPosted: 18 Apr 2021, 09:43
by T*AnTi-V!RuZz
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!
I didn't see this before now. Thanks, much appreciated! Good to see you're still around ;)