mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-27 22:57:45 +00:00
Fixed the struct generator and added a small struct test app
This commit is contained in:
parent
bad5a17850
commit
c541064b22
10 changed files with 420 additions and 19 deletions
|
@ -63,5 +63,6 @@ add_subdirectory("src/libraries/sapphire/mysqlConnector")
|
|||
|
||||
add_subdirectory("src/tools/exd_common_gen")
|
||||
add_subdirectory("src/tools/exd_struct_gen")
|
||||
add_subdirectory("src/tools/exd_struct_test")
|
||||
add_subdirectory("src/tools/quest_parser")
|
||||
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
#include "ExdData.h"
|
||||
#include "ExdDataGenerated.h"
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
Core::Data::ExdData::ExdData()
|
||||
|
||||
CONSTRUCTORS
|
||||
|
||||
Core::Data::ExdDataGenerated::ExdDataGenerated()
|
||||
{
|
||||
}
|
||||
|
||||
Core::Data::ExdData::~ExdData()
|
||||
Core::Data::ExdDataGenerated::~ExdDataGenerated()
|
||||
{
|
||||
}
|
||||
|
||||
xiv::exd::Exd Core::Data::ExdData::setupDatAccess( const std::string& name, xiv::exd::Language lang )
|
||||
xiv::exd::Exd Core::Data::ExdDataGenerated::setupDatAccess( const std::string& name, xiv::exd::Language lang )
|
||||
{
|
||||
auto& cat = m_exd_data->get_category( name );
|
||||
return static_cast< xiv::exd::Exd >( cat.get_data_ln( lang ) );
|
||||
};
|
||||
|
||||
bool Core::Data::ExdData::init( const std::string& path )
|
||||
bool Core::Data::ExdDataGenerated::init( const std::string& path )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
|
||||
namespace Core {
|
||||
namespace Data {
|
||||
|
||||
class ExdDataGenerated;
|
||||
STRUCTS
|
||||
|
||||
class ExdData
|
||||
class ExdDataGenerated
|
||||
{
|
||||
public:
|
||||
ExdData();
|
||||
~ExdData();
|
||||
ExdDataGenerated();
|
||||
~ExdDataGenerated();
|
||||
|
||||
bool init( const std::string& path );
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ Core::Logger g_log;
|
|||
Core::Data::ExdData g_exdData;
|
||||
|
||||
|
||||
//const std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" );
|
||||
const std::string datLocation( "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv" );
|
||||
const std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" );
|
||||
//const std::string datLocation( "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv" );
|
||||
std::map< uint8_t, std::string > g_typeMap;
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ std::string generateDirectGetterDef( const std::string& exd )
|
|||
std::string result = "";
|
||||
result =
|
||||
"boost::shared_ptr< Core::Data::" + exd + " >\n"
|
||||
" Core::Data::ExdData::get" + exd + "( uint32_t " + exd + "Id )\n"
|
||||
" Core::Data::ExdDataGenerated::get" + exd + "( uint32_t " + exd + "Id )\n"
|
||||
"{\n"
|
||||
" try\n"
|
||||
" {\n"
|
||||
|
@ -111,19 +111,56 @@ std::string generateStruct( const std::string &exd )
|
|||
count++;
|
||||
}
|
||||
|
||||
result += "\n " + exd + "( uint32_t id, Core::Data::ExdData* exdData )\n";
|
||||
result += "\n " + exd + "( uint32_t id, Core::Data::ExdDataGenerated* exdData );\n";
|
||||
result += " };\n";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string generateConstructorsDecl( const std::string& exd )
|
||||
{
|
||||
std::string result;
|
||||
|
||||
auto& cat = g_exdData.m_exd_data->get_category( exd );
|
||||
auto exh = cat.get_header();
|
||||
auto exhMem = exh.get_exh_members();
|
||||
|
||||
std::map< uint32_t, std::string > indexToNameMap;
|
||||
std::map< uint32_t, std::string > indexToTypeMap;
|
||||
int count = 0;
|
||||
|
||||
|
||||
for( auto member : exhMem )
|
||||
{
|
||||
auto typei = static_cast< uint8_t >( member.type );
|
||||
auto it = g_typeMap.find( typei );
|
||||
|
||||
std::string type;
|
||||
if( it != g_typeMap.end() )
|
||||
type = it->second;
|
||||
else
|
||||
type = "bool";
|
||||
|
||||
std::string fieldName = " field" + std::to_string( count );
|
||||
|
||||
indexToNameMap[count] = fieldName;
|
||||
indexToTypeMap[count] = type;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
result += "\n Core::Data::" + exd + "::" + exd + "( uint32_t id, Core::Data::ExdDataGenerated* exdData )\n";
|
||||
result += " {\n";
|
||||
count = 0;
|
||||
std::string indent = " ";
|
||||
result += indent + " auto row = exdData->m_AetheryteDat.get_row( id );\n";
|
||||
result += indent + " auto row = exdData->m_" + exd + "Dat.get_row( id );\n";
|
||||
for( auto member : exhMem )
|
||||
{
|
||||
result += indent + indexToNameMap[count] + " = exdData->getField< " + indexToTypeMap[count] + " >( &row.at( " + std::to_string( count) + " ) );\n";
|
||||
result += indent + indexToNameMap[count] + " = exdData->getField< " + indexToTypeMap[count] + " >( row, " + std::to_string( count) + " );\n";
|
||||
count++;
|
||||
}
|
||||
result += " }\n";
|
||||
result += " };\n";
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -135,7 +172,7 @@ int main()
|
|||
g_typeMap[3] = "uint8_t";
|
||||
g_typeMap[4] = "int16_t";
|
||||
g_typeMap[5] = "uint16_t";
|
||||
g_typeMap[6] = "int32";
|
||||
g_typeMap[6] = "int32_t";
|
||||
g_typeMap[7] = "uint32_t";
|
||||
g_typeMap[9] = "float";
|
||||
g_typeMap[11] = "uint64_t";
|
||||
|
@ -162,6 +199,7 @@ int main()
|
|||
std::string getterDecl;
|
||||
std::string datAccCall;
|
||||
std::string getterDef;
|
||||
std::string constructorDecl;
|
||||
|
||||
// for all sheets in the json i guess....
|
||||
structDefs += generateStruct( "TerritoryType" );
|
||||
|
@ -169,7 +207,7 @@ int main()
|
|||
getterDecl += generateDirectGetters( "TerritoryType" );
|
||||
datAccCall += generateSetDatAccessCall( "TerritoryType" );
|
||||
getterDef += generateDirectGetterDef( "TerritoryType" );
|
||||
|
||||
constructorDecl += generateConstructorsDecl( "TerritoryType" );
|
||||
|
||||
std::string result;
|
||||
result = std::regex_replace( exdH, std::regex( "\\STRUCTS" ), structDefs );
|
||||
|
@ -178,8 +216,17 @@ int main()
|
|||
|
||||
g_log.info( result );
|
||||
|
||||
std::ofstream outH("ExdDataGenerated.h");
|
||||
outH << result;
|
||||
outH.close();
|
||||
|
||||
result = std::regex_replace( exdC, std::regex( "\\SETUPDATACCESS" ), datAccCall );
|
||||
result = std::regex_replace( result, std::regex( "\\DIRECTGETTERS" ), getterDef );
|
||||
result = std::regex_replace( result, std::regex( "\\CONSTRUCTORS" ), constructorDecl );
|
||||
|
||||
std::ofstream outC("ExdDataGenerated.cpp");
|
||||
outC << result;
|
||||
outC.close();
|
||||
|
||||
g_log.info( result );
|
||||
|
||||
|
|
33
src/tools/exd_struct_test/CMakeLists.txt
Normal file
33
src/tools/exd_struct_test/CMakeLists.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
cmake_policy(SET CMP0015 NEW)
|
||||
project(Tool_ExdStructTest)
|
||||
|
||||
set(SAPPHIRE_BOOST_VER 1.63.0)
|
||||
set(SAPPHIRE_BOOST_FOLDER_NAME boost_1_63_0)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/")
|
||||
|
||||
|
||||
file(GLOB SERVER_PUBLIC_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*")
|
||||
file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*")
|
||||
|
||||
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin/")
|
||||
add_executable(exd_struct_test ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES})
|
||||
|
||||
set_target_properties(exd_struct_test PROPERTIES
|
||||
CXX_STANDARD 14
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
CXX_EXTENSIONS ON
|
||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../bin/"
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../bin/"
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../bin/"
|
||||
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/../bin/"
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
target_link_libraries (exd_struct_test Common xivdat pthread mysqlclient dl z)
|
||||
else()
|
||||
target_link_libraries (exd_struct_test Common xivdat libmysql zlib1)
|
||||
endif()
|
||||
|
||||
target_link_libraries(exd_struct_test ${Boost_LIBRARIES} ${Boost_LIBRARIES})
|
||||
|
42
src/tools/exd_struct_test/ExdData.cpp.tmpl
Normal file
42
src/tools/exd_struct_test/ExdData.cpp.tmpl
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "ExdDataGenerated.h"
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
Core::Data::ExdDataGenerated::ExdDataGenerated()
|
||||
{
|
||||
}
|
||||
|
||||
Core::Data::ExdDataGenerated::~ExdDataGenerated()
|
||||
{
|
||||
}
|
||||
|
||||
xiv::exd::Exd Core::Data::ExdDataGenerated::setupDatAccess( const std::string& name, xiv::exd::Language lang )
|
||||
{
|
||||
auto& cat = m_exd_data->get_category( name );
|
||||
return static_cast< xiv::exd::Exd >( cat.get_data_ln( lang ) );
|
||||
};
|
||||
|
||||
bool Core::Data::ExdDataGenerated::init( const std::string& path )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_data = boost::make_shared< xiv::dat::GameData >( path );
|
||||
m_exd_data = boost::make_shared< xiv::exd::ExdData >( *m_data );
|
||||
|
||||
SETUPDATACCESS
|
||||
}
|
||||
catch( std::runtime_error )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// DIRECT GETTERS
|
||||
DIRECTGETTERS
|
||||
|
||||
|
||||
|
48
src/tools/exd_struct_test/ExdData.h.tmpl
Normal file
48
src/tools/exd_struct_test/ExdData.h.tmpl
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef _EXDDATA_H
|
||||
#define _EXDDATA_H
|
||||
|
||||
/* This file has been automatically generated.
|
||||
Changes will be lost upon regeneration.
|
||||
To change the content edit tools/exd_struct_gen */
|
||||
|
||||
#include <GameData.h>
|
||||
#include <File.h>
|
||||
#include <ExdData.h>
|
||||
#include <ExdCat.h>
|
||||
#include <Exd.h>
|
||||
|
||||
namespace Core {
|
||||
namespace Data {
|
||||
|
||||
STRUCTS
|
||||
|
||||
class ExdDataGenerated
|
||||
{
|
||||
public:
|
||||
ExdDataGenerated();
|
||||
~ExdDataGenerated();
|
||||
|
||||
bool init( const std::string& path );
|
||||
|
||||
xiv::exd::Exd setupDatAccess( const std::string& name, xiv::exd::Language lang );
|
||||
|
||||
template< class T >
|
||||
T getField( std::vector< xiv::exd::Field >& fields, uint32_t index )
|
||||
{
|
||||
return *boost::get< T >( &fields.at( index ) );
|
||||
}
|
||||
|
||||
boost::shared_ptr< xiv::dat::GameData > m_data;
|
||||
boost::shared_ptr< xiv::exd::ExdData > m_exd_data;
|
||||
|
||||
DATACCESS
|
||||
|
||||
DIRECTGETTERS
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
94
src/tools/exd_struct_test/ExdDataGenerated.cpp
Normal file
94
src/tools/exd_struct_test/ExdDataGenerated.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
#include "ExdDataGenerated.h"
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
|
||||
|
||||
Core::Data::TerritoryType::TerritoryType( uint32_t id, Core::Data::ExdDataGenerated* exdData )
|
||||
{
|
||||
auto row = exdData->m_TerritoryTypeDat.get_row( id );
|
||||
field0 = exdData->getField< std::string >( row, 0 );
|
||||
field1 = exdData->getField< std::string >( row, 1 );
|
||||
field2 = exdData->getField< uint8_t >( row, 2 );
|
||||
field3 = exdData->getField< uint16_t >( row, 3 );
|
||||
field4 = exdData->getField< uint16_t >( row, 4 );
|
||||
field5 = exdData->getField< uint16_t >( row, 5 );
|
||||
field6 = exdData->getField< uint16_t >( row, 6 );
|
||||
field7 = exdData->getField< uint8_t >( row, 7 );
|
||||
field8 = exdData->getField< uint8_t >( row, 8 );
|
||||
field9 = exdData->getField< uint16_t >( row, 9 );
|
||||
field10 = exdData->getField< uint8_t >( row, 10 );
|
||||
field11 = exdData->getField< uint8_t >( row, 11 );
|
||||
field12 = exdData->getField< bool >( row, 12 );
|
||||
field13 = exdData->getField< bool >( row, 13 );
|
||||
field14 = exdData->getField< bool >( row, 14 );
|
||||
field15 = exdData->getField< uint16_t >( row, 15 );
|
||||
field16 = exdData->getField< int32_t >( row, 16 );
|
||||
field17 = exdData->getField< int32_t >( row, 17 );
|
||||
field18 = exdData->getField< uint32_t >( row, 18 );
|
||||
field19 = exdData->getField< uint16_t >( row, 19 );
|
||||
field20 = exdData->getField< int32_t >( row, 20 );
|
||||
field21 = exdData->getField< int32_t >( row, 21 );
|
||||
field22 = exdData->getField< uint8_t >( row, 22 );
|
||||
field23 = exdData->getField< int8_t >( row, 23 );
|
||||
field24 = exdData->getField< bool >( row, 24 );
|
||||
field25 = exdData->getField< uint8_t >( row, 25 );
|
||||
field26 = exdData->getField< uint8_t >( row, 26 );
|
||||
field27 = exdData->getField< uint8_t >( row, 27 );
|
||||
field28 = exdData->getField< uint8_t >( row, 28 );
|
||||
}
|
||||
|
||||
|
||||
Core::Data::ExdDataGenerated::ExdDataGenerated()
|
||||
{
|
||||
}
|
||||
|
||||
Core::Data::ExdDataGenerated::~ExdDataGenerated()
|
||||
{
|
||||
}
|
||||
|
||||
xiv::exd::Exd Core::Data::ExdDataGenerated::setupDatAccess( const std::string& name, xiv::exd::Language lang )
|
||||
{
|
||||
auto& cat = m_exd_data->get_category( name );
|
||||
return static_cast< xiv::exd::Exd >( cat.get_data_ln( lang ) );
|
||||
};
|
||||
|
||||
bool Core::Data::ExdDataGenerated::init( const std::string& path )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_data = boost::make_shared< xiv::dat::GameData >( path );
|
||||
m_exd_data = boost::make_shared< xiv::exd::ExdData >( *m_data );
|
||||
|
||||
m_TerritoryTypeDat = setupDatAccess( "TerritoryType", xiv::exd::Language::none );
|
||||
}
|
||||
catch( std::runtime_error )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// DIRECT GETTERS
|
||||
boost::shared_ptr< Core::Data::TerritoryType >
|
||||
Core::Data::ExdDataGenerated::getTerritoryType( uint32_t TerritoryTypeId )
|
||||
{
|
||||
try
|
||||
{
|
||||
auto row = m_TerritoryTypeDat.get_row( TerritoryTypeId );
|
||||
auto info = boost::make_shared< TerritoryType >( TerritoryTypeId, this );
|
||||
return info;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
83
src/tools/exd_struct_test/ExdDataGenerated.h
Normal file
83
src/tools/exd_struct_test/ExdDataGenerated.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
#ifndef _EXDDATA_H
|
||||
#define _EXDDATA_H
|
||||
|
||||
/* This file has been automatically generated.
|
||||
Changes will be lost upon regeneration.
|
||||
To change the content edit tools/exd_struct_gen */
|
||||
|
||||
#include <GameData.h>
|
||||
#include <File.h>
|
||||
#include <ExdData.h>
|
||||
#include <ExdCat.h>
|
||||
#include <Exd.h>
|
||||
|
||||
namespace Core {
|
||||
namespace Data {
|
||||
class ExdDataGenerated;
|
||||
struct TerritoryType
|
||||
{
|
||||
std::string field0;
|
||||
std::string field1;
|
||||
uint8_t field2;
|
||||
uint16_t field3;
|
||||
uint16_t field4;
|
||||
uint16_t field5;
|
||||
uint16_t field6;
|
||||
uint8_t field7;
|
||||
uint8_t field8;
|
||||
uint16_t field9;
|
||||
uint8_t field10;
|
||||
uint8_t field11;
|
||||
bool field12;
|
||||
bool field13;
|
||||
bool field14;
|
||||
uint16_t field15;
|
||||
int32_t field16;
|
||||
int32_t field17;
|
||||
uint32_t field18;
|
||||
uint16_t field19;
|
||||
int32_t field20;
|
||||
int32_t field21;
|
||||
uint8_t field22;
|
||||
int8_t field23;
|
||||
bool field24;
|
||||
uint8_t field25;
|
||||
uint8_t field26;
|
||||
uint8_t field27;
|
||||
uint8_t field28;
|
||||
|
||||
TerritoryType( uint32_t id, Core::Data::ExdDataGenerated* exdData );
|
||||
};
|
||||
|
||||
|
||||
class ExdDataGenerated
|
||||
{
|
||||
public:
|
||||
ExdDataGenerated();
|
||||
~ExdDataGenerated();
|
||||
|
||||
bool init( const std::string& path );
|
||||
|
||||
xiv::exd::Exd setupDatAccess( const std::string& name, xiv::exd::Language lang );
|
||||
|
||||
template< class T >
|
||||
T getField( std::vector< xiv::exd::Field >& fields, uint32_t index )
|
||||
{
|
||||
return *boost::get< T >( &fields.at( index ) );
|
||||
}
|
||||
|
||||
boost::shared_ptr< xiv::dat::GameData > m_data;
|
||||
boost::shared_ptr< xiv::exd::ExdData > m_exd_data;
|
||||
|
||||
xiv::exd::Exd m_TerritoryTypeDat;
|
||||
|
||||
|
||||
boost::shared_ptr< TerritoryType > getTerritoryType( uint32_t TerritoryTypeId );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
50
src/tools/exd_struct_test/main.cpp
Normal file
50
src/tools/exd_struct_test/main.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
|
||||
#include <GameData.h>
|
||||
#include <File.h>
|
||||
#include <DatCat.h>
|
||||
#include <ExdData.h>
|
||||
#include <ExdCat.h>
|
||||
#include <Exd.h>
|
||||
#include <Exh.h>
|
||||
#include <iostream>
|
||||
#include <cctype>
|
||||
#include <set>
|
||||
#include "ExdDataGenerated.h"
|
||||
#include <src/servers/Server_Common/Logging/Logger.h>
|
||||
#include <boost/range/algorithm/remove_if.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
#include <regex>
|
||||
|
||||
|
||||
Core::Logger g_log;
|
||||
Core::Data::ExdDataGenerated g_exdData;
|
||||
|
||||
|
||||
const std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" );
|
||||
//const std::string datLocation( "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv" );
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
g_log.init();
|
||||
|
||||
g_log.info( "Setting up EXD data" );
|
||||
if( !g_exdData.init( datLocation ) )
|
||||
{
|
||||
g_log.fatal( "Error setting up EXD data " );
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto teri = g_exdData.getTerritoryType( 132 );
|
||||
|
||||
g_log.info( teri->field0 );
|
||||
g_log.info( teri->field1 );
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue