Files
psopeeps-newserv/src/LevelTable.hh
T
Martin Michelsen 826eb88e2e add __packed_ws_be__
2026-04-26 17:57:59 -07:00

152 lines
4.9 KiB
C++

#pragma once
#include <stdint.h>
#include <array>
#include <memory>
#include <phosg/Encoding.hh>
#include <string>
#include "Text.hh"
class LevelTable;
template <bool BE>
struct CharacterStatsT {
/* 00 */ U16T<BE> atp = 0;
/* 02 */ U16T<BE> mst = 0;
/* 04 */ U16T<BE> evp = 0;
/* 06 */ U16T<BE> hp = 0;
/* 08 */ U16T<BE> dfp = 0;
/* 0A */ U16T<BE> ata = 0;
/* 0C */ U16T<BE> lck = 0;
/* 0E */
operator CharacterStatsT<!BE>() const {
CharacterStatsT<!BE> ret;
ret.atp = this->atp;
ret.mst = this->mst;
ret.evp = this->evp;
ret.hp = this->hp;
ret.dfp = this->dfp;
ret.ata = this->ata;
ret.lck = this->lck;
return ret;
}
} __packed_ws_be__(CharacterStatsT, 0x0E);
using CharacterStats = CharacterStatsT<false>;
using CharacterStatsBE = CharacterStatsT<true>;
template <bool BE>
struct PlayerStatsT {
/* 00 */ CharacterStatsT<BE> char_stats;
/* 0E */ U16T<BE> esp = 0;
/* 10 */ F32T<BE> attack_range = 0.0;
/* 14 */ F32T<BE> knockback_range = 0.0;
/* 18 */ U32T<BE> level = 0; // Qedit specifies this as tech level when used for enemies
/* 1C */ U32T<BE> experience = 0;
/* 20 */ U32T<BE> meseta = 0; // Qedit specifies this as TP when used for enemies
/* 24 */
operator PlayerStatsT<!BE>() const {
PlayerStatsT<!BE> ret;
ret.char_stats = this->char_stats;
ret.esp = this->esp;
ret.attack_range = this->attack_range;
ret.knockback_range = this->knockback_range;
ret.level = this->level;
ret.experience = this->experience;
ret.meseta = this->meseta;
return ret;
}
} __packed_ws_be__(PlayerStatsT, 0x24);
using PlayerStats = PlayerStatsT<false>;
using PlayerStatsBE = PlayerStatsT<true>;
template <bool BE>
struct LevelStatsDeltaT {
/* 00 */ uint8_t atp;
/* 01 */ uint8_t mst;
/* 02 */ uint8_t evp;
/* 03 */ uint8_t hp;
/* 04 */ uint8_t dfp;
/* 05 */ uint8_t ata;
/* 06 */ uint8_t lck;
/* 07 */ uint8_t tp;
/* 08 */ U32T<BE> experience;
/* 0C */
void apply(CharacterStats& ps) const {
ps.ata += this->ata;
ps.atp += this->atp;
ps.dfp += this->dfp;
ps.evp += this->evp;
ps.hp += this->hp;
ps.mst += this->mst;
ps.lck += this->lck;
}
} __packed_ws_be__(LevelStatsDeltaT, 0x0C);
using LevelStatsDelta = LevelStatsDeltaT<false>;
using LevelStatsDeltaBE = LevelStatsDeltaT<true>;
class LevelTable {
// This is the base class for all the LevelTable implementations. The public interface here only defines functions
// that the server needs to handle requests, but some subclasses implement more functionality. See the comments and
// Offsets structures inside the subclasses' constructor implementations for more details on the file formats.
public:
virtual ~LevelTable() = default;
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const = 0;
virtual const PlayerStats& max_stats_for_class(uint8_t char_class) const = 0;
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const = 0;
void reset_to_base(PlayerStats& stats, uint8_t char_class) const;
void advance_to_level(PlayerStats& stats, uint32_t level, uint8_t char_class) const;
protected:
LevelTable() = default;
};
class LevelTableV2 : public LevelTable { // from PlayerTable.prs (PC)
public:
LevelTableV2(const std::string& data, bool compressed);
virtual ~LevelTableV2() = default;
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
const PlayerStats& level_100_stats_for_class(uint8_t char_class) const;
virtual const PlayerStats& max_stats_for_class(uint8_t char_class) const;
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
private:
std::array<CharacterStats, 9> base_stats;
std::array<PlayerStats, 9> level_100_stats;
std::array<PlayerStats, 9> max_stats;
std::array<std::array<LevelStatsDelta, 200>, 9> level_deltas;
};
class LevelTableV3BE : public LevelTable { // from PlyLevelTbl.cpt (GC)
public:
LevelTableV3BE(const std::string& data, bool encrypted);
virtual ~LevelTableV3BE() = default;
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
virtual const PlayerStats& max_stats_for_class(uint8_t char_class) const;
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
private:
std::array<std::array<LevelStatsDelta, 200>, 12> level_deltas;
};
class LevelTableV4 : public LevelTable { // from PlyLevelTbl.prs (BB)
public:
LevelTableV4(const std::string& data, bool compressed);
virtual ~LevelTableV4() = default;
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
virtual const PlayerStats& max_stats_for_class(uint8_t char_class) const;
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
private:
std::array<CharacterStats, 12> base_stats;
std::array<std::array<LevelStatsDelta, 200>, 12> level_deltas;
};