Exemple #1
0
void gtkui_cheats_par_add(GtkWidget *widget, gpointer userdata) {
	// Add a Pro Action Rocky code to the list
	GtkTreeIter iter;
	
	Cheats cheats(emulator);
	Cheats::Code code;
	
	char codebuf[9];
	char descbuf[512];
	
	snprintf(codebuf, sizeof(codebuf), "%.8s", gtk_entry_get_text(GTK_ENTRY(paredit)));
	snprintf(descbuf, sizeof(descbuf), "%s", gtk_entry_get_text(GTK_ENTRY(descedit)));
	
	if (cheats.ProActionRockyDecode(codebuf, code) == Nes::RESULT_OK) {
		gtk_tree_store_append(treestore, &iter, NULL);
		gtk_tree_store_set(treestore, &iter,
					0, true,
					1, codebuf,
					4, descbuf,
					-1);
		gtk_entry_set_text(GTK_ENTRY(descedit), "");
		gtk_entry_set_text(GTK_ENTRY(ggedit), "");
		gtk_entry_set_text(GTK_ENTRY(paredit), "");
		gtk_widget_hide(infobar);
		gtk_label_set_text(GTK_LABEL(infolabel), "");
		cheats.SetCode(code);
	}
	else {
		gtk_info_bar_set_message_type(GTK_INFO_BAR(infobar), GTK_MESSAGE_ERROR);
		gtk_label_set_text(GTK_LABEL(infolabel), "Error: Invalid PAR code");
		gtk_widget_show(infobar);
	}
}
Exemple #2
0
void gtkui_cheats_toggle(GtkWidget *widget, gpointer userdata) {
	// Toggle a cheat on or off
	GtkTreeIter iter;
	GtkTreeModel *model;
	GtkTreeSelection *selection;
	
	bool value;
	
	// Get the selected item
	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
	gtk_tree_selection_get_selected(selection, &model, &iter);
	
	// Read the value of the checkbox
	gtk_tree_model_get(model, &iter, 0, &value, -1);
	
	// Flip the value and set it
	value ^= 1;
	gtk_tree_store_set(treestore, &iter, 0, value, -1);
	
	//Re-initialize the cheats
	Cheats cheats(emulator);
	cheats.ClearCodes();
	
	gtk_tree_model_foreach(GTK_TREE_MODEL(model), gtkui_cheats_scan_list, NULL);
}
Exemple #3
0
void cheats_code_gg_add(const wchar_t *data) {
	// Add a Game Genie code
	Cheats cheats(emulator);
	Cheats::Code code;
	
	char gg[9];
	wcstombs(gg, data, sizeof(gg));
	
	cheats.GameGenieDecode(gg, code);
	cheats.SetCode(code);
}
Exemple #4
0
void cheats_code_par_add(const wchar_t *data) {
	// Add a Pro Action Rocky code
	Cheats cheats(emulator);
	Cheats::Code code;
	
	char par[9];
	wcstombs(par, data, sizeof(par));
	
	cheats.ProActionRockyDecode(par, code);
	cheats.SetCode(code);
}
Exemple #5
0
gboolean gtkui_cheats_scan_list(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer userdata) {
	// Scan through the list of cheats
	Cheats cheats(emulator);
	Cheats::Code code;
	
	bool enabled;
	gchar *ggcode, *parcode, *rawcode, *description;
	
	gtk_tree_model_get(model, iter, 0, &enabled, 1, &ggcode, 2, &parcode, 3, &rawcode, 4, &description, -1);
	
	if (enabled) {
		if (ggcode) {
			cheats.GameGenieDecode(ggcode, code);
			cheats.SetCode(code);
		}
		else if (parcode) {
			cheats.ProActionRockyDecode(parcode, code);
			cheats.SetCode(code);
		}
		else if (rawcode) {
			code.useCompare = false;
			
			int addr, value, compare;
			char buf[5];
			
			snprintf(buf, sizeof(buf), "%c%c%c%c", rawcode[0], rawcode[1], rawcode[2], rawcode[3]);
			sscanf(buf, "%x", &addr);
			
			snprintf(buf, sizeof(buf), "%c%c", rawcode[5], rawcode[6]);
			sscanf(buf, "%x", &value);
			
			snprintf(buf, sizeof(buf), "%c%c", rawcode[8], rawcode[9]);
			sscanf(buf, "%x", &compare);
			
			code.address = addr;
			code.value = value;
			code.compare = compare;
			
			if (compare) { code.useCompare = true; }
			
			cheats.SetCode(code);
		}
	}
	
	g_free(ggcode);
	g_free(parcode);
	g_free(rawcode);
	g_free(description);
	
	return false;
}
		void Cheats::Flush() const
		{
			Nes::Cheats cheats( emulator );
			cheats.ClearCodes();

			if (game && paths.AutoSaveCheatsEnabled())
			{
				const Path path( paths.GetCheatPath( emulator.GetImagePath() ) );

				if (dialog->Save( path ))
					Io::Log() << "Cheats: saved cheats to \"" << path << "\"\r\n";
			}

			dialog->Flush();
		}
Exemple #7
0
void cheats_code_raw_add(Xml::Node node) {
	// Add a Raw code
	Cheats cheats(emulator);
	Cheats::Code code;
	
	code.useCompare = false;
	
	code.address = node.GetChild(L"address").GetUnsignedValue();
	if (node.GetChild(L"value")) {
		code.value = node.GetChild(L"value").GetUnsignedValue();
	}
	if (node.GetChild(L"compare")) {
		code.compare = node.GetChild(L"compare").GetUnsignedValue();
		code.useCompare = true;
	}
	cheats.SetCode(code);
}
		void Cheats::Update() const
		{
			Nes::Cheats cheats( emulator );
			cheats.ClearCodes();

			if (game)
			{
				for (uint crc = Nes::Cartridge(emulator).GetProfile() ? Nes::Cartridge(emulator).GetProfile()->hash.GetCrc32() : 0, i = 0; i < 2; ++i)
				{
					const Window::Cheats::Codes& codes = dialog->GetCodes( i ? Window::Cheats::PERMANENT_CODES : Window::Cheats::TEMPORARY_CODES );

					for (Window::Cheats::Codes::const_iterator it(codes.begin()), end(codes.end()); it != end; ++it)
					{
						if (it->enabled && (it->crc == 0 || it->crc == crc))
							cheats.SetCode( it->ToNesCode() );
					}
				}
			}
		}
Exemple #9
0
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();
	}
}
Exemple #10
0
void gtkui_cheats_remove(GtkWidget *widget, gpointer userdata) {
	// Remove a cheat from the list
	GtkTreeIter iter;
	GtkTreeModel *model;
	GtkTreeSelection *selection;
	
	// Get the selected item
	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
	gtk_tree_selection_get_selected(selection, &model, &iter);

	// Remove the cheat
	if (gtk_tree_store_iter_is_valid(treestore, &iter)) {
		gtk_tree_store_remove(treestore, &iter);
	}
	
	//Re-initialize the cheats
	Cheats cheats(emulator);
	cheats.ClearCodes();
	
	gtk_tree_model_foreach(GTK_TREE_MODEL(model), gtkui_cheats_scan_list, NULL);
}
Exemple #11
0
void gtkui_cheats_clear() {
	// Clear the list
	gtk_tree_store_clear(treestore);
	Cheats cheats(emulator);
	cheats.ClearCodes();
}