SilentNightSound / SR-Model-Importer

Tools and instructions for importing custom models into a certain anime game number 2
684 stars 57 forks source link

Update 3DMigotoLoader.exe and .py with d3dx.ini config variable reading #34

Open kvnxiao opened 8 months ago

kvnxiao commented 8 months ago

I noticed that the launch parameter in d3dx.ini wasn't working to auto-launch the game.

The pyinstaller built exe and the python script should be updated to read from the ini with a simple change to the python script. And instead of hardcoding StarRail.exe we should probably also use the target value from the ini as well.

import psutil
from pyinjector import inject
import re

AUTO_LAUNCH_REGEX = re.compile(r"^launch\s*=\s(.*)$")
TARGET_REGEX = re.compile(r"^target\s*=\s(.*)$")

def _load_config() -> tuple[str, str]:
    auto_launch: str = ""
    target_proc: str = ""
    with open("d3dx.ini", "r") as f:
        for line in f.readlines():
            m = AUTO_LAUNCH_REGEX.match(line)
            if m and not auto_launch:
                auto_launch = m.group(1)
            m = TARGET_REGEX.match(line)
            if m and not target_proc:
                target_proc = m.group(1)
    return auto_launch, target_proc

def main():
    auto_launch, target_proc = _load_config()
    if auto_launch != "":
        print(f"Launching ${auto_launch}...")
        psutil.Popen(auto_launch)
    print("Waiting for program...")
    # Iterate over all running process
    while True:
        for proc in psutil.process_iter():
            try:
                if proc.name() == target_proc:
                    print(f"Found {target_proc}")
                    print(proc.name(), proc.pid)
                    inject(proc.pid, "d3d11.dll")
                    return
            except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
                pass

if __name__ == "__main__":
    main()
kvnxiao commented 8 months ago

cc @SilentNightSound (apologies for ping!)