cheat lua plugins

This forum is for making announcements about updated cheat files (for any emulator), updated web pages and of course about improvements to the MAME/MESS cheat engine.
User avatar
Pugsy
Posts: 3418
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Contact:

Re: cheat lua plugins

Post by Pugsy » Sun Mar 17, 2019 11:34 pm

Noticed an issue with saving cheats in some systems, as an example in a800 it only has "ram" as a region tag (dev.tag). I can search and test cheats fine but when I come to SAVE the cheats it comes up with the "Unable to write file\nEnsure that cheatpath folder exists" message, which is not accurate it just cant find the region.

I can make it work by adding a new cheat string format which defaults to :maincpu.

Code: Select all

cheat_save.simple_maincpu = string.format("%s,:maincpu,%X,%s,%X,%%s\n", setname, match.addr, widchar, pokevalue)
and then adding

Code: Select all

						else 
							file = io.open(cheat_save.path .. "/cheat.simple", "a")
							if file then
								file:write(string.format(cheat_save.simple_maincpu, desc))
								-- old cheat .dat format, write support only (for cheat forum posting of new cheats if posted in simple format)
								file:write(string.format(cheat_save.dat, desc))
								file:close()
								manager:machine():popmessage(_("Cheat added to cheat.simple"))
								written = true
							end
						end
to before

Code: Select all

						if not written then
However, I see adding a default is a bit of hack which might cause issues if maincpu doesn't exist. Is there a correct/better solution?

Working cheats:

Code: Select all

a800_flop/bdash2,:maincpu,A7,b,9,Infinite Time
:a800_flop/bdash2:40000000:A7:00000009:FFFFFFFF:Infinite Time
a800_flop/bdash2,:maincpu,25AA,b,9,Infinite Lives
:a800_flop/bdash2:40000000:25AA:00000009:FFFFFFFF:Infinite Lives
a800_flop/brucelee,:maincpu,26,b,63,Infinite Lives
:a800_flop/brucelee:40000000:26:00000063:FFFFFFFF:Infinite Lives
a800_flop/brucelee,:maincpu,D4,b,24,Infinite Energy
:a800_flop/brucelee:40000000:D4:00000024:FFFFFFFF:Infinite Energy
Pugsy

Servicing your cheating needs since 1985 ;-)

Grab the latest cheat collection:
MAME 0.221 XML cheat collection 19 JUNE 2020) from http://www.mamecheat.co.uk or direct from:-
http://www.mediafire.com/file/y5dktfpea ... 1.zip/file (ZIP Archive 3.66MB)

crazyc
Posts: 22
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc » Tue Mar 19, 2019 1:55 am

The json cheat format should always be written because it supports everything. Is this for the simple format as the xml format can't work with ram device cheats?

User avatar
Pugsy
Posts: 3418
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Contact:

Re: cheat lua plugins

Post by Pugsy » Tue Mar 19, 2019 11:53 pm

crazyc wrote:
Tue Mar 19, 2019 1:55 am
The json cheat format should always be written because it supports everything. Is this for the simple format as the xml format can't work with ram device cheats?
For the a800 softwarelist example of :

mame a800 brucelee

Without the hack/modification it doesn't write anything at all be it json, xml or simple (written == false and the Unable to write file message pops up).

Also (partially related) it doesn't write a .json file if it's a softwarelist image loaded, I've found a few lynx SL cheats before the modification above and they saved to cheat.simple file fine, but there are no lynx*.json files at all in my cheat folder.

I appreciate my fix is a hack as I've taken ram=maincpu which is strictly wrong, but it does make it write to cheat.simple and it does work when read back in. It is also quick and easy to save and reload multiple cheats as it appends to cheat.simple, cheat finder created json files need renaming and merging to load multiple cheats in which gets old quite quick.
Pugsy

Servicing your cheating needs since 1985 ;-)

Grab the latest cheat collection:
MAME 0.221 XML cheat collection 19 JUNE 2020) from http://www.mamecheat.co.uk or direct from:-
http://www.mediafire.com/file/y5dktfpea ... 1.zip/file (ZIP Archive 3.66MB)

crazyc
Posts: 22
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc » Thu Mar 21, 2019 1:50 am

Without the hack/modification it doesn't write anything at all be it json, xml or simple (written == false and the Unable to write file message pops up).
It doesn't create the subdir. If you make a a800_flop directory under cheat they should be created there. I'll have to fix that sometime.
I appreciate my fix is a hack as I've taken ram=maincpu which is strictly wrong, but it does make it write to cheat.simple and it does work when read back in.
Trouble is it'll only work by coincidence. If the cpu name is maincpu and the ram device is mapped at 0 in the program address space. Even the a800 appears to use ram banking which would break that if the bank changes while a cheat is enabled. This is true for the apple 2 and c64 too (it wouldn't affect the ibmpc). Real ram device support will have to be added to the simple cheat parser.

Here's something quick and untested:

Code: Select all

diff --git a/plugins/cheat/cheat_simple.lua b/plugins/cheat/cheat_simple.lua
index 11c63e6e64..9458ea98a7 100644
--- a/plugins/cheat/cheat_simple.lua
+++ b/plugins/cheat/cheat_simple.lua
@@ -70,8 +70,14 @@ end
 
 local function prepare_ram_cheat(desc, tag, addr, val, size)
        local cheat
+       local wtype = " cpup:write_u" .. size
        if desc:sub(1,1) ~= "^" then
-               currcheat = { desc = desc, space = { cpup = { tag = tag, type = "program" } }, script = { run = "" } }
+               if manager:machine().devices[tag].spaces["program"] then
+                       currcheat = { desc = desc, space = { cpup = { tag = tag, type = "program" } }, script = { run = "" } }
+               else
+                       currcheat = { desc = desc, ram = { ram = tag }, script = { run = "" } }
+                       wtype = " ram:write"
+               end
                cheat = currcheat
        end
-       currcheat.script.run = currcheat.script.run .. " cpup:write_u" .. size .. "(" .. addr .. "," .. val .. ", true)"
+       currcheat.script.run = currcheat.script.run .. wtype .. "(" .. addr .. "," .. val .. ", true)"
        return cheat
 end

You'd then replace :maincpu with the ram device tag (probably :ram).

algorithm
Posts: 1
Joined: Mon May 25, 2020 11:49 pm

Re: cheat lua plugins

Post by algorithm » Tue May 26, 2020 7:24 am

Not sure if this would be possible, but it would be amazingly convenient if there was a way to hover mouse and see sprite address?
Im aware of the tile ripping mame, but the idea of dumping giant varieties of data when only 1 part is desired isnt the best.Also the idea of having 100 different iterations of mame isnt so ideal.

If its not possible via cheat find but another way please let me know.

Thanks crazyc and Pugsy for all you have done, keep up the great work.

crazyc
Posts: 22
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc » Wed May 27, 2020 12:47 am

This isn't possible in a general way. It is potentially possible for all the software on a particular hardware platform in lua but not with the cheat engine or finder.

algorithm
Posts: 1
Joined: Mon May 25, 2020 11:49 pm

Re: cheat lua plugins

Post by algorithm » Wed May 27, 2020 6:17 pm

crazyc wrote:
> This isn't possible in a general way. It is potentially possible for all
> the software on a particular hardware platform in lua but not with the
> cheat engine or finder.

All good, after asking I figured it wouldnt be, but a closed mouth doesnt get fed. lol
Thanks again

Post Reply