mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-26 14:37:44 +00:00
Instance parser updated to map sgb content to EObjects
This commit is contained in:
parent
619d39e6f8
commit
0e9e155e53
4 changed files with 114 additions and 19 deletions
|
@ -9,7 +9,7 @@ public:
|
|||
|
||||
void onInit( InstanceContentPtr instance ) override
|
||||
{
|
||||
EOBJ_INIT
|
||||
EOBJ_INIT
|
||||
}
|
||||
|
||||
void onUpdate( InstanceContentPtr instance, uint32_t currTime ) override
|
||||
|
|
|
@ -257,7 +257,7 @@ struct LGB_GROUP
|
|||
{
|
||||
entries.push_back( std::make_shared< LGB_BGPARTS_ENTRY >( buf, entryOffset ) );
|
||||
}
|
||||
else if( !ignoreModels && type == LgbEntryType::Gimmick )
|
||||
else if( type == LgbEntryType::Gimmick )
|
||||
{
|
||||
entries.push_back( std::make_shared< LGB_GIMMICK_ENTRY >( buf, entryOffset ) );
|
||||
}
|
||||
|
|
|
@ -236,7 +236,9 @@ void loadEobjNames()
|
|||
auto id = row.first;
|
||||
auto& fields = row.second;
|
||||
auto name = *boost::get< std::string >( &fields.at( 0 ) );
|
||||
eobjNameMap[id] = name;
|
||||
|
||||
if( !name.empty() )
|
||||
eobjNameMap[id] = name;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,7 +433,7 @@ int main( int argc, char* argv[] )
|
|||
std::vector< LGB_FILE > lgbList{ bgLgb, planmapLgb };
|
||||
uint32_t max_index = 0;
|
||||
|
||||
if( ignoreModels )
|
||||
//if( ignoreModels )
|
||||
{
|
||||
std::map< std::string, SGB_FILE > sgbFiles;
|
||||
|
||||
|
@ -470,6 +472,7 @@ int main( int argc, char* argv[] )
|
|||
uint32_t count = 0;
|
||||
for( const auto& lgb : lgbList )
|
||||
{
|
||||
std::map< std::string, uint32_t> nameMap;
|
||||
for( const auto& group : lgb.groups )
|
||||
{
|
||||
//std::cout << "\t" << group.name << " Size " << group.header.entryCount << "\n";
|
||||
|
@ -494,32 +497,93 @@ int main( int argc, char* argv[] )
|
|||
std::string typeStr;
|
||||
uint32_t eobjlevelHierachyId = 0;
|
||||
|
||||
if( pObj->getType() == LgbEntryType::EventObject )
|
||||
auto pEobj = reinterpret_cast< LGB_EOBJ_ENTRY* >( pObj );
|
||||
id = pEobj->header.eobjId;
|
||||
unknown = pEobj->header.unknown;
|
||||
|
||||
|
||||
typeStr = eobjStr;
|
||||
eobjlevelHierachyId = pEobj->header.levelHierachyId;
|
||||
|
||||
std::string states = "";
|
||||
std::string gimmickName = "";
|
||||
for( const auto& pEntry1 : group.entries )
|
||||
{
|
||||
auto pEobj = reinterpret_cast< LGB_EOBJ_ENTRY* >( pObj );
|
||||
id = pEobj->header.eobjId;
|
||||
unknown = pEobj->header.unknown;
|
||||
name = eobjNameMap[id];
|
||||
if( name.empty() )
|
||||
name = "unknown" + std::to_string( count++ );
|
||||
name.erase( boost::remove_if( name, boost::is_any_of( "★_ '()[]-\x1a\x1\x2\x1f\x1\x3.:" ) ), name.end() );
|
||||
name[0] = toupper( name[0] );
|
||||
typeStr = eobjStr;
|
||||
eobjlevelHierachyId = pEobj->header.levelHierachyId;
|
||||
auto pGObj = pEntry1.get();
|
||||
if( pGObj->getType() == LgbEntryType::Gimmick )
|
||||
{
|
||||
if( pGObj->header.unknown == pEobj->header.levelHierachyId )
|
||||
{
|
||||
auto pGObjR = reinterpret_cast< LGB_GIMMICK_ENTRY* >( pGObj );
|
||||
char* dataSection = nullptr;
|
||||
//std::cout << fileName << " ";
|
||||
|
||||
auto file = data1->getFile( pGObjR->gimmickFileName );
|
||||
auto sections = file->get_data_sections();
|
||||
dataSection = §ions.at( 0 )[0];
|
||||
auto sgbFile = SGB_FILE( &dataSection[0] );
|
||||
|
||||
auto pos = pGObjR->gimmickFileName.find_last_of( "/" );
|
||||
|
||||
if( pos != std::string::npos )
|
||||
{
|
||||
name = pGObjR->gimmickFileName.substr( pos + 1 );
|
||||
name = name.substr( 0, name.length() - 4 );
|
||||
gimmickName = name;
|
||||
}
|
||||
|
||||
if( sgbFile.stateEntries.size() > 0 )
|
||||
{
|
||||
states = " // States -> ";
|
||||
for( auto entries1 : sgbFile.stateEntries )
|
||||
{
|
||||
states += entries1.name + " ";
|
||||
}
|
||||
states += "\n";
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
int state = 4;
|
||||
|
||||
if( id == 2000182 )
|
||||
if( eobjNameMap.find( id ) != eobjNameMap.end() )
|
||||
{
|
||||
name = eobjNameMap[id];
|
||||
name.erase( boost::remove_if( name, boost::is_any_of( "★_ '()[]-\x1a\x1\x2\x1f\x1\x3.:" ) ), name.end() );
|
||||
name[0] = toupper( name[0] );
|
||||
}
|
||||
if( name.empty() )
|
||||
name = "unknown_" + std::to_string( count++ );
|
||||
|
||||
if( id == 2000182 || gimmickName == "sgvf_w_lvd_b0095" )
|
||||
{
|
||||
state = 5;
|
||||
name = "Entrance";
|
||||
}
|
||||
|
||||
eobjects += "\n instance->registerEObj( \"" + name + "\", " + std::to_string( id ) +
|
||||
auto count1 = 0;
|
||||
if( nameMap.find( name ) == nameMap.end() )
|
||||
{
|
||||
nameMap[name] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
nameMap[name] = ++nameMap[name];
|
||||
count1 = nameMap[name];
|
||||
}
|
||||
|
||||
if( count1 > 0 )
|
||||
name = name + "_" + std::to_string( count1 );
|
||||
|
||||
eobjects += " instance->registerEObj( \"" + name + "\", " + std::to_string( id ) +
|
||||
", " + std::to_string( eobjlevelHierachyId ) + ", " + std::to_string( state ) + ", " +
|
||||
"{ " + std::to_string( pObj->header.translation.x ) + "f, "
|
||||
+ std::to_string( pObj->header.translation.y ) + "f, "
|
||||
+ std::to_string( pObj->header.translation.z ) + "f }, " + std::to_string( pObj->header.scale.x ) + "f );";
|
||||
+ std::to_string( pObj->header.translation.z ) + "f }, " + std::to_string( pObj->header.scale.x ) + "f );\n" + states;
|
||||
|
||||
|
||||
std::string outStr(
|
||||
std::to_string( id ) + ", " + typeStr + "\"" + name + "\", " +
|
||||
|
|
|
@ -160,7 +160,7 @@ struct SGB_HEADER
|
|||
int32_t offset1C;
|
||||
|
||||
uint32_t unknown20;
|
||||
uint32_t unknown24;
|
||||
uint32_t statesOffset;
|
||||
uint32_t unknown28;
|
||||
uint32_t unknown2C;
|
||||
|
||||
|
@ -178,10 +178,30 @@ struct SGB_HEADER
|
|||
uint32_t unknown54;
|
||||
};
|
||||
|
||||
struct SGB_STATE_HEADER
|
||||
{
|
||||
uint32_t id;
|
||||
uint32_t nameOffset;
|
||||
char unknown[0x24];
|
||||
};
|
||||
|
||||
struct SGB_STATE_ENTRY
|
||||
{
|
||||
SGB_STATE_HEADER header;
|
||||
std::string name;
|
||||
|
||||
SGB_STATE_ENTRY( char* buf )
|
||||
{
|
||||
header = *reinterpret_cast< SGB_STATE_HEADER* >( buf );
|
||||
name = std::string( buf + header.nameOffset );
|
||||
}
|
||||
};
|
||||
|
||||
struct SGB_FILE
|
||||
{
|
||||
SGB_HEADER header;
|
||||
std::vector<SGB_GROUP> entries;
|
||||
std::vector<SGB_STATE_ENTRY> stateEntries;
|
||||
|
||||
SGB_FILE()
|
||||
{
|
||||
|
@ -201,6 +221,17 @@ struct SGB_FILE
|
|||
entries.push_back( group );
|
||||
auto group2 = SGB_GROUP( buf, this, header.fileSize, baseOffset + header.offset1C );
|
||||
entries.push_back( group2 );
|
||||
uint32_t stateCount = *reinterpret_cast< uint32_t* >( buf + baseOffset + header.statesOffset + 4 );
|
||||
if( stateCount > 0 )
|
||||
{
|
||||
stateCount = stateCount;
|
||||
for( int i = 0; i < stateCount; ++i )
|
||||
{
|
||||
auto state = SGB_STATE_ENTRY( buf + baseOffset + header.statesOffset + 8 + i * sizeof( SGB_STATE_HEADER ) );
|
||||
stateEntries.push_back( state );
|
||||
std::cout << state.name << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( std::exception& e )
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue