Example #1
0
static int main_add(SaveBlock & save, int argc, char ** argv) {
	
	if(!save.open(true)) {
		return 2;
	}
	
	for(int i = 0; i < argc; i++) {
		
		size_t size;
		char * data = fs::read_file(argv[i], size);
		
		if(!data) {
			cerr << "error loading " << argv[i];
		} else {
			
			string name = argv[i];
			size_t pos = name.find_last_of("/\\");
			if(pos != string::npos) {
				name = name.substr(pos + 1);
			}
			
			if(!save.save(name, data, size)) {
				cerr << "error writing " << name << " to save";
			}
			
			delete[] data;
		}
		
	}
	
	save.flush("pld");
	
	return 0;
}
Example #2
0
int getStarCoinCount() {
	SaveBlock *save = GetSaveFile()->GetBlock(-1);
	int coinsEarned = 0;

	for (int w = 0; w < 10; w++) {
		for (int l = 0; l < 42; l++) {
			u32 conds = save->GetLevelCondition(w, l);

			if (conds & COND_COIN1) { coinsEarned++; }
			if (conds & COND_COIN2) { coinsEarned++; }
			if (conds & COND_COIN3) { coinsEarned++; }
		}
	}

	return coinsEarned;
}
Example #3
0
int main_rename(SaveBlock & save, int argc, char ** argv) {
	
	(void)argv;
	
	if(argc != 1) {
		return -1;
	}
	
	if(!save.open(true)) {
		std::cerr << "failed to open savefile" << std::endl;
		return 2;
	}
	
	MappedPld pld(save);
	
	if(!pld.load()) {
		std::cerr << "failed to load pld data" << std::endl;
		return 3;
	}
	
	std::string oldName = pld.getName();
	std::string newName = argv[0];
	
	std::cout << "Old Name: \"" << oldName << '"' << std::endl;
	std::cout << "New Name: \"" << newName << '"' << std::endl;
	
	pld.setName(newName);
	pld.save();
	
	return 0;
}
Example #4
0
static int main_extract(SaveBlock & save, int argc, char ** argv) {
	
	(void)argv;
	
	if(argc != 0) {
		return -1;
	}
	
	if(!save.open()) {
		return 2;
	}
	
	vector<string> files = save.getFiles();
	
	for(vector<string>::iterator file = files.begin(); file != files.end(); ++file) {
		
		size_t size;
		char * data = save.load(*file, size);
		if(!data) {
			cerr << "error loading " << *file << " from save" << endl;
			continue;
		}
		
		fs::ofstream h(*file, std::ios_base::out | std::ios_base::binary);
		if(!h.is_open()) {
			cerr << "error opening " << *file << " for writing" << endl;
			continue;
		}
		
		if(h.write(data, size).fail()) {
			cerr << "error writing to " << *file << endl;
		}
		
	}
	
	return 0;
}