ModOrganizer 2: Add option to change Silent Mode Executable #1131
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1130.
Overiview
Adds the option to choose which ModOrganizer 2 Executable Configuration gets launched in Silent Mode.
(Note: The default value is
none
, but for illustration purposes, I chose this an alternative value from the dropdown.)Background
To launch in Silent Mode, we pass the MO2EXE
moshortcut://:exe_name
(note that this has two colons). By default, this is the Executable configuration matching the INI/default internal MO2 Instance name (i.e.Oblivion
,Skyrim Special Edition
,Fallout New Vegas
). So by default for SkyrimSE, we would launchmolaunch://:Skyrim Special Edition
. This name should correspond to an executable configuration defined in MO2 which points to a real executable, working directory, etc. MO2 creates these for Bethesda games in order to skip the launcher usually, so this would launch the SkyrimSE EXE without using the launcher.However some games, such as SkyrimSE, need to use SkyrimSE Script Extender (SKSE64) in order to launch the game with mods. This launch configuration will be defined inside of MO2 in order to launch the game with mods in GUI mode, but to use it in Silent Mode, we need a way to give
moshortcut://:
a different executable configuration name. In this case, instead of usingmoshortcut://:Skyrim Special Edition
, we need a way to give itmoshortcut://:SKSE64
.Implementation
To achieve this, I added a combobox entry dropdown on the Game Menu to optionally override the Executable Configuration name given to the
moshortcut://:
command. This is under the ModOrganizer 2 settings so will be hidden if ModOrganizer 2 is not used. This dropdown controls the value ofMO2SILENTMODEEXEOVERRIDE
(which isnone
by default).By default, dropdown is this is
none
, meaning we will do nothing by default, we won't override anything, and any users using Silent Mode today will not be impacted. If the dropdown is blank we also won't do anything.However a user can click on this dropdown and choose a list of executable configurations parsed out of the ModOrganizer 2 instance INI at
/path/to/mo2compdata/pfx/drive_c/users/steamuser/AppData/Local/ModOrganizer/<GAMENAME>/ModOrganizer.ini
. The list of available executable configurations is stored in the INI like this:Oblivion INI example
The part we have to give to
moshortcut://:
is thetitle
property. So we can parse out the executable titles usingsed
, getting every line that starts with a number and a backlash containingtitle=
. We also have to remove the carriage return, I tried to do this withsed
but ended up just doing it with parameter expansion.To populate the dropdown with these values we create a new function called
createMO2SilentModeExeProfilesList
that runs on the Main Menu, similar to how we run a function on the Main Menu to populate the ReShade versions list. This function will exit early if the current game is not inmo2games.txt
(and similarly ifmo2games.txt
doesn't exist). Then, if the INI file we need doesn't exist, we also return early. This should hopefully minimize loading times, as the Main Menu can take quite a while to load and this would be an IO bound task.Assuming we are able to find the INI, we loop through the matches returned by
sed -n 's/^[0-9]\\title=//p'
(matches everything after patterns line\1title=
on each line). The order of these matches is determined by their order in the ModOrganizer 2 executable configurations list. You can re-order entries, so the order we use here follows that as the INI also stores these sequentially.We store these entries in an exclamation-point-delimited string, because that's what
cleanDropDown
expects. If an executable name contained an exclamation point, this could be problematic, so we should document this potential problem. Likewise we should document that although there is a preset list, the user can enter their own custom value, but if they enter a value that doesn't exist then ModOrganizer 2 may not work.The final string, which could look something like
none!Oblivion Launcher!Oblivion!Explore Virtual Folder
, is then used on the Game Menu to display the items in the dropdown. The value forMO2SILENTMODEEXEOVERRIDE
can also be manually set in the Per-Game Config File, as usual.Once selected, when we try to launch ModOrganizer 2 in Silent Mode, if we have a defined
MO2SILENTMODEEXEOVERRIDE
that is notnone
. then we use that as the value to pass tomoshortcut://:
instead of hardcoding to the INI name. IfMO2SILENTMODEEXEOVERRIDE
is blank ornone
, then we fall back to the INI name that we're currently using.I tested this one and it seems to work as expected, resolving the linked issue.
TODO:
GLOBALMISCDIR
works as expectedSKSE64
)