* Cheats: update the window when ROM is changed

* Cheats: show the number of active cheats after a ROM is loaded
This commit is contained in:
ansstuff 2013-02-28 13:33:13 +00:00
parent d814920f00
commit 755d9dc64d
2 changed files with 89 additions and 92 deletions

View File

@ -68,25 +68,29 @@ HWND hGGConv;
void EncodeGG(char *str, int a, int v, int c);
void ListGGAddresses();
uint16 StrToU16(char *s) {
uint16 StrToU16(char *s)
{
unsigned int ret=0;
sscanf(s,"%4x",&ret);
return ret;
}
uint8 StrToU8(char *s) {
uint8 StrToU8(char *s)
{
unsigned int ret=0;
sscanf(s,"%2x",&ret);
return ret;
}
char *U16ToStr(uint16 a) {
char *U16ToStr(uint16 a)
{
static char str[5];
sprintf(str,"%04X",a);
return str;
}
char *U8ToStr(uint8 a) {
char *U8ToStr(uint8 a)
{
static char str[3];
sprintf(str,"%02X",a);
return str;
@ -94,7 +98,8 @@ char *U8ToStr(uint8 a) {
static HWND hwndLB;
//int RedoCheatsCallB(char *name, uint32 a, uint8 v, int s) { //bbit edited: this commented out line was changed to the below for the new fceud
int RedoCheatsCallB(char *name, uint32 a, uint8 v, int c, int s, int type, void*data) {
int RedoCheatsCallB(char *name, uint32 a, uint8 v, int c, int s, int type, void*data)
{
char str[259] = { 0 };
strcpy(str,(s?"* ":" "));
@ -112,13 +117,25 @@ int RedoCheatsCallB(char *name, uint32 a, uint8 v, int c, int s, int type, void*
return 1;
}
void RedoCheatsLB(HWND hwndDlg) {
SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_RESETCONTENT,0,0);
hwndLB=hwndDlg;
FCEUI_ListCheats(RedoCheatsCallB,0);
void RedoCheatsLB(HWND hwndDlg)
{
SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LB_RESETCONTENT, 0, 0);
hwndLB = hwndDlg;
FCEUI_ListCheats(RedoCheatsCallB, 0);
if (selcheat >= 0)
{
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_DEL), TRUE);
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_UPD), TRUE);
} else
{
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_DEL), FALSE);
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_UPD), FALSE);
}
}
int ShowResultsCallB(uint32 a, uint8 last, uint8 current) {
int ShowResultsCallB(uint32 a, uint8 last, uint8 current)
{
char temp[16];
sprintf(temp,"$%04X: %02X | %02X",(unsigned int)a,last,current);
@ -126,7 +143,8 @@ int ShowResultsCallB(uint32 a, uint8 last, uint8 current) {
return 1;
}
void ShowResults(HWND hwndDlg) {
void ShowResults(HWND hwndDlg)
{
int n=FCEUI_CheatSearchGetCount();
int t;
char str[20];
@ -148,7 +166,8 @@ void ShowResults(HWND hwndDlg) {
SetDlgItemText(hwndDlg,IDC_CHEAT_BOX_POSSIBILITIES,str);
}
void EnableCheatButtons(HWND hwndDlg, int enable) {
void EnableCheatButtons(HWND hwndDlg, int enable)
{
EnableWindow(GetDlgItem(hwndDlg,IDC_CHEAT_VAL_KNOWN),enable);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_KNOWN),enable);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_EQ),enable);
@ -157,7 +176,8 @@ void EnableCheatButtons(HWND hwndDlg, int enable) {
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_LT),enable);
}
BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LOGFONT lf;
RECT wrect;
@ -169,7 +189,8 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
int c;
int s;
switch (uMsg) {
switch (uMsg)
{
case WM_INITDIALOG:
if (ChtPosX==-32000) ChtPosX=0; //Just in case
if (ChtPosY==-32000) ChtPosY=0;
@ -204,9 +225,8 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
//disable or enable buttons
EnableWindow(GetDlgItem(hwndDlg,IDC_CHEAT_VAL_KNOWN),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_DEL),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_UPD),FALSE);
if (scrollnum) {
if (scrollnum)
{
EnableCheatButtons(hwndDlg,TRUE);
ShowResults(hwndDlg);
sprintf(str,"%d Possibilities",(int)FCEUI_CheatSearchGetCount());
@ -215,11 +235,8 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
else EnableCheatButtons(hwndDlg,FALSE);
//misc setup
//RedoCheatsLB(hwndDlg); //adelikat: Moved to UpdateCheatsAdded() function
searchdone=0;
SetDlgItemText(hwndDlg,IDC_CHEAT_VAL_KNOWN,(LPTSTR)U8ToStr(knownvalue));
InitializeCheatsAdded(hwndDlg);
// Enable Context Sub-Menus
hCheatcontext = LoadMenu(fceu_hInstance,"CHEATCONTEXTMENUS");
@ -453,16 +470,14 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
SetDlgItemText(hwndDlg,IDC_CHEAT_VAL,(LPTSTR)"");
SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)"");
SetDlgItemText(hwndDlg,IDC_CHEAT_NAME,(LPTSTR)"");
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_DEL),TRUE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_UPD),TRUE);
}
if(hMemView)UpdateColorTable(); //if the memory viewer is open then update any blue freeze locations in it as well
if (hMemView) UpdateColorTable(); //if the memory viewer is open then update any blue freeze locations in it as well
UpdateCheatsAdded();
break;
case ID_CHEATLISTPOPUP_DELETESELECTEDCHEATS:
case IDC_BTN_CHEAT_DEL:
if (selcheatcount > 1) {
if (selcheatcount > 1)
{
if (IDYES == MessageBox(hwndDlg, "Multiple cheats selected. Continue with delete?", "Delete multiple cheats?", MB_ICONQUESTION | MB_YESNO)) { //Get message box
selcheat=-1;
for (int selcheattemp=SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_GETCOUNT,0,0)-1;selcheattemp>=0;selcheattemp--) {
@ -475,9 +490,7 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
SetDlgItemText(hwndDlg,IDC_CHEAT_VAL,(LPTSTR)"");
SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)"");
SetDlgItemText(hwndDlg,IDC_CHEAT_NAME,(LPTSTR)"");
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_DEL),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_UPD),FALSE);
if(hMemView)UpdateColorTable(); //if the memory viewer is open then update any blue freeze locations in it as well
if (hMemView) UpdateColorTable(); //if the memory viewer is open then update any blue freeze locations in it as well
UpdateCheatsAdded();
}
} else {
@ -490,9 +503,7 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)"");
SetDlgItemText(hwndDlg,IDC_CHEAT_NAME,(LPTSTR)"");
}
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_DEL),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_UPD),FALSE);
if(hMemView)UpdateColorTable(); //if the memory viewer is open then update any blue freeze locations in it as well
if (hMemView) UpdateColorTable(); //if the memory viewer is open then update any blue freeze locations in it as well
UpdateCheatsAdded();
}
break;
@ -566,8 +577,6 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
if (file)
{
FCEU_LoadGameCheats(file);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_DEL),TRUE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_UPD),TRUE);
if (hMemView) UpdateColorTable(); //if the memory viewer is open then update any blue freeze locations in it as well
UpdateCheatsAdded();
savecheats = 1;
@ -670,16 +679,18 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
case LBN_SELCHANGE:
switch (LOWORD(wParam)) {
case IDC_LIST_CHEATS:
selcheat = SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_GETCURSEL,0,0);
selcheatcount = SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_GETSELCOUNT,0,0);
selcheat = SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LB_GETCURSEL, 0, 0);
selcheatcount = SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LB_GETSELCOUNT, 0, 0);
if (selcheat < 0) break;
FCEUI_GetCheat(selcheat,&name,&a,&v,&c,&s,NULL);
SetDlgItemText(hwndDlg,IDC_CHEAT_NAME,(LPTSTR)name);
SetDlgItemText(hwndDlg,IDC_CHEAT_ADDR,(LPTSTR)U16ToStr(a));
SetDlgItemText(hwndDlg,IDC_CHEAT_VAL,(LPTSTR)U8ToStr(v));
if(c == -1) SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)"");
else SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)U8ToStr(c));
if (c == -1)
SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)"");
else
SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)U8ToStr(c));
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_DEL),TRUE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_UPD),TRUE);
@ -721,8 +732,10 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
}
void ConfigCheats(HWND hParent) {
if (!GameInfo) {
void ConfigCheats(HWND hParent)
{
if (!GameInfo)
{
FCEUD_PrintError("You must have a game loaded before you can manipulate cheats.");
return;
}
@ -736,9 +749,10 @@ void ConfigCheats(HWND hParent) {
selcheat=-1;
CheatWindow=1;
if (CheatStyle)
pwindow = hCheat = CreateDialog(fceu_hInstance,"CHEATCONSOLE",NULL,CheatConsoleCallB);
pwindow = hCheat = CreateDialog(fceu_hInstance, "CHEATCONSOLE", NULL, CheatConsoleCallB);
else
DialogBox(fceu_hInstance,"CHEATCONSOLE",hParent,CheatConsoleCallB);
UpdateCheatsAdded();
} else
{
ShowWindow(hCheat, SW_SHOWNORMAL);
@ -754,57 +768,34 @@ void UpdateCheatList()
ShowResults(pwindow);
}
//This is necessary during the intialization of the cheats dialog, it is redundant with UpdateCheatsAdded except the handle is passed by CheatConsoleCallB
void InitializeCheatsAdded(HWND hwndDlg)
{
char temp[64];
if (FrozenAddressCount < 256)
sprintf(temp,"Active Cheats %d", FrozenAddressCount);
else if (FrozenAddressCount == 256)
{
sprintf(temp,"Active Cheats %d (Max Limit)", FrozenAddressCount);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_ADD),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_ADDFROMFILE),FALSE);
}
else
{
sprintf(temp,"%d Error: Too many cheats loaded!", FrozenAddressCount);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_ADD),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_ADDFROMFILE),FALSE);
}
SetDlgItemText(hwndDlg,201,temp);
RedoCheatsLB(hwndDlg);
}
//Used by cheats and external dialogs such as hex editor to update items in the cheat search dialog
void UpdateCheatsAdded()
{
char temp[64];
if(!pwindow)
return;
if (FrozenAddressCount < 256)
{
sprintf(temp,"Active Cheats %d", FrozenAddressCount);
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADD), TRUE);
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADDFROMFILE), TRUE);
} else if (FrozenAddressCount == 256)
{
sprintf(temp,"Active Cheats %d (Max Limit)", FrozenAddressCount);
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADD), FALSE);
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADDFROMFILE), FALSE);
}
else
{
if (FrozenAddressCount < 256)
sprintf(temp,"Active Cheats %d", FrozenAddressCount);
else if (FrozenAddressCount == 256)
{
sprintf(temp,"Active Cheats %d (Max Limit)", FrozenAddressCount);
EnableWindow(GetDlgItem(hCheat,IDC_BTN_CHEAT_ADD),FALSE);
EnableWindow(GetDlgItem(hCheat,IDC_BTN_CHEAT_ADDFROMFILE),FALSE);
}
else
{
sprintf(temp,"%d Error: Too many cheats loaded!", FrozenAddressCount);
EnableWindow(GetDlgItem(hCheat,IDC_BTN_CHEAT_ADD),FALSE);
EnableWindow(GetDlgItem(hCheat,IDC_BTN_CHEAT_ADDFROMFILE),FALSE);
}
SetDlgItemText(hCheat,201,temp);
RedoCheatsLB(hCheat);
sprintf(temp,"%d Error: Too many cheats loaded!", FrozenAddressCount);
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADD), FALSE);
EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADDFROMFILE), FALSE);
}
SetDlgItemText(hCheat,201,temp);
RedoCheatsLB(hCheat);
}
BOOL CALLBACK GGConvCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
BOOL CALLBACK GGConvCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
char str[100];
int i;
@ -934,7 +925,8 @@ BOOL CALLBACK GGConvCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
//The code in this function is a modified version
//of Chris Covell's work - I'd just like to point that out
void EncodeGG(char *str, int a, int v, int c){
void EncodeGG(char *str, int a, int v, int c)
{
uint8 num[8];
static char lets[16]={'A','P','Z','L','G','I','T','Y','E','O','X','U','K','S','V','N'};
int i;
@ -962,7 +954,8 @@ void EncodeGG(char *str, int a, int v, int c){
return;
}
void ListGGAddresses(){
void ListGGAddresses()
{
uint32 i, j = 0; //mbg merge 7/18/06 changed from int
char str[20];
SendDlgItemMessage(hGGConv,IDC_LIST_GGADDRESSES,LB_RESETCONTENT,0,0);
@ -981,14 +974,13 @@ void ListGGAddresses(){
SendDlgItemMessage(hGGConv,IDC_LIST_GGADDRESSES,LB_ADDSTRING,0,(LPARAM)(LPSTR)str);
}
}
}
//A different model for this could be to have everything
//set in the INITDIALOG message based on the internal
//variables, and have this simply call that.
void SetGGConvFocus(int address,int compare){
void SetGGConvFocus(int address,int compare)
{
char str[10];
if(!hGGConv)DoGGConv();
GGaddr = address;

View File

@ -76,6 +76,7 @@ extern void RefreshThrottleFPS();
//TODO - we really need some kind of global platform-specific options api
#ifdef WIN32
#include "drivers/win/main.h"
#include "drivers/win/memview.h"
#include "drivers/win/cheat.h"
#include "drivers/win/texthook.h"
#include "drivers/win/ram_search.h"
@ -486,11 +487,6 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen
if (GameInfo->type != GIT_NSF)
FCEU_LoadGameCheats(0);
#if defined (WIN32) || defined (WIN64)
DoDebuggerDataReload(); // Reloads data without reopening window
CDLoggerROMChanged();
#endif
if (AutoResumePlay && (GameInfo->type != GIT_NSF))
{
// load "-resume" savestate
@ -502,6 +498,15 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen
ResetScreenshotsCounter();
#if defined (WIN32) || defined (WIN64)
DoDebuggerDataReload(); // Reloads data without reopening window
CDLoggerROMChanged();
if (hMemView) UpdateColorTable();
if (hCheat) UpdateCheatsAdded();
if (FrozenAddressCount)
FCEU_DispMessage("%d cheats active", 0, FrozenAddressCount);
#endif
return GameInfo;
}