MM3- Isles of Terra modding progress

The role-playing games (I-X) that started it all and the various spin-offs (including Dark Messiah).
ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

MM3- Isles of Terra modding progress

Unread postby ludmeister » 09 Sep 2011, 22:16

Greetings to the Might and Magic modding community!

I've been playing around with the various tools out there for working with .CC files. I had a lot of fun creating a monster spawn mod for World of Xeen which gives your party a running challenge.

Now, I've gotten interested in working with MM3.CC. I know a fair bit about the game, because I've been able to decrypt the game's executable. I even am able, through the wonders of the wonderful DOSBOX debugger, to find where in memory all monster's HP is stored.

Now, there's a file in MM3.CC called MONHP.DAT... and theoretically that would be where the monster's HP is stored. There's 90 monsters in the game in all, and each monster's HP is stored as a 2 byte word, so that's 180 bytes used. One would expect MONHP.DAT to be (at least) 180 bytes... but it isn't. In MM3.DAT, this file weighs in at 141 bytes, and many other files appear to be smaller than expected as well.

This indicates to me that a compression algorithm was used on those files... and it's pretty hairy to attempt to trace the inflation of that data through the DOSBOX debugger. It doesn't rule out any XOR in the data... but makes it unlikely, since compressing text makes it pretty unreadable anyway.

I'm hoping that the key to decrypting MM3.CC's files lies in a Inflate/Deflate C++ library out there somewhere, as MM3.exe was compiled by Borland C++. I've heard that Zlib was in use at that time...

Is there someone in this community who could take a look at MM3.CC, and possibly assist in the decryption/inflation of its compressed files? I'd be most appreciative!
Last edited by ludmeister on 28 Nov 2011, 04:32, edited 1 time in total.

User avatar
Talin_Trollbane
Swordsman
Swordsman
Posts: 598
Joined: 23 Apr 2006
Location: Up North

Unread postby Talin_Trollbane » 13 Sep 2011, 20:20

finally someone even peeking at MM3 modding.
Ultima, Elder Scrolls and Might and Magic Veteran.

User avatar
Corlagon
Archangel
Archangel
Posts: 1421
Joined: 03 Sep 2007
Location: HC/CH

Unread postby Corlagon » 14 Sep 2011, 07:54

Well I'd be the first to lavish praise on anybody who manages to decrypt MM3.CC. It's literally the only MM game whose text I haven't (fully) collected :)

I unfortunately know next to nothing about actually doing so, but here are some resources and links to and from people who know what they're talking about:

http://rewiki.regengedanken.de/wiki/.CC
http://xeen.wikia.com/wiki/CC_File_Format
http://www.gog.com/en/forum/might_and_m ... _mm3_music
http://www.gog.com/en/forum/might_and_m ... map_editor

I'd expect WizardStan, Agalloch or CedricBusch to be able to assist. If you like I will try and contact them.

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 14 Sep 2011, 13:47

Corlagon,
I'd expect WizardStan, Agalloch or CedricBusch to be able to assist. If you like I will try and contact them.
I've been in contact with Cedric as a couple of his Xeen apps have been instrumental in ferreting out info about the .CC's themselves (MM3.CC and SAVExx.MM3). His work is tremendously helpful to the MM3/4/5 modding community, and I think it's every bit as helpful as the Cosmic Forge was for Wizardry 8 modding, (if any of you are familiar with Wizardry 8).

It seems that MM3's crazy encryption has driven back even the best and brightest out there... and I've been watching it run in my debugging emulator for a while without any more insight than WizardStan had back in the thread about mm3 music.

Then... I had an idea. Image

If I can't beat MM3's encryption algorithm, I'll join it. Using the debugger, I figured out when a certain file loads when you fire up mm3.exe. I found out exactly how it is stored in memory. Then, I observed that I can change which file from MM3.CC loads in that place. Lastly, I found out where I need to set a breakpoint in the code so that the file would be completely loaded and decoded... right before the load routine exits.

Result: I can decode any file in MM3.CC of which I know its original name (about 430+ files!).

I have actually been working pretty steadily at this, and have decoded almost 260 of the 558 files, at a rate of about one file every 2 minutes or so, when I get in a groove.

Cedric's file packer should be instrumental in repacking the decoded files in Xeen-style 0x35 XOR. That leaves only one other hitch for modding purposes... making a version of MM3.EXE that has a CC loader which doesn't do the decryption algorithm, and merely XORs the content when it loads files. I feel confident that I'll be able to pull this off when I have most of the files decoded. (I'll probably need a bit of trial and error to determine the names of some of the files... I'll just let MM3.exe scream them at me when it force closes Image)

I plan to offer patches for MM3.exe and MM3.CC to convert the encrypted versions to decrypted versions on my website when I'm done.

MM3 was one of my favorite games, and it holds a lot of nostalgia for me, and if I can help it stay fresh, that's a huge win in my book. I know this isn't the ideal solution, but I'm confident that it's workable.

User avatar
Corlagon
Archangel
Archangel
Posts: 1421
Joined: 03 Sep 2007
Location: HC/CH

Unread postby Corlagon » 15 Sep 2011, 19:29

That's very interesting - I'm delighted you met success. Kudos to you for beating out WizardStan :D

Even if you can't prevail in the repacking endeavours, I assure you that if you manage to get the game's files extracted and readable (especially texts!), they will be put to very good use on the wiki and elsewhere.

If you find yourself stuck, I can try and get you some help by putting out an alert in the Age of Heroes news, or ask Kalah to do so for Celestial Heavens. MM3 is my favourite game in the RPG series, and it's a pity there's no modding interface for it in the past.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 15 Sep 2011, 20:21

Same here, MM3 is my favourite NWC game as well, and it's awesome to see someone working on the CC files! Personally I'd love to be able to extract FM music out of it, it's the only game so far that has custom music in a format that is unreadable in its original form.

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 17 Sep 2011, 16:30

Just a quick update on my progress:

I believe I have all 558 files decrypted now. I figured out where in program execution the hash for a particular file was calculated thoroughly, and by changing that hash to the IDs for which I didn't know their true file name, I was still able to decrypt those files.

I have also packed them into a readable .CC format, with no XOR. This MM3.CC has a dummy Xeen save, and I have renamed the default Save files that MM3 will build save games from from OUTx.SPL to DFLTSAVx. I can't give Cedric enough kudos for his Xeen CC Packer program, which has saved me weeks of time and energy in realizing this part of the project (not to mention his CC File List program, which was invaluable to me in figuring out all the files I have to work with).

I must say, Timer.drv is not what I expected, as it contains no manual lookups and no target words. What it is... is actually additional code that is executed, and its checks need to successfully complete in order to run MM3. In fact, I believe it may actually be the code that checks for the correct word from the manual. It is the first file from the .CC actually loaded when MM3 is booted up.

My challenge now is to get the decoded files loaded exactly as they would have been loaded in the encrypted .EXE/.CC combo. I have done a fair bit of preliminary scouting as to where Timer.drv loads, and why it gets put where it does, and I am about 75% confident that I will be able to hack the loading algorithm such that it won't decrypt the files. If I am able to do this, then we will have the basework done for MM3 modding endeavors!

I'll be working at this as I get time this weekend...

User avatar
Rune_Caster
Demon
Demon
Posts: 304
Joined: 02 May 2010
Location: Attacking you behind a wall (Texas)

Unread postby Rune_Caster » 17 Sep 2011, 23:31

I have a question about WoX and possibly MM3 too... I know that Bows do not spawn at Sapphire, Diamond and Obsidian loot levels. And I have always wondered if it might be possible to mod the part that selects what items are available at Gold to Obsidian and Obsidian loot levels.

The other question is does this bug also exist in MM3?

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 18 Sep 2011, 00:42

Image Success! Image

I'm not sure I can believe it, but my decrypted MM3.CC can be read from properly, given my edits to the loading algorithm in MM3.EXE. I have attempted to create a save game, and it worked flawlessly (at least, to the eye test that I gave it).

If all goes according to plan, I'll put a page up on my website on Tuesday which describes this project and has the following downloads:
  • A patch to decrypt MM3.CC (decrypted)
  • A patch for MM3.EXE (companion to MM3.CC... don't attempt to use a compressed MM3.CC with this)
  • MM3 CC Files (a zip file containing all decrypted files, in two formats: in d_#####.ccx format with dummy Xeen save game which allows repacking using Cedric's awesome Xeen-CC-Packer, and in 0xhhhh-Filename.ext format for easier perusal).
Until then, if anyone wishes to take a look at them, just pm me and I'll send you the files. Cheers!

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 18 Sep 2011, 01:05

RuneCaster,

I've never noticed that in Xeen, but I think you're right, too... I don't think I've ever gotten a Diamond Crossbow (for example) either. I'm sure it's possible to mod that, but it would take some digging into the code. I can't recall whether I've received one in MM3 or not.

Bows always sorta annoyed me in MM3/4/5... Part of my WOX mod is actually about making bows a viable attack option for longer... they grow useless quickly because you only take one shot per monster step, no matter what level your characters are. Not only this, but when you have an elemental enchantment on a weapon, its damage is only applied once, not once per hit. So, I drastically increased the elemental damage done by elemental-enchanted weapons. Had a neat side effect of increasing their cost as well, making them useful to lug around and sell. An electric crossbow hitting a target for about 80 damage? Yes, please Image

User avatar
Rune_Caster
Demon
Demon
Posts: 304
Joined: 02 May 2010
Location: Attacking you behind a wall (Texas)

Unread postby Rune_Caster » 18 Sep 2011, 09:38

ludmeister wrote:RuneCaster,

I've never noticed that in Xeen, but I think you're right, too... I don't think I've ever gotten a Diamond Crossbow (for example) either. I'm sure it's possible to mod that, but it would take some digging into the code. I can't recall whether I've received one in MM3 or not.
Clouds of Xeen ontop of Darzog's Tower is the only place I have successfully gotten a Sapphire, Diamond or Obsidian bow, there is a Long Bow, a Crossbow and two Short Bows are available from the hands holding the bows in the clouds. Elemental weapons don't give hit bonuses either so I tend not to use them except when monsters are 100 % immune to physical attacks (Winterkill for example)

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 21 Sep 2011, 19:12

I have a question about WoX and possibly MM3 too... I know that Bows do not spawn at Sapphire, Diamond and Obsidian loot levels. And I have always wondered if it might be possible to mod the part that selects what items are available at Gold to Obsidian and Obsidian loot levels.

The other question is does this bug also exist in MM3?
I've done some searching about this... I actually was annoyed by the lack of quality loot sold at blacksmiths, and I stumbled upon the answer to this. I don't know if it is a bug, but it definitely is an oversight in the coding.

When creating an item, Xeen rolls two numbers to create it. The first is between 1 and 100 all the time. The second is normally between 1 and 100 as well, but incidentally, at the highest magic level the second roll is between 1 and 80. Why this is, I do not know, but the code specifically does this, and perhaps it is a concession to fix another, more nasty potential bug.

When getting a bow, the second roll has to be 85 or higher. So you are correct, you will never get bow random spawned (or, potentially, in weapon shops) at power level 6. Though as you have pointed out, they can be spawned directly using events.

User avatar
Talin_Trollbane
Swordsman
Swordsman
Posts: 598
Joined: 23 Apr 2006
Location: Up North

Unread postby Talin_Trollbane » 28 Sep 2011, 19:18

GreatEmerald wrote:Same here, MM3 is my favourite NWC game as well, and it's awesome to see someone working on the CC files! Personally I'd love to be able to extract FM music out of it, it's the only game so far that has custom music in a format that is unreadable in its original form.
yes, please do.
Ultima, Elder Scrolls and Might and Magic Veteran.

User avatar
tolich
Spectre
Spectre
Posts: 748
Joined: 10 Jan 2009
Location: Minsk, Belarus

Unread postby tolich » 29 Sep 2011, 07:28

Talin_Trollbane wrote:
GreatEmerald wrote:Personally I'd love to be able to extract FM music out of it.
yes, please do.
Perhaps, he's still unable to do.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 29 Sep 2011, 09:27

He did extract them, just that there is no program to play them.

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 29 Sep 2011, 12:50

He did extract them, just that there is no program to play them.
This. At least not yet.

GreatEmerald has attempted to play Might and Magic 3's Inn ditty in a Xeen midi file player. The other files were also attempted but did not get as interesting a result... some even complaining that "Command x is not implemented".

Might and Magic 3's midi files are encoded slightly differently than Xeen's music is, and my theory (perhaps others can tell me how strong the theory is) is that Xeen's install program allows for a certain number of MIDI sound outputs (music cards) and MM3's install program allows for a certain number. IIRC, MM3 actually supports a greater number of music cards (since Creative's Sound Blasters made obsolete a large number of other sound solutions, such as Adlib which actually went bankrupt in 1992 due to Sound Blaster's dominance).

If I understand WizardStan's breakdown of the M file format, each of the midi files have their own instrument data, as well as information required for each sound solution to play those instruments back. I believe, therefore, that MM3's music actually starts at a different offset than Xeen's (0x1a? 0x1b?).

It's something for someone who has more MIDI savvy than me to look into, but maybe it's a step in the right direction.

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 13 Oct 2011, 17:26

Don't know if anyone is interested, but I have updated the downloads on my site...

First, there is now a .zip containing the MM3 save game files, handily named in such a way as to be packed with Cedric's Xeen CC Packer.

Second, I developed a Might and Magic 3 Monster Editor last night. Since monster data is literally stored in 22 separate files in MM3.CC, it would be a somewhat tedious exercise to view or modify this data with only a hex editor. So I made this to further my modding efforts, but absolutely, if anyone wants to make use of it they can do so freely.

Cheers.

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 18 Oct 2011, 14:17

I wanted you all to be aware of two updates to the MM3 resources:

One very important update was to the Default Save files download… I found in my testing that I had swapped the names of two files within the MM3 save- MAZE53.DAT and MAZE54.DAT. This means that instead of #53’s map data being Map D1 and #54’s map data being Map D2, the data was switched. This had the effect of borking save games created from my data, as when the party entered any of the following maps, bad things occurred, from erratic behavior to engine instability to instant crashes.
  • Area D1— “Monsters Exceeded” notification… Engine crashed.
  • Area D2— Engine crashed immediately without warning.
  • Area D3— Northern border of map became water (as opposed to Fire Isle terrain as expected). Lava did no damage.
  • Area E2— Engine crashed immediately without warning.
Therefore, the Default Save files package has been updated, and it is recommended that if you previously downloaded this package then you should either download this updated package, or swap the names of MAZE53.DAT and MAZE54.DAT. This will ensure that any save games built from repacking these files will work.

I wanted you all to be aware of this mistake and I apologize for the error.

The second update is a happier one… the patch for MM3.EXE has also been updated, as I have cleared away a bug that always bothered me-- the Arena Experience bug has been fixed.

In stock MM3, when character’s emerge triumphant in the Arena, their Arena Wins byte is increased by one, and then they earn Experience points equal to (1000 * Arena Wins). At least, that was what was supposed to happen. In actuality, the Arena Experience bonus was rendered as a 16-bit signed integer. In layman’s terms, when you won your 33rd Arena battle, you actually lost close to 32000 experience points!
Last edited by ludmeister on 22 Nov 2011, 03:30, edited 1 time in total.

User avatar
Talin_Trollbane
Swordsman
Swordsman
Posts: 598
Joined: 23 Apr 2006
Location: Up North

Unread postby Talin_Trollbane » 19 Nov 2011, 23:35

finally someone addressing that bug. :)

also, dont you dare drop this project, or we will find you and "re-educate" you and give you new "insights" to our cause. ;)
Ultima, Elder Scrolls and Might and Magic Veteran.

ludmeister
Leprechaun
Leprechaun
Posts: 19
Joined: 09 Sep 2011
Contact:

Unread postby ludmeister » 21 Nov 2011, 23:48

Haven't dropped the project... actually I'm playtesting through my MM3 Monster Spawn mod. My party's level 50, and I found another oversight in my Default Save files... swapped the names for MAZE35.DAT and MAZE36.DAT, so I didn't see what I expected when I entered the Main Storage Sector :mad:

Will update the files on my site tomorrow.

Glad to hear there's interest in the MM3/4/5 project. Thanks Talin!


Return to “Might and Magic”

Who is online

Users browsing this forum: Ahrefs [Bot] and 31 guests