plugins/cheatfind: add operand size to simple cheat and write cheats from cheatfind into simple file (nw)

This commit is contained in:
cracyc 2016-07-14 14:57:47 -05:00
parent 5707b183dd
commit fa6bd37265
3 changed files with 40 additions and 14 deletions

View File

@ -2,7 +2,8 @@
-- copyright-holders:Miodrag Milanovic
require('lfs')
local function env_replace(str)
-- add helper to lfs for plugins to use
function lfs.env_replace(str)
local pathsep = package.config:sub(1,1)
local function dorep(val)
ret = os.getenv(val)
@ -19,7 +20,7 @@ local function env_replace(str)
end
return str
end
local dir = env_replace(manager:options().entries.pluginspath:value())
local dir = lfs.env_replace(manager:options().entries.pluginspath:value())
package.path = package.path .. ";" .. dir .. "/?.lua;" .. dir .. "/?/init.lua"

View File

@ -2,17 +2,27 @@ local simple = {}
-- converter for simple cheats
-- simple cheats are single address every frame ram cheats in one file called cheat.simple
-- format: <set name>,<cputag>,<hex offset>,<hex value>,<desc>
-- format: <set name>,<cputag>,<hex offset>,<b|w|d|q - size>,<hex value>,<desc>
-- only program address space is supported, comments are prepended with ;
-- size is b - u8, w - u16, d - u32, q - u64
function simple.conv_cheat(romset, data)
local cheats = {}
for line in data:gmatch('([^\n;]+)') do
local set, cputag, offset, val, name = line:match('([^,]+),([^,]+),([^,]+),([^,]+),(.+)')
local set, cputag, offset, size, val, name = line:match('([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),(.+)')
if set == romset then
local cheat = {}
cheat.desc = name
cheat.space = { cpup = { tag = cputag, type = "program" } }
cheat.script = { run = "cpup:write_u8(0x" .. offset .. ",0x" .. val .. ", true)" }
if size == "w" then
size "u16"
elseif size == "d" then
size = "u32"
elseif size == "q" then
size = "u64"
else
size = "u8"
end
cheat.script = { run = "cpup:write_" .. size .. "(0x" .. offset .. ",0x" .. val .. ", true)" }
cheats[#cheats + 1] = cheat
end
end

View File

@ -581,21 +581,21 @@ function cheatfind.startplugin()
if wid == "h" then
wid = "u16"
form = "%08x %04x"
xmlcheat = "pw"
xmlcheat = "w"
elseif wid == "l" then
wid = "u32"
form = "%08x %08x"
xmlcheat = "pd"
xmlcheat = "d"
elseif wid == "j" then
wid = "u64"
form = "%08x %016x"
xmlcheat = "pq"
xmlcheat = "q"
else
wid = "u8"
form = "%08x %02x"
xmlcheat = "pb"
xmlcheat = "b"
end
xmlcheat = string.format("<mamecheat version=1>\n<cheat desc=\"%s\">\n<script state=\"run\">\n<action>%s.%s@%X=%X</action>\n</script>\n</cheat>\n</mamecheat>", cheat.desc, dev.tag:sub(2), xmlcheat, match.addr, match.newval)
if dev.space.shortname then
cheat.ram = { ram = dev.tag }
@ -611,15 +611,30 @@ function cheatfind.startplugin()
_G.ce.inject(cheat)
end
elseif match.mode == 2 then
local filename = string.format("%s/%s_%08X_cheat", manager:machine():options().entries.cheatpath:value():match("([^;]+)"), emu.romname(), match.addr)
-- lfs.env_replace is defined in boot.lua
local setname = emu.romname()
if emu.softname() ~= "" then
for name, image in pairs(manager:machine().images) do
if image:exists() and image:software_list_name() ~= "" then
setname = image:software_list_name() .. "/" .. emu.softname()
end
end
end
local cheatpath = lfs.env_replace(manager:machine():options().entries.cheatpath:value()):match("([^;]+)")
local filename = string.format("%s/%s_%08X_cheat", cheatpath, setname, match.addr)
local json = require("json")
local file = io.open(filename .. ".json", "w")
if file then
file:write(json.stringify({[1] = cheat}, {indent = true}))
file:close()
file = io.open(filename .. ".xml", "w")
file:write(xmlcheat)
file:close()
if not dev.space.shortname then -- no xml or simple for ram_device cheat
file = io.open(filename .. ".xml", "w")
file:write(string.format("<mamecheat version=1>\n<cheat desc=\"%s\">\n<script state=\"run\">\n<action>%s.pp%s@%X=%X</action>\n</script>\n</cheat>\n</mamecheat>", cheat.desc, dev.tag:sub(2), xmlcheat, match.addr, match.newval))
file:close()
file = io.open(cheatpath .. "/cheat.simple", "a")
file:write(string.format("%s,%s,%X,%s,%X,%s\n", setname, dev.tag, match.addr, xmlcheat, match.newval, cheat.desc))
file:close()
end
manager:machine():popmessage("Cheat written to " .. filename)
else
manager:machine():popmessage("Unable to write file\nCheck cheatpath dir exists")