2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project 64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-05-23 10:05:41 +00:00
|
|
|
#include "stdafx.h"
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-14 23:28:15 +00:00
|
|
|
#include "Settings/SettingType/SettingsType-Cheats.h"
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
enum { WM_EDITCHEAT = WM_USER + 0x120 };
|
|
|
|
enum { UM_CHANGECODEEXTENSION = WM_USER + 0x121 };
|
|
|
|
|
2015-02-26 10:57:51 +00:00
|
|
|
CCheats::CCheats (const CN64Rom * Rom ) :
|
|
|
|
m_Rom(Rom),
|
2008-09-18 03:15:49 +00:00
|
|
|
m_rcList(new RECT),
|
|
|
|
m_rcAdd(new RECT),
|
|
|
|
m_EditCheat(-1),
|
|
|
|
m_DeleteingEntries(false),
|
|
|
|
m_CheatSelectionChanged(false)
|
|
|
|
{
|
|
|
|
m_Window = NULL;
|
|
|
|
m_hSelectCheat = NULL;
|
|
|
|
m_AddCheat = NULL;
|
|
|
|
m_hCheatTree = NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
CCheats::~CCheats()
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
delete m_rcList;
|
|
|
|
delete m_rcAdd;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCheats::LoadCode (int CheatNo, LPCSTR CheatString)
|
|
|
|
{
|
|
|
|
if (!IsValid16BitCode(CheatString))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * ReadPos = CheatString;
|
|
|
|
|
|
|
|
CODES Code;
|
|
|
|
while (ReadPos)
|
|
|
|
{
|
|
|
|
GAMESHARK_CODE CodeEntry;
|
|
|
|
|
|
|
|
CodeEntry.Command = AsciiToHex(ReadPos);
|
|
|
|
ReadPos = strchr(ReadPos,' ');
|
|
|
|
if (ReadPos == NULL) { break; }
|
|
|
|
ReadPos +=1;
|
|
|
|
|
|
|
|
if (strncmp(ReadPos,"????",4) == 0) {
|
|
|
|
if (CheatNo < 0 || CheatNo > MaxCheats) { return false; }
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr CheatExt = g_Settings->LoadStringIndex(Cheat_Extension,CheatNo);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (CheatExt.empty()) { return false; }
|
|
|
|
CodeEntry.Value = CheatExt[0] == '$'?(WORD)AsciiToHex(&CheatExt.c_str()[1]):(WORD)atol(CheatExt.c_str());
|
|
|
|
} else if (strncmp(ReadPos,"??",2) == 0) {
|
|
|
|
if (CheatNo < 0 || CheatNo > MaxCheats) { return false; }
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr CheatExt = g_Settings->LoadStringIndex(Cheat_Extension,CheatNo);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (CheatExt.empty()) { return false; }
|
|
|
|
CodeEntry.Value = (BYTE)(AsciiToHex(ReadPos));
|
|
|
|
CodeEntry.Value |= (CheatExt[0] == '$'?(BYTE)AsciiToHex(&CheatExt.c_str()[1]):(BYTE)atol(CheatExt.c_str())) << 16;
|
|
|
|
} else if (strncmp(&ReadPos[2],"??",2) == 0) {
|
|
|
|
if (CheatNo < 0 || CheatNo > MaxCheats) { return false; }
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr CheatExt = g_Settings->LoadStringIndex(Cheat_Extension,CheatNo);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (CheatExt.empty()) { return false; }
|
|
|
|
CodeEntry.Value = (WORD)(AsciiToHex(ReadPos) << 16);
|
|
|
|
CodeEntry.Value |= CheatExt[0] == '$'?(BYTE)AsciiToHex(&CheatExt.c_str()[1]):(BYTE)atol(CheatExt.c_str());
|
|
|
|
} else {
|
|
|
|
CodeEntry.Value = (WORD)AsciiToHex(ReadPos);
|
|
|
|
}
|
|
|
|
Code.push_back(CodeEntry);
|
|
|
|
|
|
|
|
ReadPos = strchr(ReadPos,',');
|
|
|
|
if (ReadPos == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ReadPos++;
|
|
|
|
}
|
|
|
|
if (Code.size() == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Codes.push_back(Code);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-26 10:57:51 +00:00
|
|
|
void CCheats::LoadPermCheats (CPlugins * Plugins)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadBool(Debugger_DisableGameFixes))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int CheatNo = 0; CheatNo < MaxCheats; CheatNo ++ )
|
|
|
|
{
|
2008-11-14 20:51:06 +00:00
|
|
|
stdstr LineEntry;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (!g_Settings->LoadStringIndex(Rdb_GameCheatFix,CheatNo,LineEntry) || LineEntry.empty())
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2015-02-26 10:57:51 +00:00
|
|
|
|
|
|
|
stdstr CheatPlugins;
|
|
|
|
bool LoadEntry = true;
|
|
|
|
if (g_Settings->LoadStringIndex(Rdb_GameCheatFixPlugin,CheatNo,CheatPlugins) && !CheatPlugins.empty())
|
|
|
|
{
|
|
|
|
LoadEntry = false;
|
|
|
|
|
|
|
|
strvector PluginList = CheatPlugins.Tokenize(',');
|
|
|
|
for (size_t i = 0, n = PluginList.size(); i < n; i++)
|
|
|
|
{
|
|
|
|
stdstr PluginName = PluginList[i].Trim();
|
|
|
|
if (strstr(Plugins->Gfx()->PluginName(),PluginName.c_str()) != NULL)
|
|
|
|
{
|
|
|
|
LoadEntry = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strstr(Plugins->Audio()->PluginName(),PluginName.c_str()) != NULL)
|
|
|
|
{
|
|
|
|
LoadEntry = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strstr(Plugins->RSP()->PluginName(),PluginName.c_str()) != NULL)
|
|
|
|
{
|
|
|
|
LoadEntry = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strstr(Plugins->Control()->PluginName(),PluginName.c_str()) != NULL)
|
|
|
|
{
|
|
|
|
LoadEntry = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LoadEntry)
|
|
|
|
{
|
|
|
|
LoadCode(-1, LineEntry.c_str());
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 06:58:41 +00:00
|
|
|
void CCheats::LoadCheats(bool DisableSelected, CPlugins * Plugins)
|
2015-02-26 10:57:51 +00:00
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
m_CheatSelectionChanged = false;
|
|
|
|
m_Codes.clear();
|
2015-03-12 06:58:41 +00:00
|
|
|
LoadPermCheats(Plugins);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
for (int CheatNo = 0; CheatNo < MaxCheats; CheatNo ++ )
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr LineEntry = g_Settings->LoadStringIndex(Cheat_Entry,CheatNo);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (LineEntry.empty()) { break; }
|
2012-11-17 01:02:04 +00:00
|
|
|
if (!g_Settings->LoadBoolIndex(Cheat_Active,CheatNo))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (DisableSelected)
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveBoolIndex(Cheat_Active,CheatNo,false);
|
2008-09-18 03:15:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
//Find the start and end of the name which is surrounded in ""
|
2008-09-18 03:15:49 +00:00
|
|
|
int StartOfName = LineEntry.find("\"");
|
|
|
|
if (StartOfName == -1) { continue; }
|
|
|
|
int EndOfName = LineEntry.find("\"",StartOfName + 1);
|
|
|
|
if (EndOfName == -1) { continue; }
|
|
|
|
|
|
|
|
LoadCode(CheatNo, &LineEntry.c_str()[EndOfName + 2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************
|
|
|
|
ConvertXP64Address
|
|
|
|
|
|
|
|
Purpose: Decode encoded XP64 address to physical address
|
|
|
|
Parameters:
|
|
|
|
Returns:
|
|
|
|
Author: Witten
|
|
|
|
|
|
|
|
********************************************************************************************/
|
|
|
|
DWORD ConvertXP64Address (DWORD Address) {
|
|
|
|
DWORD tmpAddress;
|
|
|
|
|
|
|
|
tmpAddress = (Address ^ 0x68000000) & 0xFF000000;
|
|
|
|
tmpAddress += ((Address + 0x002B0000) ^ 0x00810000) & 0x00FF0000;
|
|
|
|
tmpAddress += ((Address + 0x00002B00) ^ 0x00008200) & 0x0000FF00;
|
|
|
|
tmpAddress += ((Address + 0x0000002B) ^ 0x00000083) & 0x000000FF;
|
|
|
|
return tmpAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************
|
|
|
|
ConvertXP64Value
|
|
|
|
|
|
|
|
Purpose: Decode encoded XP64 value
|
|
|
|
Parameters:
|
|
|
|
Returns:
|
|
|
|
Author: Witten
|
|
|
|
|
|
|
|
********************************************************************************************/
|
|
|
|
WORD ConvertXP64Value (WORD Value) {
|
|
|
|
WORD tmpValue;
|
|
|
|
|
|
|
|
tmpValue = ((Value + 0x2B00) ^ 0x8400) & 0xFF00;
|
|
|
|
tmpValue += ((Value + 0x002B) ^ 0x0085) & 0x00FF;
|
|
|
|
return tmpValue;
|
|
|
|
}
|
|
|
|
|
2012-11-17 01:26:00 +00:00
|
|
|
void CCheats::ApplyCheats(CMipsMemory * MMU)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-10-23 18:53:01 +00:00
|
|
|
for (size_t CurrentCheat = 0; CurrentCheat < m_Codes.size(); CurrentCheat ++)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
const CODES & CodeEntry = m_Codes[CurrentCheat];
|
2010-11-12 05:30:08 +00:00
|
|
|
for (size_t CurrentEntry = 0; CurrentEntry < CodeEntry.size();)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-05-02 22:14:19 +00:00
|
|
|
CurrentEntry += ApplyCheatEntry(MMU, CodeEntry,CurrentEntry, true);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-17 01:26:00 +00:00
|
|
|
void CCheats::ApplyGSButton (CMipsMemory * MMU)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
DWORD Address;
|
2010-11-12 05:30:08 +00:00
|
|
|
for (size_t CurrentCheat = 0; CurrentCheat < m_Codes.size(); CurrentCheat ++)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
const CODES & CodeEntry = m_Codes[CurrentCheat];
|
2010-10-23 18:53:01 +00:00
|
|
|
for (size_t CurrentEntry = 0; CurrentEntry < CodeEntry.size(); CurrentEntry ++)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
const GAMESHARK_CODE & Code = CodeEntry[CurrentEntry];
|
|
|
|
switch (Code.Command & 0xFF000000) {
|
|
|
|
case 0x88000000:
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->SB_VAddr(Address,(BYTE)Code.Value);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0x89000000:
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->SH_VAddr(Address,Code.Value);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
// Xplorer64
|
|
|
|
case 0xA8000000:
|
|
|
|
Address = 0x80000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->SB_VAddr(Address,(BYTE)ConvertXP64Value(Code.Value));
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xA9000000:
|
|
|
|
Address = 0x80000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->SH_VAddr(Address,ConvertXP64Value(Code.Value));
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCheats::IsValid16BitCode (LPCSTR CheatString) const
|
|
|
|
{
|
|
|
|
const char * ReadPos = CheatString;
|
|
|
|
bool GSButtonCheat = false, FirstEntry = true;
|
|
|
|
|
|
|
|
while (ReadPos)
|
|
|
|
{
|
|
|
|
GAMESHARK_CODE CodeEntry;
|
|
|
|
|
|
|
|
CodeEntry.Command = AsciiToHex(ReadPos);
|
|
|
|
ReadPos = strchr(ReadPos,' ');
|
|
|
|
if (ReadPos == NULL) { break; }
|
|
|
|
ReadPos +=1;
|
|
|
|
|
|
|
|
//validate Code Entry
|
|
|
|
switch (CodeEntry.Command & 0xFF000000) {
|
|
|
|
case 0x50000000:
|
|
|
|
case 0x80000000:
|
|
|
|
case 0xA0000000:
|
|
|
|
case 0xD0000000:
|
|
|
|
case 0xD2000000:
|
|
|
|
case 0xC8000000:
|
|
|
|
case 0xE8000000:
|
|
|
|
case 0x10000000: // Xplorer64
|
|
|
|
break;
|
|
|
|
case 0x81000000:
|
|
|
|
case 0xA1000000:
|
|
|
|
case 0xD1000000: // Added by Witten (witten@pj64cheats.net)
|
|
|
|
case 0xD3000000:
|
|
|
|
if (((CodeEntry.Command & 0xFFFFFF) & 1) == 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x88000000:
|
|
|
|
case 0xA8000000:
|
|
|
|
if (FirstEntry) { GSButtonCheat = true; }
|
|
|
|
if (!GSButtonCheat) { return false; }
|
|
|
|
break;
|
|
|
|
case 0x89000000:
|
|
|
|
if (FirstEntry) { GSButtonCheat = true; }
|
|
|
|
if (!GSButtonCheat) { return false; }
|
|
|
|
if (((CodeEntry.Command & 0xFFFFFF) & 1) == 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xA9000000:
|
|
|
|
if (FirstEntry) { GSButtonCheat = true; }
|
|
|
|
if (!GSButtonCheat) { return false; }
|
|
|
|
if (((ConvertXP64Address(CodeEntry.Command) & 0xFFFFFF) & 1) == 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x11000000: // Xplorer64
|
|
|
|
case 0xE9000000:
|
|
|
|
case 0xC9000000:
|
|
|
|
if (((ConvertXP64Address(CodeEntry.Command) & 0xFFFFFF) & 1) == 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FirstEntry = false;
|
|
|
|
|
|
|
|
ReadPos = strchr(ReadPos,',');
|
|
|
|
if (ReadPos == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ReadPos++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-02 22:14:19 +00:00
|
|
|
int CCheats::ApplyCheatEntry (CMipsMemory * MMU, const CODES & CodeEntry, int CurrentEntry, bool Execute )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-11-12 05:30:08 +00:00
|
|
|
if (CurrentEntry < 0 || CurrentEntry >= (int)CodeEntry.size())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const GAMESHARK_CODE & Code = CodeEntry[CurrentEntry];
|
2010-05-22 04:47:15 +00:00
|
|
|
DWORD Address;
|
|
|
|
WORD wMemory;
|
|
|
|
BYTE bMemory;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
switch (Code.Command & 0xFF000000) {
|
|
|
|
// Gameshark / AR
|
|
|
|
case 0x50000000: // Added by Witten (witten@pj64cheats.net)
|
|
|
|
{
|
2010-10-23 18:53:01 +00:00
|
|
|
if ((CurrentEntry + 1) >= (int)CodeEntry.size())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GAMESHARK_CODE & NextCodeEntry = CodeEntry[CurrentEntry + 1];
|
|
|
|
int numrepeats = (Code.Command & 0x0000FF00) >> 8;
|
|
|
|
int offset = Code.Command & 0x000000FF;
|
|
|
|
int incr = Code.Value;
|
2010-09-22 21:43:42 +00:00
|
|
|
int i;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
switch (NextCodeEntry.Command & 0xFF000000) {
|
|
|
|
case 0x10000000: // Xplorer64
|
|
|
|
case 0x80000000:
|
|
|
|
Address = 0x80000000 | (NextCodeEntry.Command & 0xFFFFFF);
|
2010-05-22 04:47:15 +00:00
|
|
|
wMemory = NextCodeEntry.Value;
|
2010-09-22 21:43:42 +00:00
|
|
|
for (i=0; i<numrepeats; i++) {
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->SB_VAddr(Address,(BYTE)wMemory);
|
2008-09-18 03:15:49 +00:00
|
|
|
Address += offset;
|
2012-10-06 04:09:17 +00:00
|
|
|
wMemory += (WORD)incr;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
case 0x11000000: // Xplorer64
|
|
|
|
case 0x81000000:
|
|
|
|
Address = 0x80000000 | (NextCodeEntry.Command & 0xFFFFFF);
|
2010-05-22 04:47:15 +00:00
|
|
|
wMemory = NextCodeEntry.Value;
|
2010-09-22 21:43:42 +00:00
|
|
|
for (i=0; i<numrepeats; i++) {
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->SH_VAddr(Address,wMemory);
|
2008-09-18 03:15:49 +00:00
|
|
|
Address += offset;
|
2012-10-06 04:09:17 +00:00
|
|
|
wMemory += (WORD)incr;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
default: return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x80000000:
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SB_VAddr(Address,(BYTE)Code.Value); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0x81000000:
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SH_VAddr(Address,Code.Value); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xA0000000:
|
|
|
|
Address = 0xA0000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SB_VAddr(Address,(BYTE)Code.Value); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xA1000000:
|
|
|
|
Address = 0xA0000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SH_VAddr(Address,Code.Value); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xD0000000: // Added by Witten (witten@pj64cheats.net)
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->LB_VAddr(Address,bMemory);
|
2015-05-02 22:14:19 +00:00
|
|
|
if (bMemory != Code.Value) { Execute = false; }
|
2012-11-17 01:26:00 +00:00
|
|
|
return ApplyCheatEntry(MMU,CodeEntry,CurrentEntry + 1,Execute) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
case 0xD1000000: // Added by Witten (witten@pj64cheats.net)
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->LH_VAddr(Address,wMemory);
|
2015-05-02 22:14:19 +00:00
|
|
|
if (wMemory != Code.Value) { Execute = false; }
|
2012-11-17 01:26:00 +00:00
|
|
|
return ApplyCheatEntry(MMU,CodeEntry,CurrentEntry + 1,Execute) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
case 0xD2000000: // Added by Witten (witten@pj64cheats.net)
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->LB_VAddr(Address,bMemory);
|
2015-05-02 22:14:19 +00:00
|
|
|
if (bMemory == Code.Value) { Execute = false; }
|
2012-11-17 01:26:00 +00:00
|
|
|
return ApplyCheatEntry(MMU,CodeEntry,CurrentEntry + 1,Execute) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
case 0xD3000000: // Added by Witten (witten@pj64cheats.net)
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->LH_VAddr(Address,wMemory);
|
2015-05-02 22:14:19 +00:00
|
|
|
if (wMemory == Code.Value) { Execute = false; }
|
2012-11-17 01:26:00 +00:00
|
|
|
return ApplyCheatEntry(MMU,CodeEntry,CurrentEntry + 1,Execute) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
// Xplorer64 (Author: Witten)
|
|
|
|
case 0x30000000:
|
|
|
|
case 0x82000000:
|
|
|
|
case 0x84000000:
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SB_VAddr(Address,(BYTE)Code.Value); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0x31000000:
|
|
|
|
case 0x83000000:
|
|
|
|
case 0x85000000:
|
|
|
|
Address = 0x80000000 | (Code.Command & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SH_VAddr(Address,Code.Value); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xE8000000:
|
|
|
|
Address = 0x80000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SB_VAddr(Address,(BYTE)ConvertXP64Value(Code.Value)); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xE9000000:
|
|
|
|
Address = 0x80000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SH_VAddr(Address,ConvertXP64Value(Code.Value)); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xC8000000:
|
|
|
|
Address = 0xA0000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SB_VAddr(Address,(BYTE)Code.Value); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xC9000000:
|
|
|
|
Address = 0xA0000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
if (Execute) { MMU->SH_VAddr(Address,ConvertXP64Value(Code.Value)); }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case 0xB8000000:
|
|
|
|
Address = 0x80000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->LB_VAddr(Address,bMemory);
|
2015-05-02 22:14:19 +00:00
|
|
|
if (bMemory != ConvertXP64Value(Code.Value)) { Execute = false; }
|
2012-11-17 01:26:00 +00:00
|
|
|
return ApplyCheatEntry(MMU,CodeEntry,CurrentEntry + 1,Execute) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
case 0xB9000000:
|
|
|
|
Address = 0x80000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->LH_VAddr(Address,wMemory);
|
2015-05-02 22:14:19 +00:00
|
|
|
if (wMemory != ConvertXP64Value(Code.Value)) { Execute = false; }
|
2012-11-17 01:26:00 +00:00
|
|
|
return ApplyCheatEntry(MMU,CodeEntry,CurrentEntry + 1,Execute) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
case 0xBA000000:
|
|
|
|
Address = 0x80000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->LB_VAddr(Address,bMemory);
|
2015-05-02 22:14:19 +00:00
|
|
|
if (bMemory == ConvertXP64Value(Code.Value)) { Execute = false; }
|
2012-11-17 01:26:00 +00:00
|
|
|
return ApplyCheatEntry(MMU,CodeEntry,CurrentEntry + 1,Execute) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
case 0xBB000000:
|
|
|
|
Address = 0x80000000 | (ConvertXP64Address(Code.Command) & 0xFFFFFF);
|
2012-11-17 01:26:00 +00:00
|
|
|
MMU->LH_VAddr(Address,wMemory);
|
2015-05-02 22:14:19 +00:00
|
|
|
if (wMemory == ConvertXP64Value(Code.Value)) { Execute = false; }
|
2012-11-17 01:26:00 +00:00
|
|
|
return ApplyCheatEntry(MMU,CodeEntry,CurrentEntry + 1,Execute) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
case 0: return MaxGSEntries; break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DWORD CCheats::AsciiToHex (const char * HexValue) {
|
|
|
|
DWORD Count, Finish, Value = 0;
|
|
|
|
|
|
|
|
Finish = strlen(HexValue);
|
|
|
|
if (Finish > 8 ) { Finish = 8; }
|
|
|
|
|
|
|
|
for (Count = 0; Count < Finish; Count++){
|
|
|
|
Value = (Value << 4);
|
|
|
|
switch( HexValue[Count] ) {
|
|
|
|
case '0': break;
|
|
|
|
case '1': Value += 1; break;
|
|
|
|
case '2': Value += 2; break;
|
|
|
|
case '3': Value += 3; break;
|
|
|
|
case '4': Value += 4; break;
|
|
|
|
case '5': Value += 5; break;
|
|
|
|
case '6': Value += 6; break;
|
|
|
|
case '7': Value += 7; break;
|
|
|
|
case '8': Value += 8; break;
|
|
|
|
case '9': Value += 9; break;
|
|
|
|
case 'A': Value += 10; break;
|
|
|
|
case 'a': Value += 10; break;
|
|
|
|
case 'B': Value += 11; break;
|
|
|
|
case 'b': Value += 11; break;
|
|
|
|
case 'C': Value += 12; break;
|
|
|
|
case 'c': Value += 12; break;
|
|
|
|
case 'D': Value += 13; break;
|
|
|
|
case 'd': Value += 13; break;
|
|
|
|
case 'E': Value += 14; break;
|
|
|
|
case 'e': Value += 14; break;
|
|
|
|
case 'F': Value += 15; break;
|
|
|
|
case 'f': Value += 15; break;
|
|
|
|
default:
|
|
|
|
Value = (Value >> 4);
|
|
|
|
Count = Finish;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
void CCheats::AddCodeLayers (int CheatNumber, const stdstr &CheatName, HWND hParent, bool CheatActive) {
|
2008-09-18 03:15:49 +00:00
|
|
|
TV_INSERTSTRUCT tv;
|
|
|
|
|
|
|
|
//Work out text to add
|
|
|
|
char Text[500], Item[500];
|
2015-03-11 19:50:30 +00:00
|
|
|
if (CheatName.length() > (sizeof(Text) - 5)) { g_Notify->BreakPoint(__FILEW__,__LINE__); }
|
2008-09-18 03:15:49 +00:00
|
|
|
strcpy(Text,CheatName.c_str());
|
|
|
|
if (strchr(Text,'\\') > 0) { *strchr(Text,'\\') = 0; }
|
|
|
|
|
|
|
|
//See if text is already added
|
|
|
|
tv.item.mask = TVIF_TEXT;
|
|
|
|
tv.item.pszText = Item;
|
|
|
|
tv.item.cchTextMax = sizeof(Item);
|
|
|
|
tv.item.hItem = TreeView_GetChild((HWND)m_hCheatTree,hParent);
|
|
|
|
while (tv.item.hItem) {
|
|
|
|
TreeView_GetItem((HWND)m_hCheatTree,&tv.item);
|
|
|
|
if (strcmp(Text,Item) == 0) {
|
|
|
|
//If already exists then just use existing one
|
2015-01-27 05:07:44 +00:00
|
|
|
int State = TV_GetCheckState(m_hCheatTree,(HWND)tv.item.hItem);
|
2008-09-18 03:15:49 +00:00
|
|
|
if ((CheatActive && State == TV_STATE_CLEAR) || (!CheatActive && State == TV_STATE_CHECKED)) {
|
2015-01-27 05:07:44 +00:00
|
|
|
TV_SetCheckState(m_hCheatTree,(HWND)tv.item.hItem,TV_STATE_INDETERMINATE);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-10-23 18:53:01 +00:00
|
|
|
size_t StartPos = strlen(Text) + 1;
|
2008-09-18 03:15:49 +00:00
|
|
|
stdstr TempCheatName;
|
|
|
|
if (StartPos < CheatName.length())
|
|
|
|
{
|
|
|
|
TempCheatName = CheatName.substr(StartPos);
|
|
|
|
}
|
2015-01-27 05:07:44 +00:00
|
|
|
AddCodeLayers(CheatNumber,TempCheatName, (HWND)tv.item.hItem, CheatActive);
|
2008-09-18 03:15:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
tv.item.hItem = TreeView_GetNextSibling((HWND)m_hCheatTree,tv.item.hItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Add to dialog
|
|
|
|
tv.hInsertAfter = TVI_SORT;
|
|
|
|
tv.item.mask = TVIF_TEXT | TVIF_PARAM;
|
|
|
|
tv.item.pszText = Text;
|
|
|
|
tv.item.lParam = CheatNumber;
|
|
|
|
tv.hParent = (HTREEITEM)hParent;
|
2015-01-27 05:07:44 +00:00
|
|
|
hParent = (HWND)TreeView_InsertItem((HWND)m_hCheatTree,&tv);
|
2008-09-18 03:15:49 +00:00
|
|
|
TV_SetCheckState(m_hCheatTree,hParent,CheatActive?TV_STATE_CHECKED:TV_STATE_CLEAR);
|
|
|
|
|
|
|
|
if (strcmp(Text,CheatName.c_str()) == 0) { return; }
|
|
|
|
AddCodeLayers(CheatNumber,(stdstr)(CheatName.substr(strlen(Text) + 1)), hParent, CheatActive);
|
|
|
|
}
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
stdstr CCheats::GetCheatName(int CheatNo, bool AddExtension) const
|
|
|
|
{
|
2015-03-11 19:50:30 +00:00
|
|
|
if (CheatNo > MaxCheats) { g_Notify->BreakPoint(__FILEW__,__LINE__); }
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr LineEntry = g_Settings->LoadStringIndex(Cheat_Entry,CheatNo);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (LineEntry.length() == 0) { return LineEntry; }
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
//Find the start and end of the name which is surrounded in ""
|
2008-09-18 03:15:49 +00:00
|
|
|
int StartOfName = LineEntry.find("\"");
|
|
|
|
if (StartOfName == -1) { return stdstr(""); }
|
|
|
|
int EndOfName = LineEntry.find("\"",StartOfName + 1);
|
|
|
|
if (EndOfName == -1) { return stdstr(""); }
|
|
|
|
|
|
|
|
stdstr Name = LineEntry.substr(StartOfName + 1, EndOfName - StartOfName - 1 );
|
|
|
|
LPCSTR CodeString = &(LineEntry.c_str())[EndOfName + 2];
|
|
|
|
if (!IsValid16BitCode(CodeString))
|
|
|
|
{
|
|
|
|
Name.Format("*** %s",Name.c_str());
|
2013-04-17 10:34:20 +00:00
|
|
|
Name.Replace("\\","\\*** ");
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
if (AddExtension && CheatUsesCodeExtensions(LineEntry)) {
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr CheatValue(g_Settings->LoadStringIndex(Cheat_Extension,CheatNo));
|
2008-09-18 03:15:49 +00:00
|
|
|
Name.Format("%s (=>%s)",Name.c_str(),CheatValue.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCheats::CheatUsesCodeExtensions (const stdstr &LineEntry) {
|
|
|
|
//Find the start and end of the name which is surronded in ""
|
|
|
|
if (LineEntry.length() == 0){ return false; }
|
|
|
|
int StartOfName = LineEntry.find("\"");
|
|
|
|
if (StartOfName == -1) { return false; }
|
|
|
|
int EndOfName = LineEntry.find("\"",StartOfName + 1);
|
|
|
|
if (EndOfName == -1) { return false; }
|
|
|
|
|
|
|
|
//Read through the gameshark entries till you find a ??
|
|
|
|
const char *ReadPos = &(LineEntry.c_str())[EndOfName + 2];
|
|
|
|
bool CodeExtension = false;
|
|
|
|
|
2010-09-22 21:43:42 +00:00
|
|
|
for (int i = 0; i < MaxGSEntries && CodeExtension == false; i ++) {
|
2008-09-18 03:15:49 +00:00
|
|
|
if (strchr(ReadPos,' ') == NULL) { break; }
|
|
|
|
ReadPos = strchr(ReadPos,' ') + 1;
|
|
|
|
if (ReadPos[0] == '?' && ReadPos[1]== '?') { CodeExtension = true; }
|
|
|
|
if (ReadPos[2] == '?' && ReadPos[3]== '?') { CodeExtension = true; }
|
|
|
|
if (strchr(ReadPos,',') == NULL) { continue; }
|
|
|
|
ReadPos = strchr(ReadPos,',') + 1;
|
|
|
|
}
|
|
|
|
return CodeExtension;
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CCheats::RefreshCheatManager()
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
if (m_Window == NULL) { return; }
|
|
|
|
|
|
|
|
m_DeleteingEntries = true;
|
|
|
|
TreeView_DeleteAllItems((HWND)m_hCheatTree);
|
|
|
|
m_DeleteingEntries = false;
|
2010-09-22 21:43:42 +00:00
|
|
|
for (int i = 0; i < MaxCheats; i ++ ) {
|
|
|
|
stdstr Name = GetCheatName(i,true);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Name.length() == 0) { break; }
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
AddCodeLayers(i,Name,(HWND)TVI_ROOT, g_Settings->LoadBoolIndex(Cheat_Active,i) != 0);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
stdstr CCheats::GetDlgItemStr (HWND hDlg, int nIDDlgItem)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
HWND hDlgItem = GetDlgItem(hDlg,nIDDlgItem);
|
2008-09-18 03:15:49 +00:00
|
|
|
int length = SendMessage(hDlgItem, WM_GETTEXTLENGTH, 0, 0);
|
|
|
|
if (length == 0)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
stdstr Result;
|
|
|
|
Result.resize(length + 1);
|
|
|
|
|
|
|
|
GetWindowText(hDlgItem,(char *)Result.c_str(),Result.length());
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
void CCheats::SelectCheats(HWND hParent, bool BlockExecution) {
|
2008-09-18 03:15:49 +00:00
|
|
|
if (m_Window != NULL) {
|
|
|
|
SetForegroundWindow((HWND)m_Window);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hParent)
|
|
|
|
{
|
|
|
|
if (BlockExecution)
|
|
|
|
{
|
|
|
|
DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Cheats_Select),
|
|
|
|
(HWND)hParent, (DLGPROC)ManageCheatsProc,(LPARAM)this);
|
|
|
|
} else {
|
|
|
|
CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Cheats_Select),
|
|
|
|
(HWND)hParent, (DLGPROC)ManageCheatsProc,(LPARAM)this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
bool CCheats::CheatChanged (HWND hDlg)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
bool Changed = false;
|
|
|
|
if (m_EditName != GetDlgItemStr(hDlg,IDC_CODE_NAME) ||
|
|
|
|
m_EditCode != GetDlgItemStr(hDlg,IDC_CHEAT_CODES) ||
|
|
|
|
m_EditOptions != GetDlgItemStr(hDlg,IDC_CHEAT_OPTIONS) ||
|
|
|
|
m_EditNotes != GetDlgItemStr(hDlg,IDC_NOTES))
|
|
|
|
{
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
if (!Changed)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
int Result = MessageBoxW(hDlg,GS(CHEAT_CHANGED_MSG),GS(CHEAT_CHANGED_TITLE),MB_YESNOCANCEL);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Result == IDCANCEL)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Result == IDYES)
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
SendMessage(hDlg,WM_COMMAND, MAKELPARAM(IDC_ADD, 0), (LPARAM)GetDlgItem(hDlg,IDC_ADD));
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
void CCheats::RecordCheatValues ( HWND hDlg )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
m_EditName = GetDlgItemStr(hDlg,IDC_CODE_NAME);
|
|
|
|
m_EditCode = GetDlgItemStr(hDlg,IDC_CHEAT_CODES);
|
|
|
|
m_EditOptions = GetDlgItemStr(hDlg,IDC_CHEAT_OPTIONS);
|
|
|
|
m_EditNotes = GetDlgItemStr(hDlg,IDC_NOTES);
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
int CALLBACK CCheats::CheatAddProc (HWND hDlg,DWORD uMsg,DWORD wParam, DWORD lParam)
|
|
|
|
{
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
CCheats * _this = (CCheats *)lParam;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetProp(hDlg,"Class",_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowTextW(hDlg,GS(CHEAT_ADDCHEAT_FRAME));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_NAME),GS(CHEAT_ADDCHEAT_NAME));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_CODE),GS(CHEAT_ADDCHEAT_CODE));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_LABEL_OPTIONS),GS(CHEAT_ADDCHEAT_OPT));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_CODE_DES),GS(CHEAT_ADDCHEAT_CODEDES));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_LABEL_OPTIONS_FORMAT),GS(CHEAT_ADDCHEAT_OPTDES));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_CHEATNOTES),GS(CHEAT_ADDCHEAT_NOTES));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_NEWCHEAT),GS(CHEAT_ADDCHEAT_NEW));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_ADD),GS(CHEAT_ADDCHEAT_ADD));
|
|
|
|
SetProp(hDlg,"validcodes",false);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->RecordCheatValues(hDlg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
case IDC_CODE_NAME:
|
2015-03-04 09:36:08 +00:00
|
|
|
if (HIWORD(wParam) == EN_CHANGE)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
bool validcodes,validoptions, nooptions;
|
|
|
|
int CodeFormat;
|
|
|
|
ReadCodeString(hDlg,validcodes,validoptions,nooptions,CodeFormat);
|
2015-03-04 09:36:08 +00:00
|
|
|
if (!nooptions)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
ReadOptionsString(hDlg,validcodes,validoptions,nooptions,CodeFormat);
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
if (validcodes && (validoptions || nooptions) && SendDlgItemMessage(hDlg,IDC_CODE_NAME,EM_LINELENGTH,0,0) > 0)
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_ADD), true);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_ADD), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_CHEAT_CODES:
|
2015-03-04 09:36:08 +00:00
|
|
|
if (HIWORD(wParam) == EN_CHANGE)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
bool validcodes,validoptions, nooptions;
|
|
|
|
int CodeFormat;
|
|
|
|
ReadCodeString(hDlg,validcodes,validoptions,nooptions,CodeFormat);
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
if ((CodeFormat > 0) && !IsWindowEnabled(GetDlgItem(hDlg, IDC_LABEL_OPTIONS)) )
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_LABEL_OPTIONS), true);
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_LABEL_OPTIONS_FORMAT), true);
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_CHEAT_OPTIONS), true);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
if ((CodeFormat <= 0) && IsWindowEnabled(GetDlgItem(hDlg, IDC_LABEL_OPTIONS)) )
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_LABEL_OPTIONS), false);
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_LABEL_OPTIONS_FORMAT), false);
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_CHEAT_OPTIONS), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
if (!nooptions)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
ReadOptionsString(hDlg,validcodes,validoptions,nooptions,CodeFormat);
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
if (validcodes && (validoptions || nooptions) && SendDlgItemMessage(hDlg,IDC_CODE_NAME,EM_LINELENGTH,0,0) > 0)
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_ADD), true);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_ADD), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_CHEAT_OPTIONS:
|
2015-03-04 09:36:08 +00:00
|
|
|
if (HIWORD(wParam) == EN_CHANGE)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
bool validcodes,validoptions, nooptions;
|
|
|
|
int CodeFormat;
|
|
|
|
ReadOptionsString(hDlg,validcodes,validoptions,nooptions,CodeFormat);
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
if (validcodes && (validoptions || nooptions) && SendDlgItemMessage(hDlg,IDC_CODE_NAME,EM_LINELENGTH,0,0) > 0)
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_ADD), true);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_ADD), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_ADD:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
stdstr NewCheatName = GetDlgItemStr(hDlg,IDC_CODE_NAME);
|
2010-09-22 21:43:42 +00:00
|
|
|
int i = 0;
|
2015-03-04 09:36:08 +00:00
|
|
|
for (i = 0; i < MaxCheats; i ++)
|
|
|
|
{
|
2010-09-22 21:43:42 +00:00
|
|
|
if (_this->m_EditCheat == i)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-22 21:43:42 +00:00
|
|
|
stdstr CheatName(_this->GetCheatName(i,false));
|
2008-09-18 03:15:49 +00:00
|
|
|
if (CheatName.length() == 0)
|
|
|
|
{
|
|
|
|
if (_this->m_EditCheat < 0)
|
|
|
|
{
|
2010-09-22 21:43:42 +00:00
|
|
|
_this->m_EditCheat = i;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
if (_stricmp(CheatName.c_str(),NewCheatName.c_str()) == 0)
|
|
|
|
{
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayError(GS(MSG_CHEAT_NAME_IN_USE));
|
2015-03-04 09:36:08 +00:00
|
|
|
SetFocus(GetDlgItem(hDlg,IDC_CODE_NAME));
|
2008-09-18 03:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
if (_this->m_EditCheat < 0 && i == MaxCheats)
|
|
|
|
{
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayError(GS(MSG_MAX_CHEATS));
|
2008-09-18 03:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Update the entries
|
|
|
|
bool validcodes,validoptions, nooptions;
|
|
|
|
int CodeFormat;
|
|
|
|
stdstr_f Cheat("\"%s\"%s",NewCheatName.c_str(),ReadCodeString(hDlg,validcodes,validoptions,nooptions,CodeFormat).c_str());
|
|
|
|
stdstr Options = ReadOptionsString(hDlg,validcodes,validoptions,nooptions,CodeFormat);
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_Entry, _this->m_EditCheat,Cheat.c_str());
|
|
|
|
g_Settings->SaveStringIndex(Cheat_Notes, _this->m_EditCheat,GetDlgItemStr(hDlg,IDC_NOTES));
|
|
|
|
g_Settings->SaveStringIndex(Cheat_Options, _this->m_EditCheat,Options);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->RecordCheatValues(hDlg);
|
2010-05-14 23:28:15 +00:00
|
|
|
CSettingTypeCheats::FlushChanges();
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->RefreshCheatManager();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_NEWCHEAT:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (_this->CheatChanged(hDlg))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_this->m_EditCheat = -1;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_CODE_NAME,"");
|
|
|
|
SetDlgItemText(hDlg,IDC_CHEAT_CODES,"");
|
|
|
|
SetDlgItemText(hDlg,IDC_CHEAT_OPTIONS,"");
|
|
|
|
SetDlgItemText(hDlg,IDC_NOTES,"");
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_ADD), false);
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_CHEAT_OPTIONS), false);
|
|
|
|
SetDlgItemTextW(hDlg,IDC_ADD,GS(CHEAT_ADDNEW));
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->RecordCheatValues(hDlg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_EDITCHEAT:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->m_EditCheat = wParam;
|
|
|
|
if (_this->m_EditCheat < 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->CheatChanged(hDlg))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr CheatEntryStr = g_Settings->LoadStringIndex(Cheat_Entry,_this->m_EditCheat);
|
2008-09-18 03:15:49 +00:00
|
|
|
LPCSTR String = CheatEntryStr.c_str();
|
|
|
|
|
|
|
|
//Set Cheat Name
|
|
|
|
int len = strrchr(String,'"') - strchr(String,'"') - 1;
|
|
|
|
stdstr CheatName(strchr(String,'"') + 1);
|
|
|
|
CheatName.resize(len);
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_CODE_NAME,CheatName.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Add Gameshark codes to screen
|
|
|
|
LPCSTR ReadPos = strrchr(String,'"') + 2;
|
|
|
|
stdstr Buffer;
|
2015-03-04 09:36:08 +00:00
|
|
|
do
|
|
|
|
{
|
2010-09-22 21:43:42 +00:00
|
|
|
char * End = strchr((char *)ReadPos,',');
|
2008-09-18 03:15:49 +00:00
|
|
|
if (End)
|
|
|
|
{
|
|
|
|
Buffer.append(ReadPos,End - ReadPos);
|
2015-03-04 09:36:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
Buffer.append(ReadPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadPos = strchr(ReadPos,',');
|
2015-03-04 09:36:08 +00:00
|
|
|
if (ReadPos != NULL)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
Buffer.append("\r\n");
|
|
|
|
ReadPos += 1;
|
|
|
|
}
|
|
|
|
} while (ReadPos);
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_CHEAT_CODES,Buffer.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Add option values to screen
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr CheatOptionStr = g_Settings->LoadStringIndex(Cheat_Options,_this->m_EditCheat);
|
2008-09-18 03:15:49 +00:00
|
|
|
ReadPos = strchr(CheatOptionStr.c_str(),'$');
|
|
|
|
Buffer.erase();
|
2015-03-04 09:36:08 +00:00
|
|
|
if (ReadPos)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
ReadPos += 1;
|
2015-03-04 09:36:08 +00:00
|
|
|
do
|
|
|
|
{
|
2010-09-22 21:43:42 +00:00
|
|
|
char * End = strchr((char *)ReadPos,',');
|
2008-09-18 03:15:49 +00:00
|
|
|
if (End)
|
|
|
|
{
|
|
|
|
Buffer.append(ReadPos,End - ReadPos);
|
2015-03-04 09:36:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
Buffer.append(ReadPos);
|
|
|
|
}
|
|
|
|
ReadPos = strchr(ReadPos,'$');
|
2015-03-04 09:36:08 +00:00
|
|
|
if (ReadPos != NULL)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
Buffer.append("\r\n");
|
|
|
|
ReadPos += 1;
|
|
|
|
}
|
|
|
|
} while (ReadPos);
|
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_CHEAT_OPTIONS,Buffer.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Add cheat Notes
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr CheatNotesStr = g_Settings->LoadStringIndex(Cheat_Notes,_this->m_EditCheat);
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_NOTES,CheatNotesStr.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
SendMessage(hDlg,WM_COMMAND, MAKELPARAM(IDC_CHEAT_CODES, EN_CHANGE), (LPARAM)GetDlgItem(hDlg,IDC_CHEAT_CODES));
|
|
|
|
SetDlgItemTextW(hDlg,IDC_ADD,GS(CHEAT_EDITCHEAT_UPDATE));
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
_this->RecordCheatValues(hDlg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
int CALLBACK CCheats::CheatListProc (HWND hDlg,DWORD uMsg,DWORD wParam, DWORD lParam) {
|
2015-03-04 09:36:08 +00:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
CCheats * _this = (CCheats *)lParam;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetProp(hDlg,"Class",_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
DWORD Style;
|
|
|
|
RECT rcList;
|
|
|
|
RECT rcButton;
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_CHEATSFRAME),GS(CHEAT_LIST_FRAME));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_NOTESFRAME),GS(CHEAT_NOTES_FRAME));
|
|
|
|
SetWindowTextW(GetDlgItem(hDlg,IDC_UNMARK),GS(CHEAT_MARK_NONE));
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
GetWindowRect(GetDlgItem(hDlg, IDC_CHEATSFRAME), &rcList);
|
|
|
|
GetWindowRect(GetDlgItem(hDlg, IDC_UNMARK), &rcButton);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
_this->m_hCheatTree = (HWND)CreateWindowEx(WS_EX_CLIENTEDGE,WC_TREEVIEW,"",
|
2015-03-29 07:23:58 +00:00
|
|
|
WS_CHILD | WS_VISIBLE | WS_VSCROLL | TVS_HASLINES |
|
2008-09-18 03:15:49 +00:00
|
|
|
TVS_HASBUTTONS | TVS_LINESATROOT | TVS_DISABLEDRAGDROP |WS_TABSTOP|
|
|
|
|
TVS_FULLROWSELECT, 8, 15, rcList.right-rcList.left-16,
|
2015-03-04 09:36:08 +00:00
|
|
|
rcButton.top-rcList.top-22, hDlg, (HMENU)IDC_MYTREE, GetModuleHandle(NULL), NULL);
|
2008-09-18 03:15:49 +00:00
|
|
|
Style = GetWindowLong((HWND)_this->m_hCheatTree,GWL_STYLE);
|
|
|
|
SetWindowLong((HWND)_this->m_hCheatTree,GWL_STYLE,TVS_CHECKBOXES |TVS_SHOWSELALWAYS| Style);
|
|
|
|
|
|
|
|
//Creats an image list from the bitmap in the resource section
|
|
|
|
HIMAGELIST hImageList;
|
|
|
|
HBITMAP hBmp;
|
|
|
|
|
|
|
|
hImageList = ImageList_Create( 16,16, ILC_COLOR | ILC_MASK, 40, 40);
|
|
|
|
hBmp = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_TRI_STATE));
|
|
|
|
ImageList_AddMasked(hImageList,hBmp, RGB(255,0,255));
|
|
|
|
DeleteObject(hBmp);
|
|
|
|
|
|
|
|
TreeView_SetImageList((HWND)_this->m_hCheatTree,hImageList,TVSIL_STATE);
|
|
|
|
|
|
|
|
_this->m_hSelectedItem = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
case ID_POPUP_ADDNEWCHEAT:
|
|
|
|
//DialogBox(hInst, MAKEINTRESOURCE(IDD_Cheats_Add),hDlg,(DLGPROC)CheatAddProc);
|
|
|
|
break;
|
|
|
|
case ID_POPUP_EDIT:
|
|
|
|
//DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_Cheats_Edit),hDlg,(DLGPROC)CheatEditProc,(LPARAM)hSelectedItem);
|
|
|
|
break;
|
|
|
|
case ID_POPUP_DELETE:
|
|
|
|
{
|
|
|
|
TVITEM item;
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
int Response = MessageBoxW(hDlg,GS(MSG_DEL_SURE),GS(MSG_DEL_TITLE),MB_YESNO|MB_ICONQUESTION);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Response != IDYES) { break; }
|
|
|
|
|
|
|
|
//Delete selected cheat
|
|
|
|
item.hItem = (HTREEITEM)_this->m_hSelectedItem;
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
TreeView_GetItem((HWND)_this->m_hCheatTree,&item);
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
_this->ChangeChildrenStatus((HWND)TVI_ROOT,false);
|
2010-05-14 23:28:15 +00:00
|
|
|
_this->DeleteCheat(item.lParam);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->RefreshCheatManager();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_UNMARK:
|
2015-01-27 05:07:44 +00:00
|
|
|
_this->ChangeChildrenStatus((HWND)TVI_ROOT,false);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->m_CheatSelectionChanged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (_this->m_DeleteingEntries)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
LPNMHDR lpnmh = (LPNMHDR) lParam;
|
|
|
|
|
|
|
|
if ((lpnmh->code == NM_RCLICK) && (lpnmh->idFrom == IDC_MYTREE))
|
|
|
|
{
|
|
|
|
|
|
|
|
//Work out what item is selected
|
|
|
|
TVHITTESTINFO ht = {0};
|
|
|
|
DWORD dwpos = GetMessagePos();
|
|
|
|
|
|
|
|
// include <windowsx.h> and <windows.h> header files
|
|
|
|
ht.pt.x = GET_X_LPARAM(dwpos);
|
|
|
|
ht.pt.y = GET_Y_LPARAM(dwpos);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
|
|
|
|
|
|
|
|
TreeView_HitTest(lpnmh->hwndFrom, &ht);
|
2015-01-27 05:07:44 +00:00
|
|
|
_this->m_hSelectedItem = (HWND)ht.hItem;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadBool(UserInterface_BasicMode)) { return true; }
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Show Menu
|
|
|
|
HMENU hMenu = LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_CHEAT_MENU));
|
|
|
|
HMENU hPopupMenu = GetSubMenu(hMenu,0);
|
|
|
|
POINT Mouse;
|
|
|
|
|
|
|
|
GetCursorPos(&Mouse);
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
MenuSetText(hPopupMenu, 0, GS(CHEAT_ADDNEW), NULL);
|
|
|
|
MenuSetText(hPopupMenu, 1, GS(CHEAT_EDIT), NULL);
|
|
|
|
MenuSetText(hPopupMenu, 3, GS(CHEAT_DELETE), NULL);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (_this->m_hSelectedItem == NULL ||
|
|
|
|
TreeView_GetChild((HWND)_this->m_hCheatTree,_this->m_hSelectedItem) != NULL)
|
|
|
|
{
|
|
|
|
DeleteMenu(hPopupMenu,3,MF_BYPOSITION);
|
|
|
|
DeleteMenu(hPopupMenu,2,MF_BYPOSITION);
|
|
|
|
DeleteMenu(hPopupMenu,1,MF_BYPOSITION);
|
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
TrackPopupMenu(hPopupMenu, 0, Mouse.x, Mouse.y, 0,hDlg, NULL);
|
2008-09-18 03:15:49 +00:00
|
|
|
DestroyMenu(hMenu);
|
|
|
|
}
|
|
|
|
if ((lpnmh->code == NM_CLICK) && (lpnmh->idFrom == IDC_MYTREE))
|
|
|
|
{
|
|
|
|
TVHITTESTINFO ht = {0};
|
|
|
|
DWORD dwpos = GetMessagePos();
|
|
|
|
|
|
|
|
// include <windowsx.h> and <windows.h> header files
|
|
|
|
ht.pt.x = GET_X_LPARAM(dwpos);
|
|
|
|
ht.pt.y = GET_Y_LPARAM(dwpos);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
|
|
|
|
|
|
|
|
TreeView_HitTest(lpnmh->hwndFrom, &ht);
|
|
|
|
|
|
|
|
if(TVHT_ONITEMSTATEICON & ht.flags)
|
|
|
|
{
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
switch (TV_GetCheckState(_this->m_hCheatTree,(HWND)ht.hItem)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
case TV_STATE_CLEAR:
|
|
|
|
case TV_STATE_INDETERMINATE:
|
|
|
|
//Make sure that the item has a valid code extenstion selected
|
2015-01-27 05:07:44 +00:00
|
|
|
if (TreeView_GetChild((HWND)_this->m_hCheatTree, (HWND)ht.hItem) == NULL) {
|
2008-09-18 03:15:49 +00:00
|
|
|
TVITEM item;
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
item.hItem = (HTREEITEM)ht.hItem;
|
|
|
|
TreeView_GetItem((HWND)_this->m_hCheatTree,&item);
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr LineEntry = g_Settings->LoadStringIndex(Cheat_Entry,item.lParam);
|
2008-11-14 20:51:06 +00:00
|
|
|
if (CheatUsesCodeExtensions(LineEntry))
|
|
|
|
{
|
|
|
|
stdstr CheatExtension;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (!g_Settings->LoadStringIndex(Cheat_Extension,item.lParam,CheatExtension))
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
SendMessage(hDlg, UM_CHANGECODEEXTENSION, 0, (LPARAM)ht.hItem);
|
2015-01-27 05:07:44 +00:00
|
|
|
TV_SetCheckState(_this->m_hCheatTree,(HWND)ht.hItem,TV_STATE_CLEAR);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-27 05:07:44 +00:00
|
|
|
TV_SetCheckState(_this->m_hCheatTree,(HWND)ht.hItem,TV_STATE_CHECKED);
|
|
|
|
_this->ChangeChildrenStatus((HWND)ht.hItem,true);
|
|
|
|
_this->CheckParentStatus((HWND)TreeView_GetParent((HWND)_this->m_hCheatTree,ht.hItem));
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case TV_STATE_CHECKED:
|
2015-01-27 05:07:44 +00:00
|
|
|
TV_SetCheckState(_this->m_hCheatTree,(HWND)ht.hItem,TV_STATE_CLEAR);
|
|
|
|
_this->ChangeChildrenStatus((HWND)ht.hItem,false);
|
|
|
|
_this->CheckParentStatus((HWND)TreeView_GetParent((HWND)_this->m_hCheatTree,ht.hItem));
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-27 05:07:44 +00:00
|
|
|
switch (TV_GetCheckState(_this->m_hCheatTree,(HWND)ht.hItem)) {
|
|
|
|
case TV_STATE_CHECKED: TV_SetCheckState(_this->m_hCheatTree,(HWND)ht.hItem,TV_STATE_INDETERMINATE); break;
|
|
|
|
case TV_STATE_CLEAR: TV_SetCheckState(_this->m_hCheatTree,(HWND)ht.hItem,TV_STATE_CHECKED); break;
|
|
|
|
case TV_STATE_INDETERMINATE: TV_SetCheckState(_this->m_hCheatTree,(HWND)ht.hItem,TV_STATE_CLEAR); break;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_this->m_CheatSelectionChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((lpnmh->code == NM_DBLCLK) && (lpnmh->idFrom == IDC_MYTREE))
|
|
|
|
{
|
|
|
|
TVHITTESTINFO ht = {0};
|
|
|
|
DWORD dwpos = GetMessagePos();
|
|
|
|
|
|
|
|
// include <windowsx.h> and <windows.h> header files
|
|
|
|
ht.pt.x = GET_X_LPARAM(dwpos);
|
|
|
|
ht.pt.y = GET_Y_LPARAM(dwpos);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
|
|
|
|
|
|
|
|
TreeView_HitTest(lpnmh->hwndFrom, &ht);
|
|
|
|
|
|
|
|
if(TVHT_ONITEMLABEL & ht.flags)
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
PostMessage(hDlg, UM_CHANGECODEEXTENSION, 0, (LPARAM)ht.hItem);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((lpnmh->code == TVN_SELCHANGED) && (lpnmh->idFrom == IDC_MYTREE)) {
|
|
|
|
HTREEITEM hItem;
|
|
|
|
|
|
|
|
hItem = TreeView_GetSelection((HWND)_this->m_hCheatTree);
|
|
|
|
if (TreeView_GetChild((HWND)_this->m_hCheatTree,hItem) == NULL) {
|
|
|
|
TVITEM item;
|
|
|
|
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
item.hItem = hItem;
|
|
|
|
TreeView_GetItem((HWND)_this->m_hCheatTree,&item);
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr Notes(g_Settings->LoadStringIndex(Cheat_Notes,item.lParam));
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_NOTES,Notes.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
if (_this->m_AddCheat)
|
|
|
|
{
|
|
|
|
SendMessage((HWND)_this->m_AddCheat,WM_EDITCHEAT,item.lParam,0); //edit cheat
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_NOTES,"");
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UM_CHANGECODEEXTENSION:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
;
|
|
|
|
//Get the selected item
|
2015-01-27 05:07:44 +00:00
|
|
|
_this->m_hSelectedItem = (HWND)lParam;
|
2008-09-18 03:15:49 +00:00
|
|
|
TVITEM item;
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
item.hItem = (HTREEITEM)_this->m_hSelectedItem;
|
|
|
|
TreeView_GetItem((HWND)_this->m_hCheatTree,&item);
|
|
|
|
|
|
|
|
//Make sure the selected line can use code extensions
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr LineEntry = g_Settings->LoadStringIndex(Cheat_Entry,item.lParam);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (!CheatUsesCodeExtensions(LineEntry)) { break; }
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
stdstr Options;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadStringIndex(Cheat_Options,item.lParam,Options) && Options.length() > 0)
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Cheats_CodeEx),hDlg,(DLGPROC)CheatsCodeExProc,(LPARAM)_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2008-11-14 20:51:06 +00:00
|
|
|
stdstr Range;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadStringIndex(Cheat_Range,item.lParam,Range) && Range.length() > 0)
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Cheats_Range),hDlg,(DLGPROC)CheatsCodeQuantProc,(LPARAM)_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Update cheat listing with new extention
|
|
|
|
stdstr CheatName(_this->GetCheatName(item.lParam,true));
|
2010-09-22 21:43:42 +00:00
|
|
|
char * Cheat = strrchr((char *)CheatName.c_str(),'\\');
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Cheat == NULL) {
|
|
|
|
Cheat = const_cast<char *>(CheatName.c_str());
|
|
|
|
} else {
|
|
|
|
Cheat += 1;
|
|
|
|
}
|
|
|
|
item.mask = TVIF_TEXT;
|
|
|
|
item.pszText = Cheat;
|
|
|
|
item.cchTextMax = CheatName.length();
|
|
|
|
TreeView_SetItem((HWND)_this->m_hCheatTree,&item);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
int CALLBACK CCheats::CheatsCodeExProc (HWND hDlg,DWORD uMsg,DWORD wParam, DWORD lParam) {
|
2008-09-18 03:15:49 +00:00
|
|
|
switch (uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
CCheats * _this = (CCheats *)lParam;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetProp(hDlg,"Class",_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Find the cheat Number of the option being selected
|
|
|
|
TVITEM item;
|
|
|
|
item.hItem = (HTREEITEM)_this->m_hSelectedItem;
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
TreeView_GetItem((HWND)_this->m_hCheatTree,&item);
|
|
|
|
stdstr CheatName = _this->GetCheatName(item.lParam,false);
|
|
|
|
|
|
|
|
//Set up language support for dialog
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowTextW(hDlg, GS(CHEAT_CODE_EXT_TITLE));
|
|
|
|
SetDlgItemTextW(hDlg,IDC_NOTE, GS(CHEAT_CODE_EXT_TXT));
|
|
|
|
SetDlgItemTextW(hDlg,IDOK, GS(CHEAT_OK));
|
|
|
|
SetDlgItemTextW(hDlg,IDCANCEL, GS(CHEAT_CANCEL));
|
|
|
|
SetDlgItemText(hDlg,IDC_CHEAT_NAME,CheatName.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Read through and add all options to the list box
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr Options(g_Settings->LoadStringIndex(Cheat_Options,item.lParam));
|
|
|
|
stdstr CurrentExt(g_Settings->LoadStringIndex(Cheat_Extension,item.lParam));
|
2008-09-18 03:15:49 +00:00
|
|
|
const char * ReadPos = Options.c_str();
|
|
|
|
while (*ReadPos != 0) {
|
|
|
|
const char * NextComma = strchr(ReadPos,',');
|
|
|
|
int len = NextComma == NULL ? strlen(ReadPos) : NextComma - ReadPos;
|
|
|
|
stdstr CheatExt(ReadPos);
|
|
|
|
CheatExt.resize(len);
|
2015-03-04 09:36:08 +00:00
|
|
|
int index = SendMessage(GetDlgItem(hDlg,IDC_CHEAT_LIST),LB_ADDSTRING,0,(LPARAM)CheatExt.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
if (CheatExt == CurrentExt) {
|
2015-03-04 09:36:08 +00:00
|
|
|
SendMessage(GetDlgItem(hDlg,IDC_CHEAT_LIST),LB_SETCURSEL,index,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
//Move to next entry or end
|
|
|
|
ReadPos = NextComma ? NextComma + 1 : ReadPos + strlen(ReadPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDC_CHEAT_LIST:
|
2015-03-04 09:36:08 +00:00
|
|
|
if (HIWORD(wParam) == LBN_DBLCLK) { PostMessage(hDlg,WM_COMMAND,IDOK,0); break; }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case IDOK:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Find the cheat Number of the option being selected
|
|
|
|
TVITEM item;
|
|
|
|
item.hItem = (HTREEITEM)_this->m_hSelectedItem;
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
TreeView_GetItem((HWND)_this->m_hCheatTree,&item);
|
|
|
|
|
|
|
|
//Get the selected cheat extension
|
|
|
|
char CheatExten[300];
|
2015-03-04 09:36:08 +00:00
|
|
|
int index = SendMessage(GetDlgItem(hDlg,IDC_CHEAT_LIST),LB_GETCURSEL,0,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (index < 0) { index = 0; }
|
2015-03-04 09:36:08 +00:00
|
|
|
SendMessage(GetDlgItem(hDlg,IDC_CHEAT_LIST),LB_GETTEXT,index,(LPARAM)CheatExten);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_Extension,item.lParam,CheatExten);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->m_CheatSelectionChanged = true;
|
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
RemoveProp(hDlg,"Class");
|
|
|
|
EndDialog(hDlg,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case IDCANCEL:
|
2015-03-04 09:36:08 +00:00
|
|
|
RemoveProp(hDlg,"Class");
|
|
|
|
EndDialog(hDlg,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
int CALLBACK CCheats::CheatsCodeQuantProc (HWND hDlg,DWORD uMsg,DWORD wParam, DWORD lParam) {
|
2008-09-18 03:15:49 +00:00
|
|
|
static WORD Start, Stop, SelStart, SelStop;
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
CCheats * _this = (CCheats *)lParam;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetProp(hDlg,"Class",_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Find the cheat Number of the option being selected
|
|
|
|
TVITEM item;
|
|
|
|
item.hItem = (HTREEITEM)_this->m_hSelectedItem;
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
TreeView_GetItem((HWND)_this->m_hCheatTree,&item);
|
|
|
|
stdstr CheatName = _this->GetCheatName(item.lParam,false);
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr RangeNote(g_Settings->LoadStringIndex(Cheat_RangeNotes, item.lParam));
|
|
|
|
stdstr Range(g_Settings->LoadStringIndex(Cheat_Range,item.lParam));
|
|
|
|
stdstr Value(g_Settings->LoadStringIndex(Cheat_Extension,item.lParam));
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Set up language support for dialog
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowTextW(hDlg, GS(CHEAT_CODE_EXT_TITLE));
|
|
|
|
SetDlgItemTextW(hDlg, IDC_DIGITAL_TEXT, GS(CHEAT_CHOOSE_VALUE));
|
|
|
|
SetDlgItemTextW(hDlg, IDC_VALUE_TEXT, GS(CHEAT_VALUE));
|
|
|
|
SetDlgItemTextW(hDlg, IDC_NOTES_TEXT, GS(CHEAT_NOTES));
|
|
|
|
SetDlgItemText(hDlg,IDC_NOTES,RangeNote.c_str());
|
|
|
|
SetDlgItemText(hDlg,IDC_CHEAT_NAME,CheatName.c_str());
|
|
|
|
SetDlgItemText(hDlg,IDC_VALUE,Value.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
Start = (WORD)(Range.c_str()[0] == '$'?AsciiToHex(&Range.c_str()[1]):atol(Range.c_str()));
|
|
|
|
const char * ReadPos = strrchr(Range.c_str(),'-');
|
|
|
|
if (ReadPos != NULL) {
|
|
|
|
Stop = (WORD)(ReadPos[1] == '$'?AsciiToHex(&ReadPos[2]):atol(&ReadPos[1]));
|
|
|
|
} else {
|
|
|
|
Stop = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char Text[500];
|
|
|
|
sprintf(Text,"%s $%X %s $%X",GS(CHEAT_FROM),Start,GS(CHEAT_TO),Stop);
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_RANGE,Text);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDC_VALUE:
|
|
|
|
if (HIWORD(wParam) == EN_UPDATE) {
|
|
|
|
TCHAR szTmp[10], szTmp2[10];
|
|
|
|
DWORD Value;
|
2015-03-04 09:36:08 +00:00
|
|
|
GetDlgItemText(hDlg,IDC_VALUE,szTmp,sizeof(szTmp));
|
2008-09-18 03:15:49 +00:00
|
|
|
Value = szTmp[0] =='$'?AsciiToHex(&szTmp[1]):AsciiToHex(szTmp);
|
|
|
|
if (Value > Stop) { Value = Stop; }
|
|
|
|
if (Value < Start) { Value = Start; }
|
|
|
|
sprintf(szTmp2,"$%X",Value);
|
|
|
|
if (strcmp(szTmp,szTmp2) != 0) {
|
2015-03-04 09:36:08 +00:00
|
|
|
SetDlgItemText(hDlg,IDC_VALUE,szTmp2);
|
2012-10-06 04:09:17 +00:00
|
|
|
if (SelStop == 0) { SelStop = (WORD)strlen(szTmp2); SelStart = SelStop; }
|
2015-03-04 09:36:08 +00:00
|
|
|
SendDlgItemMessage(hDlg,IDC_VALUE,EM_SETSEL,(WPARAM)SelStart,(LPARAM)SelStop);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
|
|
|
WORD NewSelStart, NewSelStop;
|
2015-03-04 09:36:08 +00:00
|
|
|
SendDlgItemMessage(hDlg,IDC_VALUE,EM_GETSEL,(WPARAM)&NewSelStart,(LPARAM)&NewSelStop);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (NewSelStart != 0) { SelStart = NewSelStart; SelStop = NewSelStop; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDOK:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Find the cheat Number of the option being selected
|
|
|
|
TVITEM item;
|
|
|
|
item.hItem = (HTREEITEM)_this->m_hSelectedItem;
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
TreeView_GetItem((HWND)_this->m_hCheatTree,&item);
|
|
|
|
|
|
|
|
//Get the selected cheat extension
|
|
|
|
TCHAR CheatExten[300], szTmp[10];
|
|
|
|
DWORD Value;
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
GetDlgItemText(hDlg,IDC_VALUE,szTmp,sizeof(szTmp));
|
2008-09-18 03:15:49 +00:00
|
|
|
Value = szTmp[0] =='$'?AsciiToHex(&szTmp[1]):AsciiToHex(szTmp);
|
|
|
|
if (Value > Stop) { Value = Stop; }
|
|
|
|
if (Value < Start) { Value = Start; }
|
|
|
|
sprintf(CheatExten,"$%X",Value);
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_Extension, item.lParam,CheatExten);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->m_CheatSelectionChanged = true;
|
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
RemoveProp(hDlg,"Class");
|
|
|
|
EndDialog(hDlg,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case IDCANCEL:
|
2015-03-04 09:36:08 +00:00
|
|
|
RemoveProp(hDlg,"Class");
|
|
|
|
EndDialog(hDlg,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCheats::IsCheatMessage( MSG * msg )
|
|
|
|
{
|
|
|
|
if (m_Window)
|
|
|
|
{
|
|
|
|
return IsDialogMessage((HWND)m_Window,msg) != 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
int CALLBACK CCheats::ManageCheatsProc (HWND hDlg,DWORD uMsg,DWORD wParam, DWORD lParam) {
|
2008-09-18 03:15:49 +00:00
|
|
|
switch (uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
CCheats * _this = (CCheats *)lParam;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetProp(hDlg,"Class",_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->m_Window = hDlg;
|
|
|
|
|
|
|
|
WINDOWPLACEMENT WndPlac;
|
|
|
|
WndPlac.length = sizeof(WndPlac);
|
2015-03-04 09:36:08 +00:00
|
|
|
GetWindowPlacement(hDlg, &WndPlac);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-04-01 15:14:46 +00:00
|
|
|
LONG_PTR originalWndProc = GetWindowLongPtrW(hDlg, GWLP_WNDPROC);
|
|
|
|
SetWindowLongPtrW(hDlg, GWLP_WNDPROC, (LONG_PTR) DefWindowProcW);
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowTextW(hDlg, GS(CHEAT_TITLE));
|
2015-04-01 15:14:46 +00:00
|
|
|
SetWindowLongPtrW(hDlg, GWLP_WNDPROC, originalWndProc);
|
2015-03-04 09:36:08 +00:00
|
|
|
_this->m_hSelectCheat = (HWND)CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Cheats_List),hDlg,(DLGPROC)CheatListProc,(LPARAM)_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
SetWindowPos((HWND)_this->m_hSelectCheat,HWND_TOP, 5, 8, 0, 0, SWP_NOSIZE);
|
|
|
|
ShowWindow((HWND)_this->m_hSelectCheat,SW_SHOW);
|
|
|
|
|
|
|
|
RECT * rc = &WndPlac.rcNormalPosition;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadDword(UserInterface_BasicMode))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2012-10-06 04:09:17 +00:00
|
|
|
RECT * rcList = (RECT *)_this->m_rcList;
|
2008-09-18 03:15:49 +00:00
|
|
|
GetWindowRect(GetDlgItem((HWND)_this->m_hSelectCheat, IDC_CHEATSFRAME), rcList);
|
|
|
|
_this->m_MinSizeDlg = rcList->right - rcList->left + 16;
|
|
|
|
_this->m_MaxSizeDlg = _this->m_MinSizeDlg;
|
|
|
|
|
|
|
|
_this->m_DialogState = CONTRACTED;
|
|
|
|
WndPlac.rcNormalPosition.right = WndPlac.rcNormalPosition.left + _this->m_MinSizeDlg;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowPlacement(hDlg, &WndPlac);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
ShowWindow(GetDlgItem(hDlg, IDC_STATE),SW_HIDE);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2015-03-04 09:36:08 +00:00
|
|
|
_this->m_AddCheat = (HWND)CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Cheats_Add),hDlg,(DLGPROC)CheatAddProc,(LPARAM)_this);
|
2008-09-18 03:15:49 +00:00
|
|
|
SetWindowPos((HWND)_this->m_AddCheat, HWND_TOP, (rc->right - rc->left)/2, 8, 0, 0, SWP_NOSIZE);
|
|
|
|
ShowWindow((HWND)_this->m_AddCheat,SW_HIDE);
|
|
|
|
|
|
|
|
|
|
|
|
RECT * rcAdd = (RECT *)_this->m_rcAdd, * rcList = (RECT *)_this->m_rcList;
|
|
|
|
GetWindowRect(GetDlgItem((HWND)_this->m_hSelectCheat, IDC_CHEATSFRAME), rcList);
|
|
|
|
GetWindowRect(GetDlgItem((HWND)_this->m_AddCheat, IDC_ADDCHEATSFRAME), rcAdd);
|
|
|
|
_this->m_MinSizeDlg = rcList->right - rcList->left + 32;
|
|
|
|
_this->m_MaxSizeDlg = rcAdd->right - rcList->left + 32;
|
|
|
|
|
|
|
|
_this->m_DialogState = CONTRACTED;
|
|
|
|
WndPlac.rcNormalPosition.right = WndPlac.rcNormalPosition.left + _this->m_MinSizeDlg;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowPlacement(hDlg, &WndPlac);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
GetClientRect(hDlg, rc);
|
|
|
|
HWND hStateButton = GetDlgItem(hDlg, IDC_STATE);
|
2008-09-18 03:15:49 +00:00
|
|
|
SetWindowPos(hStateButton, HWND_TOP, (rc->right - rc->left) - 16, 0, 16, rc->bottom - rc->top, 0);
|
|
|
|
HANDLE hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RIGHT),IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
|
2015-03-04 09:36:08 +00:00
|
|
|
SendDlgItemMessage(hDlg, IDC_STATE, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) (HANDLE) hIcon);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//re-center cheat window
|
|
|
|
RECT rcDlg, rcParent;
|
2015-03-04 09:36:08 +00:00
|
|
|
GetWindowRect(hDlg, &rcDlg);
|
|
|
|
GetWindowRect(GetParent(hDlg), &rcParent);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
int DlgWidth = rcDlg.right - rcDlg.left;
|
|
|
|
int DlgHeight = rcDlg.bottom - rcDlg.top;
|
|
|
|
|
|
|
|
int X = (((rcParent.right - rcParent.left) - DlgWidth) / 2) + rcParent.left;
|
|
|
|
int Y = (((rcParent.bottom - rcParent.top) - DlgHeight) / 2) + rcParent.top;
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowPos(hDlg,NULL,X,Y,0,0,SWP_NOZORDER|SWP_NOSIZE);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
_this->RefreshCheatManager();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDCANCEL:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
if (_this->m_AddCheat) {
|
|
|
|
DestroyWindow((HWND)_this->m_AddCheat);
|
|
|
|
_this->m_AddCheat = NULL;
|
|
|
|
}
|
|
|
|
_this->m_Window = NULL;
|
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
RemoveProp(hDlg,"Class");
|
|
|
|
EndDialog(hDlg,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case IDC_STATE:
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
CCheats * _this = (CCheats *)GetProp(hDlg,"Class");
|
2008-09-18 03:15:49 +00:00
|
|
|
WINDOWPLACEMENT WndPlac;
|
|
|
|
WndPlac.length = sizeof(WndPlac);
|
2015-03-04 09:36:08 +00:00
|
|
|
GetWindowPlacement(hDlg, &WndPlac);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (_this->m_DialogState == CONTRACTED)
|
|
|
|
{
|
|
|
|
_this->m_DialogState = EXPANDED;
|
|
|
|
WndPlac.rcNormalPosition.right = WndPlac.rcNormalPosition.left + _this->m_MaxSizeDlg;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowPlacement(hDlg, &WndPlac);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
RECT clientrect;
|
2015-03-04 09:36:08 +00:00
|
|
|
GetClientRect(hDlg, &clientrect);
|
|
|
|
HWND hStateButton = GetDlgItem(hDlg, IDC_STATE);
|
2008-09-18 03:15:49 +00:00
|
|
|
SetWindowPos(hStateButton, HWND_TOP, (clientrect.right - clientrect.left) - 16, 0, 16, clientrect.bottom - clientrect.top, 0);
|
|
|
|
|
|
|
|
HANDLE hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LEFT),IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
|
2015-03-04 09:36:08 +00:00
|
|
|
SendDlgItemMessage(hDlg, IDC_STATE, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) (HANDLE) hIcon);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
ShowWindow((HWND)_this->m_AddCheat,SW_SHOW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_this->m_DialogState = CONTRACTED;
|
|
|
|
WndPlac.rcNormalPosition.right = WndPlac.rcNormalPosition.left + _this->m_MinSizeDlg;
|
2015-03-04 09:36:08 +00:00
|
|
|
SetWindowPlacement(hDlg, &WndPlac);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
HANDLE hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RIGHT),IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
|
2015-03-04 09:36:08 +00:00
|
|
|
SendDlgItemMessage(hDlg, IDC_STATE, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) (HANDLE) hIcon);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
RECT clientrect;
|
2015-03-04 09:36:08 +00:00
|
|
|
GetClientRect(hDlg, &clientrect);
|
|
|
|
HWND hStateButton = GetDlgItem(hDlg, IDC_STATE);
|
2008-09-18 03:15:49 +00:00
|
|
|
SetWindowPos(hStateButton, HWND_TOP, (clientrect.right - clientrect.left) - 16, 0, 16, clientrect.bottom - clientrect.top, 0);
|
|
|
|
|
|
|
|
ShowWindow((HWND)_this->m_AddCheat,SW_HIDE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
bool CCheats::TV_SetCheckState(HWND hwndTreeView, HWND hItem, TV_CHECK_STATE state)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
TVITEM tvItem;
|
|
|
|
|
|
|
|
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
|
|
|
|
tvItem.hItem = (HTREEITEM)hItem;
|
|
|
|
tvItem.stateMask = TVIS_STATEIMAGEMASK;
|
|
|
|
|
|
|
|
/*Image 1 in the tree-view check box image list is the
|
|
|
|
unchecked box. Image 2 is the checked box.*/
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case TV_STATE_CHECKED: tvItem.state = INDEXTOSTATEIMAGEMASK(1); break;
|
|
|
|
case TV_STATE_CLEAR: tvItem.state = INDEXTOSTATEIMAGEMASK(2); break;
|
|
|
|
case TV_STATE_INDETERMINATE: tvItem.state = INDEXTOSTATEIMAGEMASK(3); break;
|
|
|
|
default: tvItem.state = INDEXTOSTATEIMAGEMASK(0); break;
|
|
|
|
}
|
|
|
|
return TreeView_SetItem((HWND)hwndTreeView, &tvItem) != 0;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
int CCheats::TV_GetCheckState(HWND hwndTreeView, HWND hItem)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
TVITEM tvItem;
|
|
|
|
|
|
|
|
// Prepare to receive the desired information.
|
|
|
|
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
|
|
|
|
tvItem.hItem = (HTREEITEM)hItem;
|
|
|
|
tvItem.stateMask = TVIS_STATEIMAGEMASK;
|
|
|
|
|
|
|
|
// Request the information.
|
|
|
|
TreeView_GetItem((HWND)hwndTreeView, &tvItem);
|
|
|
|
|
|
|
|
// Return zero if it's not checked, or nonzero otherwise.
|
|
|
|
switch (tvItem.state >> 12) {
|
|
|
|
case 1: return TV_STATE_CHECKED;
|
|
|
|
case 2: return TV_STATE_CLEAR;
|
|
|
|
case 3: return TV_STATE_INDETERMINATE;
|
|
|
|
}
|
|
|
|
return ((int)(tvItem.state >> 12) -1);
|
|
|
|
}
|
|
|
|
|
2015-04-20 19:41:25 +00:00
|
|
|
void CCheats::MenuSetText ( HMENU hMenu, int MenuPos, const wchar_t * Title, const wchar_t * ShortCut)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
|
|
|
MENUITEMINFOW MenuInfo;
|
|
|
|
wchar_t String[256];
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
if (Title == NULL || wcslen(Title) == 0) { return; }
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
memset(&MenuInfo, 0, sizeof(MENUITEMINFO));
|
|
|
|
MenuInfo.cbSize = sizeof(MENUITEMINFO);
|
|
|
|
MenuInfo.fMask = MIIM_TYPE;
|
|
|
|
MenuInfo.fType = MFT_STRING;
|
|
|
|
MenuInfo.fState = MFS_ENABLED;
|
|
|
|
MenuInfo.dwTypeData = String;
|
|
|
|
MenuInfo.cch = 256;
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
GetMenuItemInfoW(hMenu,MenuPos,true,&MenuInfo);
|
|
|
|
wcscpy(String,Title);
|
|
|
|
if (wcschr(String,'\t') != NULL) { *(wcschr(String,'\t')) = '\0'; }
|
2015-04-20 19:41:25 +00:00
|
|
|
if (ShortCut) { _swprintf(String,L"%s\t%s",String,ShortCut); }
|
2015-03-04 09:36:08 +00:00
|
|
|
SetMenuItemInfoW(hMenu,MenuPos,true,&MenuInfo);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:28:15 +00:00
|
|
|
void CCheats::DeleteCheat(int Index)
|
|
|
|
{
|
|
|
|
for (int CheatNo = Index; CheatNo < MaxCheats; CheatNo ++ )
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr LineEntry = g_Settings->LoadStringIndex(Cheat_Entry,CheatNo + 1);
|
2010-05-14 23:28:15 +00:00
|
|
|
if (LineEntry.empty())
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->DeleteSettingIndex(Cheat_RangeNotes,CheatNo);
|
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Range,CheatNo);
|
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Options,CheatNo);
|
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Notes,CheatNo);
|
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Extension,CheatNo);
|
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Entry,CheatNo);
|
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Active,CheatNo);
|
2010-05-14 23:28:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
stdstr Value;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadStringIndex(Cheat_RangeNotes,CheatNo+1,Value))
|
2010-05-14 23:28:15 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_RangeNotes,CheatNo, Value);
|
2010-05-14 23:28:15 +00:00
|
|
|
} else {
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->DeleteSettingIndex(Cheat_RangeNotes,CheatNo);
|
2010-05-14 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadStringIndex(Cheat_Range,CheatNo+1,Value))
|
2010-05-14 23:28:15 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_Range,CheatNo, Value);
|
2010-05-14 23:28:15 +00:00
|
|
|
} else {
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Range,CheatNo);
|
2010-05-14 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadStringIndex(Cheat_Options,CheatNo+1,Value))
|
2010-05-14 23:28:15 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_Options,CheatNo, Value);
|
2010-05-14 23:28:15 +00:00
|
|
|
} else {
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Options,CheatNo);
|
2010-05-14 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadStringIndex(Cheat_Notes,CheatNo+1,Value))
|
2010-05-14 23:28:15 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_Notes,CheatNo, Value);
|
2010-05-14 23:28:15 +00:00
|
|
|
} else {
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Notes,CheatNo);
|
2010-05-14 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadStringIndex(Cheat_Extension,CheatNo+1,Value))
|
2010-05-14 23:28:15 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_Extension,CheatNo, Value);
|
2010-05-14 23:28:15 +00:00
|
|
|
} else {
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Extension,CheatNo);
|
2010-05-14 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool bValue;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadBoolIndex(Cheat_Active,CheatNo+1,bValue))
|
2010-05-14 23:28:15 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveBoolIndex(Cheat_Active,CheatNo, bValue);
|
2010-05-14 23:28:15 +00:00
|
|
|
} else {
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->DeleteSettingIndex(Cheat_Active,CheatNo);
|
2010-05-14 23:28:15 +00:00
|
|
|
}
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Cheat_Entry,CheatNo, LineEntry);
|
2010-05-14 23:28:15 +00:00
|
|
|
}
|
|
|
|
CSettingTypeCheats::FlushChanges();
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
void CCheats::ChangeChildrenStatus(HWND hParent, bool Checked) {
|
2008-09-18 03:15:49 +00:00
|
|
|
HTREEITEM hItem = TreeView_GetChild((HWND)m_hCheatTree, hParent);
|
|
|
|
if (hItem == NULL) {
|
|
|
|
if ((HTREEITEM)hParent == TVI_ROOT) { return; }
|
|
|
|
|
|
|
|
TVITEM item;
|
|
|
|
item.mask = TVIF_PARAM ;
|
|
|
|
item.hItem = (HTREEITEM)hParent;
|
|
|
|
TreeView_GetItem((HWND)m_hCheatTree,&item);
|
|
|
|
|
|
|
|
//if cheat uses a extension and it is not set then do not set it
|
|
|
|
if (Checked) {
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr LineEntry = g_Settings->LoadStringIndex(Cheat_Entry,item.lParam);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (CheatUsesCodeExtensions(LineEntry)) {
|
2008-11-14 20:51:06 +00:00
|
|
|
stdstr CheatExten;
|
2012-11-17 01:02:04 +00:00
|
|
|
if (!g_Settings->LoadStringIndex(Cheat_Extension,item.lParam,CheatExten) || CheatExten.empty())
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Save Cheat
|
|
|
|
TV_SetCheckState(m_hCheatTree,hParent,Checked?TV_STATE_CHECKED:TV_STATE_CLEAR);
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveBoolIndex(Cheat_Active,item.lParam,Checked);
|
2008-09-18 03:15:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
TV_CHECK_STATE state = TV_STATE_UNKNOWN;
|
|
|
|
while (hItem != NULL) {
|
2015-01-27 05:07:44 +00:00
|
|
|
TV_CHECK_STATE ChildState = (TV_CHECK_STATE)TV_GetCheckState(m_hCheatTree,(HWND)hItem);
|
2008-09-18 03:15:49 +00:00
|
|
|
if ((ChildState != TV_STATE_CHECKED || !Checked) &&
|
|
|
|
(ChildState != TV_STATE_CLEAR || Checked))
|
|
|
|
{
|
2015-01-27 05:07:44 +00:00
|
|
|
ChangeChildrenStatus((HWND)hItem,Checked);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2015-01-27 05:07:44 +00:00
|
|
|
ChildState = (TV_CHECK_STATE)TV_GetCheckState(m_hCheatTree,(HWND)hItem);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (state == TV_STATE_UNKNOWN) { state = ChildState; }
|
|
|
|
if (state != ChildState) { state = TV_STATE_INDETERMINATE; }
|
|
|
|
hItem = TreeView_GetNextSibling((HWND)m_hCheatTree,hItem);
|
|
|
|
}
|
|
|
|
if (state != TV_STATE_UNKNOWN) {
|
|
|
|
TV_SetCheckState(m_hCheatTree,hParent,state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
void CCheats::CheckParentStatus(HWND hParent) {
|
2008-09-18 03:15:49 +00:00
|
|
|
TV_CHECK_STATE CurrentState, InitialState;
|
|
|
|
HTREEITEM hItem;
|
|
|
|
|
|
|
|
if (!hParent) { return; }
|
|
|
|
hItem = TreeView_GetChild((HWND)m_hCheatTree, (HTREEITEM)hParent);
|
|
|
|
InitialState = (TV_CHECK_STATE)TV_GetCheckState(m_hCheatTree,hParent);
|
2015-01-27 05:07:44 +00:00
|
|
|
CurrentState = (TV_CHECK_STATE)TV_GetCheckState((HWND)m_hCheatTree,(HWND)hItem);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
while (hItem != NULL) {
|
2015-01-27 05:07:44 +00:00
|
|
|
if (TV_GetCheckState((HWND)m_hCheatTree,(HWND)hItem) != CurrentState) {
|
2008-09-18 03:15:49 +00:00
|
|
|
CurrentState = TV_STATE_INDETERMINATE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hItem = TreeView_GetNextSibling((HWND)m_hCheatTree,hItem);
|
|
|
|
}
|
2015-01-27 05:07:44 +00:00
|
|
|
TV_SetCheckState((HWND)m_hCheatTree,(HWND)hParent,CurrentState);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (InitialState != CurrentState) {
|
2015-01-27 05:07:44 +00:00
|
|
|
CheckParentStatus((HWND)TreeView_GetParent((HWND)m_hCheatTree,(HTREEITEM)hParent));
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
stdstr CCheats::ReadCodeString (HWND hDlg, bool &validcodes, bool &validoptions, bool &nooptions, int &codeformat ) {
|
2008-09-18 03:15:49 +00:00
|
|
|
int numlines, linecount, len;
|
|
|
|
char str[128];
|
|
|
|
int i;
|
|
|
|
char* formatnormal = "XXXXXXXX XXXX";
|
|
|
|
char* formatoptionlb = "XXXXXXXX XX??";
|
|
|
|
char* formatoptionw = "XXXXXXXX ????";
|
|
|
|
char tempformat[128];
|
|
|
|
|
|
|
|
validcodes = true;
|
|
|
|
nooptions = true;
|
|
|
|
codeformat = -1;
|
|
|
|
int numcodes = 0;
|
|
|
|
|
|
|
|
char codestring[2048];
|
|
|
|
memset(codestring, '\0', sizeof(codestring));
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
numlines = SendDlgItemMessage(hDlg, IDC_CHEAT_CODES, EM_GETLINECOUNT, 0, 0);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (numlines == 0) { validcodes = false; }
|
|
|
|
|
|
|
|
for (linecount=0; linecount<numlines; linecount++) //read line after line (bypassing limitation GetDlgItemText)
|
|
|
|
{
|
|
|
|
memset(tempformat, 0, sizeof(tempformat));
|
|
|
|
|
|
|
|
//str[0] = sizeof(str) > 255?255:sizeof(str);
|
|
|
|
*(LPWORD)str = sizeof(str);
|
2015-03-04 09:36:08 +00:00
|
|
|
len = SendDlgItemMessage(hDlg, IDC_CHEAT_CODES, EM_GETLINE, (WPARAM)linecount, (LPARAM)(LPCSTR)str);
|
2008-09-18 03:15:49 +00:00
|
|
|
str[len] = 0;
|
|
|
|
|
|
|
|
if (len <= 0) { continue; }
|
|
|
|
|
|
|
|
for (i=0; i<128; i++) {
|
2015-04-22 18:06:02 +00:00
|
|
|
if (isxdigit(str[i])) {
|
2008-09-18 03:15:49 +00:00
|
|
|
tempformat[i] = 'X';
|
|
|
|
}
|
|
|
|
if ((str[i] == ' ') || (str[i] == '?')) {
|
|
|
|
tempformat[i] = str[i];
|
|
|
|
}
|
|
|
|
if (str[i] == 0) { break; }
|
|
|
|
}
|
|
|
|
if (strcmp(tempformat, formatnormal) == 0) {
|
|
|
|
strcat(codestring, ",");
|
|
|
|
strcat(codestring, str);
|
|
|
|
numcodes++;
|
|
|
|
if (codeformat < 0) codeformat = 0;
|
|
|
|
}
|
|
|
|
else if (strcmp(tempformat, formatoptionlb) == 0) {
|
|
|
|
if (codeformat != 2) {
|
|
|
|
strcat(codestring, ",");
|
|
|
|
strcat(codestring, str);
|
|
|
|
numcodes++;
|
|
|
|
codeformat = 1;
|
|
|
|
nooptions = false;
|
|
|
|
validoptions = false;
|
|
|
|
}
|
|
|
|
else validcodes = false;
|
|
|
|
}
|
|
|
|
else if (strcmp(tempformat, formatoptionw) == 0) {
|
|
|
|
if (codeformat != 1) {
|
|
|
|
strcat(codestring, ",");
|
|
|
|
strcat(codestring, str);
|
|
|
|
numcodes++;
|
|
|
|
codeformat = 2;
|
|
|
|
nooptions = false;
|
|
|
|
validoptions = false;
|
|
|
|
}
|
|
|
|
else validcodes = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
validcodes = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strlen(codestring) == 0)
|
|
|
|
{
|
|
|
|
validcodes = false;
|
|
|
|
}
|
|
|
|
return codestring;
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:07:44 +00:00
|
|
|
stdstr CCheats::ReadOptionsString(HWND hDlg, bool &/*validcodes*/, bool &validoptions, bool &/*nooptions*/, int &codeformat)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
int numlines, linecount, len;
|
|
|
|
char str[128];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
validoptions = true;
|
|
|
|
int numoptions = 0;
|
|
|
|
|
|
|
|
char optionsstring[2048];
|
|
|
|
memset(optionsstring, '\0', sizeof(optionsstring));
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
numlines = SendDlgItemMessage(hDlg, IDC_CHEAT_OPTIONS, EM_GETLINECOUNT, 0, 0);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
for (linecount=0; linecount<numlines; linecount++) //read line after line (bypassing limitation GetDlgItemText)
|
|
|
|
{
|
|
|
|
memset(str,0,sizeof(str));
|
|
|
|
//str[0] = sizeof(str) > 255?255:sizeof(str);
|
|
|
|
*(LPWORD)str = sizeof(str);
|
2015-03-04 09:36:08 +00:00
|
|
|
len = SendDlgItemMessage(hDlg, IDC_CHEAT_OPTIONS, EM_GETLINE, (WPARAM)linecount, (LPARAM)(LPCSTR)str);
|
2008-09-18 03:15:49 +00:00
|
|
|
str[len] = 0;
|
|
|
|
|
|
|
|
if (len > 0) {
|
|
|
|
switch (codeformat) {
|
|
|
|
case 1: //option = lower byte
|
|
|
|
if (len >= 2) {
|
|
|
|
for (i=0; i<2; i++) {
|
2015-04-22 18:06:02 +00:00
|
|
|
if (!isxdigit(str[i])) {
|
2008-09-18 03:15:49 +00:00
|
|
|
validoptions = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((str[2] != ' ') && (len > 2)) {
|
|
|
|
validoptions = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j=0; j<2; j++) {
|
2012-10-06 04:09:17 +00:00
|
|
|
str[j] = (char)toupper(str[j]);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (optionsstring[0] == 0)
|
|
|
|
{
|
|
|
|
strcat(optionsstring, "$");
|
|
|
|
} else {
|
|
|
|
strcat(optionsstring, ",$");
|
|
|
|
}
|
|
|
|
strcat(optionsstring, str);
|
|
|
|
numoptions++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
validoptions = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: //option = word
|
|
|
|
if (len >= 4) {
|
|
|
|
for (i=0; i<4; i++) {
|
2015-04-22 18:06:02 +00:00
|
|
|
if (!isxdigit(str[i])) {
|
2008-09-18 03:15:49 +00:00
|
|
|
validoptions = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str[4] != ' ' && (len > 4)) {
|
|
|
|
validoptions = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j=0; j<4; j++) {
|
2012-10-06 04:09:17 +00:00
|
|
|
str[j] = (char)toupper(str[j]);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strcat(optionsstring, ",$");
|
|
|
|
strcat(optionsstring, str);
|
|
|
|
numoptions++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
validoptions = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numoptions < 1) validoptions = false;
|
|
|
|
return optionsstring;
|
|
|
|
}
|