Second to last commit

Everything but getting ISO name
This commit is contained in:
Steven Cherry 2013-05-18 17:04:01 -05:00
parent 0b2885c2fe
commit 9d2667fc0d
7 changed files with 243 additions and 216 deletions

View File

@ -22,6 +22,27 @@
#include "CommonPaths.h"
#include "StringUtils.h"
long parseHexLong(std::string s) {
long value = 0;
if (s.substr(0,2) == "0x") {
//s = s.substr(2);
}
value = strtoul(s.c_str(),0, 0);
return value;
}
long parseLong(std::string s) {
long value = 0;
if (s.substr(0,2) == "0x") {
s = s.substr(2);
value = strtol(s.c_str(),NULL, 16);
} else {
value = strtol(s.c_str(),NULL, 10);
}
return value;
}
// faster than sscanf
bool AsciiToHex(const char* _szValue, u32& result)
{

View File

@ -22,7 +22,8 @@
#include <base/stringutil.h>
#include "Common.h"
long parseHexLong(std::string s);
long parseLong(std::string s);
std::string StringFromFormat(const char* format, ...);
// Cheap!
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args);

View File

@ -80,6 +80,7 @@ public:
bool bTexDeposterize;
int iFpsLimit;
u32 iMaxRecent;
int iEnableCheats;
// Sound
bool bEnableSound;

View File

@ -1,39 +1,48 @@
#include "CwCheat.h"
#include "../Core/CoreTiming.h"
#include "../Core/CoreParameter.h"
#include "StringUtils.h"
#include "Common/FileUtil.h"
#include "Config.h"
using namespace std;
static int CheatEvent = -1;
CheatsGUI member;
CheatsGUI cheatsThread;
CWCheatEngine member;
CWCheatEngine cheatsThread;
void hleCheat(u64 userdata, int cyclesLate);
void __CheatInit() {
CheatEvent = CoreTiming::RegisterEvent("CheatEvent", &hleCheat);
CoreTiming::ScheduleEvent(msToCycles(600), CheatEvent, 0);
CoreTiming::ScheduleEvent(msToCycles(77), CheatEvent, 0);
File::CreateFullPath("Cheats");
if (!File::Exists("Cheats/Cheats.ini")) {
File::CreateEmptyFile("Cheats/Cheats.ini");
}
}
void __CheatShutdown() {
member.Exit();
}
void hleCheat(u64 userdata, int cyclesLate) {
CoreTiming::ScheduleEvent(msToCycles(660), CheatEvent, 0);
CoreTiming::ScheduleEvent(msToCycles(77), CheatEvent, 0);
if (g_Config.iEnableCheats == 1) {
member.Run();
}
CheatsGUI::CheatsGUI() {
}
}
void CheatsGUI::Exit() {
CWCheatEngine::CWCheatEngine() {
}
void CWCheatEngine::Exit() {
exit2 = true;
}
string CheatsGUI::GetNextCode() {
string CWCheatEngine::GetNextCode() {
string code;
string modifier = "_L";
char modifier2 = ' ';
char modifier2 = '0';
while (true) {
if (currentCode >= codes.size()) {
code.clear();
@ -53,7 +62,7 @@ string CheatsGUI::GetNextCode() {
return code;
}
void CheatsGUI::skipCodes(int count) {
void CWCheatEngine::skipCodes(int count) {
for (int i = 0; i < count; i ++) {
if (GetNextCode() == "") {
break;
@ -61,11 +70,11 @@ void CheatsGUI::skipCodes(int count) {
}
}
void CheatsGUI::skipAllCodes() {
void CWCheatEngine::skipAllCodes() {
currentCode = codes.size();
}
int CheatsGUI::getAddress(int value) {
int CWCheatEngine::getAddress(int value) {
// The User space base address has to be added to given value
return (value + 0x08800000) & 0x3FFFFFFF;
}
@ -73,7 +82,7 @@ int CheatsGUI::getAddress(int value) {
void CheatsGUI::AddCheatLine(string& line) {
void CWCheatEngine::AddCheatLine(string& line) {
//Need GUI text area here
string cheatCodes;
if (cheatCodes.length() <= 0) {
@ -81,29 +90,7 @@ void CheatsGUI::AddCheatLine(string& line) {
} else {
cheatCodes += "\n" + line;
}
}
inline static long parseHexLong(string s) {
long value = 0;
if (s.substr(0,2) == "0x") {
s = s.substr(2);
}
value = strtol(s.c_str(),NULL, 16);
return value;
}
inline static long parseLong(string s) {
long value = 0;
if (s.substr(0,2) == "0x") {
s = s.substr(2);
value = strtol(s.c_str(),NULL, 16);
} else {
value = strtol(s.c_str(),NULL, 10);
}
return value;
}
}
inline void trim2(string& str)
{
@ -128,40 +115,55 @@ inline vector<string> makeCodeParts(string l) {
}
trim2(l);
istringstream iss (l);
for (std::string each; std::getline(iss, each, split_char);parts.push_back(each))
{}
std::string each;
while (std::getline(iss, each, split_char)) {
parts.push_back(each);
}
return parts;
}
vector<string> CheatsGUI::GetCodesList() {
string text = "0x203BFA00 0x05F5E0FF";
vector<string> codeslist;
codeslist = makeCodeParts(text);
trim2(codeslist[0]);
trim2(codeslist[1]);
return codeslist;
}
void CheatsGUI::OnCheatsThreadEnded() {
test = 0;
vector<string> CWCheatEngine::GetCodesList() {
string line;
char* skip = "//";
vector<string> codesList; //Read from INI here
ifstream list("D:\\User\\Steven\\Documents\\GitHub\\ppsspp\\Cheats\\Cheats.ini");
for (int i = 0; !list.eof(); i ++) {
getline(list,line, '\n');
if (line.substr(0,2) == skip)
{line.clear();
}
void CheatsGUI::Dispose() {
else {
codesList.push_back(line);
}
}
for( int i = 0; i < codesList.size(); i++) {
trim2(codesList[i]);
}
return codesList;
}
void CheatsGUI::Run() {
CheatsGUI cheats;
void CWCheatEngine::Run() {
CWCheatEngine cheats;
exit2 = false;
while (!exit2) {
codes = cheats.GetCodesList(); //UI Member
currentCode = 0;
while (true) {
string code = "0x203BFA00 0x05F5E0FF";
string code = GetNextCode();
if (code == "") {
Exit();
break;
}
vector<string>parts = makeCodeParts(code);
if (parts[0] == "" || parts.size() < 2) {
continue;
}
int value;
trim2(parts[0]);
trim2(parts[1]);
cout << parts[0] << endl << parts[1];
//cout << parts[0] << endl << parts[1];
unsigned int comm = (unsigned int)parseHexLong(parts[0]);
int arg = (int)parseHexLong(parts[1]);
int addr = getAddress(comm & 0x0FFFFFFF);
@ -465,16 +467,12 @@ void CheatsGUI::Run() {
}
break;
}
default:
break;
}
Exit();
break;
}
}
// exiting...
cheats.OnCheatsThreadEnded();
}
Exit();
}

View File

@ -14,11 +14,9 @@ using namespace std;
vector<string> makeCodeParts(string l);
void trim2(string& str);
static long parseLong(string s);
static long parseHexLong(string s);
class CheatsGUI {
class CWCheatEngine {
private:
static long const serialVersionUID = 6791588139795694296L;
static long const int cheatsThreadSleepMillis = 5;
@ -29,14 +27,11 @@ private:
void skipCodes(int count);
void skipAllCodes();
int getAddress(int value);
bool test;
public:
CheatsGUI();
CWCheatEngine();
string String();
void AddCheatLine(string& line);
void OnCheatsThreadEnded();
void Dispose();
vector<string> GetCodesList();
void Exit();

View File

@ -939,6 +939,14 @@ void SystemScreen::render() {
if (UICheckBox(GEN_ID, x, y += stride, s->T("12HR Time Format"), ALIGN_TOPLEFT, &tf)) {
g_Config.itimeformat = tf ? 1 : 0;
}
bool bEnableCheats = g_Config.iEnableCheats != 0;
UICheckBox(GEN_ID, x, y += stride, s->T("Enable Cheats"), ALIGN_TOPLEFT, &bEnableCheats);
if (bEnableCheats) {
g_Config.iEnableCheats = 1;
}
else {
g_Config.iEnableCheats = 0;
}
bool reportingEnabled = Reporting::IsEnabled();
const static std::string reportHostOfficial = "report.ppsspp.org";

View File

@ -186,6 +186,9 @@ namespace MainWindow
void setFpsLimit(int fps) {
g_Config.iFpsLimit = fps;
}
void enableCheats(int cheats){
g_Config.iEnableCheats = cheats;
}
BOOL Show(HINSTANCE hInstance, int nCmdShow)
{