Skip to content

Pass on shell environment variables to launched game #2212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
W-Drew opened this issue Feb 22, 2025 · 1 comment
Open

Pass on shell environment variables to launched game #2212

W-Drew opened this issue Feb 22, 2025 · 1 comment
Labels
Feature Request User submitted feature request.

Comments

@W-Drew
Copy link

W-Drew commented Feb 22, 2025

Normally when debugging non-Mod Organizer applications, I can launch with session-specific environment variables. If I were to do this with Skyrim outside of Mod Organizer, it might looks something like:

  1. As a mod developer, I can create a number of saves in different game locations to quickly test different parts of my mod
  2. In my IDE, I can create launch presets which depending on the preset sets an environment variable such as "DevAutoLoadSave": "RiverwoodTest" which only applies to the current shell
  3. In my mod, I can read the DevAutoLoadSave at runtime and automatically load that save on startup rather than having to manually type load RiverwoodTest in the console (particularly useful in VR where the console is difficult to use with a headset on)

Obviously MO interrupts this as a middleman though. It would be nice if the environment from the shell MO was launched in was mirrored to the launched game.

Potential tie-in with #2196

@W-Drew W-Drew added the Feature Request User submitted feature request. label Feb 22, 2025
@metacubed
Copy link

Disclaimer: I'm not a MO2 maintainer, just a random user.

Looking at the process spawning code, it passes a NULL to the environment block (7th parameter) of CreateProcess.

modorganizer/src/spawn.cpp

Lines 459 to 467 in d2832ec

if (sp.hooked) {
success = ::usvfsCreateProcessHooked(
nullptr, const_cast<wchar_t*>(wcommandLine.c_str()), nullptr, nullptr,
inheritHandles, flags, nullptr, wcwd.c_str(), &si, &pi);
} else {
success = ::CreateProcess(nullptr, const_cast<wchar_t*>(wcommandLine.c_str()),
nullptr, nullptr, inheritHandles, flags, nullptr,
wcwd.c_str(), &si, &pi);
}

This means that environment variables from MO2 would get automatically inherited by any spawned processes. Do you see different actual behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request User submitted feature request.
Projects
None yet
Development

No branches or pull requests

2 participants