mirror of
https://github.com/korenkonder/ReDIVA.git
synced 2026-10-06 13:48:01 +03:00
Temp commit. Need to store all sh... Changes
This commit is contained in:
+106
-113
@@ -4,14 +4,14 @@
|
||||
*/
|
||||
|
||||
#include "motion.hpp"
|
||||
#include "../io/path.h"
|
||||
#include "../io/stream.h"
|
||||
#include "../io/path.hpp"
|
||||
#include "../io/stream.hpp"
|
||||
#include "../farc.hpp"
|
||||
#include "../hash.hpp"
|
||||
#include "../str_utils.h"
|
||||
#include "../str_utils.hpp"
|
||||
|
||||
static void motion_database_read_inner(motion_database* mot_db, stream* s);
|
||||
static void motion_database_write_inner(motion_database* mot_db, stream* s);
|
||||
static void motion_database_read_inner(motion_database* mot_db, stream& s);
|
||||
static void motion_database_write_inner(motion_database* mot_db, stream& s);
|
||||
|
||||
motion_database::motion_database() : ready() {
|
||||
|
||||
@@ -33,9 +33,8 @@ void motion_database::read(const char* path) {
|
||||
farc_file* ff = f.read_file("mot_db.bin");
|
||||
if (ff) {
|
||||
stream s;
|
||||
io_open(&s, ff->data, ff->size);
|
||||
motion_database_read_inner(this, &s);
|
||||
io_free(&s);
|
||||
s.open(ff->data, ff->size);
|
||||
motion_database_read_inner(this, s);
|
||||
}
|
||||
}
|
||||
free(path_farc);
|
||||
@@ -53,9 +52,8 @@ void motion_database::read(const wchar_t* path) {
|
||||
farc_file* ff = f.read_file("mot_db.bin");
|
||||
if (ff) {
|
||||
stream s;
|
||||
io_open(&s, ff->data, ff->size);
|
||||
motion_database_read_inner(this, &s);
|
||||
io_free(&s);
|
||||
s.open(ff->data, ff->size);
|
||||
motion_database_read_inner(this, s);
|
||||
}
|
||||
}
|
||||
free(path_farc);
|
||||
@@ -66,9 +64,8 @@ void motion_database::read(const void* data, size_t size) {
|
||||
return;
|
||||
|
||||
stream s;
|
||||
io_open(&s, data, size);
|
||||
motion_database_read_inner(this, &s);
|
||||
io_free(&s);
|
||||
s.open(data, size);
|
||||
motion_database_read_inner(this, s);
|
||||
}
|
||||
|
||||
void motion_database::write(const char* path) {
|
||||
@@ -81,10 +78,9 @@ void motion_database::write(const char* path) {
|
||||
farc_file* ff = &f.files.back();
|
||||
|
||||
stream s;
|
||||
io_open(&s);
|
||||
motion_database_write_inner(this, &s);
|
||||
io_copy(&s, &ff->data, &ff->size);
|
||||
io_free(&s);
|
||||
s.open();
|
||||
motion_database_write_inner(this, s);
|
||||
s.copy(&ff->data, &ff->size);
|
||||
|
||||
f.write(path, FARC_COMPRESS_FArC, false);
|
||||
}
|
||||
@@ -99,10 +95,9 @@ void motion_database::write(const wchar_t* path) {
|
||||
farc_file* ff = &f.files.back();
|
||||
|
||||
stream s;
|
||||
io_open(&s);
|
||||
motion_database_write_inner(this, &s);
|
||||
io_copy(&s, &ff->data, &ff->size);
|
||||
io_free(&s);
|
||||
s.open();
|
||||
motion_database_write_inner(this, s);
|
||||
s.copy(&ff->data, &ff->size);
|
||||
|
||||
f.write(path, FARC_COMPRESS_FArC, false);
|
||||
}
|
||||
@@ -112,10 +107,9 @@ void motion_database::write(void** data, size_t* size) {
|
||||
return;
|
||||
|
||||
stream s;
|
||||
io_open(&s);
|
||||
motion_database_write_inner(this, &s);
|
||||
io_copy(&s, data, size);
|
||||
io_free(&s);
|
||||
s.open();
|
||||
motion_database_write_inner(this, s);
|
||||
s.copy(data, size);
|
||||
}
|
||||
|
||||
void motion_database::merge_mdata(motion_database* base_mot_db,
|
||||
@@ -360,172 +354,171 @@ motion_set_info::~motion_set_info() {
|
||||
|
||||
}
|
||||
|
||||
static void motion_database_read_inner(motion_database* mot_db, stream* s) {
|
||||
if (io_read_uint32_t(s) != 0x01)
|
||||
static void motion_database_read_inner(motion_database* mot_db, stream& s) {
|
||||
if (s.read_uint32_t() != 0x01)
|
||||
return;
|
||||
|
||||
uint32_t motion_sets_offset = io_read_uint32_t(s);
|
||||
uint32_t motion_set_ids_offset = io_read_uint32_t(s);
|
||||
uint32_t motion_set_count = io_read_uint32_t(s);
|
||||
uint32_t bone_name_offsets_offset = io_read_uint32_t(s);
|
||||
uint32_t bone_name_count = io_read_uint32_t(s);
|
||||
uint32_t motion_sets_offset = s.read_uint32_t();
|
||||
uint32_t motion_set_ids_offset = s.read_uint32_t();
|
||||
uint32_t motion_set_count = s.read_uint32_t();
|
||||
uint32_t bone_name_offsets_offset = s.read_uint32_t();
|
||||
uint32_t bone_name_count = s.read_uint32_t();
|
||||
|
||||
mot_db->motion_set.resize(motion_set_count);
|
||||
|
||||
io_position_push(s, motion_sets_offset, SEEK_SET);
|
||||
s.position_push(motion_sets_offset, SEEK_SET);
|
||||
for (uint32_t i = 0; i < motion_set_count; i++) {
|
||||
motion_set_info& set_info = mot_db->motion_set[i];
|
||||
|
||||
uint32_t name_offset = io_read_uint32_t(s);
|
||||
uint32_t motion_name_offsets_offset = io_read_uint32_t(s);
|
||||
uint32_t motion_count = io_read_uint32_t(s);
|
||||
uint32_t motion_ids_offset = io_read_uint32_t(s);
|
||||
uint32_t name_offset = s.read_uint32_t();
|
||||
uint32_t motion_name_offsets_offset = s.read_uint32_t();
|
||||
uint32_t motion_count = s.read_uint32_t();
|
||||
uint32_t motion_ids_offset = s.read_uint32_t();
|
||||
|
||||
io_read_string_null_terminated_offset(s, name_offset, &set_info.name);
|
||||
set_info.name = s.read_string_null_terminated_offset(name_offset);
|
||||
set_info.name_hash = hash_string_murmurhash(&set_info.name);
|
||||
|
||||
set_info.motion.resize(motion_count);
|
||||
|
||||
io_position_push(s, motion_name_offsets_offset, SEEK_SET);
|
||||
s.position_push(motion_name_offsets_offset, SEEK_SET);
|
||||
for (uint32_t j = 0; j < motion_count; j++) {
|
||||
io_read_string_null_terminated_offset(s,
|
||||
io_read_uint32_t(s), &set_info.motion[j].name);
|
||||
set_info.motion[j].name = s.read_string_null_terminated_offset(s.read_uint32_t());
|
||||
set_info.motion[j].name_hash = hash_string_murmurhash(&set_info.motion[j].name);
|
||||
}
|
||||
io_position_pop(s);
|
||||
s.position_pop();
|
||||
|
||||
io_position_push(s, motion_ids_offset, SEEK_SET);
|
||||
s.position_push(motion_ids_offset, SEEK_SET);
|
||||
for (uint32_t j = 0; j < motion_count; j++)
|
||||
set_info.motion[j].id = io_read_uint32_t(s);
|
||||
io_position_pop(s);
|
||||
set_info.motion[j].id = s.read_uint32_t();
|
||||
s.position_pop();
|
||||
}
|
||||
io_position_pop(s);
|
||||
s.position_pop();
|
||||
|
||||
io_position_push(s, motion_set_ids_offset, SEEK_SET);
|
||||
s.position_push(motion_set_ids_offset, SEEK_SET);
|
||||
for (uint32_t i = 0; i < motion_set_count; i++)
|
||||
mot_db->motion_set[i].id = io_read_uint32_t(s);
|
||||
io_position_pop(s);
|
||||
mot_db->motion_set[i].id = s.read_uint32_t();
|
||||
s.position_pop();
|
||||
|
||||
mot_db->bone_name.resize(bone_name_count);
|
||||
|
||||
io_position_push(s, bone_name_offsets_offset, SEEK_SET);
|
||||
s.position_push(bone_name_offsets_offset, SEEK_SET);
|
||||
for (uint32_t i = 0; i < bone_name_count; i++)
|
||||
io_read_string_null_terminated_offset(s, io_read_uint32_t(s), &mot_db->bone_name[i]);
|
||||
io_position_pop(s);
|
||||
mot_db->bone_name[i] = s.read_string_null_terminated_offset(s.read_uint32_t());
|
||||
s.position_pop();
|
||||
|
||||
mot_db->ready = true;
|
||||
}
|
||||
|
||||
static void motion_database_write_inner(motion_database* mot_db, stream* s) {
|
||||
io_write_int32_t(s, 0);
|
||||
io_write_int32_t(s, 0);
|
||||
io_write_int32_t(s, 0);
|
||||
io_write_int32_t(s, 0);
|
||||
io_write_int32_t(s, 0);
|
||||
io_write_int32_t(s, 0);
|
||||
io_align_write(s, 0x40);
|
||||
static void motion_database_write_inner(motion_database* mot_db, stream& s) {
|
||||
s.write_int32_t(0);
|
||||
s.write_int32_t(0);
|
||||
s.write_int32_t(0);
|
||||
s.write_int32_t(0);
|
||||
s.write_int32_t(0);
|
||||
s.write_int32_t(0);
|
||||
s.align_write(0x40);
|
||||
|
||||
size_t bone_name_count = mot_db->bone_name.size();
|
||||
size_t motion_set_count = mot_db->motion_set.size();
|
||||
|
||||
int64_t motion_sets_offset = io_get_position(s);
|
||||
io_write(s, 0x10 * motion_set_count + 0x10);
|
||||
io_align_write(s, 0x20);
|
||||
int64_t motion_sets_offset = s.get_position();
|
||||
s.write(0x10 * motion_set_count + 0x10);
|
||||
s.align_write(0x20);
|
||||
|
||||
size_t size = 0;
|
||||
for (motion_set_info& i : mot_db->motion_set)
|
||||
size += i.name.size() + 1;
|
||||
|
||||
int64_t motion_set_name_offset = io_get_position(s);
|
||||
io_write(s, size);
|
||||
int64_t motion_set_name_offset = s.get_position();
|
||||
s.write(size);
|
||||
|
||||
size = 0;
|
||||
for (motion_set_info& i : mot_db->motion_set)
|
||||
for (motion_info& j : i.motion)
|
||||
size += j.name.size() + 1;
|
||||
|
||||
int64_t motion_name_offset = io_get_position(s);
|
||||
io_write(s, size);
|
||||
io_align_write(s, 0x20);
|
||||
int64_t motion_name_offset = s.get_position();
|
||||
s.write(size);
|
||||
s.align_write(0x20);
|
||||
|
||||
int64_t motion_names_offset = io_get_position(s);
|
||||
int64_t motion_names_offset = s.get_position();
|
||||
size = 0;
|
||||
for (motion_set_info& i : mot_db->motion_set)
|
||||
size += 0x04 * i.motion.size();
|
||||
io_write(s, size);
|
||||
io_align_write(s, 0x20);
|
||||
s.write(size);
|
||||
s.align_write(0x20);
|
||||
|
||||
int64_t motion_ids_offset = io_get_position(s);
|
||||
int64_t motion_ids_offset = s.get_position();
|
||||
for (motion_set_info& i : mot_db->motion_set)
|
||||
for (motion_info& j : i.motion)
|
||||
io_write_uint32_t(s, j.id);
|
||||
io_align_write(s, 0x20);
|
||||
s.write_uint32_t(j.id);
|
||||
s.align_write(0x20);
|
||||
|
||||
int64_t motion_set_ids_offset = io_get_position(s);
|
||||
int64_t motion_set_ids_offset = s.get_position();
|
||||
for (motion_set_info& i : mot_db->motion_set)
|
||||
io_write_uint32_t(s, i.id);
|
||||
s.write_uint32_t(i.id);
|
||||
|
||||
int64_t bone_name_offset = io_get_position(s);
|
||||
int64_t bone_name_offset = s.get_position();
|
||||
size = 0;
|
||||
for (std::string& i : mot_db->bone_name)
|
||||
size += i.size() + 1;
|
||||
io_write(s, size);
|
||||
io_align_write(s, 0x20);
|
||||
s.write(size);
|
||||
s.align_write(0x20);
|
||||
|
||||
io_position_push(s, motion_set_name_offset, SEEK_SET);
|
||||
s.position_push(motion_set_name_offset, SEEK_SET);
|
||||
for (motion_set_info& i : mot_db->motion_set)
|
||||
io_write_string_null_terminated(s, &i.name);
|
||||
io_position_pop(s);
|
||||
s.write_string_null_terminated(i.name);
|
||||
s.position_pop();
|
||||
|
||||
io_position_push(s, motion_name_offset, SEEK_SET);
|
||||
s.position_push(motion_name_offset, SEEK_SET);
|
||||
for (motion_set_info& i : mot_db->motion_set)
|
||||
for (motion_info& j : i.motion)
|
||||
io_write_string_null_terminated(s, &j.name);
|
||||
io_position_pop(s);
|
||||
s.write_string_null_terminated(j.name);
|
||||
s.position_pop();
|
||||
|
||||
io_position_push(s, bone_name_offset, SEEK_SET);
|
||||
s.position_push(bone_name_offset, SEEK_SET);
|
||||
for (std::string& i : mot_db->bone_name)
|
||||
io_write_string_null_terminated(s, &i);
|
||||
io_position_pop(s);
|
||||
s.write_string_null_terminated(i);
|
||||
s.position_pop();
|
||||
|
||||
int64_t bone_name_offsets_offset = io_get_position(s);
|
||||
io_write(s, 0x04 * bone_name_count);
|
||||
io_align_write(s, 0x20);
|
||||
int64_t bone_name_offsets_offset = s.get_position();
|
||||
s.write(0x04 * bone_name_count);
|
||||
s.align_write(0x20);
|
||||
|
||||
io_position_push(s, motion_names_offset, SEEK_SET);
|
||||
s.position_push(motion_names_offset, SEEK_SET);
|
||||
for (motion_set_info& i : mot_db->motion_set)
|
||||
for (motion_info& j : i.motion) {
|
||||
io_write_uint32_t(s, (uint32_t)motion_name_offset);
|
||||
s.write_uint32_t((uint32_t)motion_name_offset);
|
||||
motion_name_offset += j.name.size() + 1;
|
||||
}
|
||||
io_position_pop(s);
|
||||
s.position_pop();
|
||||
|
||||
io_position_push(s, motion_sets_offset, SEEK_SET);
|
||||
s.position_push(motion_sets_offset, SEEK_SET);
|
||||
for (motion_set_info& i : mot_db->motion_set) {
|
||||
io_write_uint32_t(s, (uint32_t)motion_set_name_offset);
|
||||
io_write_uint32_t(s, (uint32_t)motion_names_offset);
|
||||
io_write_uint32_t(s, (uint32_t)i.motion.size());
|
||||
io_write_uint32_t(s, (uint32_t)motion_ids_offset);
|
||||
s.write_uint32_t((uint32_t)motion_set_name_offset);
|
||||
s.write_uint32_t((uint32_t)motion_names_offset);
|
||||
s.write_uint32_t((uint32_t)i.motion.size());
|
||||
s.write_uint32_t((uint32_t)motion_ids_offset);
|
||||
motion_set_name_offset += i.name.size() + 1;
|
||||
motion_names_offset += 0x04 * i.motion.size();
|
||||
motion_ids_offset += 0x04 * i.motion.size();
|
||||
}
|
||||
io_write(s, 0x10);
|
||||
io_position_pop(s);
|
||||
s.write(0x10);
|
||||
s.position_pop();
|
||||
|
||||
io_position_push(s, bone_name_offsets_offset, SEEK_SET);
|
||||
s.position_push(bone_name_offsets_offset, SEEK_SET);
|
||||
for (std::string& i : mot_db->bone_name) {
|
||||
io_write_uint32_t(s, (uint32_t)bone_name_offset);
|
||||
s.write_uint32_t((uint32_t)bone_name_offset);
|
||||
bone_name_offset += i.size() + 1;
|
||||
}
|
||||
io_position_pop(s);
|
||||
s.position_pop();
|
||||
|
||||
io_position_push(s, 0x00, SEEK_SET);
|
||||
io_write_uint32_t(s, 0x01);
|
||||
io_write_uint32_t(s, (uint32_t)motion_sets_offset);
|
||||
io_write_uint32_t(s, (uint32_t)motion_set_ids_offset);
|
||||
io_write_uint32_t(s, (uint32_t)motion_set_count);
|
||||
io_write_uint32_t(s, (uint32_t)bone_name_offsets_offset);
|
||||
io_write_uint32_t(s, (uint32_t)bone_name_count);
|
||||
io_position_pop(s);
|
||||
s.position_push(0x00, SEEK_SET);
|
||||
s.write_uint32_t(0x01);
|
||||
s.write_uint32_t((uint32_t)motion_sets_offset);
|
||||
s.write_uint32_t((uint32_t)motion_set_ids_offset);
|
||||
s.write_uint32_t((uint32_t)motion_set_count);
|
||||
s.write_uint32_t((uint32_t)bone_name_offsets_offset);
|
||||
s.write_uint32_t((uint32_t)bone_name_count);
|
||||
s.position_pop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user