diff --git a/src/cheat.cpp b/src/cheat.cpp index 0b8f4166..fbdd901b 100644 --- a/src/cheat.cpp +++ b/src/cheat.cpp @@ -40,7 +40,7 @@ static uint8 *CheatRPtrs[64]; vector FrozenAddresses; //List of addresses that are currently frozen void UpdateFrozenList(void); //Function that populates the list of frozen addresses -unsigned int FrozenAddressCount=0; //Keeps up with the Frozen address count, necessary for using in other dialogs (such as hex editor) +unsigned int FrozenAddressCount = 0; //Keeps up with the Frozen address count, necessary for using in other dialogs (such as hex editor) void FCEU_CheatResetRAM(void) { @@ -60,9 +60,9 @@ void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p) } -CHEATF_SUBFAST SubCheats[256]; -uint32 numsubcheats=0; -struct CHEATF *cheats=0,*cheatsl=0; +CHEATF_SUBFAST SubCheats[256] = { 0 }; +uint32 numsubcheats = 0; +struct CHEATF *cheats = 0, *cheatsl = 0; #define CHEATC_NONE 0x8000 @@ -74,7 +74,7 @@ int savecheats = 0; static DECLFR(SubCheatsRead) { - CHEATF_SUBFAST *s=SubCheats; + CHEATF_SUBFAST *s = SubCheats; int x=numsubcheats; do @@ -99,40 +99,35 @@ static DECLFR(SubCheatsRead) void RebuildSubCheats(void) { uint32 x; - struct CHEATF *c=cheats; - for(x=0;xtype==1 && c->status) + if(c->type == 1 && c->status) { - if(GetReadHandler(c->addr)==SubCheatsRead) + if(GetReadHandler(c->addr) != SubCheatsRead) { - /* Prevent a catastrophe by this check. */ - //FCEU_DispMessage("oops",0); - } - else - { - SubCheats[numsubcheats].PrevRead=GetReadHandler(c->addr); - SubCheats[numsubcheats].addr=c->addr; - SubCheats[numsubcheats].val=c->val; - SubCheats[numsubcheats].compare=c->compare; - SetReadHandler(c->addr,c->addr,SubCheatsRead); + SubCheats[numsubcheats].PrevRead = GetReadHandler(c->addr); + SubCheats[numsubcheats].addr = c->addr; + SubCheats[numsubcheats].val = c->val; + SubCheats[numsubcheats].compare = c->compare; + SetReadHandler(c->addr, c->addr, SubCheatsRead); numsubcheats++; } } - c=c->next; + c = c->next; } FrozenAddressCount = numsubcheats; //Update the frozen address list UpdateFrozenList(); - //FCEUI_DispMessage("Active Cheats: %d",0, FrozenAddresses.size()/*FrozenAddressCount*/); //Debug + } void FCEU_PowerCheats() { - numsubcheats=0; /* Quick hack to prevent setting of ancient read addresses. */ + numsubcheats = 0; /* Quick hack to prevent setting of ancient read addresses. */ RebuildSubCheats(); } @@ -154,31 +149,38 @@ static void CheatMemErr(void) static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type) { struct CHEATF *temp; - if(!(temp=(struct CHEATF *)FCEU_dmalloc(sizeof(struct CHEATF)))) + if(!(temp = (struct CHEATF *)FCEU_dmalloc(sizeof(struct CHEATF)))) { CheatMemErr(); return(0); } - temp->name=name; - temp->addr=addr; - temp->val=val; - temp->status=status; - temp->compare=compare; - temp->type=type; - temp->next=0; + + temp->name = strcpy((char*) FCEU_dmalloc(strlen(name) + 1), name); + temp->addr = addr; + temp->val = val; + temp->status = status; + temp->compare = compare; + temp->type = type; + temp->next = 0; if(cheats) { - cheatsl->next=temp; - cheatsl=temp; + cheatsl->next = temp; + cheatsl = temp; } else - cheats=cheatsl=temp; + cheats = cheatsl = temp; - return(1); + return (1); } -void FCEU_LoadGameCheats(FILE *override) +/* The "override_existing" parameter is used only in cheat dialog import. + Since the default behaviour will reset numsubcheats to 0 everytime, + In game loading, this is absolutely right, but when importing in cheat window, + resetting numsubcheats to 0 will override existed cheat items to make them + invalid. +*/ +void FCEU_LoadGameCheats(FILE *override, int override_existing) { FILE *fp; unsigned int addr; @@ -189,84 +191,95 @@ void FCEU_LoadGameCheats(FILE *override) int x; char linebuf[2048]; - char *namebuf; - int tc=0; + char *namebuf = NULL; + int tc = 0; char *fn; - numsubcheats=savecheats=0; + savecheats = 0; + if (override_existing) + numsubcheats = 0; if(override) fp = override; else { - fn=strdup(FCEU_MakeFName(FCEUMKF_CHEAT,0,0).c_str()); - fp=FCEUD_UTF8fopen(fn,"rb"); + fn = strdup(FCEU_MakeFName(FCEUMKF_CHEAT, 0, 0).c_str()); + fp = FCEUD_UTF8fopen(fn, "rb"); free(fn); - if(!fp) return; + if (!fp) { + return; + } } - FCEU_DispMessage("Cheats file loaded.",0); //Tells user a cheats file was loaded. - while(fgets(linebuf,2048,fp) != nullptr) + while(fgets(linebuf, 2048, fp) != nullptr) { - char *tbuf=linebuf; - int doc=0; + char *tbuf = linebuf; + int doc = 0; - addr=val=compare=status=type=0; + addr = val = compare = status = type = 0; - if(tbuf[0]=='S') + if(tbuf[0] == 'S') { tbuf++; - type=1; + type = 1; } - else type=0; + else + type = 0; - if(tbuf[0]=='C') + if(tbuf[0] == 'C') { tbuf++; - doc=1; + doc = 1; } - if(tbuf[0]==':') + if(tbuf[0] == ':') { tbuf++; - status=0; + status = 0; } - else status=1; + else status = 1; if(doc) { - char *neo=&tbuf[4+2+2+1+1+1]; - if(sscanf(tbuf,"%04x%*[:]%02x%*[:]%02x",&addr,&val,&compare)!=3) + char *neo = &tbuf[4+2+2+1+1+1]; + if(sscanf(tbuf, "%04x%*[:]%02x%*[:]%02x", &addr, &val, &compare) != 3) continue; - if (!(namebuf=(char *)FCEU_dmalloc(strlen(neo)+1))) + if (!(namebuf = (char *)FCEU_dmalloc(strlen(neo) + 1))) return; - strcpy(namebuf,neo); + strcpy(namebuf, neo); } else { - char *neo=&tbuf[4+2+1+1]; - if(sscanf(tbuf,"%04x%*[:]%02x",&addr,&val)!=2) + char *neo = &tbuf[4+2+1+1]; + if(sscanf(tbuf, "%04x%*[:]%02x", &addr, &val) != 2) continue; - if (!(namebuf=(char *)FCEU_dmalloc(strlen(neo)+1))) + if (!(namebuf = (char *)FCEU_dmalloc(strlen(neo) + 1))) return; - strcpy(namebuf,neo); + strcpy(namebuf, neo); } - for(x=0;x<(int)strlen(namebuf);x++) + for(x = 0; x < (int)strlen(namebuf); x++) { - if(namebuf[x]==10 || namebuf[x]==13) + if(namebuf[x] == 10 || namebuf[x] == 13) { - namebuf[x]=0; + namebuf[x] = 0; break; } else if(namebuf[x] > 0x00 && namebuf[x] < 0x20) - namebuf[x]=0x20; + namebuf[x] = 0x20; } - AddCheatEntry(namebuf,addr,val,doc?compare:-1,status,type); + AddCheatEntry(namebuf, addr, val, doc ? compare : -1, status, type); tc++; } + + if (namebuf) + free(namebuf); + RebuildSubCheats(); + + FCEU_DispMessage("Cheats file loaded.", 0); //Tells user a cheats file was loaded. + if(!override) fclose(fp); } @@ -355,23 +368,26 @@ void FCEU_FlushGameCheats(FILE *override, int nosave) int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type) { - char *t; + char *t = NULL; - if(!(t=(char *)FCEU_dmalloc(strlen(name)+1))) + if(!(t = (char *)FCEU_dmalloc(strlen(name) + 1))) { CheatMemErr(); return(0); } strcpy(t,name); - if(!AddCheatEntry(t,addr,val,compare,1,type)) + if(!AddCheatEntry(t, addr, val, compare, 1, type)) { free(t); return(0); } - savecheats=1; + savecheats = 1; RebuildSubCheats(); - return(1); + if (t) + free(t); + + return 1; } int FCEUI_DelCheat(uint32 which) @@ -588,43 +604,40 @@ int FCEUI_DecodePAR(const char *str, int *a, int *v, int *c, int *type) int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int c, int s, int type) { - struct CHEATF *next=cheats; - uint32 x=0; + struct CHEATF *next = cheats; + uint32 x = 0; while(next) { - if(x==which) + if(x == which) { if(name) { char *t; - if((t=(char *)realloc(next->name, strlen(name)+1))) - { - next->name=t; - strcpy(next->name,name); - } + if((t = (char *)realloc(next->name, strlen(name) + 1))) + strcpy(next->name = t, name); else - return(0); + return 0; } - if(a>=0) - next->addr=a; - if(v>=0) - next->val=v; - if(s>=0) - next->status=s; - if(c>=-1) - next->compare=c; - next->type=type; + if(a >= 0) + next->addr = a; + if(v >= 0) + next->val = v; + if(s >= 0) + next->status = s; + if(c >= -1) + next->compare = c; + next->type = type; - savecheats=1; + savecheats = 1; RebuildSubCheats(); - return(1); + return 1; } - next=next->next; + next = next->next; x++; } - return(0); + return 0; } /* Convenience function. */ @@ -793,130 +806,56 @@ void FCEUI_CheatSearchEnd(int type, uint8 v1, uint8 v2) } } - - if(!type) // Change to a specific value. + switch (type) { - for(x=0;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if(CheatComp[x]==v1 && CheatRPtrs[x>>10][x]==v2) - { - - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } + default: + case FCEU_SEARCH_SPECIFIC_CHANGE: // Change to a specific value + for (x = 0; x < 0x10000; ++x) + if (!(CheatComp[x] & CHEATC_NOSHOW) && (CheatComp[x] != v1 || CheatRPtrs[x >> 10][x] != v2)) + CheatComp[x] |= CHEATC_EXCLUDED; + break; + case FCEU_SEARCH_RELATIVE_CHANGE: // Search for relative change(between values). + for (x = 0; x < 0x10000; x++) + if (!(CheatComp[x] & CHEATC_NOSHOW) && (CheatComp[x] != v1 || CAbs(CheatComp[x] - CheatRPtrs[x >> 10][x]) != v2)) + CheatComp[x] |= CHEATC_EXCLUDED; + break; + case FCEU_SEARCH_PUERLY_RELATIVE_CHANGE: // Purely relative change. + for (x = 0x000; x<0x10000; x++) + if (!(CheatComp[x] & CHEATC_NOSHOW) && CAbs(CheatComp[x] - CheatRPtrs[x >> 10][x]) != v2) + CheatComp[x] |= CHEATC_EXCLUDED; + break; + case FCEU_SEARCH_ANY_CHANGE: // Any change. + for (x = 0x000; x < 0x10000; x++) + if (!(CheatComp[x] & CHEATC_NOSHOW) && CheatComp[x] == CheatRPtrs[x >> 10][x]) + CheatComp[x] |= CHEATC_EXCLUDED; + break; + case FCEU_SEARCH_NEWVAL_KNOWN: // new value = known + for (x = 0x000; x < 0x10000; x++) + if (!(CheatComp[x] & CHEATC_NOSHOW) && CheatRPtrs[x >> 10][x] != v1) + CheatComp[x] |= CHEATC_EXCLUDED; + break; + case FCEU_SEARCH_NEWVAL_GT: // new value greater than + for (x = 0x000; x < 0x10000; x++) + if (!(CheatComp[x] & CHEATC_NOSHOW) && CheatComp[x] >= CheatRPtrs[x >> 10][x]) + CheatComp[x] |= CHEATC_EXCLUDED; + break; + case FCEU_SEARCH_NEWVAL_LT: // new value less than + for (x = 0x000; x < 0x10000; x++) + if (!(CheatComp[x] & CHEATC_NOSHOW) && CheatComp[x] <= CheatRPtrs[x >> 10][x]) + CheatComp[x] |= CHEATC_EXCLUDED; + break; + case FCEU_SEARCH_NEWVAL_GT_KNOWN: // new value greater than by known value + for (x = 0x000; x < 0x10000; x++) + if (!(CheatComp[x] & CHEATC_NOSHOW) && CheatRPtrs[x >> 10][x] - CheatComp[x] != v2) + CheatComp[x] |= CHEATC_EXCLUDED; + break; + case FCEU_SEARCH_NEWVAL_LT_KNOWN: // new value less than by known value + for (x = 0x000; x < 0x10000; x++) + if (!(CheatComp[x] & CHEATC_NOSHOW) && (CheatComp[x] - CheatRPtrs[x >> 10][x]) != v2) + CheatComp[x] |= CHEATC_EXCLUDED; + break; } - else if(type==1) // Search for relative change(between values). - { - for(x=0;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if(CheatComp[x]==v1 && CAbs(CheatComp[x]-CheatRPtrs[x>>10][x])==v2) - { - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } - } - else if(type==2) // Purely relative change. - { - for(x=0x000;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if(CAbs(CheatComp[x]-CheatRPtrs[x>>10][x])==v2) - { - - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } - } - else if(type==3) // Any change. - { - for(x=0x000;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if(CheatComp[x]!=CheatRPtrs[x>>10][x]) - { - - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } - - } - else if(type==4) // new value = known - { - for(x=0x000;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if(CheatRPtrs[x>>10][x]==v1) - { - - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } - - } - else if(type==5) // new value greater than - { - for(x=0x000;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if(CheatComp[x]>10][x]) - { - - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } - - } - else if(type==6) // new value less than - { - for(x=0x000;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if(CheatComp[x]>CheatRPtrs[x>>10][x]) - { - - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } - - } - else if(type==7) // new value greater than by known value - { - for(x=0x000;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if((CheatRPtrs[x>>10][x]-CheatComp[x])==v2) - { - - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } - - } - else if(type==8) // new value less than by known value - { - for(x=0x000;x<0x10000;x++) - if(!(CheatComp[x]&CHEATC_NOSHOW)) - { - if((CheatComp[x]-CheatRPtrs[x>>10][x])==v2) - { - - } - else - CheatComp[x]|=CHEATC_EXCLUDED; - } - - } } int FCEU_CheatGetByte(uint32 A) @@ -958,7 +897,7 @@ void UpdateFrozenList(void) // disable all cheats int FCEU_DisableAllCheats(){ int count = 0; - struct CHEATF *next=cheats; + struct CHEATF *next = cheats; while(next) { if(next->status){ @@ -967,7 +906,7 @@ int FCEU_DisableAllCheats(){ next->status = 0; next = next->next; } - savecheats=1; + savecheats = 1; RebuildSubCheats(); return count; } diff --git a/src/cheat.h b/src/cheat.h index d7130a37..b828ccee 100644 --- a/src/cheat.h +++ b/src/cheat.h @@ -1,7 +1,7 @@ void FCEU_CheatResetRAM(void); void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p); -void FCEU_LoadGameCheats(FILE *override); +void FCEU_LoadGameCheats(FILE *override, int override_existing = 1); void FCEU_FlushGameCheats(FILE *override, int nosave); void FCEU_ApplyPeriodicCheats(void); void FCEU_PowerCheats(void); @@ -24,7 +24,7 @@ typedef struct { struct CHEATF { struct CHEATF *next; - char *name; + char *name = ""; uint16 addr; uint8 val; int compare; /* -1 for no compare. */ @@ -32,9 +32,19 @@ struct CHEATF { int status; }; +#define FCEU_SEARCH_SPECIFIC_CHANGE 0 +#define FCEU_SEARCH_RELATIVE_CHANGE 1 +#define FCEU_SEARCH_PUERLY_RELATIVE_CHANGE 2 +#define FCEU_SEARCH_ANY_CHANGE 3 +#define FCEU_SEARCH_NEWVAL_KNOWN 4 +#define FCEU_SEARCH_NEWVAL_GT 5 +#define FCEU_SEARCH_NEWVAL_LT 6 +#define FCEU_SEARCH_NEWVAL_GT_KNOWN 7 +#define FCEU_SEARCH_NEWVAL_LT_KNOWN 8 + #define CalcAddressRangeCheatCount(count, address, size) \ count = 0; \ for (int i = 0; i < numsubcheats && count < size; ++i) \ if (SubCheats[i].addr >= address && SubCheats[i].addr < address + size) \ - ++count; + ++count diff --git a/src/driver.h b/src/driver.h index f221b9bb..29411760 100644 --- a/src/driver.h +++ b/src/driver.h @@ -14,7 +14,9 @@ inline FILE *FCEUD_UTF8fopen(const std::string &n, const char *mode) { return FC EMUFILE_FILE* FCEUD_UTF8_fstream(const char *n, const char *m); inline EMUFILE_FILE* FCEUD_UTF8_fstream(const std::string &n, const char *m) { return FCEUD_UTF8_fstream(n.c_str(),m); } FCEUFILE* FCEUD_OpenArchiveIndex(ArchiveScanRecord& asr, std::string& fname, int innerIndex); +FCEUFILE* FCEUD_OpenArchiveIndex(ArchiveScanRecord& asr, std::string& fname, int innerIndex, bool* userCancel); FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename); +FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename, bool* userCancel); ArchiveScanRecord FCEUD_ScanArchive(std::string fname); //mbg 7/23/06 diff --git a/src/drivers/win/archive.cpp b/src/drivers/win/archive.cpp index 355378c9..0c9cea92 100644 --- a/src/drivers/win/archive.cpp +++ b/src/drivers/win/archive.cpp @@ -275,10 +275,6 @@ public: } }; -// indicator for the open in archive dialog that if the load was canceled by the user. -// TODO: Since I can't think of a better way to indicate it, hope someone could imporve it. -extern bool archiveManuallyCanceled; - static BOOL CALLBACK ArchiveFileSelectorCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) @@ -289,7 +285,7 @@ static BOOL CALLBACK ArchiveFileSelectorCallback(HWND hwndDlg, UINT uMsg, WPARAM for(uint32 i=0;isize();i++) { std::string& name = (*currFileSelectorContext)[i].name; - SendMessage(hwndListbox,LB_ADDSTRING,0,(LPARAM)name.c_str()); + SendMessage(hwndListbox, LB_ADDSTRING, 0, (LPARAM)name.c_str()); } } break; @@ -310,9 +306,6 @@ static BOOL CALLBACK ArchiveFileSelectorCallback(HWND hwndDlg, UINT uMsg, WPARAM case IDCANCEL: EndDialog(hwndDlg, LB_ERR); - // Tell the parent window that the operation was canceled rather than loading error - // TODO: find a better way to do this. - archiveManuallyCanceled = true; return TRUE; } break; @@ -493,7 +486,7 @@ extern HWND hAppWnd; //TODO - factor out the filesize and name extraction code from below (it is already done once above) -static FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename, int innerIndex) +static FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename, int innerIndex, bool* userCancel) { FCEUFILE* fp = 0; @@ -565,7 +558,11 @@ static FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, s delete ms; } - } //if returned a file from the fileselector + } + else { + if(userCancel) + *userCancel = true; + }//if returned a file from the fileselector } //if we opened the 7z correctly object->Release(); @@ -574,11 +571,26 @@ static FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, s return fp; } +static FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename, int innerIndex) +{ + return FCEUD_OpenArchive(asr, fname, innerFilename, innerIndex, NULL); +} + +FCEUFILE* FCEUD_OpenArchiveIndex(ArchiveScanRecord& asr, std::string& fname, int innerIndex, bool* userCancel) +{ + return FCEUD_OpenArchive(asr, fname, 0, innerIndex, userCancel); +} + FCEUFILE* FCEUD_OpenArchiveIndex(ArchiveScanRecord& asr, std::string& fname, int innerIndex) { return FCEUD_OpenArchive(asr, fname, 0, innerIndex); } +FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename, bool* userCancel) +{ + return FCEUD_OpenArchive(asr, fname, innerFilename, -1, userCancel); +} + FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename) { return FCEUD_OpenArchive(asr, fname, innerFilename, -1); diff --git a/src/drivers/win/archive.h b/src/drivers/win/archive.h index f4eb40ca..619f075d 100644 --- a/src/drivers/win/archive.h +++ b/src/drivers/win/archive.h @@ -11,8 +11,10 @@ void initArchiveSystem(); //if you want to autopilot this, pass in an innerfilename to try and automatically load FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename); +FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename, bool* userCancel); FCEUFILE* FCEUD_OpenArchiveIndex(ArchiveScanRecord& asr, std::string& fname, int innerIndex); +FCEUFILE* FCEUD_OpenArchiveIndex(ArchiveScanRecord& asr, std::string& fname, int innerIndex, bool* userCancel); //scans a file to see if it is an archive you can handle ArchiveScanRecord FCEUD_ScanArchive(std::string fname); diff --git a/src/drivers/win/cheat.cpp b/src/drivers/win/cheat.cpp index 1d58673a..ea538048 100644 --- a/src/drivers/win/cheat.cpp +++ b/src/drivers/win/cheat.cpp @@ -32,16 +32,28 @@ HWND hCheat = 0; //mbg merge 7/19/06 had to add static HMENU hCheatcontext; //Handle to context menu static HMENU hCheatcontextsub; //Handle to context sub menu -void InitializeCheatsAdded(HWND hwndDlg); - bool pauseWhileActive = false; //For checkbox "Pause while active" extern bool wasPausedByCheats; int CheatWindow; -int CheatStyle=1; +int CheatStyle = 1; #define GGLISTSIZE 128 //hopefully this is enough for all cases +// deselect the old one and select the new one +#define ListView_MoveSelectionMark(hwnd, prevIndex, newIndex) \ +LVITEM lvi; \ +SendMessage(hwnd, LVM_SETITEMSTATE, prevIndex, (LPARAM)&(lvi.mask = LVIF_STATE, lvi.stateMask = LVIS_SELECTED, lvi.state = 0, lvi)), \ +SendMessage(hwnd, LVM_SETITEMSTATE, newIndex, (LPARAM)&(lvi.state = LVIS_SELECTED, lvi)), \ +SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, newIndex) + +#define ClearCheatListText(hwnd) \ +(SetDlgItemText(hwnd, IDC_CHEAT_ADDR, (LPTSTR)"") & \ +SetDlgItemText(hwnd, IDC_CHEAT_VAL, (LPTSTR)"") & \ +SetDlgItemText(hwnd, IDC_CHEAT_COM, (LPTSTR)"") & \ +SetDlgItemText(hwnd, IDC_CHEAT_NAME, (LPTSTR)"")) + + int selcheat; int selcheatcount; int ChtPosX,ChtPosY; @@ -96,41 +108,54 @@ char *U8ToStr(uint8 a) return str; } -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 }; + char str[256] = { 0 }; - strcpy(str,(s?"* ":" ")); - if(name[0] == 0) { - if(a >= 0x8000) { - EncodeGG(str+2, a, v, c); - } else { - if(c == -1) sprintf(str+2,"%04X:%02X",(int)a,(int)v); - else sprintf(str+2,"%04X?%02X:%02X",(int)a,(int)c,(int)v); - } + if(a >= 0x8000) + EncodeGG(str, a, v, c); + else { + if(c == -1) + sprintf(str, "%04X:%02X", (int)a, (int)v); + else + sprintf(str, "%04X?%02X:%02X", (int)a, (int)c, (int)v); } - else strcat(str,name); - SendDlgItemMessage(hwndLB,IDC_LIST_CHEATS,LB_ADDSTRING,0,(LPARAM)(LPSTR)str); + LVITEM lvi = { 0 }; + lvi.mask = LVIF_TEXT; + lvi.iItem = data ? *((int*)data) : GGLISTSIZE; + lvi.pszText = str; + + if (data) + SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LVM_SETITEM, 0, (LPARAM)&lvi); + else + lvi.iItem = SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LVM_INSERTITEM, 0, (LPARAM)&lvi); + lvi.iSubItem = 1; + lvi.pszText = name; + SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LVM_SETITEM, 0, (LPARAM)&lvi); + + lvi.mask = LVIF_STATE; + lvi.stateMask = LVIS_STATEIMAGEMASK; + lvi.state = INDEXTOSTATEIMAGEMASK(s ? 2 : 1); + SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LVM_SETITEMSTATE, lvi.iItem, (LPARAM)&lvi); + return 1; } void RedoCheatsLB(HWND hwndDlg) { - SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LB_RESETCONTENT, 0, 0); - hwndLB = hwndDlg; + SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_DELETEALLITEMS, 0, 0); FCEUI_ListCheats(RedoCheatsCallB, 0); if (selcheat >= 0) { - EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_DEL), TRUE); - EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_UPD), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_CHEAT_DEL), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_CHEAT_UPD), TRUE); } else { - EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_DEL), FALSE); - EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_UPD), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_CHEAT_DEL), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_CHEAT_UPD), FALSE); } } @@ -139,7 +164,7 @@ int ShowResultsCallB(uint32 a, uint8 last, uint8 current) char temp[16]; sprintf(temp,"$%04X: %02X | %02X",(unsigned int)a,last,current); - SendDlgItemMessage(hwndLB,IDC_CHEAT_LIST_POSSIBILITIES,LB_ADDSTRING,0,(LPARAM)(LPSTR)temp); + SendDlgItemMessage(hCheat, IDC_CHEAT_LIST_POSSIBILITIES, LB_ADDSTRING, 0, (LPARAM)(LPSTR)temp); return 1; } @@ -152,7 +177,6 @@ void ShowResults(HWND hwndDlg) scrollnum=n; scrollindex=-32768; - hwndLB=hwndDlg; SendDlgItemMessage(hwndDlg,IDC_CHEAT_LIST_POSSIBILITIES,LB_RESETCONTENT,0,0); FCEUI_CheatSearchGetRange(0,16,ShowResultsCallB); @@ -176,75 +200,102 @@ void EnableCheatButtons(HWND hwndDlg, int enable) EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_LT),enable); } +HWND InitializeCheatList(HWND hwnd) +{ + HWND hwndChtList = GetDlgItem(hwnd, IDC_LIST_CHEATS); + + // prepare the columns + LVCOLUMN lv = { 0 }; + lv.mask = LVCF_TEXT | LVCF_WIDTH; + + lv.pszText = "Code"; + lv.cx = 100; + SendMessage(hwndChtList, LVM_INSERTCOLUMN, 0, (LPARAM)&lv); + + lv.pszText = "Name"; + lv.cx = 140; + SendMessage(hwndChtList, LVM_INSERTCOLUMN, 1, (LPARAM)&lv); + + // Add a checkbox to indicate if the cheat is activated + SendMessage(hwndChtList, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES); + + return hwndChtList; +} + BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { LOGFONT lf; RECT wrect; - char str[259] = { 0 },str2[259] = { 0 }; +// char str[256] = { 0 }, str2[256] = { 0 }; - char *name; - uint32 a; - uint8 v; - int c; - int s; +// char *name = ""; +// uint32 a; +// uint8 v; +// int c; +// int s; switch (uMsg) { case WM_INITDIALOG: - if (ChtPosX==-32000) ChtPosX=0; //Just in case - if (ChtPosY==-32000) ChtPosY=0; - SetWindowPos(hwndDlg,0,ChtPosX,ChtPosY,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOOWNERZORDER); - + { + if (ChtPosX == -32000) ChtPosX = 0; //Just in case + if (ChtPosY == -32000) ChtPosY = 0; + SetWindowPos(hwndDlg, 0, ChtPosX, ChtPosY, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER); + CheckDlgButton(hwndDlg, IDC_CHEAT_PAUSEWHENACTIVE, pauseWhileActive ? MF_CHECKED : MF_UNCHECKED); //setup font hFont = (HFONT)SendMessage(hwndDlg, WM_GETFONT, 0, 0); GetObject(hFont, sizeof(LOGFONT), &lf); - strcpy(lf.lfFaceName,"Courier New"); + strcpy(lf.lfFaceName, "Courier New"); hNewFont = CreateFontIndirect(&lf); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_ADDR,WM_SETFONT,(WPARAM)hNewFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL,WM_SETFONT,(WPARAM)hNewFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_COM,WM_SETFONT,(WPARAM)hNewFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL_KNOWN,WM_SETFONT,(WPARAM)hNewFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_LIST_POSSIBILITIES,WM_SETFONT,(WPARAM)hNewFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL_NE_BY,WM_SETFONT,(WPARAM)hNewFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL_GT_BY,WM_SETFONT,(WPARAM)hNewFont,FALSE); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL_LT_BY,WM_SETFONT,(WPARAM)hNewFont,FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_ADDR, WM_SETFONT, (WPARAM)hNewFont, FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL, WM_SETFONT, (WPARAM)hNewFont, FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_COM, WM_SETFONT, (WPARAM)hNewFont, FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL_KNOWN, WM_SETFONT, (WPARAM)hNewFont, FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_LIST_POSSIBILITIES, WM_SETFONT, (WPARAM)hNewFont, FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL_NE_BY, WM_SETFONT, (WPARAM)hNewFont, FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL_GT_BY, WM_SETFONT, (WPARAM)hNewFont, FALSE); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL_LT_BY, WM_SETFONT, (WPARAM)hNewFont, FALSE); //text limits - SendDlgItemMessage(hwndDlg,IDC_CHEAT_ADDR,EM_SETLIMITTEXT,4,0); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL,EM_SETLIMITTEXT,2,0); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_COM,EM_SETLIMITTEXT,2,0); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_NAME,EM_SETLIMITTEXT,256,0); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL_KNOWN,EM_SETLIMITTEXT,2,0); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL_NE_BY,EM_SETLIMITTEXT,2,0); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL_GT_BY,EM_SETLIMITTEXT,2,0); - SendDlgItemMessage(hwndDlg,IDC_CHEAT_VAL_LT_BY,EM_SETLIMITTEXT,2,0); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_ADDR, EM_SETLIMITTEXT, 4, 0); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL, EM_SETLIMITTEXT, 2, 0); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_COM, EM_SETLIMITTEXT, 2, 0); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_NAME, EM_SETLIMITTEXT, 256, 0); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL_KNOWN, EM_SETLIMITTEXT, 2, 0); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL_NE_BY, EM_SETLIMITTEXT, 2, 0); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL_GT_BY, EM_SETLIMITTEXT, 2, 0); + SendDlgItemMessage(hwndDlg, IDC_CHEAT_VAL_LT_BY, EM_SETLIMITTEXT, 2, 0); //disable or enable buttons - EnableWindow(GetDlgItem(hwndDlg,IDC_CHEAT_VAL_KNOWN),FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHEAT_VAL_KNOWN), FALSE); if (scrollnum) { - EnableCheatButtons(hwndDlg,TRUE); + char str[256] = { 0 }; + EnableCheatButtons(hwndDlg, TRUE); ShowResults(hwndDlg); - sprintf(str,"%d Possibilities",(int)FCEUI_CheatSearchGetCount()); - SetDlgItemText(hwndDlg,IDC_CHEAT_BOX_POSSIBILITIES,str); + sprintf(str, "%d Possibilities", (int)FCEUI_CheatSearchGetCount()); + SetDlgItemText(hwndDlg, IDC_CHEAT_BOX_POSSIBILITIES, str); } - else EnableCheatButtons(hwndDlg,FALSE); + else EnableCheatButtons(hwndDlg, FALSE); + + //add header for cheat list + InitializeCheatList(hwndDlg); //misc setup - searchdone=0; - SetDlgItemText(hwndDlg,IDC_CHEAT_VAL_KNOWN,(LPTSTR)U8ToStr(knownvalue)); + searchdone = 0; + SetDlgItemText(hwndDlg, IDC_CHEAT_VAL_KNOWN, (LPTSTR)U8ToStr(knownvalue)); + // Enable Context Sub-Menus - hCheatcontext = LoadMenu(fceu_hInstance,"CHEATCONTEXTMENUS"); + hCheatcontext = LoadMenu(fceu_hInstance, "CHEATCONTEXTMENUS"); break; - + } case WM_KILLFOCUS: break; - case WM_NCACTIVATE: if (pauseWhileActive) { @@ -264,27 +315,29 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l ShowResults(hwndDlg); } break; - case WM_CLOSE: - case WM_QUIT: - CheatWindow=0; - hCheat = 0; - if (CheatStyle) DestroyWindow(hwndDlg); - else EndDialog(hwndDlg,0); + if (CheatStyle) + DestroyWindow(hwndDlg); + else + EndDialog(hwndDlg, 0); + break; + case WM_DESTROY: + CheatWindow = 0; + hCheat = NULL; DeleteObject(hFont); DeleteObject(hNewFont); - if (searchdone) FCEUI_CheatSearchSetCurrentAsOriginal(); + if (searchdone) + FCEUI_CheatSearchSetCurrentAsOriginal(); break; - case WM_MOVE: if (!IsIconic(hwndDlg)) { - GetWindowRect(hwndDlg,&wrect); - ChtPosX = wrect.left; - ChtPosY = wrect.top; + GetWindowRect(hwndDlg,&wrect); + ChtPosX = wrect.left; + ChtPosY = wrect.top; - #ifdef WIN32 - WindowBoundsCheckNoResize(ChtPosX,ChtPosY,wrect.right); - #endif + #ifdef WIN32 + WindowBoundsCheckNoResize(ChtPosX,ChtPosY,wrect.right); + #endif } break; @@ -384,18 +437,17 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l case WM_CONTEXTMENU: { // Handle certain subborn context menus for nearly incapable controls. - - if (wParam == (uint32)GetDlgItem(hwndDlg,IDC_LIST_CHEATS)) { + if (GetDlgCtrlID((HWND)wParam) == IDC_LIST_CHEATS) { // Only open the menu if a cheat is selected if (selcheat >= 0) { // Open IDC_LIST_CHEATS Context Menu - hCheatcontextsub = GetSubMenu(hCheatcontext,0); - SetMenuDefaultItem(hCheatcontextsub, CHEAT_CONTEXT_TOGGLECHEAT, false); + hCheatcontextsub = GetSubMenu(hCheatcontext, 0); + // SetMenuDefaultItem(hCheatcontextsub, CHEAT_CONTEXT_TOGGLECHEAT, false); if (lParam != -1) - TrackPopupMenu(hCheatcontextsub,TPM_RIGHTBUTTON,LOWORD(lParam),HIWORD(lParam),0,hwndDlg,0); //Create menu + TrackPopupMenu(hCheatcontextsub, TPM_RIGHTBUTTON, LOWORD(lParam), HIWORD(lParam), 0, hwndDlg, 0); //Create menu else { // Handle the context menu keyboard key - GetWindowRect(GetDlgItem(hwndDlg,IDC_LIST_CHEATS), &wrect); - TrackPopupMenu(hCheatcontextsub,TPM_RIGHTBUTTON,wrect.left + int((wrect.right - wrect.left) / 3),wrect.top + int((wrect.bottom - wrect.top) / 3),0,hwndDlg,0); //Create menu + GetWindowRect(GetDlgItem(hwndDlg, IDC_LIST_CHEATS), &wrect); + TrackPopupMenu(hCheatcontextsub, TPM_RIGHTBUTTON, wrect.left + int((wrect.right - wrect.left) / 3), wrect.top + int((wrect.bottom - wrect.top) / 3), 0, hwndDlg, 0); //Create menu } } @@ -409,16 +461,41 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l case BN_CLICKED: switch (LOWORD(wParam)) { case CHEAT_CONTEXT_TOGGLECHEAT: - CheatConsoleCallB(hwndDlg, WM_COMMAND, (LBN_DBLCLK * 0x10000) | (IDC_LIST_CHEATS), lParam); + { + LVITEM lvi; + lvi.mask = LVIF_STATE; + lvi.stateMask = LVIS_STATEIMAGEMASK; + int tmpsel = SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LVM_GETNEXTITEM, -1, LVNI_ALL | LVNI_SELECTED); + while (tmpsel != -1) + { + char* name = ""; uint32 a = 0; uint8 v = 0; int s = 0; int c = 0; + FCEUI_GetCheat(tmpsel, &name, &a, &v, &c, &s, NULL); + FCEUI_SetCheat(tmpsel, name, -1, -1, -2, s ^= 1, 1); + + lvi.iItem = tmpsel; + lvi.state = INDEXTOSTATEIMAGEMASK(s ? 2 : 1); + SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LVM_SETITEMSTATE, tmpsel, (LPARAM)&lvi); + + tmpsel = SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_GETNEXTITEM, tmpsel, LVNI_ALL | LVNI_SELECTED); + } + UpdateCheatWindowRelatedWindow(); + UpdateCheatListGroupBoxUI(); + } break; case CHEAT_CONTEXT_POKECHEATVALUE: - FCEUI_GetCheat(selcheat,&name,&a,&v,NULL,&s,NULL); - BWrite[a](a,v); + { + char* name = ""; uint32 a; uint8 v; int s; + FCEUI_GetCheat(selcheat, &name, &a, &v, NULL, &s, NULL); + BWrite[a](a, v); + } break; case CHEAT_CONTEXT_GOTOINHEXEDITOR: + { DoMemView(); - FCEUI_GetCheat(selcheat,&name,&a,&v,NULL,&s,NULL); + char* name = ""; uint32 a; uint8 v; int s; + FCEUI_GetCheat(selcheat, &name, &a, &v, NULL, &s, NULL); SetHexEditorAddress(a); + } break; case IDC_CHEAT_PAUSEWHENACTIVE: pauseWhileActive ^= 1; @@ -431,128 +508,126 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l } break; case IDC_BTN_CHEAT_ADD: + { + char str[256] = { 0 }; + uint32 a = 0; + uint8 v = 0; + int c = 0; dodecode = true; - - GetDlgItemText(hwndDlg,IDC_CHEAT_ADDR,str,5); - if(str[0] != 0) dodecode = false; - a=StrToU16(str); - GetDlgItemText(hwndDlg,IDC_CHEAT_VAL,str,3); - if(str[0] != 0) dodecode = false; - v=StrToU8(str); - GetDlgItemText(hwndDlg,IDC_CHEAT_COM,str,3); - if(str[0] != 0) dodecode = false; - c=(str[0] == 0)?-1:StrToU8(str); - GetDlgItemText(hwndDlg,IDC_CHEAT_NAME,str,256); - if(dodecode && (strlen(str) == 6 || strlen(str) == 8)) { + + GetDlgItemText(hwndDlg, IDC_CHEAT_ADDR, str, 5); + if(str[0] != 0) + dodecode = false; + a = StrToU16(str); + GetDlgItemText(hwndDlg, IDC_CHEAT_VAL, str, 3); + if(str[0] != 0) + dodecode = false; + v = StrToU8(str); + GetDlgItemText(hwndDlg,IDC_CHEAT_COM, str, 3); + if(str[0] != 0) + dodecode = false; + c = (str[0] == 0) ? -1 : StrToU8(str); + GetDlgItemText(hwndDlg, IDC_CHEAT_NAME, str, 256); + if(dodecode && (strlen(str) == 6 || strlen(str) == 8)) if(FCEUI_DecodeGG(str, &GGaddr, &GGval, &GGcomp)) { a = GGaddr; v = GGval; c = GGcomp; } - } -// if (FCEUI_AddCheat(str,a,v)) { //bbit edited: replaced this with the line below - if (FCEUI_AddCheat(str,a,v,c,1)) { - if(str[0] == 0) { - if(a >= 0x8000) EncodeGG(str, a, v, c); - else { - if(c == -1) sprintf(str,"%04X:%02X",(int)a,(int)v); //bbit edited: added this line to give your cheat a name if you didn't supply one - else sprintf(str,"%04X?%02X:%02X",(int)a,(int)c,(int)v); - } - } - strcpy(str2,"* "); - strcat(str2,str); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_ADDSTRING,0,(LPARAM)(LPSTR)str2); - selcheat = (SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_GETCOUNT,0,0) - 1); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_SETCURSEL,selcheat,0); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_SETSEL,(WPARAM)1,selcheat); + if (FCEUI_AddCheat(str, a, v, c, 1)) { + RedoCheatsCallB(str, a, v, c, 1, 1, NULL); - SetDlgItemText(hwndDlg,IDC_CHEAT_ADDR,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_VAL,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_NAME,(LPTSTR)""); + int newselcheat = SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_GETITEMCOUNT, 0, 0) - 1; + ListView_MoveSelectionMark(GetDlgItem(hwndDlg, IDC_LIST_CHEATS), selcheat, newselcheat); + selcheat = newselcheat; + + ClearCheatListText(hwndDlg); } UpdateCheatWindowRelatedWindow(); - UpdateCheatsAdded(); + UpdateCheatListGroupBoxUI(); break; + } case ID_CHEATLISTPOPUP_DELETESELECTEDCHEATS: case IDC_BTN_CHEAT_DEL: 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--) { - if (SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_GETSEL,selcheattemp,0)) { - FCEUI_DelCheat(selcheattemp); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_DELETESTRING,selcheattemp,0); - } + selcheat = -1; + + int selcheattemp = SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_GETNEXTITEM, -1, LVNI_ALL | LVNI_SELECTED); + LVITEM lvi; + lvi.mask = LVIF_STATE; + lvi.stateMask = LVIS_SELECTED; + lvi.state = 0; + while (selcheattemp != -1) + { + FCEUI_DelCheat(selcheattemp); + SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_DELETEITEM, selcheattemp, 0); + selcheattemp = SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_GETNEXTITEM, -1, LVNI_ALL | LVNI_SELECTED); } - SetDlgItemText(hwndDlg,IDC_CHEAT_ADDR,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_VAL,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_NAME,(LPTSTR)""); + + ClearCheatListText(hwndDlg); + UpdateCheatWindowRelatedWindow(); - UpdateCheatsAdded(); + UpdateCheatListGroupBoxUI(); } } else { if (selcheat >= 0) { FCEUI_DelCheat(selcheat); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_DELETESTRING,selcheat,0); - selcheat=-1; - SetDlgItemText(hwndDlg,IDC_CHEAT_ADDR,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_VAL,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)""); - SetDlgItemText(hwndDlg,IDC_CHEAT_NAME,(LPTSTR)""); + SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_DELETEITEM, selcheat, 0); + selcheat = -1; + ClearCheatListText(hwndDlg); } UpdateCheatWindowRelatedWindow(); - UpdateCheatsAdded(); + UpdateCheatListGroupBoxUI(); } break; case IDC_BTN_CHEAT_UPD: - dodecode = true; + { + selcheat = SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_GETSELECTIONMARK, 0, 0); - if (selcheat < 0) break; - GetDlgItemText(hwndDlg,IDC_CHEAT_ADDR,str,5); - if(str[0] != 0) dodecode = false; - a=StrToU16(str); - GetDlgItemText(hwndDlg,IDC_CHEAT_VAL,str,3); - if(str[0] != 0) dodecode = false; - v=StrToU8(str); - GetDlgItemText(hwndDlg,IDC_CHEAT_COM,str,3); - if(str[0] != 0) dodecode = false; - c=(str[0] == 0)?-1:StrToU8(str); - GetDlgItemText(hwndDlg,IDC_CHEAT_NAME,str,256); - if(dodecode && (strlen(str) == 6 || strlen(str) == 8)) { - if(FCEUI_DecodeGG(str, &GGaddr, &GGval, &GGcomp)) { + dodecode = true; + char str[256] = { 0 }; + char* name = ""; uint32 a; uint8 v; int s; int c; + + if (selcheat < 0) + break; + GetDlgItemText(hwndDlg, IDC_CHEAT_ADDR, str, 5); + if (str[0] != 0) + dodecode = false; + a = StrToU16(str); + GetDlgItemText(hwndDlg, IDC_CHEAT_VAL, str, 3); + if (str[0] != 0) + dodecode = false; + v = StrToU8(str); + GetDlgItemText(hwndDlg, IDC_CHEAT_COM, str, 3); + if (str[0] != 0) + dodecode = false; + c = (str[0] == 0) ? -1 : StrToU8(str); + GetDlgItemText(hwndDlg, IDC_CHEAT_NAME, str, 256); + if (dodecode && (strlen(str) == 6 || strlen(str) == 8)) { + if (FCEUI_DecodeGG(str, &GGaddr, &GGval, &GGcomp)) { a = GGaddr; v = GGval; c = GGcomp; } } -// FCEUI_SetCheat(selcheat,str,a,v,-1); //bbit edited: replaced this with the line below - FCEUI_SetCheat(selcheat,str,a,v,c,-1,1); -// FCEUI_GetCheat(selcheat,&name,&a,&v,&s); //bbit edited: replaced this with the line below - FCEUI_GetCheat(selcheat,&name,&a,&v,&c,&s,NULL); - strcpy(str2,(s?"* ":" ")); - if(str[0] == 0) { - if(a >= 0x8000) EncodeGG(str, a, v, c); - else { - if(c == -1) sprintf(str,"%04X:%02X",(int)a,(int)v); //bbit edited: added this line to give your cheat a name if you didn't supply one - else sprintf(str,"%04X?%02X:%02X",(int)a,(int)c,(int)v); - } - } - strcat(str2,str); + FCEUI_SetCheat(selcheat, str, a, v, c, -1, 1); + FCEUI_GetCheat(selcheat, &name, &a, &v, &c, &s, NULL); + RedoCheatsCallB(name, a, v, c, s, 1, &selcheat); + SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_SETSELECTIONMARK, 0, selcheat); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_DELETESTRING,selcheat,0); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_INSERTSTRING,selcheat,(LPARAM)(LPSTR)str2); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_SETCURSEL,selcheat,0); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_SETSEL,(WPARAM)1,selcheat); - - 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)); + 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)); UpdateCheatWindowRelatedWindow(); + UpdateCheatListGroupBoxUI(); + // UpdateCheatAdded(); break; + } case IDC_BTN_CHEAT_ADDFROMFILE: { OPENFILENAME ofn; @@ -576,7 +651,7 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l FILE* file = FCEUD_UTF8fopen(nameo, "rb"); if (file) { - FCEU_LoadGameCheats(file); + FCEU_LoadGameCheats(file, 0); UpdateCheatWindowRelatedWindow(); UpdateCheatsAdded(); savecheats = 1; @@ -590,44 +665,56 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l EnableCheatButtons(hwndDlg,TRUE); break; case IDC_BTN_CHEAT_KNOWN: - searchdone=1; - GetDlgItemText(hwndDlg,IDC_CHEAT_VAL_KNOWN,str,3); - knownvalue=StrToU8(str); - FCEUI_CheatSearchEnd(4,knownvalue,0); + { + char str[256] = { 0 }; + searchdone = 1; + GetDlgItemText(hwndDlg, IDC_CHEAT_VAL_KNOWN, str, 3); + knownvalue = StrToU8(str); + FCEUI_CheatSearchEnd(FCEU_SEARCH_NEWVAL_KNOWN, knownvalue, 0); ShowResults(hwndDlg); break; + } case IDC_BTN_CHEAT_EQ: - searchdone=1; - FCEUI_CheatSearchEnd(2,0,0); + searchdone = 1; + FCEUI_CheatSearchEnd(FCEU_SEARCH_PUERLY_RELATIVE_CHANGE,0,0); ShowResults(hwndDlg); break; case IDC_BTN_CHEAT_NE: - searchdone=1; - if (IsDlgButtonChecked(hwndDlg,IDC_CHEAT_CHECK_NE_BY) == BST_CHECKED) { - GetDlgItemText(hwndDlg,IDC_CHEAT_VAL_NE_BY,str,3); - FCEUI_CheatSearchEnd(2,0,StrToU8(str)); + { + char str[256] = { 0 }; + searchdone = 1; + if (IsDlgButtonChecked(hwndDlg, IDC_CHEAT_CHECK_NE_BY) == BST_CHECKED) { + GetDlgItemText(hwndDlg, IDC_CHEAT_VAL_NE_BY, str, 3); + FCEUI_CheatSearchEnd(FCEU_SEARCH_PUERLY_RELATIVE_CHANGE, 0, StrToU8(str)); } - else FCEUI_CheatSearchEnd(3,0,0); + else FCEUI_CheatSearchEnd(FCEU_SEARCH_ANY_CHANGE, 0, 0); ShowResults(hwndDlg); break; + } case IDC_BTN_CHEAT_GT: - searchdone=1; - if (IsDlgButtonChecked(hwndDlg,IDC_CHEAT_CHECK_GT_BY) == BST_CHECKED) { - GetDlgItemText(hwndDlg,IDC_CHEAT_VAL_GT_BY,str,3); - FCEUI_CheatSearchEnd(7,0,StrToU8(str)); + { + char str[256] = { 0 }; + searchdone = 1; + if (IsDlgButtonChecked(hwndDlg, IDC_CHEAT_CHECK_GT_BY) == BST_CHECKED) { + GetDlgItemText(hwndDlg, IDC_CHEAT_VAL_GT_BY, str, 3); + FCEUI_CheatSearchEnd(FCEU_SEARCH_NEWVAL_GT_KNOWN, 0, StrToU8(str)); } - else FCEUI_CheatSearchEnd(5,0,0); + else FCEUI_CheatSearchEnd(FCEU_SEARCH_NEWVAL_GT, 0, 0); ShowResults(hwndDlg); break; + } case IDC_BTN_CHEAT_LT: - searchdone=1; - if (IsDlgButtonChecked(hwndDlg,IDC_CHEAT_CHECK_LT_BY) == BST_CHECKED) { - GetDlgItemText(hwndDlg,IDC_CHEAT_VAL_LT_BY,str,3); - FCEUI_CheatSearchEnd(8,0,StrToU8(str)); + { + char str[256] = { 0 }; + searchdone = 1; + if (IsDlgButtonChecked(hwndDlg, IDC_CHEAT_CHECK_LT_BY) == BST_CHECKED) { + GetDlgItemText(hwndDlg, IDC_CHEAT_VAL_LT_BY, str, 3); + FCEUI_CheatSearchEnd(FCEU_SEARCH_NEWVAL_LT_KNOWN, 0, StrToU8(str)); } - else FCEUI_CheatSearchEnd(6,0,0); + else FCEUI_CheatSearchEnd(FCEU_SEARCH_NEWVAL_LT, 0, 0); ShowResults(hwndDlg); break; + } } break; case LBN_DBLCLK: @@ -635,90 +722,38 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l case IDC_CHEAT_LIST_POSSIBILITIES: if (EmulationPaused == 1) //We only want to send info to memwatch if paused { //otherwise we will be sending info while it is updating causing unpredictable behavior - lbfocus=1; - SendDlgItemMessage(hwndDlg, - IDC_CHEAT_LIST_POSSIBILITIES, - LB_GETTEXT, - SendDlgItemMessage(hwndDlg, - IDC_CHEAT_LIST_POSSIBILITIES, - LB_GETCURSEL,0,0), - (LPARAM)(LPCTSTR)str); - strcpy(str2,str+1); + lbfocus = 1; + char str[256] = { 0 }, str2[256] = { 0 }; + SendDlgItemMessage(hwndDlg, IDC_CHEAT_LIST_POSSIBILITIES, LB_GETTEXT, + SendDlgItemMessage(hwndDlg, IDC_CHEAT_LIST_POSSIBILITIES, LB_GETCURSEL, 0, 0), (LPARAM)(LPCTSTR)str); + strcpy(str2, str+1); str2[4] = 0; AddMemWatch(str2); } break; - case IDC_LIST_CHEATS: - //SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_GETSEL,(WPARAM)x,(LPARAM)0); - for (int selcheattemp=SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_GETCOUNT,0,0)-1;selcheattemp>=0;selcheattemp--) { - if (SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_GETSEL,selcheattemp,0)) { -// FCEUI_GetCheat(selcheattemp,&name,&a,&v,&s); //bbit edited: replaced this with the line below - FCEUI_GetCheat(selcheattemp,&name,&a,&v,&c,&s,NULL); -// FCEUI_SetCheat(selcheattemp,0,-1,-1,s^=1);//bbit edited: replaced this with the line below - FCEUI_SetCheat(selcheattemp,0,-1,-1,-2,s^=1,1); - strcpy(str,(s?"* ":" ")); - if(name[0] == 0) { - if(a >= 0x8000) EncodeGG(str+2, a, v, c); - else { - if(c == -1) sprintf(str+2,"%04X:%02X",(int)a,(int)v); //bbit edited: added this line to give your cheat a name if you didn't supply one - else sprintf(str+2,"%04X?%02X:%02X",(int)a,(int)c,(int)v); - } - } - else strcat(str,name); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_DELETESTRING,selcheattemp,0); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_INSERTSTRING,selcheattemp,(LPARAM)(LPSTR)str); - } - } - UpdateCheatsAdded(); - UpdateCheatWindowRelatedWindow(); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_SETCURSEL,selcheat,0); - SendDlgItemMessage(hwndDlg,IDC_LIST_CHEATS,LB_SETSEL,(WPARAM)1,selcheat); - break; } break; 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); - 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)); - - EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_DEL),TRUE); - EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_UPD),TRUE); - break; case IDC_CHEAT_LIST_POSSIBILITIES: - lbfocus=1; - SendDlgItemMessage(hwndDlg, - IDC_CHEAT_LIST_POSSIBILITIES, - LB_GETTEXT, - SendDlgItemMessage(hwndDlg, - IDC_CHEAT_LIST_POSSIBILITIES, - LB_GETCURSEL,0,0), - (LPARAM)(LPCTSTR)str); - strcpy(str2,str+1); + { + char str[256] = { 0 }, str2[256] = { 0 }; + lbfocus = 1; + SendDlgItemMessage(hwndDlg, IDC_CHEAT_LIST_POSSIBILITIES, LB_GETTEXT, + SendDlgItemMessage(hwndDlg, IDC_CHEAT_LIST_POSSIBILITIES, LB_GETCURSEL, 0, 0), + (LPARAM)(LPCTSTR)str); + strcpy(str2, str + 1); str2[4] = 0; - SetDlgItemText(hwndDlg,IDC_CHEAT_ADDR,(LPTSTR)str2); - strcpy(str2,str+13); - SetDlgItemText(hwndDlg,IDC_CHEAT_VAL,(LPTSTR)str2); - SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)""); + SetDlgItemText(hwndDlg, IDC_CHEAT_ADDR, (LPTSTR)str2); + strcpy(str2, str + 13); + SetDlgItemText(hwndDlg, IDC_CHEAT_VAL, (LPTSTR)str2); + SetDlgItemText(hwndDlg, IDC_CHEAT_COM, (LPTSTR)""); break; + } } break; case LBN_SELCANCEL: switch(LOWORD(wParam)) { - case IDC_LIST_CHEATS: - EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_DEL),FALSE); - EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_CHEAT_UPD),FALSE); - break; case IDC_CHEAT_LIST_POSSIBILITIES: lbfocus=0; break; @@ -727,6 +762,77 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l } break; + case WM_NOTIFY: + { + switch (wParam) + { + case IDC_LIST_CHEATS: + { + NMHDR* lP = (NMHDR*)lParam; + switch (lP->code) { + case LVN_ITEMCHANGED: + { + NMLISTVIEW* pNMListView = (NMLISTVIEW*)lP; + +// selcheat = pNMListView->iItem; + selcheatcount = SendDlgItemMessage(hwndDlg, IDC_LIST_CHEATS, LVM_GETSELECTEDCOUNT, 0, 0); + if (pNMListView->uNewState & LVIS_FOCUSED || + !(pNMListView->uOldState & LVIS_SELECTED) && pNMListView->uNewState & LVIS_SELECTED) + { + selcheat = pNMListView->iItem; + if (selcheat >= 0) + { + char* name = ""; uint32 a; uint8 v; int s; int c; + 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)); + SetDlgItemText(hwndDlg, IDC_CHEAT_COM, (LPTSTR)(c == -1 ? "" : U8ToStr(c))); + } + + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_CHEAT_DEL), selcheatcount > 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_CHEAT_UPD), selcheatcount > 0); + } + + if (pNMListView->uChanged & LVIF_STATE) + // uncheck -> check + if (pNMListView->uOldState & INDEXTOSTATEIMAGEMASK(1) && + pNMListView->uNewState & INDEXTOSTATEIMAGEMASK(2)) + { + int tmpsel = pNMListView->iItem; + char* name = ""; uint32 a; uint8 v; int s; int c; + FCEUI_GetCheat(tmpsel, &name, &a, &v, &c, &s, NULL); + if (!s) + { + FCEUI_SetCheat(tmpsel, name, -1, -1, -2, s ^= 1, 1); + + UpdateCheatWindowRelatedWindow(); + UpdateCheatListGroupBoxUI(); + } + } + // check -> uncheck + else if (pNMListView->uOldState & INDEXTOSTATEIMAGEMASK(2) && + pNMListView->uNewState & INDEXTOSTATEIMAGEMASK(1)) + { + int tmpsel = pNMListView->iItem; + char* name = ""; uint32 a; uint8 v; int s; int c; + FCEUI_GetCheat(tmpsel, &name, &a, &v, &c, &s, NULL); + if (s) + { + FCEUI_SetCheat(tmpsel, name, -1, -1, -2, s ^= 1, 1); + + UpdateCheatWindowRelatedWindow(); + UpdateCheatListGroupBoxUI(); + } + } + + break; + } + } + } + break; + } + } } return 0; } @@ -746,12 +852,12 @@ void ConfigCheats(HWND hParent) if (!CheatWindow) { - selcheat=-1; - CheatWindow=1; + selcheat = -1; + CheatWindow = 1; if (CheatStyle) - pwindow = hCheat = CreateDialog(fceu_hInstance, "CHEATCONSOLE", NULL, CheatConsoleCallB); + pwindow = hCheat = CreateDialog(fceu_hInstance, "CHEATCONSOLE", hParent, CheatConsoleCallB); else - DialogBox(fceu_hInstance,"CHEATCONSOLE",hParent,CheatConsoleCallB); + DialogBox(fceu_hInstance, "CHEATCONSOLE", hParent, CheatConsoleCallB); UpdateCheatsAdded(); } else { @@ -768,30 +874,36 @@ void UpdateCheatList() ShowResults(pwindow); } -//Used by cheats and external dialogs such as hex editor to update items in the cheat search dialog -void UpdateCheatsAdded() +void UpdateCheatListGroupBoxUI() { char temp[64]; if (FrozenAddressCount < 256) { - sprintf(temp,"Active Cheats %d", FrozenAddressCount); + 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) + } + else if (FrozenAddressCount == 256) { - sprintf(temp,"Active Cheats %d (Max Limit)", FrozenAddressCount); + 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); + 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); + SetDlgItemText(hCheat, IDC_GROUPBOX_CHEATLIST, temp); +} + +//Used by cheats and external dialogs such as hex editor to update items in the cheat search dialog +void UpdateCheatsAdded() +{ RedoCheatsLB(hCheat); + UpdateCheatListGroupBoxUI(); } BOOL CALLBACK GGConvCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -887,20 +999,21 @@ BOOL CALLBACK GGConvCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) if(GGaddr < 0x8000)GGaddr += 0x8000; - if (FCEUI_AddCheat(GGcode,GGaddr,GGval,GGcomp,1) && (hCheat != 0)) { - strcpy(str,"* "); - strcat(str,GGcode); - SendDlgItemMessage(hCheat,IDC_LIST_CHEATS,LB_ADDSTRING,0,(LPARAM)(LPSTR)str); - selcheat = (SendDlgItemMessage(hCheat,IDC_LIST_CHEATS,LB_GETCOUNT,0,0) - 1); - SendDlgItemMessage(hCheat,IDC_LIST_CHEATS,LB_SETCURSEL,selcheat,0); + if (FCEUI_AddCheat(GGcode, GGaddr, GGval, GGcomp, 1) && hCheat) { + RedoCheatsCallB(GGcode, GGaddr, GGval, GGcomp, 1, 1, NULL); + int newselcheat = SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LVM_GETITEMCOUNT, 0, 0) - 1; + ListView_MoveSelectionMark(GetDlgItem(hCheat, IDC_LIST_CHEATS), selcheat, newselcheat); + selcheat = newselcheat; - SetDlgItemText(hCheat,IDC_CHEAT_ADDR,(LPTSTR)U16ToStr(GGaddr)); - SetDlgItemText(hCheat,IDC_CHEAT_VAL,(LPTSTR)U8ToStr(GGval)); - if(GGcomp == -1) SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)""); - else SetDlgItemText(hwndDlg,IDC_CHEAT_COM,(LPTSTR)U8ToStr(GGcomp)); + SetDlgItemText(hCheat, IDC_CHEAT_ADDR, (LPTSTR)U16ToStr(GGaddr)); + SetDlgItemText(hCheat, IDC_CHEAT_VAL, (LPTSTR)U8ToStr(GGval)); + if(GGcomp == -1) + SetDlgItemText(hwndDlg, IDC_CHEAT_COM, (LPTSTR)""); + else + SetDlgItemText(hwndDlg, IDC_CHEAT_COM, (LPTSTR)U8ToStr(GGcomp)); - EnableWindow(GetDlgItem(hCheat,IDC_BTN_CHEAT_DEL),TRUE); - EnableWindow(GetDlgItem(hCheat,IDC_BTN_CHEAT_UPD),TRUE); + EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_DEL), TRUE); + EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_UPD), TRUE); UpdateCheatsAdded(); } } @@ -1032,22 +1145,13 @@ CPoint test = point; void DisableAllCheats() { if(FCEU_DisableAllCheats() && hCheat){ - LRESULT sel; char str[259]; - for (int tempSelCheat = SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LB_GETCOUNT, 0, 0) - 1; tempSelCheat >= 0; --tempSelCheat) - { - SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LB_GETTEXT, tempSelCheat, (LPARAM)(LPCTSTR)str); - if (str[0] == '*') - { - str[0] = ' '; - sel = SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LB_GETSEL, tempSelCheat, 0); - SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LB_DELETESTRING, tempSelCheat, 0); - SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LB_INSERTSTRING, tempSelCheat, (LPARAM)(LPSTR)str); - if (sel) - SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LB_SETSEL, 1, tempSelCheat); - } - } - sprintf(str, "Active Cheats %d", 0); - SetDlgItemText(hCheat, 201, str); + LVITEM lvi; + lvi.mask = LVIF_STATE; + lvi.stateMask = LVIS_STATEIMAGEMASK; + lvi.state = INDEXTOSTATEIMAGEMASK(1); + for (int current = SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LB_GETCOUNT, 0, 0) - 1; current >= 0; --current) + SendDlgItemMessage(hCheat, IDC_LIST_CHEATS, LVM_GETITEMSTATE, current, (LPARAM)&lvi); + UpdateCheatListGroupBoxUI(); } } diff --git a/src/drivers/win/cheat.h b/src/drivers/win/cheat.h index bd8a9f26..ee12b804 100644 --- a/src/drivers/win/cheat.h +++ b/src/drivers/win/cheat.h @@ -3,12 +3,14 @@ extern int CheatWindow,CheatStyle; //bbit edited: this line added extern HWND hCheat; +HWND InitializeCheatList(HWND hwndDlg); void RedoCheatsLB(HWND hwndDlg); void ConfigCheats(HWND hParent); void DoGGConv(); void SetGGConvFocus(int address,int compare); void UpdateCheatList(); +void UpdateCheatListGroupBoxUI(); void UpdateCheatsAdded(); extern unsigned int FrozenAddressCount; diff --git a/src/drivers/win/mapinput.cpp b/src/drivers/win/mapinput.cpp index cdd5d964..f769d9b9 100644 --- a/src/drivers/win/mapinput.cpp +++ b/src/drivers/win/mapinput.cpp @@ -23,7 +23,7 @@ else if (filter > EMUCMDTYPE_MISC && filter < EMUCMDTYPE_MAX || filter == EMUCMD else \ lpListView->iSubItem = mapInputSortCol; \ if (SendMessage(hwndListView, LVM_SORTITEMS, (WPARAM)lpListView, (LPARAM)MapInputItemSortFunc)) \ - UpdateSortColumnIcon(hwndListView, mapInputSortCol, mapInputSortAsc); + UpdateSortColumnIcon(hwndListView, mapInputSortCol, mapInputSortAsc) void KeyboardUpdateState(void); //mbg merge 7/17/06 yech had to add this @@ -768,9 +768,10 @@ BOOL CALLBACK MapInputDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM break; case WM_CLOSE: + EndDialog(hwndDlg, 0); + break; case WM_DESTROY: case WM_QUIT: - EndDialog(hwndDlg, 0); break; case WM_NOTIFY: diff --git a/src/drivers/win/ram_search.cpp b/src/drivers/win/ram_search.cpp index 7127e4aa..256c8158 100644 --- a/src/drivers/win/ram_search.cpp +++ b/src/drivers/win/ram_search.cpp @@ -1078,9 +1078,6 @@ void signal_new_frame () -bool RamSearchClosed = false; -bool RamWatchClosed = false; - void ResetResults() { reset_address_info(); @@ -1093,40 +1090,27 @@ void CloseRamWindows() //Close the Ram Search & Watch windows when rom closes ResetWatches(); ResetResults(); if (RamSearchHWnd) - { SendMessage(RamSearchHWnd,WM_CLOSE,NULL,NULL); - RamSearchClosed = true; - } if (RamWatchHWnd) - { SendMessage(RamWatchHWnd,WM_CLOSE,NULL,NULL); - RamWatchClosed = true; - } } void ReopenRamWindows() //Reopen them when a new Rom is loaded { HWND hwnd = GetActiveWindow(); - if (RamSearchClosed) + if(!RamSearchHWnd) { - RamSearchClosed = false; - if(!RamSearchHWnd) - { - reset_address_info(); - LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - RamSearchHWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_RAMSEARCH), hWnd, (DLGPROC) RamSearchProc); - } - } - if (RamWatchClosed || AutoRWLoad) - { - RamWatchClosed = false; - if(!RamWatchHWnd) - { - if (AutoRWLoad) OpenRWRecentFile(0); - RamWatchHWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc); - } + reset_address_info(); + LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + RamSearchHWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_RAMSEARCH), hWnd, (DLGPROC) RamSearchProc); } + if (AutoRWLoad) + OpenRWRecentFile(0); + + if (!RamWatchHWnd) + RamWatchHWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc); + if (hwnd == hWnd && hwnd != GetActiveWindow()) SetActiveWindow(hWnd); // restore focus to the main window if it had it before } @@ -2045,15 +2029,6 @@ invalid_field: signal_new_size(); {rv = true; break;} } - //case IDOK: - case IDCANCEL: - RamSearchHWnd = NULL; -/* if (theApp.pauseDuringCheatSearch) - EndDialog(hDlg, true); // this should never be called on a modeless dialog - else -*/ - DestroyWindow(hDlg); - {rv = true; break;} } // check refresh for comparison preview color update @@ -2097,12 +2072,12 @@ invalid_field: return rv; } break; - -// case WM_CLOSE: + case WM_CLOSE: + DestroyWindow(hDlg); + break; case WM_DESTROY: RamSearchHWnd = NULL; // theApp.modelessCheatDialogIsOpen = false; -// return true; break; } diff --git a/src/drivers/win/ramwatch.cpp b/src/drivers/win/ramwatch.cpp index c26eb228..6a1c27dd 100644 --- a/src/drivers/win/ramwatch.cpp +++ b/src/drivers/win/ramwatch.cpp @@ -34,7 +34,7 @@ bool RWSaveWindowPos = false; //Keeps track of whether Save Window position is c char currentWatch[1024]; int ramw_x, ramw_y; //Used to store ramwatch dialog window positions std::map rswatches; -int WatchCount=0; +int WatchCount = 0; char applicationPath[2048]; struct InitRamWatch @@ -129,7 +129,6 @@ bool InsertWatch(const AddressWatcher& Watch) } - /* LRESULT CALLBACK PromptWatchNameProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) //Gets the description of a watched address { @@ -1021,7 +1020,8 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam //regSetDwordValue(RAMWY, ramw_y); TODO } break; - case WM_INITDIALOG: { + case WM_INITDIALOG: + { RECT r, r2; int dx1, dy1, dx2, dy2; @@ -1126,7 +1126,7 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam { case LVN_ITEMCHANGED: // selection changed event { - NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lP; + NMLISTVIEW* pNMListView = (NMLISTVIEW*)lP; if(pNMListView->uNewState & LVIS_FOCUSED || (pNMListView->uNewState ^ pNMListView->uOldState) & LVIS_SELECTED) @@ -1493,12 +1493,9 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam return true; } break; -// case WM_CLOSE: -// RamWatchHWnd = NULL; -// DragAcceptFiles(hDlg, FALSE); -// DestroyWindow(hDlg); -// return false; - + case WM_CLOSE: + DestroyWindow(hDlg); + break; case WM_DESTROY: // this is the correct place RamWatchHWnd = NULL; @@ -1507,7 +1504,6 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam // release the hdc related objects SeparatorCache::DeInit(); - break; case WM_DROPFILES: @@ -1532,22 +1528,33 @@ void UpdateWatchCheats() { void SeparatorCache::Init(HWND hBox) { - RECT ir; - ir.left = LVIR_BOUNDS; + if (!iHeight) + { + RECT ir; + ir.left = LVIR_BOUNDS; - int count = SendMessage(hBox, LVM_GETITEMCOUNT, 0, 0); - SendMessage(hBox, LVM_SETITEMCOUNT, 1, 0); - SendMessage(hBox, LVM_GETITEMRECT, 0, (LPARAM)&ir); - SendMessage(hBox, LVM_SETITEMCOUNT, count, 0); + int count = SendMessage(hBox, LVM_GETITEMCOUNT, 0, 0); + SendMessage(hBox, LVM_SETITEMCOUNT, 1, 0); + SendMessage(hBox, LVM_GETITEMRECT, 0, (LPARAM)&ir); + SendMessage(hBox, LVM_SETITEMCOUNT, count, 0); - sepOffY = (iHeight = ir.bottom - ir.top) / 2; + iHeight = ir.bottom - ir.top; + } - sepPen = CreatePen(PS_SOLID, 1, RGB(160, 160, 160)); - sepPenSel = CreatePen(PS_SOLID, 1, RGB(224, 224, 224)); + if (!sepOffY) + sepOffY = iHeight / 2; - LOGFONT logFont; - GetObject((HANDLE)SendMessage(hBox, WM_GETFONT, NULL, NULL), sizeof(logFont), &logFont); - sepFon = (HFONT)CreateFontIndirect((logFont.lfWeight = FW_SEMIBOLD, &logFont)); + if (!sepPen) + sepPen = CreatePen(PS_SOLID, 1, RGB(160, 160, 160)); + if (!sepPenSel) + sepPenSel = CreatePen(PS_SOLID, 1, RGB(224, 224, 224)); + + if (!sepFon) + { + LOGFONT logFont; + GetObject((HANDLE)SendMessage(hBox, WM_GETFONT, NULL, NULL), sizeof(logFont), &logFont); + sepFon = (HFONT)CreateFontIndirect((logFont.lfWeight = FW_SEMIBOLD, &logFont)); + } } void SeparatorCache::DeInit() @@ -1555,6 +1562,10 @@ void SeparatorCache::DeInit() DeleteObject(sepPen); DeleteObject(sepPenSel); DeleteObject(sepFon); + + sepPen = NULL; + sepPenSel = NULL; + sepFon = NULL; } diff --git a/src/drivers/win/ramwatch.h b/src/drivers/win/ramwatch.h index b5b95930..0d1ce60c 100644 --- a/src/drivers/win/ramwatch.h +++ b/src/drivers/win/ramwatch.h @@ -59,8 +59,9 @@ extern HWND RamWatchHWnd; extern HACCEL RamWatchAccels; bool InsertWatch(const AddressWatcher& Watch); -bool InsertWatch(const AddressWatcher& Watch, HWND parent); // asks user for comment) -bool EditWatch(int watchIndex, AddressWatcher& watcher); +bool InsertWatch(const AddressWatcher& Watch, HWND parent); // asks user for comment +bool InsertWatch(int watchIndex, const AddressWatcher& watcher); +bool EditWatch(int watchIndex, const AddressWatcher& watcher); bool RemoveWatch(int watchIndex); void Update_RAM_Watch(); diff --git a/src/drivers/win/replay.cpp b/src/drivers/win/replay.cpp index 6baf6221..5013ce50 100644 --- a/src/drivers/win/replay.cpp +++ b/src/drivers/win/replay.cpp @@ -957,6 +957,23 @@ static BOOL CALLBACK RecordDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP { case IDOK: { + extern unsigned int FrozenAddressCount; + if (FrozenAddressCount) + { + char ch[512]; + sprintf(ch, "You have %d activated cheats. If this is not your intentional, it can cause playback prblems! Do you want to disable all of them and continue?", FrozenAddressCount); + switch (MessageBox(hwndDlg, ch, "Movie recording problem", MB_YESNOCANCEL | MB_ICONEXCLAMATION)) + { + case IDCANCEL: + return TRUE; + case IDYES: + extern void DisableAllCheats(); + DisableAllCheats(); + extern void UpdateCheatWindowRelatedWindow(); + UpdateCheatWindowRelatedWindow(); + } + } + LONG lIndex = SendDlgItemMessage(hwndDlg, IDC_COMBO_RECORDFROM, CB_GETCURSEL, 0, 0); p->szFilename = GetRecordPath(hwndDlg); p->recordFrom = (int)lIndex; diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 7bfd47a8..8db6568c 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -12,11 +12,11 @@ #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// -// +// 非特定语言 resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#pragma code_page(1252) +#pragma code_page(936) ///////////////////////////////////////////////////////////////////////////// // @@ -633,7 +633,7 @@ CHEATCONTEXTMENUS MENU BEGIN POPUP "CheatListPopup" BEGIN - MENUITEM "Toggle selected Cheats\tDbl-Clk", CHEAT_CONTEXT_TOGGLECHEAT + MENUITEM "Toggle selected Cheats", CHEAT_CONTEXT_TOGGLECHEAT MENUITEM "Poke Cheat Value", CHEAT_CONTEXT_POKECHEATVALUE MENUITEM "Goto in Hex Editor", CHEAT_CONTEXT_GOTOINHEXEDITOR MENUITEM "Delete selected Cheats", ID_CHEATLISTPOPUP_DELETESELECTEDCHEATS @@ -1966,46 +1966,46 @@ BEGIN LTEXT "New Selection Name:",-1,5,240,68,8 END -CHEATCONSOLE DIALOGEX 0, 0, 379, 189 +CHEATCONSOLE DIALOGEX 0, 0, 420, 190 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Cheat Search" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - GROUPBOX "Active Cheats",201,5,2,129,182,WS_TABSTOP - GROUPBOX "Cheat Search",202,140,2,233,182,WS_TABSTOP - LISTBOX IDC_LIST_CHEATS,11,11,118,98,LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL - LTEXT "Name:",IDC_STATIC,12,114,22,10 - LTEXT "Addr:",IDC_STATIC,12,130,18,10 - LTEXT "Val:",IDC_STATIC,61,130,12,10 - LTEXT "Cmp:",IDC_STATIC,95,130,16,10 - EDITTEXT IDC_CHEAT_NAME,35,112,94,12,ES_AUTOHSCROLL | ES_WANTRETURN - EDITTEXT IDC_CHEAT_ADDR,31,128,25,12,ES_UPPERCASE | ES_WANTRETURN - EDITTEXT IDC_CHEAT_VAL,74,128,16,12,ES_UPPERCASE | ES_WANTRETURN - EDITTEXT IDC_CHEAT_COM,113,128,16,12,ES_UPPERCASE | ES_WANTRETURN - DEFPUSHBUTTON "Add",IDC_BTN_CHEAT_ADD,11,144,36,16 - PUSHBUTTON "Delete",IDC_BTN_CHEAT_DEL,52,144,36,16 - PUSHBUTTON "Update",IDC_BTN_CHEAT_UPD,93,144,36,16 - PUSHBUTTON "Reset",IDC_BTN_CHEAT_RESET,146,12,55,15 - PUSHBUTTON "Known Value:",IDC_BTN_CHEAT_KNOWN,146,31,55,15 - LTEXT "0x",IDC_STATIC,205,34,9,8 - EDITTEXT IDC_CHEAT_VAL_KNOWN,215,32,18,12,ES_UPPERCASE - GROUPBOX "Previous Compare",204,145,49,113,115 - PUSHBUTTON "Equal",IDC_BTN_CHEAT_EQ,151,62,55,15,WS_GROUP - PUSHBUTTON "Not Equal",IDC_BTN_CHEAT_NE,151,87,55,15 - CONTROL "By:",IDC_CHEAT_CHECK_NE_BY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,210,90,22,10 - EDITTEXT IDC_CHEAT_VAL_NE_BY,234,89,18,12,ES_UPPERCASE | ES_WANTRETURN - PUSHBUTTON "Greater Than",IDC_BTN_CHEAT_GT,151,114,55,15 - CONTROL "By:",IDC_CHEAT_CHECK_GT_BY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,210,117,22,10 - EDITTEXT IDC_CHEAT_VAL_GT_BY,234,116,18,12,ES_UPPERCASE | ES_WANTRETURN - PUSHBUTTON "Less Than",IDC_BTN_CHEAT_LT,151,141,55,15 - CONTROL "By:",IDC_CHEAT_CHECK_LT_BY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,210,144,22,10 - EDITTEXT IDC_CHEAT_VAL_LT_BY,234,143,18,12,ES_UPPERCASE | ES_WANTRETURN - GROUPBOX "Possibilities",IDC_CHEAT_BOX_POSSIBILITIES,263,8,105,156,WS_TABSTOP - LISTBOX IDC_CHEAT_LIST_POSSIBILITIES,268,18,85,142,LBS_SORT | LBS_NOINTEGRALHEIGHT | LBS_WANTKEYBOARDINPUT | WS_TABSTOP - SCROLLBAR IDC_CHEAT_SCRL_POSSIBILITIES,354,18,10,142,SBS_VERT + GROUPBOX "Active Cheats",IDC_GROUPBOX_CHEATLIST,5,2,171,182,WS_TABSTOP + GROUPBOX "Cheat Search",IDC_GROUPBOX_CHEATSEARCH,181,2,233,182,WS_TABSTOP + CONTROL "", IDC_LIST_CHEATS, "SysListView32", LVS_REPORT | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP, 11,11,159,118 + LTEXT "Name:",IDC_STATIC,12,135,22,10 + LTEXT "Address:",IDC_STATIC,12,150,30,8 + LTEXT "Value:",IDC_STATIC,73,150,22,8 + LTEXT "Compare:",IDC_STATIC,116,150,34,8 + EDITTEXT IDC_CHEAT_NAME,36,133,132,12,ES_AUTOHSCROLL | ES_WANTRETURN + EDITTEXT IDC_CHEAT_ADDR,44,148,25,12,ES_UPPERCASE | ES_WANTRETURN + EDITTEXT IDC_CHEAT_VAL,97,148,16,12,ES_UPPERCASE | ES_WANTRETURN + EDITTEXT IDC_CHEAT_COM,152,148,16,12,ES_UPPERCASE | ES_WANTRETURN + DEFPUSHBUTTON "Add",IDC_BTN_CHEAT_ADD,11,163,36,16 + PUSHBUTTON "Delete",IDC_BTN_CHEAT_DEL,47,163,36,16 + PUSHBUTTON "Update",IDC_BTN_CHEAT_UPD,83,163,36,16 + PUSHBUTTON "Reset",IDC_BTN_CHEAT_RESET,187,12,55,15 + PUSHBUTTON "Known Value:",IDC_BTN_CHEAT_KNOWN,187,31,55,15 + LTEXT "0x",IDC_STATIC,246,34,9,8 + EDITTEXT IDC_CHEAT_VAL_KNOWN,256,32,18,12,ES_UPPERCASE + GROUPBOX "Previous Compare",204,186,49,113,115 + PUSHBUTTON "Equal",IDC_BTN_CHEAT_EQ,192,62,55,15,WS_GROUP + PUSHBUTTON "Not Equal",IDC_BTN_CHEAT_NE,192,87,55,15 + CONTROL "By:",IDC_CHEAT_CHECK_NE_BY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,251,90,22,10 + EDITTEXT IDC_CHEAT_VAL_NE_BY,275,89,18,12,ES_UPPERCASE | ES_WANTRETURN + PUSHBUTTON "Greater Than",IDC_BTN_CHEAT_GT,192,114,55,15 + CONTROL "By:",IDC_CHEAT_CHECK_GT_BY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,251,117,22,10 + EDITTEXT IDC_CHEAT_VAL_GT_BY,275,116,18,12,ES_UPPERCASE | ES_WANTRETURN + PUSHBUTTON "Less Than",IDC_BTN_CHEAT_LT,192,141,55,15 + CONTROL "By:",IDC_CHEAT_CHECK_LT_BY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,251,144,22,10 + EDITTEXT IDC_CHEAT_VAL_LT_BY,275,143,18,12,ES_UPPERCASE | ES_WANTRETURN + GROUPBOX "Possibilities",IDC_CHEAT_BOX_POSSIBILITIES,304,8,105,156,WS_TABSTOP + LISTBOX IDC_CHEAT_LIST_POSSIBILITIES,309,18,85,142,LBS_SORT | LBS_NOINTEGRALHEIGHT | LBS_WANTKEYBOARDINPUT | WS_TABSTOP + SCROLLBAR IDC_CHEAT_SCRL_POSSIBILITIES,395,18,10,142,SBS_VERT CONTROL " Pause emulation when this window is active",IDC_CHEAT_PAUSEWHENACTIVE, - "Button",BS_AUTOCHECKBOX,147,169,157,10 - PUSHBUTTON "Add from CHT file...",IDC_BTN_CHEAT_ADDFROMFILE,23,163,93,16 + "Button",BS_AUTOCHECKBOX,188,169,157,10 + PUSHBUTTON "Import...",IDC_BTN_CHEAT_ADDFROMFILE,127,163,43,16 END IDD_LUA DIALOGEX 0, 0, 270, 150 @@ -2142,7 +2142,7 @@ END IDD_RAMWATCH DIALOGEX 0, 0, 269, 298 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION " RAM Watch" +CAPTION "RAM Watch" MENU RAMWATCH_MENU FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN @@ -2425,7 +2425,8 @@ BEGIN "CHEATCONSOLE", DIALOG BEGIN - BOTTOMMARGIN, 188 + RIGHTMARGIN, 419 + BOTTOMMARGIN, 189 END "VIDEOCONFIG", DIALOG @@ -2499,6 +2500,11 @@ BEGIN 0 END +CHEATCONSOLE AFX_DIALOG_LAYOUT +BEGIN + 0 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -2670,12 +2676,12 @@ IDB_BITMAP_SELECTED17 BITMAP "res\\te_17_selected.bmp" IDB_BITMAP_SELECTED18 BITMAP "res\\te_18_selected.bmp" IDB_BITMAP_SELECTED19 BITMAP "res\\te_19_selected.bmp" IDB_BRANCH_SPRITESHEET BITMAP "res\\branch_spritesheet.bmp" -#endif +#endif // 非特定语言 resources ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// -// English(U.S.) resources +// 英语(美国) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US @@ -2704,7 +2710,7 @@ END #endif // APSTUDIO_INVOKED -#endif // English(U.S.) resources +#endif // 英语(美国) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index a94b891b..e8f30292 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -238,6 +238,7 @@ #define IDC_DEBUGGER_FLAG_N 200 #define IDC_ADDBP_ADDR_START 200 #define MENU_POWER 201 +#define IDC_GROUPBOX_CHEATLIST 201 #define TXT_PAD2 201 #define IDC_BUTTON_BROWSEFILE 201 #define IDC_CHECK_READONLY 201 @@ -260,6 +261,7 @@ #define IDC_ADDBP_CONDITION 202 #define IDC_ASSEMBLER_SAVE 202 #define IDD_TASEDITOR_NEWPROJECT 202 +#define IDC_GROUPBOX_CHEATSEARCH 202 #define MENU_SWITCH_DISK 203 #define IDC_NETMOO_NICK 203 #define IDC_CHEAT_BOX_POSSIBILITIES 203 diff --git a/src/fceu.cpp b/src/fceu.cpp index b515b70f..52376f8f 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -114,10 +114,6 @@ bool AutoResumePlay = false; char romNameWhenClosingEmulator[2048] = {0}; -// indicator for the open in archive dialog that if the load was canceled by the user. -// TODO: Since I can't think of a better way to indicate it, hope someone could imporve it. -bool archiveManuallyCanceled = false; - FCEUGI::FCEUGI() : filename(0), archiveFilename(0) { @@ -404,9 +400,6 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode); int FDSLoad(const char *name, FCEUFILE *fp); int NSFLoad(const char *name, FCEUFILE *fp); -//char lastLoadedGameName [2048] = {0,}; // hack for movie WRAM clearing on record from poweron -extern bool archiveManuallyCanceled; - //name should be UTF-8, hopefully, or else there may be trouble FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silent) { @@ -418,16 +411,18 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen int lastdendy = dendy; const char* romextensions[] = { "nes", "fds", 0 }; - fp = FCEU_fopen(name, 0, "rb", 0, -1, romextensions); + + // indicator for if the operaton was canceled by user + // currently there's only one situation: + // the user clicked cancel form the open from archive dialog + bool userCancel = false; + fp = FCEU_fopen(name, 0, "rb", 0, -1, romextensions, &userCancel); if (!fp) { // Although !fp, if the operation was canceled from archive select dialog box, don't show the error message; - if (!silent && !archiveManuallyCanceled) + if (!silent && !userCancel) FCEU_PrintError("Error opening \"%s\"!", name); - // Set it back to false, since user might not load ROM from dialog the next time. - // TODO: find a better way to do this. - archiveManuallyCanceled = false; return 0; } diff --git a/src/file.cpp b/src/file.cpp index 3ef0bf6a..04d943f2 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -256,7 +256,7 @@ zpfail: return 0; } -FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext, int index, const char** extensions) +FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext, int index, const char** extensions, bool* userCancel) { FILE *ipsfile=0; FCEUFILE *fceufp=0; @@ -360,11 +360,11 @@ FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext //open an archive file if(archive == "") if(index != -1) - fceufp = FCEUD_OpenArchiveIndex(asr, fileToOpen, index); + fceufp = FCEUD_OpenArchiveIndex(asr, fileToOpen, index, userCancel); else - fceufp = FCEUD_OpenArchive(asr, fileToOpen, 0); + fceufp = FCEUD_OpenArchive(asr, fileToOpen, 0, userCancel); else - fceufp = FCEUD_OpenArchive(asr, archive, &fname); + fceufp = FCEUD_OpenArchive(asr, archive, &fname, userCancel); if(!fceufp) return 0; diff --git a/src/file.h b/src/file.h index 5a6a5d4a..3b85639f 100644 --- a/src/file.h +++ b/src/file.h @@ -11,11 +11,6 @@ extern bool bindSavestate; -// indicator for the open in archive dialog that if the load was canceled by the user. -// TODO: Since I can't think of a better way to indicate it, hope someone could imporve it. -extern bool archiveManuallyCanceled; - - struct FCEUFILE { //the stream you can use to access the data //std::iostream *stream; @@ -127,7 +122,7 @@ struct ArchiveScanRecord }; -FCEUFILE *FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext, int index=-1, const char** extensions = 0); +FCEUFILE *FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext, int index=-1, const char** extensions = 0, bool* userCancel = NULL); bool FCEU_isFileInArchive(const char *path); int FCEU_fclose(FCEUFILE*); uint64 FCEU_fread(void *ptr, size_t size, size_t nmemb, FCEUFILE*);