convert shop random sets to JSON

This commit is contained in:
Martin Michelsen
2026-06-06 07:43:06 -07:00
parent efe7401d7b
commit 708d2a9fb0
25 changed files with 6020 additions and 435 deletions
-111
View File
@@ -284,114 +284,3 @@ class JSONCommonItemSet : public CommonItemSet {
public:
explicit JSONCommonItemSet(const phosg::JSON& json);
};
class RELFileSet {
public:
template <typename ValueT, typename WeightT = ValueT>
struct WeightTableEntry {
ValueT value;
WeightT weight;
phosg::JSON json() const {
return phosg::JSON::dict({{"Weight", this->weight}, {"Value", this->value}});
}
static WeightTableEntry<ValueT, WeightT> from_json(const phosg::JSON& json) {
return WeightTableEntry<ValueT, WeightT>{json.get_int("Weight"), json.get_int("Value")};
}
} __attribute__((packed));
using WeightTableEntry8 = WeightTableEntry<uint8_t>;
using WeightTableEntry32 = WeightTableEntry<be_uint32_t>;
check_struct_size(WeightTableEntry8, 2);
check_struct_size(WeightTableEntry32, 8);
protected:
std::shared_ptr<const std::string> data;
phosg::StringReader r;
struct TableSpec {
be_uint32_t offset;
uint8_t entries_per_table;
parray<uint8_t, 3> unused;
} __packed_ws__(TableSpec, 8);
RELFileSet(std::shared_ptr<const std::string> data);
template <typename T>
std::pair<const T*, size_t> get_table(const TableSpec& spec, size_t index) const {
const T* entries = &r.pget<T>(
spec.offset + index * spec.entries_per_table * sizeof(T), spec.entries_per_table * sizeof(T));
return std::make_pair(entries, spec.entries_per_table);
}
};
class ArmorRandomSet : public RELFileSet {
public:
// This class parses and accesses data from ArmorRandom.rel
ArmorRandomSet(std::shared_ptr<const std::string> data);
std::pair<const WeightTableEntry8*, size_t> get_armor_table(size_t index) const;
std::pair<const WeightTableEntry8*, size_t> get_shield_table(size_t index) const;
std::pair<const WeightTableEntry8*, size_t> get_unit_table(size_t index) const;
private:
const parray<TableSpec, 3>* tables;
};
class ToolRandomSet : public RELFileSet {
public:
// This class parses and accesses data from ToolRandom.rel
ToolRandomSet(std::shared_ptr<const std::string> data);
struct TechDiskLevelEntry {
enum class Mode : uint8_t {
LEVEL_1 = 0,
PLAYER_LEVEL_DIVISOR = 1,
RANDOM_IN_RANGE = 2,
};
Mode mode;
uint8_t player_level_divisor_or_min_level;
uint8_t max_level;
} __packed_ws__(TechDiskLevelEntry, 3);
std::pair<const uint8_t*, size_t> get_common_recovery_table(size_t index) const;
std::pair<const WeightTableEntry8*, size_t> get_rare_recovery_table(size_t index) const;
std::pair<const WeightTableEntry8*, size_t> get_tech_disk_table(size_t index) const;
std::pair<const TechDiskLevelEntry*, size_t> get_tech_disk_level_table(size_t index) const;
private:
const TableSpec* common_recovery_table_spec;
const TableSpec* rare_recovery_table_spec;
const TableSpec* tech_disk_table_spec;
const TableSpec* tech_disk_level_table_spec;
};
class WeaponRandomSet : public RELFileSet {
public:
// This class parses and accesses data from WeaponRandom*.rel
WeaponRandomSet(std::shared_ptr<const std::string> data);
struct RangeTableEntry {
be_uint32_t min;
be_uint32_t max;
} __packed_ws__(RangeTableEntry, 8);
std::pair<const WeightTableEntry8*, size_t> get_weapon_type_table(size_t index) const;
const parray<WeightTableEntry32, 6>* get_bonus_type_table(size_t which, size_t index) const;
const RangeTableEntry* get_bonus_range(size_t which, size_t index) const;
const parray<WeightTableEntry32, 3>* get_special_mode_table(size_t index) const;
const RangeTableEntry* get_standard_grind_range(size_t index) const;
const RangeTableEntry* get_favored_grind_range(size_t index) const;
private:
struct Offsets {
be_uint32_t weapon_type_table; // [{c, o -> (table)}](10)
be_uint32_t bonus_type_table1; // [[{u32 value, u32 weight}](6)](9)
be_uint32_t bonus_type_table2; // [[{u32 value, u32 weight}](6)](9)
be_uint32_t bonus_range_table1; // [{u32 min_index, u32 max_index}](9)
be_uint32_t bonus_range_table2; // [{u32 min_index, u32 max_index}](9)
be_uint32_t special_mode_table; // [[{u32 value, u32 weight}](3)](8)
be_uint32_t standard_grind_range_table; // [{u32 min, u32 max}](6)
be_uint32_t favored_grind_range_table; // [{u32 min, u32 max}](6)
} __packed_ws__(Offsets, 0x20);
const Offsets* offsets;
};