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.
Post Reply
User avatar
Pugsy
Posts: 3679
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: cheat lua plugins

Post by Pugsy »

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 8)

Grab the latest cheat collection:
MAME 0.264 XML cheat collection (3 APRIL 2024) from http://www.mamecheat.co.uk or direct from:-
https://mega.nz/file/SxsQUJoT#jBdz6GLm_ ... QzFGSMms2c (ZIP Archive 3.8 MB)
crazyc
Posts: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc »

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: 3679
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: cheat lua plugins

Post by Pugsy »

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 8)

Grab the latest cheat collection:
MAME 0.264 XML cheat collection (3 APRIL 2024) from http://www.mamecheat.co.uk or direct from:-
https://mega.nz/file/SxsQUJoT#jBdz6GLm_ ... QzFGSMms2c (ZIP Archive 3.8 MB)
crazyc
Posts: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc »

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 »

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: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc »

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 »

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: 3679
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: cheat lua plugins

Post by Pugsy »

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 8)

Grab the latest cheat collection:
MAME 0.264 XML cheat collection (3 APRIL 2024) from http://www.mamecheat.co.uk or direct from:-
https://mega.nz/file/SxsQUJoT#jBdz6GLm_ ... QzFGSMms2c (ZIP Archive 3.8 MB)
crazyc
Posts: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc »

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: 3679
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: cheat lua plugins

Post by Pugsy »

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 8)

Grab the latest cheat collection:
MAME 0.264 XML cheat collection (3 APRIL 2024) from http://www.mamecheat.co.uk or direct from:-
https://mega.nz/file/SxsQUJoT#jBdz6GLm_ ... QzFGSMms2c (ZIP Archive 3.8 MB)
crazyc
Posts: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc »

For now I made it a -verbose warning.
TheCimmerian
Posts: 2
Joined: Sat Jul 08, 2017 8:57 am

Re: cheat lua plugins

Post by TheCimmerian »

Hi there.

I'm writing because I've just downloaded the new version of MAME (0227) and the SET function for the cheats (the one that you can map to a button) no longer works. I don't know what I'm doing wrong, the plugin.ini that mame generates is very much the same that before, but when I want to set the cheat, I'm getting this error: [LUA ERROR] in menu_callback [string "P1 Drain All Energy Now"]:1: attempt to call a nil value (method 'write_log_u8')

This is really weird, because the last mame version didn't have any problems setting a key to a cheat; besides that the cheat codes work as intended.
What can it be?

Happy New Year and thanks for your time.
User avatar
Pugsy
Posts: 3679
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: cheat lua plugins

Post by Pugsy »

To quote crazyc from another post:-
crazyc wrote: Fri Jan 01, 2021 7:57 pm This was fixed after release. Get https://raw.githubusercontent.com/mamed ... at_xml.lua and put it in your plugins/cheat directory.
Pugsy

Servicing your cheating needs since 1985 8)

Grab the latest cheat collection:
MAME 0.264 XML cheat collection (3 APRIL 2024) from http://www.mamecheat.co.uk or direct from:-
https://mega.nz/file/SxsQUJoT#jBdz6GLm_ ... QzFGSMms2c (ZIP Archive 3.8 MB)
TheCimmerian
Posts: 2
Joined: Sat Jul 08, 2017 8:57 am

Re: cheat lua plugins

Post by TheCimmerian »

Pugsy wrote:
> To quote crazyc from another post:-
>
> [quote=crazyc post_id=25850 time=1609527443 user_id=22938]
> This was fixed after release. Get
> https://raw.githubusercontent.com/mamed ... at_xml.lua
> and put it in your plugins/cheat directory.
> [/quote]

Thanks. It worked like a charm.
ZX81v2
Posts: 0
Joined: Mon May 17, 2021 3:04 pm

Re: cheat lua plugins

Post by ZX81v2 »

So... Is there an actual file for these cheats as such, I don't understand the LUA cheat system, where as cheats used to be in a file cheat.dat, now how do I get any cheats without having to find them and do everything by hand?!
Cheat.dat worked simply and contained all the cheats I used. LUA is a little confusing, especially for actual Cheat collection like cheat.dat did.
No cheat.dat update since 221...
Am I missing something?
crazyc
Posts: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc »

Lua cheats are part of the cheat package. If you use the plugin they will be listed in the Plugins-Cheats menu otherwise they are ignored.
ZX81v2
Posts: 0
Joined: Mon May 17, 2021 3:04 pm

Re: cheat lua plugins

Post by ZX81v2 »

sorry for late reply, but thanks :)
User avatar
Pugsy
Posts: 3679
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: cheat lua plugins

Post by Pugsy »

@crazyc

I am running through some tests for the next cheat file update, there seems to be a problem with 'height' in the json/lua hitbox viewer cheats.

error cheat script error: "Hitbox viewer" [string "Hitbox vieweron"]:223: attempt to call a number value (method 'height')

So far only tested on sf2 and sf2ce but I guess it will be on the other ones..
Pugsy

Servicing your cheating needs since 1985 8)

Grab the latest cheat collection:
MAME 0.264 XML cheat collection (3 APRIL 2024) from http://www.mamecheat.co.uk or direct from:-
https://mega.nz/file/SxsQUJoT#jBdz6GLm_ ... QzFGSMms2c (ZIP Archive 3.8 MB)
crazyc
Posts: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: cheat lua plugins

Post by crazyc »

I was hoping that wouldn't happen but thankfully it's not a big problem. Screen height is a property now so changing screen:height() to screen.height should fix it.
User avatar
Pugsy
Posts: 3679
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: cheat lua plugins

Post by Pugsy »

Thanks, that's sorted it.
Pugsy

Servicing your cheating needs since 1985 8)

Grab the latest cheat collection:
MAME 0.264 XML cheat collection (3 APRIL 2024) from http://www.mamecheat.co.uk or direct from:-
https://mega.nz/file/SxsQUJoT#jBdz6GLm_ ... QzFGSMms2c (ZIP Archive 3.8 MB)
Post Reply