Page 1 of 1

Scrapping Buildings

Posted: Sun Dec 21, 2008 4:27 pm
by Gowron
Scrapping buildings does not exactly yield a lot of cash, here's some info about it :)


1. Default Revenue

The default scrapping revenue for buildings is equal to the square root of the building value (IIRC this has already been posted by Spocks-cuddly-tribble).

If two or more buildings of the same type and in the same star system are scrapped simultaneously, then their values are added up BEFORE the square root operation is executed. This means that scrapping those buildings simultaneously will yield MUCH LESS cash than scrapping them separately (i.e. at different turns).


2. Corresponding Code Segment

The corresponding square root operation is located in trek.exe at position 0x44F74. The surrounding subroutine returns at position 0x44F9B, followed by three empty bytes.


3. Modding

Overwriting the fsqrt (D9 FA) statement at position 0x44F74 with "90 90" will cancel it. However, we can do more/better than that.

At position 0x44F66, the building value is stored and then loaded into the FPU. Before that happens, one or more small integer operations can be performed (up to 5 bytes, if you overwrite both the fsqrt statement and the three empty bytes).

Note that there's a call position 0x44F78, calling a distant function that does the floating-point rounding. The respective relative offset has to be adjusted, if the offset of the call itself changes (and thus differs from 0x44F78).

Posted: Mon Dec 22, 2008 4:47 pm
by jaruler
wow never knew that before, that we get credits back from them that is..

Posted: Mon Dec 22, 2008 5:25 pm
by Flocke
m2, good work gowron! =)[size=0][/size]

Posted: Wed Dec 24, 2008 3:26 pm
by stardust
damn....cheeky sods...meh, i'll stick to scrapping the dozens of farms in one go in all those minor race systems that they bequeath onto you when they join you..

Posted: Sun Jul 11, 2010 12:09 pm
by Peter1981
Gowron said
At position 0x44F66, the building value is stored and then loaded into the FPU. Before that happens, one or more small integer operations can be performed (up to 5 bytes, if you overwrite both the fsqrt statement and the three empty bytes).
sorry to as but not very good with this kind of coding

Code: Select all

C1 E3 03 is hex for  shl   ebx, 3
i think? can someone please tell me how i might use something similar to divied the returned crdits by 2 im thinking shr ebx, 1 ? anyway would like to only return half the value (or 25%) for scrapped buildings. would something like

Code: Select all

C1 E8 01  shr eax, 1 
work?

Posted: Sun Jul 18, 2010 7:37 am
by Gowron
Yes, that would work.

This is the statement that I'm using for BoP:

Code: Select all

asm address   hex code  asm code
:00445B66     C1E803    shr eax, 03
It results in the revenue being equal to 1/8 of the building value.
To get 25% revenue, use "C1E802".

Don't forget to correct the call to subroutine 0051D6D4.

Posted: Sun Jul 18, 2010 11:46 am
by Peter1981
Honestly gowron thank you ever so much for this I think I'm begining to understand this asm stuff a little :)

Posted: Sun Jul 18, 2010 1:03 pm
by Peter1981
so replace 0x44F66

Code: Select all

89 84 24 b8 00 00 00 db 84 24 b8 00 00 00 90 90
8b 17 e8 57 7b 0d 00 df bc 24 b0 00 00 00 03 94
24 b0 00 00 00 b8 01 00 00 00 89 17 81 c4 bc 00
00 00 5f 5e 59 c3 00 00 00 00


with for 1/8 return

Code: Select all

c1 e8 03 89 84 24 b8 00 00 00 db 84 24 b8 00 00
00 8b 17 e8 56 7b 0d 00 df bc 24 b0 00 00 00 03
94 24 b0 00 00 00 b8 01 00 00 00 89 17 81 c4 bc
00 00 00 5f 5e 59 c3 00 00 00
or for 1/2 return

Code: Select all

c1 e8 01 89 84 24 b8 00 00 00 db 84 24 b8 00 00
00 8b 17 e8 56 7b 0d 00 df bc 24 b0 00 00 00 03
94 24 b0 00 00 00 b8 01 00 00 00 89 17 81 c4 bc
00 00 00 5f 5e 59 c3 00 00 00

Posted: Sun Jul 18, 2010 4:39 pm
by Gowron
Yep, that's exactly the way to do it :)


For 50% revenue, you could also use "D1 E8" instead of "C1 E8 01" (then you wouldn't have to worry about the function call), but I'd still prefer "C1 E8 01" because maybe you want to change it to, say, 25% later, and then it's easier this way.

Posted: Sun Jul 18, 2010 5:15 pm
by Peter1981
thanks for confirming -- made a typo [last line put DE not 5E! lol] so thought i'd jiggered trek.exe thanks for the responce I really really appreciate your feed back on this matter :D