Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize pixelmap/material/model/actor structs to file #80

Merged
merged 14 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/BRSRC13/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
add_library(brender STATIC)

option(BRENDER_FIX_BUGS "Fix BRender bugs" ON)

target_include_directories(brender
PRIVATE
.
Expand Down Expand Up @@ -31,6 +33,9 @@ else()
/wd4996
)
endif()
if(BRENDER_FIX_BUGS)
target_compile_definitions(brender PRIVATE BRENDER_FIX_BUGS)
endif()

target_sources(brender PRIVATE
include/brender/brender.h
Expand Down Expand Up @@ -165,6 +170,7 @@ target_sources(brender PRIVATE
CORE/STD/logwrite.h
CORE/V1DB/actsupt.c
CORE/V1DB/actsupt.h
CORE/V1DB/chunkids.h
CORE/V1DB/custsupt.c
CORE/V1DB/custsupt.h
CORE/V1DB/dbsetup.c
Expand Down Expand Up @@ -197,6 +203,7 @@ target_sources(brender PRIVATE
CORE/V1DB/regsupt.h
CORE/V1DB/render.c
CORE/V1DB/render.h
CORE/V1DB/stackids.h
CORE/V1DB/v1dbfile.c
CORE/V1DB/v1dbfile.h
)
30 changes: 22 additions & 8 deletions src/BRSRC13/CORE/FW/datafile.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,19 @@ struct {
int count;
} DatafileStack[1024];

#ifdef BRENDER_FIX_BUGS
char* ChunkNames[62] = {
#else
char* ChunkNames[61] = {
#endif
"END",
"IMAGE_PLANE",
"RLE_IMAGE_PLANE",
#ifdef BRENDER_FIX_BUGS
"PIXELMAP_OLD",
#else
"PIXELMAP",
#endif
"MATERIAL_OLD",
"ADD_MATERIAL",
"OLD_ACTOR",
Expand Down Expand Up @@ -206,7 +214,12 @@ char* ChunkNames[61] = {
"SATURN_FACES",
"SATURN_MODEL",
"INDEX_FOG_REF",
#ifdef BRENDER_FIX_BUGS
"MATERIAL",
"PIXELMAP",
#else
"MATERIAL_OLD",
#endif
};

int DatafileStackTop;
Expand Down Expand Up @@ -266,7 +279,7 @@ int DfTopType() {
// IDA: int __usercall TextReadLine@<EAX>(br_datafile *df@<EAX>, char **ident@<EDX>, char **data@<EBX>)
int TextReadLine(br_datafile* df, char** ident, char** data) {
char* cp;
LOG_TRACE("(%p, %p, %p)", df, ident, data);
LOG_TRACE9("(%p, %p, %p)", df, ident, data);

while (1) {
cp = BrScratchString();
Expand Down Expand Up @@ -690,7 +703,7 @@ int DfStructSizeBinary(br_datafile* df, br_file_struct* str, void* base) {
// IDA: int __usercall EnumFromString@<EAX>(br_file_enum *e@<EAX>, char *str@<EDX>)
int EnumFromString(br_file_enum* e, char* str) {
unsigned int m;
LOG_TRACE("(%p, \"%s\")", e, str);
LOG_TRACE9("(%p, \"%s\")", e, str);

if (e == NULL) {
BrFailure("Unknown enum string: %s", str);
Expand All @@ -706,7 +719,7 @@ int EnumFromString(br_file_enum* e, char* str) {
// IDA: char* __usercall EnumToString@<EAX>(br_file_enum *e@<EAX>, int num@<EDX>)
char* EnumToString(br_file_enum* e, int num) {
unsigned int m;
LOG_TRACE("(%p, %d)", e, num);
LOG_TRACE9("(%p, %d)", e, num);

if (e == NULL) {
goto fail;
Expand Down Expand Up @@ -860,7 +873,7 @@ br_uint_32 StructWriteTextSub(br_datafile* df, br_file_struct* str, void* base,
br_uint_32 DfStructReadText(br_datafile* df, br_file_struct* str, void* base) {
char* id;
char* data;
LOG_TRACE("(%p, %p, %p)", df, str, base);
LOG_TRACE9("(%p, %p, %p)", df, str, base);

TextReadLine(df, &id, &data);
if (BrStrCmp(id, "struct") != 0) {
Expand All @@ -886,7 +899,7 @@ br_uint_32 StructReadTextSub(br_datafile* df, br_file_struct* str, void* base) {
char* id;
char* data;
char* ep;
LOG_TRACE("(%p, %p, %p)", df, str, base);
LOG_TRACE9("(%p, %p, %p)", df, str, base);

for (m = 0; m < str->nmembers; m++) {
sm = &str->members[m];
Expand Down Expand Up @@ -1096,7 +1109,7 @@ int DfChunkReadText(br_datafile* df, br_uint_32* plength) {
int i;
char* id;
char* data;
LOG_TRACE("(%p, %p)", df, plength);
LOG_TRACE9("(%p, %p)", df, plength);

if (TextReadLine(df, &id, &data) == 0) {
return -1;
Expand Down Expand Up @@ -1252,7 +1265,7 @@ int DfBlockWriteText(br_datafile* df, void* base, int block_size, int block_stri
BrFilePutChar('\n', df->h);
}
}
if ((i & 0x1f) != 0x1f) {
if ((i & 0x1f) != 0x0) {
BrFilePutChar('\n', df->h);
}
if (block != base) {
Expand All @@ -1269,7 +1282,7 @@ void* DfBlockReadText(br_datafile* df, void* base, int* count, int size, int mty
int s;
int a;
char b[3];
LOG_TRACE("(%p, %p, %p, %d, %d)", df, base, count, size, mtype);
LOG_TRACE9("(%p, %p, %p, %d, %d)", df, base, count, size, mtype);

TextReadLine(df, &id, &data);
if (BrStrCmp(id, "block") != 0) {
Expand Down Expand Up @@ -1463,6 +1476,7 @@ int DfSkipText(br_datafile* df, br_uint_32 length) {

while ((BrFileEof(df->h) == 0) && (length != 0)) {
TextReadLine(df, &data, &id);
length--;
}
return 0;
}
Expand Down
36 changes: 30 additions & 6 deletions src/BRSRC13/CORE/FW/genfile.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
#include "genfile.h"
#include "harness/trace.h"

#include "CORE/V1DB/chunkids.h"
#include <stddef.h>
#include <stdlib.h>

br_file_struct_member file_info_FM[2];
br_file_struct file_info_F;
br_file_enum_member file_type_FM[10];
br_file_enum file_type_F;
br_file_enum_member file_type_FM[10] = {
{ FILE_TYPE_NONE, "FILE_TYPE_NONE" },
{ FILE_TYPE_ACTORS, "FILE_TYPE_ACTORS" },
{ FILE_TYPE_PIXELMAP, "FILE_TYPE_PIXELMAP" },
{ FILE_TYPE_LIGHT, "FILE_TYPE_LIGHT" },
{ FILE_TYPE_CAMERA, "FILE_TYPE_CAMERA" },
{ FILE_TYPE_MATERIAL_OLD, "FILE_TYPE_MATERIAL_OLD" },
{ FILE_TYPE_MODEL, "FILE_TYPE_MODEL" },
{ FILE_TYPE_ANIMATION, "FILE_TYPE_ANIMATION" },
{ FILE_TYPE_TREE, "FILE_TYPE_TREE" },
{ FILE_TYPE_MATERIAL, "FILE_TYPE_MATERIAL" },
};
br_file_enum file_type_F = { BR_ASIZE(file_type_FM), file_type_FM };

br_file_struct_member file_info_FM[2] = {
{ 15, offsetof(file_info, type), "type", &file_type_F },
{ 5, offsetof(file_info, version), "version", NULL },
};
br_file_struct file_info_F = { "file_info", BR_ASIZE(file_info_FM), file_info_FM, sizeof(file_info) };

// IDA: int __usercall FopRead_END@<EAX>(br_datafile *df@<EAX>, br_uint_32 id@<EDX>, br_uint_32 length@<EBX>, br_uint_32 count@<ECX>)
int FopRead_END(br_datafile* df, br_uint_32 id, br_uint_32 length, br_uint_32 count) {
Expand All @@ -15,12 +33,18 @@ int FopRead_END(br_datafile* df, br_uint_32 id, br_uint_32 length, br_uint_32 co
// IDA: int __usercall FopWrite_END@<EAX>(br_datafile *df@<EAX>)
int FopWrite_END(br_datafile* df) {
LOG_TRACE("(%p)", df);
NOT_IMPLEMENTED();

df->prims->chunk_write(df, CHUNKID_END, 0);
}

// IDA: int __usercall FopWrite_FILE_INFO@<EAX>(br_datafile *df@<EAX>, br_uint_32 type@<EDX>)
int FopWrite_FILE_INFO(br_datafile* df, br_uint_32 type) {
file_info fi;
LOG_TRACE("(%p, %d)", df, type);
NOT_IMPLEMENTED();

fi.type = type;
fi.version = 2;
df->prims->chunk_write(df, CHUNKID_FILE_INFO, df->prims->struct_size(df, &file_info_F, &fi));
df->prims->struct_write(df, &file_info_F, &fi);
return 0;
}
11 changes: 11 additions & 0 deletions src/BRSRC13/CORE/FW/genfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@

#include "brender/br_types.h"

#define FILE_TYPE_NONE 0x0
#define FILE_TYPE_ACTORS 0x1
#define FILE_TYPE_PIXELMAP 0x2
#define FILE_TYPE_LIGHT 0x3
#define FILE_TYPE_CAMERA 0x4
#define FILE_TYPE_MATERIAL_OLD 0x5
#define FILE_TYPE_MODEL 0xface
#define FILE_TYPE_ANIMATION 0xa11
#define FILE_TYPE_TREE 0x5eed
#define FILE_TYPE_MATERIAL 0x6

int FopRead_END(br_datafile* df, br_uint_32 id, br_uint_32 length, br_uint_32 count);

int FopWrite_END(br_datafile* df);
Expand Down
25 changes: 25 additions & 0 deletions src/BRSRC13/CORE/MATH/angles.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
#include "brender/br_types.h"
#include <math.h>

#define BR_EULER_XYZ_S 0
#define BR_EULER_XYX_S 8
#define BR_EULER_XZY_S 4
#define BR_EULER_XZX_S 12
#define BR_EULER_YZX_S 1
#define BR_EULER_YZY_S 9
#define BR_EULER_YXZ_S 5
#define BR_EULER_YXY_S 13
#define BR_EULER_ZXY_S 2
#define BR_EULER_ZXZ_S 10
#define BR_EULER_ZYX_S 6
#define BR_EULER_ZYZ_S 14
#define BR_EULER_ZYX_R 16
#define BR_EULER_XYX_R 24
#define BR_EULER_YZX_R 20
#define BR_EULER_XZX_R 28
#define BR_EULER_XZY_R 17
#define BR_EULER_YZY_R 25
#define BR_EULER_ZXY_R 21
#define BR_EULER_YXY_R 29
#define BR_EULER_YXZ_R 18
#define BR_EULER_ZXZ_R 26
#define BR_EULER_XYZ_R 22
#define BR_EULER_ZYZ_R 30

br_matrix34* BrEulerToMatrix34(br_matrix34* mat, br_euler* euler);

br_euler* BrMatrix34ToEuler(br_euler* euler, br_matrix34* mat);
Expand Down
Loading