diff --git a/src/CRE/Glitter/curve.cpp b/src/CRE/Glitter/curve.cpp index 09ee3741..d1dc2a28 100644 --- a/src/CRE/Glitter/curve.cpp +++ b/src/CRE/Glitter/curve.cpp @@ -748,6 +748,22 @@ namespace Glitter { ? -key.random_range : 0.0f, key.random_range); } + Curve& Curve::operator=(const Curve& curv) { + type = curv.type; + repeat = curv.repeat; + start_time = curv.start_time; + end_time = curv.end_time; + flags = curv.flags; + random_range = curv.random_range; + keys.assign(curv.keys.begin(), curv.keys.end()); + #if defined(CRE_DEV) + keys_rev.assign(curv.keys_rev.begin(), curv.keys_rev.end()); +#endif + version = curv.version; + keys_version = curv.keys_version; + return *this; + } + void Curve::GetKeyIndices(const std::vector& keys, float_t frame, size_t& curr, size_t& next) { size_t count = keys.size(); diff --git a/src/CRE/Glitter/file_writer.cpp b/src/CRE/Glitter/file_writer.cpp index 3bc8901b..c34ef23c 100644 --- a/src/CRE/Glitter/file_writer.cpp +++ b/src/CRE/Glitter/file_writer.cpp @@ -2163,7 +2163,7 @@ namespace Glitter { } void FileWriter::Write(GLT, EffectGroup* eff_group, const char* path, - const char* file, bool compress, bool encrypt, bool big_endian) { + const char* file, bool compress, bool encrypt, bool save_lst, bool big_endian) { FileWriter fr; fr.type = GLT_VAL; @@ -2205,7 +2205,7 @@ namespace Glitter { } } - if (fr.type == Glitter::FT) { + if (fr.type == Glitter::FT || save_lst) { f2_struct lst_st; if (fr.UnparseDivaList(eff_group, &lst_st, big_endian)) { memcpy(&temp[file_len], ".lst", 4); @@ -2242,7 +2242,7 @@ namespace Glitter { } char* temp = str_utils_add(path, file); - if (glt_type != Glitter::FT) { + if (glt_type != Glitter::FT && !save_lst) { char* list_temp = str_utils_add(temp, ".glitter.txt"); file_stream s; s.open(list_temp, "wb"); diff --git a/src/CRE/Glitter/glitter.hpp b/src/CRE/Glitter/glitter.hpp index 7df96114..b980e838 100644 --- a/src/CRE/Glitter/glitter.hpp +++ b/src/CRE/Glitter/glitter.hpp @@ -587,6 +587,8 @@ namespace Glitter { float_t XRandomize(float_t value, Random* random); float_t XRandomizeKey(const Curve::Key& key, Random* random); + Curve& operator=(const Curve& curv); + static void GetKeyIndices(const std::vector& keys, float_t frame, size_t& curr, size_t& next); @@ -1225,7 +1227,7 @@ namespace Glitter { f2_struct* st, Particle* ptcl, Effect* eff, bool big_endian); static void Write(GLT, EffectGroup* eff_group, const char* path, - const char* file, bool compress, bool encrypt, bool big_endian = false); + const char* file, bool compress, bool encrypt, bool save_lst = false, bool big_endian = false); }; struct LocusHistory { diff --git a/src/KKdLib/txp.cpp b/src/KKdLib/txp.cpp index 36b41f89..945f6583 100644 --- a/src/KKdLib/txp.cpp +++ b/src/KKdLib/txp.cpp @@ -427,3 +427,8 @@ bool txp_set::unpack_file_modern(const void* data, size_t size, uint32_t signatu ret = unpack_file(st.data.data(), st.header.use_big_endian); return ret; } + +txp_set& txp_set::operator=(const txp_set& set) { + textures.assign(set.textures.begin(), set.textures.end()); + return *this; +} diff --git a/src/KKdLib/txp.hpp b/src/KKdLib/txp.hpp index 7be18ca3..a6532c71 100644 --- a/src/KKdLib/txp.hpp +++ b/src/KKdLib/txp.hpp @@ -63,4 +63,6 @@ struct txp_set { bool produce_enrs(enrs* enrs); bool unpack_file(const void* data, bool big_endian); bool unpack_file_modern(const void* data, size_t size, uint32_t signature); + + txp_set& operator=(const txp_set& set); }; diff --git a/src/ReDIVA/config.hpp b/src/ReDIVA/config.hpp index eed13fcc..b36a202c 100644 --- a/src/ReDIVA/config.hpp +++ b/src/ReDIVA/config.hpp @@ -7,6 +7,7 @@ #define BAKE_PNG (0) #define BAKE_VIDEO (0) #define BAKE_PV826 (0) +#define BAKE_X_PACK (1) #define DW_TRANSLATE (0) #define PV_DEBUG (1) diff --git a/src/ReDIVA/game_state.cpp b/src/ReDIVA/game_state.cpp index 0da9e896..b0349d32 100644 --- a/src/ReDIVA/game_state.cpp +++ b/src/ReDIVA/game_state.cpp @@ -1234,8 +1234,12 @@ bool SubGameState::Selector::Init() { return true; } #endif + +#if BAKE_X_PACK +#else x_pv_game_selector_init(); app::TaskWork::add_task(x_pv_game_selector_get(), "X PVGAME SELECTOR", 0); +#endif #endif return true; } @@ -1283,7 +1287,10 @@ bool SubGameState::Selector::Ctrl() { return false; } #endif + #if defined(CRE_DEV) +#if BAKE_X_PACK +#else XPVGameSelector* sel = x_pv_game_selector_get(); if (sel->exit) { if (sel->start && x_pv_game_init()) { @@ -1295,6 +1302,7 @@ bool SubGameState::Selector::Ctrl() { game_state_set_game_state_next(GAME_STATE_ADVERTISE); return true; } +#endif #endif return false; } @@ -1304,26 +1312,28 @@ bool SubGameState::Selector::Dest() { #if PV_DEBUG if (!pv_x) { PVGameSelector* sel = pv_game_selector_get(); - if (!app::TaskWork::check_task_ready(sel)) { - pv_game_selector_free(); - return true; + if (app::TaskWork::check_task_ready(sel)) { + sel->del(); + return false; } + pv_game_selector_free(); + return true; + } +#endif + +#if BAKE_X_PACK +#else + XPVGameSelector* sel = x_pv_game_selector_get(); + if (app::TaskWork::check_task_ready(sel)) { sel->del(); return false; } + + x_pv_game_selector_free(); +#endif #endif - XPVGameSelector* sel = x_pv_game_selector_get(); - if (!app::TaskWork::check_task_ready(sel)) { - x_pv_game_selector_free(); - return true; - } - - sel->del(); - return false; -#else return true; -#endif } bool SubGameState::GameMain::Init() { diff --git a/src/ReDIVA/render.cpp b/src/ReDIVA/render.cpp index f7c250db..7b9b0eb9 100644 --- a/src/ReDIVA/render.cpp +++ b/src/ReDIVA/render.cpp @@ -231,7 +231,11 @@ int32_t render_main(render_init_struct* ris) { if (!render_lock) return 0; +#if BAKE_X_PACK || DOF_BAKE + render_timer = new timer(600.0); +#else render_timer = new timer(60.0); +#endif window_handle = 0; diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index 88067eab..adc52c4c 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -239,7 +239,10 @@ dof_cam dof_cam_data; #endif x_pv_game* x_pv_game_ptr; x_pv_game_music* x_pv_game_music_ptr; +#if BAKE_X_PACK +#else XPVGameSelector* x_pv_game_selector_ptr; +#endif extern render_context* rctx_ptr; @@ -254,18 +257,25 @@ static void x_pv_game_map_auth_3d_to_mot(x_pv_game* xpvgm, bool add_keys); #endif static void x_pv_game_reset_field(x_pv_game* xpvgm); +#if BAKE_X_PACK static void x_pv_game_update_object_set(ObjsetInfo* info); -static void x_pv_game_write_auth_3d(auth_3d* auth); +static void x_pv_game_write_auth_3d(farc* f, auth_3d* auth); static void x_pv_game_write_glitter(Glitter::EffectGroup* eff_group); static void x_pv_game_write_object_set(ObjsetInfo* info, object_database* obj_db, texture_database* tex_db); +#endif static void print_dsc_command(dsc& dsc, dsc_data* dsc_data_ptr, int64_t time); static void print_dsc_command(dsc& dsc, dsc_data* dsc_data_ptr, int64_t* time); +#if BAKE_X_PACK || DOF_BAKE static void replace_pv832(char* str); static void replace_pv832(std::string& str); -static void replace_stgpv(char* str); -static void replace_stgpv(std::string& str); +#endif + +#if BAKE_X_PACK +static void replace_names(char* str); +static void replace_names(std::string& str); +#endif bool x_pv_bar_beat_data::compare_bar_time_less(float_t time) { return (time + 0.0001f) < bar_time; @@ -6233,6 +6243,7 @@ bool x_pv_game::ctrl() { if (wait_load) break; +#if BAKE_X_PACK state_old = 18; } break; case 18: { @@ -6425,20 +6436,48 @@ bool x_pv_game::ctrl() { } for (auto& i : chara_effect_auth_3ds) - x_pv_game_write_auth_3d(i); + x_pv_game_write_auth_3d(0, i); - for (auto& i : song_effect_auth_3ds) - x_pv_game_write_auth_3d(i); + if (song_effect_auth_3ds.size()) { + char name[0x40]; + sprintf_s(name, sizeof(name), "EFFPV%03d", pv_data.pv_id); + replace_names(name); - for (auto& i : stage_data_effect_auth_3ds) - x_pv_game_write_auth_3d(i); + char path[MAX_PATH]; + strcpy_s(path, sizeof(path), "patch\\!temp\\auth_3d\\"); + strcat_s(path, sizeof(path), name); - for (auto& i : stage_data_change_effect_auth_3ds) - x_pv_game_write_auth_3d(i); + farc* f = new farc; + for (auto& i : song_effect_auth_3ds) + x_pv_game_write_auth_3d(f, i); + + f->write(path, FARC_FArC, FARC_NONE, false); + delete f; + } + + if (stage_data_effect_auth_3ds.size() || stage_data_change_effect_auth_3ds.size()) { + char name[0x40]; + sprintf_s(name, sizeof(name), "EFFSTGPV%03d", stage_data.stage_id); + replace_names(name); + + char path[MAX_PATH]; + strcpy_s(path, sizeof(path), "patch\\!temp\\auth_3d\\"); + strcat_s(path, sizeof(path), name); + + farc* f = new farc; + for (auto& i : stage_data_effect_auth_3ds) + x_pv_game_write_auth_3d(f, i); + + for (auto& i : stage_data_change_effect_auth_3ds) + x_pv_game_write_auth_3d(f, i); + + f->write(path, FARC_FArC, FARC_NONE, false); + delete f; + } for (auto& i : glitter_eff_groups) x_pv_game_write_glitter(i); - +#endif state_old = 19; } break; case 19: { @@ -7660,6 +7699,8 @@ void x_pv_game::stop_current_pv() { field_71994.reset(); } +#if BAKE_X_PACK +#else XPVGameSelector::XPVGameSelector() : charas(), modules(), start(), exit() { pv_id = 823; stage_id = 23; @@ -7904,6 +7945,7 @@ void XPVGameSelector::window() { ImGui::End(); } +#endif bool x_pv_game_init() { x_pv_game_ptr = new x_pv_game; @@ -7943,6 +7985,8 @@ bool x_pv_game_free() { return true; } +#if BAKE_X_PACK +#else bool x_pv_game_selector_init() { if (!x_pv_game_selector_ptr) x_pv_game_selector_ptr = new XPVGameSelector; @@ -7960,6 +8004,7 @@ bool x_pv_game_selector_free() { } return true; } +#endif #if DOF_BAKE dof_cam::dof_cam() { @@ -8424,6 +8469,7 @@ static void auth_3d_key_rev(auth_3d_key& k, std::vector& values_src) { } } +#if BAKE_X_PACK static void x_pv_game_update_object_set(ObjsetInfo* info) { prj::shared_ptr old_alloc = info->alloc_handler; @@ -8435,7 +8481,7 @@ static void x_pv_game_update_object_set(ObjsetInfo* info) { info->obj_set = set; } -static void x_pv_game_write_auth_3d(auth_3d* auth) { +static void x_pv_game_write_auth_3d(farc* f, auth_3d* auth) { char name[0x200]; strcpy_s(name, sizeof(name), auth->file_name.c_str()); @@ -8451,22 +8497,7 @@ static void x_pv_game_write_auth_3d(auth_3d* auth) { ext = strstr(name, a3da_ext); } - replace_stgpv(name); - - for (char* i = name; *i && i != ext; i++) { - char c = *i; - if (c >= 'A' && c <= 'Z') - *i += 0x20; - } - - if (strstr(name, "effchrpv826")) - return; - - char buf[0x200]; - file_stream s; - - strcpy_s(buf, sizeof(buf), "patch\\!temp\\auth_3d\\"); - strcat_s(buf, sizeof(buf), name); + replace_names(name); for (char* i = name; *i && i != ext; i++) { char c = *i; @@ -8474,6 +8505,9 @@ static void x_pv_game_write_auth_3d(auth_3d* auth) { *i -= 0x20; } + if (strstr(name, "EFFCHRPV826")) + return; + a3da a; float_t max_frame = auth->max_frame; auth->max_frame = auth->play_control.size; @@ -8488,51 +8522,74 @@ static void x_pv_game_write_auth_3d(auth_3d* auth) { for (a3da_m_object_hrc& i : a.m_object_hrc) { for (a3da_object_instance& j : i.instance) { - replace_stgpv(j.name); - replace_stgpv(j.uid_name); + replace_names(j.name); + replace_names(j.uid_name); } - replace_stgpv(i.name); + replace_names(i.name); } for (std::string& i : a.m_object_hrc_list) - replace_stgpv(i); + replace_names(i); for (a3da_object& i : a.object) { - replace_stgpv(i.name); - replace_stgpv(i.parent_name); - replace_stgpv(i.uid_name); + replace_names(i.name); + replace_names(i.parent_name); + replace_names(i.uid_name); } for (a3da_object_hrc& i : a.object_hrc) { - replace_stgpv(i.name); - replace_stgpv(i.parent_name); - replace_stgpv(i.uid_name); + replace_names(i.name); + replace_names(i.parent_name); + replace_names(i.uid_name); } for (std::string& i : a.object_hrc_list) - replace_stgpv(i); + replace_names(i); for (std::string& i : a.object_list) - replace_stgpv(i); + replace_names(i); - void* a3da_data = 0; - size_t a3da_length = 0; - a.write(&a3da_data, &a3da_length); + bool own_farc = !f; + + if (own_farc) + f = new farc; - s.open(buf, "wb"); - s.write(a3da_data, a3da_length); - s.close(); + farc_file* ff = f->add_file(name); + a.write(&ff->data, &ff->size); - free_def(a3da_data); + + if (own_farc) { + char path[MAX_PATH]; + strcpy_s(path, sizeof(path), "patch\\!temp\\auth_3d\\"); + strncat_s(path, sizeof(path), name, ext - name); + + f->write(path, FARC_FArC, FARC_NONE, false); + delete f; + } } static void x_pv_game_write_glitter(Glitter::EffectGroup* eff_group) { + Glitter::EffectGroup temp_eff_group(Glitter::X); + temp_eff_group.name.assign(eff_group->name); + temp_eff_group.version = eff_group->version; + + temp_eff_group.effects.reserve(eff_group->effects.size()); + for (Glitter::Effect* i : eff_group->effects) { + Glitter::Effect* eff = new Glitter::Effect(Glitter::X); + *eff = *i; + temp_eff_group.effects.push_back(eff); + } + + temp_eff_group.resource_hashes.assign( + eff_group->resource_hashes.begin(), eff_group->resource_hashes.end()); + temp_eff_group.resources_tex = eff_group->resources_tex; + char name[0x200]; strcpy_s(name, sizeof(name), eff_group->name.c_str()); - replace_stgpv(name); + replace_names(name); data_struct* x_data = &data_list[DATA_X]; auto& hashes = x_data->glitter_list_murmurhash; @@ -8548,13 +8605,14 @@ static void x_pv_game_write_glitter(Glitter::EffectGroup* eff_group) { auto elem = hashes.find(e->data.name_hash); if (elem != hashes.end()) { e->name.assign(elem->second); - replace_stgpv(e->name); + replace_names(e->name); } else printf_debug("Couldn't find name for hash 0x%08X\n", e->data.name_hash); } - Glitter::FileWriter::Write(Glitter::X, eff_group, "patch\\!temp\\particle\\", name, true, true); + Glitter::FileWriter::Write(Glitter::X, &temp_eff_group, + "patch\\!temp\\particle_x\\", name, true, true, true); } static void x_pv_game_write_object_set(ObjsetInfo* info, object_database* obj_db, texture_database* tex_db) { @@ -8567,19 +8625,19 @@ static void x_pv_game_write_object_set(ObjsetInfo* info, object_database* obj_db name[j] += 0x20; } - replace_stgpv(name); + replace_names(name); if (strstr(name, "effchrpv826")) return; + farc f; { data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; texture_database* aft_tex_db = &aft_data->data_ft.tex_db; - char buf[0x200]; - strcpy_s(buf, sizeof(buf), "patch\\!temp\\objset\\"); - strcat_s(buf, sizeof(buf), name); + char buf[0x100]; + strcpy_s(buf, sizeof(buf), name); strcat_s(buf, sizeof(buf), "_obj.bin"); prj::shared_ptr alloc(new prj::stack_allocator); @@ -8590,7 +8648,7 @@ static void x_pv_game_write_object_set(ObjsetInfo* info, object_database* obj_db for (uint32_t i = 0; i < obj_num; i++) { obj* obj = set->obj_data[i]; - replace_stgpv((char*)obj->name); + replace_names((char*)obj->name); obj->id = aft_obj_db->get_object_info(obj->name).id; uint32_t num_material = obj->num_material; @@ -8606,7 +8664,7 @@ static void x_pv_game_write_object_set(ObjsetInfo* info, object_database* obj_db if (tex_name) { char name_buf[0x200]; strcpy_s(name_buf, sizeof(name_buf), tex_name); - replace_stgpv(name_buf); + replace_names(name_buf); k.tex_index = aft_tex_db->get_texture_id(name_buf); } else @@ -8629,7 +8687,7 @@ static void x_pv_game_write_object_set(ObjsetInfo* info, object_database* obj_db if (tex_name) { char name_buf[0x200]; strcpy_s(name_buf, sizeof(name_buf), tex_name); - replace_stgpv(name_buf); + replace_names(name_buf); id = aft_tex_db->get_texture_id(name_buf); } @@ -8639,22 +8697,14 @@ static void x_pv_game_write_object_set(ObjsetInfo* info, object_database* obj_db set->modern = false; - void* obj_data = 0; - size_t obj_length = 0; - set->pack_file(&obj_data, &obj_length); - - file_stream s; - s.open(buf, "wb"); - s.write(obj_data, obj_length); - s.close(); - - free_def(obj_data); + farc_file* ff_obj = f.add_file(buf); + set->pack_file(&ff_obj->data, &ff_obj->size); + ff_obj->compressed = true; } { - char buf[0x200]; - strcpy_s(buf, sizeof(buf), "patch\\!temp\\objset\\"); - strcat_s(buf, sizeof(buf), name); + char buf[0x100]; + strcpy_s(buf, sizeof(buf), name); strcat_s(buf, sizeof(buf), "_tex.bin"); uint32_t tex_num = info->tex_num; @@ -8665,18 +8715,18 @@ static void x_pv_game_write_object_set(ObjsetInfo* info, object_database* obj_db for (uint32_t j = 0; j < tex_num; j++) texture_txp_store(tex_data[j], &txp.textures[j]); - void* txp_data = 0; - size_t txp_length = 0; - txp.pack_file(&txp_data, &txp_length, false); - - file_stream s; - s.open(buf, "wb"); - s.write(txp_data, txp_length); - s.close(); - - free_def(txp_data); + farc_file* ff_tex = f.add_file(buf); + txp.pack_file(&ff_tex->data, &ff_tex->size, false); + ff_tex->compressed = true; } + + char buf[0x200]; + strcpy_s(buf, sizeof(buf), "patch\\!temp\\objset\\"); + strcat_s(buf, sizeof(buf), name); + + f.write(buf, FARC_FArC, FARC_NONE, false); } +#endif static void print_dsc_command(dsc& dsc, dsc_data* dsc_data_ptr, int64_t time) { print_dsc_command(dsc, dsc_data_ptr, &time); @@ -8714,6 +8764,7 @@ static void print_dsc_command(dsc& dsc, dsc_data* dsc_data_ptr, int64_t* time) { dw_console_printf(DW_CONSOLE_PV_SCRIPT, ")\n"); } +#if BAKE_X_PACK || DOF_BAKE static void replace_pv832(char* str) { char* pv; pv = str; @@ -8740,8 +8791,10 @@ static void replace_pv832(char* str) { inline static void replace_pv832(std::string& str) { replace_pv832((char*)str.data()); } +#endif -static void replace_stgpv(char* str) { +#if BAKE_X_PACK +static void replace_names(char* str) { char* stgpv; stgpv = str; while (true) { @@ -8763,10 +8816,32 @@ static void replace_stgpv(char* str) { stgpv += 6; } + char* effpv; + effpv = str; + while (true) { + effpv = strstr(effpv, "EFFPV"); + if (!effpv || strstr(effpv, "EFFPV815") || strstr(effpv, "PTC")) + break; + + memcpy(effpv, "ITMPV", 5); + effpv += 6; + } + + effpv = str; + while (true) { + effpv = strstr(effpv, "effpv"); + if (!effpv || strstr(effpv, "effpv815") || strstr(effpv, "ptc")) + break; + + memcpy(effpv, "itmpv", 5); + effpv += 6; + } + replace_pv832(str); } -inline static void replace_stgpv(std::string& str) { - replace_stgpv((char*)str.data()); +inline static void replace_names(std::string& str) { + replace_names((char*)str.data()); } #endif +#endif diff --git a/src/ReDIVA/x_pv_game.hpp b/src/ReDIVA/x_pv_game.hpp index 0a7cd1f3..f252c9e5 100644 --- a/src/ReDIVA/x_pv_game.hpp +++ b/src/ReDIVA/x_pv_game.hpp @@ -815,6 +815,8 @@ public: } }; +#if BAKE_X_PACK +#else class XPVGameSelector : public app::TaskWindow { public: int32_t pv_id; @@ -834,12 +836,16 @@ public: virtual bool dest() override; virtual void window() override; }; +#endif extern bool x_pv_game_init(); extern x_pv_game* x_pv_game_get(); extern bool x_pv_game_free(); +#if BAKE_X_PACK +#else extern bool x_pv_game_selector_init(); extern XPVGameSelector* x_pv_game_selector_get(); extern bool x_pv_game_selector_free(); #endif +#endif