Adjusting trade good output

Adjusting trade good output; support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
Nucky9
Ensign
Ensign
Posts: 20
Joined: Tue Sep 15, 2009 2:00 am

Adjusting trade good output

Post by Nucky9 »

I have read the topic dealing with trade good output, but I am not a good enough programmer to use that information to adjust trade good output to some variable other then the 100% given as an example.

Using UDM III as a starting point, I would like to adjust the income from trade goods to 33%.

Is this possible, and if so, can anyone give me guidelines on how to do this?
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 »

Try this, it should work for vanilla BotF, but I cannot guarantee that it works with the UDM.

Open trek.exe with a hex editor.

At position 0x5F84C, paste this code over the next 48 bytes (so byte 0x5F84C is the first byte to be overwritten):

Code: Select all

69 C0 A9 00 00 00 90 90 C1 E8 09 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 8B 29 90 90 90 90 90 90 90
At position 0x5FD10, paste this code over the next 48 bytes:

Code: Select all

69 C0 A9 00 00 00 90 90 C1 E8 09 C3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
At position 0x60301, paste this code over the next 34 bytes:

Code: Select all

69 C0 A9 00 00 00 90 90 C1 E8 09 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 8B 0A 90 90 90
At position 0x60394, paste this code over the next 36 bytes:

Code: Select all

69 C0 A9 00 00 00 90 90 C1 E8 09 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 8B 3A 90 90 90 90
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Nucky9
Ensign
Ensign
Posts: 20
Joined: Tue Sep 15, 2009 2:00 am

Post by Nucky9 »

Fantastic, it worked perfectly! Thank you very much for your help! Being able to make changes like these really helps breath new life into an old game.

You've already been a big help, but if you don't mind, I am curious how the operation works. Is it dividing the industry by three or something like that? Would it be possible to adjust the value in a fairly straightforward manner, or would any given value for the industry output require custom code?

Thanks again!
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 »

You're welcome :)

What this code does is actually a multiplication by 169, followed by a division by 512, resulting in a trade goods output equal to 33.008% of the industrial output.

Normally division is difficult to do in ASM, because most of the time it would use two registers (eax and edx). But division by a power of 2 can be done by a simple rightshift operation. That's why a factor of 169/512 is much easier to apply than 33/100, which would be exactly 33% (but 169/512 is still pretty close, much closer than e.g. 1/3).

There are two operations that you can modify if you want to:

1. the multiplication

Code: Select all

69 C0 A9 00 00 00
This multiplies by 0xA9 = 169(dec). If you want to change the factor, then you have to replace "A9 00 00 00" by the new factor in all four code sections. Note the little-endian format:
"01 00 00 00" = 1(dec)
"10 00 00 00" = 16(dec)
"00 01 00 00" = 256(dec)
"00 10 00 00" = 4096(dec)
"00 00 01 00" = 65536(dec)
etc.


2. the division

Code: Select all

C1 E8 09
This performs a division by 2^9 (=512). To change the divisor, replace the "09" by another number. For example, "05" would divide by 32, or "0A" would divide by 1024. If the result is not a whole number, then it is rounded down.
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Nucky9
Ensign
Ensign
Posts: 20
Joined: Tue Sep 15, 2009 2:00 am

Post by Nucky9 »

Prefect, just in case I need to do some tweaking. Again, I really appreciate your help!
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Converting Industry into Credits (conversion ratios)

Post by Spocks-cuddly-tribble »

In total there are eight code sequences: (default square root)
  • trade goods (preview, effective & for raiding amounts)
  • emergency trade goods forced due to 'credit deficit' (extra code during upgrade)
  • compensation trade goods during 'dilithium shortage'
  • scrapping revenues from buildings and ships
(dilithium shortage & scrapping ships is broken/unfinished)


The below concept uses a shared base ratio in percent, allowing for an easier control and editing.

For scrapping revenues, credit deficit & dilithium shortage(to-do) the result gets halved afterwards. This can be disabled via overwriting the 'SHR EAX, 1' statements (hex code D1E8) with 9090. But be especially careful with the ship scrapping revenue since this must be lower due to the auto-upgrade feature and possible ship building bonuses (for vanilla should be rather 'SHR EAX, 2' i.e. /4).


1. Trade Goods Preview (sub_460910)

Sets the shared base ratio in percent (rounded up) at 0x5FD15 (default 0x32).

The second code change by Gowron at 0x5FD10 (see above) has to be undone first!

Code: Select all

trek.exe at 0x5FD13 new code 0x29 bytes:

6B C0 32 89 04 24 DB 04 24 DC 0D 14 89 57 00 83 EC 08 DD 1C 24 E8 C7 CD 0B 00 E8 A2 CD 0B 00 DF 3C 24 8B 04 24 83 C4 0C C3

asm code:
00460913     6BC0 32         IMUL EAX, EAX, 32  // base ratio 50%
00460916     890424          MOV [ESP],  EAX
00460919     DB0424          FILD DWORD [ESP]
0046091C     DC0D 14895700   FMUL QWORD [578914]  // 0.01 credit multiplier
00460922     83EC 08         SUB ESP, 8
00460925     DD1C24          FSTP QWORD [ESP]
00460928     E8 C7CD0B00     CALL 51D6F4
0046092D     E8 A2CD0B00     CALL 51D6D4
00460932     DF3C24          FISTP QWORD [ESP]
00460935     8B0424          MOV EAX, [ESP]
00460938     83C4 0C         ADD ESP, 0C
0046093B     C3              RETN
2. Trade Goods Effective

Use #6. Adapting AI Trade Goods -> Trade Goods 1:1 only for AI
viewtopic.php?f=9&t=1805


3. Trade Goods for Raiding Amounts

Raiding bugfix #2 automatically adapts underlying system credit outputs:
viewtopic.php?p=33996&sid=ab6b31bf1d6b2 ... ff5#p33996


4. Credit Deficit

Code: Select all

trek.exe at 0x60301 new code 0x26 bytes:

E8 0A FA FF FF D1 E8 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 01 02

asm code:
00460F01     E8 0AFAFFFF   CALL 460910
00460F06     D1E8          SHR EAX, 1
00460F08-460F24     90     NOP
00460F25     0102          ADD [EDX], EAX
5. Credit Deficit (during upgrade)

Code: Select all

trek.exe at 0x5F84C new code 0x32 bytes:

E8 BF 04 00 00 D1 E8 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 01 01

asm code:
0046044C     E8 BF040000   CALL 460910
00460451     D1E8          SHR EAX, 1
00460453-46047B     90     NOP
0046047C     0101          ADD [ECX], EAX 
6. Dilithium Shortage

Still to do (when enabling the global dilithium pool), base ratio must at least be halved due to possible ship building bonuses.


7. Scrapping Buildings

First undo possible changes:
viewtopic.php?f=9&t=547

Code: Select all

trek.exe at 0x44F66 new code 0x2C bytes:

E8 A5 AD 01 00 D1 E8 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 01 07

asm code:
00445B66     E8 A5AD0100    CALL 460910
00445B6B     D1E8           SHR EAX, 1
00445B6D-445B8F     90      NOP
00445B90     0107           ADD [EDI], EAX
8. Scrapping Ships

Undo all changes from this topic:
viewtopic.php?p=26633&sid=ab6b31bf1d6b2 ... ff5#p26633
(if desired keep only the fix at 0x68794 i.e. the first of the three code changes)

Code: Select all

trek.exe at 0x6881B new code 0x1C bytes:

3B C1 75 1A 66 8B 84 24 1C 01 00 00 E8 E4 74 FF FF D1 E8 90 90 90 90 90 90 90 90 90

asm code:
0046941B     3BC1                 CMP EAX, ECX
0046941D     75 1A                JNZ 469439
0046941F     66:8B8424 1C010000   MOV AX, [ESP+11C]
00469427     E8 E474FFFF          CALL 460910
0046942C     D1E8                 SHR EAX, 1
0046942E-469436     90            NOP
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
WhiteCat
Cadet 2nd Year
Cadet 2nd Year
Posts: 9
Joined: Mon Jan 11, 2010 3:00 am

Re:

Post by WhiteCat »

Gowron wrote:Try this, it should work for vanilla BotF, but I cannot guarantee that it works with the UDM.
Could someone provide the code to set the Trade Goods credit output to a flat 50% of the industry output?
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7849
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Adjusting trade good output

Post by thunderchero »

WhiteCat wrote:Could someone provide the code to set the Trade Goods credit output to a flat 50% of the industry output?
here is what I would suggest from Gowrons 2 posts above

Open trek.exe with a hex editor.

At position 0x5F84C, paste this code over the next 48 bytes (so byte 0x5F84C is the first byte to be overwritten):

Code: Select all

69 C0 00 01 00 00 90 90 C1 E8 09 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 8B 29 90 90 90 90 90 90 90
At position 0x5FD10, paste this code over the next 48 bytes:

Code: Select all

69 C0 00 01 00 00 90 90 C1 E8 09 C3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
At position 0x60301, paste this code over the next 34 bytes:

Code: Select all

69 C0 00 01 00 00 90 90 C1 E8 09 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 8B 0A 90 90 90
At position 0x60394, paste this code over the next 36 bytes:

Code: Select all

69 C0 00 01 00 00 90 90 C1 E8 09 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 8B 3A 90 90 90 90
What this code does is actually a multiplication by 256 (69 C0 00 01), followed by a division by 512 (C1 E8 09), resulting in a trade goods output equal to 50.00% of the industrial output.
User avatar
WhiteCat
Cadet 2nd Year
Cadet 2nd Year
Posts: 9
Joined: Mon Jan 11, 2010 3:00 am

Re: Adjusting trade good output

Post by WhiteCat »

Thanks, but it looks like I actually need to modify the code at all eight of the locations that Spock's Cuddly Tribble identified. He talks about a "shared base ratio in percent," but I don't understand what that means, or how to adapt that to the desired credit ratio.

He also says that for locations 4-8 (i.e. everything except Trade Goods) "the result gets halved afterwards" -- does that mean that using his exact code will already provide the 50% credits that I'm looking for?

1) 0x5FD13 Trade goods preview ->
2) 0x60394 Trade goods effective ->
3) ??????? Trade goods raid -> Error Correction Mod will already make this calculation the same as #2?
4) 0x60301 Credit deficit ->
5) 0x5F84C Credit deficit (upgrade) ->
6) ??????? Dilithium shortage compensation ->
7) 0x44F66 Scrapping buildings ->
8) 0x6881B Scrapping ships ->
Post Reply

Return to “Adjusting trade good output”