Save ROM name hints

This commit is contained in:
Ilari Liusvaara 2013-09-13 21:34:59 +03:00
parent 82440c44bb
commit 83dcbee83a
10 changed files with 56 additions and 19 deletions

View file

@ -7,9 +7,9 @@
#include <map>
#include "core/controllerframe.hpp"
#include "core/rom.hpp"
#include "core/romtype.hpp"
#include "core/subtitles.hpp"
/**
* This structure gives parsed representationg of movie file, as result of decoding or for encoding.
*/
@ -76,11 +76,15 @@ struct moviefile
/**
* SHA-256 of ROM (empty string if none).
*/
std::string romimg_sha256[27];
std::string romimg_sha256[ROM_SLOT_COUNT];
/**
* SHA-256 of ROM XML (empty string if none).
*/
std::string romxml_sha256[27];
std::string romxml_sha256[ROM_SLOT_COUNT];
/**
* ROM hints (empty string if none).
*/
std::string romname_hint[ROM_SLOT_COUNT];
/**
* Authors of the run, first in each pair is full name, second is nickname.
*/

View file

@ -1,11 +1,14 @@
#ifndef _rom__hpp__included__
#define _rom__hpp__included__
#define ROM_SLOT_COUNT 27
#include <string>
#include <map>
#include <vector>
#include <stdexcept>
#include "core/misc.hpp"
#include "core/moviefile.hpp"
#include "core/romtype.hpp"
/**
@ -60,6 +63,10 @@ struct loaded_slot
* SHA-256 for the data in this slot if data is valid. If no valid data, this field is "".
*/
std::string sha256;
/**
* Name hint. Only for non-XML slots.
*/
std::string namehint;
/**
* Get pointer to loaded data
*
@ -121,11 +128,11 @@ struct loaded_rom
/**
* Loaded main ROM
*/
loaded_slot romimg[27];
loaded_slot romimg[ROM_SLOT_COUNT];
/**
* Loaded main ROM XML
*/
loaded_slot romxml[27];
loaded_slot romxml[ROM_SLOT_COUNT];
/**
* MSU-1 base.
*/

View file

@ -278,9 +278,10 @@ namespace
messages << "Loading ROM " << filenam << std::endl;
loaded_rom newrom(filenam);
*our_rom = newrom;
for(size_t i = 0; i < sizeof(our_rom->romimg)/sizeof(our_rom->romimg[0]); i++) {
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
our_movie.romimg_sha256[i] = our_rom->romimg[i].sha256;
our_movie.romxml_sha256[i] = our_rom->romxml[i].sha256;
our_movie.romname_hint[i] = our_rom->romxml[i].namehint;
}
} catch(std::exception& e) {
messages << "Can't reload ROM: " << e.what() << std::endl;

View file

@ -420,7 +420,9 @@ void do_load_state(struct moviefile& _movie, int lmode)
<< "\tFile is from: " << _movie.coreversion << std::endl;
}
bool rom_ok = true;
for(size_t i = 0; i < sizeof(our_rom->romimg)/sizeof(our_rom->romimg[0]); i++) {
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
if(_movie.romname_hint[i] == "")
_movie.romname_hint[i] = our_rom->romimg[i].namehint;
rom_ok = rom_ok & warn_hash_mismatch(_movie.romimg_sha256[i], our_rom->romimg[i],
(stringfmt() << "ROM #" << (i + 1)).str(), will_load_state);
rom_ok = rom_ok & warn_hash_mismatch(_movie.romxml_sha256[i], our_rom->romxml[i],

View file

@ -387,14 +387,17 @@ moviefile::moviefile(const std::string& movie) throw(std::bad_alloc, std::runtim
read_linefile(r, "coreversion", coreversion);
read_linefile(r, "rom.sha256", romimg_sha256[0], true);
read_linefile(r, "romxml.sha256", romxml_sha256[0], true);
read_linefile(r, "rom.hint", romname_hint[0], true);
unsigned base = 97;
if(r.has_member("slot`.sha256"))
base = 96;
for(size_t i = 0; i < 26; i++) {
read_linefile(r, (stringfmt() << "slot" << (char)(base + i) << ".sha256").str(), romimg_sha256[i + 1],
for(size_t i = 1; i < ROM_SLOT_COUNT; i++) {
read_linefile(r, (stringfmt() << "slot" << (char)(base + i - 1) << ".sha256").str(), romimg_sha256[i],
true);
read_linefile(r, (stringfmt() << "slot" << (char)(base + i) << "xml.sha256").str(),
romxml_sha256[i + 1], true);
read_linefile(r, (stringfmt() << "slot" << (char)(base + i - 1) << "xml.sha256").str(),
romxml_sha256[i], true);
read_linefile(r, (stringfmt() << "slot" << (char)(base + i - 1) << ".hint").str(),
romname_hint[i], true);
}
read_linefile(r, "prefix", prefix, true);
read_subtitles(r, "subtitles", subtitles);
@ -458,11 +461,14 @@ void moviefile::save(const std::string& movie, unsigned compression) throw(std::
write_rrdata(w);
write_linefile(w, "rom.sha256", romimg_sha256[0], true);
write_linefile(w, "romxml.sha256", romxml_sha256[0], true);
for(size_t i = 0; i < 26; i++) {
write_linefile(w, (stringfmt() << "slot" << (char)(97 + i) << ".sha256").str(), romimg_sha256[i + 1],
write_linefile(w, "rom.hint", romname_hint[0], true);
for(size_t i = 1; i < ROM_SLOT_COUNT; i++) {
write_linefile(w, (stringfmt() << "slot" << (char)(96 + i) << ".sha256").str(), romimg_sha256[i],
true);
write_linefile(w, (stringfmt() << "slot" << (char)(97 + i) << "xml.sha256").str(),
romxml_sha256[i + 1], true);
write_linefile(w, (stringfmt() << "slot" << (char)(96 + i) << "xml.sha256").str(),
romxml_sha256[i], true);
write_linefile(w, (stringfmt() << "slot" << (char)(96 + i) << ".hint").str(),
romname_hint[i], true);
}
write_subtitles(w, "subtitles", subtitles);
write_linefile(w, "prefix", prefix, true);

View file

@ -63,6 +63,17 @@ loaded_slot::loaded_slot(const std::string& filename, const std::string& base,
return;
}
valid = true;
std::string _filename = filename;
#if defined(_WIN32) || defined(_WIN64)
const char* split = "/\\";
#else
const char* split = "/";
#endif
size_t s1 = _filename.find_last_of(split);
size_t s2 = _filename.find_last_of(".");
if(s1 < _filename.length()) s1 = s1 + 1; else s1 = 0;
if(s2 <= s1 || s2 >= _filename.length()) s2 = _filename.length();
namehint = _filename.substr(s1, s2 - s1);
data = read_file_relative(filename, base);
if(!xml)
headered = imginfo.headersize(data.size());

View file

@ -36,9 +36,10 @@ struct moviefile generate_movie_template(std::vector<std::string> cmdline, loade
movie.coreversion = bsnes_core_version;
movie.projectid = get_random_hexstring(40);
movie.gametype = &r.rtype->combine_region(*r.region);
for(size_t i = 0; i < sizeof(r.romimg)/sizeof(r.romimg[0]); i++) {
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
movie.romimg_sha256[i] = r.romimg[i].sha256;
movie.romxml_sha256[i] = r.romxml[i].sha256;
movie.romname_hint[i] = r.romimg[i].namehint;
}
movie.movie_sram = load_sram_commandline(cmdline);
for(auto i = cmdline.begin(); i != cmdline.end(); i++) {

View file

@ -459,9 +459,10 @@ bool lsnes_app::OnInit()
//Initialize the remainder.
mov->coreversion = bsnes_core_version;
mov->rerecords = "0";
for(size_t i = 0; i < sizeof(rom->romimg)/sizeof(rom->romimg[0]); i++) {
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
mov->romimg_sha256[i] = rom->romimg[i].sha256;
mov->romxml_sha256[i] = rom->romxml[i].sha256;
mov->romname_hint[i] = rom->romimg[i].namehint;
}
mov->gametype = &rom->rtype->combine_region(*rom->region);
}

View file

@ -374,9 +374,10 @@ struct moviefile wxwin_project::make_movie()
f.prefix = sanitize_prefix(tostdstring(prefix->GetValue()));
f.projectid = get_random_hexstring(40);
f.rerecords = "0";
for(size_t i = 0; i < sizeof(our_rom->romimg)/sizeof(our_rom->romimg[0]); i++) {
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
f.romimg_sha256[i] = our_rom->romimg[i].sha256;
f.romxml_sha256[i] = our_rom->romxml[i].sha256;
f.romname_hint[i] = our_rom->romimg[i].namehint;
}
size_t lines = authors->GetNumberOfLines();
for(size_t i = 0; i < lines; i++) {

View file

@ -56,8 +56,11 @@ int main(int argc, char** argv)
else
std::cout << "No game name available" << std::endl;
std::cout << "Project ID: " << escape_string(m.projectid) << std::endl;
for(size_t i = 0; i < sizeof(m.romimg_sha256)/sizeof(m.romimg_sha256[0]); i++) {
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
if(m.romimg_sha256[i] != "") {
if(m.romname_hint[i] != "")
std::cout << name_subrom(*rtype, 2 * i + 0) << " namehint: "
<< escape_string(m.romname_hint[i]) << std::endl;
std::cout << name_subrom(*rtype, 2 * i + 0) << " checksum: "
<< escape_string(m.romimg_sha256[i]) << std::endl;
if(m.romxml_sha256[i] != "") {