EldenRingModLoader icon indicating copy to clipboard operation
EldenRingModLoader copied to clipboard

System DLLs are hardcoded to the C: drive

Open ketsuban opened this issue 2 years ago • 4 comments

I'm unfamiliar with Visual Studio; does it still work if you replace C:\\\\Windows with %SYSTEMROOT%? This is the usual way to get the location of the Windows folder regardless of which drive it's on.

ketsuban avatar Apr 05 '23 08:04 ketsuban

The linker comments are resolved at compile time, so using a macro or environment variable will only make it work for the setup that you have on the machine which it was built on.

I do have solutions for this issue coming up at some point though.

techiew avatar Apr 05 '23 14:04 techiew

hi I would love to fix this! I think you could do something like:

#include <Windows.h>

int main() {
    char buffer[MAX_PATH];
    UINT length = GetSystemDirectoryA(buffer, MAX_PATH);
    if (length > 0 && length < MAX_PATH) {
        // The path is stored in the 'buffer' variable
        printf("System directory: %s\n", buffer);
    } else {
        printf("Error retrieving system directory.\n");
    }
    return 0;
}

This should allow you to build all references dinput8.dll dynamically, agnostic to the system drive path. I'd love to add this in and make a pull request if you give me permissions.

rmilejcz avatar May 20 '24 16:05 rmilejcz

This does work, however this makes it so the forward exporting/proxying is done at runtime and could theoretically cause race conditions, unless combined with a waiting/spinlock mechanism when the proxy functions are called before the proxy is ready (which I have tried and then experienced issues in some cases, namely with late calls to GetProcAddress when third party hooks are involved).

That's why the exports are done the way they are now, statically declared at compile time, so there are no race conditions or other issues - except for the hardcoding to the C drive.

However I have made a library which deals with DLL proxying without all the ugliness and problems, which I will add to EML at some point, I just haven't been programming for a while. https://github.com/techiew/UniversalProxyDLL

techiew avatar May 22 '24 08:05 techiew

Could the following work at all?

I believe the env variable "SYSTEMDRIVE", this should return where ever the windows folder is located, example:

PS C:\Users\pceim> $env:SYSTEMDRIVE
C:
#include <stdlib.h>

// Function to retrieve the value of an environment variable
int getEnvVar(const char* name, char* buffer) {
    return GetEnvironmentVariable(name, buffer, MAX_PATH);
}

// Example usage in your DLL
char envVar[MAX_PATH];
getEnvVar("SYSTEMDRIVE", envVar);

I don't know if this gets around any of the conditions you mentioned that were causing issue~

It would be rather strange for someone to install on non C:\ drive letter.....

pceimpulsive avatar Jun 26 '24 13:06 pceimpulsive