Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

Any coders here with experience in DLL hooking?

Self-Ejected

Drog Black Tooth

Self-Ejected
Joined
Feb 20, 2008
Messages
2,636
I basically want to remake the unofficial Arcanum patch as a ddraw.dll hook. Kinda like sfall for Fallout or Temple+ for ToEE. You'd have an INI file where you can turn things on/off, like high resolution, windowed mode, software rendering, level cap, sprite mirroring, combat music, intro movies etc. Or turn additional mods on/off, like Virgil's Debug Menu, extra effects for the Pyro bow, annoying spell effects remover, extra riddles for the ancient game quest and many other loose mods I still have on my HDD.

I've tried doing basic DLL hooking back then and it works, but I was doing that in pure ASM and it's just not very productive.

We could even package the whole UAP into a single data file and include a switch to turn the whole thing on/off.

Or make a launcher/settings app where you can set whatever you want and launch the game.

Any helpers? Let's do it, I'll share the sources. This would increase the compatibility a lot and make the installation very simple. It'd work with Steam and GOG versions without altering any of the files.
 
Last edited:
Self-Ejected

Drog Black Tooth

Self-Ejected
Joined
Feb 20, 2008
Messages
2,636
I'm thinking about just doing a basic hook in ddraw.dll to a custom DLL that I would write in C++. It would read an INI file and patch variables in memory. I could include the whole high resolution patch in its entirety and make the game run in the user's desktop resolution by default. Then there would be a settings app with tick boxes and stuffies to turn various engine mods (like level cap) on and off, it would just write to the INI file and not do anything fancy itself. All of this should be pretty simple to do, I can do this myself.

The one thing that I'd love to try as well is to make a Bethesda game like mod launcher. It would list all custom DAT files (which you put in some specific mod folder like \UAP) and then you can enable and disable them, change the load order etc. And if you run the game without the DLL hook they won't be loaded at all, thus giving you the one click switch between vanilla and the UAP at any point. But this could be beyond my coding ability.

Any ideas? We already have Unix fags protesting the idea of DLL hooking in another thread lol.
 

Pugmeister

Educated
Patron
Joined
May 1, 2015
Messages
65
So there are a few options.

You could actually go with C++/CLI and mix it strongly with C# to make your life just *that* much easier.
It's also possible to go pure C#, but I would recommend against that since it makes hooking a pain in the ass.

For actually hooking existing functions, this is what you want:
https://github.com/TsudaKageyu/minhook

To get your own DLL to load before anything interesting happens in Arcanum, there are actually multiple options.
You can do a separate launcher EXE (think SKSE for Skyrim), which means you don't need to overwrite an existing DLL (ddraw.dll),
or you could use the usual ddraw.dll override that is similar to what the ENB shader mods do it. Personally I don't like this approach as much,
since it means you have to implement useless stubs, and it's harder to disable/enable the hooks.

Does Arcanum use a setup similar to that of ToEE (minimal exe + fat game dll)? Or is it just one big fat Arcanum.exe?
If it's an exe, injecting your stuff with your custom EXE launcher is *slightly* more involved, but not terribly so. If you wanna go
down that route, let me know, I can probably help with more details.

We have some additional helper stuff in ToEE that you might want to grab for yourself:

For accessing stuff from the base game:
https://github.com/GrognardsFromHell/TemplePlus/blob/master/Temple/src/dll.cpp
https://github.com/GrognardsFromHell/TemplePlus/blob/master/Temple/include/temple/dll.h

For replacing stuff (redirecting jumps etc.):
https://github.com/GrognardsFromHell/TemplePlus/blob/master/TemplePlus/util/fixes.cpp
https://github.com/GrognardsFromHell/TemplePlus/blob/master/TemplePlus/util/fixes.h

It's a pretty broad topic, so just feel free to ask any specific questions :)
 
Self-Ejected

Drog Black Tooth

Self-Ejected
Joined
Feb 20, 2008
Messages
2,636
Pugmeister

Thanks for dropping by bro!

All game code is in Arcanum.exe, there's no fat ass DLL like in ToEE. The code starts at 0x400000 in memory like in many old games. Pretty much you just add 0x400000 to whatever address you have in Arcanum.exe to get the same thing in memory.

Now, I've tried the following to test it out. I just copied ddraw.dll to the same folder as Arcanum.exe, added an extra jump to the end of the file in ddraw.dll, and then added some simple code in ASM that would patch shit in memory.

And lo and behold, it worked, I was able to switch off the sprite mirroring without modifying Arcanum.exe.

Now, I either need a way to add compiled code to ddraw.dll or make it load another DLL, because just the high resolution patch alone takes hundreds of lines of code and it's just not feasible to hex edit it line by line in ASM.
 
Last edited:

Pugmeister

Educated
Patron
Joined
May 1, 2015
Messages
65
Would you prefer to still go with a ddraw.dll drop-in? (You'd need to build a new ddraw.dll that delegates all existing methods to the real ddraw.dll, plus run any of your own code).
Or would you prefer a separate exe to launch?

I can help you with both.
 
Self-Ejected

Drog Black Tooth

Self-Ejected
Joined
Feb 20, 2008
Messages
2,636
Pugmeister turned out to be an open source fanatic that tried to pressure me to post all my notes in a forum thread. lolwat, fuck off faggot

Guess I'll just do it myself, less worries that way.
 

Pugmeister

Educated
Patron
Joined
May 1, 2015
Messages
65
Well, I am very sorry for not wanting to contribute to your closed source project.

Regardless, I wish you the best of luck for your endeavor.
 

Bester

⚰️☠️⚱️
Patron
Vatnik
Joined
Sep 28, 2014
Messages
10,992
Location
USSR
Pugmeister turned out to be an open source fanatic that tried to pressure me to post all my notes in a forum thread. lolwat, fuck off faggot
It's not like releasing sources for a fucking mod doesn't endanger our entire species. Such secrets must be protected, lest unprepared eyes gaze onto the code, photons literally bouncing from lines of code into the eyes of the unprepared, such abominable things must not be allowed.
 

Hoaxmetal

Arcane
Joined
Jul 19, 2009
Messages
9,157
What if Drog writes erotic Arcanum fanfiction in the code comments? A man has right to privacy.
 

Absinthe

Arcane
Joined
Jan 6, 2012
Messages
4,062
Pugmeister turned out to be an open source fanatic that tried to pressure me to post all my notes in a forum thread. lolwat, fuck off faggot

Guess I'll just do it myself, less worries that way.
You realize pug doesn't owe you shit, right? He's welcome to set his own stipulations for helping you and you're welcome to turn him down.

It's not like releasing sources for a fucking mod doesn't endanger our entire species. Such secrets must be protected, lest unprepared eyes gaze onto the code, photons literally bouncing from lines of code into the eyes of the unprepared, such abominable things must not be allowed.
Honestly I don't know how Drog got his panties in a twist about open-sourcing the mod either. It's not like he's ever going to be making money off of that shit. The only thing it would do is help a few others make their own mods.
 

puppyonastik

Augur
Joined
Aug 3, 2004
Messages
175
Location
Northern Illinois
Pugmeister turned out to be an open source fanatic that tried to pressure me to post all my notes in a forum thread. lolwat, fuck off faggot

Guess I'll just do it myself, less worries that way.

I don't see why you two gentlemen can't come to an agreement over a helping of coke and hookers? FOR THE GOOD OF THE COMMUNITY!
:mob:

Edit: Here's hoping that this disagreement is a joke and you both have some surprise in tow.
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
Any ideas? We already have Unix fags protesting the idea of DLL hooking in another thread lol.

Why? You can do the same thing with Shared Objects.
For me, it's because wine. While i can enforce a certain dll loading/substitution order there and it's often enough to make these kind of loaders work (i suppose, especially if they are stubs to the system one with hooks and the dll is not just that important like in bloodlines which is some printer thing or whatever), often on the more complex one it will not work (for example to this day, Morrowind Script Extender and that other one bundling that and the distance hack - will not work. They pretend to work, but actually all advanced functions are writing to garbage memory).

The only real way to be sure is testing i suppose. And it obviously depends on the ambition of the hacks. It's not very surprising that MWSE doesn't work and the Bloodlines pre-loading dll patching does imo, considering one interacts directly with directx and weird interprocess pipes (for persistent io in MWSE).

I'm actually satisfied by the current Arcanum patch (though i haven't played the game in years) so even if it becomes incompatible, i will not find it a big deal thou.
 
Last edited:

Pugmeister

Educated
Patron
Joined
May 1, 2015
Messages
65
What I would usually do for a separate EXE loader is the pretty standard way (using documented APIs) of doing CreateProcess with the main thread starting in suspended state. Then just go ahead and hook WinMain in the remote process to LoadLibrary the injection DLL, then proceed to hook functions/write memory from DllMain as-usual.
I don't see why this wouldn't work on Wine to be honest, since it's using pretty normal Win32 API functions.
In Temple+ the more serious issue we've had is that previous DLL hacks ignored the possibility of temple.dll loading at a different base address, which leads to super strange crashes when that actually happens. And once we started linking against a bunch more DLLs, it almost always happened. We did figure out a way of fixing this in the end, but for a game like Arcanum that uses a fat-exe which is not relocatable anyway, this would not be an issue.
But even in those cases I think it's probably good practice to not use static memory addresses and account for the actual base address at which the exe got loaded.
I do believe we might have Wine compat issues in Temle+ that don't actually stem from the hooking/injection but rather from us porting the graphics engine over to DX11 and using a .NET based launcher/patcher.
 
Self-Ejected

Drog Black Tooth

Self-Ejected
Joined
Feb 20, 2008
Messages
2,636
Honestly I don't know how Drog got his panties in a twist about open-sourcing the mod either. It's not like he's ever going to be making money off of that shit. The only thing it would do is help a few others make their own mods.
Some people are just uncomfortable with exposing their workflow or to be more frank with giving away their hard work for the community to bastardize.

Ask Wesp or other modders, why don't they provide sources for their shit.

I mean, my engine mods were always closed source and the high res patch script was obfuscated, you knew how I worked, why this sudden push to go open source and post everything that I have/want to do in this thread?

Fuck you. All I gotta say on the subject.

I'll gladly share the sources and all the cool stuffies with an experienced coder willing to help the project, tho.
 
Self-Ejected

Drog Black Tooth

Self-Ejected
Joined
Feb 20, 2008
Messages
2,636
You know what. Here's how we're gonna roll.

Here's a simple test. If anybody passes it, I'll PM them and work together with them.

Produce a ddraw.dll that patches Arcanum.exe in memory and reads an INI file with settings. Include a single setting of your choosing. Whatever you want, it could be a god mode hack for all I care. Just prove that you can write a DLL hook that patches Arcanum.exe and reads from an INI file.

That is all.
 
Unwanted

cucrophi

Unwanted
Queued Shitposter
Joined
Jan 7, 2017
Messages
26
Christ, Drog.
Whats the point of replacing the dll to just patch Arcanum.exe?
Puggo already told you: CreateProcess, WriteProcessMemory, Done. The dumbest loader in existence. VirtualAllocEx if you need space.
 

Mustawd

Guest
You know what. Here's how we're gonna roll.

Here's a simple test. If anybody passes it, I'll PM them and work together with them.

Produce a ddraw.dll that patches Arcanum.exe in memory and reads an INI file with settings. Include a single setting of your choosing. Whatever you want, it could be a god mode hack for all I care. Just prove that you can write a DLL hook that patches Arcanum.exe and reads from an INI file.

That is all.


Check your PMs.

I didn't send you anything, but just reminding you to check. You never know.
 

Black

Arcane
Joined
May 8, 2007
Messages
1,872,592
I love how even a thread about coders-wanted gets its share of drama. Truly Codex is a magickal place.
 

Absinthe

Arcane
Joined
Jan 6, 2012
Messages
4,062

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom