dethrace-labs / dethrace

Reverse engineering the 1997 game "Carmageddon"
https://twitter.com/dethrace_labs
GNU General Public License v3.0
667 stars 38 forks source link

Cannot start dethrace from terminal (Windows) #351

Closed madebr closed 2 months ago

madebr commented 11 months ago

From discord:

strangely enough, on windows 10, running dethrace.exe directly from the explorer window works, but starting it from the command line doesn't :

D:\Carmageddon>Dethrace version: 8051ca2
Using root directory:
[PANIC] Harness_Init Failed to chdir. Error is Invalid argument
PierreMarieBaty commented 8 months ago

In src/harness/harness.c around line 182 after

    char* root_dir = getenv("DETHRACE_ROOT_DIR");
    if (root_dir != NULL) {
        LOG_INFO("DETHRACE_ROOT_DIR is set to '%s'", root_dir);
    } else {
        root_dir = OS_Dirname(argv[0]);
    }

I had to add this for macOS app bundle and Windows console support

    char* root_dir = getenv("DETHRACE_ROOT_DIR");
    if (root_dir != NULL) {
        LOG_INFO("DETHRACE_ROOT_DIR is set to '%s'", root_dir);
    } else {
        root_dir = OS_Dirname(argv[0]);
#ifdef __APPLE__
        strcat (root_dir, "/../Resources"); // Pierre-Marie Baty -- macOS .app fix
#endif /* __APPLE__ */
        if (root_dir[0] == 0)
            strcpy(root_dir, "."); // Pierre-Marie Baty -- consistency check (also Win32 fix)
    }

Basically calling chdir("") on Win32 raises an errno (which looks legit to me, what's intriguing here is that it swallows it on POSIX platforms).

madebr commented 8 months ago

The original issue is about Macos finder running applications from / instead of the directory containing the executable.

You're using a "macosx bundle", which our cmake script does not support at all. Somebody with an app should modify cmake + sources to add that. CMake has MACOSX_BUNDLE.

A complication with macosx bundles is that for legal reasons, we cannot bundle game resources with an app bundle.

PierreMarieBaty commented 8 months ago

Defaulting root_dir to "." when neither the DETHRACE_ROOT_DIR envvar is set nor OS_Dirname(argv[0]) fails to return a directory when argv[0] is just an executable name does prevent the issue described here, actually.

I understand and agree that proprietary game resources can't be distributed in a macOS app bundle, but the end user is still allowed to copy them there. That's what the DosBox .app bundle does. Dethrace could take advantage of that maybe?

I don't use the CMake script. I made my own build script in bourne shell for dethrace for POSIX platforms, so that I can compile the game with just a compiler and a linker as a requirement (and of course the needed system libraries). Sorry for diverging from the mainstream :/

Message ID: @.***>

madebr commented 8 months ago

No need to say sorry. If somebody with a mac and knowledge of CMake comes along, (s)he's free to add this support.

dethrace-labs commented 2 months ago

Fixed by https://github.com/dethrace-labs/dethrace/pull/381