Skip to content
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

ScriptableAutoSplit: Allow init to reject processes #2460

Open
apple1417 opened this issue Jul 1, 2021 · 0 comments
Open

ScriptableAutoSplit: Allow init to reject processes #2460

apple1417 opened this issue Jul 1, 2021 · 0 comments
Labels
area: ScriptableAutoSplit Affects the ScriptableAutoSplit component.

Comments

@apple1417
Copy link
Contributor

apple1417 commented Jul 1, 2021

When there are multiple processes with the same name matching a state descriptor, currently the newest one is seleted. 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.

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.

@wooferzfg wooferzfg transferred this issue from LiveSplit/LiveSplit.ScriptableAutoSplit Apr 18, 2024
@wooferzfg wooferzfg added the area: ScriptableAutoSplit Affects the ScriptableAutoSplit component. label Apr 18, 2024
@wooferzfg wooferzfg changed the title Allow init to reject processes ScriptableAutoSplit: Allow init to reject processes Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ScriptableAutoSplit Affects the ScriptableAutoSplit component.
Projects
None yet
Development

No branches or pull requests

2 participants