Upgrading buildings bug (fix)

Upgrading buildings bug (fix) above 65535 credits; support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Upgrading buildings bug (fix)

Post by DCER »

There's a function in botf that calculates the upgrade cost. The result is then used in multiple places as a short instead of integer. This fixes all but two of them which in my testing weren't used for the building I was upgrading. Maybe the AI uses those. So unless I left out a fix these changes will let you upgrade buildings when the upgrade cost goes above 65635 and the right amount of credits will be taken from your treasury as well:


EDIT: This fix code is incomplete. See below.


At 0x5EAE9:

66 89 F8

replace with

90 89 F8

At 0x5FAC8:

66 89 C2

replace with

90 89 C2

At 0x5FAEB:

66 89 56 04 31 D2 66 8B 56 04

replace with

90 89 56 04 90 90 90 90 90 90

At 0x5FB03:

66 01 42 2A

replace with

90 01 42 2A


I'll probably check the other two later today. It's 3 am here and I need some sleep :) Let me know if this works! :)
Last edited by DCER on Wed Oct 29, 2008 7:41 am, edited 1 time in total.
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Post by DCER »

Ok, tested the other two.

One is used when you buy a ship. Since ship cost is a short value this doesn't need fixing.

The other one is used when a building is built for the first time. Because it's cost is also always a short this doesn't need fixing either.
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Re: Upgrading buildings bug (fix)

Post by DCER »

Spocks-cuddly-tribble wrote:
DCER wrote: Let me know if this works! :)
I just updated 60 8O Class 9 klingon Foundries (total cost of 142.200) without any problem. :)

That would be entirely sufficient even for the massive UDM3 and UM4 populations. :wink:

Btw what's the current upper limit?


We can't thank you enough for fixing this (almost 10 years nerving) bug. :D
:D The limit is at least 2,147,483,647 credits. It'll probably be enough for a while :)
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 »

cooool!
That's an improvement I've awaited for a very long time! 8O
You've really great experience in disassembling and analysing that code, DCER! I've to take my hat off cause that assemblercode hurts my head.
Thank ya and keep up the great work.

With your knowledge, might it even be possible to figure out which piece of code is calling for example the tactical fight as well as figure out the corresponding data about fleets and stuff and instead call own functions being implemented in external libraries?
So replace internal trek.exe functions with external own ones? Whoo, that might open doors... :roll:
Theoretical I believe it should be possible, but you've much more practical experience (just a theoretical question about practice, not limited to tactical fight ;)).

I'm currently having lots to do for universaty, but I'll continue on my projects soon again.
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Post by DCER »

You're overestimating my knowledge, Flocke :) I'm sure it's possible to insert calls to dlls into the code, I think modders do this for Diablo II, but I don't know how it's done.
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Post by DCER »

To get this to work you need a hex editor.

To learn some basics about hex editing read "First you need to know this" (ignore the info about shiplist editing)
http://members.aon.at/zelli/shiplist.htm

Find a free hex editor to use and open trek.exe with it (make a backup first) then just follow the instructions in my first post. Just make sure you are replacing bytes not inserting them and make sure you are replacing the right bytes. One false move and you can make trek.exe crash.

The addresses are expressed in hex, you can use windows calculator to convert them to decimal (scientific mode)

Hope this helps. Btw. version 1.0.3 has this fix (among others) applied to it already.
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.

Post by thunderchero »

DCER wrote:Ok, tested the other two.

One is used when you buy a ship. Since ship cost is a short value this doesn't need fixing.

The other one is used when a building is built for the first time. Because it's cost is also always a short this doesn't need fixing either.
not sure if this is what I am getting

but here is what is happing to my mod.

I have raised cost of all ships and top class with build cost of as high as 36792 here is screen shot of ue of vor'cha


notice build cost of 35807

here is ingame image of vor'cha build cost


it shows build cost of -29729

But when I buy ship it show right build cost



I can buy ship and it will build with no problems in correct time but display wrong.

was there a fix for this?

thunderchero
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Post by DCER »

No, I haven't even noticed it at the time.

I took a look at the 43DEE0 function again and from where it's called. Here are the rest of the fixes just to be on the safe side:

At 0x5F4E5, and 0x5FEDF replace 66 with 90

This however won't fix the display bug, to fix that one go to 0x17EBE2 an change 0x64 to 0x75
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.

Post by thunderchero »

thanks Dcer,

will check out tonight

Edited exe and works great thanks DCER.

also got your new rank done tonight. You and Gowron deserve them.

thunderchero
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Post by DCER »

Good to hear. I was getting worried it wasn't working. :)
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.

Post by thunderchero »

I just ran 3 tests and you may buy anything above 65635 credit, The game will stop adding industry per turn after more than 65635.

But the turn before going over 65635 all industry will be added for that turn. Example current invested 65620, industry per turn 3000 you will have 68620 invested but will get stuck at that point. And no longer adding industry per turn for that build.

thunderchero
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

re;

Post by Spocks-cuddly-tribble »

Using this info I got it to work now: :)

systInfo:
+0x80 = ORDER ECONOMY (typeID)
+0x84 = invested industry
+0x88 = ID of building/ship under construction


I'll summarise all needed code changes, including those by DCER (redundant data was omitted ->single buildings/ships).


:arrow: At all locations change 0x66 to 0x90 (unless otherwise instructed):


=> Buy Cost calculation fix:

43E000 mov ax, [ebx+4] -> 0x3D400
43E03A mov ax, [ebx+4] -> 0x3D43A

=> Buy cost preview fix:

45F6E9 mov ax, di -> 0x5EAE9

=> Effective build/buy cost fix:

46055B mov ax, [esi+4] -> 0x5F95B
460566 jbe loc_46089B -> 0x5F966 change 0F 86 to 90 E9
4606C8 mov dx, ax -> 0x5FAC8
4606EB mov [esi+4], dx -> 0x5FAEB
4606F1 mov dx, [esi+4] -> 0x5FAF1
460703 add [edx+2Ah], ax -> 0x5FB03
4608A2 mov ax, [edx+2Ch] -> 0x5FCA2
4608A6 add [esi+4], ax -> 0x5FCA6

=> Sumary / Systems -> "X Turn(s)" fix:

44195F mov ax, [ecx+4] -> 0x40D5F
441A4D mov ax, [ecx+4] -> 0x40E4D

=> Production Queue -> "Turns Remaining X" fix:

4F2E57 mov ax, [esp+22Ch] -> 0xF2257

=> "Industry Invested" display fix:

4FD998 mov dx, [edi+84h] -> 0xFCD98
4FD99F test dx, dx -> 0xFCD9F
4FD9B3 mov ax, dx -> 0xFCDB3

=> high morale bonuses fix:

0043FA55 mov dx, [ecx+4] // 0x3EE55
0043FA62 mov [ecx+4], dx // 0x3EE62

=> Ship stats build cost above 32767 fix:

0x17EBE2 -> change 0x64 to 0x75
Last edited by Spocks-cuddly-tribble on Mon Apr 19, 2010 4:17 pm, edited 2 times in total.
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
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.

Post by thunderchero »

Spocks-cuddly-tribble,

Great job :D I just tested on latest version of UDM with out any problems.

Also I tested ship building and it looks like it special structure is still giving credit as it should (for ship building only) But as before it is not shown on time left to build.

this used old code by DCER already, so some changes were not needed.
Spocks-cuddly-tribble wrote:I'll summarise all needed code changes, including those by DCER (redundant data was omitted ->single buildings/ships).
Just wondering, The changes in old code DCER created should they be done first? (as in my test) or are only new changes needed? Or does it matter? Should I go back and reset code before making your changes?

thunderchero

Spocks-cuddly-tribble wrote:This is the only difference (unimportant deviation):
DCER wrote:At 0x5FAEB:

66 89 56 04 31 D2 66 8B 56 04

replace with

90 89 56 04 90 90 90 90 90 90
My:
4606EB mov [esi+4], dx -> 0x5FAEB
xor edx, edx -> not removed
4606F1 mov dx, [esi+4] -> 0x5FAF1 -> not removed
DCER wrote:At 0x5F4E5, and 0x5FEDF replace 66 with 90
Redundant -> omitted
User avatar
Bigmac57
Cadet 4th Year
Cadet 4th Year
Posts: 18
Joined: Tue Jan 20, 2009 3:00 am

Post by Bigmac57 »

I made the changes in the first post and am not sure how to do the additional ones.

Could a second post be added for that?

Thank you!
Spocks-cuddly-tribble wrote:1.) Download a hex editor like for example HxD.

2.) Enter the above advised BOLD addresses (without 0x - this only means make sure your offset base is set to hexadecimal).

3.) Follow my instruction above:
Spocks-cuddly-tribble wrote: :arrow: At all locations change 0x66 to 0x90 (unless otherwise instructed):
Done.

Based on the first post, I changed the code at the locations referenced by DCER.

I have now also made all the changes you described in your post.

At some locations, the value was already "90" and that must be because those initial changes were already made (DCER's code changes).

Thank you very much.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Upgrading buildings bug (fix)

Post by Spocks-cuddly-tribble »

Update: (included in the main fix post)

high morale bonuses fix:

0043FA55 mov dx, [ecx+4] // 0x3EE55
0043FA62 mov [ecx+4], dx // 0x3EE62
-> 66 -> 90 each
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
Post Reply

Return to “Upgrading buildings bug (fix) above 65535 credits”