annotate src/win32/GBCheatsDlg.cpp @ 2:3549bbe597ed

adding makefile.am
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:47 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 // GBCheats.cpp : implementation file
rlm@1 2 //
rlm@1 3
rlm@1 4 #include "stdafx.h"
rlm@1 5 #include "resource.h"
rlm@1 6 #include "GBCheatsDlg.h"
rlm@1 7 #include "Reg.h"
rlm@1 8 #include "StringTokenizer.h"
rlm@1 9 #include "WinResUtil.h"
rlm@1 10 #include "Sound.h"
rlm@1 11 #include "VBA.h"
rlm@1 12
rlm@1 13 #include "../common/CheatSearch.h"
rlm@1 14 #include "../gb/gbCheats.h"
rlm@1 15 #include "../gb/gbGlobals.h"
rlm@1 16
rlm@1 17 static inline bool winGbCheatAddVerifyGs(const char *code, const char *desc)
rlm@1 18 {
rlm@1 19 gbAddGsCheat(code, desc);
rlm@1 20 return true;
rlm@1 21 }
rlm@1 22
rlm@1 23 static inline bool winGbCheatAddVerifyGg(const char *code, const char *desc)
rlm@1 24 {
rlm@1 25 gbAddGgCheat(code, desc);
rlm@1 26 return true;
rlm@1 27 }
rlm@1 28
rlm@1 29 ////////////////////////////////
rlm@1 30
rlm@1 31 bool winGbCheatReaddress()
rlm@1 32 {
rlm@1 33 if (cheatSearchData.count != 3)
rlm@1 34 return false;
rlm@1 35
rlm@1 36 CheatSearchBlock *block = &cheatSearchData.blocks[0];
rlm@1 37 if (gbRamSize > 0)
rlm@1 38 {
rlm@1 39 if (gbRam)
rlm@1 40 block->data = gbRam;
rlm@1 41 else
rlm@1 42 block->data = &gbMemory[0xa000];
rlm@1 43 block->offset = 0xa000;
rlm@1 44 block->size = gbRamSize;
rlm@1 45 cheatSearchSetSavedAndBits(block);
rlm@1 46 }
rlm@1 47 else
rlm@1 48 {
rlm@1 49 cheatSearchZeroBlock(&cheatSearchData.blocks[0]);
rlm@1 50 }
rlm@1 51
rlm@1 52 block = &cheatSearchData.blocks[1];
rlm@1 53 if (gbCgbMode)
rlm@1 54 {
rlm@1 55 block->data = &gbMemory[0xc000];
rlm@1 56 block->offset = 0xc000;
rlm@1 57 block->size = 0x1000;
rlm@1 58 cheatSearchSetSavedAndBits(block);
rlm@1 59
rlm@1 60 block = &cheatSearchData.blocks[2];
rlm@1 61 block->data = gbWram;
rlm@1 62 block->offset = 0xd000;
rlm@1 63 block->size = 0x8000;
rlm@1 64 cheatSearchSetSavedAndBits(block);
rlm@1 65 }
rlm@1 66 else
rlm@1 67 {
rlm@1 68 block->data = &gbMemory[0xc000];
rlm@1 69 block->offset = 0xc000;
rlm@1 70 block->size = 0x2000;
rlm@1 71 cheatSearchSetSavedAndBits(block);
rlm@1 72
rlm@1 73 cheatSearchZeroBlock(&cheatSearchData.blocks[2]);
rlm@1 74 }
rlm@1 75
rlm@1 76 cheatSearchData.count = 3;
rlm@1 77 return true;
rlm@1 78 }
rlm@1 79
rlm@1 80 /////////////////////////////////////////////////////////////////////////////
rlm@1 81 // GBCheatSearch dialog
rlm@1 82
rlm@1 83 GBCheatSearch::GBCheatSearch(CWnd*pParent /*=NULL*/)
rlm@1 84 : CDialog(GBCheatSearch::IDD, pParent)
rlm@1 85 {
rlm@1 86 //{{AFX_DATA_INIT(GBCheatSearch)
rlm@1 87 searchType = -1;
rlm@1 88 numberType = -1;
rlm@1 89 sizeType = -1;
rlm@1 90 updateValues = FALSE;
rlm@1 91 valueType = -1;
rlm@1 92 //}}AFX_DATA_INIT
rlm@1 93 data = NULL;
rlm@1 94 }
rlm@1 95
rlm@1 96 GBCheatSearch::~GBCheatSearch()
rlm@1 97 {
rlm@1 98 if (data)
rlm@1 99 free(data);
rlm@1 100 }
rlm@1 101
rlm@1 102 void GBCheatSearch::DoDataExchange(CDataExchange*pDX)
rlm@1 103 {
rlm@1 104 CDialog::DoDataExchange(pDX);
rlm@1 105 //{{AFX_DATA_MAP(GBCheatSearch)
rlm@1 106 DDX_Control(pDX, IDC_VALUE, m_value);
rlm@1 107 DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
rlm@1 108 DDX_Radio(pDX, IDC_EQ, searchType);
rlm@1 109 DDX_Radio(pDX, IDC_SIGNED, numberType);
rlm@1 110 DDX_Radio(pDX, IDC_SIZE_8, sizeType);
rlm@1 111 DDX_Check(pDX, IDC_UPDATE, updateValues);
rlm@1 112 DDX_Radio(pDX, IDC_OLD_VALUE, valueType);
rlm@1 113 //}}AFX_DATA_MAP
rlm@1 114 }
rlm@1 115
rlm@1 116 BEGIN_MESSAGE_MAP(GBCheatSearch, CDialog)
rlm@1 117 //{{AFX_MSG_MAP(GBCheatSearch)
rlm@1 118 ON_BN_CLICKED(ID_OK, OnOk)
rlm@1 119 ON_BN_CLICKED(IDC_ADD_CHEAT, OnAddCheat)
rlm@1 120 ON_BN_CLICKED(IDC_SEARCH, OnSearch)
rlm@1 121 ON_BN_CLICKED(IDC_START, OnStart)
rlm@1 122 ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
rlm@1 123 ON_NOTIFY(LVN_GETDISPINFO, IDC_CHEAT_LIST, OnGetdispinfoCheatList)
rlm@1 124 ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
rlm@1 125 ON_CONTROL_RANGE(BN_CLICKED, IDC_OLD_VALUE, IDC_SPECIFIC_VALUE, OnValueType)
rlm@1 126 ON_CONTROL_RANGE(BN_CLICKED, IDC_EQ, IDC_GE, OnSearchType)
rlm@1 127 ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
rlm@1 128 ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
rlm@1 129 //}}AFX_MSG_MAP
rlm@1 130 ON_WM_CLOSE()
rlm@1 131 ON_BN_CLICKED(IDC_CHEATREFRESHBUTTON, OnBnClickedCheatrefreshbutton)
rlm@1 132 END_MESSAGE_MAP()
rlm@1 133
rlm@1 134 /////////////////////////////////////////////////////////////////////////////
rlm@1 135 // GBCheatSearch message handlers
rlm@1 136
rlm@1 137 void GBCheatSearch::OnOk()
rlm@1 138 {
rlm@1 139 if (data)
rlm@1 140 free(data);
rlm@1 141 data = NULL;
rlm@1 142
rlm@1 143 if (theApp.modelessCheatDialogIsOpen)
rlm@1 144 {
rlm@1 145 theApp.modelessCheatDialogIsOpen = false;
rlm@1 146 DestroyWindow();
rlm@1 147 }
rlm@1 148 else
rlm@1 149 {
rlm@1 150 EndDialog(TRUE);
rlm@1 151 }
rlm@1 152 }
rlm@1 153
rlm@1 154 void GBCheatSearch::OnClose()
rlm@1 155 {
rlm@1 156 CDialog::OnClose();
rlm@1 157 if (theApp.modelessCheatDialogIsOpen)
rlm@1 158 {
rlm@1 159 theApp.modelessCheatDialogIsOpen = false;
rlm@1 160 DestroyWindow();
rlm@1 161 }
rlm@1 162 else
rlm@1 163 {
rlm@1 164 EndDialog(FALSE);
rlm@1 165 }
rlm@1 166 }
rlm@1 167
rlm@1 168 void GBCheatSearch::OnBnClickedCheatrefreshbutton()
rlm@1 169 {
rlm@1 170 addChanges(false);
rlm@1 171 }
rlm@1 172
rlm@1 173 void GBCheatSearch::OnAddCheat()
rlm@1 174 {
rlm@1 175 int mark = m_list.GetSelectionMark();
rlm@1 176
rlm@1 177 if (mark != -1)
rlm@1 178 {
rlm@1 179 LVITEM item;
rlm@1 180 memset(&item, 0, sizeof(item));
rlm@1 181 item.mask = LVIF_PARAM;
rlm@1 182 item.iItem = mark;
rlm@1 183 if (m_list.GetItem(&item))
rlm@1 184 {
rlm@1 185 AddGBCheat dlg((u32)item.lParam);
rlm@1 186 dlg.DoModal();
rlm@1 187 }
rlm@1 188 }
rlm@1 189 }
rlm@1 190
rlm@1 191 void GBCheatSearch::OnSearch()
rlm@1 192 {
rlm@1 193 CString buffer;
rlm@1 194 if (valueType == 0)
rlm@1 195 cheatSearch(&cheatSearchData,
rlm@1 196 searchType,
rlm@1 197 sizeType,
rlm@1 198 numberType == 0);
rlm@1 199 else
rlm@1 200 {
rlm@1 201 m_value.GetWindowText(buffer);
rlm@1 202 if (buffer.IsEmpty())
rlm@1 203 {
rlm@1 204 systemMessage(IDS_NUMBER_CANNOT_BE_EMPTY, "Number cannot be empty");
rlm@1 205 return;
rlm@1 206 }
rlm@1 207 int value = 0;
rlm@1 208 switch (numberType)
rlm@1 209 {
rlm@1 210 case 0:
rlm@1 211 sscanf(buffer, "%d", &value);
rlm@1 212 break;
rlm@1 213 case 1:
rlm@1 214 sscanf(buffer, "%u", &value);
rlm@1 215 break;
rlm@1 216 default:
rlm@1 217 sscanf(buffer, "%x", &value);
rlm@1 218 }
rlm@1 219 cheatSearchValue(&cheatSearchData,
rlm@1 220 searchType,
rlm@1 221 sizeType,
rlm@1 222 numberType == 0,
rlm@1 223 value);
rlm@1 224 }
rlm@1 225
rlm@1 226 addChanges(true);
rlm@1 227
rlm@1 228 if (updateValues)
rlm@1 229 cheatSearchUpdateValues(&cheatSearchData);
rlm@1 230
rlm@1 231 if (theApp.modelessCheatDialogIsOpen)
rlm@1 232 GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData, sizeType) == 0 ? FALSE : TRUE);
rlm@1 233
rlm@1 234 if (0 == cheatSearchGetCount(&cheatSearchData, sizeType))
rlm@1 235 OnStart();
rlm@1 236 }
rlm@1 237
rlm@1 238 void GBCheatSearch::OnStart()
rlm@1 239 {
rlm@1 240 if (cheatSearchData.count == 0)
rlm@1 241 {
rlm@1 242 CheatSearchBlock *block = &cheatSearchData.blocks[0];
rlm@1 243 if (gbRamSize > 0)
rlm@1 244 {
rlm@1 245 if (gbRam)
rlm@1 246 block->data = gbRam;
rlm@1 247 else
rlm@1 248 block->data = &gbMemory[0xa000];
rlm@1 249 block->size = gbRamSize;
rlm@1 250 block->offset = 0xa000;
rlm@1 251 block->saved = (u8 *)malloc(gbRamSize);
rlm@1 252 block->bits = (u8 *)malloc(gbRamSize >> 3);
rlm@1 253 }
rlm@1 254 else
rlm@1 255 {
rlm@1 256 cheatSearchZeroBlock(&cheatSearchData.blocks[0]);
rlm@1 257 }
rlm@1 258
rlm@1 259 block = &cheatSearchData.blocks[1];
rlm@1 260 if (gbCgbMode)
rlm@1 261 {
rlm@1 262 block->data = &gbMemory[0xc000];
rlm@1 263 block->size = 0x1000;
rlm@1 264 block->offset = 0xc000;
rlm@1 265 block->saved = (u8 *)malloc(0x1000);
rlm@1 266 block->bits = (u8 *)malloc(0x1000 >> 3);
rlm@1 267
rlm@1 268 block = &cheatSearchData.blocks[2];
rlm@1 269 block->data = gbWram;
rlm@1 270 block->size = 0x8000;
rlm@1 271 block->offset = 0xd000;
rlm@1 272 block->saved = (u8 *)malloc(0x8000);
rlm@1 273 block->bits = (u8 *)malloc(0x8000 >> 3);
rlm@1 274 }
rlm@1 275 else
rlm@1 276 {
rlm@1 277 block->data = &gbMemory[0xc000];
rlm@1 278 block->size = 0x2000;
rlm@1 279 block->offset = 0xc000;
rlm@1 280 block->saved = (u8 *)malloc(0x2000);
rlm@1 281 block->bits = (u8 *)malloc(0x2000 >> 3);
rlm@1 282
rlm@1 283 cheatSearchZeroBlock(&cheatSearchData.blocks[2]);
rlm@1 284 }
rlm@1 285
rlm@1 286 cheatSearchData.count = 3;
rlm@1 287 }
rlm@1 288
rlm@1 289 cheatSearchStart(&cheatSearchData);
rlm@1 290 GetDlgItem(IDC_SEARCH)->EnableWindow(TRUE);
rlm@1 291
rlm@1 292 if (theApp.modelessCheatDialogIsOpen)
rlm@1 293 {
rlm@1 294 GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
rlm@1 295 GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
rlm@1 296 }
rlm@1 297 }
rlm@1 298
rlm@1 299 void GBCheatSearch::OnUpdate()
rlm@1 300 {
rlm@1 301 if (GetDlgItem(IDC_UPDATE)->SendMessage(BM_GETCHECK,
rlm@1 302 0,
rlm@1 303 0) & BST_CHECKED)
rlm@1 304 updateValues = true;
rlm@1 305 else
rlm@1 306 updateValues = false;
rlm@1 307 regSetDwordValue("gbCheatsUpdate", updateValues);
rlm@1 308 }
rlm@1 309
rlm@1 310 BOOL GBCheatSearch::OnInitDialog()
rlm@1 311 {
rlm@1 312 CDialog::OnInitDialog();
rlm@1 313
rlm@1 314 CString temp = winResLoadString(IDS_ADDRESS);
rlm@1 315
rlm@1 316 m_list.InsertColumn(0, temp, LVCFMT_CENTER, 125, 0);
rlm@1 317
rlm@1 318 temp = winResLoadString(IDS_OLD_VALUE);
rlm@1 319 m_list.InsertColumn(1, temp, LVCFMT_CENTER, 125, 1);
rlm@1 320
rlm@1 321 temp = winResLoadString(IDS_NEW_VALUE);
rlm@1 322 m_list.InsertColumn(2, temp, LVCFMT_CENTER, 125, 2);
rlm@1 323
rlm@1 324 m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
rlm@1 325 TRUE);
rlm@1 326
rlm@1 327 m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
rlm@1 328
rlm@1 329 if (!cheatSearchData.count)
rlm@1 330 {
rlm@1 331 GetDlgItem(IDC_SEARCH)->EnableWindow(FALSE);
rlm@1 332 GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(FALSE);
rlm@1 333 }
rlm@1 334
rlm@1 335 valueType = regQueryDwordValue("gbCheatsValueType", 0);
rlm@1 336 if (valueType < 0 || valueType > 1)
rlm@1 337 valueType = 2;
rlm@1 338
rlm@1 339 searchType = regQueryDwordValue("gbCheatsSearchType",
rlm@1 340 SEARCH_EQ);
rlm@1 341 if (searchType < 0 || searchType > 5)
rlm@1 342 searchType = 0;
rlm@1 343
rlm@1 344 numberType = regQueryDwordValue("gbCheatsNumberType", 2);
rlm@1 345 if (numberType < 0 || numberType > 2)
rlm@1 346 numberType = 2;
rlm@1 347
rlm@1 348 sizeType = regQueryDwordValue("gbCheatsSizeType", 0);
rlm@1 349 if (sizeType < 0 || sizeType > 2)
rlm@1 350 sizeType = 0;
rlm@1 351
rlm@1 352 updateValues = regQueryDwordValue("gbCheatsUpdate", 0) ?
rlm@1 353 true : false;
rlm@1 354
rlm@1 355 UpdateData(FALSE);
rlm@1 356
rlm@1 357 if (valueType == 0)
rlm@1 358 m_value.EnableWindow(FALSE);
rlm@1 359
rlm@1 360 CenterWindow();
rlm@1 361
rlm@1 362 if (theApp.modelessCheatDialogIsOpen)
rlm@1 363 GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
rlm@1 364
rlm@1 365 if (cheatSearchData.count)
rlm@1 366 {
rlm@1 367 addChanges(false);
rlm@1 368 if (theApp.modelessCheatDialogIsOpen)
rlm@1 369 GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData,
rlm@1 370 sizeType) == 0 ? FALSE : TRUE);
rlm@1 371 }
rlm@1 372 else
rlm@1 373 {
rlm@1 374 if (theApp.modelessCheatDialogIsOpen)
rlm@1 375 GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
rlm@1 376 }
rlm@1 377
rlm@1 378 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 379 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 380 }
rlm@1 381
rlm@1 382 void GBCheatSearch::OnGetdispinfoCheatList(NMHDR*pNMHDR, LRESULT*pResult)
rlm@1 383 {
rlm@1 384 LV_DISPINFO*info = (LV_DISPINFO *)pNMHDR;
rlm@1 385 if (info->item.mask & LVIF_TEXT)
rlm@1 386 {
rlm@1 387 int index = info->item.iItem;
rlm@1 388 int col = info->item.iSubItem;
rlm@1 389
rlm@1 390 switch (col)
rlm@1 391 {
rlm@1 392 case 0:
rlm@1 393 strcpy(info->item.pszText, data[index].address);
rlm@1 394 break;
rlm@1 395 case 1:
rlm@1 396 strcpy(info->item.pszText, data[index].oldValue);
rlm@1 397 break;
rlm@1 398 case 2:
rlm@1 399 strcpy(info->item.pszText, data[index].newValue);
rlm@1 400 break;
rlm@1 401 }
rlm@1 402 }
rlm@1 403 *pResult = TRUE;
rlm@1 404 }
rlm@1 405
rlm@1 406 void GBCheatSearch::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
rlm@1 407 {
rlm@1 408 GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(m_list.GetSelectionMark() != -1);
rlm@1 409 }
rlm@1 410
rlm@1 411 int GBCheatSearch::getBank(u16 addr, int j)
rlm@1 412 {
rlm@1 413 switch (addr >> 12)
rlm@1 414 {
rlm@1 415 case 0x0a:
rlm@1 416 return j / 0x2000;
rlm@1 417 case 0x0d:
rlm@1 418 return j / 0x1000;
rlm@1 419 }
rlm@1 420 return 0;
rlm@1 421 }
rlm@1 422
rlm@1 423 void GBCheatSearch::addChange(int index, int bank, u16 address, int offset, u32 oldValue, u32 newValue)
rlm@1 424 {
rlm@1 425 data[index].bank = bank;
rlm@1 426 if (bank)
rlm@1 427 {
rlm@1 428 if (address == 0xa000)
rlm@1 429 address |= offset & 0x1fff;
rlm@1 430 else
rlm@1 431 address |= offset & 0xfff;
rlm@1 432 }
rlm@1 433 else
rlm@1 434 address |= offset;
rlm@1 435 data[index].addr = address;
rlm@1 436 sprintf(data[index].address, "%02x:%04x", bank, address);
rlm@1 437 switch (numberType)
rlm@1 438 {
rlm@1 439 case 0:
rlm@1 440 sprintf(data[index].oldValue, "%d", oldValue);
rlm@1 441 sprintf(data[index].newValue, "%d", newValue);
rlm@1 442 break;
rlm@1 443 case 1:
rlm@1 444 sprintf(data[index].oldValue, "%u", oldValue);
rlm@1 445 sprintf(data[index].newValue, "%u", newValue);
rlm@1 446 break;
rlm@1 447 case 2:
rlm@1 448 switch (sizeType)
rlm@1 449 {
rlm@1 450 case 0:
rlm@1 451 sprintf(data[index].oldValue, "%02x", oldValue);
rlm@1 452 sprintf(data[index].newValue, "%02x", newValue);
rlm@1 453 break;
rlm@1 454 case 1:
rlm@1 455 sprintf(data[index].oldValue, "%04x", oldValue);
rlm@1 456 sprintf(data[index].newValue, "%04x", newValue);
rlm@1 457 break;
rlm@1 458 case 2:
rlm@1 459 sprintf(data[index].oldValue, "%08x", oldValue);
rlm@1 460 sprintf(data[index].newValue, "%08x", newValue);
rlm@1 461 break;
rlm@1 462 }
rlm@1 463 }
rlm@1 464 }
rlm@1 465
rlm@1 466 void GBCheatSearch::addChanges(bool showMsg)
rlm@1 467 {
rlm@1 468 int count = cheatSearchGetCount(&cheatSearchData, sizeType);
rlm@1 469
rlm@1 470 m_list.DeleteAllItems();
rlm@1 471
rlm@1 472 if (count > 4000)
rlm@1 473 {
rlm@1 474 if (showMsg)
rlm@1 475 systemMessage(
rlm@1 476 IDS_SEARCH_PRODUCED_TOO_MANY,
rlm@1 477 "Search produced %d results.\nThey have been remembered, but are too many to display.\nPlease refine it better by performing additional searches.",
rlm@1 478 count);
rlm@1 479 return;
rlm@1 480 }
rlm@1 481
rlm@1 482 if (count == 0)
rlm@1 483 {
rlm@1 484 if (showMsg)
rlm@1 485 systemMessage(IDS_SEARCH_PRODUCED_NO_RESULTS, "Search produced no results");
rlm@1 486 return;
rlm@1 487 }
rlm@1 488
rlm@1 489 m_list.SetItemCount(count);
rlm@1 490 if (data)
rlm@1 491 free(data);
rlm@1 492
rlm@1 493 data = (WinGbCheatsData *)calloc(count, sizeof(WinGbCheatsData));
rlm@1 494
rlm@1 495 int inc = 1;
rlm@1 496 switch (sizeType)
rlm@1 497 {
rlm@1 498 case 1:
rlm@1 499 inc = 2;
rlm@1 500 break;
rlm@1 501 case 2:
rlm@1 502 inc = 4;
rlm@1 503 break;
rlm@1 504 }
rlm@1 505
rlm@1 506 int index = 0;
rlm@1 507 if (numberType == 0)
rlm@1 508 {
rlm@1 509 for (int i = 0; i < cheatSearchData.count; i++)
rlm@1 510 {
rlm@1 511 CheatSearchBlock *block = &cheatSearchData.blocks[i];
rlm@1 512
rlm@1 513 for (int j = 0; j < block->size; j += inc)
rlm@1 514 {
rlm@1 515 if (IS_BIT_SET(block->bits, j))
rlm@1 516 {
rlm@1 517 addChange(index++,
rlm@1 518 getBank(block->offset|j, j),
rlm@1 519 block->offset,
rlm@1 520 j,
rlm@1 521 cheatSearchSignedRead(block->saved,
rlm@1 522 j,
rlm@1 523 sizeType),
rlm@1 524 cheatSearchSignedRead(block->data,
rlm@1 525 j,
rlm@1 526 sizeType));
rlm@1 527 }
rlm@1 528 }
rlm@1 529 }
rlm@1 530 }
rlm@1 531 else
rlm@1 532 {
rlm@1 533 for (int i = 0; i < cheatSearchData.count; i++)
rlm@1 534 {
rlm@1 535 CheatSearchBlock *block = &cheatSearchData.blocks[i];
rlm@1 536
rlm@1 537 for (int j = 0; j < block->size; j += inc)
rlm@1 538 {
rlm@1 539 if (IS_BIT_SET(block->bits, j))
rlm@1 540 {
rlm@1 541 addChange(index++,
rlm@1 542 getBank(block->offset|j, j),
rlm@1 543 block->offset,
rlm@1 544 j,
rlm@1 545 cheatSearchRead(block->saved,
rlm@1 546 j,
rlm@1 547 sizeType),
rlm@1 548 cheatSearchRead(block->data,
rlm@1 549 j,
rlm@1 550 sizeType));
rlm@1 551 }
rlm@1 552 }
rlm@1 553 }
rlm@1 554 }
rlm@1 555
rlm@1 556 for (int i = 0; i < count; i++)
rlm@1 557 {
rlm@1 558 LVITEM item;
rlm@1 559
rlm@1 560 item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
rlm@1 561 item.iItem = i;
rlm@1 562 item.iSubItem = 0;
rlm@1 563 item.lParam = data[i].addr|
rlm@1 564 (data[i].bank << 16);
rlm@1 565 item.state = 0;
rlm@1 566 item.stateMask = 0;
rlm@1 567 item.pszText = LPSTR_TEXTCALLBACK;
rlm@1 568 m_list.InsertItem(&item);
rlm@1 569
rlm@1 570 m_list.SetItemText(i, 1, LPSTR_TEXTCALLBACK);
rlm@1 571 m_list.SetItemText(i, 2, LPSTR_TEXTCALLBACK);
rlm@1 572 }
rlm@1 573 }
rlm@1 574
rlm@1 575 void GBCheatSearch::OnValueType(UINT id)
rlm@1 576 {
rlm@1 577 switch (id)
rlm@1 578 {
rlm@1 579 case IDC_OLD_VALUE:
rlm@1 580 valueType = 0;
rlm@1 581 m_value.EnableWindow(FALSE);
rlm@1 582 regSetDwordValue("gbCheatsValueType", 0);
rlm@1 583 break;
rlm@1 584 case IDC_SPECIFIC_VALUE:
rlm@1 585 valueType = 1;
rlm@1 586 m_value.EnableWindow(TRUE);
rlm@1 587 regSetDwordValue("gbCheatsValueType", 1);
rlm@1 588 break;
rlm@1 589 }
rlm@1 590 }
rlm@1 591
rlm@1 592 void GBCheatSearch::OnSearchType(UINT id)
rlm@1 593 {
rlm@1 594 switch (id)
rlm@1 595 {
rlm@1 596 case IDC_EQ:
rlm@1 597 searchType = SEARCH_EQ;
rlm@1 598 regSetDwordValue("gbCheatsSearchType", 0);
rlm@1 599 break;
rlm@1 600 case IDC_NE:
rlm@1 601 searchType = SEARCH_NE;
rlm@1 602 regSetDwordValue("gbCheatsSearchType", 1);
rlm@1 603 break;
rlm@1 604 case IDC_LT:
rlm@1 605 searchType = SEARCH_LT;
rlm@1 606 regSetDwordValue("gbCheatsSearchType", 2);
rlm@1 607 break;
rlm@1 608 case IDC_LE:
rlm@1 609 searchType = SEARCH_LE;
rlm@1 610 regSetDwordValue("gbCheatsSearchType", 3);
rlm@1 611 break;
rlm@1 612 case IDC_GT:
rlm@1 613 searchType = SEARCH_GT;
rlm@1 614 regSetDwordValue("gbCheatsSearchType", 4);
rlm@1 615 break;
rlm@1 616 case IDC_GE:
rlm@1 617 searchType = SEARCH_GE;
rlm@1 618 regSetDwordValue("gbCheatsSearchType", 5);
rlm@1 619 break;
rlm@1 620 }
rlm@1 621 }
rlm@1 622
rlm@1 623 void GBCheatSearch::OnNumberType(UINT id)
rlm@1 624 {
rlm@1 625 switch (id)
rlm@1 626 {
rlm@1 627 case IDC_SIGNED:
rlm@1 628 numberType = 0;
rlm@1 629 regSetDwordValue("gbCheatsNumberType", 0);
rlm@1 630 if (m_list.GetItemCount())
rlm@1 631 {
rlm@1 632 addChanges(false);
rlm@1 633 }
rlm@1 634 break;
rlm@1 635 case IDC_UNSIGNED:
rlm@1 636 numberType = 1;
rlm@1 637 regSetDwordValue("gbCheatsNumberType", 1);
rlm@1 638 if (m_list.GetItemCount())
rlm@1 639 {
rlm@1 640 addChanges(false);
rlm@1 641 }
rlm@1 642 break;
rlm@1 643 case IDC_HEXADECIMAL:
rlm@1 644 numberType = 2;
rlm@1 645 regSetDwordValue("gbCheatsNumberType", 2);
rlm@1 646 if (m_list.GetItemCount())
rlm@1 647 {
rlm@1 648 addChanges(false);
rlm@1 649 }
rlm@1 650 break;
rlm@1 651 }
rlm@1 652 }
rlm@1 653
rlm@1 654 void GBCheatSearch::OnSizeType(UINT id)
rlm@1 655 {
rlm@1 656 switch (id)
rlm@1 657 {
rlm@1 658 case IDC_SIZE_8:
rlm@1 659 sizeType = BITS_8;
rlm@1 660 regSetDwordValue("gbCheatsSizeType", 0);
rlm@1 661 if (m_list.GetItemCount())
rlm@1 662 {
rlm@1 663 addChanges(false);
rlm@1 664 }
rlm@1 665 break;
rlm@1 666 case IDC_SIZE_16:
rlm@1 667 sizeType = BITS_16;
rlm@1 668 regSetDwordValue("gbCheatsSizeType", 1);
rlm@1 669 if (m_list.GetItemCount())
rlm@1 670 {
rlm@1 671 addChanges(false);
rlm@1 672 }
rlm@1 673 break;
rlm@1 674 case IDC_SIZE_32:
rlm@1 675 sizeType = BITS_32;
rlm@1 676 regSetDwordValue("gbCheatsSizeType", 2);
rlm@1 677 if (m_list.GetItemCount())
rlm@1 678 {
rlm@1 679 addChanges(false);
rlm@1 680 }
rlm@1 681 break;
rlm@1 682 }
rlm@1 683 }
rlm@1 684
rlm@1 685 /////////////////////////////////////////////////////////////////////////////
rlm@1 686 // AddGBCheat dialog
rlm@1 687
rlm@1 688 AddGBCheat::AddGBCheat(u32 addr, CWnd*pParent /*=NULL*/)
rlm@1 689 : CDialog(AddGBCheat::IDD, pParent)
rlm@1 690 {
rlm@1 691 //{{AFX_DATA_INIT(AddGBCheat)
rlm@1 692 numberType = regQueryDwordValue("gbCheatsNumberType", 2);
rlm@1 693 if (numberType < 0 || numberType > 2)
rlm@1 694 numberType = 2;
rlm@1 695 sizeType = regQueryDwordValue("gbCheatsSizeType", 0);
rlm@1 696 if (sizeType < 0 || sizeType > 2)
rlm@1 697 sizeType = 0;
rlm@1 698 //}}AFX_DATA_INIT
rlm@1 699 address = addr;
rlm@1 700 }
rlm@1 701
rlm@1 702 void AddGBCheat::DoDataExchange(CDataExchange*pDX)
rlm@1 703 {
rlm@1 704 CDialog::DoDataExchange(pDX);
rlm@1 705 //{{AFX_DATA_MAP(AddGBCheat)
rlm@1 706 DDX_Control(pDX, IDC_VALUE, m_value);
rlm@1 707 DDX_Control(pDX, IDC_ADDRESS, m_address);
rlm@1 708 DDX_Control(pDX, IDC_DESC, m_desc);
rlm@1 709 DDX_Radio(pDX, IDC_SIZE_8, sizeType);
rlm@1 710 DDX_Radio(pDX, IDC_SIGNED, numberType);
rlm@1 711 //}}AFX_DATA_MAP
rlm@1 712 }
rlm@1 713
rlm@1 714 BEGIN_MESSAGE_MAP(AddGBCheat, CDialog)
rlm@1 715 //{{AFX_MSG_MAP(AddGBCheat)
rlm@1 716 ON_BN_CLICKED(ID_OK, OnOk)
rlm@1 717 ON_BN_CLICKED(ID_CANCEL, OnCancel)
rlm@1 718 ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
rlm@1 719 ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
rlm@1 720 //}}AFX_MSG_MAP
rlm@1 721 END_MESSAGE_MAP()
rlm@1 722
rlm@1 723 /////////////////////////////////////////////////////////////////////////////
rlm@1 724 // AddGBCheat message handlers
rlm@1 725
rlm@1 726 void AddGBCheat::OnCancel()
rlm@1 727 {
rlm@1 728 EndDialog(FALSE);
rlm@1 729 }
rlm@1 730
rlm@1 731 void AddGBCheat::OnOk()
rlm@1 732 {
rlm@1 733 // add cheat
rlm@1 734 if (addCheat())
rlm@1 735 {
rlm@1 736 EndDialog(TRUE);
rlm@1 737 }
rlm@1 738 }
rlm@1 739
rlm@1 740 bool AddGBCheat::addCheat()
rlm@1 741 {
rlm@1 742 CString buffer;
rlm@1 743 CString code;
rlm@1 744
rlm@1 745 u32 value;
rlm@1 746 m_value.GetWindowText(buffer);
rlm@1 747
rlm@1 748 if (buffer.IsEmpty())
rlm@1 749 {
rlm@1 750 systemMessage(IDS_VALUE_CANNOT_BE_EMPTY, "Value cannot be empty");
rlm@1 751 return false;
rlm@1 752 }
rlm@1 753
rlm@1 754 switch (numberType)
rlm@1 755 {
rlm@1 756 case 0:
rlm@1 757 sscanf(buffer, "%d", &value);
rlm@1 758 break;
rlm@1 759 case 1:
rlm@1 760 sscanf(buffer, "%u", &value);
rlm@1 761 break;
rlm@1 762 default:
rlm@1 763 sscanf(buffer, "%x", &value);
rlm@1 764 }
rlm@1 765
rlm@1 766 m_desc.GetWindowText(buffer);
rlm@1 767
rlm@1 768 int bank = (address >> 16);
rlm@1 769 address &= 0xFFFF;
rlm@1 770
rlm@1 771 if (address >= 0xd000)
rlm@1 772 bank += 0x90;
rlm@1 773 else
rlm@1 774 bank = 0x01;
rlm@1 775
rlm@1 776 switch (sizeType)
rlm@1 777 {
rlm@1 778 case 0:
rlm@1 779 code.Format("%02X%02X%02X%02X", bank, value, address&0xFF, address>>8);
rlm@1 780 gbAddGsCheat(code, buffer);
rlm@1 781 break;
rlm@1 782 case 1:
rlm@1 783 code.Format("%02X%02X%02X%02X", bank, value&0xFF, address&0xFF,
rlm@1 784 address>>8);
rlm@1 785 gbAddGsCheat(code, buffer);
rlm@1 786 address++;
rlm@1 787 code.Format("%02X%02X%02X%02X", bank, value>>8, address&0xFF,
rlm@1 788 address>>8);
rlm@1 789 gbAddGsCheat(code, buffer);
rlm@1 790 break;
rlm@1 791 case 2:
rlm@1 792 code.Format("%02X%02X%02X%02X", bank, value&0xFF, address&0xFF,
rlm@1 793 address>>8);
rlm@1 794 gbAddGsCheat(code, buffer);
rlm@1 795 address++;
rlm@1 796 code.Format("%02X%02X%02X%02X", bank, (value>>8) & 0xFF, address&0xFF,
rlm@1 797 address>>8);
rlm@1 798 gbAddGsCheat(code, buffer);
rlm@1 799 address++;
rlm@1 800 code.Format("%02X%02X%02X%02X", bank, (value>>16)&0xFF, address&0xFF,
rlm@1 801 address>>8);
rlm@1 802 gbAddGsCheat(code, buffer);
rlm@1 803 address++;
rlm@1 804 code.Format("%02X%02X%02X%02X", bank, value>>24, address&0xFF,
rlm@1 805 address>>8);
rlm@1 806 gbAddGsCheat(code, buffer);
rlm@1 807 break;
rlm@1 808 }
rlm@1 809
rlm@1 810 return true;
rlm@1 811 }
rlm@1 812
rlm@1 813 BOOL AddGBCheat::OnInitDialog()
rlm@1 814 {
rlm@1 815 CDialog::OnInitDialog();
rlm@1 816
rlm@1 817 CString buffer;
rlm@1 818 buffer.Format("%02x:%08x", (address>>16), address&0xFFFF);
rlm@1 819 m_address.SetWindowText(buffer);
rlm@1 820 m_address.EnableWindow(FALSE);
rlm@1 821 ::SetWindowLong(m_address,
rlm@1 822 GWL_USERDATA,
rlm@1 823 address);
rlm@1 824
rlm@1 825 UpdateData(FALSE);
rlm@1 826
rlm@1 827 m_desc.LimitText(32);
rlm@1 828
rlm@1 829 if (address != 0)
rlm@1 830 {
rlm@1 831 GetDlgItem(IDC_SIZE_8)->EnableWindow(FALSE);
rlm@1 832 GetDlgItem(IDC_SIZE_16)->EnableWindow(FALSE);
rlm@1 833 GetDlgItem(IDC_SIZE_32)->EnableWindow(FALSE);
rlm@1 834 GetDlgItem(IDC_HEXADECIMAL)->EnableWindow(FALSE);
rlm@1 835 GetDlgItem(IDC_UNSIGNED)->EnableWindow(FALSE);
rlm@1 836 GetDlgItem(IDC_SIGNED)->EnableWindow(FALSE);
rlm@1 837 }
rlm@1 838 CenterWindow();
rlm@1 839
rlm@1 840 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 841 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 842 }
rlm@1 843
rlm@1 844 void AddGBCheat::OnNumberType(UINT id)
rlm@1 845 {
rlm@1 846 switch (id)
rlm@1 847 {
rlm@1 848 case IDC_SIGNED:
rlm@1 849 numberType = 0;
rlm@1 850 regSetDwordValue("gbCheatsNumberType", 0);
rlm@1 851 break;
rlm@1 852 case IDC_UNSIGNED:
rlm@1 853 numberType = 1;
rlm@1 854 regSetDwordValue("gbCheatsNumberType", 1);
rlm@1 855 break;
rlm@1 856 case IDC_HEXADECIMAL:
rlm@1 857 numberType = 2;
rlm@1 858 regSetDwordValue("gbCheatsNumberType", 2);
rlm@1 859 break;
rlm@1 860 }
rlm@1 861 }
rlm@1 862
rlm@1 863 void AddGBCheat::OnSizeType(UINT id)
rlm@1 864 {
rlm@1 865 switch (id)
rlm@1 866 {
rlm@1 867 case IDC_SIZE_8:
rlm@1 868 sizeType = BITS_8;
rlm@1 869 regSetDwordValue("gbCheatsSizeType", 0);
rlm@1 870 break;
rlm@1 871 case IDC_SIZE_16:
rlm@1 872 sizeType = BITS_16;
rlm@1 873 regSetDwordValue("gbCheatsSizeType", 1);
rlm@1 874 break;
rlm@1 875 case IDC_SIZE_32:
rlm@1 876 sizeType = BITS_32;
rlm@1 877 regSetDwordValue("gbCheatsSizeType", 2);
rlm@1 878 break;
rlm@1 879 }
rlm@1 880 }
rlm@1 881
rlm@1 882 /////////////////////////////////////////////////////////////////////////////
rlm@1 883 // GBCheatList dialog
rlm@1 884
rlm@1 885 GBCheatList::GBCheatList(CWnd*pParent /*=NULL*/)
rlm@1 886 : CDialog(GBCheatList::IDD, pParent)
rlm@1 887 {
rlm@1 888 //{{AFX_DATA_INIT(GBCheatList)
rlm@1 889 // NOTE: the ClassWizard will add member initialization here
rlm@1 890 //}}AFX_DATA_INIT
rlm@1 891 duringRefresh = false;
rlm@1 892 }
rlm@1 893
rlm@1 894 void GBCheatList::DoDataExchange(CDataExchange*pDX)
rlm@1 895 {
rlm@1 896 CDialog::DoDataExchange(pDX);
rlm@1 897 //{{AFX_DATA_MAP(GBCheatList)
rlm@1 898 DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
rlm@1 899 //}}AFX_DATA_MAP
rlm@1 900 }
rlm@1 901
rlm@1 902 BEGIN_MESSAGE_MAP(GBCheatList, CDialog)
rlm@1 903 //{{AFX_MSG_MAP(GBCheatList)
rlm@1 904 ON_BN_CLICKED(ID_OK, OnOk)
rlm@1 905 ON_BN_CLICKED(IDC_ADD_GG_CHEAT, OnAddGgCheat)
rlm@1 906 ON_BN_CLICKED(IDC_ADD_GS_CHEAT, OnAddGsCheat)
rlm@1 907 ON_BN_CLICKED(IDC_ENABLE, OnEnable)
rlm@1 908 ON_BN_CLICKED(IDC_REMOVE, OnRemove)
rlm@1 909 ON_BN_CLICKED(IDC_REMOVE_ALL, OnRemoveAll)
rlm@1 910 ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
rlm@1 911 //}}AFX_MSG_MAP
rlm@1 912 END_MESSAGE_MAP()
rlm@1 913
rlm@1 914 /////////////////////////////////////////////////////////////////////////////
rlm@1 915 // GBCheatList message handlers
rlm@1 916
rlm@1 917 void GBCheatList::OnOk()
rlm@1 918 {
rlm@1 919 EndDialog(TRUE);
rlm@1 920 }
rlm@1 921
rlm@1 922 void GBCheatList::OnAddGgCheat()
rlm@1 923 {
rlm@1 924 CString temp = winResLoadString(IDS_ADD_GG_CODE);
rlm@1 925 AddGBCode dlg(winGbCheatAddVerifyGg, 11, temp);
rlm@1 926 dlg.DoModal();
rlm@1 927 refresh();
rlm@1 928 }
rlm@1 929
rlm@1 930 void GBCheatList::OnAddGsCheat()
rlm@1 931 {
rlm@1 932 CString temp = winResLoadString(IDS_ADD_GS_CODE);
rlm@1 933
rlm@1 934 AddGBCode dlg(winGbCheatAddVerifyGs, 8, temp);
rlm@1 935 dlg.DoModal();
rlm@1 936 refresh();
rlm@1 937 }
rlm@1 938
rlm@1 939 void GBCheatList::OnEnable()
rlm@1 940 {
rlm@1 941 int mark = m_list.GetSelectionMark();
rlm@1 942
rlm@1 943 if (mark != -1)
rlm@1 944 {
rlm@1 945 LVITEM item;
rlm@1 946 memset(&item, 0, sizeof(item));
rlm@1 947 item.mask = LVIF_PARAM;
rlm@1 948 item.iItem = mark;
rlm@1 949 if (m_list.GetItem(&item))
rlm@1 950 {
rlm@1 951 if (gbCheatList[item.lParam].enabled)
rlm@1 952 gbCheatDisable(item.lParam);
rlm@1 953 else
rlm@1 954 gbCheatEnable(item.lParam);
rlm@1 955 refresh();
rlm@1 956 }
rlm@1 957 }
rlm@1 958 }
rlm@1 959
rlm@1 960 void GBCheatList::OnRemove()
rlm@1 961 {
rlm@1 962 int mark = m_list.GetSelectionMark();
rlm@1 963
rlm@1 964 if (mark != -1)
rlm@1 965 {
rlm@1 966 LVITEM item;
rlm@1 967 memset(&item, 0, sizeof(item));
rlm@1 968 item.mask = LVIF_PARAM;
rlm@1 969 item.iItem = mark;
rlm@1 970 if (m_list.GetItem(&item))
rlm@1 971 {
rlm@1 972 gbCheatRemove(item.lParam);
rlm@1 973 refresh();
rlm@1 974 }
rlm@1 975 }
rlm@1 976 }
rlm@1 977
rlm@1 978 void GBCheatList::OnRemoveAll()
rlm@1 979 {
rlm@1 980 gbCheatRemoveAll();
rlm@1 981 refresh();
rlm@1 982 }
rlm@1 983
rlm@1 984 void GBCheatList::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
rlm@1 985 {
rlm@1 986 if (m_list.GetSelectionMark() != -1)
rlm@1 987 {
rlm@1 988 GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
rlm@1 989 GetDlgItem(IDC_ENABLE)->EnableWindow(TRUE);
rlm@1 990 }
rlm@1 991 else
rlm@1 992 {
rlm@1 993 GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
rlm@1 994 GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
rlm@1 995 }
rlm@1 996
rlm@1 997 if (!duringRefresh)
rlm@1 998 {
rlm@1 999 LPNMLISTVIEW l = (LPNMLISTVIEW)pNMHDR;
rlm@1 1000 if (l->uChanged & LVIF_STATE)
rlm@1 1001 {
rlm@1 1002 if (((l->uOldState & LVIS_STATEIMAGEMASK)>>12) !=
rlm@1 1003 (((l->uNewState & LVIS_STATEIMAGEMASK)>>12)))
rlm@1 1004 {
rlm@1 1005 if (m_list.GetCheck(l->iItem))
rlm@1 1006 gbCheatEnable(l->lParam);
rlm@1 1007 else
rlm@1 1008 gbCheatDisable(l->lParam);
rlm@1 1009 refresh();
rlm@1 1010 }
rlm@1 1011 }
rlm@1 1012 }
rlm@1 1013 }
rlm@1 1014
rlm@1 1015 BOOL GBCheatList::OnInitDialog()
rlm@1 1016 {
rlm@1 1017 CDialog::OnInitDialog();
rlm@1 1018
rlm@1 1019 CString temp = winResLoadString(IDS_CODE);
rlm@1 1020 m_list.InsertColumn(0, temp, LVCFMT_LEFT, 120, 0);
rlm@1 1021 temp = winResLoadString(IDS_DESCRIPTION);
rlm@1 1022 m_list.InsertColumn(1, temp, LVCFMT_LEFT, 200, 1);
rlm@1 1023 temp = winResLoadString(IDS_STATUS);
rlm@1 1024 m_list.InsertColumn(2, temp, LVCFMT_LEFT, 80, 2);
rlm@1 1025
rlm@1 1026 m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
rlm@1 1027 TRUE);
rlm@1 1028
rlm@1 1029 m_list.SetExtendedStyle(LVS_EX_CHECKBOXES |
rlm@1 1030 LVS_EX_FULLROWSELECT);
rlm@1 1031
rlm@1 1032 refresh();
rlm@1 1033 GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
rlm@1 1034 GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
rlm@1 1035 CenterWindow();
rlm@1 1036
rlm@1 1037 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 1038 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 1039 }
rlm@1 1040
rlm@1 1041 void GBCheatList::refresh()
rlm@1 1042 {
rlm@1 1043 duringRefresh = true;
rlm@1 1044
rlm@1 1045 m_list.DeleteAllItems();
rlm@1 1046
rlm@1 1047 char buffer[2];
rlm@1 1048
rlm@1 1049 for (int i = 0; i < gbCheatNumber; i++)
rlm@1 1050 {
rlm@1 1051 LVITEM item;
rlm@1 1052
rlm@1 1053 item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
rlm@1 1054 item.iItem = i;
rlm@1 1055 item.iSubItem = 0;
rlm@1 1056 item.lParam = i;
rlm@1 1057 item.state = 0;
rlm@1 1058 item.stateMask = 0;
rlm@1 1059 item.pszText = gbCheatList[i].cheatCode;
rlm@1 1060 m_list.InsertItem(&item);
rlm@1 1061
rlm@1 1062 m_list.SetCheck(i, (gbCheatList[i].enabled ? TRUE : FALSE));
rlm@1 1063
rlm@1 1064 m_list.SetItemText(i, 1, gbCheatList[i].cheatDesc);
rlm@1 1065
rlm@1 1066 buffer[0] = (gbCheatList[i].enabled) ? 'E' : 'D';
rlm@1 1067 buffer[1] = 0;
rlm@1 1068 m_list.SetItemText(i, 2, buffer);
rlm@1 1069 }
rlm@1 1070 duringRefresh = false;
rlm@1 1071 }
rlm@1 1072
rlm@1 1073 /////////////////////////////////////////////////////////////////////////////
rlm@1 1074 // AddGBCode dialog
rlm@1 1075
rlm@1 1076 AddGBCode::AddGBCode(bool(*verify)(const char *, const char *), int len, const char *title, CWnd*pParent /*=NULL*/)
rlm@1 1077 : CDialog(AddGBCode::IDD, pParent)
rlm@1 1078 {
rlm@1 1079 //{{AFX_DATA_INIT(AddGBCode)
rlm@1 1080 // NOTE: the ClassWizard will add member initialization here
rlm@1 1081 //}}AFX_DATA_INIT
rlm@1 1082 addVerify = verify;
rlm@1 1083 addLength = len;
rlm@1 1084 addTitle = title;
rlm@1 1085 }
rlm@1 1086
rlm@1 1087 void AddGBCode::DoDataExchange(CDataExchange*pDX)
rlm@1 1088 {
rlm@1 1089 CDialog::DoDataExchange(pDX);
rlm@1 1090 //{{AFX_DATA_MAP(AddGBCode)
rlm@1 1091 DDX_Control(pDX, IDC_DESC, m_desc);
rlm@1 1092 DDX_Control(pDX, IDC_CODE, m_code);
rlm@1 1093 //}}AFX_DATA_MAP
rlm@1 1094 }
rlm@1 1095
rlm@1 1096 BEGIN_MESSAGE_MAP(AddGBCode, CDialog)
rlm@1 1097 //{{AFX_MSG_MAP(AddGBCode)
rlm@1 1098 ON_BN_CLICKED(ID_OK, OnOk)
rlm@1 1099 ON_BN_CLICKED(ID_CANCEL, OnCancel)
rlm@1 1100 //}}AFX_MSG_MAP
rlm@1 1101 END_MESSAGE_MAP()
rlm@1 1102
rlm@1 1103 /////////////////////////////////////////////////////////////////////////////
rlm@1 1104 // AddGBCode message handlers
rlm@1 1105
rlm@1 1106 void AddGBCode::OnOk()
rlm@1 1107 {
rlm@1 1108 CString desc;
rlm@1 1109 CString buffer;
rlm@1 1110 m_code.GetWindowText(buffer);
rlm@1 1111 m_desc.GetWindowText(desc);
rlm@1 1112
rlm@1 1113 StringTokenizer st(buffer, " \t\n\r");
rlm@1 1114 const char * t = st.next();
rlm@1 1115 while (t)
rlm@1 1116 {
rlm@1 1117 addVerify(t, desc);
rlm@1 1118 t = st.next();
rlm@1 1119 }
rlm@1 1120 EndDialog(TRUE);
rlm@1 1121 }
rlm@1 1122
rlm@1 1123 void AddGBCode::OnCancel()
rlm@1 1124 {
rlm@1 1125 EndDialog(FALSE);
rlm@1 1126 }
rlm@1 1127
rlm@1 1128 BOOL AddGBCode::OnInitDialog()
rlm@1 1129 {
rlm@1 1130 CDialog::OnInitDialog();
rlm@1 1131
rlm@1 1132 m_code.LimitText(1024);
rlm@1 1133 m_desc.LimitText(32);
rlm@1 1134 SetWindowText(addTitle);
rlm@1 1135 CenterWindow();
rlm@1 1136
rlm@1 1137 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 1138 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 1139 }
rlm@1 1140