Are you, in fact, a pregnant lady who lives in the apartment next door to Superdeath's parents? - Commodore

Create an account  

 
Disassembly questions

(October 26th, 2015, 08:26)Seravy Wrote: You'll need these views :

Hex view : This just shows you the bytes in the file. So if you want to find the machine code for some instructions, you can look here.
Ida view : This is the disassembled code. If it's not open by default then try View-subviews-disassembly.
Names : A list of stuff you have named after you identified them. To name a procedure or data reference, right click it and select rename.
Functions : A list of the functions/procedures in the file.
Strings : these are just the string constants found in the exe. Not all of them are actually here, but most are. This view is useful if you know the text the game displays and want to find where it gets displayed. For example you want to allow building when there are already 9 units in town then you search for that message.

The IDA view is weird. If you click on a name you get some code like you have below, but if you scroll using the scrollbar then it turns into a graph and you can never get back to the view you had before.

I had a function tab, but it has disappeared for some reason.

Quote:You can't. If you add even a single extra byte, everything in the file after that will be at a different address than where the loader looks for it and the game would not even load, as well as all jumps between the two parts being off by one byte.

Dumb question, but could you update the loader to point in the right place after you change the files?

Quote:You can jump to a new space, yes, but you need to MAKE the new space first. There aren't miraclous unused large spaces in the file everywhere for us, sadly. And, it has to be in the same segment, otherwise the process is ultra-difficult. Also if the jump you modify is a byte value then it has to be within +-127 bytes, otherwise you need to make +1 byte space for a larger jump instruction.

When you say segment, do you mean in the same address in memory? How large is a segment?

Quote:Not really. You literally have to look for "adds 2 to the value, then throws the result away and overwrite it with 5." style of coding where you can remove the "adds 2" part without changing the overall effect. In other words, use your brain, so it cannot be done automatically, only humans are able to do this part.
In easy cases one such place can yield 9-15 bytes of space and you can find 6-8 of them near together.
In hard cases, you have to actually re-code stuff to make it use less space through code optimalization.
For example to add the "Turns = x" display in combat, I had to recode it from

Very interesting. How do you calculate the number of bytes that you've saved?

Quote:as you can see "displaytext" is the original second half which displayed the "skill" line, except it uses the passed parameters instead of the original contants. The first half to display the "Mana" line is removed, and calls the second half 3 times, with 3 sets of parameters to display 3 lines that are no longer limited. To further restrict the options, "Turns" had to exist as a text constant available and ready to use in the data segment, fortunately it did, as it is displayed elsewhere. You can see it uses the text belonging to another game part because "Mana:" and "Skill:" has a ":" but "Turn" does not, it was only available without it. Otherwise I would have also needed free room in the data segment to add new text (I guess there are some unused texts like "as swiftness spell" which kryub made not to appear").

In this particular case there was no space that could be made, and as far calls are unmovable, I had to re-use the same one to be ran once more than originally to display more lines of text. Took about 4 hours to get it work.

So you literally have to search the code to find somewhere to save a couple of bytes somehow and then code up to that exact amount of bytes the changes you want to make. Amazing.

Quote:Assuming you have a large block of free space somewhere (I actually do because I replaced a huge AI routine somewhere so the original is not called anymore) you could in theory get away with only making 3 bytes of space, and using a near call to it IF you are within the same segment. There are about 160 segments so guess what the chances are for that? Yeah... my nice huge empty space will not be useful, it's in a segment where I don't need to add stuff at least at the moment.

Did you mention far calls? Would they be able to access space in other sections?

Quote:By the way, if you are looking for a variable or a procedure in particular, it might be faster to ask than to try find it amongst the 3500 procedures the game has yourself. Even I only identified about one third of them so far.

I was interested in looking at the part that deals with how many spells you can pick from common, uncommon and rare. Mainly though I was wanting to know roughly how modding the game works at all and what limitations there are for future changes.

How do you go about finding a piece of code in game if it isn't found already?
Reply



Messages In This Thread
Disassembly questions - by MrBiscuits - October 26th, 2015, 09:04
RE: Disassembly questions - by MrBiscuits - October 26th, 2015, 09:05
RE: Disassembly questions - by MrBiscuits - October 26th, 2015, 09:14
RE: Disassembly questions - by Seravy - October 26th, 2015, 09:56
RE: Disassembly questions - by I like Serena - October 26th, 2015, 14:00
RE: Disassembly questions - by Seravy - October 26th, 2015, 14:50
RE: Disassembly questions - by Seravy - October 26th, 2015, 14:54
RE: Disassembly questions - by I like Serena - October 26th, 2015, 14:59
RE: Disassembly questions - by Seravy - October 26th, 2015, 15:02
RE: Disassembly questions - by Bogus - May 29th, 2016, 08:01
RE: Disassembly questions - by Seravy - May 29th, 2016, 10:28
RE: Disassembly questions - by Bogus - May 29th, 2016, 11:07
RE: Disassembly questions - by Seravy - May 29th, 2016, 16:27
RE: Disassembly questions - by Bogus - May 29th, 2016, 16:46
RE: Disassembly questions - by Seravy - May 30th, 2016, 03:27
RE: Disassembly questions - by Bogus - May 30th, 2016, 07:21

Forum Jump: