LiveSplit / LiveSplit/LiveSplit
ScriptableAutoSplit: Allow init to reject processes
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1.9k
- Forks
- 815
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 3
Description
When there are multiple processes with the same name matching a state descriptor, [currently the newest one is seleted](https://github.com/LiveSplit/LiveSplit.ScriptableAutoSplit/blob/b25662cdad0d7b81eb186183e3557929fffc497b/ASL/ASLScript.cs#L156). Once a process is selected, you're stuck with it until it exits, or until you reload the autosplitter. It would be nice if init were able to reject processes, so that you could select a different one instead.
The motivating example for this is Borderlands 3 on Epic. Launching the game first starts a small launcher process, which automatically launches the main game process, but then stays running until it exits. Both processes are simply called `Borderlands3.exe`. Under current behavior, if the autosplitter loads while the game is already running, it selects the newer process, which is the full game like we want it to be. However, if the autosplitter is loaded first (e.g. if the game crashes mid run), it hooks onto the launcher process, and because the launcher doesn't exit it never moves on to the game process.
It is possible to work around this using reflection.
```cs
init {
if (condition) {
var allComponents = timer.Layout.Components;
// Grab the autosplitter from splits
if (timer.Run.AutoSplitter != null && timer.Run.AutoSplitter.Component != null) {
allComponents = allComponents.Append(timer.Run.AutoSplitter.Component);
}
foreach (var component in allComponents) {
var type = component.GetType();
if (type.Name == "ASLComponent") {
// Could also check script path, but renaming the script breaks that, and
// running multiple autosplitters at once is already just asking for problems
var script = type.GetProperty("Script").GetValue(component);
script.GetType().GetField(
"_game",
BindingFlags.NonPublic | BindingFlags.Instance
).SetValue(script, null);
}
}
return;
}
}
```
For BL3, setting the game to null causes init to be re-run, which will eventually select the newer process when it launches. In other situations, you may need to manually identify the new process and replace it with that instead.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ASL/ASLScript.cs around line 156, where the newest matching process is selected, and trace how init and process attachment are handled. Compare that flow with the reflection workaround in the issue. Done should let init reject a selected process so another matching process can be chosen without reloading the autosplitter, including the Borderlands 3 launcher case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100