Skip to content

Commit a7b0f63

Browse files
committed
Fix bugs in save converting research/manufacture
1 parent 00ba092 commit a7b0f63

3 files changed

Lines changed: 25 additions & 33 deletions

File tree

‎bin/standard/xcom1/converter.rul‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,9 @@ converter:
437437
- STR_POWER_SUIT_UC
438438
- STR_FLYING_SUIT_UC
439439
- STR_PISTOL
440-
- STR_PISTOL_CLIP
441440
- STR_RIFLE
442-
- STR_RIFLE_CLIP
443441
- STR_HEAVY_CANNON
444-
- STR_HC_AP_AMMO
445-
- STR_HC_HE_AMMO
446-
- STR_HC_I_AMMO
447442
- STR_AUTO_CANNON
448-
- STR_AC_AP_AMMO
449-
- STR_AC_HE_AMMO
450-
- STR_AC_I_AMMO
451443
- STR_ROCKET_LAUNCHER
452444
- STR_SMALL_ROCKET
453445
- STR_LARGE_ROCKET

‎bin/standard/xcom2/converter.rul‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -446,21 +446,10 @@ converter:
446446
- STR_ION_ARMOR_UC
447447
- STR_MAGNETIC_ION_ARMOR_UC
448448
- STR_DART_PISTOL
449-
- STR_DART_POD
450449
- STR_JET_HARPOON
451-
- STR_HARPOON_POD
452450
- STR_GAS_CANNON
453-
- STR_GC_AP_AMMO
454-
- STR_GC_HE_AMMO
455-
- STR_GC_P_AMMO
456451
- STR_HYDRO_JET_CANNON
457-
- STR_HJC_AP_AMMO
458-
- STR_HJC_HE_AMMO
459-
- STR_HJC_P_AMMO
460452
- STR_TORPEDO_LAUNCHER
461-
- STR_SMALL_TORPEDO
462-
- STR_LARGE_TORPEDO
463-
- STR_PHOSPHOROUS_TORPEDO
464453
- STR_GAUSS_PISTOL
465454
- STR_GAUSS_PISTOL_CLIP
466455
- STR_GAUSS_RIFLE

‎src/Savegame/SaveConverter.cpp‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "../Mod/UfoTrajectory.h"
5858
#include "../Engine/RNG.h"
5959
#include "../Mod/RuleConverter.h"
60+
#include "../Ufopaedia/Ufopaedia.h"
6061

6162
namespace OpenXcom
6263
{
@@ -1038,7 +1039,7 @@ void SaveConverter::loadDatSoldier()
10381039
current += initial;
10391040
node["currentStats"] = current;
10401041

1041-
int armor = load<Uint8>(sdata + 0x3E);
1042+
int armor = load<Uint8>(sdata + _rules->getOffset("SOLDIER.DAT_ARMOR"));
10421043
node["armor"] = _rules->getArmor()[armor];
10431044
node["improvement"] = (int)load<Uint8>(sdata + _rules->getOffset("SOLDIER.DAT_PSI"));
10441045
node["psiTraining"] = (int)load<char>(sdata + _rules->getOffset("SOLDIER.DAT_PSILAB")) != 0;
@@ -1076,7 +1077,7 @@ void SaveConverter::loadDatResearch()
10761077
std::vector<char> buffer;
10771078
char *data = binaryBuffer("RESEARCH.DAT", buffer);
10781079

1079-
const size_t ENTRY_SIZE = 22;
1080+
const size_t ENTRY_SIZE = buffer.size() / _rules->getResearch().size();
10801081
for (size_t i = 0; i < _rules->getResearch().size(); ++i)
10811082
{
10821083
char *rdata = (data + i * ENTRY_SIZE);
@@ -1109,12 +1110,12 @@ void SaveConverter::loadDatUp()
11091110
std::vector<char> buffer;
11101111
char *data = binaryBuffer("UP.DAT", buffer);
11111112

1112-
const size_t ENTRY_SIZE = 12;
1113+
const size_t ENTRY_SIZE = buffer.size() / _rules->getUfopaedia().size();
11131114
for (size_t i = 0; i < _rules->getUfopaedia().size(); ++i)
11141115
{
11151116
char *rdata = (data + i * ENTRY_SIZE);
11161117
ArticleDefinition *article = _mod->getUfopaediaArticle(_rules->getUfopaedia()[i]);
1117-
if (article != 0)
1118+
if (article != 0 && article->section != UFOPAEDIA_NOT_AVAILABLE)
11181119
{
11191120
bool discovered = load<Uint8>(rdata + 0x08) == 2;
11201121
if (discovered)
@@ -1142,15 +1143,19 @@ void SaveConverter::loadDatProject()
11421143
std::vector<char> buffer;
11431144
char *data = binaryBuffer("PROJECT.DAT", buffer);
11441145

1145-
const size_t ENTRY_SIZE = buffer.size() / _rules->getResearch().size();
1146+
const size_t ENTRIES = _rules->getResearch().size();
1147+
// days (Uint16) | scientists (Uint8)
1148+
const size_t ENTRY_SIZE = ENTRIES * (sizeof(Uint16) + sizeof(Uint8));
11461149
for (size_t i = 0; i < _save->getBases()->size(); ++i)
11471150
{
11481151
Base *base = _save->getBases()->at(i);
1152+
char *pdata = (data + i * ENTRY_SIZE);
1153+
Uint16 *arrRemaining = (Uint16*)pdata;
1154+
Uint8 *arrScientists = (Uint8*)(&arrRemaining[ENTRIES]);
11491155
for (size_t j = 0; j < _rules->getResearch().size(); ++j)
11501156
{
1151-
char *pdata = (data + i * ENTRY_SIZE);
1152-
int remaining = load<Uint16>(pdata + j * sizeof(Uint16));
1153-
int scientists = load<Uint8>(pdata + 0xC0 + j);
1157+
int remaining = load<Uint16>((char*)&arrRemaining[j]);
1158+
int scientists = load<Uint8>((char*)&arrScientists[j]);
11541159
if (remaining != 0 && !_rules->getResearch()[j].empty())
11551160
{
11561161
RuleResearch *research = _mod->getResearch(_rules->getResearch()[j]);
@@ -1176,17 +1181,23 @@ void SaveConverter::loadDatBProd()
11761181
std::vector<char> buffer;
11771182
char *data = binaryBuffer("BPROD.DAT", buffer);
11781183

1179-
const size_t ENTRY_SIZE = buffer.size() / _rules->getManufacture().size();
1184+
const size_t ENTRIES = _rules->getManufacture().size();
1185+
// hours (int) | engineers (Uint16) | quantity (Uint16)| produced (Uint16)
1186+
const size_t ENTRY_SIZE = ENTRIES * (sizeof(int) + 3 * sizeof(Uint16));
11801187
for (size_t i = 0; i < _save->getBases()->size(); ++i)
11811188
{
11821189
Base *base = _save->getBases()->at(i);
1190+
char *pdata = (data + i * ENTRY_SIZE);
1191+
int *arrRemaining = (int*)pdata;
1192+
Uint16 *arrEngineers = (Uint16*)(&arrRemaining[ENTRIES]);
1193+
Uint16 *arrTotal = (Uint16*)(&arrEngineers[ENTRIES]);
1194+
Uint16 *arrProduced = (Uint16*)(&arrTotal[ENTRIES]);
11831195
for (size_t j = 0; j < _rules->getManufacture().size(); ++j)
11841196
{
1185-
char *pdata = (data + i * ENTRY_SIZE);
1186-
int remaining = load<int>(pdata + j * sizeof(int));
1187-
int engineers = load<Uint16>(pdata + 0x8C + j * sizeof(Uint16));
1188-
int total = load<Uint16>(pdata + 0xD2 + j * sizeof(Uint16));
1189-
int produced = load<Uint16>(pdata + 0x118 + j * sizeof(Uint16));
1197+
int remaining = load<int>((char*)&arrRemaining[j]);
1198+
int engineers = load<Uint16>((char*)&arrEngineers[j]);
1199+
int total = load<Uint16>((char*)&arrTotal[j]);
1200+
int produced = load<Uint16>((char*)&arrProduced[j]);
11901201
if (remaining != 0 && !_rules->getManufacture()[j].empty())
11911202
{
11921203
RuleManufacture *manufacture = _mod->getManufacture(_rules->getManufacture()[j]);

0 commit comments

Comments
 (0)