forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Themaister
committed
Apr 17, 2011
1 parent
1005d7f
commit 092fa9d
Showing
11 changed files
with
262 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. | ||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen | ||
* | ||
* Some code herein may be based on code found in BSNES. | ||
* | ||
* SSNES is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU General Public License as published by the Free Software Found- | ||
* ation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
* PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with SSNES. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "cheats.h" | ||
#include "sha256.h" | ||
#include "dynamic.h" | ||
#include "general.h" | ||
|
||
#include <stdlib.h> | ||
#include <stddef.h> | ||
#include <string.h> | ||
|
||
#include <libxml/parser.h> | ||
#include <libxml/tree.h> | ||
|
||
struct cheat | ||
{ | ||
char *desc; | ||
bool state; | ||
char *code; | ||
}; | ||
|
||
struct cheat_manager | ||
{ | ||
struct cheat *cheats; | ||
unsigned ptr; | ||
unsigned size; | ||
}; | ||
|
||
static void xml_grab_cheats(cheat_manager_t *handle, xmlNodePtr ptr) | ||
{ | ||
xmlNodePtr node = NULL; | ||
for (node = ptr; node; node = node->next) | ||
{ | ||
if (strcmp((const char*)node->name, "name") == 0) | ||
{ | ||
xmlChar *name = xmlNodeGetContent(node); | ||
if (name) | ||
{ | ||
SSNES_LOG("Found cheat for game: \"%s\"\n", name); | ||
xmlFree(name); | ||
} | ||
} | ||
} | ||
} | ||
|
||
cheat_manager_t* cheat_manager_new(const char *path) | ||
{ | ||
psnes_cheat_reset(); | ||
|
||
cheat_manager_t *handle = calloc(1, sizeof(handle)); | ||
if (!handle) | ||
return NULL; | ||
|
||
xmlParserCtxtPtr ctx = NULL; | ||
xmlDocPtr doc = NULL; | ||
|
||
ctx = xmlNewParserCtxt(); | ||
if (!ctx) | ||
goto error; | ||
|
||
doc = xmlCtxtReadFile(ctx, path, NULL, 0); | ||
if (!doc) | ||
{ | ||
SSNES_ERR("Failed to parse XML file: %s\n", path); | ||
goto error; | ||
} | ||
|
||
if (ctx->valid == 0) | ||
{ | ||
SSNES_ERR("Cannot validate XML file: %s\n", path); | ||
goto error; | ||
} | ||
|
||
xmlNodePtr head = xmlDocGetRootElement(doc); | ||
xmlNodePtr cur = NULL; | ||
for (cur = head; cur; cur = cur->next) | ||
{ | ||
if (cur->type == XML_ELEMENT_NODE && strcmp((const char*)cur->name, "database") == 0) | ||
break; | ||
} | ||
|
||
if (!cur) | ||
goto error; | ||
|
||
for (cur = cur->children; cur; cur = cur->next) | ||
{ | ||
if (cur->type != XML_ELEMENT_NODE) | ||
continue; | ||
|
||
if (strcmp((const char*)cur->name, "cartridge") == 0) | ||
{ | ||
xmlChar *sha256 = xmlGetProp(cur, (const xmlChar*)"sha256"); | ||
if (!sha256) | ||
continue; | ||
|
||
if (memcmp(sha256, g_extern.sha256, 64) == 0) | ||
{ | ||
xmlFree(sha256); | ||
break; | ||
} | ||
|
||
xmlFree(sha256); | ||
} | ||
} | ||
|
||
if (!cur) | ||
goto error; | ||
|
||
xml_grab_cheats(handle, cur->children); | ||
|
||
xmlFreeDoc(doc); | ||
xmlFreeParserCtxt(ctx); | ||
return handle; | ||
|
||
error: | ||
cheat_manager_free(handle); | ||
if (doc) | ||
xmlFreeDoc(doc); | ||
if (ctx) | ||
xmlFreeParserCtxt(ctx); | ||
return NULL; | ||
} | ||
|
||
void cheat_manager_free(cheat_manager_t *handle) | ||
{ | ||
if (!handle) | ||
return; | ||
|
||
if (handle->cheats) | ||
{ | ||
for (unsigned i = 0; i < handle->size; i++) | ||
{ | ||
xmlFree(handle->cheats[i].desc); | ||
xmlFree(handle->cheats[i].code); | ||
} | ||
|
||
free(handle->cheats); | ||
} | ||
|
||
free(handle); | ||
} | ||
|
||
void cheat_manager_toggle(cheat_manager_t *handle) | ||
{ | ||
handle->cheats[handle->ptr].state ^= true; | ||
psnes_cheat_set(handle->ptr, handle->cheats[handle->ptr].state, handle->cheats[handle->ptr].code); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. | ||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen | ||
* | ||
* Some code herein may be based on code found in BSNES. | ||
* | ||
* SSNES is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU General Public License as published by the Free Software Found- | ||
* ation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
* PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with SSNES. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __SSNES_CHEATS_H | ||
#define __SSNES_CHEATS_H | ||
|
||
typedef struct cheat_manager cheat_manager_t; | ||
|
||
cheat_manager_t* cheat_manager_new(const char *path); | ||
void cheat_manager_free(cheat_manager_t *handle); | ||
|
||
void cheat_manager_index_offset(cheat_manager_t *handle, int offset); | ||
void cheat_manager_toggle(cheat_manager_t *handle); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.