mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-06 02:37:47 +00:00
slightly cleaned up PCB reader, added some exception logging
This commit is contained in:
parent
edd529297c
commit
c35795a9f3
2 changed files with 277 additions and 256 deletions
|
@ -57,24 +57,6 @@ enum class LgbEntryType : uint32_t
|
||||||
SphereCastRange = 75,
|
SphereCastRange = 75,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LGB_BGPARTS_HEADER
|
|
||||||
{
|
|
||||||
LgbEntryType type;
|
|
||||||
uint32_t unknown2;
|
|
||||||
uint32_t nameOffset;
|
|
||||||
vec3 translation;
|
|
||||||
vec3 rotation;
|
|
||||||
vec3 scale;
|
|
||||||
uint32_t modelFileOffset;
|
|
||||||
uint32_t collisionFileOffset;
|
|
||||||
uint32_t unknown4;
|
|
||||||
uint32_t unknown5;
|
|
||||||
uint32_t unknown6;
|
|
||||||
uint32_t unknown7;
|
|
||||||
uint32_t unknown8;
|
|
||||||
uint32_t unknown9;
|
|
||||||
};
|
|
||||||
|
|
||||||
class LGB_MODEL_ENTRY
|
class LGB_MODEL_ENTRY
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -94,6 +76,25 @@ public:
|
||||||
virtual ~LGB_MODEL_ENTRY() {};
|
virtual ~LGB_MODEL_ENTRY() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct LGB_BGPARTS_HEADER
|
||||||
|
{
|
||||||
|
LgbEntryType type;
|
||||||
|
uint32_t unknown2;
|
||||||
|
uint32_t nameOffset;
|
||||||
|
vec3 translation;
|
||||||
|
vec3 rotation;
|
||||||
|
vec3 scale;
|
||||||
|
uint32_t modelFileOffset;
|
||||||
|
uint32_t collisionFileOffset;
|
||||||
|
uint32_t unknown4;
|
||||||
|
uint32_t unknown5;
|
||||||
|
uint32_t unknown6;
|
||||||
|
uint32_t unknown7;
|
||||||
|
uint32_t unknown8;
|
||||||
|
uint32_t unknown9;
|
||||||
|
};
|
||||||
|
|
||||||
class LGB_BGPARTS_ENTRY : public LGB_MODEL_ENTRY
|
class LGB_BGPARTS_ENTRY : public LGB_MODEL_ENTRY
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
#include <Exd.h>
|
#include <Exd.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
namespace fs = std::experimental::filesystem;
|
namespace fs = std::experimental::filesystem;
|
||||||
struct face
|
struct face
|
||||||
{
|
{
|
||||||
|
@ -28,7 +32,7 @@ int parseBlockEntry( char* data, std::vector<PCB_BLOCK_ENTRY>& entries, int gOff
|
||||||
{
|
{
|
||||||
PCB_BLOCK_ENTRY block_entry;
|
PCB_BLOCK_ENTRY block_entry;
|
||||||
memcpy( &block_entry.header, data + offset, sizeof( block_entry.header ) );
|
memcpy( &block_entry.header, data + offset, sizeof( block_entry.header ) );
|
||||||
isgroup = block_entry.header.type == 0x30 ? true : false;
|
isgroup = block_entry.header.type == 0x30;
|
||||||
|
|
||||||
//printf( " BLOCKHEADER_%X: type: %i, group_size: %i\n", gOff + offset, block_entry.header.type, block_entry.header.group_size );
|
//printf( " BLOCKHEADER_%X: type: %i, group_size: %i\n", gOff + offset, block_entry.header.type, block_entry.header.group_size );
|
||||||
|
|
||||||
|
@ -115,6 +119,8 @@ std::string zoneNameToPath( const std::string& name )
|
||||||
|
|
||||||
int main( int argc, char* argv[] )
|
int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
|
auto startTime = std::chrono::system_clock::now();
|
||||||
|
|
||||||
std::string gamePath = "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv";
|
std::string gamePath = "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv";
|
||||||
std::string zoneName = "r1f1";
|
std::string zoneName = "r1f1";
|
||||||
|
|
||||||
|
@ -128,6 +134,8 @@ int main( int argc, char* argv[] )
|
||||||
}
|
}
|
||||||
const auto& zonePath = zoneNameToPath( zoneName );
|
const auto& zonePath = zoneNameToPath( zoneName );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
xiv::dat::GameData data1( gamePath );
|
xiv::dat::GameData data1( gamePath );
|
||||||
xiv::exd::ExdData eData( data1 );
|
xiv::exd::ExdData eData( data1 );
|
||||||
|
|
||||||
|
@ -139,7 +147,6 @@ int main( int argc, char* argv[] )
|
||||||
int32_t size = *(uint32_t*)§ion[4];
|
int32_t size = *(uint32_t*)§ion[4];
|
||||||
|
|
||||||
std::vector<std::string> stringList;
|
std::vector<std::string> stringList;
|
||||||
std::vector<std::string> stringList2;
|
|
||||||
|
|
||||||
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 §ion1 = test_file1->access_data_sections().at( 0 );
|
auto §ion1 = test_file1->access_data_sections().at( 0 );
|
||||||
|
@ -181,7 +188,10 @@ int main( int argc, char* argv[] )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw std::exception( "Cannot create new file. Run as admin." );
|
std::string errorMessage( "Cannot create " + zoneName + ".obj\n" +
|
||||||
|
" Check no programs have a handle to file and run as admin.\n" );
|
||||||
|
std::cout << errorMessage;
|
||||||
|
throw std::exception( errorMessage.c_str() );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +222,7 @@ int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
PCB_BLOCK_ENTRY block_entry;
|
PCB_BLOCK_ENTRY block_entry;
|
||||||
memcpy( &block_entry.header, &dataSection[0] + offset, sizeof( block_entry.header ) );
|
memcpy( &block_entry.header, &dataSection[0] + offset, sizeof( block_entry.header ) );
|
||||||
isgroup = block_entry.header.type == 0x30 ? true : false;
|
isgroup = block_entry.header.type == 0x30;
|
||||||
|
|
||||||
//printf( "BLOCKHEADER_%X: type: %i, group_size: %i\n", offset, block_entry.header.type, block_entry.header.group_size );
|
//printf( "BLOCKHEADER_%X: type: %i, group_size: %i\n", offset, block_entry.header.type, block_entry.header.group_size );
|
||||||
//
|
//
|
||||||
|
@ -264,12 +274,9 @@ int main( int argc, char* argv[] )
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for( auto &vertex_list : entry.data.vertices )
|
for( auto &vertex : entry.data.vertices )
|
||||||
{
|
{
|
||||||
vec3 v;
|
vec3 v( vertex.x, vertex.y, vertex.z );
|
||||||
v.x = vertex_list.x;
|
|
||||||
v.y = vertex_list.y;
|
|
||||||
v.z = vertex_list.z;
|
|
||||||
makeTranslation( v );
|
makeTranslation( v );
|
||||||
fprintf( fp_out, "v %f %f %f\n", v.x, v.y, v.z );
|
fprintf( fp_out, "v %f %f %f\n", v.x, v.y, v.z );
|
||||||
}
|
}
|
||||||
|
@ -291,16 +298,13 @@ int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
//if( index.index[0] != 0 || index.index[1] != 0 || index.index[2] != 0 )
|
//if( index.index[0] != 0 || index.index[1] != 0 || index.index[2] != 0 )
|
||||||
{
|
{
|
||||||
face f;
|
fprintf( fp_out, "f %i %i %i\n",
|
||||||
f.f1 = index.index[0] + max_index;
|
index.index[0] + max_index + 1,
|
||||||
f.f2 = index.index[1] + max_index;
|
index.index[1] + max_index + 1,
|
||||||
f.f3 = index.index[2] + max_index;
|
index.index[2] + max_index + 1 );
|
||||||
|
|
||||||
fprintf( fp_out, "f %i %i %i\n", f.f1 + 1, f.f2 + 1, f.f3 + 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 = vertices.size();
|
|
||||||
max_index += entry.data.vertices.size() + entry.data.vertices_i16.size();
|
max_index += entry.data.vertices.size() + entry.data.vertices_i16.size();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -320,13 +324,22 @@ int main( int argc, char* argv[] )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto pBgParts = dynamic_cast<LGB_BGPARTS_ENTRY*>(pEntry.get());
|
auto pBgParts = dynamic_cast<LGB_BGPARTS_ENTRY*>(pEntry.get());
|
||||||
if( !pBgParts || pBgParts->collisionFileName.empty()
|
if( pBgParts && pBgParts->collisionFileName.empty() )
|
||||||
|| std::find( stringList.begin(), stringList.end(), pBgParts->collisionFileName ) != stringList.end() )
|
{
|
||||||
|
pBgParts->collisionFileName = pBgParts->modelFileName;
|
||||||
|
boost::replace_all( pBgParts->collisionFileName, "bgparts", "collision" );
|
||||||
|
boost::replace_all( pBgParts->collisionFileName, ".mdl", ".pcb" );
|
||||||
|
//std::cout << pBgParts->collisionFileName << " renamed\n";
|
||||||
|
}
|
||||||
|
if( !pBgParts || pBgParts->collisionFileName.empty() )
|
||||||
|
//|| std::find( stringList.begin(), stringList.end(), pBgParts->collisionFileName ) != stringList.end() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto it = pcbFiles.find( pBgParts->collisionFileName );
|
auto it = pcbFiles.find( pBgParts->collisionFileName );
|
||||||
if( it == pcbFiles.end() )
|
if( it == pcbFiles.end() )
|
||||||
{
|
{
|
||||||
loadPcbFile( pBgParts->collisionFileName );
|
loadPcbFile( pBgParts->collisionFileName );
|
||||||
|
//std::cout << "\t\tLoaded PCB File " << pBgParts->collisionFileName << "\n";
|
||||||
}
|
}
|
||||||
if( it != pcbFiles.end() )
|
if( it != pcbFiles.end() )
|
||||||
{
|
{
|
||||||
|
@ -342,5 +355,12 @@ int main( int argc, char* argv[] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::cout << "Finished exporting " << zoneName << " in " <<
|
||||||
|
std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - startTime).count() << " seconds\n";
|
||||||
|
}
|
||||||
|
catch( std::exception& e )
|
||||||
|
{
|
||||||
|
std::cout << e.what() << std::endl;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue