Skip to content

Commit

Permalink
refine BattleParamEntry format
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzziqersoftware committed Oct 28, 2023
1 parent ed05a5f commit 75c11ae
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 129 deletions.
36 changes: 11 additions & 25 deletions src/BattleParamsIndex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

using namespace std;

string BattleParamsIndex::Entry::str() const {
string a1str = format_data_string(this->unknown_a1.data(), this->unknown_a1.bytes());
string BattleParamsIndex::PhysicalData::str() const {
return string_printf(
"BattleParamsEntry[ATP=%hu PSV=%hu EVP=%hu HP=%hu DFP=%hu ATA=%hu LCK=%hu ESP=%hu a1=%s EXP=%" PRIu32 " diff=%" PRIu32 "]",
"PhysicalData[ATP=%hu PSV=%hu EVP=%hu HP=%hu DFP=%hu ATA=%hu LCK=%hu ESP=%hu a1=[%g, %g] a2=%" PRIu32 " EXP=%" PRIu32 " diff=%" PRIu32 "]",
this->atp.load(),
this->psv.load(),
this->evp.load(),
Expand All @@ -21,16 +20,17 @@ string BattleParamsIndex::Entry::str() const {
this->ata.load(),
this->lck.load(),
this->esp.load(),
a1str.c_str(),
this->unknown_a1[0].load(),
this->unknown_a1[1].load(),
this->unknown_a2.load(),
this->experience.load(),
this->difficulty.load());
}

void BattleParamsIndex::Table::print(FILE* stream) const {
auto print_entry = +[](FILE* stream, const Entry& e) {
string a1str = format_data_string(e.unknown_a1.data(), e.unknown_a1.bytes());
auto print_entry = +[](FILE* stream, const PhysicalData& e) {
fprintf(stream,
"%5hu %5hu %5hu %5hu %5hu %5hu %5hu %5hu %s %5" PRIu32 " %5" PRIu32,
"%5hu %5hu %5hu %5hu %5hu %5hu %5hu %5hu %5" PRIu32 " %5" PRIu32,
e.atp.load(),
e.psv.load(),
e.evp.load(),
Expand All @@ -39,17 +39,16 @@ void BattleParamsIndex::Table::print(FILE* stream) const {
e.ata.load(),
e.lck.load(),
e.esp.load(),
a1str.c_str(),
e.experience.load(),
e.difficulty.load());
};

for (size_t diff = 0; diff < 4; diff++) {
fprintf(stream, "%c ZZ ATP PSV EVP HP DFP ATA LCK ESP A1 EXP DIFF\n",
fprintf(stream, "%c ZZ ATP PSV EVP HP DFP ATA LCK ESP EXP DIFF\n",
abbreviation_for_difficulty(diff));
for (size_t z = 0; z < 0x60; z++) {
fprintf(stream, " %02zX ", z);
print_entry(stream, this->difficulty[diff][z]);
print_entry(stream, this->physical_data[diff][z]);
fputc('\n', stream);
}
}
Expand Down Expand Up @@ -82,20 +81,7 @@ BattleParamsIndex::BattleParamsIndex(
}
}

const BattleParamsIndex::Entry& BattleParamsIndex::get(
bool solo, Episode episode, uint8_t difficulty, EnemyType type) const {
return this->get(solo, episode, difficulty, battle_param_index_for_enemy_type(episode, type));
}

const BattleParamsIndex::Entry& BattleParamsIndex::get(
bool solo, Episode episode, uint8_t difficulty, size_t index) const {
if (difficulty > 4) {
throw invalid_argument("incorrect difficulty");
}
if (index >= 0x60) {
throw invalid_argument("incorrect monster type");
}

const BattleParamsIndex::Table& BattleParamsIndex::get_table(bool solo, Episode episode) const {
uint8_t ep_index;
switch (episode) {
case Episode::EP1:
Expand All @@ -111,5 +97,5 @@ const BattleParamsIndex::Entry& BattleParamsIndex::get(
throw invalid_argument("invalid episode");
}

return this->files[!!solo][ep_index].table->difficulty[difficulty][index];
return *this->files[!!solo][ep_index].table;
}
96 changes: 76 additions & 20 deletions src/BattleParamsIndex.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,83 @@

class BattleParamsIndex {
public:
struct Entry {
le_uint16_t atp;
le_uint16_t psv; // Perseverance (intelligence?)
le_uint16_t evp;
le_uint16_t hp;
le_uint16_t dfp;
le_uint16_t ata;
le_uint16_t lck;
le_uint16_t esp; // Unknown
parray<uint8_t, 0x0C> unknown_a1;
le_uint32_t experience;
le_uint32_t difficulty;
// These files are little-endian, even on PSO GC.

struct PhysicalData {
/* 00 */ le_uint16_t atp;
/* 02 */ le_uint16_t psv; // Perseverance (intelligence?)
/* 04 */ le_uint16_t evp;
/* 06 */ le_uint16_t hp;
/* 08 */ le_uint16_t dfp;
/* 0A */ le_uint16_t ata;
/* 0C */ le_uint16_t lck;
/* 0E */ le_uint16_t esp; // Unknown
/* 10 */ parray<le_float, 2> unknown_a1;
/* 18 */ le_uint32_t unknown_a2;
/* 1C */ le_uint32_t experience;
/* 20 */ le_uint32_t difficulty;
/* 24 */

std::string str() const;
} __attribute__((packed));

struct AttackData {
/* 00 */ le_int16_t unknown_a1;
/* 02 */ le_int16_t unknown_a2;
/* 04 */ le_uint16_t unknown_a3;
/* 06 */ le_uint16_t unknown_a4;
/* 08 */ le_float distance_x;
/* 0C */ le_float angle_x;
/* 10 */ le_float distance_y;
/* 14 */ le_uint16_t unknown_a8;
/* 16 */ le_uint16_t unknown_a9;
/* 18 */ le_uint16_t unknown_a10;
/* 1A */ le_uint16_t unknown_a11;
/* 1C */ le_uint32_t unknown_a12;
/* 20 */ le_uint32_t unknown_a13;
/* 24 */ le_uint32_t unknown_a14;
/* 28 */ le_uint32_t unknown_a15;
/* 2C */ le_uint32_t unknown_a16;
/* 30 */
} __attribute__((packed));

struct ResistData {
/* 00 */ le_int16_t evp_bonus;
/* 02 */ le_uint16_t efr;
/* 04 */ le_uint16_t eic;
/* 06 */ le_uint16_t eth;
/* 08 */ le_uint16_t elt;
/* 0A */ le_uint16_t edk;
/* 0C */ le_uint32_t unknown_a6;
/* 10 */ le_uint32_t unknown_a7;
/* 14 */ le_uint32_t unknown_a8;
/* 18 */ le_uint32_t unknown_a9;
/* 1C */ le_int32_t dfp_bonus;
/* 20 */
} __attribute__((packed));

struct MovementData {
/* 00 */ le_float idle_move_speed;
/* 04 */ le_float idle_animation_speed;
/* 08 */ le_float move_speed;
/* 0C */ le_float animation_speed;
/* 10 */ le_float unknown_a1;
/* 14 */ le_float unknown_a2;
/* 18 */ le_uint32_t unknown_a3;
/* 1C */ le_uint32_t unknown_a4;
/* 20 */ le_uint32_t unknown_a5;
/* 24 */ le_uint32_t unknown_a6;
/* 28 */ le_uint32_t unknown_a7;
/* 2C */ le_uint32_t unknown_a8;
/* 30 */
} __attribute__((packed));

struct Table {
parray<parray<Entry, 0x60>, 4> difficulty;
/* 0000 */ parray<parray<PhysicalData, 0x60>, 4> physical_data;
/* 3600 */ parray<parray<AttackData, 0x60>, 4> attack_data;
/* 7E00 */ parray<parray<ResistData, 0x60>, 4> resist_data;
/* AE00 */ parray<parray<MovementData, 0x60>, 4> movement_data;
/* F600 */

void print(FILE* stream) const;
} __attribute__((packed));
Expand All @@ -44,17 +103,14 @@ public:
std::shared_ptr<const std::string> data_off_ep2, // BattleParamEntry_lab.dat
std::shared_ptr<const std::string> data_off_ep4); // BattleParamEntry_ep4.dat

const Entry& get(
bool solo, Episode episode, uint8_t difficulty, EnemyType type) const;
const Entry& get(
bool solo, Episode episode, uint8_t difficulty, size_t entry_index) const;
const Table& get_table(bool solo, Episode episode) const;

private:
struct LoadedFile {
struct File {
std::shared_ptr<const std::string> data;
const Table* table;
};

// online/offline, episode
LoadedFile files[2][3];
// Indexed as [online/offline][episode]
std::array<std::array<File, 3>, 2> files;
};
Loading

0 comments on commit 75c11ae

Please sign in to comment.