Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gg.require('8.55.1')
- local ver = 'Script loader v2.0'
- -- https://gameguardian.net/forum/files/file/140-script-loader/
- local config = {}
- local save_filename = ''
- local open_menu = false
- function get_scripts()
- local empty = {}
- local ret = empty
- if config['separate_lists'] ~= nil then
- local target = gg.getTargetInfo()
- ret = config[target['packageName']]
- if ret == nil then config[target['packageName']] = empty end
- else
- ret = config['scripts']
- if ret == nil then config['scripts'] = empty end
- end
- if ret == nil then ret = empty end
- return ret
- end
- function main_menu()
- local options = {}
- local scripts = get_scripts()
- for i, v in ipairs(scripts) do
- options[i] = v
- end
- local add = #options + 1
- options[add] = 'Add script';
- local remove = #options + 1
- options[remove] = 'Remove script';
- local toggle = #options + 1
- options[toggle] = config['open_after_run'] == nil and 'Open menu after run script' or 'Hide menu after run script'
- local mode = #options + 1
- options[mode] = config['separate_lists'] ~= nil and 'One list for all' or 'Separate lists for apps'
- local exit = #options + 1
- options[exit] = 'Exit';
- selected = gg.choice(options, nil, ver..'\n'..(config['separate_lists'] ~= nil and gg.getTargetInfo()['label'] or 'One list for all'))
- if scripts[selected] ~= nil then
- run_script(scripts[selected])
- if config['open_after_run'] ~= nil then
- open_menu = true
- end
- end
- if selected == add then
- add_script()
- save_config()
- open_menu = true
- end
- if selected == remove then
- remove_script()
- save_config()
- open_menu = true
- end
- if selected == toggle then
- config['open_after_run'] = config['open_after_run'] == nil and 1 or nil
- save_config()
- open_menu = true
- end
- if selected == mode then
- config['separate_lists'] = config['separate_lists'] == nil and 1 or nil
- save_config()
- open_menu = true
- end
- if selected == exit then
- os.exit()
- end
- end
- function run_script(file)
- print(file..' start')
- local script = loadfile(file)
- local msg = nil
- if script == nil then
- msg = 'Failed load script: '..file
- else
- local ret, err = pcall(script)
- if not ret then
- msg = 'Script error: '..err
- print(msg)
- msg = nil
- end
- end
- if msg ~= nil then
- print(msg)
- gg.alert(msg)
- end
- print(file..' finish')
- end
- function add_script()
- local scripts = get_scripts()
- local info = nil
- while true do
- info = gg.prompt({'Select script file:'}, {config['last_file']}, {'file'})
- if info == nil then return end
- local test = loadfile(info[1])
- if test == nil then
- gg.alert('Failed load script: '..info[1])
- else
- break
- end
- end
- scripts[#scripts + 1] = info[1]
- config['last_file'] = info[1]
- end
- function remove_script()
- local scripts = get_scripts()
- local selected = gg.choice(scripts, nil, 'Select script for remove:')
- if selected == nil then return end
- for i = selected, #scripts - 1 do
- scripts[i] = scripts[i + 1]
- end
- scripts[#scripts] = nil
- end
- function load_config()
- local chunk = loadfile(save_filename)
- if chunk == nil then
- config = {}
- else
- config = chunk()
- end
- if config['last_file'] == nil then
- config['last_file'] = get_file()
- end
- end
- function save_config()
- gg.saveVariable(config, save_filename)
- end
- function get_file()
- local file = gg.getFile()
- if file:sub(1, 1) == '@' then file = file:sub(2, #file) end
- return file
- end
- save_filename = get_file()..'.cfg'
- load_config()
- gg.toast(ver, true)
- --gg.setVisible(false)
- while true do
- if gg.isVisible() then
- gg.setVisible(false)
- open_menu = true
- end
- if open_menu then
- open_menu = false
- main_menu()
- else
- gg.sleep(100)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement