Jump to content

EXE editing & programming issues


MrFlibble
 Share

Recommended Posts

Ti_ says he wrote his worm respawning code from scratch, just using functions already available in Dune (I guess the spawning of spice blooms is based on single infantry spawning from a group code). Nevertheless, it would be nice if parts of the original code would be found that indicated that worm respawning was actually intended by the developers.

Link to comment
Share on other sites

Now, the first thing I noticed that the gamePause switch did not work for me on any version - although Segra said it's some kind of map preview mode where the entire map is visible, but no action takes place (i.e. the game is not playable in this mode). Perhaps I did something wrong, but simply setting this value to 1 did not do anything.

This reminds me a LOT of the 'Editor' mode in C&C1... a mode in which nearly nothing worked, which was a leftover of the built-in mission editor.

gameWin, objectsNoDamage and gameImmediateBuild work fine (and are great for testing btw), however, unlike what Segra said, only the first mission that is loaded after the game starts will end with immediate victory (which is kind of logical for testing, otherwise the developers would be caught in a loop of victories leading to the final cinematic without any possibility to exit the game).

Interesting. I thought it'd just be something they linked to a hotkey ingame to make the game finish the mission. Either way, it seems to be reset to 0 during the end-of-mission code.

gameDemoMode generates a file called DUNE.LOG when set, which seems to be a record of all internal processes during a game session (I think this is what's called a "memory dump" but I'm not sure :)). Doesn't seem to do anything else.

Ah yeah, we've seen that at work in the demo... I should look into that in C&C1, heh. I know the same demo mode is in there somewhere.

IntroSkipAllow - if set, the game no longer requires ONETIME.DAT, _SAVE000.DAT or SAVEFAME.DAT to allow the player to skip the game intro by pressing a key. Also, the game won't generate ONETIME.DAT if no such file is found in the game directory.

Awesome. Very useful stuff :)

Just before IntroSkipAllow is the word_46BC6 variable which is already set to 1 by default. If you set it to 0, the game will under no circumstances allow to skip the intro via keypress.

Seems like the kind of thing they'd set in the demo... combined with the previous one to make it not generate the onetime.dat

language - haven't figured out what this one does. I thought that it forces a specific game language choice that overrides the setup, but this seems not to be the case.

It could just be the memory spot where the game SAVES the language read from the config file... in which case modifying the value that's there in the exe does nothing.

I have no idea what tmpStackCount and other undefined switches may be responsible for.

Stack count? Seems like real debug stuff.

This is the code which is responsible for drawing House heralds on the score screen. It involves some intricate math to calculate which heralds to use (depending on the internal House ID), and I decided not to bother with it in DuneX altogether.

You could just replace the logos, and make the code do the house ID -3 somewhere so F,S,M become H,A,O to the program, and uses their logo locations.

Link to comment
Share on other sites

Okay, I figured it out... I got code that works, but your logos are in the wrong order on the CPS: to correspond to H-A-O, they should be in the order F-S-M. They are in the order S-F-M though :P

[edit]

Here ya go:

You need to do 2 things... first, replace both occurrences of

cmp houseHumanID, 0 ; minimum house ID

[...]

cmp houseHumanID, 2 ; maximum house ID

by compares with 3 and 5 for the respective minimum and maximum. In a DB of your dunex.exe, they should be located at ovr207:0B56 and ovr207:0B9E

In your exe, that's offset 578EA and 578F1 for the first one, and 57932 and 57939 for the second.

Then there's the piece where I subtract 3 from the house ID (well, a copy of it)... this is a bit long, since I had to free up some space a bit further in the code, meaning the code in between is moved down a bit. Luckily, there was an opportunity to free up the required bytes only about 15 bytes further :)

At 578F7, replace the current code by these bytes:

EB14 A1383A BA3800 83E803 F7EA 050800 B103 D3F8 8BF8 B80200 50 50

In case you're interested, the actual new code of this is:

 
#eip=61A87 ; 578F7
EB14         jmp    .skipHouseCode
A1383A       mov     ax, houseHumanID
BA3800       mov     dx, 38h
83E803       sub     ax, 3  ; NEW INSERTED COMMAND: subtraction to shift FSM to HAO
F7EA         imul    dx
050800       add     ax, 8
B103         mov     cl, 3
D3F8         sar     ax, cl
8BF8         mov     di, ax
        skipHouseCode:
B80200       mov     ax, 2
50           push    ax
;       REMOVED TO GET FREE SPACE: B80200       mov     ax, 2
50           push    ax

As you see, I removed a command there to free up space to be able to insert the "sub ax, 3" command earlier in the code. That second "mov ax, 2" command wasn't needed anyway, since ax was already put to "2" :)

So yeah, this code, and an adaption of your CPS to put the logos in the right order, and you're set. I attached a fixed CPS that worked for me :)Here's the changes list as compare list, dunno if that's easier for you:

# Comparing files DUNEX_orig.EXE and DUNEX_LOGOSFIXED.EXE
000578EA: 00 03
000578F1: 02 05
000578F8: 11 14
000578FF: F7 83
00057900: EA E8
00057901: 05 03
00057902: 08 F7
00057903: 00 EA
00057904: B1 05
00057905: 03 08
00057906: D3 00
00057907: F8 B1
00057908: 8B 03
00057909: F8 D3
0005790A: B8 F8
0005790B: 02 8B
0005790C: 00 F8
0005790D: 50 B8
0005790E: B8 02
0005790F: 02 00
00057910: 00 50
00057932: 00 03
00057939: 02 05

fame_cps.zip

Edited by Nyerguds
  • Upvote 1
Link to comment
Share on other sites

Wow, cool, great thanks man! ;D I did figure out that the game calculates the position of the required heralds on the screen from the house ID, but playing with those alone produced weird results.

Okay, I figured it out... I got code that works, but your logos are in the wrong order on the CPS: to correspond to H-A-O, they should be in the order F-S-M. They are in the order S-F-M though :P

That's just because I thought the Sardaukar and Fremen heralds (which are shown with the unmodified code) look better than any of the two coupled with the Mercenary herald :)

Link to comment
Share on other sites

Well yeah, I skipped the entire problem with the positions by simply making the game think the IDs are 0, 1 and 2 ;D

The biggest problem is that you have to do it before the "imul dx" command, since that actually means dx=dx*ax. So despite the fact ax isn't mentioned in the command, it DOES use it.

I wouldn't be surprised if I can do the same thing for all other heralds stuff, actually. Though the problem is always that I need some opportunity to free up 3 bytes somewhere close-by so I can insert the houseID-3 command (which is typically 3 bytes long).

Link to comment
Share on other sites

What is really beyond me is why fixing the heralds on the map selection screen was so easy compared to the score and production screens. With the map selection (I posted the code somewhere above), the game simply checks for the Human House ID and then goes to the appropriate code segment that draws the necessary herald. In the very same way, the game handles cutscenes and ending cinematics, score screen progress bar colours, production screen item selection colours, and heralds shown during the copy protection dialogue. Maybe this simple way can be used once per event, and in the case of production and score screens those already got used up by things I listed above? ???

Link to comment
Share on other sites

Meh, it's just the programmers' choice. It's simply because the IDs are 0,1,2. For these heralds, which are all in one row, and each have the same fixed width, you can just do that width * the ID and then add the starting coordinates of the first one to it, and you got the location. It's just simpler than making yet another table with stuff in it, that's all.

Link to comment
Share on other sites

Hmm... is there any way to make the game play both the sounds and show the subtitles in the intro? I've looked into the movieSoundTextHandle function in Segra's DB, which seems to handle both the sound and the subtitles, but it's not really clear how it excludes the 2. I tried modifying some stuff, but it had no effect ingame.

Link to comment
Share on other sites

With the help of Segra's database I've been able to track down and fix the notorious Ix remap bug laugh.gif

dune2063.png

To fix, search for the bytes (identical in all versions):

90 7C 09 3C A0

And replace 3C A0 with 3C 96

An interesting side note, Dune 2 has separate code for unit remap, structure remap and button/menu coloured text remap, although the colours used in each case are all the same.

Link to comment
Share on other sites

Amazing work :D

An interesting side note, Dune 2 has separate code for unit remap, structure remap and button/menu coloured text remap, although the colours used in each case are all the same.

Well, seeing as how building graphics work totally different, with the colour limitation on each cell, that doesn't surprise me.

Anyway, I updated the upload :)

http://nyerguds.arsaneus-design.com/dune/dune2patch/dune2_107_fix.rar

Link to comment
Share on other sites

Not exactly. The colour index range is different in each case: it's 90h to A0h (I suppose that excludes A0) for buildings, 90h to 98h (97h and 98h are the first two light blue colours) for units, and for remapped text colours I can't tell you the exact range right now.

Link to comment
Share on other sites

An interesting side note, Dune 2 has separate code for unit remap, structure remap and button/menu coloured text remap, although the colours used in each case are all the same.

It has just occurred to me that the Brotherhood of Nod colour scheme in C&C must be an indication of the same thing, or am I wrong?

Anyway, here's a bit more info on the whole thing: in fact, I have been able to identify the remapable colour range for units and structures, and I also identified the way the game picks colours for remapable text and regions on the map selection screen (plus there are separate chunks of code for a) the colours of the animated arrows pointing at the regions that can be selected for the next mission and cool.gif for the Dune planet image in the ending credits). All of those use the 90h as the index of the first colour of the array (which is how I found them in the first place). Now, a bit about the remapable text/regions/arrows: 90h in the code for them stands not for the colours that should be remapped (as in the case of units and buildings), but for the start of sets of colours for each House/faction, which the game then calculates from the House ID. I.e. if you change 90h to A0h, the Harkonnens will have blue text, the Atreides will have green, the Ordos will have brown etc. On the other hand, if you change 90h to A0h in the unit/structure code, this will effectively disable remap for units and structures.

What I have been unable to find is, conversely, the way the game picks up colours for units and buildings, and the colour range of remapable colours for text, regions and arrows. I have checked all instances of 90h IDA Pro would find (with the "Search for immediate value" option), but changing none of them gave the same effect as with units and structures (i.e. disabling remap for good).

Link to comment
Share on other sites

The Nod dual remap colour thing is just a small exception in the remap logic that is applied to all structures, the harvester and the MCV of the side that has the exception. But I've already expanded it to work with any houses I want, with any secondary colours I want, and even as mission-specific settings so the colours are only that way in one mission :)

missioncolors.png

Link to comment
Share on other sites

What I have been unable to find is, conversely, the way the game picks up colours for units and buildings, and the colour range of remapable colours for text, regions and arrows. I have checked all instances of 90h IDA Pro would find (with the "Search for immediate value" option), but changing none of them gave the same effect as with units and structures (i.e. disabling remap for good).

(Warning: All from memory!)

The programmers used a shortcut there. Rather than checking each single pixel for the to-be-remapped colors, they used (IIRC) XLAT to translate from the pixel value into an array of color values to use. So if the original values for a row of pixels is (just some random values)

00 01 90 91 50 51

after an XLAT into the Harkonnen color array, they would translated into

00 01 90 91 50 51

(because the Harkonnen color array doesn't change colors -- the default unit colors are Harkonnen), and for the Atreides, they'd get translated into

00 01 A0 A1 50 51

because in the position '90 91 92 .. etc.' in Atreides' palette, it contains the values 'A0 A1 A2 ..' etc.

Assembly Refresher: XLAT uses AL as input and returns the value in DS:[bX+AL] into AL again. So all you have to do, as a programmer, is point DS:BX to the color translation array.

Link to comment
Share on other sites

Thanks for the info Jongware! :) May I also ask how did you get to know it? (I'm sorry I don't remember if you're part of the OpenDUNE team or maybe another project)

Nah -- back when Dune II was new it was my favourite game! I spend hours on disassembling it, first with DOS based utilities, then with one of the first free IDAs. You've come a long way since then ...

I was mainly checking out how the graphics worked, and wrote sort of a self-running demo with a day/night cycle -- quads riding around with headlights, stuff like that.

I'm fairly sure I still have a commented disassembly somewhere on my PC; if I can find it, I'll try to confirm what I wrote above, as it was totally from memory.

Link to comment
Share on other sites

Nah -- back when Dune II was new it was my favourite game! I spend hours on disassembling it, first with DOS based utilities, then with one of the first free IDAs. You've come a long way since then ...

I was mainly checking out how the graphics worked, and wrote sort of a self-running demo with a day/night cycle -- quads riding around with headlights, stuff like that.

Wow... this is pure uber-coolness cheesy.gif:laugh:

I'm fairly sure I still have a commented disassembly somewhere on my PC; if I can find it, I'll try to confirm what I wrote above, as it was totally from memory.

Thanks! :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...