Scrapping Buildings
Posted: Sun Dec 21, 2008 4:27 pm
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).
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).