diff --git a/.gitignore b/.gitignore index 456609e8..c931620b 100644 --- a/.gitignore +++ b/.gitignore @@ -111,3 +111,6 @@ src/common/Version\.cpp # travis-ci build mtime cache .mtime_cache + +# generated script loader files +scripts/native/*/ScriptLoader.cpp \ No newline at end of file diff --git a/scripts/native/CMakeLists.txt b/scripts/native/CMakeLists.txt index c09d37a8..aeaa0094 100644 --- a/scripts/native/CMakeLists.txt +++ b/scripts/native/CMakeLists.txt @@ -2,47 +2,66 @@ cmake_minimum_required(VERSION 3.0) project(Sapphire_Script) file(GLOB SCRIPT_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h") -file(GLOB_RECURSE SCRIPT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") include_directories("${CMAKE_SOURCE_DIR}/src/servers/") include_directories("${CMAKE_SOURCE_DIR}/src/servers/sapphire_zone/") include_directories("${CMAKE_CURRENT_SOURCE_DIR}") -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yc\"${CMAKE_CURRENT_SOURCE_DIR}/ScriptObject.h\" /FI\"${CMAKE_CURRENT_SOURCE_DIR}/ScriptObject.h\"") -endif() +message("exec: ${EXECUTABLE_OUTPUT_DIRECTORY}") -message( "exec: ${EXECUTABLE_OUTPUT_DIRECTORY}" ) +set(SCRIPT_LIB_DIR "${EXECUTABLE_OUTPUT_DIRECTORY}/compiledscripts/" ) +set(EXECUTABLE_OUTPUT_PATH "${SCRIPT_LIB_DIR}") +set(LIBRARY_OUTPUT_PATH "${SCRIPT_LIB_DIR}") +set(RUNTIME_OUTPUT_DIRECTORY "${SCRIPT_LIB_DIR}") -set( SCRIPT_LIB_DIR "${EXECUTABLE_OUTPUT_DIRECTORY}/compiledscripts/" ) -set( EXECUTABLE_OUTPUT_PATH "${SCRIPT_LIB_DIR}") -set( LIBRARY_OUTPUT_PATH "${SCRIPT_LIB_DIR}") -set( RUNTIME_OUTPUT_DIRECTORY "${SCRIPT_LIB_DIR}") -foreach(_sourcefile ${SCRIPT_FILES}) - get_filename_component(_file "${_sourcefile}" NAME_WE) - add_library("${_file}" MODULE "${_sourcefile}" "${SCRIPT_INCLUDE_FILES}") +file(GLOB children "${CMAKE_CURRENT_SOURCE_DIR}/*" ) +foreach(_scriptDir ${children}) + get_filename_component(_name "${_scriptDir}" NAME_WE) + if(IS_DIRECTORY ${_scriptDir} AND NOT ${_name} MATCHES "CMakeFiles") + message("discovered plugin lib: ${_scriptDir} (${_name})") - if(MSVC) - set_source_files_properties("${_file}" PROPERTIES - COMPILE_FLAGS "/YuScriptObject.h" - ) - set_target_properties(${_file} PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON - LIBRARY_OUTPUT_DIRECTORY_DEBUG "${SCRIPT_LIB_DIR}" - LIBRARY_OUTPUT_DIRECTORY_RELEASE "${SCRIPT_LIB_DIR}" - LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${SCRIPT_LIB_DIR}" - LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${SCRIPT_LIB_DIR}" + file(GLOB_RECURSE SCRIPT_FILES "${_scriptDir}/*.cpp") + + # build file list + foreach(_script ${SCRIPT_FILES}) + get_filename_component( _scriptname "${_script}" NAME_WE) + + if(NOT ${_scriptname} MATCHES "ScriptLoader") + if(ScriptIncludes) + set(ScriptIncludes "${ScriptIncludes}\n#include \"${_script}\"") + else() + set(ScriptIncludes "#include \"${_script}\"") + endif() + + set(ScriptNames "${ScriptNames} static_cast< ScriptObject* >( new ${_scriptname} ),\n") + endif() + endforeach() + + add_library("script_${_name}" MODULE "${SCRIPT_FILES}" "${SCRIPT_INCLUDE_FILES}" "${_scriptDir}/ScriptLoader.cpp") + target_link_libraries("script_${_name}" sapphire_zone) + + if(MSVC) + set_target_properties("script_${_name}" PROPERTIES + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS ON + LIBRARY_OUTPUT_DIRECTORY_DEBUG "${SCRIPT_LIB_DIR}" + LIBRARY_OUTPUT_DIRECTORY_RELEASE "${SCRIPT_LIB_DIR}" + LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${SCRIPT_LIB_DIR}" + LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${SCRIPT_LIB_DIR}" + ) + endif() + + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ScriptLoader.cpp.in" "${_scriptDir}/ScriptLoader.cpp") + + add_custom_command(TARGET "script_${_name}" POST_BUILD + COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.exp" + COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.lib" + COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.ilk" ) + + unset(ScriptIncludes) + unset(ScriptNames) endif() - - target_link_libraries("${_file}" sapphire_zone) - - add_custom_command(TARGET "${_file}" POST_BUILD - COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/${_file}.exp" - COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/${_file}.lib" - COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/${_file}.ilk" - ) -endforeach(_sourcefile ${SCRIPT_FILES}) +endforeach() diff --git a/scripts/native/CmnDef/CmnDefCutSceneReplay.cpp b/scripts/native/CmnDef/CmnDefCutSceneReplay.cpp index f190b7d5..618c1610 100644 --- a/scripts/native/CmnDef/CmnDefCutSceneReplay.cpp +++ b/scripts/native/CmnDef/CmnDefCutSceneReplay.cpp @@ -33,6 +33,4 @@ public: { Scene00000( player ); } -}; - -EXPORT_SCRIPTOBJECT( CmnDefCutSceneReplay ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/CmnDef/CmnDefInnBed.cpp b/scripts/native/CmnDef/CmnDefInnBed.cpp index 0238eeac..5e675b88 100644 --- a/scripts/native/CmnDef/CmnDefInnBed.cpp +++ b/scripts/native/CmnDef/CmnDefInnBed.cpp @@ -53,6 +53,4 @@ public: { Scene00100( player ); } -}; - -EXPORT_SCRIPTOBJECT( CmnDefInnBed ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/CmnDef/CmnDefLinkShell.cpp b/scripts/native/CmnDef/CmnDefLinkShell.cpp index b85b2d9b..eb2a7b29 100644 --- a/scripts/native/CmnDef/CmnDefLinkShell.cpp +++ b/scripts/native/CmnDef/CmnDefLinkShell.cpp @@ -55,6 +55,4 @@ public: { Scene00001( player ); } -}; - -EXPORT_SCRIPTOBJECT( CmnDefLinkShell ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/CmnDef/HouFurOrchestrion.cpp b/scripts/native/CmnDef/HouFurOrchestrion.cpp index 6544712c..bb370e24 100644 --- a/scripts/native/CmnDef/HouFurOrchestrion.cpp +++ b/scripts/native/CmnDef/HouFurOrchestrion.cpp @@ -1,9 +1,9 @@ #include "../ScriptObject.h" -class HouFurOrchestrionDef : public EventScript +class HouFurOrchestrion : public EventScript { public: - HouFurOrchestrionDef() : EventScript( "HouFurOrchestrionDef", 721226 ) + HouFurOrchestrion() : EventScript( "HouFurOrchestrion", 721226 ) {} void Scene00000( Entity::Player& player ) @@ -15,6 +15,4 @@ public: { Scene00000( player ); } -}; - -EXPORT_SCRIPTOBJECT( HouFurOrchestrionDef ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/ScriptLoader.cpp.in b/scripts/native/ScriptLoader.cpp.in new file mode 100644 index 00000000..633ca309 --- /dev/null +++ b/scripts/native/ScriptLoader.cpp.in @@ -0,0 +1,16 @@ +#include + +class ScriptObject; + +@ScriptIncludes@ + +const ScriptObject* ptrs[] = +{ +@ScriptNames@ + nullptr +}; + +extern "C" EXPORT const ScriptObject** getScripts() +{ + return ptrs; +} diff --git a/scripts/native/action/ActionSprint3.cpp b/scripts/native/action/ActionSprint3.cpp index d1312d03..6e9af153 100644 --- a/scripts/native/action/ActionSprint3.cpp +++ b/scripts/native/action/ActionSprint3.cpp @@ -10,6 +10,4 @@ public: { player.addStatusEffectByIdIfNotExist( 50, 20000, player, 30 ); } -}; - -EXPORT_SCRIPTOBJECT( ActionSprint3 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/aetheryte/Aethernet.cpp b/scripts/native/aetheryte/Aethernet.cpp index d2ac491d..b3881120 100644 --- a/scripts/native/aetheryte/Aethernet.cpp +++ b/scripts/native/aetheryte/Aethernet.cpp @@ -43,6 +43,4 @@ public: } } -}; - -EXPORT_SCRIPTOBJECT( Aethernet ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/aetheryte/Aetheryte.cpp b/scripts/native/aetheryte/Aetheryte.cpp index c4e0e0b0..96ba8675 100644 --- a/scripts/native/aetheryte/Aetheryte.cpp +++ b/scripts/native/aetheryte/Aetheryte.cpp @@ -65,6 +65,4 @@ public: {}, 0 ); } } -}; - -EXPORT_SCRIPTOBJECT( Aetheryte ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/opening/OpeningGridania.cpp b/scripts/native/opening/OpeningGridania.cpp index 45fcbbb6..c6463ef7 100644 --- a/scripts/native/opening/OpeningGridania.cpp +++ b/scripts/native/opening/OpeningGridania.cpp @@ -1,31 +1,28 @@ #include "../ScriptObject.h" -#define ERANGE_HOWTO_ANN_AND_QUEST 2117539 -#define ERANGE_HOWTO_QUEST_REWARD 2366417 -#define ERANGE_SEQ_1_CLOSED_1 2351918 -#define POS_SEQ_1_CLOSED_RETURN_1 2351921 -#define ERANGE_SEQ_1_CLOSED_2 2351919 -#define POS_SEQ_1_CLOSED_RETURN_2 2351921 -#define ERANGE_ALWAYS_CLOSED_1 2280846 -#define POS_ALWAYS_CLOSED_RETURN_1 2320804 -#define ENPC_ALWAYS_CLOSED_1 2367988 -#define ERANGE_ALWAYS_CLOSED_3 2280851 -#define POS_ALWAYS_CLOSED_RETURN_3 2320811 -#define ENPC_ALWAYS_CLOSED_3 2563491 -#define BGM_MUSIC_ZONE_FST_TWN 1003 -#define NCUT_FST_1 3 -#define NCUT_FST_2 53 -#define NCUT_FST_3 226 -#define ENPC_QUEST_OFFER 1985150 -#define NCUT_LIGHT_ALL 2 -#define NCUT_LIGHT_FST_1 147 -#define NCUT_LIGHT_FST_2 146 - class OpeningGridania : public EventScript { -public: - OpeningGridania() : EventScript( "OpeningGridania", 1245186 ) - {} +private: + static constexpr auto ERANGE_HOWTO_ANN_AND_QUEST = 2117539; + static constexpr auto ERANGE_HOWTO_QUEST_REWARD = 2366417; + static constexpr auto ERANGE_SEQ_1_CLOSED_1 = 2351918; + static constexpr auto POS_SEQ_1_CLOSED_RETURN_1 = 2351921; + static constexpr auto ERANGE_SEQ_1_CLOSED_2 = 2351919; + static constexpr auto POS_SEQ_1_CLOSED_RETURN_2 = 2351921; + static constexpr auto ERANGE_ALWAYS_CLOSED_1 = 2280846; + static constexpr auto POS_ALWAYS_CLOSED_RETURN_1 = 2320804; + static constexpr auto ENPC_ALWAYS_CLOSED_1 = 2367988; + static constexpr auto ERANGE_ALWAYS_CLOSED_3 = 2280851; + static constexpr auto POS_ALWAYS_CLOSED_RETURN_3 = 2320811; + static constexpr auto ENPC_ALWAYS_CLOSED_3 = 2563491; + static constexpr auto BGM_MUSIC_ZONE_FST_TWN = 1003; + static constexpr auto NCUT_FST_1 = 3; + static constexpr auto NCUT_FST_2 = 53; + static constexpr auto NCUT_FST_3 = 226; + static constexpr auto ENPC_QUEST_OFFER = 1985150; + static constexpr auto NCUT_LIGHT_ALL = 2; + static constexpr auto NCUT_LIGHT_FST_1 = 147; + static constexpr auto NCUT_LIGHT_FST_2 = 146; void Scene00000( Entity::Player& player ) { @@ -67,7 +64,9 @@ public: player.eventPlay( getId(), 40, 1, 2, 1, callback ); } - /////////////////////////////// +public: + OpeningGridania() : EventScript( "OpeningGridania", 1245186 ) + {} void onEnterZone( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override { @@ -88,6 +87,4 @@ public: Scene00020( player ); } } -}; - -EXPORT_SCRIPTOBJECT( OpeningGridania ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/opening/OpeningLimsa.cpp b/scripts/native/opening/OpeningLimsa.cpp index 17ec1170..369e8686 100644 --- a/scripts/native/opening/OpeningLimsa.cpp +++ b/scripts/native/opening/OpeningLimsa.cpp @@ -95,6 +95,4 @@ public: { // todo: handle closed events } -}; - -EXPORT_SCRIPTOBJECT( OpeningLimsa ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/opening/OpeningUldah.cpp b/scripts/native/opening/OpeningUldah.cpp index df9da939..ba940295 100644 --- a/scripts/native/opening/OpeningUldah.cpp +++ b/scripts/native/opening/OpeningUldah.cpp @@ -88,6 +88,4 @@ public: Scene00020( player ); } } -}; - -EXPORT_SCRIPTOBJECT( OpeningUldah ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/ManFst001.cpp b/scripts/native/quest/ManFst001.cpp index 5603657b..726d2dc5 100644 --- a/scripts/native/quest/ManFst001.cpp +++ b/scripts/native/quest/ManFst001.cpp @@ -6,29 +6,29 @@ // Start NPC: 1001148 // End NPC: 1001140 -#define SEQ_0 0 -#define SEQ_FINISH 255 - -#define RewardExpFactor 50 -#define RewardGil 103 - -#define ACTOR0 1001148 -#define ACTOR1 1001140 -#define CUT_EVENT 29 -#define EOBJECT0 2001659 -#define EOBJECT1 2001660 -#define EOBJECT7 2616477 -#define EVENT_ACTION_SEARCH 1 -#define HOWTO_QUEST_ACCEPT 12 -#define HOWTO_QUEST_ANNOUNCE 2 -#define HOWTO_REWARD 11 -#define HOWTO_TODO 3 -#define OPENING_EVENT_HANDLER 1245186 -#define SEQ_2_ACTOR1 2 - class ManFst001 : public EventScript { private: + static constexpr auto SEQ_0 = 0; + static constexpr auto SEQ_FINISH = 255; + + static constexpr auto RewardExpFactor = 50; + static constexpr auto RewardGil = 103; + + static constexpr auto ACTOR0 = 1001148; + static constexpr auto ACTOR1 = 1001140; + static constexpr auto CUT_EVENT = 29; + static constexpr auto EOBJECT0 = 2001659; + static constexpr auto EOBJECT1 = 2001660; + static constexpr auto EOBJECT7 = 2616477; + static constexpr auto EVENT_ACTION_SEARCH = 1; + static constexpr auto HOWTO_QUEST_ACCEPT = 12; + static constexpr auto HOWTO_QUEST_ANNOUNCE = 2; + static constexpr auto HOWTO_REWARD = 11; + static constexpr auto HOWTO_TODO = 3; + static constexpr auto OPENING_EVENT_HANDLER = 1245186; + static constexpr auto SEQ_2_ACTOR1 = 2; + void Scene00000( Entity::Player& player ) { auto callback = [&]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 ) @@ -101,6 +101,4 @@ public: else if( actor == ACTOR1 ) Scene00004( player ); } -}; - -EXPORT_SCRIPTOBJECT( ManFst001 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/ManFst002.cpp b/scripts/native/quest/ManFst002.cpp index 9857ba60..6b084490 100644 --- a/scripts/native/quest/ManFst002.cpp +++ b/scripts/native/quest/ManFst002.cpp @@ -220,6 +220,4 @@ public: else if( actor == ACTOR4 ) Scene00005( player ); } -}; - -EXPORT_SCRIPTOBJECT( ManFst002 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/ManFst003.cpp b/scripts/native/quest/ManFst003.cpp index 5d8ada95..e564a7ca 100644 --- a/scripts/native/quest/ManFst003.cpp +++ b/scripts/native/quest/ManFst003.cpp @@ -18,6 +18,4 @@ public: { } -}; - -EXPORT_SCRIPTOBJECT( ManFst003 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/ManFst004.cpp b/scripts/native/quest/ManFst004.cpp index 874fd650..b8896a41 100644 --- a/scripts/native/quest/ManFst004.cpp +++ b/scripts/native/quest/ManFst004.cpp @@ -78,7 +78,7 @@ class ManFst004 : public EventScript // Event Handlers void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override { - auto actor = Event::mapEventActorToRealActor( actorId ); + auto actor = Event::mapEventActorToRealActor( static_cast< uint32_t >( actorId ) ); if( actor == ManFst004::Actor0 ) { Scene00000( player ); @@ -254,6 +254,4 @@ class ManFst004 : public EventScript }); } -}; - -EXPORT_SCRIPTOBJECT( ManFst004 ); \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/ManSea001.cpp b/scripts/native/quest/ManSea001.cpp index 63a1b750..2a3e4aaa 100644 --- a/scripts/native/quest/ManSea001.cpp +++ b/scripts/native/quest/ManSea001.cpp @@ -158,6 +158,4 @@ public: else if( actor == ACTOR2 ) Scene00011( player ); } -}; - -EXPORT_SCRIPTOBJECT( ManSea001 ); \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/ManSea002.cpp b/scripts/native/quest/ManSea002.cpp index ed43f35c..5db24e06 100644 --- a/scripts/native/quest/ManSea002.cpp +++ b/scripts/native/quest/ManSea002.cpp @@ -146,6 +146,4 @@ public: if( actor == ACTOR0 ) Scene00000( player ); } -}; - -EXPORT_SCRIPTOBJECT( ManSea002 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/ManWil001.cpp b/scripts/native/quest/ManWil001.cpp index e19b08b6..93b7f42f 100644 --- a/scripts/native/quest/ManWil001.cpp +++ b/scripts/native/quest/ManWil001.cpp @@ -140,6 +140,4 @@ public: else if( actor == ACTOR1 ) Scene00004( player ); } -}; - -EXPORT_SCRIPTOBJECT( ManWil001 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/ManWil002.cpp b/scripts/native/quest/ManWil002.cpp index 6791a312..3f1c399c 100644 --- a/scripts/native/quest/ManWil002.cpp +++ b/scripts/native/quest/ManWil002.cpp @@ -153,6 +153,4 @@ public: if( actor == ACTOR0 ) Scene00000( player ); } -}; - -EXPORT_SCRIPTOBJECT( ManWil002 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/subquest/gridania/SubFst001.cpp b/scripts/native/quest/subquest/gridania/SubFst001.cpp index 4b5a31a2..c6b18dbc 100644 --- a/scripts/native/quest/subquest/gridania/SubFst001.cpp +++ b/scripts/native/quest/subquest/gridania/SubFst001.cpp @@ -81,6 +81,4 @@ public: Scene00100( player ); } } -}; - -EXPORT_SCRIPTOBJECT( SubFst001 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/subquest/gridania/SubFst010.cpp b/scripts/native/quest/subquest/gridania/SubFst010.cpp index 6883fae6..bccd887d 100644 --- a/scripts/native/quest/subquest/gridania/SubFst010.cpp +++ b/scripts/native/quest/subquest/gridania/SubFst010.cpp @@ -53,6 +53,4 @@ public: else if( actor == ACTOR1 ) Scene00001( player ); } -}; - -EXPORT_SCRIPTOBJECT( SubFst010 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/scripts/native/quest/subquest/gridania/SubFst013.cpp b/scripts/native/quest/subquest/gridania/SubFst013.cpp index 5e3cb63a..d696642f 100644 --- a/scripts/native/quest/subquest/gridania/SubFst013.cpp +++ b/scripts/native/quest/subquest/gridania/SubFst013.cpp @@ -181,6 +181,4 @@ public: else if( actor == ACTOR1 && emoteId == 11 && player.getQuestSeq( getId() ) == SEQ_5 ) Scene00096( player ); } -}; - -EXPORT_SCRIPTOBJECT( SubFst013 ) \ No newline at end of file +}; \ No newline at end of file diff --git a/src/common/Version.cpp b/src/common/Version.cpp deleted file mode 100644 index 6658cae1..00000000 --- a/src/common/Version.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Version.h" - -namespace Core { - namespace Version { - - const std::string GIT_HASH = "d799f2e3c2d745f9d9e07d6e37664fc031b7c264"; - const std::string VERSION = "-128-NOTFOUND"; - - } /* Version */ -} /* Core */ diff --git a/src/servers/sapphire_zone/DebugCommand/DebugCommandHandler.cpp b/src/servers/sapphire_zone/DebugCommand/DebugCommandHandler.cpp index dccb6ce8..c3fe7904 100644 --- a/src/servers/sapphire_zone/DebugCommand/DebugCommandHandler.cpp +++ b/src/servers/sapphire_zone/DebugCommand/DebugCommandHandler.cpp @@ -567,9 +567,9 @@ void Core::DebugCommandHandler::script( char* data, Entity::Player &player, boos for( auto it = scripts.begin(); it != scripts.end(); ++it ) { auto script = *it; - player.sendDebug( " - '" + script->script_name + "' loaded at @ 0x" + + player.sendDebug( " - '" + script->library_name + "' loaded at @ 0x" + boost::str( boost::format( "%|X|" ) % script->handle ) + - ", script ptr: 0x" + boost::str( boost::format( "%|X|" ) % script->script ) ); + ", num scripts: " + std::to_string( script->scripts.size() ) ); } } else diff --git a/src/servers/sapphire_zone/Script/NativeScriptApi.h b/src/servers/sapphire_zone/Script/NativeScriptApi.h index cf3d4eb2..f5f1ba59 100644 --- a/src/servers/sapphire_zone/Script/NativeScriptApi.h +++ b/src/servers/sapphire_zone/Script/NativeScriptApi.h @@ -12,10 +12,6 @@ #define EXPORT __attribute__((visibility("default"))) #endif -#define EXPORT_SCRIPTOBJECT( type ) \ -extern "C" EXPORT ScriptObject* getScript() \ -{ return static_cast< ScriptObject* >( new type ); } - using namespace Core; // constant script ids for certain events diff --git a/src/servers/sapphire_zone/Script/NativeScriptManager.cpp b/src/servers/sapphire_zone/Script/NativeScriptManager.cpp index a28a823f..dce4e6e5 100644 --- a/src/servers/sapphire_zone/Script/NativeScriptManager.cpp +++ b/src/servers/sapphire_zone/Script/NativeScriptManager.cpp @@ -57,38 +57,50 @@ namespace Core { if( !module ) return false; - auto script = m_loader.getScriptObject( module->handle ); - if( !script ) + auto scripts = m_loader.getScripts( module->handle ); + if( !scripts ) { m_loader.unloadScript( module ); return false; } - module->script = script; - module->script_name = script->getName(); - module->type = script->getType(); + // + bool success = false; - switch( script->getType() ) + for( int i = 0; ; i++ ) { - case ScriptType::StatusEffect: - m_statusEffectScripts[ script->getId() ] = dynamic_cast< StatusEffectScript* >( script ); - break; - case ScriptType::Action: - m_actionScripts[ script->getId() ] = dynamic_cast< ActionScript* >( script ); - break; - case ScriptType::Quest: - m_eventScripts[ script->getId() ] = dynamic_cast< EventScript* >( script ); - break; - case ScriptType::BattleNpc: - m_battleNpcScripts[ script->getId() ] = dynamic_cast< BattleNpcScript* >( script ); - break; - case ScriptType::Zone: - m_zoneScripts[ script->getId() ] = dynamic_cast< ZoneScript* >( script ); + if( scripts[i] == nullptr ) break; - default: - m_loader.unloadScript( module ); - return false; + auto script = scripts[i]; + module->scripts.push_back( script ); + + switch( script->getType() ) + { + case ScriptType::StatusEffect: + m_statusEffectScripts[ script->getId() ] = dynamic_cast< StatusEffectScript* >( script ); + break; + case ScriptType::Action: + m_actionScripts[ script->getId() ] = dynamic_cast< ActionScript* >( script ); + break; + case ScriptType::Quest: + m_eventScripts[ script->getId() ] = dynamic_cast< EventScript* >( script ); + break; + case ScriptType::BattleNpc: + m_battleNpcScripts[ script->getId() ] = dynamic_cast< BattleNpcScript* >( script ); + break; + case ScriptType::Zone: + m_zoneScripts[ script->getId() ] = dynamic_cast< ZoneScript* >( script ); + break; + } + + success = true; + } + + if( !success ) + { + m_loader.unloadScript( module->handle ); + return false; } return true; @@ -110,28 +122,29 @@ namespace Core { bool NativeScriptManager::unloadScript( ScriptInfo* info ) { - auto ptr = info->script; - - switch( info->type ) + for( auto& script : info->scripts ) { - case ScriptType::StatusEffect: - removeValueFromMap< uint32_t, StatusEffectScript* >( ptr, m_statusEffectScripts ); - break; - case ScriptType::Action: - removeValueFromMap< uint32_t, ActionScript* >( ptr, m_actionScripts ); - break; - case ScriptType::Quest: - removeValueFromMap< uint32_t, EventScript* >( ptr, m_eventScripts ); - break; - case ScriptType::BattleNpc: - removeValueFromMap< uint32_t, BattleNpcScript* >( ptr, m_battleNpcScripts ); - break; - case ScriptType::Zone: - removeValueFromMap< uint32_t, ZoneScript* >( ptr, m_zoneScripts ); - break; + switch( script->getType() ) + { + case ScriptType::StatusEffect: + removeValueFromMap< uint32_t, StatusEffectScript* >( script, m_statusEffectScripts ); + break; + case ScriptType::Action: + removeValueFromMap< uint32_t, ActionScript* >( script, m_actionScripts ); + break; + case ScriptType::Quest: + removeValueFromMap< uint32_t, EventScript* >( script, m_eventScripts ); + break; + case ScriptType::BattleNpc: + removeValueFromMap< uint32_t, BattleNpcScript* >( script, m_battleNpcScripts ); + break; + case ScriptType::Zone: + removeValueFromMap< uint32_t, ZoneScript* >( script, m_zoneScripts ); + break; - default: - return false; + default: + continue; + } } return m_loader.unloadScript( info ); diff --git a/src/servers/sapphire_zone/Script/ScriptInfo.h b/src/servers/sapphire_zone/Script/ScriptInfo.h index 19945723..7ddabc18 100644 --- a/src/servers/sapphire_zone/Script/ScriptInfo.h +++ b/src/servers/sapphire_zone/Script/ScriptInfo.h @@ -1,6 +1,8 @@ #ifndef SAPPHIRE_SCRIPTINFO_H #define SAPPHIRE_SCRIPTINFO_H +#include + #include "NativeScriptApi.h" #ifdef _WIN32 @@ -22,9 +24,8 @@ namespace Scripting { std::string cache_path; std::string library_path; - std::string script_name; ModuleHandle handle; - ScriptObject* script; + std::vector< ScriptObject* > scripts; ScriptType type; }; } diff --git a/src/servers/sapphire_zone/Script/ScriptLoader.cpp b/src/servers/sapphire_zone/Script/ScriptLoader.cpp index 81b9abfe..e37678cd 100644 --- a/src/servers/sapphire_zone/Script/ScriptLoader.cpp +++ b/src/servers/sapphire_zone/Script/ScriptLoader.cpp @@ -100,22 +100,21 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st return info; } -ScriptObject* Core::Scripting::ScriptLoader::getScriptObject( ModuleHandle handle ) +ScriptObject** Core::Scripting::ScriptLoader::getScripts( ModuleHandle handle ) { - using getScript = ScriptObject*(*)(); + using getScripts = ScriptObject**(*)(); #ifdef _WIN32 - getScript func = reinterpret_cast< getScript >( GetProcAddress( handle, "getScript" ) ); + getScripts func = reinterpret_cast< getScripts >( GetProcAddress( handle, "getScripts" ) ); #else - getScript func = reinterpret_cast< getScript >( dlsym( handle, "getScript" ) ); + getScripts func = reinterpret_cast< getScripts >( dlsym( handle, "getScripts" ) ); #endif if( func ) { auto ptr = func(); - g_log.debug( "got ScriptObject @ 0x" + boost::str( boost::format( "%|08X|" ) % ptr ) ); - g_log.debug( "script info -> name: " + std::string( ptr->getName() ) + ", id: " + std::to_string( ptr->getId() ) ); + g_log.debug( "got ScriptObject array @ 0x" + boost::str( boost::format( "%|08X|" ) % ptr ) ); return ptr; } @@ -171,7 +170,7 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::getScriptInfo( std:: { for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it ) { - if( it->second->script_name == name ) + if( it->second->library_name == name ) { return it->second; } @@ -184,7 +183,7 @@ void Core::Scripting::ScriptLoader::findScripts( std::set< Core::Scripting::Scri { for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it ) { - if( it->second->script_name.find( search ) != std::string::npos ) + if( it->second->library_name.find( search ) != std::string::npos ) { scripts.insert( it->second ); } diff --git a/src/servers/sapphire_zone/Script/ScriptLoader.h b/src/servers/sapphire_zone/Script/ScriptLoader.h index 0f452d19..1e99d86e 100644 --- a/src/servers/sapphire_zone/Script/ScriptLoader.h +++ b/src/servers/sapphire_zone/Script/ScriptLoader.h @@ -19,24 +19,30 @@ typedef void* ModuleHandle; namespace Core { namespace Scripting { - class ScriptLoader { + class ScriptLoader + { protected: - std::unordered_map< std::string, ScriptInfo* > m_scriptMap; + std::unordered_map< std::string, ScriptInfo* > m_scriptMap; - bool unloadModule( ModuleHandle ); + bool unloadModule( ModuleHandle ); public: - ScriptLoader(); + ScriptLoader(); - const std::string getModuleExtension(); - ScriptInfo* loadModule( const std::string& ); - bool unloadScript( ScriptInfo* ); - bool unloadScript( ModuleHandle ); - ScriptInfo* getScriptInfo( std::string name ); - ScriptObject* getScriptObject( ModuleHandle handle ); - bool isModuleLoaded( std::string name ); + const std::string getModuleExtension(); + ScriptInfo* loadModule( const std::string& ); - void findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search ); + bool unloadScript( ScriptInfo* ); + bool unloadScript( ModuleHandle ); + + ScriptInfo* getScriptInfo( std::string name ); + + ScriptObject** getScripts( ModuleHandle handle ); + ScriptObject* getScriptObject( ModuleHandle handle ); + + bool isModuleLoaded( std::string name ); + + void findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search ); }; }