themaoci wrote: ↑Sat Aug 19, 2023 12:31 pm
- added start game initializer (for testing not sure if that gonna work...) [EvenLess]
I haven't tested your CT, but I know the launching of the game works.
I've updated my script a bit, and added both
bg3_dx11.exe
and
bg3.exe
, but as a table that I can loop through, rather than two static variables
The thing that isn't working right now, in my code below, is attaching to the game process, if it was launched by the script. I think it's because the process respawns or something. At least the very first PID that it attaches to, is not the PID that I can attach to a few moments later (by disabling/enabling my script again). Maybe your timer is what fixes this. Haven't gotten my head wrapped around that yet.
Code: Select all
[ENABLE]
{$lua}
if syntaxcheck then return end
local executable = { 'bg3_dx11.exe', 'bg3.exe' }
local executablePath = 'C:\\Games\\Steam\\steamapps\\common\\Baldurs Gate 3\\bin\\'
local executableParameters = '--skip-launcher'
local openedPID = getOpenedProcessID()
local actualPID = nil
-- Find the first process with either of the bg3 executables.
for i = 1, #executable do
actualPID = getProcessIDFromProcessName(executable[i])
if actualPID ~= nil then
print(string.format('Found "%s" with PID "%s".', executable[i], actualPID))
executableFile = executable[i]
break
end
end
-- Check if game is running.
if actualPID == nil then
print(string.format('Attempting to launch "%s".', executable[1]))
createProcess(executablePath .. executable[1], executableParameters)
actualPID = getProcessIDFromProcessName(executable[1])
end
-- Check if attached to game.
if actualPID ~= nil and actualPID ~= openedPID then
print(string.format('Attaching to new PID "%s". Old PID was "%s".', actualPID, openedPID))
-- Might need some delay here? When both launching and attaching in one go, loading Console Commands doesn't work.
openProcess(tonumber(actualPID))
else
print(string.format('Already attached to "%s".', openedPID))
end
{$asm}
[DISABLE]
As for the hardcoded path, that is not the default path for the game. The path either needs to manually edited by the end-user, or if you can figure out a way to read values from the HKLM registry, then you can probably make that dynamic too.
It should be possible to retrieve the installation path from the installed applications list. It's located in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
(or
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
if 32-bit install on 64-bit Windows). Searching through all the sub-keys for the for the
DisplayName
equals
Baldur's Gate 3
. That should give you the key that contains BG3. If it's a Steam game you'll actually have the Steam Install path as part of the
UninstallString
. If it's not a Steam game, I would think the
InstallLocation
will have the proper path, as any normally installed application. You can also read the Steam
InstallPath
from the key
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam
(or
HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam
for 32-bit Windows).