コード例 #1
0
ファイル: cheats.cpp プロジェクト: Pulfer/nestopia
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();
	}
}
コード例 #2
0
ファイル: gtkui_cheats.cpp プロジェクト: joepogo/nestopia
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();
	}	
}