1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-08 06:59:55 +00:00

protected the loading of modes

This commit is contained in:
Zeno Rogue 2024-06-02 16:51:45 +02:00
parent 43f998453e
commit cd11bc2332
2 changed files with 33 additions and 22 deletions

View File

@ -202,14 +202,6 @@ int modecodetable[42][6] = {
}; };
// unused codes: 6 (cheat/tampered), 25, 254, 255 // unused codes: 6 (cheat/tampered), 25, 254, 255
EX eLandStructure get_default_land_structure() {
return
(princess::challenge || tactic::on) ? lsSingle :
racing::on ? lsSingle :
yendor::on ? yendor::get_land_structure() :
lsNiceWalls;
}
EX modecode_t legacy_modecode() { EX modecode_t legacy_modecode() {
if(int(geometry) > 3 || int(variation) > 1) return UNKNOWN; if(int(geometry) > 3 || int(variation) > 1) return UNKNOWN;
if(casual) return UNKNOWN; if(casual) return UNKNOWN;

View File

@ -1160,7 +1160,10 @@ EX modecode_t modecode(int mode) {
code_for[nover] = next; code_for[nover] = next;
identify_modes[next] = next; identify_modes[next] = next;
if(mode == 2) return next; if(mode == 2) {
mode_description_of[next] = mode_description1();
return next;
}
if(scorefile == "") return next; if(scorefile == "") return next;
@ -1403,7 +1406,7 @@ EX namespace peace {
auto aNext = addHook(hooks_nextland, 100, getNext); auto aNext = addHook(hooks_nextland, 100, getNext);
EX } EX }
map<modecode_t, string> mode_description_of; EX map<modecode_t, string> mode_description_of;
void mode_screen_for_current() { void mode_screen_for_current() {
cmode = sm::SIDE | sm::MAYDARK; cmode = sm::SIDE | sm::MAYDARK;
@ -1438,24 +1441,40 @@ void mode_screen_for_current() {
dialog::display(); dialog::display();
} }
void push_mode_screen_for(modecode_t mf) { void enable_mode_by_code(modecode_t mf) {
stop_game(); stop_game();
shstream ss; shstream ss;
ss.s = meaning[mf]; ss.s = meaning[mf];
if(ss.s == "LEGACY") { println(hlog, "enabling modecode ", mf, " : ", as_hexstring(ss.s));
hlog.flush();
try {
if(ss.s == "LEGACY" || mf < FIRST_MODECODE) {
legacy_modecode_read(mf); legacy_modecode_read(mf);
} }
else { else {
ss.read(ss.vernum); ss.read(ss.vernum);
if(ss.vernum < 0xAA05) if(ss.vernum < 0xAA05) {
use_custom_land_list = false;
mapstream::load_geometry(ss); mapstream::load_geometry(ss);
}
else { else {
ss.write_char(0); ss.write_char(0);
load_mode_data_with_zero(ss); load_mode_data_with_zero(ss);
} }
} }
start_game();
mode_description_of[mf] = mode_description1(); mode_description_of[mf] = mode_description1();
}
catch(hr_exception& e) {
stop_game();
println(hlog, "failed: ", e.what());
mode_description_of[mf] = "FAILED";
geometry = gNormal; variation = eVariation::bitruncated;
}
}
void push_mode_screen_for(modecode_t mf) {
enable_mode_by_code(mf);
start_game();
pushScreen(mode_screen_for_current); pushScreen(mode_screen_for_current);
} }