Customized cheat.c

If you are having problems finding or using cheats for an Emulator (particularly MAME/MESS) or have found a trick that you wish to share this is the place to do it. But please read the Cheat FAQ first.
stephh
Posts: 601
Joined: Fri Aug 17, 2001 1:00 am
Location: Paris, France

Post by stephh »

I've been very busy last 2 weeks, and I submitted the updated source file too late :( But, here is Aaron's reply :
It was too late for u5, and I don't like to include big scary changes in a non-u release. It will be in u1.
Anyway, the new stuff is great (even if I haven't found time to check how it was coded) :)

Image Steph from The Ultimate Patchers Image
Last edited by stephh on Tue Nov 07, 2006 5:04 pm, edited 1 time in total.
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

I succeeded to compile my customized cheat.c in 0.110.
This (latest) version doesn't have an update for cheat source file too (I believe).

And more update info.
  • Added "View Last Results", "Restore Result" and "Region Selection" to the advanced mode.
  • Added quick page switcher by left/right arrow key in the result viewer.
  • Fixed key input bug for watch code addition from watch list menu to cheat list menu.
stephh
Posts: 601
Joined: Fri Aug 17, 2001 1:00 am
Location: Paris, France

Post by stephh »

Added quick page switcher by left/right arrow key in the result viewer.
Good idea ! :)
Fixed key input bug for watch code addition from watch list menu to cheat list menu.
What was the bug ?

Image Steph from The Ultimate Patchers Image
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

stephh wrote:What was the bug ?
It's simple bug.

See ChooseWatch().

Code: Select all

	if(ShiftKeyPressed())					// Pressed Shift Key
	{
		if(input_ui_pressed(IPT_UI_ADD_CHEAT))		// shift + add = insert new watchpoint
		{
			AddWatchBefore(sel);
		}

		if(input_ui_pressed(IPT_UI_DELETE_CHEAT))	// shift + delete = delete selected watchpoint
		{
			DeleteWatchAt(sel);
		}
	}
	else							// Not. So the following functions are available if NOT PRESSED SHIFT KEY
		if(input_ui_pressed(IPT_UI_SAVE_CHEAT))
		{
			if(watch)				// save = save selected watchpoint as watchpoint code to the database
			{
				CheatEntry	entry;

				memset(&entry, 0, sizeof(CheatEntry));

				SetupCheatFromWatchAsWatch(&entry, watch);
				SaveCheat(&entry);
				DisposeCheat(&entry);
			}
		}

		if(input_ui_pressed(IPT_UI_ADD_CHEAT))
		{
			if(watch)
			{
				if(ShiftKeyPressed())		// shift (???) + add = add selcted code as watchpoint code to cheat list
				{
					CheatEntry	* entry = GetNewCheat();

					DisposeCheat(entry);
					SetupCheatFromWatchAsWatch(entry, watch);
				}
				else				// add = add selected code as cheat code to cheat list
				{
					AddCheatFromWatch(watch);
				}
			}
		}
"Shift + Add" is defined twice. (new watchpoint insert and watchpoint code addition to cheat list)
But the later doesn't work because you must get "Shift + Add" and "Not Shift + Add" at the same time. (Check "if - else" again)
I think it's ctrl key instead of shift key.
stephh
Posts: 601
Joined: Fri Aug 17, 2001 1:00 am
Location: Paris, France

Post by stephh »

ARGH ! I don't know what you changed (it seems to be related to the new '_command' options), but cheats in old format (like in MY cheat databases) can't be loaded anymore :( Could you have a look and tell me what's wrong ? TIA for your help ...

Image Steph from The Ultimate Patchers Image
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

stephh wrote:I don't know what you changed (it seems to be related to the new '_command' options), but cheats in old format (like in MY cheat databases) can't be loaded anymore
Sorry, I have not explained about it.

I have left checking convert function (ConvertOldCode()) stand and forgotten completely.
Because I never use old format so that I have been unable to understand this function.
So I have revoked it temporarily.

But in my heart of hearts, I hope to marge old format into new completely and delete it.
Current source file is too big to understand for beginner.
So it may be the best to divide cheat.c, just like recent other MAME core files (user interface etc).
(Yes, ian refered to it and rewrite cheat menu interface in the past...)
But I don't know how to divide because it needs to fix other files (my customization is for cheat.c and cheat.h only) and the cheat engine has too many functions (I have not finished checking all functions yet.)

If you want to bring back old format convertion, delete the following line in LoadCheatFile().

Code: Select all

			else
			{
#ifdef MESS
				if(!MatchesCRCTable(crc))
					continue;
#endif
				continue;		<--- DELETE THIS LINE !
				// convert the old code to the new format
				type = ConvertOldCode(oldCode, oldCPU, &data, &extendData);
			}
		}
Anyway I try to add new command option, "Load Old Format Code".

Code: Select all

MSB                             LSB
33222222 22221111 11111100 00000000
10987654 32109876 54321098 76543210

-------- -------- -------- ---x----     load old format code
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

Oops... I have found the bug about Save Activation Key in Enable/Disable Cheat menu.
In this menu, an activation key will be saved with ctrl key only and even it causes MAME crash under a specific condition.

In EnableDisableCheatMenu()...
BEFORE

Code: Select all

		if(ControlKeyPressed())
		{
			if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
			{
				SaveCheat(entry, sel, 1);			// save activation key

				ui_popup_time(1, "activation key saved");
			}
			else
				ui_popup_time(1, "no activation key");
		}
I have forgotten to add the following line. Please insert it on line 2835.

Code: Select all

if(input_ui_pressed(IPT_UI_SAVE_CHEAT))
AFTER

Code: Select all

		if(ControlKeyPressed())
		{
			if(input_ui_pressed(IPT_UI_SAVE_CHEAT))		// ctrl + save = save activation key
			{
				if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
				{
					SaveCheat(entry, sel, 1);

					ui_popup_time(1, "activation key saved");
				}
				else
					ui_popup_time(1, "no activation key");
			}
		}
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

More update.
  • Fixed saving activation key bug in Enable/Disable Cheat menu. (See the above topic)
  • Added "Load Old Format" command option. Default is OFF. (See the above topic)
  • Added "Save Command (Options) Code". Push "Save Cheat" key in Options menu.
And I have "down"-converted the latest customized cheat.c to HazeMD 0.12a.
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

More update for View Last Result menu.
  • Don't open View Last Result menu to avoid MAME crash in case of no search region like sms.c in HazeMD.
  • Improved key input for View Last Result menu.
    • Right : go to next page
    • Shift + Right : go to last page
    • Ctrl + Right : go to next region
    • Left : go to previous page
    • Shift + Left : go to first page
    • Ctrl + Left : go to previous region
  • Improved "no reults" region skip with arrow key but incomplete.
    First region (in case of left key) or last region (in case of right key) is always displayed even if there don't have any results.
User avatar
Gaius_4
Posts: 138
Joined: Sun Oct 26, 2003 2:27 pm

Post by Gaius_4 »

I have an idea. In the menu - you can always tell wherever you are since it's highlighted. I got to thinking about - when you go into the 'Configure Watchpoints'... in the middle you can see where you're at but it's hard to tell (for me anyways) which one you're on in regards to the numbers/bytes on the far left side of the screen.

What if when you select a certain address - it's byte that you're watching is also highlighted on the left side? :) That way you can tell better which one you may want to delete from watching.

If you don't like the idea... fine. I can stick to counting...

edit: Okay. Here's the real deal. It might be nice to have way to have a space between some addresses that you watch. All those numbers bunched up together can get confusing. :P What I do is watch an extra address that I don't need, then I delete that unneeded address/es from the watch section -- which I usually put between 2 or 3 sets of addresses that I watch.

But sometimes I select the wrong one - after I've deleted it... it's all messed up. :cry:
As always, your patients is appreciated. :cool:
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

Sorry, I can't imagine your idea.
Do you want to see selected item fairly with hilight or space in the watchpoint list menu ? (...why ?)
Anyway I can't understand unless you give a concrete example...
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

I have added new function, "Quick Menu Switch".
If you current cursor is on the return item in Enable/Disable, Add/Edit, Search or Watchpoint menu,
pressging left or right key changes menu directly.

Enable/Disable <-> Add/Edit <-> Search <-> Watchpoint <-> Enable/Disable ...

For example, if move cursor to return item then press left key in "Search" menu, go to "Add/Edit" menu directly.
You don't need to return to the general menu then choose "Add/Edit".
User avatar
Gaius_4
Posts: 138
Joined: Sun Oct 26, 2003 2:27 pm

Post by Gaius_4 »

ShimaPong wrote:Sorry, I can't imagine your idea.
Do you want to see selected item fairly with hilight or space in the watchpoint list menu ? (...why ?)
Anyway I can't understand unless you give a concrete example...
I suppose the spacing wouldn't be needed as long as you can tell which one you're one when it's highlighted. Below is as best of an example I can give. Normally the bytes on the left side of the screen are NOT highlighted. This is what I meant....

00__________FF3F4B (1)
0F__________FF3F4C (1)
65__________FF501D (1)
02__________FF501F (1)
52__________FF473A (1)

When you are in the 'Configure Watchpoints' menu and you select with the down/up arrows... the address you're on is highlighted yellow. These are represented by the addresses in the middle of the screen (i.e. the cheat menu).

The numbers on the left are the bytes/address that you have chosen to watch... and after watching you have a better idea of what IS NOT related to what you're looking for. So, after you Delete the unneeded address the next step would look like this.

00__________FF3F4B (1)
0F__________FF3F4C (1)
65__________FF501D (1)
____________FF501F (0)
52__________FF473A (1)

Notice the '0' and the blank watch field on the left. I know this is a small number of addresses to watch. I was just using it as an example. And everything I've said in this 2nd part - you all know. :P The main focus is on my first example of how when you're in the menu - the same one you have highlighted in the menu is also highlighted on the left.

It would also be nice to not have to add an address from here, go back to add/edit cheat and hit watch. It should be watchable from the 'configure watchpoints' menu without the back tracking -IMO. :oops:
As always, your patients is appreciated. :cool:
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

It's impossible for me.

Because "real" watchpoint can't have to get current cursor position on watchpoint list.
And watchpoint drawing function (ui_draw_text) doesn't require font color parameter so that we can't hilight it.
I think that we need to update menu interface to do but it's not my job.

Ian or stephh may know about it though.
stephh
Posts: 601
Joined: Fri Aug 17, 2001 1:00 am
Location: Paris, France

Post by stephh »

Menus and watches are NOT displayed at the same time, so it's impossible to "highlight" a watch ...

Shimapong, could you please give me a link (and password) to your updated cheat.c file (as well as cheatnew.txt) ?
It would be cool to have your work before MAME 0.111 (even if there might be a 0.110u4 before) ...

Image Steph from The Ultimate Patchers Image
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

Changed input for "Quick Menu Switch".
Because previous input (move cursor to return item then press left or right key) is too annoying.
Therefore I have assigned UI ZOOM IN/OUT key which are unused in the cheat menu.
Also I have assigned the above keys to the button on the joystick.
Yes, this function is for the cheat searcher who uses joystick mainly.

Mounted UI CLEAR key (default : delete key) too.
  • When you edit value, this key resets the value.
  • In the watchpoint list menu, this key resets all watchpoints.
Divided the cheat engine information to cheat.txt and move it into "docs" folder.
It is first step of dividing current "big" cheat source file.
Stephh wrote:Shimapong, could you please give me a link (and password) to your updated cheat.c file (as well as cheatnew.txt) ?
Please wait a few days. I need to check source file and document.
But the main problem is that too many changes more than previous update...


BTW, I have re-tried analizing custom region handling.
The biggest goal for my customization is that hack ROM on encrypted CPU via the cheat engine.
But it's too hard to get a hint...
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

I have found a hint about custom region access via the cheat engine.

See screen shot.
http://zetubou.mine.nu/timer/file/bomber31547_d5.png
Can you confirm that the opcode on $361A is changed (bgt -> bra) ?
Sonicbom is one of segas16b.c games and works on encrypted CPU.
But this hacking is via the cheat engine ONLY. NOT Windows memory editor !

It's miracle but too BAD and DIRTY !

I have mounted memory_get_op_ptr() for the cheat engine.
This function returns the pointer for Program Space itself (and perhaps it's NOT "Region").
You will be able to access to Program Space directly instead of Region.
But normal ROM hacking uses Region pointer so that it will be illigal access.
So if you want to hack a code in BANKED ROM, it may be impossible by this way though.
Because "Program Space" is not "Region" so that all codes are not stored, I think.
And endianness seems to be incorrect...

How to get the pointer for the "custom handling" REGION ?
Does MAME supports it by default, like memory_region() or memory_get_op_ptr() ??

Anyway, I have also succeeded in hacking ROM for sms.c in HazeMD and other encrypted CPU games by this way.
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

Program Space accessor in type filed.

Code: Select all

xxx----- -------- -------- --------     type
                                            000 =   standard memory write
                                            001 =   memory region
                                            010 =   write handler mapped memory
                                            011 =   custom
                                            100 =   relative address (CPU)
                                            101 =   direct program space write
                                            110 =   cheatscript (unmounted now)
                                            111 =   unused
Therefore, Default code (CPU 1) is 0xA0000000 (vs 0x20000000 is normal ROM type).
And it's the best that use "Restore Previous Value" option like other ROM codes.

Sample 1 : Pengo [encrypted]

Code: Select all

:pengo:A0800000:4C2B:00000000:FFFFFFFF:Invincibility
Sample 2 : Sonic Boom [encrypted]

Code: Select all

:sonicbom:A0800000:00361A:00000060:FFFFFFFF:Invincibility - Player
:sonicbom:A0810000:00377A:00000060:FFFFFFFF:Invincibility - Player (2/5):1st = Enemy, 2nd = Fire
:sonicbom:A0810000:004786:00000060:FFFFFFFF:Invincibility - Player (3/5):Large Enemy (Stage 5)
:sonicbom:A0810000:009E5A:00000060:FFFFFFFF:Invincibility - Player (4/5):Electronic Line (Stage 4)
:sonicbom:A0810000:0122BE:00000060:FFFFFFFF:Invincibility - Player (5/5):Explosion (Stage 2)
:sonicbom:A0800000:0037DA:00000060:FFFFFFFF:Invincibility - Side Fighter
Sample 3 : Fantasy Zone (Master System) [custom handling]

Code: Select all

:s_fzone:A0D00000:248E:000037C9:FFFFFFFF:Invincibility
:s_fzone:A0810000:24BC:00000037:FFFFFFFF:Invincibility (2/2):1st = Object, 2nd = Base
NOTE : 1st code for s_fzone uses "endianness" option because different order from normal region code.

...OK, the above codes work fine !
Also I have added it in the code edit screen. You can choose "Program Space" type in this menu.
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

Sample 4 : Aurail

Code: Select all

:aurailj:A0800000:0041C2:00000060:FFFFFFFF:Invincibility
:aurailj:A0810000:004636:00000060:FFFFFFFF:Invincibility (2/8):1st = Mine (3D Stage) 2nd = Enemy (3D Stage)
:aurailj:A0810000:004AD4:00000060:FFFFFFFF:Invincibility (3/8):Missile (3D Stage)
:aurailj:A0810000:004B18:00000060:FFFFFFFF:Invincibility (4/8):Fire (3D Stage)
:aurailj:A0810000:00E5FC:00000060:FFFFFFFF:Invincibility (5/8):Enemy (2D Stage)
:aurailj:A0810000:00E693:00000010:FFFFFFFF:Invincibility (6/8):Fire (2D Stage) [bsr $e6a6 -> $e6a4 (rts)]
:aurailj:A0810000:014822:00000060:FFFFFFFF:Invincibility (7/8):Round 9 Boss
:aurailj:A0810000:02A693:00000064:FFFFFFFF:Invincibility (8/8):Round 16 Boss [$ea66 -> $ea64 (rts)]
Sample 5 : Super Hang-On

Code: Select all

:shangon3:A0800000:007150:00000060:FFFFFFFF:Invincibility
:shangon3:A0810000:0076F8:00000060:FFFFFFFF:Invincibility (2/2):1st = Obstacle, 2nd = Bike
:shangon3:A0800000:008162:00000060:FFFFFFFF:No Slowing Down on Off Road
:shangon3:A0800000:006489:00000000:FFFFFFFF:Always Ready Turbo
The above ROM hacking codes for "SEGA encrypted" games work with program space accesor.

Sample 6 : Jail Break / Manhattan 24 Bunsyo

Code: Select all

:manhatan:A0800000:9A70:00000020:FFFFFFFF:Invincibility - Player
:manhatan:A0810000:9AE2:00000039:FFFFFFFF:Invincibility - Player (2/3):1st = Fire, 2nd = Enemy
:manhatan:A0810000:9B3F:00000020:FFFFFFFF:Invincibility - Player (3/3):Car
:manhatan:A0800000:98E1:00000039:FFFFFFFF:Invincibility - Hostage
Also several Konami encrypted games.

Sample 7 : Fantasy Zone II (Master System)

Code: Select all

;s_fzon2j:60000000:00000:00000000:00000000:----- Invinciblity : 1st = Scenery (Boss), 2nd-13th = Objects [banked ROM] -----
:s_fzon2j:A0800000:013AE:0000007D:FFFFFFFF:Invincibility
:s_fzon2j:39A10000:2FADB:00BF90C3:FFFFFFFF:Invincibility (02/13):BADB - jp $BF90
:s_fzon2j:39B10000:2FF90:00C0A03A:FFFFFFFF:Invincibility (03/13):BF90 - ld a,($C0A0)
:s_fzon2j:39B10000:2FF93:173007FE:FFFFFFFF:Invincibility (04/13):BF93 - cp $07 / BF95 - jr nc,$BFAE
:s_fzon2j:39A10000:2FF97:00007EFD:FFFFFFFF:Invincibility (05/13):BF97 - ld a,(iy+$00)
:s_fzon2j:39B10000:2FF9A:112805FE:FFFFFFFF:Invincibility (06/13):BF9A - cp $05 / BF9C - jr z,$BFAF
:s_fzon2j:39B10000:2FF9E:0D280DFE:FFFFFFFF:Invincibility (07/13):BF9E - cp $0D / BFA0 - jr z,$BFAF
:s_fzon2j:39B10000:2FFA2:093808FE:FFFFFFFF:Invincibility (08/13):BFA2 - cp $08 / BFA4 - jr c,$BFAF
:s_fzon2j:39B10000:2FFA6:043811FE:FFFFFFFF:Invincibility (09/13):BFA6 - cp $11 / BFA8 - jr c,$BFAE
:s_fzon2j:39910000:2FFAA:000015FE:FFFFFFFF:Invincibility (10/13):BFAA - cp $15
:s_fzon2j:39A10000:2FFAC:00C90138:FFFFFFFF:Invincibility (11/13):BFAC - jr c,$BFA4 / BFAE - ret [No Hit - Enemy/Fire]
:s_fzon2j:39B10000:2FFAF:FE02CBDD:FFFFFFFF:Invincibility (12/13):BFAF - set 7,(ix+$02) [Hit - Item/Warp/Shop]
:s_fzon2j:39A10000:2FFB3:00BADFC3:FFFFFFFF:Invincibility (13/13):BFB3 - jp $BADF
;s_fzon2j:60000000:00000:00000000:00000000:----- Starting Round Selection : 2nd-7th = in banked ROM -----
:s_fzon2j:39800300:1FE62:00000006:FFFFFFFF:Select Starting Round [Incomplete]:Can't select final round
:s_fzon2j:A0A10000:01CFC:00BE60CD:FFFFFFFF:Select Starting Round [Incomplete] (2/7):1CFC - call $BE60
:s_fzon2j:39910000:1FE60:00003EF5:FFFFFFFF:Select Starting Round [Incomplete] (3/7):BE60 - push af / BE61 - ld a,$xx [xx = starting round]
:s_fzon2j:39A10000:1FE63:00C0A032:FFFFFFFF:Select Starting Round [Incomplete] (4/7):BE63 - ld ($C0A0),a [main]
:s_fzon2j:39A10000:1FE66:00C0A232:FFFFFFFF:Select Starting Round [Incomplete] (5/7):BE66 - ld ($C0A2),a [display]
:s_fzon2j:39B10000:1FE69:C0A332F1:FFFFFFFF:Select Starting Round [Incomplete] (6/7):BE69 - pop af / BE6A - ld ($C0A3),a
:s_fzon2j:39810000:1FE6D:000000C9:FFFFFFFF:Select Starting Round [Incomplete] (7/7):BE6D - ret
Oops... this game has "banked ROM" problem so that the above codes has mixed memory region and program space codes.
$13AE and $1CFC are not in banked ROM so that it is made by program space type but $BADB and $BE60 are not.
Fortunately it seems to work without problem.
ShimaPong
Posts: 1063
Joined: Wed May 21, 2003 4:19 pm
Location: Japan

Post by ShimaPong »

Sample 8 : Shinobi (encrypted sets)

Code: Select all

:shinobi1:A0800000:003F8A:00000060:FFFFFFFF:Invincibility
Sample 9 : Astro Warrior (Master System)

Code: Select all

;s_astrow:60000000:0000:00000000:00000000:----- Invincibility : 1st-4th = Objects, 5th-8th = Boss -----
:s_astrow:A0900000:1A7D:00001CE0:FFFFFFFF:Invincibility
:s_astrow:A0A10000:1CE0:00007EFD:FFFFFFFF:Invincibility (2/8):1A70 - call $1CE0 / 1CE0 - ld a,(iy+$00)
:s_astrow:A0B10000:1CE3:033013FE:FFFFFFFF:Invincibility (3/8):1CE3 - cp $13 / 1CE5 - jr nc,$1CEA
:s_astrow:A0B10000:1CE7:C91A88CD:FFFFFFFF:Invincibility (4/8):1CE7 - call $1A88 / 1CEA - ret
:s_astrow:A0A10000:2535:001CEBCD:FFFFFFFF:Invincibility (5/8):2535 - call $1CEB
:s_astrow:A0A10000:1CEB:00007EDD:FFFFFFFF:Invincibility (6/8):1CEB - ld a,(ix+$00)
:s_astrow:A0B10000:1CEE:012001FE:FFFFFFFF:Invincibility (7/8):1CEE - cp $01 / 1CF0 - jr nz,$1CF3
:s_astrow:A0910000:1CF2:0000C9AF:FFFFFFFF:Invincibility (8/8):1CF2 - xor a / 1CF3 - ret
If you want to insert original program code, you must find "non-banked" area.
$8000 seems to be empty with 0xFF but it is in banked ROM so that you can't use this addresse.
Post Reply