// DIP Switches void dip_handle() { // Handle the DIP switch file DipSwitches dipswitches(emulator); Xml xml; char dippath[512]; snprintf(dippath, sizeof(dippath), "%s%s.dip", nstpaths.savedir, nstpaths.gamename); std::ifstream dipfile(dippath, std::ifstream::in|std::ifstream::binary); if (dipfile.is_open()) { xml.Read(dipfile); if (xml.GetRoot().IsType(L"dipswitches")) { Xml::Node root(xml.GetRoot()); Xml::Node node(root.GetFirstChild()); for (int i = 0; i < root.NumChildren(L"dip"); i++) { if (node.GetChild(L"value")) { dipswitches.SetValue(i, node.GetChild(L"value").GetUnsignedValue()); } node = node.GetNextSibling(); } } dipfile.close(); } else { Xml::Node root(xml.GetRoot()); root = xml.Create(L"dipswitches"); root.AddAttribute(L"version", L"1.0"); wchar_t wbuf[32]; char buf[2]; int numdips = dipswitches.NumDips(); if (numdips > 0) { for (int i = 0; i < numdips; i++) { Xml::Node node(root.AddChild(L"dip")); mbstowcs(wbuf, dipswitches.GetDipName(i), sizeof(wbuf)); node.AddChild(L"description", wbuf); snprintf(buf, sizeof(buf), "%d", dipswitches.GetValue(i)); mbstowcs(wbuf, buf, sizeof(buf)); node.AddChild(L"value", wbuf); } } std::ofstream dipout(dippath, std::ifstream::out|std::ifstream::binary); if (dipout.is_open()) { xml.Write(root, dipout); } dipout.close(); } }
void Netplay::LoadFile() { try { //const Path path( Application::Instance::GetExePath(L"netplaylist.xml") ); const Path path( Application::Instance::GetConfigPath(L"netplaylist.xml") );//bg if (path.FileExists()) { typedef Nes::Core::Xml Xml; Xml xml; { Io::Stream::In stream( path ); xml.Read( stream ); } if (!xml.GetRoot().IsType( L"netplaylist" )) throw 1; for (Xml::Node node(xml.GetRoot().GetFirstChild()); node; node=node.GetNextSibling()) { if (!node.IsType( L"file" )) throw 1; Add( node.GetValue() ); } Io::Log() << "Netplay: loaded game list from \"netplaylist.xml\"\r\n"; } else { Io::Log() << "Netplay: game list file \"netplaylist.xml\" not present..\r\n"; } } catch (...) { games.state = Games::DIRTY; Io::Log() << "Netplay: warning, couldn't load game list \"netplaylist.xml\"!\r\n"; } }
void cheats_init() { // Initialize cheat engine Cheats cheats(emulator); Xml xml; cheats.ClearCodes(); std::ifstream cheatfile(nstpaths.cheatpath, std::ifstream::in|std::ifstream::binary); if (cheatfile.is_open()) { xml.Read(cheatfile); if (xml.GetRoot().IsType(L"cheats")) { Xml::Node root(xml.GetRoot()); Xml::Node node(root.GetFirstChild()); for (int i = 0; i < root.NumChildren(L"cheat"); i++) { if (node.GetAttribute(L"enabled").IsValue(L"1")) { if (node.GetChild(L"genie")) { // Game Genie cheats_code_gg_add(node.GetChild(L"genie").GetValue()); } else if (node.GetChild(L"rocky")) { // Pro Action Rocky cheats_code_par_add(node.GetChild(L"rocky").GetValue()); } else if (node.GetChild(L"address")) { // Raw cheats_code_raw_add(node); } //fprintf(stderr, "Cheat: %ls\n", node.GetChild(L"description").GetValue()); } node = node.GetNextSibling(); } } cheatfile.close(); } }
void on_cheatopen_clicked(GtkButton *button, gpointer user_data) { GtkWidget *dialog; GtkFileFilter *filter; Xml xml; Cheats cheats(emulator); CheatMgr *cmgr = (CheatMgr *)user_data; char description[64]; dialog = gtk_file_chooser_dialog_new ("Import cheats (.xml)", GTK_WINDOW(mainwindow), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, "NEStopia XML cheats"); gtk_file_filter_add_pattern(filter, "*.xml"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); std::ifstream stream( filename, std::ifstream::in|std::ifstream::binary ); if (stream.is_open()) { xml.Read( stream ); if (xml.GetRoot().IsType( L"cheats" )) { for (Xml::Node node(xml.GetRoot().GetFirstChild()); node; node=node.GetNextSibling()) { if (!node.IsType( L"cheat" )) continue; Cheats::Code code; code.useCompare = false; if (const Xml::Node address=node.GetChild( L"address" )) { uint v; if (0xFFFF < (v=address.GetUnsignedValue())) continue; code.address = v; if (const Xml::Node value=node.GetChild( L"value" )) { if (0xFF < (v=value.GetUnsignedValue())) continue; code.value = v; } if (const Xml::Node compare=node.GetChild( L"compare" )) { if (0xFF < (v=compare.GetUnsignedValue())) continue; code.compare = v; code.useCompare = true; } } else { char codestr[512]; if (const Xml::Node genie=node.GetChild( L"genie" )) { wcstombs(codestr, genie.GetValue(), 511); if (cheats.GameGenieDecode(codestr, code) != Nes::RESULT_OK) { continue; } } else if (const Xml::Node rocky=node.GetChild( L"rocky" )) { wcstombs(codestr, rocky.GetValue(), 511); if (cheats.ProActionRockyDecode(codestr, code) != Nes::RESULT_OK) { continue; } } else { continue; } } // add the code, with a description if it's got one if (node.GetChild( L"description" )) { wcstombs(description, node.GetChild( L"description" ).GetValue(), 63); cmgr->AddCode(code, true, node.GetAttribute( L"enabled" ).IsValue( L"0" ) ? false : true, description); } else { cmgr->AddCode(code, true, node.GetAttribute( L"enabled" ).IsValue( L"0" ) ? false : true); } // poke in the CRC too if there is one cheatlist[cheatlist.size()-1].crc = node.GetAttribute( L"game" ).GetUnsignedValue(); } } } g_free (filename); } gtk_widget_destroy(dialog); }
void gtkui_cheats_fill_tree(char *filename) { // Fill the cheat list Xml xml; GtkTreeIter iter; bool enabled = false; char codebuf[9]; char descbuf[512]; gtkui_cheats_clear(); std::ifstream cheatfile(filename, std::ifstream::in|std::ifstream::binary); if (cheatfile.is_open()) { xml.Read(cheatfile); if (xml.GetRoot().IsType(L"cheats")) { Xml::Node root(xml.GetRoot()); Xml::Node node(root.GetFirstChild()); for (int i = 0; i < root.NumChildren(L"cheat"); i++) { wcstombs(descbuf, node.GetChild(L"description").GetValue(), sizeof(descbuf)); // Check if the cheat is enabled node.GetAttribute(L"enabled").IsValue(L"1") ? enabled = true : enabled = false; // Add the cheats to the list if (node.GetChild(L"genie")) { // Game Genie wcstombs(codebuf, node.GetChild(L"genie").GetValue(), sizeof(codebuf)); gtk_tree_store_append(treestore, &iter, NULL); gtk_tree_store_set(treestore, &iter, 0, enabled, 1, codebuf, 4, descbuf, -1); if (enabled) { cheats_code_gg_add(node.GetChild(L"genie").GetValue()); } } else if (node.GetChild(L"rocky")) { // Pro Action Rocky wcstombs(codebuf, node.GetChild(L"rocky").GetValue(), sizeof(codebuf)); gtk_tree_store_append(treestore, &iter, NULL); gtk_tree_store_set(treestore, &iter, 0, enabled, 2, codebuf, 4, descbuf, -1); if (enabled) { cheats_code_par_add(node.GetChild(L"rocky").GetValue()); } } else if (node.GetChild(L"address")) { // Raw char rawbuf[11]; snprintf(rawbuf, sizeof(rawbuf), "%04lu %02lu %02lu", node.GetChild(L"address").GetUnsignedValue(), node.GetChild(L"value").GetUnsignedValue(), node.GetChild(L"compare").GetUnsignedValue()); gtk_tree_store_append(treestore, &iter, NULL); gtk_tree_store_set(treestore, &iter, 0, enabled, 3, rawbuf, 4, descbuf, -1); if (enabled) { cheats_code_raw_add(node); } } node = node.GetNextSibling(); } } cheatfile.close(); } }