Scrapping Buildings

Scrapping Buildings (for money); support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Scrapping Buildings

Post 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).
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
jaruler
Lieutenant-Commander
Lieutenant-Commander
Posts: 181
Joined: Sun Oct 19, 2008 2:00 am

Post by jaruler »

wow never knew that before, that we get credits back from them that is..
Last edited by jaruler on Mon Dec 22, 2008 5:59 pm, edited 1 time in total.
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3197
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Post by Flocke »

m2, good work gowron! =)[size=0][/size]
stardust
Rear-Admiral
Rear-Admiral
Posts: 1381
Joined: Sat Apr 26, 2008 2:00 am
Location: good ole Blighty

Post 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..
Computers! [Expletive deleted]

My 4shared folder
User avatar
Peter1981
Rear-Admiral
Rear-Admiral
Posts: 1118
Joined: Tue May 06, 2008 2:00 am
Location: England

Post 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?
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Post 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.
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Peter1981
Rear-Admiral
Rear-Admiral
Posts: 1118
Joined: Tue May 06, 2008 2:00 am
Location: England

Post by Peter1981 »

Honestly gowron thank you ever so much for this I think I'm begining to understand this asm stuff a little :)
Last edited by Peter1981 on Sun Jul 18, 2010 1:08 pm, edited 1 time in total.
User avatar
Peter1981
Rear-Admiral
Rear-Admiral
Posts: 1118
Joined: Tue May 06, 2008 2:00 am
Location: England

Post 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
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Post 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.
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Peter1981
Rear-Admiral
Rear-Admiral
Posts: 1118
Joined: Tue May 06, 2008 2:00 am
Location: England

Post 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
Post Reply

Return to “Scrapping Buildings (for money)”