diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/GBACheatsDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,1279 @@
     1.4 +// GBACheats.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "GBACheatsDlg.h"
    1.10 +#include "Reg.h"
    1.11 +#include "StringTokenizer.h"
    1.12 +#include "WinResUtil.h"
    1.13 +#include "Sound.h"
    1.14 +#include "VBA.h"
    1.15 +
    1.16 +#include "../gba/GBACheats.h"
    1.17 +#include "../gba/GBAGlobals.h"
    1.18 +#include "../common/CheatSearch.h"
    1.19 +
    1.20 +////////////////////////////////
    1.21 +
    1.22 +bool winGbaCheatReaddress()
    1.23 +{
    1.24 +	if (cheatSearchData.count != 2)
    1.25 +		return false;
    1.26 +
    1.27 +	CheatSearchBlock *block = &cheatSearchData.blocks[0];
    1.28 +	block->data   = workRAM;
    1.29 +
    1.30 +	block         = &cheatSearchData.blocks[1];
    1.31 +	block->data   = internalRAM;
    1.32 +	
    1.33 +	cheatSearchData.count = 2;
    1.34 +	return true;
    1.35 +}
    1.36 +
    1.37 +/////////////////////////////////////////////////////////////////////////////
    1.38 +// GBACheatSearch dialog
    1.39 +
    1.40 +GBACheatSearch::GBACheatSearch(CWnd*pParent /*=NULL*/)
    1.41 +	: CDialog(GBACheatSearch::IDD, pParent)
    1.42 +{
    1.43 +	//{{AFX_DATA_INIT(GBACheatSearch)
    1.44 +	valueType    = -1;
    1.45 +	sizeType     = -1;
    1.46 +	searchType   = -1;
    1.47 +	numberType   = -1;
    1.48 +	updateValues = FALSE;
    1.49 +	//}}AFX_DATA_INIT
    1.50 +	data = NULL;
    1.51 +}
    1.52 +
    1.53 +GBACheatSearch::~GBACheatSearch()
    1.54 +{
    1.55 +	if (data)
    1.56 +		free(data);
    1.57 +}
    1.58 +
    1.59 +void GBACheatSearch::DoDataExchange(CDataExchange*pDX)
    1.60 +{
    1.61 +	CDialog::DoDataExchange(pDX);
    1.62 +	//{{AFX_DATA_MAP(GBACheatSearch)
    1.63 +	DDX_Control(pDX, IDC_VALUE, m_value);
    1.64 +	DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
    1.65 +	DDX_Radio(pDX, IDC_OLD_VALUE, valueType);
    1.66 +	DDX_Radio(pDX, IDC_SIZE_8, sizeType);
    1.67 +	DDX_Radio(pDX, IDC_EQ, searchType);
    1.68 +	DDX_Radio(pDX, IDC_SIGNED, numberType);
    1.69 +	DDX_Check(pDX, IDC_UPDATE, updateValues);
    1.70 +	//}}AFX_DATA_MAP
    1.71 +}
    1.72 +
    1.73 +BEGIN_MESSAGE_MAP(GBACheatSearch, CDialog)
    1.74 +//{{AFX_MSG_MAP(GBACheatSearch)
    1.75 +ON_BN_CLICKED(ID_OK, OnOk)
    1.76 +ON_BN_CLICKED(IDC_START, OnStart)
    1.77 +ON_BN_CLICKED(IDC_SEARCH, OnSearch)
    1.78 +ON_BN_CLICKED(IDC_ADD_CHEAT, OnAddCheat)
    1.79 +ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
    1.80 +ON_NOTIFY(LVN_GETDISPINFO, IDC_CHEAT_LIST, OnGetdispinfoCheatList)
    1.81 +ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
    1.82 +ON_CONTROL_RANGE(BN_CLICKED, IDC_OLD_VALUE, IDC_SPECIFIC_VALUE, OnValueType)
    1.83 +ON_CONTROL_RANGE(BN_CLICKED, IDC_EQ, IDC_GE, OnSearchType)
    1.84 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
    1.85 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
    1.86 +//}}AFX_MSG_MAP
    1.87 +ON_WM_CLOSE()
    1.88 +ON_BN_CLICKED(IDC_CHEATREFRESHBUTTON, OnBnClickedCheatrefreshbutton)
    1.89 +//ON_WM_DESTROY()
    1.90 +//ON_WM_NCDESTROY()
    1.91 +//ON_WM_SYSCOMMAND()
    1.92 +//ON_WM_ACTIVATE()
    1.93 +END_MESSAGE_MAP()
    1.94 +
    1.95 +/////////////////////////////////////////////////////////////////////////////
    1.96 +// GBACheatSearch message handlers
    1.97 +
    1.98 +void GBACheatSearch::OnOk()
    1.99 +{
   1.100 +	if (theApp.modelessCheatDialogIsOpen)
   1.101 +	{
   1.102 +		theApp.modelessCheatDialogIsOpen = false;
   1.103 +		DestroyWindow();
   1.104 +	}
   1.105 +	else
   1.106 +	{
   1.107 +		EndDialog(TRUE);
   1.108 +	}
   1.109 +}
   1.110 +
   1.111 +void GBACheatSearch::OnClose()
   1.112 +{
   1.113 +	CDialog::OnClose();
   1.114 +	if (theApp.modelessCheatDialogIsOpen)
   1.115 +	{
   1.116 +		theApp.modelessCheatDialogIsOpen = false;
   1.117 +		DestroyWindow();
   1.118 +	}
   1.119 +	else
   1.120 +	{
   1.121 +		EndDialog(FALSE);
   1.122 +	}
   1.123 +}
   1.124 +
   1.125 +void GBACheatSearch::OnStart()
   1.126 +{
   1.127 +	if (cheatSearchData.count == 0)
   1.128 +	{
   1.129 +		CheatSearchBlock *block = &cheatSearchData.blocks[0];
   1.130 +		block->data   = workRAM;
   1.131 +		block->offset = 0x2000000;
   1.132 +		block->size   = 0x40000;
   1.133 +		block->saved  = (u8 *)malloc(0x40000);
   1.134 +		block->bits   = (u8 *)malloc(0x40000>>3);
   1.135 +
   1.136 +		block         = &cheatSearchData.blocks[1];
   1.137 +		block->data   = internalRAM;
   1.138 +		block->offset = 0x3000000;
   1.139 +		block->size   = 0x8000;
   1.140 +		block->saved  = (u8 *)malloc(0x8000);
   1.141 +		block->bits   = (u8 *)malloc(0x8000>>3);
   1.142 +
   1.143 +		cheatSearchData.count = 2;
   1.144 +	}
   1.145 +
   1.146 +	cheatSearchStart(&cheatSearchData);
   1.147 +	GetDlgItem(IDC_SEARCH)->EnableWindow(TRUE);
   1.148 +
   1.149 +	if (theApp.modelessCheatDialogIsOpen)
   1.150 +	{
   1.151 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
   1.152 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
   1.153 +	}
   1.154 +}
   1.155 +
   1.156 +void GBACheatSearch::OnSearch()
   1.157 +{
   1.158 +	CString buffer;
   1.159 +
   1.160 +	if (valueType == 0)
   1.161 +		cheatSearch(&cheatSearchData,
   1.162 +		            searchType,
   1.163 +		            sizeType,
   1.164 +		            numberType == 0);
   1.165 +	else
   1.166 +	{
   1.167 +		m_value.GetWindowText(buffer);
   1.168 +		if (buffer.IsEmpty())
   1.169 +		{
   1.170 +			systemMessage(IDS_NUMBER_CANNOT_BE_EMPTY, "Number cannot be empty");
   1.171 +			return;
   1.172 +		}
   1.173 +		int value = 0;
   1.174 +		switch (numberType)
   1.175 +		{
   1.176 +		case 0:
   1.177 +			sscanf(buffer, "%d", &value);
   1.178 +			break;
   1.179 +		case 1:
   1.180 +			sscanf(buffer, "%u", &value);
   1.181 +			break;
   1.182 +		default:
   1.183 +			sscanf(buffer, "%x", &value);
   1.184 +		}
   1.185 +		cheatSearchValue(&cheatSearchData,
   1.186 +		                 searchType,
   1.187 +		                 sizeType,
   1.188 +		                 numberType == 0,
   1.189 +		                 value);
   1.190 +	}
   1.191 +
   1.192 +	addChanges(true);
   1.193 +
   1.194 +	if (updateValues)
   1.195 +		cheatSearchUpdateValues(&cheatSearchData);
   1.196 +
   1.197 +	if (theApp.modelessCheatDialogIsOpen)
   1.198 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData, sizeType) == 0 ? FALSE : TRUE);
   1.199 +
   1.200 +	if (0 == cheatSearchGetCount(&cheatSearchData, sizeType))
   1.201 +		OnStart();
   1.202 +}
   1.203 +
   1.204 +void GBACheatSearch::OnAddCheat()
   1.205 +{
   1.206 +	int mark = m_list.GetSelectionMark();
   1.207 +
   1.208 +	if (mark != -1)
   1.209 +	{
   1.210 +		LVITEM item;
   1.211 +		memset(&item, 0, sizeof(item));
   1.212 +		item.mask  = LVIF_PARAM;
   1.213 +		item.iItem = mark;
   1.214 +		if (m_list.GetItem(&item))
   1.215 +		{
   1.216 +			AddCheat dlg((u32)item.lParam);
   1.217 +			dlg.DoModal();
   1.218 +		}
   1.219 +	}
   1.220 +}
   1.221 +
   1.222 +void GBACheatSearch::OnUpdate()
   1.223 +{
   1.224 +	if (GetDlgItem(IDC_UPDATE)->SendMessage(BM_GETCHECK,
   1.225 +	                                        0,
   1.226 +	                                        0) & BST_CHECKED)
   1.227 +		updateValues = true;
   1.228 +	else
   1.229 +		updateValues = false;
   1.230 +	regSetDwordValue("cheatsUpdate", updateValues);
   1.231 +}
   1.232 +
   1.233 +void GBACheatSearch::OnGetdispinfoCheatList(NMHDR*pNMHDR, LRESULT*pResult)
   1.234 +{
   1.235 +	LV_DISPINFO*info = (LV_DISPINFO *)pNMHDR;
   1.236 +	if (info->item.mask & LVIF_TEXT)
   1.237 +	{
   1.238 +		int index = info->item.iItem;
   1.239 +		int col   = info->item.iSubItem;
   1.240 +
   1.241 +		switch (col)
   1.242 +		{
   1.243 +		case 0:
   1.244 +			strcpy(info->item.pszText, data[index].address);
   1.245 +			break;
   1.246 +		case 1:
   1.247 +			strcpy(info->item.pszText, data[index].oldValue);
   1.248 +			break;
   1.249 +		case 2:
   1.250 +			strcpy(info->item.pszText, data[index].newValue);
   1.251 +			break;
   1.252 +		}
   1.253 +	}
   1.254 +	*pResult = TRUE;
   1.255 +}
   1.256 +
   1.257 +void GBACheatSearch::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
   1.258 +{
   1.259 +	GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(m_list.GetSelectionMark() != -1);
   1.260 +	*pResult = TRUE;
   1.261 +}
   1.262 +
   1.263 +BOOL GBACheatSearch::OnInitDialog()
   1.264 +{
   1.265 +	CDialog::OnInitDialog();
   1.266 +
   1.267 +	CString temp = winResLoadString(IDS_ADDRESS);
   1.268 +
   1.269 +	m_list.InsertColumn(0, temp, LVCFMT_CENTER, 125, 0);
   1.270 +
   1.271 +	temp = winResLoadString(IDS_OLD_VALUE);
   1.272 +	m_list.InsertColumn(1, temp, LVCFMT_CENTER, 125, 1);
   1.273 +
   1.274 +	temp = winResLoadString(IDS_NEW_VALUE);
   1.275 +	m_list.InsertColumn(2, temp, LVCFMT_CENTER, 125, 2);
   1.276 +
   1.277 +	m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
   1.278 +	               TRUE);
   1.279 +
   1.280 +	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
   1.281 +
   1.282 +	if (!cheatSearchData.count)
   1.283 +	{
   1.284 +		GetDlgItem(IDC_SEARCH)->EnableWindow(FALSE);
   1.285 +		GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(FALSE);
   1.286 +	}
   1.287 +
   1.288 +	valueType = regQueryDwordValue("cheatsValueType", 0);
   1.289 +	if (valueType < 0 || valueType > 1)
   1.290 +		valueType = 0;
   1.291 +
   1.292 +	searchType = regQueryDwordValue("cheatsSearchType", SEARCH_EQ);
   1.293 +	if (searchType > 5 || searchType < 0)
   1.294 +		searchType = 0;
   1.295 +
   1.296 +	numberType = regQueryDwordValue("cheatsNumberType", 2);
   1.297 +	if (numberType < 0 || numberType > 2)
   1.298 +		numberType = 2;
   1.299 +
   1.300 +	sizeType = regQueryDwordValue("cheatsSizeType", 0);
   1.301 +	if (sizeType < 0 || sizeType > 2)
   1.302 +		sizeType = 0;
   1.303 +
   1.304 +	updateValues = regQueryDwordValue("cheatsUpdate", 0) ?
   1.305 +	               true : false;
   1.306 +
   1.307 +	UpdateData(FALSE);
   1.308 +
   1.309 +	if (valueType == 0)
   1.310 +		m_value.EnableWindow(FALSE);
   1.311 +	CenterWindow();
   1.312 +
   1.313 +	if (theApp.modelessCheatDialogIsOpen)
   1.314 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
   1.315 +
   1.316 +	if (cheatSearchData.count)
   1.317 +	{
   1.318 +		addChanges(false);
   1.319 +		if (theApp.modelessCheatDialogIsOpen)
   1.320 +			GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData,
   1.321 +			                                                                     sizeType) == 0 ? FALSE : TRUE);
   1.322 +	}
   1.323 +	else
   1.324 +	{
   1.325 +		if (theApp.modelessCheatDialogIsOpen)
   1.326 +			GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
   1.327 +	}
   1.328 +
   1.329 +	return TRUE; // return TRUE unless you set the focus to a control
   1.330 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.331 +}
   1.332 +
   1.333 +void GBACheatSearch::addChanges(bool showMsgs)
   1.334 +{
   1.335 +	int count = cheatSearchGetCount(&cheatSearchData, sizeType);
   1.336 +
   1.337 +	m_list.DeleteAllItems();
   1.338 +
   1.339 +	if (count > 4000)
   1.340 +	{
   1.341 +		if (showMsgs)
   1.342 +			systemMessage(
   1.343 +			    IDS_SEARCH_PRODUCED_TOO_MANY,
   1.344 +			    "Search produced %d results.\nThey have been remembered, but are too many to display.\nPlease refine it better by performing additional searches.",
   1.345 +			    count);
   1.346 +		return;
   1.347 +	}
   1.348 +
   1.349 +	if (count == 0)
   1.350 +	{
   1.351 +		if (showMsgs)
   1.352 +			systemMessage(IDS_SEARCH_PRODUCED_NO_RESULTS, "Search produced no results.");
   1.353 +		return;
   1.354 +	}
   1.355 +
   1.356 +	m_list.SetItemCount(count);
   1.357 +	if (data)
   1.358 +		free(data);
   1.359 +
   1.360 +	data = (WinCheatsData *)calloc(count, sizeof(WinCheatsData));
   1.361 +
   1.362 +	int inc = 1;
   1.363 +	switch (sizeType)
   1.364 +	{
   1.365 +	case 1:
   1.366 +		inc = 2;
   1.367 +		break;
   1.368 +	case 2:
   1.369 +		inc = 4;
   1.370 +		break;
   1.371 +	}
   1.372 +
   1.373 +	int index = 0;
   1.374 +	if (numberType == 0)
   1.375 +	{
   1.376 +		for (int i = 0; i < cheatSearchData.count; i++)
   1.377 +		{
   1.378 +			CheatSearchBlock *block = &cheatSearchData.blocks[i];
   1.379 +
   1.380 +			for (int j = 0; j < block->size; j += inc)
   1.381 +			{
   1.382 +				if (IS_BIT_SET(block->bits, j))
   1.383 +				{
   1.384 +					addChange(index++,
   1.385 +					          block->offset | j,
   1.386 +					          cheatSearchSignedRead(block->saved,
   1.387 +					                                j,
   1.388 +					                                sizeType),
   1.389 +					          cheatSearchSignedRead(block->data,
   1.390 +					                                j,
   1.391 +					                                sizeType));
   1.392 +				}
   1.393 +			}
   1.394 +		}
   1.395 +	}
   1.396 +	else
   1.397 +	{
   1.398 +		for (int i = 0; i < cheatSearchData.count; i++)
   1.399 +		{
   1.400 +			CheatSearchBlock *block = &cheatSearchData.blocks[i];
   1.401 +
   1.402 +			for (int j = 0; j < block->size; j += inc)
   1.403 +			{
   1.404 +				if (IS_BIT_SET(block->bits, j))
   1.405 +				{
   1.406 +					addChange(index++,
   1.407 +					          block->offset | j,
   1.408 +					          cheatSearchRead(block->saved,
   1.409 +					                          j,
   1.410 +					                          sizeType),
   1.411 +					          cheatSearchRead(block->data,
   1.412 +					                          j,
   1.413 +					                          sizeType));
   1.414 +				}
   1.415 +			}
   1.416 +		}
   1.417 +	}
   1.418 +
   1.419 +	for (int i = 0; i < count; i++)
   1.420 +	{
   1.421 +		LVITEM item;
   1.422 +
   1.423 +		item.mask      = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
   1.424 +		item.iItem     = i;
   1.425 +		item.iSubItem  = 0;
   1.426 +		item.lParam    = data[i].addr;
   1.427 +		item.state     = 0;
   1.428 +		item.stateMask = 0;
   1.429 +		item.pszText   = LPSTR_TEXTCALLBACK;
   1.430 +		m_list.InsertItem(&item);
   1.431 +
   1.432 +		m_list.SetItemText(i, 1, LPSTR_TEXTCALLBACK);
   1.433 +		m_list.SetItemText(i, 2, LPSTR_TEXTCALLBACK);
   1.434 +	}
   1.435 +}
   1.436 +
   1.437 +void GBACheatSearch::addChange(int index, u32 address, u32 oldValue, u32 newValue)
   1.438 +{
   1.439 +	data[index].addr = address;
   1.440 +	sprintf(data[index].address, "%08x", address);
   1.441 +	switch (numberType)
   1.442 +	{
   1.443 +	case 0:
   1.444 +		sprintf(data[index].oldValue, "%d", oldValue);
   1.445 +		sprintf(data[index].newValue, "%d", newValue);
   1.446 +		break;
   1.447 +	case 1:
   1.448 +		sprintf(data[index].oldValue, "%u", oldValue);
   1.449 +		sprintf(data[index].newValue, "%u", newValue);
   1.450 +		break;
   1.451 +	case 2:
   1.452 +		switch (sizeType)
   1.453 +		{
   1.454 +		case 0:
   1.455 +			sprintf(data[index].oldValue, "%02x", oldValue);
   1.456 +			sprintf(data[index].newValue, "%02x", newValue);
   1.457 +			break;
   1.458 +		case 1:
   1.459 +			sprintf(data[index].oldValue, "%04x", oldValue);
   1.460 +			sprintf(data[index].newValue, "%04x", newValue);
   1.461 +			break;
   1.462 +		case 2:
   1.463 +			sprintf(data[index].oldValue, "%08x", oldValue);
   1.464 +			sprintf(data[index].newValue, "%08x", newValue);
   1.465 +			break;
   1.466 +		}
   1.467 +	}
   1.468 +}
   1.469 +
   1.470 +void GBACheatSearch::OnValueType(UINT id)
   1.471 +{
   1.472 +	switch (id)
   1.473 +	{
   1.474 +	case IDC_OLD_VALUE:
   1.475 +		valueType = 0;
   1.476 +		m_value.EnableWindow(FALSE);
   1.477 +		regSetDwordValue("cheatsValueType", 0);
   1.478 +		break;
   1.479 +	case IDC_SPECIFIC_VALUE:
   1.480 +		valueType = 1;
   1.481 +		m_value.EnableWindow(TRUE);
   1.482 +		regSetDwordValue("cheatsValueType", 1);
   1.483 +		break;
   1.484 +	}
   1.485 +}
   1.486 +
   1.487 +void GBACheatSearch::OnSearchType(UINT id)
   1.488 +{
   1.489 +	switch (id)
   1.490 +	{
   1.491 +	case IDC_EQ:
   1.492 +		searchType = SEARCH_EQ;
   1.493 +		regSetDwordValue("cheatsSearchType", 0);
   1.494 +		break;
   1.495 +	case IDC_NE:
   1.496 +		searchType = SEARCH_NE;
   1.497 +		regSetDwordValue("cheatsSearchType", 1);
   1.498 +		break;
   1.499 +	case IDC_LT:
   1.500 +		searchType = SEARCH_LT;
   1.501 +		regSetDwordValue("cheatsSearchType", 2);
   1.502 +		break;
   1.503 +	case IDC_LE:
   1.504 +		searchType = SEARCH_LE;
   1.505 +		regSetDwordValue("cheatsSearchType", 3);
   1.506 +		break;
   1.507 +	case IDC_GT:
   1.508 +		searchType = SEARCH_GT;
   1.509 +		regSetDwordValue("cheatsSearchType", 4);
   1.510 +		break;
   1.511 +	case IDC_GE:
   1.512 +		searchType = SEARCH_GE;
   1.513 +		regSetDwordValue("cheatsSearchType", 5);
   1.514 +		break;
   1.515 +	}
   1.516 +}
   1.517 +
   1.518 +void GBACheatSearch::OnNumberType(UINT id)
   1.519 +{
   1.520 +	switch (id)
   1.521 +	{
   1.522 +	case IDC_SIGNED:
   1.523 +		numberType = 0;
   1.524 +		regSetDwordValue("cheatsNumberType", 0);
   1.525 +		if (m_list.GetItemCount())
   1.526 +		{
   1.527 +			addChanges(false);
   1.528 +		}
   1.529 +		break;
   1.530 +	case IDC_UNSIGNED:
   1.531 +		numberType = 1;
   1.532 +		regSetDwordValue("cheatsNumberType", 1);
   1.533 +		if (m_list.GetItemCount())
   1.534 +		{
   1.535 +			addChanges(false);
   1.536 +		}
   1.537 +		break;
   1.538 +	case IDC_HEXADECIMAL:
   1.539 +		numberType = 2;
   1.540 +		regSetDwordValue("cheatsNumberType", 2);
   1.541 +		if (m_list.GetItemCount())
   1.542 +		{
   1.543 +			addChanges(false);
   1.544 +		}
   1.545 +		break;
   1.546 +	}
   1.547 +}
   1.548 +
   1.549 +void GBACheatSearch::OnSizeType(UINT id)
   1.550 +{
   1.551 +	switch (id)
   1.552 +	{
   1.553 +	case IDC_SIZE_8:
   1.554 +		sizeType = BITS_8;
   1.555 +		regSetDwordValue("cheatsSizeType", 0);
   1.556 +		if (m_list.GetItemCount())
   1.557 +		{
   1.558 +			addChanges(false);
   1.559 +		}
   1.560 +		break;
   1.561 +	case IDC_SIZE_16:
   1.562 +		sizeType = BITS_16;
   1.563 +		regSetDwordValue("cheatsSizeType", 1);
   1.564 +		if (m_list.GetItemCount())
   1.565 +		{
   1.566 +			addChanges(false);
   1.567 +		}
   1.568 +		break;
   1.569 +	case IDC_SIZE_32:
   1.570 +		sizeType = BITS_32;
   1.571 +		regSetDwordValue("cheatsSizeType", 2);
   1.572 +		if (m_list.GetItemCount())
   1.573 +		{
   1.574 +			addChanges(false);
   1.575 +		}
   1.576 +		break;
   1.577 +	}
   1.578 +}
   1.579 +
   1.580 +/////////////////////////////////////////////////////////////////////////////
   1.581 +// AddCheat dialog
   1.582 +
   1.583 +AddCheat::AddCheat(u32 address, CWnd*pParent /*=NULL*/)
   1.584 +	: CDialog(AddCheat::IDD, pParent)
   1.585 +{
   1.586 +	//{{AFX_DATA_INIT(AddCheat)
   1.587 +	numberType = regQueryDwordValue("cheatsNumberType", 2);
   1.588 +	if (numberType < 0 || numberType > 2)
   1.589 +		numberType = 2;
   1.590 +	sizeType = regQueryDwordValue("cheatsSizeType", 0);
   1.591 +	if (sizeType < 0 || sizeType > 2)
   1.592 +		sizeType = 0;
   1.593 +	//}}AFX_DATA_INIT
   1.594 +	this->address = address;
   1.595 +}
   1.596 +
   1.597 +void AddCheat::DoDataExchange(CDataExchange*pDX)
   1.598 +{
   1.599 +	CDialog::DoDataExchange(pDX);
   1.600 +	//{{AFX_DATA_MAP(AddCheat)
   1.601 +	DDX_Control(pDX, IDC_VALUE, m_value);
   1.602 +	DDX_Control(pDX, IDC_DESC, m_desc);
   1.603 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
   1.604 +	DDX_Radio(pDX, IDC_SIZE_8, sizeType);
   1.605 +	DDX_Radio(pDX, IDC_SIGNED, numberType);
   1.606 +	//}}AFX_DATA_MAP
   1.607 +}
   1.608 +
   1.609 +BEGIN_MESSAGE_MAP(AddCheat, CDialog)
   1.610 +//{{AFX_MSG_MAP(AddCheat)
   1.611 +ON_BN_CLICKED(ID_OK, OnOk)
   1.612 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
   1.613 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
   1.614 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
   1.615 +//}}AFX_MSG_MAP
   1.616 +END_MESSAGE_MAP()
   1.617 +
   1.618 +/////////////////////////////////////////////////////////////////////////////
   1.619 +// AddCheat message handlers
   1.620 +
   1.621 +void AddCheat::OnOk()
   1.622 +{
   1.623 +	// add cheat
   1.624 +	if (addCheat())
   1.625 +	{
   1.626 +		EndDialog(TRUE);
   1.627 +	}
   1.628 +}
   1.629 +
   1.630 +void AddCheat::OnCancel()
   1.631 +{
   1.632 +	EndDialog(FALSE);
   1.633 +}
   1.634 +
   1.635 +BOOL AddCheat::OnInitDialog()
   1.636 +{
   1.637 +	CDialog::OnInitDialog();
   1.638 +
   1.639 +	if (address != 0)
   1.640 +	{
   1.641 +		CString buffer;
   1.642 +		buffer.Format("%08x", address);
   1.643 +		m_address.SetWindowText(buffer);
   1.644 +		m_address.EnableWindow(FALSE);
   1.645 +	}
   1.646 +
   1.647 +	UpdateData(FALSE);
   1.648 +
   1.649 +	GetDlgItem(IDC_DESC)->SendMessage(EM_LIMITTEXT,
   1.650 +	                                  32,
   1.651 +	                                  0);
   1.652 +	if (address != 0)
   1.653 +	{
   1.654 +		GetDlgItem(IDC_SIZE_8)->EnableWindow(FALSE);
   1.655 +		GetDlgItem(IDC_SIZE_16)->EnableWindow(FALSE);
   1.656 +		GetDlgItem(IDC_SIZE_32)->EnableWindow(FALSE);
   1.657 +		GetDlgItem(IDC_HEXADECIMAL)->EnableWindow(FALSE);
   1.658 +		GetDlgItem(IDC_UNSIGNED)->EnableWindow(FALSE);
   1.659 +		GetDlgItem(IDC_SIGNED)->EnableWindow(FALSE);
   1.660 +	}
   1.661 +
   1.662 +	CenterWindow();
   1.663 +
   1.664 +	return TRUE; // return TRUE unless you set the focus to a control
   1.665 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.666 +}
   1.667 +
   1.668 +void AddCheat::OnNumberType(UINT id)
   1.669 +{
   1.670 +	switch (id)
   1.671 +	{
   1.672 +	case IDC_SIGNED:
   1.673 +		numberType = 0;
   1.674 +		regSetDwordValue("cheatsNumberType", 0);
   1.675 +		break;
   1.676 +	case IDC_UNSIGNED:
   1.677 +		numberType = 1;
   1.678 +		regSetDwordValue("cheatsNumberType", 1);
   1.679 +		break;
   1.680 +	case IDC_HEXADECIMAL:
   1.681 +		numberType = 2;
   1.682 +		regSetDwordValue("cheatsNumberType", 2);
   1.683 +		break;
   1.684 +	}
   1.685 +}
   1.686 +
   1.687 +void AddCheat::OnSizeType(UINT id)
   1.688 +{
   1.689 +	switch (id)
   1.690 +	{
   1.691 +	case IDC_SIZE_8:
   1.692 +		sizeType = BITS_8;
   1.693 +		regSetDwordValue("cheatsSizeType", 0);
   1.694 +		break;
   1.695 +	case IDC_SIZE_16:
   1.696 +		sizeType = BITS_16;
   1.697 +		regSetDwordValue("cheatsSizeType", 1);
   1.698 +		break;
   1.699 +	case IDC_SIZE_32:
   1.700 +		sizeType = BITS_32;
   1.701 +		regSetDwordValue("cheatsSizeType", 2);
   1.702 +		break;
   1.703 +	}
   1.704 +}
   1.705 +
   1.706 +bool AddCheat::addCheat()
   1.707 +{
   1.708 +	CString buffer;
   1.709 +	CString code;
   1.710 +
   1.711 +	m_address.GetWindowText(buffer);
   1.712 +	u32 address = 0;
   1.713 +	sscanf(buffer, "%x", &address);
   1.714 +	if ((address >= 0x02000000 && address < 0x02040000) ||
   1.715 +	    (address >= 0x03000000 && address < 0x03008000))
   1.716 +	{}
   1.717 +	else
   1.718 +	{
   1.719 +		systemMessage(IDS_INVALID_ADDRESS, "Invalid address: %08x", address);
   1.720 +		return false;
   1.721 +	}
   1.722 +	if (sizeType != 0)
   1.723 +	{
   1.724 +		if (sizeType == 1 && address & 1)
   1.725 +		{
   1.726 +			systemMessage(IDS_MISALIGNED_HALFWORD, "Misaligned half-word address: %08x", address);
   1.727 +			return false;
   1.728 +		}
   1.729 +		if (sizeType == 2 && address & 3)
   1.730 +		{
   1.731 +			systemMessage(IDS_MISALIGNED_WORD, "Misaligned word address: %08x", address);
   1.732 +			return false;
   1.733 +		}
   1.734 +	}
   1.735 +	u32 value;
   1.736 +	m_value.GetWindowText(buffer);
   1.737 +
   1.738 +	if (buffer.IsEmpty())
   1.739 +	{
   1.740 +		systemMessage(IDS_VALUE_CANNOT_BE_EMPTY, "Value cannot be empty");
   1.741 +		return false;
   1.742 +	}
   1.743 +
   1.744 +	switch (numberType)
   1.745 +	{
   1.746 +	case 0:
   1.747 +		sscanf(buffer, "%d", &value);
   1.748 +		break;
   1.749 +	case 1:
   1.750 +		sscanf(buffer, "%u", &value);
   1.751 +		break;
   1.752 +	default:
   1.753 +		sscanf(buffer, "%x", &value);
   1.754 +	}
   1.755 +
   1.756 +	m_desc.GetWindowText(buffer);
   1.757 +
   1.758 +	switch (sizeType)
   1.759 +	{
   1.760 +	case 0:
   1.761 +		code.Format("%08x:%02x", address, value);
   1.762 +		break;
   1.763 +	case 1:
   1.764 +		code.Format("%08x:%04x", address, value);
   1.765 +		break;
   1.766 +	case 2:
   1.767 +		code.Format("%08x:%08x", address, value);
   1.768 +		break;
   1.769 +	}
   1.770 +
   1.771 +	cheatsAdd(code, buffer, address, value, -1, sizeType);
   1.772 +	return true;
   1.773 +}
   1.774 +
   1.775 +/////////////////////////////////////////////////////////////////////////////
   1.776 +// GBACheatList dialog
   1.777 +
   1.778 +GBACheatList::GBACheatList(CWnd*pParent /*=NULL*/)
   1.779 +	: CDialog(GBACheatList::IDD, pParent)
   1.780 +{
   1.781 +	//{{AFX_DATA_INIT(GBACheatList)
   1.782 +	// NOTE: the ClassWizard will add member initialization here
   1.783 +	//}}AFX_DATA_INIT
   1.784 +}
   1.785 +
   1.786 +void GBACheatList::DoDataExchange(CDataExchange*pDX)
   1.787 +{
   1.788 +	CDialog::DoDataExchange(pDX);
   1.789 +	//{{AFX_DATA_MAP(GBACheatList)
   1.790 +	DDX_Control(pDX, IDC_RESTORE, m_restore);
   1.791 +	DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
   1.792 +	//}}AFX_DATA_MAP
   1.793 +}
   1.794 +
   1.795 +BEGIN_MESSAGE_MAP(GBACheatList, CDialog)
   1.796 +//{{AFX_MSG_MAP(GBACheatList)
   1.797 +ON_BN_CLICKED(IDC_ADD_CHEAT, OnAddCheat)
   1.798 +ON_BN_CLICKED(IDC_ADD_CODE, OnAddCode)
   1.799 +ON_BN_CLICKED(IDC_ADD_CODEBREAKER, OnAddCodebreaker)
   1.800 +ON_BN_CLICKED(IDC_ADD_GAMESHARK, OnAddGameshark)
   1.801 +ON_BN_CLICKED(IDC_ENABLE, OnEnable)
   1.802 +ON_BN_CLICKED(IDC_REMOVE, OnRemove)
   1.803 +ON_BN_CLICKED(IDC_REMOVE_ALL, OnRemoveAll)
   1.804 +ON_BN_CLICKED(IDC_RESTORE, OnRestore)
   1.805 +ON_BN_CLICKED(ID_OK, OnOk)
   1.806 +ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
   1.807 +//}}AFX_MSG_MAP
   1.808 +END_MESSAGE_MAP()
   1.809 +
   1.810 +/////////////////////////////////////////////////////////////////////////////
   1.811 +// GBACheatList message handlers
   1.812 +
   1.813 +void GBACheatList::OnAddCheat()
   1.814 +{
   1.815 +	AddCheat dlg(0);
   1.816 +	dlg.DoModal();
   1.817 +	refresh();
   1.818 +}
   1.819 +
   1.820 +void GBACheatList::OnAddCode()
   1.821 +{
   1.822 +	AddCheatCode dlg;
   1.823 +	dlg.DoModal();
   1.824 +	refresh();
   1.825 +}
   1.826 +
   1.827 +void GBACheatList::OnAddCodebreaker()
   1.828 +{
   1.829 +	AddCBACode dlg;
   1.830 +	dlg.DoModal();
   1.831 +	refresh();
   1.832 +}
   1.833 +
   1.834 +void GBACheatList::OnAddGameshark()
   1.835 +{
   1.836 +	AddGSACode dlg;
   1.837 +	dlg.DoModal();
   1.838 +	refresh();
   1.839 +}
   1.840 +
   1.841 +void GBACheatList::OnEnable()
   1.842 +{
   1.843 +	int mark  = m_list.GetSelectionMark();
   1.844 +	int count = m_list.GetItemCount();
   1.845 +
   1.846 +	if (mark != -1)
   1.847 +	{
   1.848 +		LVITEM item;
   1.849 +		for (int i = 0; i < count; i++)
   1.850 +		{
   1.851 +			memset(&item, 0, sizeof(item));
   1.852 +			item.mask      = LVIF_PARAM|LVIF_STATE;
   1.853 +			item.stateMask = LVIS_SELECTED;
   1.854 +			item.iItem     = i;
   1.855 +			if (m_list.GetItem(&item))
   1.856 +			{
   1.857 +				if (item.state & LVIS_SELECTED)
   1.858 +				{
   1.859 +					if (cheatsList[item.lParam].enabled)
   1.860 +						cheatsDisable(item.lParam);
   1.861 +					else
   1.862 +						cheatsEnable(item.lParam);
   1.863 +				}
   1.864 +			}
   1.865 +		}
   1.866 +		refresh();
   1.867 +	}
   1.868 +}
   1.869 +
   1.870 +void GBACheatList::OnRemove()
   1.871 +{
   1.872 +	int mark  = m_list.GetSelectionMark();
   1.873 +	int count = m_list.GetItemCount();
   1.874 +
   1.875 +	if (mark != -1)
   1.876 +	{
   1.877 +		for (int i = count - 1; i >= 0; i--)
   1.878 +		{
   1.879 +			LVITEM item;
   1.880 +			memset(&item, 0, sizeof(item));
   1.881 +			item.mask      = LVIF_PARAM|LVIF_STATE;
   1.882 +			item.iItem     = i;
   1.883 +			item.stateMask = LVIS_SELECTED;
   1.884 +			if (m_list.GetItem(&item))
   1.885 +			{
   1.886 +				if (item.state & LVIS_SELECTED)
   1.887 +				{
   1.888 +					cheatsDelete(item.lParam, restoreValues);
   1.889 +				}
   1.890 +			}
   1.891 +		}
   1.892 +		refresh();
   1.893 +	}
   1.894 +}
   1.895 +
   1.896 +void GBACheatList::OnRemoveAll()
   1.897 +{
   1.898 +	cheatsDeleteAll(restoreValues);
   1.899 +	refresh();
   1.900 +}
   1.901 +
   1.902 +void GBACheatList::OnRestore()
   1.903 +{
   1.904 +	restoreValues = !restoreValues;
   1.905 +	regSetDwordValue("cheatsRestore", restoreValues);
   1.906 +}
   1.907 +
   1.908 +void GBACheatList::OnOk()
   1.909 +{
   1.910 +	EndDialog(TRUE);
   1.911 +}
   1.912 +
   1.913 +void GBACheatList::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
   1.914 +{
   1.915 +	if (m_list.GetSelectionMark() != -1)
   1.916 +	{
   1.917 +		GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
   1.918 +		GetDlgItem(IDC_ENABLE)->EnableWindow(TRUE);
   1.919 +	}
   1.920 +	else
   1.921 +	{
   1.922 +		GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
   1.923 +		GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
   1.924 +	}
   1.925 +
   1.926 +	if (!duringRefresh)
   1.927 +	{
   1.928 +		LPNMLISTVIEW l = (LPNMLISTVIEW)pNMHDR;
   1.929 +		if (l->uChanged & LVIF_STATE)
   1.930 +		{
   1.931 +			if (((l->uOldState & LVIS_STATEIMAGEMASK)>>12) !=
   1.932 +			    (((l->uNewState & LVIS_STATEIMAGEMASK)>>12)))
   1.933 +			{
   1.934 +				if (m_list.GetCheck(l->iItem))
   1.935 +					cheatsEnable(l->lParam);
   1.936 +				else
   1.937 +					cheatsDisable(l->lParam);
   1.938 +				refresh();
   1.939 +			}
   1.940 +		}
   1.941 +	}
   1.942 +
   1.943 +	*pResult = 0;
   1.944 +}
   1.945 +
   1.946 +BOOL GBACheatList::OnInitDialog()
   1.947 +{
   1.948 +	CDialog::OnInitDialog();
   1.949 +
   1.950 +	CString temp = winResLoadString(IDS_CODE);
   1.951 +	m_list.InsertColumn(0, temp, LVCFMT_LEFT, 170, 0);
   1.952 +	temp = winResLoadString(IDS_DESCRIPTION);
   1.953 +	m_list.InsertColumn(1, temp, LVCFMT_LEFT, 150, 1);
   1.954 +	temp = winResLoadString(IDS_STATUS);
   1.955 +	m_list.InsertColumn(2, temp, LVCFMT_LEFT, 80, 1);
   1.956 +
   1.957 +	m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
   1.958 +	               TRUE);
   1.959 +
   1.960 +	m_list.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
   1.961 +
   1.962 +	duringRefresh = false;
   1.963 +
   1.964 +	restoreValues = regQueryDwordValue("cheatsRestore", 0) ?
   1.965 +	                true : false;
   1.966 +
   1.967 +	m_restore.SetCheck(restoreValues);
   1.968 +
   1.969 +	refresh();
   1.970 +	GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
   1.971 +	GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
   1.972 +	CenterWindow();
   1.973 +
   1.974 +	return TRUE; // return TRUE unless you set the focus to a control
   1.975 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.976 +}
   1.977 +
   1.978 +void GBACheatList::refresh()
   1.979 +{
   1.980 +	duringRefresh = true;
   1.981 +	m_list.DeleteAllItems();
   1.982 +
   1.983 +	CString buffer;
   1.984 +
   1.985 +	for (int i = 0; i < cheatsNumber; i++)
   1.986 +	{
   1.987 +		LVITEM item;
   1.988 +
   1.989 +		item.mask      = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
   1.990 +		item.iItem     = i;
   1.991 +		item.iSubItem  = 0;
   1.992 +		item.lParam    = i;
   1.993 +		item.state     = 0;
   1.994 +		item.stateMask = 0;
   1.995 +		item.pszText   = cheatsList[i].codestring;
   1.996 +		m_list.InsertItem(&item);
   1.997 +
   1.998 +		m_list.SetCheck(i, (cheatsList[i].enabled) ? TRUE : FALSE);
   1.999 +
  1.1000 +		m_list.SetItemText(i, 1, cheatsList[i].desc);
  1.1001 +
  1.1002 +		buffer = (cheatsList[i].enabled) ? 'E' : 'D';
  1.1003 +		m_list.SetItemText(i, 2, buffer);
  1.1004 +	}
  1.1005 +	duringRefresh = false;
  1.1006 +}
  1.1007 +
  1.1008 +/////////////////////////////////////////////////////////////////////////////
  1.1009 +// AddGSACode dialog
  1.1010 +
  1.1011 +AddGSACode::AddGSACode(CWnd*pParent /*=NULL*/)
  1.1012 +	: CDialog(AddGSACode::IDD, pParent)
  1.1013 +{
  1.1014 +	//{{AFX_DATA_INIT(AddGSACode)
  1.1015 +	// NOTE: the ClassWizard will add member initialization here
  1.1016 +	//}}AFX_DATA_INIT
  1.1017 +}
  1.1018 +
  1.1019 +void AddGSACode::DoDataExchange(CDataExchange*pDX)
  1.1020 +{
  1.1021 +	CDialog::DoDataExchange(pDX);
  1.1022 +	//{{AFX_DATA_MAP(AddGSACode)
  1.1023 +	DDX_Control(pDX, IDC_DESC, m_desc);
  1.1024 +	DDX_Control(pDX, IDC_CODE, m_code);
  1.1025 +	//}}AFX_DATA_MAP
  1.1026 +}
  1.1027 +
  1.1028 +BEGIN_MESSAGE_MAP(AddGSACode, CDialog)
  1.1029 +//{{AFX_MSG_MAP(AddGSACode)
  1.1030 +ON_BN_CLICKED(ID_OK, OnOk)
  1.1031 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  1.1032 +//}}AFX_MSG_MAP
  1.1033 +END_MESSAGE_MAP()
  1.1034 +
  1.1035 +/////////////////////////////////////////////////////////////////////////////
  1.1036 +// AddGSACode message handlers
  1.1037 +
  1.1038 +void AddGSACode::OnOk()
  1.1039 +{
  1.1040 +	CString desc;
  1.1041 +	CString buffer;
  1.1042 +	CString part1;
  1.1043 +	CString code;
  1.1044 +	CString token;
  1.1045 +
  1.1046 +	m_code.GetWindowText(buffer);
  1.1047 +	m_desc.GetWindowText(desc);
  1.1048 +
  1.1049 +	StringTokenizer st(buffer, " \t\n\r");
  1.1050 +	part1.Empty();
  1.1051 +	const char *t = st.next();
  1.1052 +	while (t)
  1.1053 +	{
  1.1054 +		token = t;
  1.1055 +		token.MakeUpper();
  1.1056 +		if (token.GetLength() == 16)
  1.1057 +			cheatsAddGSACode(token, desc, false);
  1.1058 +		else if (token.GetLength() == 12)
  1.1059 +		{
  1.1060 +			code  = token.Left(8);
  1.1061 +			code += " ";
  1.1062 +			code += token.Right(4);
  1.1063 +			cheatsAddCBACode(code, desc);
  1.1064 +		}
  1.1065 +		else if (part1.IsEmpty())
  1.1066 +			part1 = token;
  1.1067 +		else
  1.1068 +		{
  1.1069 +			if (token.GetLength() == 4)
  1.1070 +			{
  1.1071 +				code  = part1;
  1.1072 +				code += " ";
  1.1073 +				code += token;
  1.1074 +				cheatsAddCBACode(code, desc);
  1.1075 +			}
  1.1076 +			else
  1.1077 +			{
  1.1078 +				code = part1 + token;
  1.1079 +				cheatsAddGSACode(code, desc, true);
  1.1080 +			}
  1.1081 +			part1.Empty();
  1.1082 +		}
  1.1083 +
  1.1084 +		t = st.next();
  1.1085 +	}
  1.1086 +	EndDialog(TRUE);
  1.1087 +}
  1.1088 +
  1.1089 +void AddGSACode::OnCancel()
  1.1090 +{
  1.1091 +	EndDialog(FALSE);
  1.1092 +}
  1.1093 +
  1.1094 +BOOL AddGSACode::OnInitDialog()
  1.1095 +{
  1.1096 +	CDialog::OnInitDialog();
  1.1097 +
  1.1098 +	m_code.LimitText(1024);
  1.1099 +	m_desc.LimitText(32);
  1.1100 +	CString title = winResLoadString(IDS_ADD_GSA_CODE);
  1.1101 +	SetWindowText(title);
  1.1102 +	CenterWindow();
  1.1103 +
  1.1104 +	return TRUE; // return TRUE unless you set the focus to a control
  1.1105 +	             // EXCEPTION: OCX Property Pages should return FALSE
  1.1106 +}
  1.1107 +
  1.1108 +/////////////////////////////////////////////////////////////////////////////
  1.1109 +// AddCBACode dialog
  1.1110 +
  1.1111 +AddCBACode::AddCBACode(CWnd*pParent /*=NULL*/)
  1.1112 +	: CDialog(AddCBACode::IDD, pParent)
  1.1113 +{
  1.1114 +	//{{AFX_DATA_INIT(AddCBACode)
  1.1115 +	// NOTE: the ClassWizard will add member initialization here
  1.1116 +	//}}AFX_DATA_INIT
  1.1117 +}
  1.1118 +
  1.1119 +void AddCBACode::DoDataExchange(CDataExchange*pDX)
  1.1120 +{
  1.1121 +	CDialog::DoDataExchange(pDX);
  1.1122 +	//{{AFX_DATA_MAP(AddCBACode)
  1.1123 +	DDX_Control(pDX, IDC_DESC, m_desc);
  1.1124 +	DDX_Control(pDX, IDC_CODE, m_code);
  1.1125 +	//}}AFX_DATA_MAP
  1.1126 +}
  1.1127 +
  1.1128 +BEGIN_MESSAGE_MAP(AddCBACode, CDialog)
  1.1129 +//{{AFX_MSG_MAP(AddCBACode)
  1.1130 +ON_BN_CLICKED(ID_OK, OnOk)
  1.1131 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  1.1132 +//}}AFX_MSG_MAP
  1.1133 +END_MESSAGE_MAP()
  1.1134 +
  1.1135 +/////////////////////////////////////////////////////////////////////////////
  1.1136 +// AddCBACode message handlers
  1.1137 +
  1.1138 +void AddCBACode::OnOk()
  1.1139 +{
  1.1140 +	CString desc;
  1.1141 +	CString buffer;
  1.1142 +	CString part1;
  1.1143 +	CString code;
  1.1144 +	CString token;
  1.1145 +
  1.1146 +	m_code.GetWindowText(buffer);
  1.1147 +	m_desc.GetWindowText(desc);
  1.1148 +
  1.1149 +	StringTokenizer st(buffer, " \t\n\r");
  1.1150 +	part1.Empty();
  1.1151 +	const char *t = st.next();
  1.1152 +	while (t)
  1.1153 +	{
  1.1154 +		token = t;
  1.1155 +		token.MakeUpper();
  1.1156 +		if (token.GetLength() == 16)
  1.1157 +			cheatsAddGSACode(token, desc, false);
  1.1158 +		else if (token.GetLength() == 12)
  1.1159 +		{
  1.1160 +			code  = token.Left(8);
  1.1161 +			code += " ";
  1.1162 +			code += token.Right(4);
  1.1163 +			cheatsAddCBACode(code, desc);
  1.1164 +		}
  1.1165 +		else if (part1.IsEmpty())
  1.1166 +			part1 = token;
  1.1167 +		else
  1.1168 +		{
  1.1169 +			if (token.GetLength() == 4)
  1.1170 +			{
  1.1171 +				code  = part1;
  1.1172 +				code += " ";
  1.1173 +				code += token;
  1.1174 +				cheatsAddCBACode(code, desc);
  1.1175 +			}
  1.1176 +			else
  1.1177 +			{
  1.1178 +				code = part1 + token;
  1.1179 +				cheatsAddGSACode(code, desc, true);
  1.1180 +			}
  1.1181 +			part1.Empty();
  1.1182 +		}
  1.1183 +
  1.1184 +		t = st.next();
  1.1185 +	}
  1.1186 +	EndDialog(TRUE);
  1.1187 +}
  1.1188 +
  1.1189 +void AddCBACode::OnCancel()
  1.1190 +{
  1.1191 +	EndDialog(FALSE);
  1.1192 +}
  1.1193 +
  1.1194 +BOOL AddCBACode::OnInitDialog()
  1.1195 +{
  1.1196 +	CDialog::OnInitDialog();
  1.1197 +
  1.1198 +	m_code.LimitText(1024);
  1.1199 +	m_desc.LimitText(32);
  1.1200 +	CString title = winResLoadString(IDS_ADD_CBA_CODE);
  1.1201 +	SetWindowText(title);
  1.1202 +	CenterWindow();
  1.1203 +
  1.1204 +	return TRUE; // return TRUE unless you set the focus to a control
  1.1205 +	             // EXCEPTION: OCX Property Pages should return FALSE
  1.1206 +}
  1.1207 +
  1.1208 +/////////////////////////////////////////////////////////////////////////////
  1.1209 +// AddCheatCode dialog
  1.1210 +
  1.1211 +AddCheatCode::AddCheatCode(CWnd*pParent /*=NULL*/)
  1.1212 +	: CDialog(AddCheatCode::IDD, pParent)
  1.1213 +{
  1.1214 +	//{{AFX_DATA_INIT(AddCheatCode)
  1.1215 +	// NOTE: the ClassWizard will add member initialization here
  1.1216 +	//}}AFX_DATA_INIT
  1.1217 +}
  1.1218 +
  1.1219 +void AddCheatCode::DoDataExchange(CDataExchange*pDX)
  1.1220 +{
  1.1221 +	CDialog::DoDataExchange(pDX);
  1.1222 +	//{{AFX_DATA_MAP(AddCheatCode)
  1.1223 +	DDX_Control(pDX, IDC_DESC, m_desc);
  1.1224 +	DDX_Control(pDX, IDC_CODE, m_code);
  1.1225 +	//}}AFX_DATA_MAP
  1.1226 +}
  1.1227 +
  1.1228 +BEGIN_MESSAGE_MAP(AddCheatCode, CDialog)
  1.1229 +//{{AFX_MSG_MAP(AddCheatCode)
  1.1230 +ON_BN_CLICKED(ID_OK, OnOk)
  1.1231 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  1.1232 +//}}AFX_MSG_MAP
  1.1233 +END_MESSAGE_MAP()
  1.1234 +
  1.1235 +/////////////////////////////////////////////////////////////////////////////
  1.1236 +// AddCheatCode message handlers
  1.1237 +
  1.1238 +void AddCheatCode::OnOk()
  1.1239 +{
  1.1240 +	CString desc;
  1.1241 +	CString buffer;
  1.1242 +	CString token;
  1.1243 +
  1.1244 +	m_code.GetWindowText(buffer);
  1.1245 +	m_desc.GetWindowText(desc);
  1.1246 +
  1.1247 +	StringTokenizer st(buffer, " \t\n\r");
  1.1248 +	const char *    t = st.next();
  1.1249 +	while (t)
  1.1250 +	{
  1.1251 +		token = t;
  1.1252 +		token.MakeUpper();
  1.1253 +		cheatsAddCheatCode(token, desc);
  1.1254 +		t = st.next();
  1.1255 +	}
  1.1256 +	EndDialog(TRUE);
  1.1257 +}
  1.1258 +
  1.1259 +void AddCheatCode::OnCancel()
  1.1260 +{
  1.1261 +	EndDialog(FALSE);
  1.1262 +}
  1.1263 +
  1.1264 +BOOL AddCheatCode::OnInitDialog()
  1.1265 +{
  1.1266 +	CDialog::OnInitDialog();
  1.1267 +
  1.1268 +	m_code.LimitText(1024);
  1.1269 +	m_desc.LimitText(32);
  1.1270 +	CString title = winResLoadString(IDS_ADD_CHEAT_CODE);
  1.1271 +	SetWindowText(title);
  1.1272 +	CenterWindow();
  1.1273 +
  1.1274 +	return TRUE; // return TRUE unless you set the focus to a control
  1.1275 +	             // EXCEPTION: OCX Property Pages should return FALSE
  1.1276 +}
  1.1277 +
  1.1278 +void GBACheatSearch::OnBnClickedCheatrefreshbutton()
  1.1279 +{
  1.1280 +	addChanges(false);
  1.1281 +}
  1.1282 +