1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 07:37:45 +00:00

Merge pull request #146 from takhlaq/pcb

cleaned up some compiler warnings in pcb_reader
This commit is contained in:
Mordred 2017-10-20 21:27:59 +02:00 committed by GitHub
commit 0b25ec89ae
2 changed files with 66 additions and 56 deletions

View file

@ -151,7 +151,7 @@ int main( int argc, char* argv[] )
auto test_file1 = data1.get_file( "bg/ffxiv/" + zonePath + "/collision/list.pcb" ); auto test_file1 = data1.get_file( "bg/ffxiv/" + zonePath + "/collision/list.pcb" );
auto section1 = test_file1->access_data_sections().at( 0 ); auto section1 = test_file1->access_data_sections().at( 0 );
std::string path = "bg/ffxiv/" + zonePath + "/collision/"; std::string path = "bg/ffxiv/" + zonePath + "/collision/";
int offset1 = 0x20; uint32_t offset1 = 0x20;
for( ; ; ) for( ; ; )
{ {
@ -170,14 +170,7 @@ int main( int argc, char* argv[] )
} }
LGB_FILE bgLgb( &section[0] ); LGB_FILE bgLgb( &section[0] );
uint32_t max_index = 0;
int max_index = 0;
std::vector<std::string> vertices;
std::vector<std::string> indices;
char *data;
int counter = 0;
// dont bother if we cant write to a file // dont bother if we cant write to a file
auto fp_out = fopen( ( zoneName + ".obj" ).c_str(), "w" ); auto fp_out = fopen( ( zoneName + ".obj" ).c_str(), "w" );
@ -248,27 +241,30 @@ int main( int argc, char* argv[] )
auto loadSgbFile = [&]( const std::string& fileName ) -> bool auto loadSgbFile = [&]( const std::string& fileName ) -> bool
{ {
SGB_FILE sgbFile;
try try
{ {
auto file = data1.get_file( fileName ); auto file = data1.get_file( fileName );
auto sections = file->get_data_sections(); auto sections = file->get_data_sections();
auto dataSection = &sections.at( 0 )[0]; auto dataSection = &sections.at( 0 )[0];
SGB_FILE sgbFile = SGB_FILE( &dataSection[0] ); sgbFile = SGB_FILE( &dataSection[0] );
sgbFiles.insert( std::make_pair( fileName, sgbFile ) ); sgbFiles.insert( std::make_pair( fileName, sgbFile ) );
return true; return true;
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
std::cout << "Unable to load SGB " << fileName << "\n\tError:\n\t" << e.what() << "\n"; std::cout << "Unable to load SGB " << fileName << "\n\tError:\n\t" << e.what() << "\n";
return false; sgbFiles.insert( std::make_pair( fileName, sgbFile ) );
} }
return false;
}; };
auto pushVerts = [&]( const PCB_FILE& pcb_file, const std::string& name, const vec3* scale = nullptr, const vec3* rotation = nullptr, const vec3* translation = nullptr ) auto pushVerts = [&]( const PCB_FILE& pcb_file, const std::string& name, const vec3* scale = nullptr, const vec3* rotation = nullptr, const vec3* translation = nullptr )
{ {
char name2[0x7F]; char name2[0x100];
memset( name2, 0, 0x7F ); memset( name2, 0, 0x100 );
sprintf(&name2[0], "%s_%u", &name[0], objCount[name]++ ); sprintf( &name2[0], "%s_%u", &name[0], objCount[name]++ );
fprintf( fp_out, "o %s\n", &name2[0] ); //fprintf( fp_out, "o %s\n", &name2[0] );
uint32_t groupCount = 0; uint32_t groupCount = 0;
for( const auto &entry : pcb_file.entries ) for( const auto &entry : pcb_file.entries )
{ {
@ -316,14 +312,11 @@ int main( int argc, char* argv[] )
//fprintf( fp_out, "g %s_", (name2 + "_" + std::to_string( groupCount++ )).c_str() ); //fprintf( fp_out, "g %s_", (name2 + "_" + std::to_string( groupCount++ )).c_str() );
for( const auto &index : entry.data.indices ) for( const auto &index : entry.data.indices )
{
//if( index.index[0] != 0 || index.index[1] != 0 || index.index[2] != 0 )
{ {
fprintf( fp_out, "f %i %i %i\n", fprintf( fp_out, "f %i %i %i\n",
index.index[0] + max_index + 1, index.index[0] + max_index + 1,
index.index[1] + max_index + 1, index.index[1] + max_index + 1,
index.index[2] + max_index + 1 ); index.index[2] + max_index + 1 );
}
// std::cout << std::to_string( index.unknown[0] )<< " " << std::to_string( index.unknown[1] )<< " " << std::to_string( index.unknown[2]) << std::endl; // std::cout << std::to_string( index.unknown[0] )<< " " << std::to_string( index.unknown[1] )<< " " << std::to_string( index.unknown[2]) << std::endl;
} }
max_index += entry.data.vertices.size() + entry.data.vertices_i16.size(); max_index += entry.data.vertices.size() + entry.data.vertices_i16.size();
@ -343,59 +336,63 @@ int main( int argc, char* argv[] )
{ {
//std::cout << "\t" << group.name << " Size " << group.header.entryCount << "\n"; //std::cout << "\t" << group.name << " Size " << group.header.entryCount << "\n";
totalGroups++; totalGroups++;
for( const auto pEntry : group.entries ) for( const auto& pEntry : group.entries )
{ {
LGB_GIMMICK_ENTRY* pGimmick = nullptr; LGB_GIMMICK_ENTRY* pGimmick = dynamic_cast<LGB_GIMMICK_ENTRY*>( pEntry.get() );
auto pBgParts = dynamic_cast<LGB_BGPARTS_ENTRY*>( pEntry.get() ); auto pBgParts = dynamic_cast<LGB_BGPARTS_ENTRY*>( pEntry.get() );
if( pBgParts && pBgParts->header.type != LgbEntryType::BgParts )
pBgParts = nullptr;
auto fileName = pBgParts ? pBgParts->collisionFileName : std::string(""); std::string fileName( "" );
fileName.resize( 256 );
if( pBgParts && fileName.empty() ) totalGroupEntries++;
continue;
// write files // write files
auto writeOutput = [&]() auto writeOutput = [&]( const std::string& fileName, const vec3* scale, const vec3* rotation, const vec3* translation ) -> bool
{ {
{ {
const auto& it = pcbFiles.find( fileName ); const auto& it = pcbFiles.find( fileName );
if( it == pcbFiles.end() ) if( it == pcbFiles.end() )
{ {
if( !fileName.empty() ) if( fileName.empty() || !loadPcbFile( fileName ) )
loadPcbFile( fileName ); return false;
//std::cout << "\t\tLoaded PCB File " << pBgParts->collisionFileName << "\n"; //std::cout << "\t\tLoaded PCB File " << pBgParts->collisionFileName << "\n";
} }
} }
const auto& it = pcbFiles.find( fileName ); const auto& it = pcbFiles.find( fileName );
if( it != pcbFiles.end() ) if( it != pcbFiles.end() )
{ {
totalGroupEntries++;
const auto* scale = pBgParts ? &pBgParts->header.scale : &pGimmick->header.scale;
const auto* rotation = pBgParts ? &pBgParts->header.rotation : &pGimmick->header.rotation;
const auto* translation = pBgParts ? &pBgParts->header.translation : &pGimmick->header.translation;
const auto& pcb_file = it->second; const auto& pcb_file = it->second;
pushVerts( pcb_file, fileName, scale, rotation, translation ); pushVerts( pcb_file, fileName, scale, rotation, translation );
} }
return true;
}; };
// gimmick entry if( pBgParts )
if( !pBgParts ) {
fileName = pBgParts->collisionFileName;
if( !writeOutput( fileName, &pBgParts->header.scale, &pBgParts->header.rotation, &pBgParts->header.translation ) )
{
fileName = pBgParts->modelFileName;
boost::replace_all( fileName, "bgparts", "collision" );
boost::replace_all( fileName, ".mdl", ".pcb" );
writeOutput( fileName, &pBgParts->header.scale, &pBgParts->header.rotation, &pBgParts->header.translation );
}
}
// gimmick entry
if( pGimmick )
{ {
pGimmick = dynamic_cast<LGB_GIMMICK_ENTRY*>( pEntry.get() );
{ {
const auto& it = sgbFiles.find( pGimmick->gimmickFileName ); const auto& it = sgbFiles.find( pGimmick->gimmickFileName );
if( it == sgbFiles.end() ) if( it == sgbFiles.end() )
{ {
//std::cout << "\tGIMMICK:\n\t\t" << pGimmick->name << " " << pGimmick->gimmickFileName << "\n";
loadSgbFile( pGimmick->gimmickFileName ); loadSgbFile( pGimmick->gimmickFileName );
} }
} }
const auto& it = sgbFiles.find( pGimmick->gimmickFileName ); const auto& it = sgbFiles.find( pGimmick->gimmickFileName );
if( it != sgbFiles.end() ) if( it != sgbFiles.end() )
{ {
totalGroupEntries++;
const auto& sgbFile = it->second; const auto& sgbFile = it->second;
for( const auto& group : sgbFile.entries ) for( const auto& group : sgbFile.entries )
@ -403,18 +400,18 @@ int main( int argc, char* argv[] )
for( const auto& pEntry : group.entries ) for( const auto& pEntry : group.entries )
{ {
auto pModel = dynamic_cast<SGB_MODEL_ENTRY*>( pEntry.get() ); auto pModel = dynamic_cast<SGB_MODEL_ENTRY*>( pEntry.get() );
if( !pModel->collisionFileName.empty() )
{
fileName = pModel->collisionFileName; fileName = pModel->collisionFileName;
writeOutput(); if( !writeOutput( fileName, &pGimmick->header.scale, &pGimmick->header.rotation, &pGimmick->header.translation ) )
{
fileName = pModel->modelFileName;
boost::replace_all( fileName, "bgparts", "collision" );
boost::replace_all( fileName, ".mdl", ".pcb" );
writeOutput( fileName, &pGimmick->header.scale, &pGimmick->header.rotation, &pGimmick->header.translation );
} }
} }
} }
} }
continue;
} }
// bgparts
writeOutput();
} }
} }
std::cout << "\n\nLoaded " << pcbFiles.size() << " PCB Files \n"; std::cout << "\n\nLoaded " << pcbFiles.size() << " PCB Files \n";

View file

@ -114,17 +114,19 @@ struct SGB_GROUP
SGB_FILE* parent; SGB_FILE* parent;
std::vector<std::shared_ptr<SGB_GROUP_ENTRY>> entries; std::vector<std::shared_ptr<SGB_GROUP_ENTRY>> entries;
SGB_GROUP( char* buf, SGB_FILE* file, uint32_t offset ) SGB_GROUP( char* buf, SGB_FILE* file, uint32_t fileSize, uint32_t offset )
{ {
parent = file; parent = file;
header = *reinterpret_cast<SGB_GROUP_HEADER*>( buf + offset ); header = *reinterpret_cast<SGB_GROUP_HEADER*>( buf + offset );
name = std::string( buf + offset + header.nameOffset ); name = std::string( buf + offset + header.nameOffset );
auto entriesOffset = offset + sizeof( header ); auto entriesOffset = offset + sizeof( header );
for( auto i = 0; i < header.entryCount; ++i ) for( auto i = 0; i < header.entryCount; ++i )
{ {
auto entryOffset = entriesOffset + *reinterpret_cast<uint32_t*>( buf + ( entriesOffset + i * 4 ) ); auto entryOffset = entriesOffset + *reinterpret_cast<uint32_t*>( buf + ( entriesOffset + (i * 4) ) );
if( entryOffset > fileSize )
throw std::runtime_error( "SGB_GROUP entry offset was larger than SGB file size!" );
auto type = *reinterpret_cast<uint32_t*>( buf + entryOffset ); auto type = *reinterpret_cast<uint32_t*>( buf + entryOffset );
if( type == SgbGroupEntryType::Model ) if( type == SgbGroupEntryType::Model )
{ {
@ -170,6 +172,10 @@ struct SGB_FILE
SGB_HEADER header; SGB_HEADER header;
std::vector<SGB_GROUP> entries; std::vector<SGB_GROUP> entries;
SGB_FILE()
{
memset( &header, 0, sizeof( header ) );
}
SGB_FILE( char* buf ) SGB_FILE( char* buf )
{ {
constexpr int baseOffset = 0x14; constexpr int baseOffset = 0x14;
@ -178,10 +184,17 @@ struct SGB_FILE
if( strncmp( &header.magic[0], "SGB1", 4 ) != 0 || strncmp( &header.magic2[0], "SCN1", 4 ) != 0 ) if( strncmp( &header.magic[0], "SGB1", 4 ) != 0 || strncmp( &header.magic2[0], "SCN1", 4 ) != 0 )
throw std::runtime_error( "Unable to load SGB File!" ); throw std::runtime_error( "Unable to load SGB File!" );
auto group = SGB_GROUP( buf, this, baseOffset + header.sharedOffset ); try
//auto group2 = SGB_GROUP( buf, this, baseOffset + header.offset1C ); {
auto group = SGB_GROUP( buf, this, header.fileSize, baseOffset + header.sharedOffset );
entries.push_back( group ); entries.push_back( group );
//entries.push_back( group2 ); auto group2 = SGB_GROUP( buf, this, header.fileSize, baseOffset + header.offset1C );
entries.push_back( group2 );
}
catch( std::exception& e )
{
std::cout << e.what() << "\n";
}
}; };
}; };