Skip to content

Commit 08a5c48

Browse files
Updated code for parsing model to match new imhex pattern
1 parent be38d6f commit 08a5c48

File tree

1 file changed

+89
-17
lines changed

1 file changed

+89
-17
lines changed

SourceFiles/FFNA_ModelFile.h

Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ struct Chunk1_sub1
202202
uint8_t f0x24[8];
203203
uint32_t f0x2C;
204204
uint8_t num_some_struct0;
205-
uint8_t f0x31[7];
205+
uint8_t f0x31[3];
206+
uint32_t f0x34;
206207
uint32_t f0x38;
207208
uint32_t f0x3C;
208209
uint32_t f0x40;
@@ -780,11 +781,63 @@ struct TextureAndVertexShader
780781
}
781782
};
782783

784+
// SomeStruct2
785+
struct SomeStruct2
786+
{
787+
std::array<uint8_t, 8> unknown;
788+
uint32_t f0x8;
789+
uint32_t f0xC;
790+
uint32_t f0x10;
791+
uint32_t f0x14;
792+
std::vector<uint8_t> some_data; // dynamically sized
793+
794+
SomeStruct2() = default;
795+
SomeStruct2(uint32_t& curr_offset, const unsigned char* data, uint32_t data_size_bytes,
796+
bool& parsed_correctly)
797+
{
798+
if (curr_offset + sizeof(unknown) + sizeof(f0x8) + sizeof(f0xC) + sizeof(f0x10) + sizeof(f0x14) >
799+
data_size_bytes)
800+
{
801+
parsed_correctly = false;
802+
return;
803+
}
804+
805+
std::memcpy(unknown.data(), &data[curr_offset], unknown.size());
806+
curr_offset += unknown.size();
807+
808+
std::memcpy(&f0x8, &data[curr_offset], sizeof(f0x8));
809+
curr_offset += sizeof(f0x8);
810+
811+
std::memcpy(&f0xC, &data[curr_offset], sizeof(f0xC));
812+
curr_offset += sizeof(f0xC);
813+
814+
std::memcpy(&f0x10, &data[curr_offset], sizeof(f0x10));
815+
curr_offset += sizeof(f0x10);
816+
817+
std::memcpy(&f0x14, &data[curr_offset], sizeof(f0x14));
818+
curr_offset += sizeof(f0x14);
819+
820+
uint32_t data_size = f0x8 * 7 + (f0xC + f0x10 + f0x14) * 8;
821+
if (curr_offset + data_size > data_size_bytes)
822+
{
823+
parsed_correctly = false;
824+
return;
825+
}
826+
827+
some_data.resize(data_size);
828+
std::memcpy(some_data.data(), &data[curr_offset], data_size);
829+
curr_offset += data_size;
830+
}
831+
};
832+
783833
struct GeometryChunk
784834
{
785835
uint32_t chunk_id;
786836
uint32_t chunk_size;
787837
Chunk1_sub1 sub_1;
838+
std::vector<uint8_t> unknown0;
839+
std::vector<SomeStruct2> some_struct_2s;
840+
788841
TextureAndVertexShader tex_and_vertex_shader_struct;
789842
std::vector<uint8_t> unknown2;
790843
std::vector<uint8_t> unknown3;
@@ -802,6 +855,7 @@ struct GeometryChunk
802855
uint32_t unknown5;
803856
std::vector<ComplexStruct> complex_structs;
804857
std::vector<GeometryModel> models;
858+
std::vector<uint8_t> unknown_data;
805859
std::vector<uint8_t> chunk_data;
806860

807861
uint32_t compute_str_len_plus_one(const unsigned char* data, uint32_t address)
@@ -830,8 +884,30 @@ struct GeometryChunk
830884

831885
uint32_t curr_offset = offset + 8;
832886
sub_1 = Chunk1_sub1(&data[curr_offset]);
833-
sub_1.num_models;
834887
curr_offset += sizeof(sub_1);
888+
889+
uint32_t unknown0_size = sub_1.num_some_struct0 * 0x1C;
890+
if (offset + unknown0_size > offset + chunk_size + 8)
891+
{
892+
parsed_correctly = false;
893+
return;
894+
}
895+
896+
unknown0.resize(unknown0_size);
897+
std::memcpy(unknown0.data(), &data[curr_offset], unknown0_size);
898+
curr_offset += unknown0_size;
899+
900+
for (int i = 0; i < sub_1.num_some_struct2; i++)
901+
{
902+
SomeStruct2 new_some_struct2 = SomeStruct2(curr_offset, data, data_size_bytes, parsed_correctly);
903+
some_struct_2s.push_back(new_some_struct2);
904+
905+
if (! parsed_correctly) // Check if parsing was successful
906+
{
907+
break;
908+
}
909+
}
910+
835911
if (sub_1.num_models > 0)
836912
{
837913
const bool prev_parsed_correctly = parsed_correctly;
@@ -953,21 +1029,6 @@ struct GeometryChunk
9531029
return;
9541030
}
9551031

956-
if (sub_1.num_some_struct2 > 0)
957-
{
958-
// unknown2
959-
uint32_t unknown2_size = sub_1.num_some_struct2 * 0x30;
960-
unknown2.resize(unknown2_size);
961-
std::memcpy(unknown2.data(), &data[curr_offset], unknown2_size);
962-
curr_offset += unknown2_size;
963-
964-
// unknown3
965-
uint32_t unknown3_size = unknown2[0x28] * 0x18 + unknown2[0x2C] * 0x10;
966-
unknown3.resize(unknown3_size);
967-
std::memcpy(unknown3.data(), &data[curr_offset], unknown3_size);
968-
curr_offset += unknown3_size;
969-
}
970-
9711032
int num_models = sub_1.num_models;
9721033
for (int i = 0; i < num_models; i++)
9731034
{
@@ -982,6 +1043,17 @@ struct GeometryChunk
9821043
return;
9831044
}
9841045

1046+
uint32_t unknown_data_size = sub_1.f0x34;
1047+
if (curr_offset + unknown_data_size > offset + chunk_size + 8)
1048+
{
1049+
parsed_correctly = false;
1050+
return;
1051+
}
1052+
1053+
unknown_data.resize(unknown_data_size);
1054+
std::memcpy(unknown_data.data(), &data[curr_offset], unknown_data_size);
1055+
curr_offset += unknown_data_size;
1056+
9851057
// Copy remaining chunk_data after reading all other fields
9861058
size_t remaining_bytes = chunk_size + 5 + 8 - curr_offset;
9871059
if (curr_offset + remaining_bytes <= offset + chunk_size + 8 && remaining_bytes < chunk_size)

0 commit comments

Comments
 (0)