themaoci wrote: ↑Thu Aug 17, 2023 10:22 pm
If you guys need auto attach for a script
Code: Select all
[ENABLE]
{$lua}
PROCESS_NAME = 'bg3_dx11.exe'
PROCESS_NAME_BACKUP = 'bg3.exe'
if getProcessIDFromProcessName(PROCESS_NAME) ~= nil then
openProcess(PROCESS_NAME) ---- Open the process
messageDialog("Attached to bg3_dx11.exe")
elseif getProcessIDFromProcessName(PROCESS_NAME_BACKUP) ~= nil then
openProcess(PROCESS_NAME_BACKUP) ---- Open the process
messageDialog("Attached to bg3.exe")
end
{$asm}
assert(true)
[DISABLE]
As for CTRL+ALT+L (this will wait till you start a game and auto attach to it)
Code: Select all
PROCESS_NAME = 'bg3_dx11.exe'
PROCESS_NAME_BACKUP = 'bg3.exe'
--------
-------- Auto Attach
--------
local autoAttachTimer = nil ---- variable to hold timer object
local autoAttachTimerInterval = 1000 ---- Timer intervals are in milliseconds
local autoAttachTimerTicks = 0 ---- variable to count number of times the timer has run
local autoAttachTimerTickMax = 5000 ---- Set to zero to disable ticks max
local function autoAttachTimer_tick(timer) ---- Timer tick call back
---- Destroy timer if max ticks is reached
if autoAttachTimerTickMax > 0 and autoAttachTimerTicks >= autoAttachTimerTickMax then
timer.destroy()
end
---- Check if process is running
if getProcessIDFromProcessName(PROCESS_NAME) ~= nil then
timer.destroy() ---- Destroy timer
openProcess(PROCESS_NAME) ---- Open the process
messageDialog("Auto Attached To Process!")
elseif getProcessIDFromProcessName(PROCESS_NAME_BACKUP) ~= nil then
timer.destroy() ---- Destroy timer
openProcess(PROCESS_NAME_BACKUP) ---- Open the process
messageDialog("Auto Attached To Process!")
end
autoAttachTimerTicks = autoAttachTimerTicks + 1 ---- Increase ticks
end
autoAttachTimer = createTimer(getMainForm()) ---- Create timer with the main form as it's parent
autoAttachTimer.Interval = autoAttachTimerInterval ---- Set timer interval
autoAttachTimer.OnTimer = autoAttachTimer_tick ---- Set timer tick call back
Nice one. I'll have to look more thoroughly through your script. Maybe I can use the timer part to automatically attach after launch, rather than activating my script twice (first time to launch, second time to attach).
My current script is static to
bg3_dx11.exe
, but creating a table with both, and looping through them, to look for processes with both names should be quick to add.
I see you skip checking whether it's attached to the right PID, before opening the PID. I guess I could save some code by going that approach.
I've also added launching of
bg3_dx11.exe
with the
--skip-launcher
parameter, so I don't have to go through the Larian Launcher, and I don't have to wait for Steam to finish complaining about the game is running, when it's not.
Code: Select all
[ENABLE]
{$lua}
if syntaxcheck then return end
local executable = 'bg3_dx11.exe'
local executablePath = "C:\\Games\\Steam\\steamapps\\common\\Baldurs Gate 3\\bin\\" .. executable
local executableParameters = '--skip-launcher'
local openedProcessId = getOpenedProcessID()
if openedProcessId ~= nil and openedProcessId ~= 0 then
print(string.format('Currently attached to "%s" with PID "%d".', process, openedProcessId))
end
local processId = 0
for pid, name in pairs(getProcessList()) do
if name == executable then
processId = pid
processName = name
break
end
end
if openedProcessId ~= 0 and processId ~= 0 and openedProcessId ~= processId then
print(string.format('PID (%d) for the opened process have changed. Attaching to new PID (%d).', openedProcessId, processId))
openProcess(tonumber(processId))
if processId ~= getOpenedProcessID() then
print(string.format('Attaching to PID (%d) seems to have failed.', processId))
else
print(string.format('Attached to PID "%d".', processId))
end
end
if processId == 0 then
print("Game isn't running. Attempting to start it.")
createProcess(executablePath, executableParameters)
end
print('Done.')
{$asm}
[DISABLE]