--[[ ************************************** Launch Game Autorun Files Version 1.0 ************************************** --]] -- Constants local metadata_name = 'launchgame.dat' -- Globals launch_command = {'', '', ' ', false, false} -- Functions local launch_gui local launch_options_gui local get_path local write_metadata local read_metadata local launch_game -- [1] = Process Name -- [2] = Path -- [3] = Parameters -- [4] = Debug -- [5] = BreakOnEntry launch_gui = function() read_metadata() if #launch_command[1] > 0 and #launch_command[2] > 0 then local message = string.format('Launch %s?', launch_command[1]) local response = messageDialog(message, mtConfirmation, mbYes, mbNo) if response == mrYes then launch_options_gui() end end end launch_options_gui = function() local form = createForm() form.Caption = "Launch Options" form.Width = 400 form.Height = 150 form.centerScreen() form.show() local y = 10 local params_label = createLabel(form) params_label.Caption = 'Parameters' params_label.setPosition(10, y) y = y + 20 local params_input = createEdit(form) params_input.setPosition(10, y) params_input.Width = form.Width - 20 if #launch_command[3] > 0 then params_input.Text = launch_command[3] end y = y + 20 local checkBoxes = {}; checkBoxes[1] = createCheckBox( form ); checkBoxes[2] = createCheckBox( form ); local checkbox_captions = {'Debug', 'OnBreakPoint'} for x = 1, #checkBoxes do checkBoxes[x].AllowGrayed = false checkBoxes[x].Caption = checkbox_captions[x] checkBoxes[x].setPosition(10, y + x * 20) if launch_command[3 + x] == true then checkBoxes[x].State = 1 else checkBoxes[x].State = 0 end end y = y + 20 * #checkBoxes local launch_button = createButton(form) launch_button.Caption = 'Launch' launch_button.Width = 60 launch_button.setPosition((form.Width - launch_button.Width)/2, form.Height - launch_button.Height) launch_button.onClick = function() if #params_input.Text > 0 then launch_command[3] = params_input.Text else launch_command[3] = ' ' end launch_command[4] = checkBoxes[1].Checked launch_command[5] = checkBoxes[2].Checked form.destroy() launch_game() end end get_path = function(pid) local modules = enumModules(pid) if modules and #modules > 0 then return modules[1].PathToFile end return '' end write_metadata = function() local table_file = findTableFile(metadata_name) local metadata = "" for i = 1, #launch_command do local str = tostring(launch_command[i]) metadata = metadata .. str .. '\n' end if not table_file then table_file = createTableFile(metadata_name) end table_file.getData().clear() table_file.getData().writeString(metadata) end read_metadata = function() -- Original function taken from the wiki: -- https://wiki.cheatengine.org/index.php?title=Lua:Class:TableFile local fileStr = nil local tableFile = findTableFile(metadata_name) if tableFile ~= nil then local stringStream = createStringStream() stringStream.Position = 0 -- if not set before using 'copyFrom' the 'StringStream' object will be inconsistent. stringStream.copyFrom(tableFile.Stream, tableFile.Stream.Size) fileStr = stringStream.DataString stringStream.destroy() local i = 1 for line in string.gmatch(fileStr, "[^\n]+") do if i <= 3 then launch_command[i] = line elseif line == 'false' then launch_command[i] = false elseif line == 'true' then launch_command[i] = true end i = i + 1 end end end launch_game = function() local process_name = launch_command[1] if getProcessIDFromProcessName(process_name) then local message = string.format('%s is already running. Do you want to launch it anyways?', process_name) local response = messageDialog(message, mtConfirmation, mbYes, mbNo) if response == mrNo then openProcess(process_name) else createProcess(launch_command[2], launch_command[3], launch_command[4], launch_command[5]) sleep(2000) end else createProcess(launch_command[2], launch_command[3], launch_command[4], launch_command[5]) sleep(2000) openProcess(process_name) end end function onOpenProcess(processId) launch_command[1] = process launch_command[2] = get_path(processId) write_metadata() end createThread(function() while (getMainForm() == nil) or (not getMainForm().Visible) do sleep(1000) end synchronize(function() launch_gui() end) end)