porting.cpp[legacy]: import a legacy party correctly,

+ do not import empty timer...
This commit is contained in:
ALONSO Laurent
2021-09-29 11:15:50 +02:00
committed by Celtic Minstrel
parent 0c277ecefd
commit 3d1faba4b2
3 changed files with 33 additions and 15 deletions

View File

@@ -25,7 +25,7 @@ extern fs::path progDir, tempDir;
extern cCustomGraphics spec_scen_g; extern cCustomGraphics spec_scen_g;
// Load saved games // Load saved games
static bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bool in_scen, bool maps_there, bool must_port); static bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bool in_scen, bool maps_there, bool mac_file);
static bool load_party_v2(fs::path file_to_load, cUniverse& univ); static bool load_party_v2(fs::path file_to_load, cUniverse& univ);
bool load_party(fs::path file_to_load, cUniverse& univ){ bool load_party(fs::path file_to_load, cUniverse& univ){
@@ -118,20 +118,20 @@ bool load_party(fs::path file_to_load, cUniverse& univ){
fclose(file_id); fclose(file_id);
switch(format){ switch(format){
case old_mac: case old_mac:
return load_party_v1(file_to_load, univ, town_restore, in_scen, maps_there, mac_is_intel); return load_party_v1(file_to_load, univ, town_restore, in_scen, maps_there, true);
case old_win: case old_win:
return load_party_v1(file_to_load, univ, town_restore, in_scen, maps_there, !mac_is_intel); return load_party_v1(file_to_load, univ, town_restore, in_scen, maps_there, false);
case new_oboe: case new_oboe:
return load_party_v2(file_to_load, univ); return load_party_v2(file_to_load, univ);
case unknown: case unknown:
showError("This is not a Blades of Exile save file."); showError("This is not a Blades of Exile save file.");
return false; return false;
} }
return true; return true;
} }
bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restore, bool in_scen, bool maps_there, bool must_port){ extern bool cur_scen_is_mac;
bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restore, bool in_scen, bool maps_there, bool mac_file){
std::ifstream fin(file_to_load.string().c_str(), std::ios_base::binary); std::ifstream fin(file_to_load.string().c_str(), std::ios_base::binary);
fin.seekg(3*sizeof(short),std::ios_base::beg); // skip the header, which is 6 bytes in the old format fin.seekg(3*sizeof(short),std::ios_base::beg); // skip the header, which is 6 bytes in the old format
@@ -149,11 +149,14 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor
char *pc_ptr; char *pc_ptr;
long len,store_len,count; long len,store_len,count;
// ------- set scenario is mac to party_is_mac to make porting.cpp works
cur_scen_is_mac=mac_file;
// LOAD PARTY // LOAD PARTY
len = (long) sizeof(legacy::party_record_type); // should be 46398 len = (long) sizeof(legacy::party_record_type); // should be 46398
store_len = len; store_len = len;
fin.read((char*)&store_party, len); fin.read((char*)&store_party, len);
if(must_port) port_party(&store_party); port_party(&store_party);
party_ptr = (char*) &store_party; party_ptr = (char*) &store_party;
for(count = 0; count < store_len; count++) for(count = 0; count < store_len; count++)
party_ptr[count] ^= 0x5C; party_ptr[count] ^= 0x5C;
@@ -167,7 +170,7 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
len = store_len; len = store_len;
fin.read((char*)&store_pc[i], len); fin.read((char*)&store_pc[i], len);
if(must_port) port_pc(&store_pc[i]); port_pc(&store_pc[i]);
pc_ptr = (char*) &store_pc[i]; pc_ptr = (char*) &store_pc[i];
for(count = 0; count < store_len; count++) for(count = 0; count < store_len; count++)
pc_ptr[count] ^= 0x6B; pc_ptr[count] ^= 0x6B;
@@ -183,22 +186,22 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor
if(town_restore) { if(town_restore) {
len = (long) sizeof(legacy::current_town_type); len = (long) sizeof(legacy::current_town_type);
fin.read((char*)&store_c_town, len); fin.read((char*)&store_c_town, len);
if(must_port) port_c_town(&store_c_town); port_c_town(&store_c_town);
len = (long) sizeof(legacy::big_tr_type); len = (long) sizeof(legacy::big_tr_type);
fin.read((char*)&t_d, len); fin.read((char*)&t_d, len);
if(must_port) port_t_d(&t_d); port_t_d(&t_d);
len = (long) sizeof(legacy::town_item_list); len = (long) sizeof(legacy::town_item_list);
fin.read((char*)&t_i, len); fin.read((char*)&t_i, len);
if(must_port) port_t_i(&t_i); port_t_i(&t_i);
} }
// LOAD STORED ITEMS // LOAD STORED ITEMS
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
len = (long) sizeof(legacy::stored_items_list_type); len = (long) sizeof(legacy::stored_items_list_type);
fin.read((char*)&stored_items[i], len); fin.read((char*)&stored_items[i], len);
if(must_port) port_stored_items_list(&stored_items[i]); port_stored_items_list(&stored_items[i]);
} }
// LOAD SAVED MAPS // LOAD SAVED MAPS
@@ -219,7 +222,8 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor
} // end if_scen } // end if_scen
fin.close(); fin.close();
// ------- the data of the party are all port, so load_scenario can reset cur_scen_is_mac
cUniverse univ; cUniverse univ;
if(in_scen){ if(in_scen){
@@ -253,8 +257,9 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor
univ.party.import_legacy(stored_items[i],i); univ.party.import_legacy(stored_items[i],i);
univ.import_legacy(town_maps); univ.import_legacy(town_maps);
univ.import_legacy(o_maps); univ.import_legacy(o_maps);
univ.town.import_reset_fields_legacy(); if(town_restore) {
if(town_restore) // Check items in crates/barrels univ.town.import_reset_fields_legacy();
// Check items in crates/barrels
for(int i = 0; i < univ.town->max_dim; i++) { for(int i = 0; i < univ.town->max_dim; i++) {
for(int j = 0; j < univ.town->max_dim; j++) { for(int j = 0; j < univ.town->max_dim; j++) {
if(univ.town.is_barrel(i,j) || univ.town.is_crate(i,j)) { if(univ.town.is_barrel(i,j) || univ.town.is_crate(i,j)) {
@@ -265,6 +270,7 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor
} }
} }
} }
}
else { else {
univ.party.town_num = 200; univ.party.town_num = 200;
univ.town.difficulty = univ.scenario.difficulty; univ.town.difficulty = univ.scenario.difficulty;

View File

@@ -245,6 +245,9 @@ void port_out(legacy::outdoor_record_type *out) {
} }
void port_party(legacy::party_record_type* old){ void port_party(legacy::party_record_type* old){
if(cur_scen_is_mac != mac_is_intel)
return;
flip_long(&old->age); flip_long(&old->age);
flip_short(&old->gold); flip_short(&old->gold);
flip_short(&old->food); flip_short(&old->food);
@@ -327,6 +330,9 @@ void port_party(legacy::party_record_type* old){
} }
void port_pc(legacy::pc_record_type* old){ void port_pc(legacy::pc_record_type* old){
if(cur_scen_is_mac != mac_is_intel)
return;
flip_short(&old->main_status); flip_short(&old->main_status);
for(short i = 0; i < 30; i++) for(short i = 0; i < 30; i++)
flip_short(&old->skills[i]); flip_short(&old->skills[i]);
@@ -352,9 +358,12 @@ void port_pc(legacy::pc_record_type* old){
} }
void port_c_town(legacy::current_town_type* old){ void port_c_town(legacy::current_town_type* old){
port_town(&old->town);
if(cur_scen_is_mac != mac_is_intel)
return;
flip_short(&old->town_num); flip_short(&old->town_num);
flip_short(&old->difficulty); flip_short(&old->difficulty);
port_town(&old->town);
flip_short(&old->monst.which_town); flip_short(&old->monst.which_town);
flip_short(&old->monst.hostile); flip_short(&old->monst.hostile);
for(short j = 0; j < 60; j++){ for(short j = 0; j < 60; j++){

View File

@@ -230,6 +230,9 @@ void cParty::import_legacy(legacy::party_record_type& old, cUniverse& univ){
for(short i = 0; i < 30; i++){ for(short i = 0; i < 30; i++){
boats[i].import_legacy(old.boats[i]); boats[i].import_legacy(old.boats[i]);
horses[i].import_legacy(old.horses[i]); horses[i].import_legacy(old.horses[i]);
// boe: timer with time<=0 are empty timer
if (old.party_event_timers[i] <= 0)
continue;
cTimer t; cTimer t;
t.time = old.party_event_timers[i]; t.time = old.party_event_timers[i];
t.node_type = old.global_or_town[i] ? eSpecCtxType::TOWN : eSpecCtxType::SCEN; t.node_type = old.global_or_town[i] ? eSpecCtxType::TOWN : eSpecCtxType::SCEN;