- cleanup & add classes;
- new cheat file format;

tools:
- add 'cheat file format converter' (.dct) from old versions (console);
This commit is contained in:
mtabachenko 2009-12-20 01:31:58 +00:00
parent f397adaf47
commit 6fe8d6bdc7
15 changed files with 1153 additions and 443 deletions

View File

@ -127,6 +127,9 @@ int NDS_Init( void) {
TSCal.scr.width = (TSCal.scr.x2 - TSCal.scr.x1);
TSCal.scr.height = (TSCal.scr.y2 - TSCal.scr.y1);
cheats = new CHEATS();
cheatSearch = new CHEATSEARCH();
return 0;
}
@ -140,7 +143,11 @@ void NDS_DeInit(void) {
gpu3D->NDS_3D_Close();
WIFI_DeInit();
cheatsSearchClose();
if (cheats)
delete cheats;
if (cheatSearch)
delete cheatSearch;
}
BOOL NDS_SetROM(u8 * rom, u32 mask)
@ -376,7 +383,8 @@ int NDS_LoadROM(const char *filename, const char *logicalFilename)
}
#endif
cheatsSearchClose();
if (cheatSearch)
cheatSearch->close();
FCEUI_StopMovie();
MMU_unsetRom();
@ -396,7 +404,7 @@ int NDS_LoadROM(const char *filename, const char *logicalFilename)
path.getpathnoext(path.CHEATS, buf);
strcat(buf, ".dct"); // DeSmuME cheat :)
cheatsInit(buf);
cheats->init(buf);
gameInfo.populate();
gameInfo.crc = crc32(0,(u8*)gameInfo.romdata,gameInfo.romsize);
@ -495,7 +503,8 @@ int NDS_LoadROM(const char *filename, const char *logicalFilename)
#endif
cheatsSearchClose();
if (cheatSearch)
cheatSearch->close();
MMU_unsetRom();
NDS_SetROM(data, mask);
NDS_Reset();
@ -1813,7 +1822,8 @@ void NDS_exec(s32 nb)
lagframecounter = 0;
}
currFrameCounter++;
cheatsProcess();
if (cheats)
cheats->process();
}
void execHardware_interrupts()
@ -2004,7 +2014,7 @@ void NDS_Reset()
armcpu_init(&NDS_ARM7, header->ARM7exe);
armcpu_init(&NDS_ARM9, header->ARM9exe);
}
nds.wifiCycle = 0;
memset(nds.timerCycle, 0, sizeof(u64) * 2 * 4);
nds.VCount = 0;

File diff suppressed because it is too large Load Diff

View File

@ -23,9 +23,10 @@
#include "common.h"
#define CHEAT_VERSION_MAJOR 1
#define CHEAT_VERSION_MINOR 3
#define MAX_CHEAT_LIST 100
#define CHEAT_VERSION_MAJOR 2
#define CHEAT_VERSION_MINOR 0
#define MAX_CHEAT_LIST 100
#define MAX_XX_CODE 255
typedef struct
{
@ -33,40 +34,90 @@ typedef struct
// 1 - Action Replay
// 2 - Codebreakers
BOOL enabled;
u32 hi[255];
u32 lo[255];
//u32 code[MAX_XX_CODE][2];
u32 hi[MAX_XX_CODE];
u32 lo[MAX_XX_CODE];
char description[75];
int num;
u8 size;
} CHEATS_LIST;
extern void cheatsInit(char *path);
extern BOOL cheatsAdd(u8 size, u32 address, u32 val, char *description, BOOL enabled);
extern BOOL cheatsUpdate(u8 size, u32 address, u32 val, char *description, BOOL enabled, u32 pos);
extern BOOL cheatsAdd_AR(char *code, char *description, BOOL enabled);
extern BOOL cheatsUpdate_AR(char *code, char *description, BOOL enabled, u32 pos);
extern BOOL cheatsAdd_CB(char *code, char *description, BOOL enabled);
extern BOOL cheatsUpdate_CB(char *code, char *description, BOOL enabled, u32 pos);
extern BOOL cheatsRemove(u32 pos);
extern void cheatsGetListReset();
extern BOOL cheatsGetList(CHEATS_LIST *cheat);
extern BOOL cheatsGet(CHEATS_LIST *cheat, u32 pos);
extern u32 cheatsGetSize();
extern BOOL cheatsSave();
extern BOOL cheatsLoad();
extern BOOL cheatsPush();
extern BOOL cheatsPop();
extern void cheatsStackClear();
extern void cheatsProcess();
extern void cheatGetXXcodeString(CHEATS_LIST cheat, char *res_buf);
extern void cheatsDisable(bool disable);
class CHEATS
{
private:
CHEATS_LIST list[MAX_CHEAT_LIST];
u16 num;
u8 filename[MAX_PATH];
u32 currentGet;
u8 *stack;
u16 numStack;
bool disabled;
void clear();
void ARparser(CHEATS_LIST cheat);
BOOL XXcodePreParser(CHEATS_LIST *cheat, char *code);
char *clearCode(char *s);
public:
CHEATS::CHEATS():
num(0), currentGet(0), stack(0), numStack(0), disabled(0)
{
memset(list, 0, sizeof(list));
memset(filename, 0, sizeof(filename));
}
CHEATS::~CHEATS() {}
void init(char *path);
BOOL add(u8 size, u32 address, u32 val, char *description, BOOL enabled);
BOOL update(u8 size, u32 address, u32 val, char *description, BOOL enabled, u32 pos);
BOOL add_AR(char *code, char *description, BOOL enabled);
BOOL update_AR(char *code, char *description, BOOL enabled, u32 pos);
BOOL add_CB(char *code, char *description, BOOL enabled);
BOOL update_CB(char *code, char *description, BOOL enabled, u32 pos);
BOOL remove(u32 pos);
void getListReset();
BOOL getList(CHEATS_LIST *cheat);
BOOL get(CHEATS_LIST *cheat, u32 pos);
u32 getSize();
BOOL save();
BOOL load();
BOOL push();
BOOL pop();
void stackClear();
void process();
void getXXcodeString(CHEATS_LIST cheat, char *res_buf);
void disable(bool disable);
};
class CHEATSEARCH
{
private:
u8 *statMem;
u8 *mem;
u32 amount;
u32 lastRecord;
u32 _type;
u32 _size;
u32 _sign;
public:
CHEATSEARCH()
: statMem(0), mem(0), amount(0), lastRecord(0), _type(0), _size(0), _sign(0)
{}
~CHEATSEARCH() { close(); }
BOOL start(u8 type, u8 size, u8 sign);
BOOL close();
u32 search(u32 val);
u32 search(u8 comp);
u32 getAmount();
BOOL getList(u32 *address, u32 *curVal);
void getListReset();
};
extern CHEATS *cheats;
extern CHEATSEARCH *cheatSearch;
// ==================================================== cheat search
extern void cheatsSearchInit(u8 type, u8 size, u8 sign);
extern void cheatsSearchClose();
extern u32 cheatsSearchValue(u32 val);
extern u32 cheatsSearchComp(u8 comp);
extern u32 cheatSearchNumber();
extern BOOL cheatSearchGetList(u32 *address, u32 *curVal);
extern void cheatSearchGetListReset();

View File

@ -51,22 +51,13 @@ u8 reverseBitsInByte(u8 x)
return h;
}
void removeCR(char *buf)
char *trim(char *s)
{
int l=strlen(buf);
for (int i=0; i < l; i++)
{
if (buf[i]==0x0A) buf[i]=0;
if (buf[i]==0x0D) buf[i]=0;
}
}
u32 strlen_ws(char *buf) // length without last spaces
{
if (!strlen(buf)) return 0;
for (int i=strlen(buf); i>0; i--)
{
if (buf[i]!=32) return (i-1); // space
}
return 0;
char *ptr = NULL;
if (!s) return NULL;
if (!*s) return s;
for (ptr = s + strlen(s) - 1; (ptr >= s) && isspace(*ptr); ptr--);
ptr[1] = '\0';
return s;
}

View File

@ -34,7 +34,7 @@ extern u8 logo_data[156];
#include <winsock2.h>
#include <windows.h>
#define CLASSNAME "DeSmuME"
@ -56,8 +56,7 @@ extern u8 logo_data[156];
#endif
extern u8 reverseBitsInByte(u8 x);
extern void removeCR(char *buf);
extern u32 strlen_ws(char *buf);
extern char *trim(char *s);
#endif

View File

@ -87,9 +87,9 @@ enabled_toggled(GtkCellRendererToggle * cell,
path1 = gtk_tree_model_get_path (model, &iter);
ii = gtk_tree_path_get_indices (path)[0];
cheatsGet(&cheat, ii);
cheats->get(&cheat, ii);
cheatsUpdate(cheat.size, cheat.hi[0], cheat.lo[0], cheat.description,
cheats->update(cheat.size, cheat.hi[0], cheat.lo[0], cheat.description,
enabled, ii);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, COLUMN_ENABLED, enabled, -1);
@ -118,7 +118,7 @@ static void cheat_list_modify_cheat(GtkCellRendererText * cell,
path1 = gtk_tree_model_get_path (model, &iter);
ii = gtk_tree_path_get_indices (path)[0];
cheatsGet(&cheat, ii);
cheats->get(&cheat, ii);
gtk_tree_path_free (path1);
@ -127,22 +127,22 @@ static void cheat_list_modify_cheat(GtkCellRendererText * cell,
u32 v = atoi(new_text);
switch (column) {
case COLUMN_SIZE:
cheatsUpdate(v-1, cheat.hi[0], cheat.lo[0],
cheats->update(v-1, cheat.hi[0], cheat.lo[0],
cheat.description, cheat.enabled, ii);
break;
case COLUMN_HI:
cheatsUpdate(cheat.size, v, cheat.lo[0], cheat.description,
cheats->update(cheat.size, v, cheat.lo[0], cheat.description,
cheat.enabled, ii);
break;
case COLUMN_LO:
cheatsUpdate(cheat.size, cheat.hi[0], v, cheat.description,
cheats->update(cheat.size, cheat.hi[0], v, cheat.description,
cheat.enabled, ii);
break;
}
gtk_list_store_set(GTK_LIST_STORE(model), &iter, column,
atoi(new_text), -1);
} else if (column == COLUMN_DESC){
cheatsUpdate(cheat.size, cheat.hi[0], cheat.lo[0],
cheats->update(cheat.size, cheat.hi[0], cheat.lo[0],
g_strdup(new_text), cheat.enabled, ii);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, column,
g_strdup(new_text), -1);
@ -166,7 +166,7 @@ static void cheat_list_remove_cheat(GtkWidget * widget, gpointer data)
ii = gtk_tree_path_get_indices (path)[0];
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
cheatsRemove(ii);
cheats->remove(ii);
gtk_tree_path_free (path);
}
@ -177,7 +177,7 @@ static void cheat_list_add_cheat(GtkWidget * widget, gpointer data)
#define NEW_DESC "New cheat"
GtkListStore *store = (GtkListStore *) data;
GtkTreeIter iter;
cheatsAdd(1, 0, 0, g_strdup(NEW_DESC), FALSE);
cheats->add(1, 0, 0, g_strdup(NEW_DESC), FALSE);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
COLUMN_ENABLED, FALSE,
@ -271,7 +271,7 @@ static void cheat_list_add_columns(GtkTreeView * tree, GtkListStore * store)
static void cheatListEnd()
{
cheatsSave();
cheats->save();
if(shouldBeRunning)
Launch();
}
@ -282,10 +282,10 @@ static GtkListStore *cheat_list_populate()
G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
CHEATS_LIST cheat;
u32 chsize = cheatsGetSize();
u32 chsize = cheats->getSize();
for(u32 ii = 0; ii < chsize; ii++){
GtkTreeIter iter;
cheatsGet(&cheat, ii);
cheats->get(&cheat, ii);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
COLUMN_ENABLED, cheat.enabled,

View File

@ -415,4 +415,6 @@ char (*BLAHBLAHBLAH( UNALIGNED T (&)[N] ))[N];
#define CTASSERT(x) typedef char __assert ## y[(x) ? 1 : -1]
#endif
static const char hexValid[23] = {"0123456789ABCDEFabcdef"};
#endif

View File

@ -246,9 +246,9 @@ INT_PTR CALLBACK CheatsAddProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam
u32 tmp_addr = 0;
sscanf_s(editBuf[0], "%x", &tmp_addr);
if (cheatsAdd(searchAddSize, tmp_addr, atol(editBuf[1]), editBuf[2], searchAddFreeze))
if (cheats->add(searchAddSize, tmp_addr, atol(editBuf[1]), editBuf[2], searchAddFreeze))
{
if ((searchAddMode == 0) || (cheatsSave() && (searchAddMode == 1 || searchAddMode == 2)))
if ((searchAddMode == 0) || (cheats->save() && (searchAddMode == 1 || searchAddMode == 2)))
{
oldEditProc = saveOldEditProc;
searchAddAddress = tmp_addr;
@ -388,7 +388,7 @@ INT_PTR CALLBACK CheatsEditProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpara
oldEditProcHEX = SetWindowLongPtr(GetDlgItem(dialog, IDC_EDIT1), GWLP_WNDPROC, (LONG_PTR)EditValueHEXProc);
oldEditProc = SetWindowLongPtr(GetDlgItem(dialog, IDC_EDIT2), GWLP_WNDPROC, (LONG_PTR)EditValueProc);
cheatsGet(&tempCheat, cheatEditPos);
cheats->get(&tempCheat, cheatEditPos);
memset(buf, 0, 100);
memset(buf2, 0, 100);
@ -413,7 +413,7 @@ INT_PTR CALLBACK CheatsEditProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpara
{
case IDOK:
{
if (cheatsUpdate(tempCheat.size, tempCheat.hi[0], tempCheat.lo[0], tempCheat.description, tempCheat.enabled, cheatEditPos))
if (cheats->update(tempCheat.size, tempCheat.hi[0], tempCheat.lo[0], tempCheat.description, tempCheat.enabled, cheatEditPos))
{
oldEditProc = saveOldEditProc;
EndDialog(dialog, TRUE);
@ -559,10 +559,10 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
if (cheatXXaction != 0)
{
char buf[sizeof(tempCheat.hi)+sizeof(tempCheat.lo)] = { 0 };
char buf[(sizeof(tempCheat.hi)+sizeof(tempCheat.lo)) * 2] = { 0 };
memset(buf, 0, sizeof(buf));
cheatGetXXcodeString(tempCheat, buf);
cheats->getXXcodeString(tempCheat, buf);
SetWindowText(GetDlgItem(dialog, IDC_EDIT2), buf);
SetWindowText(GetDlgItem(dialog, IDC_EDIT3), tempCheat.description);
@ -571,7 +571,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
}
CheckDlgButton(dialog, IDC_CHECK1, tempCheat.enabled?BST_CHECKED:BST_UNCHECKED);
SendMessage(GetDlgItem(dialog, IDC_EDIT2), EM_SETLIMITTEXT, sizeof(tempCheat.hi)+sizeof(tempCheat.lo), 0);
SendMessage(GetDlgItem(dialog, IDC_EDIT2), EM_SETLIMITTEXT, (sizeof(tempCheat.hi)+sizeof(tempCheat.lo)) * 2, 0);
SendMessage(GetDlgItem(dialog, IDC_EDIT3), EM_SETLIMITTEXT, sizeof(tempCheat.description), 0);
}
return TRUE;
@ -582,7 +582,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
{
case IDOK:
{
char buf[sizeof(tempCheat.hi)+sizeof(tempCheat.lo)] = { 0 };
char buf[(sizeof(tempCheat.hi)+sizeof(tempCheat.lo)) * 2] = { 0 };
memset(buf, 0, sizeof(buf));
GetWindowText(GetDlgItem(dialog, IDC_EDIT2), buf, sizeof(buf));
@ -591,7 +591,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
{
if (cheatXXaction == 0) // add
{
if (!cheatsAdd_AR(buf, tempCheat.description, tempCheat.enabled))
if (!cheats->add_AR(buf, tempCheat.description, tempCheat.enabled))
{
MessageBox(dialog, "Syntax error in Action Replay code.\nTry again", "DeSmuME",
MB_OK | MB_ICONERROR);
@ -600,7 +600,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
}
else // edit
{
if (!cheatsUpdate_AR(buf, tempCheat.description, tempCheat.enabled, cheatEditPos))
if (!cheats->update_AR(buf, tempCheat.description, tempCheat.enabled, cheatEditPos))
{
MessageBox(dialog, "Syntax error in Action Replay code.\nTry again", "DeSmuME",
MB_OK | MB_ICONERROR);
@ -612,7 +612,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
{
if (cheatXXaction == 0) // add
{
if (!cheatsAdd_CB(buf, tempCheat.description, tempCheat.enabled))
if (!cheats->add_CB(buf, tempCheat.description, tempCheat.enabled))
{
MessageBox(dialog, "Syntax error in Codebreaker code.\nTry again", "DeSmuME",
MB_OK | MB_ICONERROR);
@ -621,7 +621,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
}
else // edit
{
if (!cheatsUpdate_CB(buf, tempCheat.description, tempCheat.enabled, cheatEditPos))
if (!cheats->update_CB(buf, tempCheat.description, tempCheat.enabled, cheatEditPos))
{
MessageBox(dialog, "Syntax error in Codebreaker code.\nTry again", "DeSmuME",
MB_OK | MB_ICONERROR);
@ -640,7 +640,7 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp
case IDC_EDIT2: // code
if (HIWORD(wparam) == EN_UPDATE)
{
char buf[sizeof(tempCheat.hi)+sizeof(tempCheat.lo)] = { 0 };
char buf[(sizeof(tempCheat.hi)+sizeof(tempCheat.lo)) * 2] = { 0 };
memset(buf, 0, sizeof(buf));
GetWindowText(GetDlgItem(dialog, IDC_EDIT2), buf, sizeof(buf));
@ -712,9 +712,9 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
lvi.mask = LVIF_TEXT|LVIF_STATE;
lvi.iItem = INT_MAX;
cheatsGetListReset();
cheats->getListReset();
SendMessage(cheatListView, WM_SETREDRAW, (WPARAM)FALSE,0);
while (cheatsGetList(&tempCheat))
while (cheats->getList(&tempCheat))
{
char buf[256];
if (tempCheat.enabled)
@ -767,20 +767,20 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
if ( tmp_msg->code == LVN_ITEMACTIVATE )
{
cheatEditPos = ListView_GetNextItem(cheatListView, -1, LVNI_SELECTED|LVNI_FOCUSED);
cheatsGet(&tempCheat, cheatEditPos);
cheats->get(&tempCheat, cheatEditPos);
tempCheat.enabled = !tempCheat.enabled;
switch (tempCheat.type)
{
case 0: // internal
cheatsUpdate(tempCheat.size, tempCheat.hi[0], tempCheat.lo[0], tempCheat.description, tempCheat.enabled, cheatEditPos);
cheats->update(tempCheat.size, tempCheat.hi[0], tempCheat.lo[0], tempCheat.description, tempCheat.enabled, cheatEditPos);
break;
case 1: // Action Replay
cheatsUpdate_AR(NULL, NULL, tempCheat.enabled, cheatEditPos);
cheats->update_AR(NULL, NULL, tempCheat.enabled, cheatEditPos);
break;
case 2: // Codebreaker
cheatsUpdate_CB(NULL, NULL, tempCheat.enabled, cheatEditPos);
cheats->update_CB(NULL, NULL, tempCheat.enabled, cheatEditPos);
break;
}
@ -815,7 +815,7 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
switch (LOWORD(wparam))
{
case IDOK:
if (cheatsSave())
if (cheats->save())
{
EndDialog(dialog, TRUE);
}
@ -905,9 +905,9 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
case IDC_BEDIT:
{
cheatEditPos = ListView_GetNextItem(cheatListView, -1, LVNI_SELECTED|LVNI_FOCUSED);
if (cheatEditPos > cheatsGetSize()) return TRUE;
if (cheatEditPos > cheats->getSize()) return TRUE;
cheatsGet(&tempCheat, cheatEditPos);
cheats->get(&tempCheat, cheatEditPos);
switch (tempCheat.type)
{
@ -915,7 +915,7 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
if (DialogBoxW(hAppInst, MAKEINTRESOURCEW(IDD_CHEAT_ADD), dialog, (DLGPROC) CheatsEditProc))
{
char buf[256];
cheatsGet(&tempCheat, cheatEditPos);
cheats->get(&tempCheat, cheatEditPos);
if (tempCheat.enabled)
ListView_SetItemText(cheatListView, cheatEditPos, 0, "X");
wsprintf(buf, "0x02%06X", tempCheat.hi[0]);
@ -937,7 +937,7 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
if (DialogBoxW(hAppInst, MAKEINTRESOURCEW(IDD_CHEAT_ADD_XX_CODE), dialog, (DLGPROC) CheatsAdd_XX_Proc))
{
cheatsGet(&tempCheat, cheatEditPos);
cheats->get(&tempCheat, cheatEditPos);
if (tempCheat.enabled)
ListView_SetItemText(cheatListView, cheatEditPos, 0, "X");
@ -965,7 +965,7 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
int tmp_pos = ListView_GetNextItem(cheatListView, -1, LVNI_SELECTED|LVNI_FOCUSED);
if (tmp_pos != -1)
{
if (cheatsRemove(tmp_pos))
if (cheats->remove(tmp_pos))
{
ListView_DeleteItem(cheatListView, tmp_pos);
EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
@ -983,17 +983,17 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
void CheatsListDialog(HWND hwnd)
{
if (!cheatsPush()) return;
memset(&tempCheat, 0, sizeof(CHEATS_LIST));
if (!cheats->push()) return;
memset(&tempCheat, 0, sizeof(tempCheat));
u32 res=DialogBoxW(hAppInst, MAKEINTRESOURCEW(IDD_CHEAT_LIST), hwnd, (DLGPROC) CheatsListBox_Proc);
if (res)
{
cheatsSave();
cheatsStackClear();
cheats->save();
cheats->stackClear();
}
else
{
cheatsPop();
cheats->pop();
}
}
@ -1012,7 +1012,7 @@ void CheatsAddDialog(HWND parentHwnd, u32 address, u32 value, u8 size, const cha
//CheatsListDialog(listParentHwnd);
//
//char buf[256];
//cheatsGet(&tempCheat, cheatEditPos);
//cheats->get(&tempCheat, cheatEditPos);
//if (tempCheat.enabled)
// ListView_SetItemText(cheatListView, cheatEditPos, 0, "X");
//wsprintf(buf, "0x02%06X", tempCheat.hi[0]);
@ -1169,9 +1169,9 @@ INT_PTR CALLBACK CheatsSearchViewWnd(HWND dialog, UINT msg,WPARAM wparam,LPARAM
lvi.mask = LVIF_TEXT|LVIF_STATE;
lvi.iItem = INT_MAX;
cheatSearchGetListReset();
cheatSearch->getListReset();
SendMessage(searchListView, WM_SETREDRAW, (WPARAM)FALSE,0);
while (cheatSearchGetList(&address, &val))
while (cheatSearch->getList(&address, &val))
{
char buf[256];
wsprintf(buf, "0x02%06X", address);
@ -1312,16 +1312,16 @@ INT_PTR CALLBACK CheatsSearchProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpa
case IDC_BSEARCH:
if (searchStep == 0)
cheatsSearchInit(searchType, searchSize, searchSign);
cheatSearch->start(searchType, searchSize, searchSign);
if (searchType == 0)
{
if (searchStep == 1)
searchNumberResults = cheatsSearchValue(exactVal);
searchNumberResults = cheatSearch->search((u32)exactVal);
}
else
{
if (searchStep == 2)
searchNumberResults = cheatsSearchComp(searchComp);
searchNumberResults = cheatSearch->search((u8)searchComp);
}
searchStep++;
@ -1340,7 +1340,7 @@ INT_PTR CALLBACK CheatsSearchProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpa
return TRUE;
case IDC_BRESTART:
cheatsSearchClose();
cheatSearch->close();
searchStep = 0;
searchNumberResults = 0;
if (searchWnd) DestroyWindow(searchWnd);

View File

@ -4655,7 +4655,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
case IDM_CHEATS_DISABLE:
_cheatsDisabled = !_cheatsDisabled;
cheatsDisable(_cheatsDisabled);
cheats->disable(_cheatsDisabled);
MainWindow->checkMenu(IDM_CHEATS_DISABLE, _cheatsDisabled );
return 0;

View File

@ -0,0 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cheatsConverter_VS2008", "cheatsConverter_VS2008.vcproj", "{6D076DD4-4000-4249-BDEA-F7AB407C813D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6D076DD4-4000-4249-BDEA-F7AB407C813D}.Release|Win32.ActiveCfg = Release|Win32
{6D076DD4-4000-4249-BDEA-F7AB407C813D}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,127 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="cheatsConverter_VS2008"
ProjectGUID="{6D076DD4-4000-4249-BDEA-F7AB407C813D}"
RootNamespace="cheatsConverter"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\.VS2008\$(ConfigurationName)"
IntermediateDirectory=".\.VS2008\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
WholeProgramOptimization="true"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_CONSOLE"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
EnableEnhancedInstructionSet="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="0"
CallingConvention="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile=".\.bin\$(ProjectName).exe"
LinkIncremental="1"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\src\common.h"
>
</File>
<File
RelativePath=".\src\convert.cpp"
>
</File>
<File
RelativePath=".\src\convert.h"
>
</File>
<File
RelativePath=".\src\main.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,70 @@
/* Cheats converter
Copyright 2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _COMMON_H__
#define _COMMON_H__
#ifdef _MSC_VER
#pragma warning(disable: 4995)
#pragma warning(disable: 4996)
#endif
#ifdef _WIN32
#include <windows.h>
#endif
#include <ctype.h>
#include <string.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned __int64 u64;
typedef signed char s8;
typedef signed short s16;
typedef signed int s32;
typedef __int64 s64;
static char *trim(char *s)
{
char *ptr = NULL;
if (!s) return NULL;
if (!*s) return s;
for (ptr = s + strlen(s) - 1; (ptr >= s) && isspace(*ptr); ptr--);
ptr[1] = '\0';
return s;
}
#ifdef _WIN32
char __forceinline *error()
{
LPVOID lpMsgBuf = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 512, NULL);
return strdup((char*)lpMsgBuf);
}
#endif
#endif

View File

@ -0,0 +1,301 @@
/* Cheats converter
Copyright 2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include "convert.h"
CHEATS_LIST list[MAX_CHEAT_LIST] = {0};
u32 num = 0;
char ROMserial[50] = {0};
static void cheatsClear()
{
memset(list, 0, sizeof(list));
for (int i = 0; i < MAX_CHEAT_LIST; i++)
list[i].type = 0xFF;
num = 0;
}
bool save(char *filename)
{
char *types[] = {"DS", "AR", "CB"};
char buf[(sizeof(list[0].hi)+sizeof(list[0].lo)) * 2 + 200] = { 0 };
FILE *flist = fopen(filename, "w");
if (flist)
{
fprintf(flist, "; DeSmuME cheat file. VERSION %i.%03i\n", CHEAT_VERSION_MAJOR, CHEAT_VERSION_MINOR);
fprintf(flist, "Name=%s\n", ROMserial);
fputs("; lists list\n", flist);
for (unsigned int i = 0; i < num; i++)
{
if (list[i].num == 0) continue;
memset(buf, 0, sizeof(buf));
sprintf(buf, "%s %c ", types[list[i].type], list[i].enabled?'1':'0');
for (int t = 0; t < list[i].num; t++)
{
char buf2[10] = { 0 };
sprintf(buf2, "%08X", list[i].hi[t]);
strcat(buf, buf2);
sprintf(buf2, "%08X", list[i].lo[t]);
strcat(buf, buf2);
if (t < (list[i].num - 1))
strcat(buf, ",");
}
strcat(buf, " ;");
strcat(buf, trim(list[i].description));
fprintf(flist, "%s\n", buf);
}
fputs("\n", flist);
fclose(flist);
return true;
}
return false;
}
//==================================================================================== Loads
bool load_1_0(char *fname)
{
#ifdef WIN32
char buf[200] = {0};
num = GetPrivateProfileInt("General", "NumberOfCheats", 0, fname);
if (num == 0) return false;
if (num > MAX_CHEAT_LIST) num = MAX_CHEAT_LIST;
for (unsigned int i = 0; i < num; i++)
{
wsprintf(buf, "Desc%04i", i);
GetPrivateProfileString("Cheats", buf, "", list[i].description, 75, fname);
wsprintf(buf, "Type%04i", i);
list[i].type = GetPrivateProfileInt("Cheats", buf, 0xFF, fname);
wsprintf(buf, "Num_%04i", i);
list[i].num = GetPrivateProfileInt("Cheats", buf, 0, fname);
wsprintf(buf, "Enab%04i", i);
list[i].enabled = GetPrivateProfileInt("Cheats", buf, 0, fname)==1?true:false;
wsprintf(buf, "Size%04i", i);
list[i].size = GetPrivateProfileInt("Cheats", buf, 0, fname);
for (int t = 0; t < list[i].num; t++)
{
char tmp_buf[10] = { 0 };
wsprintf(buf, "H%03i%04i", i, t);
GetPrivateProfileString("Cheats", buf, "0", tmp_buf, 10, fname);
sscanf_s(tmp_buf, "%x", &list[i].hi[t]);
wsprintf(buf, "L%03i%04i", i, t);
list[i].lo[t] = GetPrivateProfileInt("Cheats", buf, 0, fname);
}
}
#endif
return true;
}
bool load_1_3(char *fname)
{
FILE *fcheat = fopen(fname, "r");
char buf[4096] = {0};
int last=0;
if (fcheat)
{
cheatsClear();
memset(buf, 0, sizeof(buf));
while (!feof(fcheat))
{
fgets(buf, sizeof(buf), fcheat);
if (buf[0] == ';') continue;
strcpy(buf, trim(buf));
if (strlen(buf) == 0) continue;
if ( (buf[0] == 'D') &&
(buf[1] == 'e') &&
(buf[2] == 's') &&
(buf[3] == 'c') &&
(buf[4] == '=') ) // new cheat block
{
strncpy((char *)list[last].description, (char *)buf+5, strlen(buf)-5);
fgets(buf, sizeof(buf), fcheat);
if ( (buf[0] == 'I') &&
(buf[1] == 'n') &&
(buf[2] == 'f') &&
(buf[3] == 'o') &&
(buf[4] == '=') ) // Info cheat
{
u32 dstart = 5;
u32 dsize = 0;
char bf[4] = { 0 };
while ( (buf[dstart+dsize] != ',') && (buf[dstart+dsize]!=0)) { dsize++; };
if (buf[dstart+dsize]==0) continue; // error
strncpy(bf, (char*)buf+dstart, dsize);
list[last].type=atoi(bf);
dstart += (dsize+1); dsize=0;
while ( (buf[dstart+dsize] != ',') && (buf[dstart+dsize]!=0)) { dsize++; };
if (buf[dstart+dsize]==0) continue; // error
strncpy(bf, (char*)buf+dstart, dsize);
dstart += (dsize+1); dsize=0;
list[last].num=atoi(bf);
while ( (buf[dstart+dsize] != ',') && (buf[dstart+dsize]!=0)) { dsize++; };
if (buf[dstart+dsize]==0) continue; // error
strncpy(bf, (char*)(buf+dstart), dsize);
dstart += (dsize+1); dsize=0;
list[last].enabled=atoi(bf)==1?true:false;
while ( (buf[dstart+dsize] != ',') && (buf[dstart+dsize]!=0)) { dsize++; };
strncpy(bf, (char*)buf+dstart, dsize);
list[last].size=atoi(bf);
fgets(buf, sizeof(buf), fcheat);
if ( (buf[0] == 'D') &&
(buf[1] == 'a') &&
(buf[2] == 't') &&
(buf[3] == 'a') &&
(buf[4] == '=') ) // Data cheat
{
int offs = 5;
char tmp_buf[9];
memset(tmp_buf, 0, 9);
for (int j=0; j<list[last].num; j++)
{
strncpy(tmp_buf, (char *)buf+offs, 8);
sscanf_s(tmp_buf, "%x", &list[last].hi[j]);
offs+=8;
strncpy(tmp_buf, (char *)buf+offs, 8);
sscanf_s(tmp_buf, "%x", &list[last].lo[j]);
offs+=8;
if (buf[offs] != ',') continue; //error
offs++; // skip comma
}
}
else
continue; // error
}
else
continue; // error
last++;
} // else parser error
}
fclose(fcheat);
//INFO("Loaded %i cheats\n", last);
num = last;
return true;
}
return false;
}
bool getVersion(char *fname, u8 &major, u8 &minor)
{
FILE *fp = fopen(fname, "r");
major = 0;
minor = 0;
memset(ROMserial, 0, sizeof(ROMserial));
if (fp)
{
char buf[1024] = { 0 };
fgets(buf, 1024, fp);
strcpy(buf, trim(buf));
if (strlen(buf) == 0)
{
fclose(fp);
return false;
}
if (strncmp(buf, "; DeSmuME cheat file. VERSION ", 29) == 0)
{
char bf[10] = {0};
strncpy(bf, (char*)(buf + 30), 1);
major = atoi(bf);
strncpy(bf, (char*)(buf + 32), 3);
minor = atoi(bf);
while (!feof(fp))
{
fgets(buf, 1024, fp);
strcpy(buf, trim(buf));
if ( (buf[0] == 'N') &&
(buf[1] == 'a') &&
(buf[2] == 'm') &&
(buf[3] == 'e') &&
(buf[4] == '=') ) // serial
{
strcpy(ROMserial, (char *)(buf+5));
break;
}
}
fclose(fp);
return true;
}
if (strncmp(buf, "[General]", 9) == 0)
{
major = 1; minor = 0;
fclose(fp);
return true;
}
fclose(fp);
}
return false;
}
bool convertFile(char *fname)
{
u8 majorVersion = 0;
u8 minorVersion = 0;
if (!getVersion(fname, majorVersion, minorVersion))
return false;
//printf(" - version %i.%03i - ", majorVersion, minorVersion);
switch(majorVersion)
{
case 1:
switch (minorVersion)
{
case 0:
{
if (!load_1_0(fname)) return false;
if (!save(fname)) return false;
return true;
}
case 3:
{
if (!load_1_3(fname)) return false;
if (!save(fname)) return false;
return true;
}
default:
return false;
}
break;
case 2:
return false;
}
return false;
}

View File

@ -0,0 +1,48 @@
/* Cheats converter
Copyright 2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __CONVERT_H__
#define __CONVERT_H__
#include "common.h"
#define CHEAT_VERSION_MAJOR 2
#define CHEAT_VERSION_MINOR 0
#define MAX_CHEAT_LIST 200
#define MAX_XX_CODE 512
typedef struct
{
u8 type; // 0 - internal cheat system
// 1 - Action Replay
// 2 - Codebreakers
bool enabled;
u32 code[MAX_XX_CODE][2];
u32 hi[MAX_XX_CODE];
u32 lo[MAX_XX_CODE];
char description[75];
int num;
u8 size;
} CHEATS_LIST;
extern bool convertFile(char *fname);
#endif

View File

@ -0,0 +1,91 @@
/* Cheats converter
Copyright 2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// first release: 19/12/2009
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "common.h"
#include "convert.h"
int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = NULL;
u32 count = 0;
char buf[MAX_PATH] = {0};
SetConsoleCP(GetACP());
SetConsoleOutputCP(GetACP());
printf("DeSmuME cheats file converter\n");
printf("Copyright (C) 2009 by DeSmuME Team\n");
printf("Version 0.1\n");
printf("\n");
printf("All files (.cht) of deception in a current directory will be renamed\n");
printf("Are you sure?");
int ch = 0;
do
{
ch = getch();
if ((ch == 'N') || (ch == 'n'))
{
printf(" no\n\n");
return 2;
}
} while ((ch != 'Y') && (ch != 'y'));
printf(" yes\n");
printf("\n");
hFind = FindFirstFile("*.dct", &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
printf("%s\n", error());
return 1;
}
do
{
if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
if (strncmp(FindFileData.cFileName + (strlen(FindFileData.cFileName) - 4), ".dct", 4) != 0)
continue;
printf("%s", FindFileData.cFileName);
sprintf(buf, ".\\%s", FindFileData.cFileName);
if (convertFile(buf))
{
printf(" - Ok\n");
count++;
}
else
printf(" - Failed\n");
}
} while (FindNextFile(hFind, &FindFileData));
FindClose(hFind);
printf("\nConverted %i files\n\n", count);
printf("Done\n\n");
return 0;
}