summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2025-10-26 03:49:30 +1100
committer Vas Crabb <vas@vastheman.com>2025-10-26 03:49:30 +1100
commit3a0cd99a8e3c678a01f35ac842636eb15325dc18 (patch)
treeb9d99ccc1ef25255efcb3aaf148cec546fc671a3
parentae78e07ff054248eff02cec235b6748796cf5dda (diff)
plugins/hiscore: Fixed mixed space/tab indentation.
-rw-r--r--plugins/hiscore/init.lua416
1 files changed, 208 insertions, 208 deletions
diff --git a/plugins/hiscore/init.lua b/plugins/hiscore/init.lua
index 8284ec96644..b89324dc38e 100644
--- a/plugins/hiscore/init.lua
+++ b/plugins/hiscore/init.lua
@@ -134,56 +134,56 @@ function hiscore.startplugin()
-- build menu
local function populate_menu()
- local items = {}
+ local items = {}
- table.insert(items, { _p('plugin-hiscore', 'Hiscore Support Options'), '', 'off' })
- table.insert(items, { '---', '', '' })
+ table.insert(items, { _p('plugin-hiscore', 'Hiscore Support Options'), '', 'off' })
+ table.insert(items, { '---', '', '' })
- local game = emu.romname()
- local enabled = not is_game_excluded()
- local status = enabled and 'Yes' or 'No'
- table.insert(items, { "Enable Hiscore Support for this game", status, enabled and 'l' or 'r' })
+ local game = emu.romname()
+ local enabled = not is_game_excluded()
+ local status = enabled and 'Yes' or 'No'
+ table.insert(items, { "Enable Hiscore Support for this game", status, enabled and 'l' or 'r' })
- local setting = timed_save and _p('plugin-hiscore', 'When updated') or _p('plugin-hiscore', 'On exit')
- table.insert(items, { _p('plugin-hiscore', 'Save scores'), setting, timed_save and 'l' or 'r' })
+ local setting = timed_save and _p('plugin-hiscore', 'When updated') or _p('plugin-hiscore', 'On exit')
+ table.insert(items, { _p('plugin-hiscore', 'Save scores'), setting, timed_save and 'l' or 'r' })
- return items
+ return items
end
-- handle menu events
local function handle_menu(index, event)
- -- added menu item to enable/disable hiscore support for this game
- if index == 3 then
- if event == 'left' or event == 'right' then
- local game = emu.romname()
- if event == 'left' then
- -- Disable Hiscore Support for this game (add to exclude list)
- excluded_games[game] = true
- emu.print_verbose(string.format('[Hiscore] Hiscore support disabled for game "%s"', game))
- elseif event == 'right' then
- -- Enable Hiscore Support for this game (remove from exclude list)
- excluded_games[game] = nil
- emu.print_verbose(string.format('[Hiscore] Hiscore support enabled for game "%s"', game))
- end
- save_exclusions()
- return true
- else
- return false
+ -- added menu item to enable/disable hiscore support for this game
+ if index == 3 then
+ if event == 'left' or event == 'right' then
+ local game = emu.romname()
+ if event == 'left' then
+ -- Disable Hiscore Support for this game (add to exclude list)
+ excluded_games[game] = true
+ emu.print_verbose(string.format('[Hiscore] Hiscore support disabled for game "%s"', game))
+ elseif event == 'right' then
+ -- Enable Hiscore Support for this game (remove from exclude list)
+ excluded_games[game] = nil
+ emu.print_verbose(string.format('[Hiscore] Hiscore support enabled for game "%s"', game))
+ end
+ save_exclusions()
+ return true
+ else
+ return false
+ end
end
- end
-
- -- previous menu item to select when scores are saved remains unchanged (now on menu index #4)
- if index == 4 then
- if event == 'left' then
- timed_save = false
- return true
- elseif event == 'right' then
- timed_save = true
- return true
+
+ -- previous menu item to select when scores are saved remains unchanged (now on menu index #4)
+ if index == 4 then
+ if event == 'left' then
+ timed_save = false
+ return true
+ elseif event == 'right' then
+ timed_save = true
+ return true
+ end
end
- end
- return false
+ return false
end
@@ -198,219 +198,219 @@ function hiscore.startplugin()
local delaytime = 0;
local function parse_table ( dsting )
- local _table = {}
- for line in string.gmatch(dsting, '([^\n]+)') do
- local delay = line:match('^@delay=([.%d]*)')
- if delay and #delay > 0 then
- delaytime = emu.time() + tonumber(delay)
- else
- local cpu, mem;
- local cputag, space, offs, len, chk_st, chk_ed, fill = string.match(line, '^@([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),?(%x?%x?)');
- cpu = manager.machine.devices[cputag];
- if not cpu then
- error(cputag .. " device not found")
- end
- local rgnname, rgntype = space:match("([^/]*)/?([^/]*)")
- if rgntype == "share" then
- mem = manager.machine.memory.shares[rgnname]
+ local _table = {}
+ for line in string.gmatch(dsting, '([^\n]+)') do
+ local delay = line:match('^@delay=([.%d]*)')
+ if delay and #delay > 0 then
+ delaytime = emu.time() + tonumber(delay)
else
- mem = cpu.spaces[space]
- end
- if not mem then
- error(space .. " space not found")
+ local cpu, mem;
+ local cputag, space, offs, len, chk_st, chk_ed, fill = string.match(line, '^@([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),?(%x?%x?)');
+ cpu = manager.machine.devices[cputag];
+ if not cpu then
+ error(cputag .. " device not found")
+ end
+ local rgnname, rgntype = space:match("([^/]*)/?([^/]*)")
+ if rgntype == "share" then
+ mem = manager.machine.memory.shares[rgnname]
+ else
+ mem = cpu.spaces[space]
+ end
+ if not mem then
+ error(space .. " space not found")
+ end
+ _table[ #_table + 1 ] = {
+ mem = mem,
+ addr = tonumber(offs, 16),
+ size = tonumber(len, 16),
+ c_start = tonumber(chk_st, 16),
+ c_end = tonumber(chk_ed, 16),
+ fill = tonumber(fill, 16)
+ };
end
- _table[ #_table + 1 ] = {
- mem = mem,
- addr = tonumber(offs, 16),
- size = tonumber(len, 16),
- c_start = tonumber(chk_st, 16),
- c_end = tonumber(chk_ed, 16),
- fill = tonumber(fill, 16)
- };
end
- end
- return _table;
+ return _table;
end
local function read_hiscore_dat ()
- local file = io.open( hiscoredata_path, "r" );
- local rm_match;
- if not file then
- file = io.open( hiscore_plugin_path .. "/hiscore.dat", "r" );
- end
- if emu.softname() ~= "" then
- local soft = emu.softname():match("([^:]*)$")
- rm_match = '^' .. emu.romname() .. ',' .. soft .. ':';
- else
- rm_match = '^' .. emu.romname() .. ':';
- end
- local cluster = "";
- local current_is_match = false;
- if file then
- repeat
- line = file:read("*l");
- if line then
- -- remove comments
- line = line:gsub( '[ \t\r\n]*;.+$', '' );
- -- handle lines
- if string.find(line, '^@') then -- data line
- if current_is_match then
- cluster = cluster .. "\n" .. line;
- end
- elseif string.find(line, rm_match) then --- match this game
- current_is_match = true;
- elseif string.find(line, '^[a-z0-9_,]+:') then --- some game
- if current_is_match and string.len(cluster) > 0 then
- break; -- we're done
- end
- else --- empty line or garbage
- -- noop
- end
- end
- until not line;
- file:close();
- end
- return cluster;
+ local file = io.open( hiscoredata_path, "r" );
+ local rm_match;
+ if not file then
+ file = io.open( hiscore_plugin_path .. "/hiscore.dat", "r" );
+ end
+ if emu.softname() ~= "" then
+ local soft = emu.softname():match("([^:]*)$")
+ rm_match = '^' .. emu.romname() .. ',' .. soft .. ':';
+ else
+ rm_match = '^' .. emu.romname() .. ':';
+ end
+ local cluster = "";
+ local current_is_match = false;
+ if file then
+ repeat
+ line = file:read("*l");
+ if line then
+ -- remove comments
+ line = line:gsub( '[ \t\r\n]*;.+$', '' );
+ -- handle lines
+ if string.find(line, '^@') then -- data line
+ if current_is_match then
+ cluster = cluster .. "\n" .. line;
+ end
+ elseif string.find(line, rm_match) then --- match this game
+ current_is_match = true;
+ elseif string.find(line, '^[a-z0-9_,]+:') then --- some game
+ if current_is_match and string.len(cluster) > 0 then
+ break; -- we're done
+ end
+ else --- empty line or garbage
+ -- noop
+ end
+ end
+ until not line;
+ file:close();
+ end
+ return cluster;
end
local function check_mem ( posdata )
- if #posdata < 1 then
- return false;
- end
- for ri,row in ipairs(posdata) do
- -- must pass mem check
- if row["c_start"] ~= row["mem"]:read_u8(row["addr"]) then
- return false;
+ if #posdata < 1 then
+ return false;
end
- if row["c_end"] ~= row["mem"]:read_u8(row["addr"]+row["size"]-1) then
- return false;
+ for ri,row in ipairs(posdata) do
+ -- must pass mem check
+ if row["c_start"] ~= row["mem"]:read_u8(row["addr"]) then
+ return false;
+ end
+ if row["c_end"] ~= row["mem"]:read_u8(row["addr"]+row["size"]-1) then
+ return false;
+ end
end
- end
- return true;
+ return true;
end
local function get_file_name()
- local r;
- if emu.softname() ~= "" then
- local soft = emu.softname():match("([^:]*)$")
- r = get_data_path() .. '/' .. emu.romname() .. "_" .. soft .. ".hi";
- else
- r = get_data_path() .. '/' .. emu.romname() .. ".hi";
- end
- return r;
+ local r;
+ if emu.softname() ~= "" then
+ local soft = emu.softname():match("([^:]*)$")
+ r = get_data_path() .. '/' .. emu.romname() .. "_" .. soft .. ".hi";
+ else
+ r = get_data_path() .. '/' .. emu.romname() .. ".hi";
+ end
+ return r;
end
local function write_scores ( posdata )
- -- check if game is on the exclude list before writing
- if is_game_excluded() then
- emu.print_verbose('[Hiscore] Skipping write_scores - excluded game: ' .. emu.romname())
- return
- end
-
- emu.print_verbose("hiscore: write_scores")
- local output = io.open(get_file_name(), "wb");
- if not output then
- -- attempt to create the directory, and try again
- lfs.mkdir(get_data_path());
- output = io.open(get_file_name(), "wb");
- end
- emu.print_verbose("hiscore: write_scores output")
- if output then
- for ri,row in ipairs(posdata) do
- t = {}
- for i=0,row["size"]-1 do
- t[i+1] = row["mem"]:read_u8(row["addr"] + i)
- end
- output:write(string.char(table.unpack(t)));
+ -- check if game is on the exclude list before writing
+ if is_game_excluded() then
+ emu.print_verbose('[Hiscore] Skipping write_scores - excluded game: ' .. emu.romname())
+ return
+ end
+
+ emu.print_verbose("hiscore: write_scores")
+ local output = io.open(get_file_name(), "wb");
+ if not output then
+ -- attempt to create the directory, and try again
+ lfs.mkdir(get_data_path());
+ output = io.open(get_file_name(), "wb");
+ end
+ emu.print_verbose("hiscore: write_scores output")
+ if output then
+ for ri,row in ipairs(posdata) do
+ t = {}
+ for i=0,row["size"]-1 do
+ t[i+1] = row["mem"]:read_u8(row["addr"] + i)
+ end
+ output:write(string.char(table.unpack(t)));
+ end
+ output:close();
end
- output:close();
- end
- emu.print_verbose("hiscore: write_scores end")
+ emu.print_verbose("hiscore: write_scores end")
end
local function read_scores ( posdata )
- -- check if game is on the exclude list before loading scores
- if is_game_excluded() then
- emu.print_verbose('[Hiscore] Skipping read_scores - excluded game: ' .. emu.romname())
- return false
- end
+ -- check if game is on the exclude list before loading scores
+ if is_game_excluded() then
+ emu.print_verbose('[Hiscore] Skipping read_scores - excluded game: ' .. emu.romname())
+ return false
+ end
- local input = io.open(get_file_name(), "rb");
- if input then
- for ri,row in ipairs(posdata) do
- local str = input:read(row["size"]);
- for i=0,row["size"]-1 do
- local b = str:sub(i+1,i+1):byte();
- row["mem"]:write_u8( row["addr"] + i, b );
- end
+ local input = io.open(get_file_name(), "rb");
+ if input then
+ for ri,row in ipairs(posdata) do
+ local str = input:read(row["size"]);
+ for i=0,row["size"]-1 do
+ local b = str:sub(i+1,i+1):byte();
+ row["mem"]:write_u8( row["addr"] + i, b );
+ end
+ end
+ input:close();
+ return true;
end
- input:close();
- return true;
- end
- return false;
+ return false;
end
local function check_scores ( posdata )
- local r = 0;
- for ri,row in ipairs(posdata) do
- for i=0,row["size"]-1 do
- r = r + row["mem"]:read_u8( row["addr"] + i );
+ local r = 0;
+ for ri,row in ipairs(posdata) do
+ for i=0,row["size"]-1 do
+ r = r + row["mem"]:read_u8( row["addr"] + i );
+ end
end
- end
- return r;
+ return r;
end
local function init ()
- if not scores_have_been_read then
- if (delaytime <= emu.time()) and check_mem( positions ) then
- default_checksum = check_scores( positions );
- if read_scores( positions ) then
- emu.print_verbose( "hiscore: scores read OK" );
- else
- -- likely there simply isn't a .hi file around yet
- emu.print_verbose( "hiscore: scores read FAIL" );
- end
- scores_have_been_read = true;
- current_checksum = check_scores( positions );
- mem_check_passed = true;
- else
- -- memory check can fail while the game is still warming up
- -- TODO: only allow it to fail N many times
+ if not scores_have_been_read then
+ if (delaytime <= emu.time()) and check_mem( positions ) then
+ default_checksum = check_scores( positions );
+ if read_scores( positions ) then
+ emu.print_verbose( "hiscore: scores read OK" );
+ else
+ -- likely there simply isn't a .hi file around yet
+ emu.print_verbose( "hiscore: scores read FAIL" );
+ end
+ scores_have_been_read = true;
+ current_checksum = check_scores( positions );
+ mem_check_passed = true;
+ else
+ -- memory check can fail while the game is still warming up
+ -- TODO: only allow it to fail N many times
+ end
end
- end
end
local last_write_time = -10;
local function tick ()
- -- set up scores if they have been
- init();
- -- only allow save check to run when
- if mem_check_passed and timed_save then
- -- The reason for this complicated mess is that
- -- MAME does expose a hook for "exit". Once it does,
- -- this should obviously just be done when the emulator
- -- shuts down (or reboots).
- local checksum = check_scores( positions );
- if checksum ~= current_checksum and checksum ~= default_checksum then
- -- 5 sec grace time so we don't clobber io and cause
- -- latency. This would be bad as it would only ever happen
- -- to players currently reaching a new highscore
- if emu.time() > last_write_time + 5 then
- write_scores( positions );
- current_checksum = checksum;
- last_write_time = emu.time();
- -- emu.print_verbose( "SAVE SCORES EVENT!", last_write_time );
- end
+ -- set up scores if they have been
+ init();
+ -- only allow save check to run when
+ if mem_check_passed and timed_save then
+ -- The reason for this complicated mess is that
+ -- MAME does expose a hook for "exit". Once it does,
+ -- this should obviously just be done when the emulator
+ -- shuts down (or reboots).
+ local checksum = check_scores( positions );
+ if checksum ~= current_checksum and checksum ~= default_checksum then
+ -- 5 sec grace time so we don't clobber io and cause
+ -- latency. This would be bad as it would only ever happen
+ -- to players currently reaching a new highscore
+ if emu.time() > last_write_time + 5 then
+ write_scores( positions );
+ current_checksum = checksum;
+ last_write_time = emu.time();
+ -- emu.print_verbose( "SAVE SCORES EVENT!", last_write_time );
+ end
+ end
end
- end
end
local function reset()