2017-10-11 14:27:17 +02:00
|
|
|
|
|
|
|
#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 <src/servers/Server_Common/Exd/ExdData.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>
|
2017-10-12 15:47:21 +02:00
|
|
|
#include <boost/property_tree/json_parser.hpp>
|
|
|
|
#include <boost/property_tree/xml_parser.hpp>
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2017-10-11 14:27:17 +02:00
|
|
|
|
|
|
|
#include <fstream>
|
2017-10-12 00:07:41 +02:00
|
|
|
#include <streambuf>
|
|
|
|
#include <regex>
|
2017-10-11 14:27:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
Core::Logger g_log;
|
|
|
|
Core::Data::ExdData g_exdData;
|
2017-10-12 15:47:21 +02:00
|
|
|
bool skipUnmapped = true;
|
2017-10-11 14:27:17 +02:00
|
|
|
|
2017-10-13 14:45:14 +02:00
|
|
|
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" );
|
2017-10-11 15:03:08 +02:00
|
|
|
std::map< uint8_t, std::string > g_typeMap;
|
|
|
|
|
2017-10-11 14:27:17 +02:00
|
|
|
|
2017-10-12 00:07:41 +02:00
|
|
|
std::string generateDatAccessDecl( const std::string &exd )
|
2017-10-11 14:27:17 +02:00
|
|
|
{
|
2017-10-12 00:07:41 +02:00
|
|
|
return " xiv::exd::Exd m_" + exd + "Dat;\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string generateDirectGetters( const std::string& exd )
|
|
|
|
{
|
|
|
|
return " boost::shared_ptr< " + exd + " > get" + exd + "( uint32_t " + exd + "Id );";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string generateSetDatAccessCall( const std::string &exd )
|
|
|
|
{
|
|
|
|
auto& cat = g_exdData.m_exd_data->get_category( exd );
|
|
|
|
auto exh = cat.get_header();
|
|
|
|
|
|
|
|
std::string lang = "xiv::exd::Language::none";
|
|
|
|
auto langs = exh.get_languages();
|
|
|
|
if( langs.size() > 1 )
|
|
|
|
lang = "xiv::exd::Language::en";
|
2017-10-11 14:27:17 +02:00
|
|
|
|
2017-10-13 14:45:14 +02:00
|
|
|
return " m_" + exd + "Dat = setupDatAccess( \"" + exd + "\", " + lang + " );\n";
|
2017-10-12 00:07:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string generateDirectGetterDef( const std::string& exd )
|
|
|
|
{
|
|
|
|
std::string result = "";
|
|
|
|
result =
|
|
|
|
"boost::shared_ptr< Core::Data::" + exd + " >\n"
|
2017-10-12 09:02:28 +02:00
|
|
|
" Core::Data::ExdDataGenerated::get" + exd + "( uint32_t " + exd + "Id )\n"
|
2017-10-12 00:07:41 +02:00
|
|
|
"{\n"
|
|
|
|
" try\n"
|
|
|
|
" {\n"
|
|
|
|
" auto row = m_" + exd + "Dat.get_row( " + exd + "Id );\n"
|
|
|
|
" auto info = boost::make_shared< " + exd + " >( " + exd + "Id, this );\n"
|
|
|
|
" return info;\n"
|
|
|
|
" }\n"
|
|
|
|
" catch( ... )\n"
|
|
|
|
" {\n"
|
|
|
|
" return nullptr;\n"
|
|
|
|
" }\n"
|
|
|
|
" return nullptr;\n"
|
|
|
|
"}\n";
|
|
|
|
return result;
|
|
|
|
}
|
2017-10-12 15:47:21 +02:00
|
|
|
std::map< uint32_t, std::string > indexToNameMap;
|
|
|
|
std::map< uint32_t, std::string > indexToTypeMap;
|
2017-10-12 23:40:45 +02:00
|
|
|
std::map< uint32_t, std::string > indexToTarget;
|
2017-10-13 14:45:14 +02:00
|
|
|
std::map< uint32_t, bool > indexIsArrayMap;
|
|
|
|
std::map< uint32_t, uint32_t > indexCountMap;
|
2017-10-12 23:40:45 +02:00
|
|
|
|
|
|
|
std::map< std::string, std::string > nameTaken;
|
2017-10-12 00:07:41 +02:00
|
|
|
|
|
|
|
std::string generateStruct( const std::string &exd )
|
|
|
|
{
|
2017-10-11 14:27:17 +02:00
|
|
|
auto& cat = g_exdData.m_exd_data->get_category( exd );
|
|
|
|
auto exh = cat.get_header();
|
|
|
|
auto exhMem = exh.get_exh_members();
|
2017-10-12 00:07:41 +02:00
|
|
|
|
2017-10-11 15:03:08 +02:00
|
|
|
int count = 0;
|
|
|
|
|
2017-10-12 15:47:21 +02:00
|
|
|
using boost::property_tree::ptree;
|
|
|
|
ptree m_propTree;
|
|
|
|
boost::property_tree::read_json( "ex.json", m_propTree );
|
|
|
|
|
|
|
|
BOOST_FOREACH( boost::property_tree::ptree::value_type &sheet, m_propTree.get_child( "sheets" ) )
|
|
|
|
{
|
|
|
|
std::string name = sheet.second.get< std::string >( "sheet" );
|
|
|
|
if( name != exd )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BOOST_FOREACH( boost::property_tree::ptree::value_type &show, sheet.second.get_child( "definitions" ) )
|
|
|
|
{
|
|
|
|
uint32_t index;
|
2017-10-12 23:40:45 +02:00
|
|
|
std::string converterTarget = "";
|
2017-10-13 14:45:14 +02:00
|
|
|
bool isRepeat = false;
|
|
|
|
int num = 0;
|
2017-10-12 15:47:21 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
index = show.second.get< uint32_t >("index");
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
index = 0;
|
|
|
|
}
|
2017-10-12 23:40:45 +02:00
|
|
|
try
|
|
|
|
{
|
2017-10-12 15:47:21 +02:00
|
|
|
std::string fieldName = show.second.get< std::string >( "name" );
|
|
|
|
indexToNameMap[index] = fieldName;
|
|
|
|
}
|
2017-10-12 23:40:45 +02:00
|
|
|
catch( ... ) {}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
converterTarget = show.second.get< std::string >( "converter.target" );
|
|
|
|
if( nameTaken.find( converterTarget ) != nameTaken.end() )
|
|
|
|
indexToTarget[index] = converterTarget;
|
|
|
|
}
|
|
|
|
catch( ... ) {}
|
2017-10-13 14:45:14 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
show.second.get< std::string >( "type" );
|
|
|
|
num = show.second.get< uint8_t >( "count" );
|
|
|
|
isRepeat = true;
|
|
|
|
indexIsArrayMap[index] = true;
|
|
|
|
indexCountMap[index] = num;
|
|
|
|
std::string fName = show.second.get< std::string >( "definition.name" );
|
|
|
|
indexToNameMap[index] = fName;
|
|
|
|
}
|
|
|
|
catch( ... ) {}
|
2017-10-12 23:40:45 +02:00
|
|
|
|
2017-10-12 15:47:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string result = "struct " + exd +"\n{\n";
|
|
|
|
|
2017-10-11 14:27:17 +02:00
|
|
|
|
|
|
|
for( auto member : exhMem )
|
|
|
|
{
|
2017-10-11 15:03:08 +02:00
|
|
|
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
|
2017-10-12 00:07:41 +02:00
|
|
|
type = "bool";
|
|
|
|
|
2017-10-12 15:47:21 +02:00
|
|
|
std::string fieldName = "field" + std::to_string( count );
|
|
|
|
if( indexToNameMap.find( count ) == indexToNameMap.end() )
|
|
|
|
{
|
|
|
|
if( skipUnmapped )
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
indexToNameMap[count] = fieldName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fieldName = indexToNameMap[count];
|
|
|
|
}
|
|
|
|
fieldName[0] = std::tolower( fieldName[0] );
|
2017-10-12 18:54:19 +02:00
|
|
|
fieldName.erase( boost::remove_if( fieldName, boost::is_any_of(",-':![](){}<>% \x02\x1f\x01\x03") ), fieldName.end() );
|
2017-10-12 00:07:41 +02:00
|
|
|
indexToNameMap[count] = fieldName;
|
|
|
|
indexToTypeMap[count] = type;
|
2017-10-12 23:40:45 +02:00
|
|
|
if( indexToTarget.find( count ) != indexToTarget.end() )
|
|
|
|
result += " boost::shared_ptr< " + indexToTarget[count] + "> " + fieldName + ";\n";
|
|
|
|
else
|
2017-10-13 14:45:14 +02:00
|
|
|
{
|
|
|
|
if( indexIsArrayMap.find( count ) != indexIsArrayMap.end() )
|
|
|
|
{
|
|
|
|
type = "std::vector< " + type + " >";
|
|
|
|
}
|
2017-10-12 23:40:45 +02:00
|
|
|
result += " " + type + " " + fieldName + ";\n";
|
2017-10-13 14:45:14 +02:00
|
|
|
|
|
|
|
}
|
2017-10-11 15:03:08 +02:00
|
|
|
|
|
|
|
count++;
|
2017-10-11 14:27:17 +02:00
|
|
|
}
|
2017-10-12 00:07:41 +02:00
|
|
|
|
2017-10-12 18:54:19 +02:00
|
|
|
result += "\n " + exd + "( uint32_t row_id, Core::Data::ExdDataGenerated* exdData );\n";
|
2017-10-12 15:47:21 +02:00
|
|
|
result += "};\n\n";
|
2017-10-12 09:02:28 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
2017-10-12 18:54:19 +02:00
|
|
|
result += "\n Core::Data::" + exd + "::" + exd + "( uint32_t row_id, Core::Data::ExdDataGenerated* exdData )\n";
|
2017-10-12 00:07:41 +02:00
|
|
|
result += " {\n";
|
|
|
|
std::string indent = " ";
|
2017-10-12 18:54:19 +02:00
|
|
|
result += indent + "auto row = exdData->m_" + exd + "Dat.get_row( row_id );\n";
|
2017-10-12 00:07:41 +02:00
|
|
|
for( auto member : exhMem )
|
2017-10-12 15:47:21 +02:00
|
|
|
{
|
|
|
|
if( indexToNameMap.find( count ) == indexToNameMap.end() )
|
|
|
|
{ count++; continue; }
|
2017-10-12 23:40:45 +02:00
|
|
|
if( indexToTarget.find( count ) != indexToTarget.end() )
|
|
|
|
result += indent + indexToNameMap[count] + " = boost::make_shared< " + indexToTarget[count] + ">( exdData->getField< " +
|
|
|
|
indexToTypeMap[count] + " >( row, " + std::to_string( count ) + " ), exdData );\n";
|
|
|
|
else
|
2017-10-13 14:45:14 +02:00
|
|
|
{
|
|
|
|
if( indexIsArrayMap.find( count ) == indexIsArrayMap.end() )
|
|
|
|
result += indent + indexToNameMap[count] + " = exdData->getField< " + indexToTypeMap[count] + " >( row, " + std::to_string( count ) + " );\n";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t amount = indexCountMap[count];
|
|
|
|
for( int i = 0; i < amount; i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
result += indent + indexToNameMap[count] + ".push_back( exdData->getField< " + indexToTypeMap[count] + " >( row, " + std::to_string( count + i ) + " ) );\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2017-10-12 00:07:41 +02:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
result += " }\n";
|
2017-10-12 09:02:28 +02:00
|
|
|
|
2017-10-12 15:47:21 +02:00
|
|
|
indexToNameMap.clear();
|
|
|
|
indexToTypeMap.clear();
|
2017-10-12 23:40:45 +02:00
|
|
|
indexToTarget.clear();
|
2017-10-13 14:45:14 +02:00
|
|
|
indexIsArrayMap.clear();
|
|
|
|
indexCountMap.clear();
|
2017-10-11 15:03:08 +02:00
|
|
|
return result;
|
2017-10-11 14:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2017-10-12 00:07:41 +02:00
|
|
|
g_typeMap[0] = "std::string";
|
2017-10-11 15:03:08 +02:00
|
|
|
g_typeMap[1] = "bool";
|
|
|
|
g_typeMap[2] = "int8_t";
|
|
|
|
g_typeMap[3] = "uint8_t";
|
|
|
|
g_typeMap[4] = "int16_t";
|
|
|
|
g_typeMap[5] = "uint16_t";
|
2017-10-12 09:02:28 +02:00
|
|
|
g_typeMap[6] = "int32_t";
|
2017-10-11 15:03:08 +02:00
|
|
|
g_typeMap[7] = "uint32_t";
|
|
|
|
g_typeMap[9] = "float";
|
|
|
|
g_typeMap[11] = "uint64_t";
|
2017-10-11 14:27:17 +02:00
|
|
|
|
2017-10-12 00:07:41 +02:00
|
|
|
std::ifstream t( "ExdData.h.tmpl" );
|
|
|
|
std::string exdH( ( std::istreambuf_iterator<char>( t ) ),
|
|
|
|
std::istreambuf_iterator<char>() );
|
2017-10-11 14:27:17 +02:00
|
|
|
|
2017-10-12 00:07:41 +02:00
|
|
|
std::ifstream s( "ExdData.cpp.tmpl" );
|
|
|
|
std::string exdC( ( std::istreambuf_iterator<char>( s ) ),
|
|
|
|
std::istreambuf_iterator<char>() );
|
|
|
|
|
2017-10-12 15:47:21 +02:00
|
|
|
|
|
|
|
using boost::property_tree::ptree;
|
|
|
|
ptree m_propTree;
|
|
|
|
boost::property_tree::read_json( "ex.json", m_propTree );
|
2017-10-12 00:07:41 +02:00
|
|
|
g_log.init();
|
2017-10-11 14:27:17 +02:00
|
|
|
|
|
|
|
g_log.info( "Setting up EXD data" );
|
2017-10-12 00:07:41 +02:00
|
|
|
if( !g_exdData.init( datLocation ) )
|
2017-10-11 14:27:17 +02:00
|
|
|
{
|
|
|
|
g_log.fatal( "Error setting up EXD data " );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-12 00:07:41 +02:00
|
|
|
std::string structDefs;
|
|
|
|
std::string dataDecl;
|
|
|
|
std::string getterDecl;
|
|
|
|
std::string datAccCall;
|
|
|
|
std::string getterDef;
|
2017-10-12 09:02:28 +02:00
|
|
|
std::string constructorDecl;
|
2017-10-12 23:40:45 +02:00
|
|
|
std::string forwards;
|
2017-10-12 00:07:41 +02:00
|
|
|
|
2017-10-12 23:40:45 +02:00
|
|
|
//BOOST_FOREACH( boost::property_tree::ptree::value_type &sheet, m_propTree.get_child( "sheets" ) )
|
|
|
|
//{
|
|
|
|
//std::string name = sheet.second.get< std::string >( "sheet" );
|
|
|
|
//nameTaken[name] = "1";
|
|
|
|
//}
|
2017-10-12 15:47:21 +02:00
|
|
|
|
2017-10-12 23:40:45 +02:00
|
|
|
BOOST_FOREACH( boost::property_tree::ptree::value_type &sheet, m_propTree.get_child( "sheets" ) )
|
2017-10-12 15:47:21 +02:00
|
|
|
{
|
2017-10-12 23:40:45 +02:00
|
|
|
std::string name = sheet.second.get< std::string >( "sheet" );
|
2017-10-12 15:47:21 +02:00
|
|
|
|
2017-10-12 23:40:45 +02:00
|
|
|
forwards += "struct " + name +";\n";
|
2017-10-12 15:47:21 +02:00
|
|
|
structDefs += generateStruct( name );
|
|
|
|
dataDecl += generateDatAccessDecl( name );
|
|
|
|
getterDecl += generateDirectGetters( name );
|
|
|
|
datAccCall += generateSetDatAccessCall( name );
|
|
|
|
getterDef += generateDirectGetterDef( name );
|
|
|
|
constructorDecl += generateConstructorsDecl( name );
|
|
|
|
}
|
|
|
|
|
2017-10-12 00:07:41 +02:00
|
|
|
// for all sheets in the json i guess....
|
|
|
|
|
|
|
|
std::string result;
|
2017-10-12 23:40:45 +02:00
|
|
|
result = std::regex_replace( exdH, std::regex( "\\FORWARDS" ), forwards );
|
|
|
|
result = std::regex_replace( result, std::regex( "\\STRUCTS" ), structDefs );
|
2017-10-12 00:07:41 +02:00
|
|
|
result = std::regex_replace( result, std::regex( "\\DATACCESS" ), dataDecl );
|
|
|
|
result = std::regex_replace( result, std::regex( "\\DIRECTGETTERS" ), getterDecl );
|
2017-10-11 14:27:17 +02:00
|
|
|
|
2017-10-12 15:47:21 +02:00
|
|
|
// g_log.info( result );
|
2017-10-12 00:07:41 +02:00
|
|
|
|
2017-10-12 09:02:28 +02:00
|
|
|
std::ofstream outH("ExdDataGenerated.h");
|
|
|
|
outH << result;
|
|
|
|
outH.close();
|
|
|
|
|
2017-10-12 00:07:41 +02:00
|
|
|
result = std::regex_replace( exdC, std::regex( "\\SETUPDATACCESS" ), datAccCall );
|
|
|
|
result = std::regex_replace( result, std::regex( "\\DIRECTGETTERS" ), getterDef );
|
2017-10-12 09:02:28 +02:00
|
|
|
result = std::regex_replace( result, std::regex( "\\CONSTRUCTORS" ), constructorDecl );
|
|
|
|
|
|
|
|
std::ofstream outC("ExdDataGenerated.cpp");
|
|
|
|
outC << result;
|
|
|
|
outC.close();
|
2017-10-12 00:07:41 +02:00
|
|
|
|
2017-10-12 15:47:21 +02:00
|
|
|
// g_log.info( result );
|
2017-10-12 00:07:41 +02:00
|
|
|
|
2017-10-11 14:27:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|