annotate src/win32/GBACheatsDlg.cpp @ 1:f9f4f1b99eed

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