1#include "dcon_generated.hpp"
7#define ZSTD_STATIC_LINKING_ONLY
8#define XXH_NAMESPACE ZSTD_
17 memcpy(&length, ptr_in,
sizeof(
uint32_t));
19 return ptr_in +
sizeof(
uint32_t) + length;
24 memcpy(&length, ptr_in,
sizeof(
uint32_t));
26 return ptr_in +
sizeof(
uint32_t) + length;
31 memcpy(ptr_in, &length,
sizeof(
uint32_t));
37 memcpy(ptr_in, &length,
sizeof(
uint32_t));
52 if(
size_t(lim - ptr_in) <
sizeof(
uint32_t))
55 memcpy(&length, ptr_in,
sizeof(
uint32_t));
65 memcpy(&length, ptr_in,
sizeof(
uint32_t));
73 memcpy(ptr_in, &length,
sizeof(
uint32_t));
75 memcpy(ptr_in, path_in.c_str(), length *
sizeof(
native_char));
90 auto file_end = ptr_in + file_size;
107 uint32_t decompressed_length = uncompressed_size;
110 uncompressed_size, 0));
112 memcpy(ptr_out, §ion_length,
sizeof(
uint32_t));
115 return ptr_out +
sizeof(
uint32_t) * 2 + section_length;
122 memcpy(§ion_length, ptr_in,
sizeof(
uint32_t));
131 function(temp_buffer, decompressed_length);
133 delete[] temp_buffer;
134 return ptr_in +
sizeof(
uint32_t) * 2 + section_length;
314 dcon::load_record loaded;
315 std::byte
const* start =
reinterpret_cast<std::byte const*
>(ptr_in);
316 state.
world.deserialize(start,
reinterpret_cast<std::byte const*
>(section_end), loaded);
495 dcon::load_record result =
state.
world.make_serialize_record_store_scenario();
496 std::byte* start =
reinterpret_cast<std::byte*
>(ptr_in);
499 return reinterpret_cast<uint8_t*
>(start);
673 dcon::load_record loaded =
state.
world.make_serialize_record_store_scenario();
675 auto szb =
state.
world.serialize_size(loaded);
721 dcon::load_record loaded;
724 std::byte
const* start =
reinterpret_cast<std::byte const*
>(ptr_in);
725 state.
world.deserialize(start,
reinterpret_cast<std::byte const*
>(section_end), loaded);
727 dcon::load_record loadmask =
state.
world.make_serialize_record_store_save();
728 std::byte
const* start =
reinterpret_cast<std::byte const*
>(ptr_in);
729 state.
world.deserialize(start,
reinterpret_cast<std::byte const*
>(section_end), loaded, loadmask);
773 dcon::load_record loaded =
state.
world.make_serialize_record_store_full_save();
774 std::byte* start =
reinterpret_cast<std::byte*
>(ptr_in);
777 return reinterpret_cast<uint8_t*
>(start);
821 dcon::load_record loaded =
state.
world.make_serialize_record_store_full_save();
844 uint8_t* buffer_position = temp_buffer;
849 uint8_t* temp_scenario_buffer =
new uint8_t[scenario_space.total_size];
851 auto last_written_count = last_written - temp_scenario_buffer;
852 assert(
size_t(last_written_count) == scenario_space.total_size);
855 blake2b(checksum,
sizeof(*checksum), temp_scenario_buffer + scenario_space.checksum_offset, scenario_space.total_size - scenario_space.checksum_offset,
nullptr, 0);
859 delete[] temp_scenario_buffer;
863 auto last_save_written_count = last_save_written - temp_save_buffer;
864 assert(
size_t(last_save_written_count) == save_space);
866 delete[] temp_save_buffer;
868 auto total_size_used = buffer_position - temp_buffer;
873 delete[] temp_buffer;
877 auto save_file = open_file(dir, name);
883 uint8_t const* buffer_pos =
reinterpret_cast<uint8_t const*
>(contents.data);
884 auto file_end = buffer_pos + contents.file_size;
913 auto save_file = open_file(dir, name);
919 uint8_t const* buffer_pos =
reinterpret_cast<uint8_t const*
>(contents.data);
920 auto file_end = buffer_pos + contents.file_size;
956 auto save_file = open_file(dir, name);
962 uint8_t const* buffer_pos =
reinterpret_cast<uint8_t const*
>(contents.data);
963 auto file_end = buffer_pos + contents.file_size;
999 for(int32_t i = 64 / 4; i --> 0; ) {
1000 result += char(
'a' + (0x0F & (value >> (i * 4))));
1009 auto time_stamp = std::time(
nullptr);
1016 memcpy(header.
save_name, name.c_str(), std::min(name.length(),
size_t(31)));
1017 if(name.length() < 31) {
1029 uint8_t* buffer_position = temp_buffer;
1037 delete[] temp_save_buffer;
1039 auto total_size_used = buffer_position - temp_buffer;
1048 auto base_str =
"bookmark_" +
make_time_string(
uint64_t(std::time(
nullptr))) +
"-" + std::to_string(ymd_date.year) +
"-" + std::to_string(ymd_date.month) +
"-" + std::to_string(ymd_date.day) +
".bin";
1052 auto base_str =
make_time_string(
uint64_t(std::time(
nullptr))) +
"-" +
nations::int_to_tag(
state.
world.national_identity_get_identifying_int(header.
tag)) +
"-" + std::to_string(ymd_date.year) +
"-" + std::to_string(ymd_date.month) +
"-" + std::to_string(ymd_date.day) +
".bin";
1055 delete[] temp_buffer;
1064 data_dumps_directory,
1065 NATIVE(
"economy_dump.txt"),
1070 data_dumps_directory,
1071 NATIVE(
"prices_dump.txt"),
1076 data_dumps_directory,
1077 NATIVE(
"demand_dump.txt"),
1082 data_dumps_directory,
1083 NATIVE(
"supply_dump.txt"),
1088 data_dumps_directory,
1089 NATIVE(
"demand_by_category_dump.txt"),
1097 auto save_file = open_file(dir, name);
1103 uint8_t const* buffer_pos =
reinterpret_cast<uint8_t const*
>(contents.data);
1104 auto file_end = buffer_pos + contents.file_size;
int blake2b(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
std::vector< textured_line_with_width_vertex > river_vertices
std::vector< GLsizei > river_counts
std::vector< GLsizei > coastal_counts
std::vector< GLint > coastal_starts
std::vector< border > borders
std::vector< GLint > river_starts
std::vector< uint16_t > province_id_map
std::vector< uint8_t > diagonal_borders
std::vector< textured_line_vertex_b > border_vertices
std::vector< textured_line_vertex_b > coastal_vertices
std::vector< uint8_t > terrain_id_map
std::vector< uint32_t > province_area
year_month_day to_ymd(absolute_time_point base) const noexcept
ankerl::unordered_dense::map< uint16_t, dcon::text_key > font_names
tagged_vector< element_data, dcon::gui_def_id > gui
std::vector< window_extension > extensions
tagged_vector< gfx_object, dcon::gfx_object_id > gfx
tagged_vector< dcon::text_key, dcon::texture_id > textures
#define assert(condition)
std::string int_to_tag(uint32_t v)
native_string utf8_to_native(std::string_view data_in)
native_string extract_state(file_system const &fs)
void restore_state(file_system &fs, native_string_view data)
void write_file(directory const &dir, native_string_view file_name, char const *file_data, uint32_t file_size)
directory get_or_create_save_game_directory()
directory get_or_create_data_dumps_directory()
file_contents view_contents(file const &f)
directory get_or_create_scenario_directory()
uint8_t * write_mod_path(uint8_t *ptr_in, native_string const &path_in)
uint8_t * write_scenario_section(uint8_t *ptr_in, sys::state &state)
bool try_read_scenario_as_save_file(sys::state &state, native_string_view name)
size_t sizeof_save_section(sys::state &state)
uint8_t const * read_save_header(uint8_t const *ptr_in, save_header &header_out)
mod_identifier extract_mod_information(uint8_t const *ptr_in, uint64_t file_size)
constexpr uint32_t scenario_file_version
size_t sizeof_mod_path(native_string const &path_in)
uint8_t const * memcpy_deserialize(uint8_t const *ptr_in, T &obj)
uint8_t * write_scenario_header(uint8_t *ptr_in, scenario_header const &header_in)
void write_scenario_file(sys::state &state, native_string_view name, uint32_t count)
uint8_t const * with_decompressed_section(uint8_t const *ptr_in, T const &function)
uint8_t const * deserialize(uint8_t const *ptr_in, std::vector< T > &vec)
uint8_t * write_save_section(uint8_t *ptr_in, sys::state &state)
scenario_size sizeof_scenario_section(sys::state &state)
uint8_t const * read_scenario_header(uint8_t const *ptr_in, scenario_header &header_out)
void read_mod_path(uint8_t const *ptr_in, uint8_t const *lim, native_string &path_out)
uint8_t * write_save_header(uint8_t *ptr_in, save_header const &header_in)
std::string make_time_string(uint64_t value)
uint8_t * memcpy_serialize(uint8_t *ptr_in, T const &obj)
bool try_read_scenario_file(sys::state &state, native_string_view name)
size_t serialize_size(std::vector< T > const &vec)
constexpr int32_t max_autosaves
uint8_t * serialize(uint8_t *ptr_in, std::vector< T > const &vec)
uint8_t const * read_save_section(uint8_t const *ptr_in, uint8_t const *section_end, sys::state &state)
size_t sizeof_save_header(save_header const &header_in)
uint8_t * write_compressed_section(uint8_t *ptr_out, uint8_t const *ptr_in, uint32_t uncompressed_size)
bool try_read_save_file(sys::state &state, native_string_view name)
void write_save_file(sys::state &state, save_type type, std::string const &name)
uint8_t const * load_mod_path(uint8_t const *ptr_in, sys::state &state)
size_t sizeof_scenario_header(scenario_header const &header_in)
constexpr uint32_t save_file_version
uint8_t const * read_scenario_section(uint8_t const *ptr_in, uint8_t const *section_end, sys::state &state)
bool try_read_scenario_and_save_file(sys::state &state, native_string_view name)
std::string_view native_string_view
std::string native_string
std::vector< dcon::issue_id > political_issues
dcon::value_modifier_key conversion_chance
std::vector< dcon::reform_id > military_issues
dcon::pop_type_id farmers
dcon::value_modifier_key migration_chance
dcon::value_modifier_key colonialmigration_chance
tagged_vector< crime_info, dcon::crime_id > crimes
dcon::value_modifier_key demotion_chance
std::vector< dcon::reform_id > economic_issues
dcon::pop_type_id secondary_factory_worker
int32_t officer_leadership_points
dcon::pop_type_id bureaucrat
dcon::pop_type_id artisans
std::vector< folder_info > tech_folders
std::vector< dcon::issue_id > party_issues
std::vector< dcon::issue_id > social_issues
float bureaucrat_tax_efficiency
dcon::pop_type_id soldiers
dcon::pop_type_id primary_factory_worker
dcon::value_modifier_key assimilation_chance
dcon::pop_type_id officers
dcon::pop_type_id aristocrat
dcon::issue_option_id jingoism
dcon::pop_type_id capitalists
dcon::ideology_id conservative
dcon::value_modifier_key promotion_chance
dcon::pop_type_id laborers
dcon::value_modifier_key emigration_chance
dcon::cb_type_id standard_civil_war
dcon::cb_type_id uninstall_communist_gov
dcon::unit_type_id base_army_unit
dcon::unit_type_id irregular
tagged_vector< unit_definition, dcon::unit_type_id > unit_base_definitions
dcon::unit_type_id infantry
dcon::cb_type_id standard_status_quo
dcon::cb_type_id crisis_liberate
dcon::cb_type_id crisis_colony
dcon::cb_type_id liberate
dcon::cb_type_id standard_great_war
dcon::unit_type_id base_naval_unit
dcon::unit_type_id artillery
dcon::leader_trait_id first_background_trait
std::vector< fixed_event > on_surrender
std::vector< fixed_event > on_colony_to_state
std::vector< fixed_event > on_lost_great_nation
dcon::modifier_id overseas
std::vector< fixed_event > on_yearly_pulse
dcon::modifier_id total_occupation
dcon::modifier_id total_blockaded
std::vector< fixed_event > on_civilize
std::vector< fixed_event > on_debtor_default_small
std::vector< fixed_event > on_state_conquest
std::vector< fixed_event > on_election_started
dcon::modifier_id land_province
dcon::modifier_id easy_ai
tagged_vector< dcon::text_key, dcon::national_variable_id > variable_names
dcon::modifier_id very_hard_ai
dcon::modifier_id base_values
dcon::modifier_id generalised_debt_default
dcon::modifier_id coastal_sea
dcon::national_identity_id rebel_id
dcon::modifier_id very_hard_player
dcon::modifier_id hard_ai
std::vector< fixed_event > on_election_finished
dcon::modifier_id nationalism
std::vector< fixed_province_event > on_battle_won
dcon::modifier_id debt_default_to
dcon::modifier_id coastal
tagged_vector< dcon::text_key, dcon::global_flag_id > global_flag_variable_names
std::vector< fixed_event > on_colony_to_state_free_slaves
dcon::modifier_id hard_player
dcon::modifier_id very_easy_ai
dcon::modifier_id unciv_nation
std::vector< fixed_event > on_quarterly_pulse
dcon::modifier_id non_coastal
dcon::modifier_id in_bankrupcy
dcon::modifier_id disarming
dcon::modifier_id easy_player
int32_t num_allocated_global_flags
dcon::modifier_id bad_debter
tagged_vector< dcon::text_key, dcon::national_flag_id > flag_variable_names
dcon::modifier_id civ_nation
dcon::national_focus_id flashpoint_focus
dcon::modifier_id plurality
dcon::modifier_id no_adjacent_controlled
std::vector< fixed_event > on_debtor_default
std::vector< fixed_event > on_crisis_declare_interest
dcon::modifier_id sea_zone
dcon::modifier_id blockaded
int32_t num_allocated_national_variables
int32_t num_allocated_national_flags
std::vector< triggered_modifier > triggered_modifiers
std::vector< fixed_event > on_my_factories_nationalized
dcon::modifier_id great_power
std::vector< fixed_election_event > on_election_tick
dcon::modifier_id war_exhaustion
dcon::modifier_id infrastructure
dcon::modifier_id average_literacy
dcon::modifier_id second_power
dcon::modifier_id occupied
dcon::modifier_id very_easy_player
dcon::modifier_id has_siege
std::vector< fixed_event > on_new_great_nation
std::vector< fixed_event > on_debtor_default_second
std::vector< fixed_province_event > on_battle_lost
std::vector< dcon::bitfield_type > global_flag_variables
dcon::modifier_id south_america
ankerl::unordered_dense::map< dcon::modifier_id, dcon::gfx_object_id, sys::modifier_hash > terrain_to_gfx_map
std::vector< dcon::province_adjacency_id > canals
dcon::province_id first_sea_province
dcon::modifier_id north_america
dcon::modifier_id oceania
std::vector< dcon::province_id > canal_provinces
std::string national_economy_dump_buffer
std::string prices_dump_buffer
std::string supply_dump_buffer
std::string demand_by_category_dump_buffer
std::string demand_dump_buffer
bool is_equal(const checksum_key &a) noexcept
uint64_t scenario_time_stamp
text::font_manager font_collection
dcon::national_identity_id crisis_liberation_tag
culture::global_cultural_state culture_definitions
network_mode_type network_mode
std::vector< char > key_data
std::vector< event::pending_human_p_event > future_p_event
std::atomic< bool > save_list_updated
std::vector< event::pending_human_p_event > pending_p_event
std::vector< value_modifier_segment > value_modifier_segments
ankerl::unordered_dense::set< dcon::text_key, text::vector_backed_ci_hash, text::vector_backed_ci_eq > untrans_key_to_text_sequence
dcon::data_container world
std::vector< crisis_member_def > crisis_participants
std::vector< event::pending_human_f_p_event > pending_f_p_event
std::vector< uint16_t > effect_data
dcon::state_definition_id crisis_colony
dcon::nation_id local_player_nation
std::vector< char > unit_names
std::vector< int32_t > trigger_data_indices
uint32_t crisis_last_checked_gp
tagged_vector< value_modifier_description, dcon::value_modifier_key > value_modifiers
economy::global_economy_state economy_definitions
simple_fs::file_system common_fs
absolute_time_point start_date
absolute_time_point end_date
military::global_military_state military_definitions
sys::checksum_key scenario_checksum
std::vector< int32_t > unit_names_indices
native_string loaded_save_file
player_data player_data_cache
dcon::nation_id primary_crisis_defender
std::array< diplomatic_message::message, 128 > pending_messages
std::vector< event::pending_human_n_event > future_n_event
uint32_t scenario_counter
std::vector< great_nation > great_nations
crisis_type current_crisis
native_string loaded_scenario_file
province::global_provincial_state province_definitions
sys::date last_crisis_end_date
std::vector< event::pending_human_f_n_event > pending_f_n_event
dcon::state_instance_id crisis_state
dcon::nation_id primary_crisis_attacker
std::vector< int32_t > effect_data_indices
std::vector< event::pending_human_n_event > pending_n_event
std::vector< uint16_t > trigger_data
crisis_mode current_crisis_mode
nations::global_national_state national_definitions
size_t ZSTD_compressBound(size_t srcSize)
size_t ZSTD_compress(void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
size_t ZSTD_decompress(void *dst, size_t dstCapacity, const void *src, size_t srcSize)