Change hard coded parts

Discuss and distribute tools and methods for modding. Moderator - Grognak
dir94
Posts: 3
Joined: Wed Jun 18, 2014 9:38 pm

Change hard coded parts

Postby dir94 » Wed Jun 18, 2014 10:08 pm

Hello everyone.
I'm a part of a small team, creating a translation to another language.
Translating events and etc is no problem as all this text is kept in xml files from fat archives.
The problem we encountered is translating graphics. Of course it is no problem to redraw the buttons, the problem is the size. Many of translated words are bigger than the English ones. I know, that the sizes of buttons are hard-coded, so I'm trying to patch the executable file. Are there someone, who did this before? Can someone help me finding size bytes. Here is my progress :
Using IDA pro I disassembled the exe. Found parts of the code, responsible for the main menu. Some buttons like quit are coded like this :
https://cloud.mail.ru/public/e0c77e11672c/4.PNG

Here we can see, that first 8 operations form a structure, position of top left corner and size (width and height) of active area. And then the same for the page picture.
But some buttons are declared Ina different way :
https://cloud.mail.ru/public/c6b7aefbb417/2.PNG

So, here I can't understand how it works.
To be perfect, I'd like to see developers answer this question, but I think I it's quiet impossible. Are there anyone who can help me?
User avatar
kartoFlane
Posts: 1488
Joined: Mon Jan 14, 2013 10:20 pm

Re: Change hard coded parts

Postby kartoFlane » Thu Jun 19, 2014 4:06 pm

Nope, generally no one is willing to reverse engineer the code -- too much hassle to try to write C code by analysing assembler code, I guess. Attempts to rewrite FTL in another language have been much more popular.

To answer your question, the explanation is quite simple: the quit button image is hardcoded to be resized, but the options button is not, and uses the image's dimensions instead.

As evidenced here -- I replaced only the options_on.png button, the hovered-over image is the default one. As you can see, it is resized to match the options_on image's dimensions.
Replacing quit_on.png image, for comparison.

The assemble snippet you've provided also supports this. The code here references the quit image's size (124x50), as well as its offset:

Code: Select all

loc_5B9F52:                 # quit image function
# the following 4 instructions probably set up the hover area for the button
mov    [ebp+var_360], 43Dh  # = 1085  ; X offset + 9
mov    [ebp+var_35C], 278h  # = 632   ; Y offset + 9
mov    [ebp+var_358], 6Ah   # = 106   ; width - 18
mov    [ebp+var_354], 20h   # = 32    ; height - 18
# these 4 instructions reference the image's dimensions and button's offset
mov    [ebp+var_350], 434h  # = 1076  ; X offset of the quit button
mov    [ebp+var_34C], 26Fh  # = 623   ; Y offset of the quit button
mov    [ebp+var_348], 7Ch   # = 124   ; width of the quit button image
mov    [ebp+var_344], 32h   # = 50    ; height of the quit button image
...

...but in the other snippet, there are no values that match options' image's dimensions (194x50):

Code: Select all

loc_5B9D8C:                     # options image function
mov    [esp+4B8h+var_4B4], 1FBh # = 507   ; Y offset of the options image
mov    [esp+4B8h+var_4B8], 3EEh # = 1006  ; X offset of the options image
...


So you'll just have to figure out which images have hardcoded sizes and which do not by way of trial and error *shrugs*
Superluminal2 - a ship editor for FTL
dir94
Posts: 3
Joined: Wed Jun 18, 2014 9:38 pm

Re: Change hard coded parts

Postby dir94 » Wed Jun 25, 2014 8:17 am

kartoFlane, Thank you a lot!!! You have helped me understand this!! Can you help me one more time please? :D
Now the problem is map. With the WAIT button, when you have no fuel to jump. What i've figured out: there is a background with the blanks of ON/OFF and WAIT buttons. Here's its code:

Code: Select all

loc_4AEC99:
fld1
fst     [ebp+var_3B4]
fst     [ebp+var_3B0]
fst     [ebp+var_3AC]
fstp    [ebp+var_3A8]
lea     eax, [ebp+var_39D]
mov     [esp+698h+var_694], eax
mov     [esp+698h+var_698], offset aIpadMapSide__3 ; "ipad/map/side_wait_distress.png"
mov     [ebp+var_608], 0Fh
lea     ecx, [ebp+var_3A4]
call    sub_6E8020
sub     esp, 8
mov     [esp+698h+var_674], 0
mov     [esp+698h+var_678], 3F800000h
lea     edi, [esp+698h+var_688]
lea     esi, [ebp+var_3B4]
mov     ecx, 4
rep movsd
mov     [esp+698h+var_68C], 0
mov     [esp+698h+var_690], 1D3h  ; Y offset of the background image
mov     [esp+698h+var_694], 1C4h  ; X one
lea     eax, [ebp+var_3A4]
mov     [esp+698h+var_698], eax
mov     [ebp+var_608], 25h
mov     ecx, offset unk_7A7720
call    sub_6404D4
sub     esp, 28h
mov     ecx, [ebp+var_658]
mov     [ecx+2A4h], eax
mov     eax, [ebp+var_3A4]
mov     [ebp+var_654], eax
cmp     ds:dword_7A81E8, 0
jz      short loc_4AED6B

And a pic:
Image

Code, refered to the WAIT button:

Code: Select all

loc_4ADC8E:
mov     ecx, [ebp+var_658]
mov     byte ptr [ecx+0D5h], 1
mov     [esp+698h+var_694], 1E6h ; Y offset as i think
mov     [esp+698h+var_698], 1D7h ; X offset
mov     [ebp+var_608], 0Fh
lea     ecx, [ebp+var_4AC]
call    sub_63B05E
sub     esp, 8
lea     eax, [ebp+var_49D]
mov     [esp+698h+var_694], eax
mov     [esp+698h+var_698], offset aIpadMapButto_0 ; "ipad/map/button_wait"
lea     ecx, [ebp+var_4A4]
call    sub_6E8020
sub     esp, 8
mov     eax, [ebp+var_4AC]
mov     edx, [ebp+var_4A8]
mov     [esp+698h+var_694], eax
mov     [esp+698h+var_690], edx
lea     eax, [ebp+var_4A4]
mov     [esp+698h+var_698], eax
mov     [ebp+var_608], 15h
mov     ecx, [ebp+var_644]
call    sub_56BB86
sub     esp, 0Ch
mov     eax, [ebp+var_4A4]
mov     [ebp+var_650], eax
cmp     ds:dword_7A81E8, 0
jz      short loc_4ADD40


So, i need to make wider background image to make WAIT button bigger. So, i edited background, edited bytes, refered to its X offset (made it X - 55 = 1C4h - 55 = 18Dh), but when i edited the X offset of the WAIT buuton (made it X - 55 = 1D7h - 55 = 1A0h) nothing happened!! :shock:
Image
The button just dont move. I tried different changes in offsets, even some really big or small. Seems the WAIT button is specified in another way.

I even measured the screenshots! I've found the WAIT button is in 471 (1D7h) pixels from the left border of the map overlay indeed!!

Sorry for my bad english :D
Thanks a lot!!
dir94
Posts: 3
Joined: Wed Jun 18, 2014 9:38 pm

Re: Change hard coded parts

Postby dir94 » Sun Nov 02, 2014 9:25 am

up :roll:
Omen267901
Posts: 31
Joined: Thu May 30, 2013 10:22 pm

Re: Change hard coded parts

Postby Omen267901 » Sun Nov 02, 2014 5:29 pm

This dead? Just like every other attempt?
User avatar
kartoFlane
Posts: 1488
Joined: Mon Jan 14, 2013 10:20 pm

Re: Change hard coded parts

Postby kartoFlane » Tue Nov 18, 2014 10:17 pm

Looks like I forgot to reply... multiple times. Oh well, sorry about bringing a somewhat stale topic back up.

@dir94
I'm afraid I'm unable to help you with that, as my understanding of assembly is shaky at best. Deciphering the mov is pretty easy as it's a very straightforward & universal command, but I have no clue about most of the other ones.

Disregarding the assembly stuff completely, it's entirely possible that the values you've modified specify only the image's location, and not the actual button area, or that locations for the default and hover images for the button are specified separately.

Could also be that the code you're modifying pertains to Ipads and not PCs -- as evidenced by the 'ipad' in the image's path -- but the same graphic/code could very well be used for all platforms.

I guess you could try finding some tutorials/youtube videos explaining assembly and the various instruction sets in order to better understand what's going on.
Superluminal2 - a ship editor for FTL