Extra code space using relocation table

General Modding Information/Questions; support/discussion/questions

Moderator: thunderchero

Forum rules
:idea: Please search before starting new topic. :idea:
There is a good chance it has already been asked.
Post Reply
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7848
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Extra code space using relocation table

Post by thunderchero »

Hi Everyone,

As Flocke suggested here I was able to use the relocation table to add new code to the game.

This can be used in many different ways,

1. It will allow small code changes without moving code to make more space.
2. you could inject changes like was done with X Y project
3. complete sub-sections could be moved into new code space to make major changes. example; Tethys would like to add new map size (small med, large and extra large)

The possibilities are really unlimited with enough time and effort.

I have tested using,
E8 (call sub) with C3 return
E9 Jump with E9 jump to return (return should be able to go to different location)

I am also confident if written properly other jump statement types could be used to cmp different needs also.

here is the small patch to edit the header info
relocation2.patch
(1.15 KiB) Downloaded 136 times
here is full patch that will zero full relocation table
relocation3.patch
(590.91 KiB) Downloaded 136 times
here is a patch if energy screen project (14 per type) is already installed this will zero the remainder of the table
relocation4.patch
(584.92 KiB) Downloaded 140 times
When setting up code to be added you will need to calculate the offset to be call/jump

I found it easiest to use OllyDbg and let it give you the hex values to use.

first you will need the both the Hexadecimal address and Botf assembler offset of the locations call/jump statement and start of new code/return location. UE will give you these offsets.

once you have written call/jump statement and any number to complete statement and save edited trek.exe

next open edited trek.exe with OllyDbg and use "goto" function to go to location of call/jump statement using the Botf assembler offset.
goto.jpg
goto.jpg (284.36 KiB) Viewed 4151 times
Right click on call/jump statement line and select assemble
change.jpg
change.jpg (314.53 KiB) Viewed 4151 times
in new window change the last 6 to the Botf assembler offset you want call/jump to go to
then select assemble
new_hex.jpg
new_hex.jpg (303.44 KiB) Viewed 4151 times
After that the new hex code to be added will be highlighted red in second column.

add changes to trek.exe and save when you are ready.

Also to those who plan on using this section we should work together so we know where code is planned to be used.

example 0x0019f400 - 0x0019f71f should not be used and reserved for energy screen project.
Soon I would also like to reserve space for the X Y project. (will post code range soon)

with 77,000 byte available in this new section we could also assign areas to member who are currently doing projects.

I hope you have found this useful
thunderchero

List of reserved code locations
data space
energy screen project table 0x0019f400 - 0x0019f71f (800 bytes)
Build Queue project table 0x0019f720 - 0x019f7df (192 bytes) 16 x 12
minors on left data 0x0019f7e0 - 0x0019f7ef (16 bytes)
code space
Build Queue project 0x01a0400 - 0x01a162f (560 bytes)
Build Queue project 0x1A0800 - 0x1A081f (32 bytes)
Irregular galaxies patch 0x001a17cf - 0x001a1530 (672 bytes)
minors on left patch 0x001a17d0 - 0x01a17ff (48 bytes)
Tethys 0x01a1800 - 0x01a27ff (4096)
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3196
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Extra code space using relocation table

Post by Flocke »

great work, next give it another try to add one section and double the AUTO code space :D
just place it after the last section there but don't forget to increase the exe size along with the raw size for the new section
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7848
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Extra code space using relocation table

Post by thunderchero »

Flocke wrote: Thu Apr 15, 2021 5:07 pm great work, next give it another try to add one section and double the AUTO code space :D
just place it after the last section there but don't forget to increase the exe size along with the raw size for the new section
maybe when we use up what we have now. :grin:

here is my reserve area of code 0x01a0000 - 0x01a0e0f (3600 bytes)

I will use the area for my X Y project and my long term project of fixing the taskforce patch.
after analyzing the patch I think I see the issue, problem is the current patch is un-fixable. So I am starting over but I am able to use current patch as a guide to the locations that require editing. QD only edited the ship ID to 4 - 2 bytes, new code will require TF ID, # of ships in TF and ship ID to all be edited 4 - 2 bytes. bonus doing changes this way would be 20 ship taskforce. but will require 3 times the code changes as original patch.


wish me luck
thunderchero
User avatar
Tethys
Past Administrator
Past Administrator
Posts: 2392
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: Extra code space using relocation table

Post by Tethys »

thunderchero wrote: Thu Apr 15, 2021 10:29 pm maybe when we use up what we have now. :grin:

here is my reserve area of code 0x01a0400 - 0x01a17ff (4096)

wish me luck
thunderchero
Good luck. I am starting my section at 0x01a1800 - 0x01a27ff (4096 bytes)
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3196
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Extra code space using relocation table

Post by Flocke »

Good luck to both of you!

Indeed the relocation section already offers quite some space. What I am not sure is how much it affects the disassembling like with ida. But if I'm correct, for modded code it is rather a benefit to have it removed when the relocation table hasn't been updated anyhow.

Edit: I now checked on the assembler instructions. E9 indeed is a relative near jump that you need to calculate relative to the subsequent instruction offset. If I get it right, the EIP instruction pointer already moves to next instruction while executed, so it needs to be subtracted from your offset.

I further looked into the other jump ops, but jumping to an absolute address is not the preferred asm op, and requires you to first load the address to a register like so:

Code: Select all

CPU Disasm
Address     Hex dump                   Command                                  Comments
77C1162B      B8 FFEE2211              mov     eax, 1122EEFF
77C11630      FFE0                     jmp     eax
And the jmp far which I thought would be appropriate, has a complete different purpose. It could be used but you better don't mess with it. It works with selectors for indexing different memory segments defined by the os you use, mostly for differentiating the kernel and user access privileges. The best article I found on far jumps is: https://alex.dzyoba.com/blog/os-segmentation/

Better just stay with E9 relative near jumps. :roll:
The conditional near jumps of course work too.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1883
Joined: Sun Apr 27, 2008 2:00 am

Re: Extra code space using relocation table

Post by Spocks-cuddly-tribble »

Flocke wrote: Fri Apr 16, 2021 3:25 amWhat I am not sure is how much it affects the disassembling like with ida. But if I'm correct, for modded code it is rather a benefit to have it removed when the relocation table hasn't been updated anyhow.
Sometimes I was under the impression that some of my patches, who change code locations of absolute asm pointers, messed up the OllyDbg code analysis (still using the now broken relocation table).

But I never tested the IDA or OllyDgb analysis with removed and disabled relocation table. Could be a change for the better or worse or no effect.


Anyway, having the relocation table removed, thunderchero cannot use it's admin privileges to relocate you to the gulag, as penalty for kicking off projects and then letting do others the heavy lifting.... :wink: :wink:

And no, I'm not looking into java programming (learning the syntax sucks). Travelling to java however would be more my cup of tea.... :smile:
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3196
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Extra code space using relocation table

Post by Flocke »

Spocks-cuddly-tribble wrote: Fri Apr 16, 2021 10:11 am Anyway, having the relocation table removed, thunderchero cannot use it's admin privileges to relocate you to the gulag, as penalty for kicking off projects and then letting do others the heavy lifting.... :wink: :wink:
I already got promoted once, will I next become the super borg? :lol:

But yeah, Java never has been my favored programming language either. Much closer to asm coding indeed is C++ coding and the ugly old C coding.
There you can compile and investigate the asm machine code, or you can do neat incomprehensible inline assembler hacks if you prefer. :wink: :wink:
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7848
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Extra code space using relocation table

Post by thunderchero »

Hi Everyone,

I have updated the patch to split the relocation table so we can have a dedicated data area.
data area
0x0019f400 - 0x01a03ff (4096 bytes)
code area
0x01a0400 - 0x01b23ff (73728 bytes)

see first post for updated patch

use bof-patcher to remove old patch before installing new patch.

thunderchero
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7848
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Extra code space using relocation table

Post by thunderchero »

Hi everyone,

I have added 2 patches to first topic that will zero out the relocation table.
one that will do complete table and one that will zero out area after the energy screen project (14 objects per type)

this should help applying some of the new patches that require relocation table.

thunderchero
User avatar
borgpow
Ensign
Ensign
Posts: 41
Joined: Thu May 08, 2008 2:00 am

Re: Extra code space using relocation table

Post by borgpow »

i have a question which relocation patch do i use if i want to try the build queue project and do i need to fill in 00 in hex editor if all i want to do is the build queue i also have the energy project patch installed
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7848
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Extra code space using relocation table

Post by thunderchero »

follow instructions here
viewtopic.php?p=53977#p53977

each patch folder has a relocation patch (1 relocation patch for with energy screen and 1 relocation patch for without energy screen)
both patches will fill relocation area with 00's
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1883
Joined: Sun Apr 27, 2008 2:00 am

Re: Extra code space using relocation table

Post by Spocks-cuddly-tribble »

A nice little video on the relocation table in old DOS games like DOOM: https://www.youtube.com/watch?v=MTa3diypjv4&t=223s

Corrupting base pointers in BotF's main code leads to serious malfunctions. On the other hand, even vanilla shows increased instability if relocated from it's preferred address. Just a wild guess, but I think there is bugs in the original relocation table...
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
Tethys
Past Administrator
Past Administrator
Posts: 2392
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: Extra code space using relocation table

Post by Tethys »

0x01a2800 - 0x01a47ff (8192 bytes) for new Bar Spiral shape + new arms

If anyone is using this area please speak so we can coordinate thank you :)
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
Post Reply

Return to “General Modding Information/Questions”