示例#1
0
static void debug_parse(char *string, const char *error)
{
	if (*string && strchr("~@&", *string))
	{
		char *text = string + 1;
		const char *end;

		if (*text == '"')
		{
			end = parse_string(text, '\n');
			dc_output(1, text, -1);
		}
		else
		{
			dc_output(1, string, -1);
			end = NULL;
		}

		if (error)
			dc_error("%s, ignoring to EOLN", error);
		else if (!end)
			dc_error("\" expected");
		else if (g_str_has_prefix(string, "~^(Scope)#07"))
			on_inspect_signal(string + 12);
	}
 	else if (!strcmp(string, "(gdb) "))  /* gdb.info says "(gdb)" */
 	{
		dc_output(3, "(gdb) ", 6);
		wait_prompt = wait_result;
	}
	else
	{
		char *message;

		for (message = string; isdigit(*message); message++);

		if (error || option_library_messages || !g_str_has_prefix(message, "=library-"))
			dc_output_nl(1, string, -1);

		if (*message == '^')
		{
			iff (wait_result, "extra result")
				wait_result--;
		}

		if (*string == '0' && message > string + 1)
		{
			memmove(string, string + 1, message - string - 1);
			message[-1] = '\0';
		}
		else
			string = NULL;  /* no token */

		if (error)
			dc_error("%s, ignoring to EOLN", error);
		else
			parse_message(message, string);
	}
}
示例#2
0
static void on_memory_bytes_edited(G_GNUC_UNUSED GtkCellRendererText *renderer, gchar *path_str,
	gchar *new_text, G_GNUC_UNUSED gpointer gdata)
{
	if (*new_text && (debug_state() & DS_VARIABLE))
	{
		GtkTreeIter iter;
		const char *addr, *bytes;
		guint i;

		scp_tree_store_get_iter_from_string(store, &iter, path_str);
		scp_tree_store_get(store, &iter, MEMORY_ADDR, &addr, MEMORY_BYTES, &bytes, -1);

		for (i = 0; bytes[i]; i++)
			if (!(isxdigit(bytes[i]) ? isxdigit(new_text[i]) : new_text[i] == ' '))
				break;

		if (bytes[i] || new_text[i])
			dc_error("memory: invalid format");
		else
		{
			utils_strchrepl(new_text, ' ', '\0');
			debug_send_format(T, "07-data-write-memory-bytes 0x%s%s", addr, new_text);
		}
	}
	else
		plugin_blink();
}
示例#3
0
int main(int argc, char** argv)
{
	// Build mask
	if(nullptr != mask)delete mask;
	mask = new std::vector<char>();
	for(int i = 0; i < 0x100; ++i)
	{
		if(bitcount(i) == 4)
		{
			mask->push_back((char)(i & 0xff));
		}
	}
	// Rotate mask start
	int key_sum = 0;
	std::string key(CRYPT_KEY);
	for(uint32_t i = 0; i < key.size(); ++i)
	{
		key_sum += (int)(key[i]);
	}
	mask_pointer = (key_sum) % mask->size();
	control_sum = (char)0;
	int alloc_size = 1; // Reserve one byte for control sum;
	int tmp;
	struct data_save ds;

	// COUNT UNITS ////////////////////////////////////////////////////////////
	if(COMPILE_UNITS)
	{
		std::cout << "Counting units" << std::endl;
		if(!TDoodad::load_XML(SHARE_DIR))
		{
			std::cerr << "Error when loading xml files" << std::endl;
			return dc_error();
		}
		TCreep* tc = nullptr;
		TTower* tt = nullptr;
		Animation* anim = nullptr;
		std::cout << "Counting TCreep elements..." << std::endl;
		std::vector<int> ids = TDoodad::getTCreepIds();
		for(uint32_t i = 0; i < ids.size(); ++i)
		{
			tc = TDoodad::getTCreep(ids[i]);
			++ds.tc_count;
			alloc_size += 28 + tc->getName().size();
			std::cout << ds.tc_count << " - Allocation size: " << alloc_size << "\n";
		}
		std::cout << "Counting TTower elements..." << std::endl;
		ids = TDoodad::getTTowerIds();
		for(uint32_t i = 0; i < ids.size(); ++i)
		{
			tt = TDoodad::getTTower(ids[i]);
			++ds.tt_count;
			alloc_size += 40 + tt->getUpgrades().size() + (int)(UnitType::UNITTYPE_COUNT) + tt->getName().size();
			std::cout << ds.tt_count << " - Allocation size: " << alloc_size << "\n";
		}
		std::cout << "Counting Animation elements..." << std::endl;
		ids = TDoodad::getAnimationIds();
		for(uint32_t i = 0; i < ids.size(); ++i)
		{
			anim = TDoodad::getAnimation(ids[i]);
			++ds.anim_count;
			alloc_size += 32 + anim->getName().size();
			std::cout << ds.anim_count << " - Allocation size: " << alloc_size << "\n";
		}
		alloc_size += 12;
	}

	// COUNT TEXTURES /////////////////////////////////////////////////////////
	if(COMPILE_TEXTURES)
	{
		std::cout << "Counting textures" << std::endl;
		DIR* rep = opendir(SHARE_DIR"/texture");
		if (NULL == rep)
		{
			std::cerr << "Error when opening directory \"" << SHARE_DIR << "/texture\"" << std::endl;
			return dc_error();
		}
		struct dirent* content = readdir(rep);
		int count_textures = 0;
		while(NULL != (content = readdir(rep)))
		{
			++count_textures;
			file_info fi;
			fi.file_name = std::string(content->d_name);

			if(-1 != (int)fi.file_name.find(".png"))
			{
				if(".png" == (fi.file_name.substr(fi.file_name.length()-4, fi.file_name.length()-1)))
				{
					alloc_size += 4 + fi.file_name.size();
					fi.file_path = SHARE_DIR"/texture/" + fi.file_name;
					std::ifstream f(fi.file_path.c_str(), std::ios::ate | std::ios::binary);
					if(!f.good())
					{
						std::cerr << "Error when opening file \"" << fi.file_path << "\"" << std::endl;
						return dc_error();
					}
					fi.file_size = f.tellg();
					alloc_size += 4 + fi.file_size;
					ds.texture_files.push_back(fi);
					f.close();
				}
			}
			std::cout << count_textures << " - Allocation size: " << alloc_size << "\n";
		}
		if (-1 == closedir(rep))
		{
			std::cerr << "Error when closing directory \"" << SHARE_DIR << "/texture\"" << std::endl;
			return dc_error();
		}
	}

	// COUNT FONTS ////////////////////////////////////////////////////////////
	if(COMPILE_FONTS)
	{
		std::cout << "Counting fonts" << std::endl;
		DIR* rep = opendir(SHARE_DIR"/font");
		if (NULL == rep)
		{
			std::cerr << "Error when opening directory \"" << SHARE_DIR << "/font\"" << std::endl;
			return dc_error();
		}
		struct dirent* content = readdir(rep);
		int count_fonts = 0;
		while(NULL != (content = readdir(rep)))
		{
			++count_fonts;
			file_info fi;
			fi.file_name = std::string(content->d_name);

			if(-1 != (int)fi.file_name.find(".ttf"))
			{
				if(".ttf" == (fi.file_name.substr(fi.file_name.length()-4, fi.file_name.length()-1)))
				{
					alloc_size += 4 + fi.file_name.size();
					fi.file_path = SHARE_DIR"/font/" + fi.file_name;
					std::ifstream f(fi.file_path.c_str(), std::ios::ate | std::ios::binary);
					if(!f.good())
					{
						std::cerr << "Error when opening file \"" << fi.file_path << "\"" << std::endl;
						return dc_error();
					}
					fi.file_size = f.tellg();
					alloc_size += 4 + fi.file_size;
					ds.font_files.push_back(fi);
					f.close();
				}
			}
			std::cout << count_fonts << " - Allocation size: " << alloc_size << "\n";
		}
		if (-1 == closedir(rep))
		{
			std::cerr << "Error when closing directory \"" << SHARE_DIR << "/font\"" << std::endl;
			return dc_error();
		}
	}

	// CREATE DATA ////////////////////////////////////////////////////////////
	std::cout << "Allocating data bloc" << std::endl;
	data_byte db = new char[alloc_size];
	int data_pointer = 0;

	// SAVE UNITS /////////////////////////////////////////////////////////////
	if(COMPILE_UNITS)
	{
		std::cout << "Compiling units" << std::endl;
		TCreep* tc = nullptr;
		TTower* tt = nullptr;
		Animation* anim = nullptr;
		dc_compileInteger(&(ds.tc_count), db, &data_pointer, alloc_size);
		tmp = ds.tc_count;
		ds.tc_count = 0;
		std::cout << "Compiling TCreep elements..." << std::endl;
		std::vector<int> ids = TDoodad::getTCreepIds();
		for(uint32_t i = 0; i < ids.size(); ++i)
		{
			tc = TDoodad::getTCreep(ids[i]);
			++ds.tc_count;
			dc_compileCreep(tc, db, &data_pointer, alloc_size);
			std::cout << ds.tc_count << " / " << tmp << "\n";
		}
		dc_compileInteger(&(ds.tt_count), db, &data_pointer, alloc_size);
		tmp = ds.tt_count;
		ds.tt_count = 0;
		std::cout << "Compiling TTower elements..." << std::endl;
		ids = TDoodad::getTTowerIds();
		for(uint32_t i = 0; i < ids.size(); ++i)
		{
			tt = TDoodad::getTTower(ids[i]);
			++ds.tt_count;
			dc_compileTower(tt, db, &data_pointer, alloc_size);
			std::cout << ds.tt_count << " / " << tmp << "\n";
		}
		dc_compileInteger(&(ds.anim_count), db, &data_pointer, alloc_size);
		tmp = ds.anim_count;
		ds.anim_count = 0;
		std::cout << "Compiling Animation elements..." << std::endl;
		ids = TDoodad::getAnimationIds();
		for(uint32_t i = 0; i < ids.size(); ++i)
		{
			anim = TDoodad::getAnimation(ids[i]);
			++ds.anim_count;
			dc_compileAnimation(anim, db, &data_pointer, alloc_size);
			std::cout << ds.anim_count << " / " << tmp << "\n";
		}
	}

	// SAVE TEXTURES //////////////////////////////////////////////////////////
	if(COMPILE_TEXTURES)
	{
		std::cout << "Compiling textures" << std::endl;
		int s = ds.texture_files.size();
		dc_compileInteger(&s, db, &data_pointer, alloc_size);
		std::cout << "0 / " << s << "\n";
        for(int i = 0; i < s; ++i)
		{
			dc_compileString(&(ds.texture_files[i].file_name), db, &data_pointer, alloc_size);
			dc_compileString(&(ds.texture_files[i].file_path), db, &data_pointer, alloc_size);
			dc_compileInteger(&(ds.texture_files[i].file_size), db, &data_pointer, alloc_size);
			std::ifstream f(ds.texture_files[i].file_path.c_str(), std::ios::in | std::ios::binary);
			if(!f.good())
			{
				std::cerr << "Error when opening file \"" << ds.texture_files[i].file_path << "\"" << std::endl;
				return dc_error();
			}
			for(int j = 0; j < ds.texture_files[i].file_size; ++j)
			{
				char c;
				f.read(&c, 1);
				dc_compileChar(&c, db, &data_pointer, alloc_size);
			}
			f.close();
			std::cout << i+1 << " / " << s << "\n";
		}
	}

	// SAVE FONTS /////////////////////////////////////////////////////////////
	if(COMPILE_FONTS)
	{
		std::cout << "Compiling fonts" << std::endl;
		int s = ds.font_files.size();
		dc_compileInteger(&s, db, &data_pointer, alloc_size);
		std::cout << "0 / " << s << "\n";
        for(int i = 0; i < s; ++i)
		{
			dc_compileString(&(ds.font_files[i].file_name), db, &data_pointer, alloc_size);
			dc_compileString(&(ds.font_files[i].file_path), db, &data_pointer, alloc_size);
			dc_compileInteger(&(ds.font_files[i].file_size), db, &data_pointer, alloc_size);
			std::ifstream f(ds.font_files[i].file_path.c_str(), std::ios::in | std::ios::binary);
			if(!f.good())
			{
				std::cerr << "Error when opening file \"" << ds.font_files[i].file_path << "\"" << std::endl;
				return dc_error();
			}
			for(int j = 0; j < ds.font_files[i].file_size; ++j)
			{
				char c;
				f.read(&c, 1);
				dc_compileChar(&c, db, &data_pointer, alloc_size);
			}
			f.close();
			std::cout << i+1 << " / " << s << "\n";
		}
	}

	// SAVE FILE //////////////////////////////////////////////////////////////
	db[data_pointer] = control_sum; // Add ckecksum (one byte)
	std::cout << "\nSaving file..." << std::endl;
	dc_exportData("data.bin", db, alloc_size);
	delete [] db;
	std::cout << "done !" << std::endl;
	system("PAUSE");
	return 0;
}