Jump to content

Help needed - compile a .cpp file into a .dll


Recommended Posts

You can download Steamless binaries (see the Releases page). No need to compile that project :smile:

 

The addresses from source code are actually offsets. The base address is detected at run-time to compute the real address in memory (base + offset).

In IDA the base address for Fallout 4 executable is 0x140000000.

 

This means that for 0x0040D970 offset the address in IDA is 0x14040D970, while for 0x058CEE98 offset the address is 0x1458CEE98.

You can use the calculator to sum hex numbers, but is easier to remove a 0 from offset and to add 14 at the start.

 

Some tips:

 

1. Use Text View. If you're using Graph View then right click somewhere in the window and choose Text View.

2. Go to Options => General and there's an option to set the number of opcode bytes. By default is 0, change this to 10, so you'll see the bytes for each instruction.

3. By default the functions are named sub_XXXXXXXXX, where XXXXXXXXX is their address. If you know what a function does you can rename it (right click on the name) so will be easier to recognize. For example I've renamed all the functions used by Clipboard to wmk_cp_Enable_Native, wmk_cp_Disable_Native, wmk_cp_EffectShaderPlay etc...

4. Use Jump => Jump to Address (G key) to jump to an address.

5. Use X while a symbol is selected to see from where it is referenced.

 

You can download from here the executable from Fallout 1.10.98. And you should have one folder for each exe version.

Create an IDA project for each and open both projects in the same time. Jump to same address in both and then compare the bytes / instructions. In this way you'll see if an address has changed.

 

For example to find the new address for qword_145907F18 variable (the one that we had to change):

 

1. First change the name for all 5-6 functions in both projects (their address has not changed).

 

2. Go to 145907F18 address in the project for 1.10.98. You know that this is the address of that variable.

3. You'll find the symbol, rename it to wmk_cp_qword_145907F18 (or whatever).

4. Right click, Jump to xref to operand (or use X key) and you'll see that is used from Enable_Native (a function you renamed at step #1).

5. Go to that address (from where is used).

 

6. Then go to Enable_Natives in the project for 1.10.138.

7. Find the section of the code that looks like in 1.10.98 and you'll see the new variable => so you'll get the new address.

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Haha - it took me a while to get my head around it, but now I get it :D.

 

I messed up and had to delete the databases and start again, and each .exe file took nearly 20 minutes to fully finish decompiling or whatever it was doing.

 

I practiced it a few times and wrote down exactly what I did because I will forget it in a few days, so next time fallout4.exe changes I should be able to find the new address myself.

 

I really appreciate all your help Wolfmark, especially with the decompiling part because I know you didn't really want to go through all that - but you did anyway and I'm really grateful.

 

Many many thanks for everything.

Link to comment
Share on other sites

Update - All's well in Clipboard land, lots of people enjoying the hard work you did WolfMark.

 

Here's a link to the release page, you're welcome to drop in anytime, even if it's just to hang out.

 

https://www.nexusmods.com/fallout4/mods/39804/

 

Once again, without your help none of this would have been possible. I (and I believe many others who benefit from your work) cannot thank you enough, you're a fantastic person and I wish you all the best in life.

 

If you ever need ANYTHING, just ask.

 

Kind regards, Kev (OldBastard42).

Link to comment
Share on other sites

  • 4 months later...

Just in case anyone is still following this thread, here is an update.

 

I actually managed to figure out all the new addresses of the sub-routines and successfully recompiled Clipboard for F4SE v6.18 and Fallout4.exe v1.10.162 - yes, I'm as shocked/surprised as you lot!! :dance:.

 

Here's the updated info:

 

All sub-routine addresses have moved forward +hex120 bytes -
<_Enable_Native> now @0x0040DA90 (or 14040DA90 in IDA)
<_EffectShaderPlay> now @0x00422180 (or 140422180 in IDA)
<_Disable_Native> now @0x004E4420 (or 1404E4420 in IDA)
<_EffectShaderStop>now @0x00F0E060 (or 140F0E060 in IDA)
The "scale" sub-routine has moved to 0x03F85B0 (or 1403F85B0 in IDA)
qword_145907F18 remains unchanged (58CEE98), and can be found at address 0x058CEE98 (or 1458CEE98 in IDA).

 

I managed to find the new location of the <_Enable_Native> sub-routine in IDA by searching for it's machine code:

88 54 24 10 48 89 4C 24 08 56 48 83 EC 60 8B 41 10 48 8B F1 C1 E8 0B A8 01

...then simply worked my way backwards to find all the other values.

 

Once again, many thanks to Wolfmark for giving me the "tools" to get the job done, without his help none of this would have been possible.

 

Regards,

 

Kev (oldb@stard42)

Link to comment
Share on other sites

Sitting in the back of a car on the way to Boston, I just read this entire thread. This is magical, and I am so inspired, and I think I'm going to use the information in this thread to try again to write an F4SE plugin!

 

Also Wolfmark, you are a heckin' patient guy, thank you so much for all of your explanations!

Link to comment
Share on other sites

  • 2 weeks later...

Follow my first 2-3 posts on this thread to setup Visual Studio and the F4SE solution.

By default F4SE is build as a shared library (the result is a DLL) and for creating extensions it must be build as a static library (the result being a LIB file).

 

Then add an existing extension for which you can find the source code and the Visual Studio project. There are few: Clipboard Resurrection, Extended Dialogue Interface, Active Effects on HUD, MCM etc...

See if you can build it. Clipboard Resurrection requires changes to F4SE code, so you may skip it.

 

Then remove all the code and keep only the F4SEPlugin_Query and F4SEPlugin_Load functions. These are the ones called by F4SE when it loads an extension. Each F4SE extension must export these 2 functions.

Then start from here.

 

There's no documentation, so download the source code for any F4SE extension you can find. Even SKSE source code (the project and existing extensions) is useful.

Compiling an extension is easy, you don't need programming skills. Writing one is a different thing.

Edited by Wolfmark
Link to comment
Share on other sites

ScriptHook for Grand Theft Auto V has a comprehensive database of game native functions at https://www.dev-c.com/nativedb/.. Why hasn't anyone bothered to do the same for F4SE? This is mostly a rhetorical question... but really, I would never have been able to write a GTA mod if the documentation had been, "figure out every function call on your own"...

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...