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).
Scrapping Buildings
Moderator: thunderchero
-
- Code Master
- Posts: 304
- Joined: Sat Apr 26, 2008 2:00 am
- Location: 50° N, 11° E
Scrapping Buildings
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
-
- Lieutenant-Commander
- Posts: 181
- Joined: Sun Oct 19, 2008 2:00 am
-
- Rear-Admiral
- Posts: 1118
- Joined: Tue May 06, 2008 2:00 am
- Location: England
Gowron said
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
work?
sorry to as but not very good with this kind of codingAt 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).
Code: Select all
C1 E3 03 is hex for shl ebx, 3
Code: Select all
C1 E8 01 shr eax, 1
-
- Code Master
- Posts: 304
- Joined: Sat Apr 26, 2008 2:00 am
- Location: 50° N, 11° E
Yes, that would work.
This is the statement that I'm using for BoP:
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.
This is the statement that I'm using for BoP:
Code: Select all
asm address hex code asm code
:00445B66 C1E803 shr eax, 03
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.
-
- Rear-Admiral
- Posts: 1118
- Joined: Tue May 06, 2008 2:00 am
- Location: England
-
- Rear-Admiral
- Posts: 1118
- Joined: Tue May 06, 2008 2:00 am
- Location: England
so replace 0x44F66
with for 1/8 return
or for 1/2 return
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
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
-
- Code Master
- Posts: 304
- Joined: Sat Apr 26, 2008 2:00 am
- Location: 50° N, 11° E
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.
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.
-
- Rear-Admiral
- Posts: 1118
- Joined: Tue May 06, 2008 2:00 am
- Location: England