Save ROM hints

This commit is contained in:
Ilari Liusvaara 2013-09-14 16:29:58 +03:00
parent d25f5bbe78
commit 70ad5377b8
10 changed files with 94 additions and 4 deletions

View file

@ -24,6 +24,9 @@ struct moviefile
std::string sysregion;
std::string corename;
std::string projectid;
std::string hash[ROM_SLOT_COUNT];
std::string hashxml[ROM_SLOT_COUNT];
std::string hint[ROM_SLOT_COUNT];
uint64_t current_frame;
uint64_t rerecords;
private:
@ -94,6 +97,10 @@ struct moviefile
* SHA-256 of ROM XML (empty string if none).
*/
std::string romxml_sha256[ROM_SLOT_COUNT];
/**
* ROM name hint (empty string if none).
*/
std::string namehint[ROM_SLOT_COUNT];
/**
* Authors of the run, first in each pair is full name, second is nickname.
*/

View file

@ -38,6 +38,7 @@ struct project_info
std::string projectid;
std::string romimg_sha256[ROM_SLOT_COUNT];
std::string romxml_sha256[ROM_SLOT_COUNT];
std::string namehint[ROM_SLOT_COUNT];
std::vector<std::pair<std::string, std::string>> authors;
std::map<std::string, std::vector<char>> movie_sram;
std::vector<char> anchor_savestate;

View file

@ -182,6 +182,10 @@ struct loaded_image
* Filename this is loaded from.
*/
std::string filename;
/**
* ROM name hint.
*/
std::string namehint;
/**
* The actual data for this slot.
*/

View file

@ -348,6 +348,7 @@ namespace
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
our_movie.romimg_sha256[i] = our_rom->romimg[i].sha_256.read();
our_movie.romxml_sha256[i] = our_rom->romxml[i].sha_256.read();
our_movie.namehint[i] = our_rom->romimg[i].namehint;
}
} catch(std::exception& e) {
platform::error_message(std::string("Can't load ROM: ") + e.what());

View file

@ -213,6 +213,7 @@ void do_save_state(const std::string& filename, int binary) throw(std::bad_alloc
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
our_movie.romimg_sha256[i] = our_rom->romimg[i].sha_256.read();
our_movie.romxml_sha256[i] = our_rom->romxml[i].sha_256.read();
our_movie.namehint[i] = our_rom->romimg[i].namehint;
}
our_movie.savestate = our_rom->save_core_state();
get_framebuffer().save(our_movie.screenshot);
@ -427,6 +428,8 @@ void do_load_state(struct moviefile& _movie, int lmode)
}
bool rom_ok = true;
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
if(_movie.namehint[i] == "")
_movie.namehint[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

@ -38,7 +38,8 @@ enum lsnes_movie_tags
TAG_SAVESTATE = 0x2e5bc2ac,
TAG_SCREENSHOT = 0xc6760d0e,
TAG_SUBTITLE = 0x6a7054d3,
TAG_RAMCONTENT = 0xd3ec3770
TAG_RAMCONTENT = 0xd3ec3770,
TAG_ROMHINT = 0x6f715830
};
void read_linefile(zip_reader& r, const std::string& member, std::string& out, bool conditional = false)
@ -475,6 +476,20 @@ moviefile::brief_info::brief_info(const std::string& filename)
else
current_frame = 0;
read_numeric_file(r, "rerecords", rerecords);
read_linefile(r, "rom.sha256", hash[0], true);
read_linefile(r, "romxml.sha256", hashxml[0], true);
read_linefile(r, "rom.hint", hint[0], true);
unsigned base = 97;
if(r.has_member("slot`.sha256"))
base = 96;
for(size_t i = 1; i < ROM_SLOT_COUNT; i++) {
read_linefile(r, (stringfmt() << "slot" << (char)(base + i - 1) << ".sha256").str(), hash[i],
true);
read_linefile(r, (stringfmt() << "slot" << (char)(base + i - 1) << "xml.sha256").str(),
hashxml[i], true);
read_linefile(r, (stringfmt() << "slot" << (char)(base + i - 1) << ".hint").str(), hint[i],
true);
}
}
void moviefile::brief_info::binary_io(std::istream& _stream)
@ -497,6 +512,21 @@ void moviefile::brief_info::binary_io(std::istream& _stream)
std::vector<char> c_rrdata;
s.blob_implicit(c_rrdata);
this->rerecords = rrdata::count(c_rrdata);
}},{TAG_ROMHASH, [this](binary_input_stream& s) {
uint8_t n = s.byte();
std::string h = s.string_implicit();
if(n > 2 * ROM_SLOT_COUNT)
return;
if(n & 1)
this->hash[n >> 1] = h;
else
this->hashxml[n >> 1] = h;
}},{TAG_ROMHINT, [this](binary_input_stream& s) {
uint8_t n = s.byte();
std::string h = s.string_implicit();
if(n > ROM_SLOT_COUNT)
return;
this->hint[n] = h;
}}
}, binary_null_default);
}
@ -562,6 +592,7 @@ moviefile::moviefile(const std::string& movie, core_type& romtype) throw(std::ba
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", namehint[0], true);
unsigned base = 97;
if(r.has_member("slot`.sha256"))
base = 96;
@ -570,6 +601,8 @@ moviefile::moviefile(const std::string& movie, core_type& romtype) throw(std::ba
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(), namehint[i],
true);
}
read_subtitles(r, "subtitles", subtitles);
movie_rtc_second = DEFAULT_RTC_SECOND;
@ -653,11 +686,14 @@ void moviefile::save(const std::string& movie, unsigned compression, bool binary
write_rrdata(w);
write_linefile(w, "rom.sha256", romimg_sha256[0], true);
write_linefile(w, "romxml.sha256", romxml_sha256[0], true);
write_linefile(w, "rom.hint", namehint[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)(96 + i) << "xml.sha256").str(), romxml_sha256[i],
true);
write_linefile(w, (stringfmt() << "slot" << (char)(96 + i) << ".hint").str(), namehint[i],
true);
}
write_subtitles(w, "subtitles", subtitles);
for(auto i : movie_sram)
@ -744,12 +780,17 @@ void moviefile::binary_io(std::ostream& _stream) throw(std::bad_alloc, std::runt
out.extension(TAG_ROMHASH, [this, i](binary_output_stream& s) {
if(!this->romimg_sha256[i].length()) return;
s.byte(2 * i);
s.string_implicit(romimg_sha256[i]);
s.string_implicit(this->romimg_sha256[i]);
});
out.extension(TAG_ROMHASH, [this, i](binary_output_stream& s) {
if(!this->romxml_sha256[i].length()) return;
s.byte(2 * i + 1);
s.string_implicit(romxml_sha256[i]);
s.string_implicit(this->romxml_sha256[i]);
});
out.extension(TAG_ROMHINT, [this, i](binary_output_stream& s) {
if(!this->namehint[i].length()) return;
s.byte(i);
s.string_implicit(this->namehint[i]);
});
}
@ -888,6 +929,12 @@ void moviefile::binary_io(std::istream& _stream, core_type& romtype) throw(std::
romxml_sha256[n >> 1] = h;
else
romimg_sha256[n >> 1] = h;
}},{TAG_ROMHINT, [this](binary_input_stream& s) {
uint8_t n = s.byte();
std::string h = s.string_implicit();
if(n > ROM_SLOT_COUNT)
return;
namehint[n] = h;
}},{TAG_RRDATA, [this](binary_input_stream& s) {
s.blob_implicit(this->c_rrdata);
this->rerecords = (stringfmt() << rrdata::count(c_rrdata)).str();

View file

@ -173,6 +173,13 @@ namespace
else
s << "romxml=" << p.romxml_sha256[i] << std::endl;
}
if(p.namehint[i] != "") {
if(i)
s << "slothint" << static_cast<char>(96 + i) << "=" << p.namehint[i]
<< std::endl;
else
s << "romhint=" << p.namehint[i] << std::endl;
}
}
for(auto i : p.settings)
s << "setting." << i.first << "=" << i.second << std::endl;
@ -201,6 +208,7 @@ namespace
for(unsigned i = 0; i < ROM_SLOT_COUNT; i++) {
m.romimg_sha256[i] = p.romimg_sha256[i];
m.romxml_sha256[i] = p.romxml_sha256[i];
m.namehint[i] = p.namehint[i];
}
m.projectid = p.projectid;
m.coreversion = p.coreversion;
@ -283,6 +291,10 @@ project_info& project_load(const std::string& id)
pi.romxml_sha256[0] = r[1];
else if(r = regex("slotxml([a-z])=([0-9a-f]+)", tmp))
pi.romxml_sha256[r[2][0] - 96] = r[2];
else if(r = regex("romhint=(.*)", tmp))
pi.namehint[0] = r[1];
else if(r = regex("slothint([a-z])=(.*)", tmp))
pi.namehint[r[2][0] - 96] = r[2];
else if(r = regex("setting.([^=]+)=(.*)", tmp))
pi.settings[r[1]] = r[2];
else if(r = regex("watch.([^=]+)=(.*)", tmp))

View file

@ -396,6 +396,18 @@ loaded_image::loaded_image(sha256_hasher& h, const std::string& _filename, const
return;
}
std::string xfilename = _filename;
#if defined(_WIN32) || defined(_WIN64)
const char* split = "/\\";
#else
const char* split = "/";
#endif
size_t s1 = xfilename.find_last_of(split);
size_t s2 = xfilename.find_last_of(".");
if(s1 < xfilename.length()) s1 = s1 + 1; else s1 = 0;
if(s2 <= s1 || s2 >= xfilename.length()) s2 = xfilename.length();
namehint = xfilename.substr(s1, s2 - s1);
//Load markups and memory images.
if(info.type == info::IT_MEMORY || info.type == info::IT_MARKUP) {
unsigned headered = 0;

View file

@ -480,6 +480,7 @@ bool lsnes_app::OnInit()
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
mov->romimg_sha256[i] = rom->romimg[i].sha_256.read();
mov->romxml_sha256[i] = rom->romxml[i].sha_256.read();
mov->namehint[i] = rom->romimg[i].namehint;
}
}
mov->gametype = &rom->rtype->combine_region(*rom->region);

View file

@ -256,6 +256,7 @@ namespace
for(unsigned i = 0; i < ROM_SLOT_COUNT; i++) {
pinfo.romimg_sha256[i] = our_movie.romimg_sha256[i];
pinfo.romxml_sha256[i] = our_movie.romxml_sha256[i];
pinfo.namehint[i] = our_movie.namehint[i];
}
for(unsigned i = 0; i < luascripts->GetCount(); i++)
pinfo.luascripts.push_back(tostdstring(luascripts->GetString(i)));
@ -610,6 +611,7 @@ struct moviefile wxwin_project::make_movie()
for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
f.romimg_sha256[i] = our_rom->romimg[i].sha_256.read();
f.romxml_sha256[i] = our_rom->romxml[i].sha_256.read();
f.namehint[i] = our_rom->romimg[i].namehint;
}
size_t lines = authors->GetNumberOfLines();
for(size_t i = 0; i < lines; i++) {
@ -640,7 +642,7 @@ struct moviefile wxwin_project::make_movie()
void open_new_project_window(wxWindow* parent)
{
if(current_romfile == "") {
if(our_rom->rtype->isnull()) {
show_message_ok(parent, "Can't start new project", "No ROM loaded", wxICON_EXCLAMATION);
return;
}