2024-03-03 15:35:56 -05:00
|
|
|
#include "modeldb.h"
|
|
|
|
|
|
|
|
DECOMP_SIZE_ASSERT(ModelDbWorld, 0x18)
|
|
|
|
DECOMP_SIZE_ASSERT(ModelDbPart, 0x18)
|
|
|
|
DECOMP_SIZE_ASSERT(ModelDbModel, 0x38)
|
|
|
|
DECOMP_SIZE_ASSERT(ModelDbPartList, 0x1c)
|
|
|
|
DECOMP_SIZE_ASSERT(ModelDbPartListCursor, 0x10)
|
|
|
|
|
2024-07-02 16:04:05 -04:00
|
|
|
// FUNCTION: LEGO1 0x10027690
|
|
|
|
// FUNCTION: BETA10 0x100e5620
|
|
|
|
void ModelDbModel::Free()
|
|
|
|
{
|
|
|
|
delete[] m_modelName;
|
|
|
|
delete[] m_presenterName;
|
|
|
|
}
|
|
|
|
|
2024-03-03 17:15:24 -05:00
|
|
|
// FUNCTION: LEGO1 0x100276b0
|
2024-12-16 16:25:52 -05:00
|
|
|
MxResult ModelDbModel::Read(SDL_IOStream* p_file)
|
2024-03-03 15:35:56 -05:00
|
|
|
{
|
2024-03-03 17:15:24 -05:00
|
|
|
MxU32 len;
|
|
|
|
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &len, sizeof(len)) != sizeof(len)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_modelName = new char[len];
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, m_modelName, len) != len) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &m_unk0x04, sizeof(m_unk0x04)) != sizeof(m_unk0x04)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &m_unk0x08, sizeof(m_unk0x08)) != sizeof(m_unk0x08)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &len, sizeof(len)) != sizeof(len)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_presenterName = new char[len];
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, m_presenterName, len) != len) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, m_location, sizeof(m_location)) != sizeof(m_location)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, m_direction, sizeof(m_direction)) != sizeof(m_direction)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, m_up, sizeof(m_up)) != sizeof(m_up)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &m_unk0x34, sizeof(m_unk0x34)) != sizeof(m_unk0x34)) {
|
2024-12-16 16:13:52 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2024-03-03 17:15:24 -05:00
|
|
|
|
2024-12-16 16:13:52 -05:00
|
|
|
return SUCCESS;
|
2024-03-03 15:35:56 -05:00
|
|
|
}
|
|
|
|
|
2024-03-03 17:15:24 -05:00
|
|
|
// FUNCTION: LEGO1 0x10027850
|
2024-12-16 16:25:52 -05:00
|
|
|
MxResult ModelDbPart::Read(SDL_IOStream* p_file)
|
2024-03-03 15:35:56 -05:00
|
|
|
{
|
2024-03-03 17:15:24 -05:00
|
|
|
MxU32 len;
|
|
|
|
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &len, sizeof(len)) != sizeof(len)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2024-12-16 16:25:52 -05:00
|
|
|
char* buff = new char[len];
|
|
|
|
|
|
|
|
if (SDL_ReadIO(p_file, buff, len) != len) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_roiName = buff;
|
2024-12-16 16:25:52 -05:00
|
|
|
delete[] buff;
|
2024-03-03 17:15:24 -05:00
|
|
|
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &m_partDataLength, sizeof(m_partDataLength)) != sizeof(m_partDataLength)) {
|
2024-03-03 17:15:24 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &m_partDataOffset, sizeof(m_partDataOffset)) != sizeof(m_partDataOffset)) {
|
2024-12-16 16:13:52 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2024-03-03 17:15:24 -05:00
|
|
|
|
2024-12-16 16:13:52 -05:00
|
|
|
return SUCCESS;
|
2024-03-03 15:35:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x10027910
|
2024-12-16 16:25:52 -05:00
|
|
|
MxResult ReadModelDbWorlds(SDL_IOStream* p_file, ModelDbWorld*& p_worlds, MxS32& p_numWorlds)
|
2024-03-03 15:35:56 -05:00
|
|
|
{
|
|
|
|
p_worlds = NULL;
|
|
|
|
p_numWorlds = 0;
|
|
|
|
|
|
|
|
MxS32 numWorlds;
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &numWorlds, sizeof(numWorlds)) != sizeof(numWorlds)) {
|
2024-03-03 15:35:56 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelDbWorld* worlds = new ModelDbWorld[numWorlds];
|
|
|
|
MxS32 worldNameLen, numParts, i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < numWorlds; i++) {
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &worldNameLen, sizeof(worldNameLen)) != sizeof(worldNameLen)) {
|
2024-03-03 15:35:56 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
worlds[i].m_worldName = new char[worldNameLen];
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, worlds[i].m_worldName, worldNameLen) != worldNameLen) {
|
2024-03-03 15:35:56 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &numParts, sizeof(numParts)) != sizeof(numParts)) {
|
2024-03-03 15:35:56 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
worlds[i].m_partList = new ModelDbPartList();
|
|
|
|
|
|
|
|
for (j = 0; j < numParts; j++) {
|
|
|
|
ModelDbPart* part = new ModelDbPart();
|
|
|
|
|
|
|
|
if (part->Read(p_file) != SUCCESS) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
worlds[i].m_partList->Append(part);
|
|
|
|
}
|
|
|
|
|
2024-12-16 16:25:52 -05:00
|
|
|
if (SDL_ReadIO(p_file, &worlds[i].m_numModels, sizeof(worlds[i].m_numModels)) !=
|
|
|
|
sizeof(worlds[i].m_numModels)) {
|
2024-03-03 15:35:56 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
worlds[i].m_models = new ModelDbModel[worlds[i].m_numModels];
|
|
|
|
|
|
|
|
for (j = 0; j < worlds[i].m_numModels; j++) {
|
|
|
|
if (worlds[i].m_models[j].Read(p_file) != SUCCESS) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p_worlds = worlds;
|
|
|
|
p_numWorlds = numWorlds;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2024-07-02 16:04:05 -04:00
|
|
|
// FUNCTION: LEGO1 0x10028080
|
|
|
|
// FUNCTION: BETA10 0x100e6431
|
2024-03-03 15:35:56 -05:00
|
|
|
void FreeModelDbWorlds(ModelDbWorld*& p_worlds, MxS32 p_numWorlds)
|
|
|
|
{
|
2024-07-02 16:04:05 -04:00
|
|
|
ModelDbWorld* worlds = p_worlds;
|
|
|
|
|
|
|
|
for (MxS32 i = 0; i < p_numWorlds; i++) {
|
|
|
|
delete[] worlds[i].m_worldName;
|
|
|
|
|
|
|
|
ModelDbPartListCursor cursor(worlds[i].m_partList);
|
|
|
|
ModelDbPart* part;
|
|
|
|
|
|
|
|
while (cursor.Next(part)) {
|
|
|
|
delete part;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete worlds[i].m_partList;
|
|
|
|
|
|
|
|
ModelDbModel* models = worlds[i].m_models;
|
|
|
|
for (MxS32 j = 0; j < worlds[i].m_numModels; j++) {
|
|
|
|
models[j].Free();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] worlds[i].m_models;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] p_worlds;
|
|
|
|
p_worlds = NULL;
|
2024-03-03 15:35:56 -05:00
|
|
|
}
|