From 51303b9bc9a9cda4177e0354b06e385c599f7adc Mon Sep 17 00:00:00 2001 From: SuuperW Date: Fri, 24 Aug 2018 12:11:08 -0500 Subject: [PATCH 1/8] (Windows) Extend last column of Cheats list to fully show max-length descriptions, and shorten window/list view width. (Requested by #178) --- desmume/src/frontend/windows/cheatsWin.cpp | 2 +- desmume/src/frontend/windows/resources.rc | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/desmume/src/frontend/windows/cheatsWin.cpp b/desmume/src/frontend/windows/cheatsWin.cpp index 9b9f43f79..48e492558 100644 --- a/desmume/src/frontend/windows/cheatsWin.cpp +++ b/desmume/src/frontend/windows/cheatsWin.cpp @@ -700,7 +700,7 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l lvColumn.cx=100; lvColumn.pszText="Value"; ListView_InsertColumn(cheatListView, 2, &lvColumn); - lvColumn.cx=245; + lvColumn.cx=467; lvColumn.pszText="Description"; ListView_InsertColumn(cheatListView, 3, &lvColumn); lvColumn.fmt=LVCFMT_CENTER; diff --git a/desmume/src/frontend/windows/resources.rc b/desmume/src/frontend/windows/resources.rc index 93ba06942..9626ed4f6 100644 --- a/desmume/src/frontend/windows/resources.rc +++ b/desmume/src/frontend/windows/resources.rc @@ -202,12 +202,12 @@ BEGIN LTEXT "Description:",-1,9,116,39,8 END -IDD_CHEAT_LIST DIALOGEX 0, 0, 499, 285 +IDD_CHEAT_LIST DIALOGEX 0, 0, 461, 285 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Cheats list" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,7,488,218 + CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,7,450,218 PUSHBUTTON "internal",IDC_BADD,10,240,50,14 PUSHBUTTON "Action Replay",IDC_BADD_AR,66,240,67,14 PUSHBUTTON "Codebreaker",IDC_BADD_CB,139,240,67,14,WS_DISABLED @@ -1873,7 +1873,6 @@ BEGIN IDD_CHEAT_LIST, DIALOG BEGIN - RIGHTMARGIN, 495 BOTTOMMARGIN, 277 END From 084a42a2f8ffaa0382c3ebbd70ea01ff6aa763cb Mon Sep 17 00:00:00 2001 From: SuuperW Date: Fri, 24 Aug 2018 12:37:02 -0500 Subject: [PATCH 2/8] (Windows) Ask the user if they want to save changes to the Cheat list when the dialog's close/X button is clicked, if there are changes to save. --- desmume/src/frontend/windows/cheatsWin.cpp | 28 ++++++++++++++++++---- desmume/src/frontend/windows/resources.rc | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/desmume/src/frontend/windows/cheatsWin.cpp b/desmume/src/frontend/windows/cheatsWin.cpp index 48e492558..2b323c53f 100644 --- a/desmume/src/frontend/windows/cheatsWin.cpp +++ b/desmume/src/frontend/windows/cheatsWin.cpp @@ -670,6 +670,13 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp return FALSE; } //============================================================================== +void AttemptSaveAndClose(HWND dialog) +{ + if (cheats->save()) + EndDialog(dialog, TRUE); + else + MessageBox(dialog, "Can't save cheats to file.\nCheck your path (Menu->Config->Path Settings->\"Cheats\")", "Error", MB_OK); +} INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam) { switch(msg) @@ -823,12 +830,25 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l switch (LOWORD(wparam)) { case IDOK: - if (cheats->save()) - EndDialog(dialog, TRUE); - else - MessageBox(dialog, "Can't save cheats to file.\nCheck your path (Menu->Config->Path Settings->\"Cheats\")","Error",MB_OK); + AttemptSaveAndClose(dialog); return TRUE; + case IDCANCEL: + { + if (IsWindowEnabled(GetDlgItem(dialog, IDOK))) + { + int result = MessageBox(dialog, "Do you wish to save your changes?", "Save?", MB_YESNOCANCEL); + if (result == IDYES) + AttemptSaveAndClose(dialog); + else if (result == IDNO) + EndDialog(dialog, FALSE); + } + else + EndDialog(dialog, FALSE); + } + return TRUE; + + case IDCLOSE: EndDialog(dialog, FALSE); return TRUE; diff --git a/desmume/src/frontend/windows/resources.rc b/desmume/src/frontend/windows/resources.rc index 9626ed4f6..ca2e5172a 100644 --- a/desmume/src/frontend/windows/resources.rc +++ b/desmume/src/frontend/windows/resources.rc @@ -214,7 +214,7 @@ BEGIN PUSHBUTTON "Edit",IDC_BEDIT,245,228,64,14,WS_DISABLED PUSHBUTTON "Remove",IDC_BREMOVE,246,244,63,14,WS_DISABLED DEFPUSHBUTTON "Save",IDOK,109,263,50,14,WS_DISABLED - PUSHBUTTON "Cancel",IDCANCEL,163,263,50,14 + PUSHBUTTON "Cancel",IDCLOSE,163,263,50,14 GROUPBOX " Add cheats code as... ",IDC_STATIC,7,230,205,31 PUSHBUTTON "Cheats Database",IDC_EXPORT,246,263,63,14 END From 24cdbf0269447641f80b393d3da022c18348bdce Mon Sep 17 00:00:00 2001 From: SuuperW Date: Sat, 25 Aug 2018 09:52:49 -0500 Subject: [PATCH 3/8] (Windows) Allow rearranging of cheats in the cheat list. (Requested by #178) --- desmume/src/cheatSystem.cpp | 13 ++++ desmume/src/cheatSystem.h | 1 + desmume/src/frontend/windows/cheatsWin.cpp | 89 ++++++++++++++++++++++ 3 files changed, 103 insertions(+) diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index 9ba400437..cf1d8ba6e 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -73,6 +73,19 @@ BOOL CHEATS::update(u8 size, u32 address, u32 val, char *description, BOOL enabl return TRUE; } +BOOL CHEATS::move(u32 srcPos, u32 dstPos) +{ + if (srcPos >= list.size() || dstPos > list.size()) return false; + if (srcPos < 0 || dstPos < 0) return false; + + CHEATS_LIST srcCheat = list[srcPos]; + list.insert(list._Make_iterator_offset(dstPos), srcCheat); + if (dstPos < srcPos) srcPos++; + remove(srcPos); + + return true; +} + #define CHEATLOG(...) //#define CHEATLOG(...) printf(__VA_ARGS__) diff --git a/desmume/src/cheatSystem.h b/desmume/src/cheatSystem.h index 1cccd5410..502be154e 100644 --- a/desmume/src/cheatSystem.h +++ b/desmume/src/cheatSystem.h @@ -75,6 +75,7 @@ public: 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 move(u32 srcPos, u32 dstPos); BOOL add_AR(char *code, char *description, BOOL enabled); BOOL update_AR(char *code, char *description, BOOL enabled, u32 pos); BOOL add_AR_Direct(CHEATS_LIST cheat); diff --git a/desmume/src/frontend/windows/cheatsWin.cpp b/desmume/src/frontend/windows/cheatsWin.cpp index 2b323c53f..416a4b75a 100644 --- a/desmume/src/frontend/windows/cheatsWin.cpp +++ b/desmume/src/frontend/windows/cheatsWin.cpp @@ -56,6 +56,8 @@ static u32 cheatEditPos = 0; static u8 cheatAddPasteCheck = 0; static u8 cheatXXtype = 0; static u8 cheatXXaction = 0; +static s32 draggedItem = -1; +static s32 highlightedItem = -1; static HWND searchWnd = NULL; static HWND searchListView = NULL; @@ -677,6 +679,39 @@ void AttemptSaveAndClose(HWND dialog) else MessageBox(dialog, "Can't save cheats to file.\nCheck your path (Menu->Config->Path Settings->\"Cheats\")", "Error", MB_OK); } +void MoveRow(HWND list, int src, int dst) +{ + // move the cheat + if (!cheats->move(src, dst)) + return; + + // insert new row + LVITEM item; + memset(&item, 0, sizeof(LVITEM)); + item.mask = LVIF_TEXT | LVIF_STATE; + item.iItem = dst; + ListView_InsertItem(cheatListView, &item); + if (dst < src) src++; + + // get and set each subitem + item.iItem = src; + char* buf = new char[256]; + item.pszText = buf; + item.cchTextMax = 256; + item.mask = LVIF_TEXT; + for (int i = 1; i < 4; i++) + { + item.iSubItem = i; + ListView_GetItem(cheatListView, &item); + ListView_SetItemText(cheatListView, dst, i, item.pszText); + } + + // set check state + ListView_SetCheckState(cheatListView, dst, ListView_GetCheckState(cheatListView, src)); + + // delete the original item + ListView_DeleteItem(cheatListView, src); +} INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam) { switch(msg) @@ -819,12 +854,66 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l } } break; + + case LVN_BEGINDRAG: + { + draggedItem = ListView_GetSelectionMark(cheatListView); + SetCapture(dialog); // This sends all mouse messages to the dialog. + } + break; } return TRUE; } return FALSE; + case WM_MOUSEMOVE: + { + if (draggedItem != -1) + { + // un-highlight any previously highlighted item + if (highlightedItem != -1) + ListView_SetItemState(cheatListView, highlightedItem, 0, LVIS_DROPHILITED); + + // get location of the cursor, relative to the list view + RECT r; + GetWindowRect(GetDlgItem(dialog, IDC_LIST1), &r); + POINT p = { r.left, r.top }; + ScreenToClient(dialog, &p); + + LVHITTESTINFO hitTestInfo; + hitTestInfo.pt.x = LOWORD(lparam) - p.x; + hitTestInfo.pt.y = HIWORD(lparam) - p.y; + + // find the item under the cursor and highlight it + ListView_HitTest(cheatListView, &hitTestInfo); + if (hitTestInfo.iItem != -1) + ListView_SetItemState(cheatListView, hitTestInfo.iItem, LVIS_DROPHILITED, LVIS_DROPHILITED); + highlightedItem = hitTestInfo.iItem; + } + } + break; + + case WM_LBUTTONUP: + { + if (highlightedItem != -1) + ListView_SetItemState(cheatListView, highlightedItem, 0, LVIS_DROPHILITED); + + if (draggedItem != -1) + { + if (highlightedItem != -1 && highlightedItem != draggedItem) + { + if (highlightedItem > draggedItem) + highlightedItem++; // if dragging an item down, item should be placed below highlighted item (required to move an item to the bottom) + MoveRow(cheatListView, draggedItem, highlightedItem); + EnableWindow(GetDlgItem(dialog, IDOK), TRUE); + } + } + draggedItem = -1; + ReleaseCapture(); + } + break; + case WM_COMMAND: { switch (LOWORD(wparam)) From 534cf2515baf671deb70ce13e9fb41dfe46a9e3d Mon Sep 17 00:00:00 2001 From: SuuperW Date: Sat, 25 Aug 2018 10:56:27 -0500 Subject: [PATCH 4/8] (Windows) Allow un/checking multiple cheats at once. (#178) --- desmume/src/frontend/windows/cheatsWin.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/desmume/src/frontend/windows/cheatsWin.cpp b/desmume/src/frontend/windows/cheatsWin.cpp index 416a4b75a..bd4c8ddf9 100644 --- a/desmume/src/frontend/windows/cheatsWin.cpp +++ b/desmume/src/frontend/windows/cheatsWin.cpp @@ -58,6 +58,7 @@ static u8 cheatXXtype = 0; static u8 cheatXXaction = 0; static s32 draggedItem = -1; static s32 highlightedItem = -1; +static bool multiCheck = false; static HWND searchWnd = NULL; static HWND searchListView = NULL; @@ -852,6 +853,21 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l EnableWindow(GetDlgItem(dialog, IDOK), TRUE); } } + + // check all other selected items too + if (!multiCheck) + { + multiCheck = true; + bool check = ListView_GetCheckState(cheatListView, cheatEditPos); + int index = ListView_GetNextItem(cheatListView, -1, LVNI_SELECTED); + while (index != -1) + { + if (index != cheatEditPos) + ListView_SetCheckState(cheatListView, index, check); + index = ListView_GetNextItem(cheatListView, index, LVNI_SELECTED); + } + multiCheck = false; + } } break; From 38b203984426ccdce575a23da38abe38bb7af903 Mon Sep 17 00:00:00 2001 From: SuuperW Date: Sat, 25 Aug 2018 11:12:09 -0500 Subject: [PATCH 5/8] (Windows) Implement Ctrl+A shortcut for cheat list. --- desmume/src/frontend/windows/cheatsWin.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/desmume/src/frontend/windows/cheatsWin.cpp b/desmume/src/frontend/windows/cheatsWin.cpp index bd4c8ddf9..84bcd09a8 100644 --- a/desmume/src/frontend/windows/cheatsWin.cpp +++ b/desmume/src/frontend/windows/cheatsWin.cpp @@ -806,8 +806,8 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l case WM_NOTIFY: if (wparam == IDC_LIST1) { - LPNMHDR tmp_msg = (LPNMHDR)lparam; - switch (tmp_msg->code) + tagLVKEYDOWN* tmp_msg = (tagLVKEYDOWN*)lparam; + switch (tmp_msg->hdr.code) { case LVN_ITEMACTIVATE: SendMessage(dialog, WM_COMMAND, IDC_BEDIT, 0); @@ -877,6 +877,16 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l SetCapture(dialog); // This sends all mouse messages to the dialog. } break; + + case LVN_KEYDOWN: + { + if (tmp_msg->wVKey == 0x41) // A key + { + if (GetKeyState(VK_CONTROL) & 0x7000) + ListView_SetItemState(cheatListView, -1, LVNI_SELECTED, LVNI_SELECTED); + } + } + break; } return TRUE; From bbb190a1368b22d87e2df268014ca10930efcb8b Mon Sep 17 00:00:00 2001 From: SuuperW Date: Sat, 25 Aug 2018 11:15:56 -0500 Subject: [PATCH 6/8] bugfix (from commit 534cf251) --- desmume/src/frontend/windows/cheatsWin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desmume/src/frontend/windows/cheatsWin.cpp b/desmume/src/frontend/windows/cheatsWin.cpp index 84bcd09a8..fa9bbdb5d 100644 --- a/desmume/src/frontend/windows/cheatsWin.cpp +++ b/desmume/src/frontend/windows/cheatsWin.cpp @@ -855,7 +855,7 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l } // check all other selected items too - if (!multiCheck) + if (!multiCheck && ListView_GetItemState(cheatListView, cheatEditPos, LVNI_SELECTED)) { multiCheck = true; bool check = ListView_GetCheckState(cheatListView, cheatEditPos); From dee24cdbc1ceda178b19b22bb245faef2d8c78a4 Mon Sep 17 00:00:00 2001 From: SuuperW Date: Sat, 25 Aug 2018 11:29:54 -0500 Subject: [PATCH 7/8] Print a message when a cheat code forces the JIT to reset. --- desmume/src/cheatSystem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index cf1d8ba6e..f6f769b05 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -1034,7 +1034,10 @@ void CHEATS::process(int targetType) if(cheatsResetJit) { if(CommonSettings.use_jit) - arm_jit_reset(true,true); + { + printf("Cheat code operation potentially not compatible with JIT operations. Resetting JIT...\n"); + arm_jit_reset(true, true); + } } #endif } From 57bfbb156268c93774feb7282bb17f77b16acfe2 Mon Sep 17 00:00:00 2001 From: SuuperW Date: Sat, 25 Aug 2018 16:05:04 -0500 Subject: [PATCH 8/8] Change implementation of moving a cheat in the cheat list. (originally implemented in commit 24cdbf0) --- desmume/src/cheatSystem.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index f6f769b05..a554d6d50 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -78,10 +78,13 @@ BOOL CHEATS::move(u32 srcPos, u32 dstPos) if (srcPos >= list.size() || dstPos > list.size()) return false; if (srcPos < 0 || dstPos < 0) return false; + // get the item to move CHEATS_LIST srcCheat = list[srcPos]; - list.insert(list._Make_iterator_offset(dstPos), srcCheat); + // insert item in the new position + list.insert(list.begin() + dstPos, srcCheat); + // remove the original item if (dstPos < srcPos) srcPos++; - remove(srcPos); + list.erase(list.begin() + srcPos); return true; }