1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 06:27:45 +00:00

update quest_parser for c++ scripting

- fixed pcb_reader path
This commit is contained in:
Tahir Akhlaq 2017-12-16 13:13:49 +00:00
parent 05e48baf7b
commit 83f88102f9
3 changed files with 185 additions and 115 deletions

View file

@ -6,9 +6,10 @@ file(GLOB_RECURSE SCRIPT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
include_directories("${CMAKE_SOURCE_DIR}/src/servers/") include_directories("${CMAKE_SOURCE_DIR}/src/servers/")
include_directories("${CMAKE_SOURCE_DIR}/src/servers/Server_Zone/") include_directories("${CMAKE_SOURCE_DIR}/src/servers/Server_Zone/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
if(MSVC) if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yc${CMAKE_CURRENT_SOURCE_DIR}/ScriptObject.h /FI${CMAKE_CURRENT_SOURCE_DIR}/ScriptObject.h") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yc\"${CMAKE_CURRENT_SOURCE_DIR}/ScriptObject.h\" /FI\"${CMAKE_CURRENT_SOURCE_DIR}/ScriptObject.h\"")
endif() endif()
message( "exec: ${EXECUTABLE_OUTPUT_DIRECTORY}" ) message( "exec: ${EXECUTABLE_OUTPUT_DIRECTORY}" )

View file

@ -20,6 +20,8 @@
//#include <boost/algorithm/string.hpp> //#include <boost/algorithm/string.hpp>
#endif #endif
std::string gamePath( "C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv" );
using namespace std::chrono_literals; using namespace std::chrono_literals;
struct face struct face
@ -90,7 +92,7 @@ std::string zoneNameToPath( const std::string& name )
if( inFile.good() ) if( inFile.good() )
{ {
std::string line; std::string line;
std::regex re("(\\d+),\"(.*)\",\"(.*)\",.*"); std::regex re( "(\\d+),\"(.*)\",\"(.*)\",.*" );
while( std::getline( inFile, line ) ) while( std::getline( inFile, line ) )
{ {
std::smatch match; std::smatch match;
@ -103,18 +105,19 @@ std::string zoneNameToPath( const std::string& name )
} }
} }
} }
inFile.close();
} }
if( !path.empty() ) if( !path.empty() )
{ {
//path = path.substr( path.find_first_of( "/" ) + 1, path.size() - path.find_first_of( "/" )); //path = path.substr( path.find_first_of( "/" ) + 1, path.size() - path.find_first_of( "/" ));
//path = std::string( "ffxiv/" ) + path; //path = std::string( "ffxiv/" ) + path;
path = std::string( "bg" ) + path.substr( 0, path.find( "/level/" ) ); path = std::string( "bg/" ) + path.substr( 0, path.find( "/level/" ) );
std::cout << "[Info] " << "Found path for " << name << ": " << path << std::endl; std::cout << "[Info] " << "Found path for " << name << ": " << path << std::endl;
} }
else else
{ {
throw std::runtime_error( "Unable to find path for " + name + throw std::runtime_error( "Unable to find path for " + name +
".\n\tPlease open 0a0000.win32.index with FFXIV Explorer and extract territorytype.exh as CSV\n\tand copy territorytype.exh.csv into pcb_reader.exe directory" ); ".\n\tPlease double check spelling or open 0a0000.win32.index with FFXIV Explorer and extract territorytype.exh as CSV\n\tand copy territorytype.exh.csv into pcb_reader.exe directory if using standalone" );
} }
return path; return path;
} }
@ -142,7 +145,6 @@ int main( int argc, char* argv[] )
auto startTime = std::chrono::system_clock::now(); auto startTime = std::chrono::system_clock::now();
// todo: support expansions // todo: support expansions
std::string gamePath = "C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv";
std::string zoneName = "r1f1"; std::string zoneName = "r1f1";
if( argc > 1 ) if( argc > 1 )
@ -163,10 +165,9 @@ int main( int argc, char* argv[] )
std::vector< char > section; std::vector< char > section;
std::vector< char > section1; std::vector< char > section1;
#ifndef STANDALONE #ifndef STANDALONE
xiv::dat::GameData data1( gamePath ); xiv::dat::GameData data1( gamePath );
xiv::exd::ExdData eData( data1 ); xiv::exd::ExdData eData( data1 );
const xiv::dat::Cat& test = data1.get_category( "bg" ); const xiv::dat::Cat& test = data1.get_category( "bg" );
auto test_file = data1.get_file( bgLgbPath ); auto test_file = data1.get_file( bgLgbPath );
@ -174,12 +175,12 @@ int main( int argc, char* argv[] )
auto test_file1 = data1.get_file( listPcbPath ); auto test_file1 = data1.get_file( listPcbPath );
section1 = test_file1->access_data_sections().at( 0 ); section1 = test_file1->access_data_sections().at( 0 );
#else #else
{ {
readFileToBuffer( bgLgbPath, section ); readFileToBuffer( bgLgbPath, section );
readFileToBuffer( listPcbPath, section1 ); readFileToBuffer( listPcbPath, section1 );
} }
#endif #endif
int32_t list_offset = *( uint32_t* )&section[0x18]; int32_t list_offset = *( uint32_t* )&section[0x18];
int32_t size = *( uint32_t* )&section[4]; int32_t size = *( uint32_t* )&section[4];
@ -235,15 +236,15 @@ int main( int argc, char* argv[] )
{ {
char* dataSection = nullptr; char* dataSection = nullptr;
//std::cout << fileName << " "; //std::cout << fileName << " ";
#ifndef STANDALONE #ifndef STANDALONE
auto file = data1.get_file( fileName ); auto file = data1.get_file( fileName );
auto sections = file->get_data_sections(); auto sections = file->get_data_sections();
dataSection = &sections.at( 0 )[0]; dataSection = &sections.at( 0 )[0];
#else #else
std::vector< char > buf; std::vector< char > buf;
readFileToBuffer( fileName, buf ); readFileToBuffer( fileName, buf );
dataSection = &buf[0]; dataSection = &buf[0];
#endif #endif
//std::cout << sections.size() << "\n"; //std::cout << sections.size() << "\n";
uint32_t offset = 0; uint32_t offset = 0;
@ -287,15 +288,15 @@ int main( int argc, char* argv[] )
{ {
char* dataSection = nullptr; char* dataSection = nullptr;
//std::cout << fileName << " "; //std::cout << fileName << " ";
#ifndef STANDALONE #ifndef STANDALONE
auto file = data1.get_file( fileName ); auto file = data1.get_file( fileName );
auto sections = file->get_data_sections(); auto sections = file->get_data_sections();
dataSection = &sections.at( 0 )[0]; dataSection = &sections.at( 0 )[0];
#else #else
std::vector< char > buf; std::vector< char > buf;
readFileToBuffer( fileName, buf ); readFileToBuffer( fileName, buf );
dataSection = &buf[0]; dataSection = &buf[0];
#endif #endif
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;

View file

@ -9,30 +9,73 @@
#include <set> #include <set>
#include <src/servers/Server_Common/Exd/ExdData.h> #include <src/servers/Server_Common/Exd/ExdData.h>
#include <src/servers/Server_Common/Logging/Logger.h> #include <src/servers/Server_Common/Logging/Logger.h>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <locale>
#include <fstream> #include <fstream>
Core::Logger g_log; Core::Logger g_log;
Core::Data::ExdData g_exdData; Core::Data::ExdData g_exdData;
const std::string onTalkStr(
" void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId )\n"
" {\n"
" auto actor = Core::Event::mapEventActorToRealActor( actorId );\n"
" }\n\n"
);
void createScript( boost::shared_ptr< Core::Data::QuestInfo > pQuestData, std::set< std::string > additionalList ) const std::string onWithinRangeStr(
" void onWithinRange( uint32_t eventId, Entity::Player& player, uint64_t eRangeId, float x, float y, float z )\n"
" {\n"
" }\n\n"
);
const std::string onEmoteStr(
" void onEmote( uint32_t eventId, Entity::Player& player, uint64_t actorId, uint32_t emoteId )\n"
" {\n"
" }\n\n"
);
std::string titleCase( const std::string& str )
{
if( str.empty() )
return str;
std::string retStr(str);
std::transform( str.begin(), str.end(), retStr.begin(), ::tolower );
std::locale loc;
retStr[0] = std::toupper( str[0], loc );
for( size_t i = 1; i < str.size(); ++i )
{
if( str[i - 1] == ' ' || str[i - 1] == '_' || ( std::isdigit( str[i - 1], loc ) && !std::isdigit( str[i], loc ) ) )
retStr[i] = std::toupper( str[i], loc );
}
return retStr;
}
void createScript( boost::shared_ptr< Core::Data::QuestInfo >& pQuestData, std::set< std::string >& additionalList )
{ {
std::string header( std::string header(
"// This is an automatically generated chai script template\n" "// This is an automatically generated C++ script template\n"
"// Content needs to be added by hand to make it function\n" "// Content needs to be added by hand to make it function\n"
"// In order for this script to be loaded, change its extension to .chai\n" "// In order for this script to be loaded, change its extension to .cpp\n"
"// and move it to the correct folder in bin/scripts/chai/quest\n" "// and move it to the correct folder in <root>/scripts/native/\n"
"\n" "\n"
"#include <ScriptObject.h>\n\n"
); );
std::size_t splitPos = pQuestData->name_intern.find( "_" ); std::size_t splitPos( pQuestData->name_intern.find( "_" ) );
std::string className = pQuestData->name_intern.substr( 0, splitPos ); std::string className( pQuestData->name_intern.substr( 0, splitPos ) );
//className = "Quest" + className;
std::string sceneStr( " //////////////////////////////////////////////////////////////////////\n // Available Scenes in this quest, not necessarly all are used\n" );
std::string seqStr;
seqStr.reserve( 0xFFF );
seqStr += ( " // Steps in this quest ( 0 is before accepting, \n // 1 is first, 255 means ready for turning it in\n" );
std::string questVarStr( " // Quest vars / flags used\n" );
std::string sceneStr = " //////////////////////////////////////////////////////////////////////\n // Available Scenes in this quest, not necessarly all are used\n"; seqStr += " enum Sequence : uint8_t\n {\n";
std::string seqStr = " // Steps in this quest ( 0 is before accepting, \n // 1 is first, 255 means ready for turning it in\n";
std::string questVarStr = " // Quest vars / flags used\n";
for( auto &entry : additionalList ) for( auto &entry : additionalList )
{ {
if( entry.find( "OnScene" ) != std::string::npos ) if( entry.find( "OnScene" ) != std::string::npos )
@ -43,54 +86,64 @@ void createScript( boost::shared_ptr< Core::Data::QuestInfo > pQuestData, std::s
std::size_t numOff = sceneId.find_first_not_of( "0" ); std::size_t numOff = sceneId.find_first_not_of( "0" );
sceneId = numOff != std::string::npos ? sceneId.substr( numOff ) : "0"; sceneId = numOff != std::string::npos ? sceneId.substr( numOff ) : "0";
sceneStr += " def " + sceneName + "( player )\n"; sceneStr += std::string(
sceneStr += " {\n"; " void " +
sceneStr += " player.eventPlay( this.id, " + sceneId + ", NONE,\n"; sceneName +
sceneStr += " fun( player, eventId, param1, param2, param3 )\n"; "( Entity::Player& player )\n"
sceneStr += " {} );\n"; " {\n"
sceneStr += " }\n\n"; " player.eventPlay( this->getId(), " +
sceneId +
", 0,\n"
" [&]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )\n"
" {\n"
" });\n"
" }\n\n"
);
} }
else if( entry.find( "Flag" ) != std::string::npos || else if( entry.find( "Flag" ) != std::string::npos ||
entry.find( "QuestUI" ) != std::string::npos ) entry.find( "QuestUI" ) != std::string::npos )
{ {
questVarStr += " // " + entry + "\n"; questVarStr += " // " + entry + "\n";
} }
else if( entry.find( "SEQ" ) != std::string::npos ) else if( entry.find( "SEQ" ) != std::string::npos )
{ {
if( entry.find( "SEQ_FINISH" ) != std::string::npos ) if( entry.find( "SEQ_FINISH" ) != std::string::npos )
{ {
seqStr += " this.SEQ_FINISH = 255;\n"; seqStr += " SeqFinish = 255,\n";
} }
else if( entry.find( "SEQ_OFFER" ) != std::string::npos ) else if( entry.find( "SEQ_OFFER" ) != std::string::npos )
{ {
} }
else else
{ {
std::string seqName = entry; std::string seqName = titleCase( entry );
boost::replace_all( seqName, "_", "" );
std::string seqId = entry.substr( 4 ); std::string seqId = entry.substr( 4 );
seqStr += " this." + seqName + " = " + seqId + ";\n"; seqStr += " " + seqName + " = " + seqId + ",\n";
} }
} }
} }
std::string rewards = " // Quest rewards \n"; seqStr += " };\n";
rewards += ( pQuestData->reward_exp_factor != 0 ) ? " this.RewardExpFactor = " + std::to_string( pQuestData->reward_exp_factor ) + ";\n" : ""; std::string rewards;
rewards += ( pQuestData->reward_gil != 0 ) ? " this.RewardGil = " + std::to_string( pQuestData->reward_gil ) + ";\n" : ""; rewards.reserve( 0xFFF );
rewards += ( pQuestData->reward_emote != 0 ) ? " this.RewardEmote = " + std::to_string( pQuestData->reward_emote ) + ";\n" : ""; rewards += " // Quest rewards \n";
rewards += ( pQuestData->reward_action != 0 ) ? " this.RewardAction = " + std::to_string( pQuestData->reward_action ) + ";\n" : ""; rewards += ( pQuestData->reward_exp_factor != 0 ) ? " static constexpr auto RewardExpFactor = " + std::to_string( pQuestData->reward_exp_factor ) + ";\n" : "";
rewards += ( pQuestData->reward_action_general1 != 0 ) ? " this.RewardGeneralAction1 = " + std::to_string( pQuestData->reward_action_general1 ) + ";\n" : ""; rewards += ( pQuestData->reward_gil != 0 ) ? " static constexpr auto RewardGil = " + std::to_string( pQuestData->reward_gil ) + ";\n" : "";
rewards += ( pQuestData->reward_action_general2 != 0 ) ? " this.RewardGeneralAction2 = " + std::to_string( pQuestData->reward_action_general2 ) + ";\n" : ""; rewards += ( pQuestData->reward_emote != 0 ) ? " static constexpr auto RewardEmote = " + std::to_string( pQuestData->reward_emote ) + ";\n" : "";
rewards += ( pQuestData->reward_gc_seals != 0 ) ? " this.RewardGCSeals = " + std::to_string( pQuestData->reward_gc_seals ) + ";\n" : ""; rewards += ( pQuestData->reward_action != 0 ) ? " static constexpr auto RewardAction = " + std::to_string( pQuestData->reward_action ) + ";\n" : "";
rewards += ( pQuestData->reward_other != 0 ) ? " this.RewardOther = " + std::to_string( pQuestData->reward_other ) + ";\n" : ""; rewards += ( pQuestData->reward_action_general1 != 0 ) ? " static constexpr auto RewardGeneralAction1 = " + std::to_string( pQuestData->reward_action_general1 ) + ";\n" : "";
rewards += ( pQuestData->reward_reputation != 0 ) ? " this.RewardReputation = " + std::to_string( pQuestData->reward_reputation ) + ";\n" : ""; rewards += ( pQuestData->reward_action_general2 != 0 ) ? " static constexpr auto RewardGeneralAction2 = " + std::to_string( pQuestData->reward_action_general2 ) + ";\n" : "";
rewards += ( pQuestData->reward_tome_type != 0 ) ? " this.RewardTomeType = " + std::to_string( pQuestData->reward_tome_type ) + ";\n" : ""; rewards += ( pQuestData->reward_gc_seals != 0 ) ? " static constexpr auto RewardGCSeals = " + std::to_string( pQuestData->reward_gc_seals ) + ";\n" : "";
rewards += ( pQuestData->reward_tome_count != 0 ) ? " this.RewardTomeCount = " + std::to_string( pQuestData->reward_tome_count ) + ";\n" : ""; rewards += ( pQuestData->reward_other != 0 ) ? " static constexpr auto RewardOther = " + std::to_string( pQuestData->reward_other ) + ";\n" : "";
rewards += ( pQuestData->instanced_content_unlock != 0 ) ? " this.InstancedContentUnlock = " + std::to_string( pQuestData->instanced_content_unlock ) + ";\n" : ""; rewards += ( pQuestData->reward_reputation != 0 ) ? " static constexpr auto RewardReputation = " + std::to_string( pQuestData->reward_reputation ) + ";\n" : "";
rewards += ( pQuestData->reward_tome_type != 0 ) ? " static constexpr auto RewardTomeType = " + std::to_string( pQuestData->reward_tome_type ) + ";\n" : "";
rewards += ( pQuestData->reward_tome_count != 0 ) ? " static constexpr auto RewardTomeCount = " + std::to_string( pQuestData->reward_tome_count ) + ";\n" : "";
rewards += ( pQuestData->instanced_content_unlock != 0 ) ? " static constexpr auto InstancedContentUnlock = " + std::to_string( pQuestData->instanced_content_unlock ) + ";\n" : "";
if( pQuestData->reward_item.size() > 0 ) if( pQuestData->reward_item.size() > 0 )
{ {
rewards += " this.RewardItem = ["; rewards += " static constexpr auto RewardItem[] = { ";
for( size_t ca = 0; ca < pQuestData->reward_item.size(); ca++ ) for( size_t ca = 0; ca < pQuestData->reward_item.size(); ca++ )
{ {
rewards += std::to_string( pQuestData->reward_item.at( ca ) ); rewards += std::to_string( pQuestData->reward_item.at( ca ) );
@ -99,12 +152,12 @@ void createScript( boost::shared_ptr< Core::Data::QuestInfo > pQuestData, std::s
rewards += ", "; rewards += ", ";
} }
} }
rewards += "];\n"; rewards += " };\n";
} }
if( pQuestData->reward_item.size() > 0 ) if( pQuestData->reward_item.size() > 0 )
{ {
rewards += " this.RewardItemCount = ["; rewards += " static constexpr auto RewardItemCount[] = { ";
for( size_t ca = 0; ca < pQuestData->reward_item_count.size(); ca++ ) for( size_t ca = 0; ca < pQuestData->reward_item_count.size(); ca++ )
{ {
rewards += std::to_string( pQuestData->reward_item_count.at( ca ) ); rewards += std::to_string( pQuestData->reward_item_count.at( ca ) );
@ -113,12 +166,12 @@ void createScript( boost::shared_ptr< Core::Data::QuestInfo > pQuestData, std::s
rewards += ", "; rewards += ", ";
} }
} }
rewards += "];\n"; rewards += " };\n";
} }
if( pQuestData->reward_item_optional.size() > 0 ) if( pQuestData->reward_item_optional.size() > 0 )
{ {
rewards += " this.RewardItemOptional = ["; rewards += " static constexpr auto RewardItemOptional[] = { ";
for( size_t ca = 0; ca < pQuestData->reward_item_optional.size(); ca++ ) for( size_t ca = 0; ca < pQuestData->reward_item_optional.size(); ca++ )
{ {
rewards += std::to_string( pQuestData->reward_item_optional.at( ca ) ); rewards += std::to_string( pQuestData->reward_item_optional.at( ca ) );
@ -127,12 +180,12 @@ void createScript( boost::shared_ptr< Core::Data::QuestInfo > pQuestData, std::s
rewards += ", "; rewards += ", ";
} }
} }
rewards += "];\n"; rewards += " };\n";
} }
if( pQuestData->reward_item_optional_count.size() > 0 ) if( pQuestData->reward_item_optional_count.size() > 0 )
{ {
rewards += " this.RewardItemOptionalCount = ["; rewards += " static constexpr auto RewardItemOptionalCount[] = { ";
for( size_t ca = 0; ca < pQuestData->reward_item_optional_count.size(); ca++ ) for( size_t ca = 0; ca < pQuestData->reward_item_optional_count.size(); ca++ )
{ {
rewards += std::to_string( pQuestData->reward_item_optional_count.at( ca ) ); rewards += std::to_string( pQuestData->reward_item_optional_count.at( ca ) );
@ -141,7 +194,7 @@ void createScript( boost::shared_ptr< Core::Data::QuestInfo > pQuestData, std::s
rewards += ", "; rewards += ", ";
} }
} }
rewards += "];\n"; rewards += " };\n";
} }
bool hasERange = false; bool hasERange = false;
@ -149,29 +202,30 @@ void createScript( boost::shared_ptr< Core::Data::QuestInfo > pQuestData, std::s
bool hasEnemies = false; bool hasEnemies = false;
std::vector< uint32_t > enemy_ids; std::vector< uint32_t > enemy_ids;
std::vector< std::string > script_entities; std::vector< std::string > script_entities;
std::string sentities = " // Entities found in the script data of the quest\n"; std::string sentities = " // Entities found in the script data of the quest\n";
for( size_t ca = 0; ca < pQuestData->script_entity.size(); ca ++ ) for( size_t ca = 0; ca < pQuestData->script_entity.size(); ca ++ )
{ {
if( ( pQuestData->script_entity.at( ca ).find( "HOWTO" ) != std::string::npos ) || ( pQuestData->script_entity.at( ca ).find( "HOW_TO" ) != std::string::npos ) ) if( ( pQuestData->script_entity.at( ca ).find( "HOWTO" ) != std::string::npos ) || ( pQuestData->script_entity.at( ca ).find( "HOW_TO" ) != std::string::npos ) )
continue; continue;
if( (pQuestData->script_entity.at( ca ).find( "EMOTENO" ) != std::string::npos ) || (pQuestData->script_entity.at( ca ).find( "EMOTEOK" ) != std::string::npos ) ) if( ( pQuestData->script_entity.at( ca ).find( "EMOTENO" ) != std::string::npos ) || ( pQuestData->script_entity.at( ca ).find( "EMOTEOK" ) != std::string::npos ) )
hasEmote = true; hasEmote = true;
if(pQuestData->script_entity.at(ca).find("ENEMY") != std::string::npos) if( pQuestData->script_entity.at( ca ).find( "ENEMY" ) != std::string::npos )
{ {
hasEnemies = true; hasEnemies = true;
enemy_ids.push_back(pQuestData->script_value.at(ca)); enemy_ids.push_back( pQuestData->script_value.at( ca ) );
} }
script_entities.push_back( pQuestData->script_entity.at( ca ) + " = " + std::to_string( pQuestData->script_value.at( ca ) ) ); script_entities.push_back( pQuestData->script_entity.at( ca ) + " = " + std::to_string( pQuestData->script_value.at( ca ) ) );
} }
std::sort( script_entities.begin(), script_entities.end() ); std::sort( script_entities.begin(), script_entities.end() );
for( auto& entity : script_entities ) for( auto& entity : script_entities )
{ {
sentities += " this." + entity + ";\n"; auto name = titleCase( entity );
boost::replace_all( name, "_", "" );
sentities += " static constexpr auto " + name + ";\n";
} }
std::string additional = "// Quest Script: " + pQuestData->name_intern + "\n"; std::string additional = "// Quest Script: " + pQuestData->name_intern + "\n";
@ -180,78 +234,81 @@ void createScript( boost::shared_ptr< Core::Data::QuestInfo > pQuestData, std::s
additional += "// Start NPC: " + std::to_string( pQuestData->enpc_resident_start ) + "\n"; additional += "// Start NPC: " + std::to_string( pQuestData->enpc_resident_start ) + "\n";
additional += "// End NPC: " + std::to_string( pQuestData->enpc_resident_end ) + "\n\n"; additional += "// End NPC: " + std::to_string( pQuestData->enpc_resident_end ) + "\n\n";
std::string scriptEntry = " //////////////////////////////////////////////////////////////////////\n"; std::string scriptEntry;
scriptEntry += " // Event Handlers\n"; scriptEntry.reserve(0xFFFF);
scriptEntry += " def onTalk( eventId, player, actorId )\n"; scriptEntry += " //////////////////////////////////////////////////////////////////////\n // Event Handlers\n";
scriptEntry += " {\n";
scriptEntry += " var actor = mapActor( actorId );\n"; scriptEntry += onTalkStr;
scriptEntry += " }\n\n";
if( hasERange ) if( hasERange )
{ {
scriptEntry += " def onWithinRange( eventId, player, eRangeId, x, y, z )\n"; scriptEntry += onWithinRangeStr;
scriptEntry += " {\n";
scriptEntry += " }\n\n";
} }
if( hasEmote ) if( hasEmote )
{ {
scriptEntry += " def onEmote( eventId, player, actorId, emoteId )\n"; scriptEntry += onEmoteStr;
scriptEntry += " {\n";
scriptEntry += " }\n\n";
} }
for( auto enemy : enemy_ids ) for( auto enemy : enemy_ids )
{ {
scriptEntry += " def onMobKill_" + std::to_string(enemy) + "( player )\n"; scriptEntry += std::string(
scriptEntry += " {\n"; " void onMobKill_" + std::to_string( enemy ) + "( Entity::Player& player )\n"
scriptEntry += " }\n\n"; " {\n"
" }\n\n"
);
} }
std::string constructor; std::string constructor;
constructor += " def " + className + "Def()\n"; constructor += std::string(
constructor += " {\n"; " private:\n"
constructor += " // Basic quest information \n"; " // Basic quest information \n");
constructor += " this.name = \"" + pQuestData->name + "\";\n";
constructor += " this.id = " + std::to_string( pQuestData->id ) + ";\n\n";
constructor += questVarStr + "\n"; constructor += questVarStr + "\n";
constructor += seqStr + "\n"; constructor += seqStr + "\n";
constructor += rewards + "\n"; constructor += rewards + "\n";
constructor += sentities + "\n"; constructor += sentities + "\n";
constructor += " }\n"; constructor += " public:\n";
constructor += " " + className + "() : EventScript" + "( \"" + pQuestData->name + "\", " + std::to_string( pQuestData->id ) + " ){}; \n";
constructor += " ~" + className + "(){}; \n";
std::string classString( std::string classString(
"class " + className + "Def \n" "class " + className + " : public EventScript\n"
"{\n" "{\n" +
+ constructor + constructor +
"\n" "\n" +
+ sceneStr + sceneStr +
scriptEntry + scriptEntry +
"};\n\n" "};\n\n"
); );
std::string objName = className; std::string initObj( "EXPORT_SCRIPTOBJECT( " + className + " );" );
std::string initObj = "GLOBAL " + objName + " = " + className + "Def();\n";
std::ofstream outputFile; std::ofstream outputFile;
outputFile.open( "generated/" + className + ".chai_generated" );
outputFile.open( "generated/" + className + ".cpp_generated" );
outputFile << header << additional << classString << initObj; outputFile << header << additional << classString << initObj;
outputFile.close(); outputFile.close();
} }
int main() int main( int argc, char** argv )
{ {
g_log.init(); g_log.init();
bool unluac = false;
// std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" ); // std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" );
std::string datLocation( "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv" ); std::string datLocation( "C:/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn/game/sqpack/ffxiv" );
if ( argc > 1 )
datLocation = std::string( argv[1] );
if ( argc > 2 )
unluac = (bool)atoi( argv[2] );
g_log.info( "Setting up EXD data" ); g_log.info( "Setting up EXD data" );
if( !g_exdData.init( datLocation ) ) if( !g_exdData.init( datLocation ) )
{ {
std::cout << datLocation << "\n";
g_log.fatal( "Error setting up EXD data " ); g_log.fatal( "Error setting up EXD data " );
std::cout << "Usage: quest_parser \"path/to/ffxiv/game/sqpack\" <1/0 unluac export toggle>\n";
return 0; return 0;
} }
@ -261,9 +318,14 @@ int main()
auto QuestDat = g_exdData.setupDatAccess( "Quest", xiv::exd::Language::en ); auto QuestDat = g_exdData.setupDatAccess( "Quest", xiv::exd::Language::en );
auto rows = QuestDat.get_rows(); auto rows = QuestDat.get_rows();
for( auto row : rows ) if ( !boost::filesystem::exists( "./generated" ) )
boost::filesystem::create_directory( "./generated" );
std::cout << "Export in progress";
uint32_t updateInterval = rows.size() / 20;
uint32_t i = 0;
for( const auto& row : rows )
{ {
auto questInfo = g_exdData.getQuestInfo( row.first ); auto questInfo = g_exdData.getQuestInfo( row.first );
if( questInfo->name.empty() || questInfo->name_intern.empty() ) if( questInfo->name.empty() || questInfo->name_intern.empty() )
@ -299,23 +361,26 @@ int main()
uint32_t offset = 0; uint32_t offset = 0;
std::ofstream outputFile1; std::ofstream outputFile1;
outputFile1.open("generated/" + questInfo->name_intern + ".luab", std::ios::binary); outputFile1.open( "generated/" + questInfo->name_intern + ".luab", std::ios::binary );
outputFile1.write(&section[0], section.size()); outputFile1.write( &section[0], section.size() );
outputFile1.close(); outputFile1.close();
std::string command= std::string("java -jar unluac_2015_06_13.jar ") + "generated/" + questInfo->name_intern + ".luab" + ">> " + "generated/" + questInfo->name_intern + ".lua"; if( unluac )
if ( system( command.c_str() ) == -1 )
{ {
g_log.error( "Error executing java command:\n" + command + "\nerrno: " + std::strerror( errno ) ); std::string command = std::string( "java -jar unluac_2015_06_13.jar " ) + "generated/" + questInfo->name_intern + ".luab" + ">> " + "generated/" + questInfo->name_intern + ".lua";
return errno; if ( system( command.c_str() ) == -1 )
{
g_log.error( "Error executing java command:\n" + command + "\nerrno: " + std::strerror( errno ) );
return errno;
}
} }
for( ; ; ) for( ; ; )
{ {
std::string entry( &section[offset] ); std::string entry( &section[offset] );
offset += entry.size() + 1; offset += entry.size() + 1;
if( entry.size() > 3 if( entry.size() > 3
&& entry.find_first_not_of( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_" ) == std::string::npos ) && entry.find_first_not_of( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-" ) == std::string::npos )
{ {
if( entry.find( "SEQ" ) != std::string::npos if( entry.find( "SEQ" ) != std::string::npos
|| entry.find( "QuestUI" ) != std::string::npos || entry.find( "QuestUI" ) != std::string::npos
@ -333,8 +398,11 @@ int main()
createScript( questInfo, stringList ); createScript( questInfo, stringList );
++i;
if( i % updateInterval == 0 )
std::cout << ".";
//break; //break;
} }
std::cout << "\nDone!";
return 0; return 0;
} }