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: 3445
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: 28
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: 3445
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: 28
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: 28
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

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

Re: cheat lua plugins

Post by Pugsy » Sun Sep 06, 2020 1:12 am

I've been noticing that some nes gg codes don't seem to work in cheat.simple.....I surmise this is the fact that it's searching in 8k blocks from 0000 and poking the first compare match it gets based on the comment "-- assume 8K banks, 32K also common but is an easy multiple of 8K" in cheat_simple.lua.

Example:-

Code: Select all

nes/cluclu,gg,AEVSNAAL,Invincibility (No Hit)
nes/cluclu,gg,AVKTZPAZ,^

address: d8ef compare:30 poke:00
address: e1c2 compare:20 poke:60

<action condition="(nes_slot:cart:prg_rom.mb@58EF==30)">nes_slot:cart:prg_rom.mb@58EF=00</action> <!-- D8EF?30-00 -->
<action condition="(nes_slot:cart:prg_rom.mb@61C2==20)">nes_slot:cart:prg_rom.mb@61C2=60</action> <!-- E1C2?20-60 -->
However, because of mirroring cheat_simple.lua is poking 18EF & 01C2 as they match the compare value. From what I've seen in NES gg codes most codes use a 32K block size.

Is it possible to change the way it works so that it looks for a match using the 32K block size first (58ef,d8ef,158ef,1d8ef etc) and then falls back to a 8K block size (18ef, 38ef, 58ef, 78ef etc) if it can't find a compare value match on the 32k block size.

What to do with 6 bit GG NES codes is another problem....they are an invention of the devil and I'm not sure that supporting them at all is a good idea when it's not possible to determine if the nes_slot:cart:prg_rom.mb address == PC in any meaningful way.

Because of the amount of paging the NES does they are frowned upon by the cheat community for causing bugs/crashes.
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: 28
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc » Mon Sep 07, 2020 7:38 pm

Is it possible to change the way it works so that it looks for a match using the 32K block size first (58ef,d8ef,158ef,1d8ef etc) and then falls back to a 8K block size (18ef, 38ef, 58ef, 78ef etc) if it can't find a compare value match on the 32k block size.
Sure, this isn't hard.
What to do with 6 bit GG NES codes is another problem....they are an invention of the devil and I'm not sure that supporting them at all is a good idea when it's not possible to determine if the nes_slot:cart:prg_rom.mb address == PC in any meaningful way.
Maybe the parser can print a warning (or error out but that might be excessive) if a 6 char code is used with a game that has >32K prg rom size.

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

Re: cheat lua plugins

Post by Pugsy » Tue Sep 08, 2020 4:01 pm

Thanks, much appreciated....I did look at the code but I didn't know where to start for that.

Whatever you think is best on 6 character codes, in the cheat.simple I use which is based on your original cheat.simple release I have 118 6-char nes codes (a third of them are for smb1 alone) compared with 6251 8-char codes. More than 75% of the 6-char code games I'd say are 32K games. New 6 char codes generally don't get made by anyone who knows what they are doing. A lot of 6 character codes in the past believe it or not were made by people entering random codes and seeing what it did.....complete and utter madness!! monkeys and typewriters...
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: 28
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc » Wed Sep 09, 2020 12:54 am

For now I made it a -verbose warning.

Post Reply