diff --git a/bin/config/settings_zone.xml b/bin/config/settings_zone.xml
index fcff6d3f..9446787f 100644
--- a/bin/config/settings_zone.xml
+++ b/bin/config/settings_zone.xml
@@ -6,6 +6,20 @@
127.0.0.1
H:\\SteamLibrary\\steamapps\\common\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv
+
+
+
+ ./compiledscripts/
+
+ ./cache/
+
+
+ 1
+ ../cmake-build-debug/
+ nmake %1%
+
+
+
./compiledscripts/
diff --git a/scripts/native/CMakeLists.txt b/scripts/native/CMakeLists.txt
index 294862bf..c20848ea 100644
--- a/scripts/native/CMakeLists.txt
+++ b/scripts/native/CMakeLists.txt
@@ -1,14 +1,14 @@
-cmake_minimum_required(VERSION 3.2)
+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("../../src/servers/")
-include_directories("../../src/servers/Server_Zone/")
+include_directories("${CMAKE_SOURCE_DIR}/src/servers/")
+include_directories("${CMAKE_SOURCE_DIR}/src/servers/Server_Zone/")
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()
foreach(_sourcefile ${SCRIPT_FILES})
@@ -27,14 +27,17 @@ foreach(_sourcefile ${SCRIPT_FILES})
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON
- LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/"
- LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/"
- LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/"
- LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/"
+ LIBRARY_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/"
+ LIBRARY_OUTPUT_DIRECTORY_DEBUG "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/"
+ LIBRARY_OUTPUT_DIRECTORY_RELEASE "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/"
+ LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/"
+ LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/"
+ ARCHIVE_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/"
)
add_custom_command(TARGET "${_file}" POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/${_file}.exp"
- COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/${_file}.lib"
+ COMMAND ${CMAKE_COMMAND} -E remove "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/${_file}.exp"
+ COMMAND ${CMAKE_COMMAND} -E remove "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/${_file}.lib"
+ COMMAND ${CMAKE_COMMAND} -E remove "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/${_file}.ilk"
)
endforeach(_sourcefile ${SCRIPT_FILES})
\ No newline at end of file
diff --git a/scripts/native/CmnDef/CmnDefCutSceneReplay.cpp b/scripts/native/CmnDef/CmnDefCutSceneReplay.cpp
new file mode 100644
index 00000000..f190b7d5
--- /dev/null
+++ b/scripts/native/CmnDef/CmnDefCutSceneReplay.cpp
@@ -0,0 +1,38 @@
+#include "../ScriptObject.h"
+
+class CmnDefCutSceneReplay : public EventScript
+{
+public:
+ CmnDefCutSceneReplay() : EventScript( "CmnDefCutSceneReplay", 721028 )
+ {}
+
+ void Scene00000( Entity::Player& player )
+ {
+ auto callback = [ this ]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )
+ {
+ if( param2 != 0 )
+ {
+ Scene00001( player, param2 );
+ }
+ };
+
+ player.eventPlay( getId(), 0, 0x2000, 0, 1, callback );
+ }
+
+ void Scene00001( Entity::Player& player, uint16_t returnScene )
+ {
+ auto callback = []( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )
+ {
+ // todo: this is fucked
+ };
+
+ player.eventPlay( getId(), 1, 0xFB2EC8F8, 0, 1, returnScene, callback );
+ }
+
+ void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
+ {
+ Scene00000( player );
+ }
+};
+
+EXPORT_SCRIPTOBJECT( CmnDefCutSceneReplay )
\ No newline at end of file
diff --git a/scripts/native/CmnDef/CmnDefInnBed.cpp b/scripts/native/CmnDef/CmnDefInnBed.cpp
new file mode 100644
index 00000000..0238eeac
--- /dev/null
+++ b/scripts/native/CmnDef/CmnDefInnBed.cpp
@@ -0,0 +1,58 @@
+#include "../ScriptObject.h"
+
+class CmnDefInnBed : public EventScript
+{
+public:
+ CmnDefInnBed() : EventScript( "CmnDefInnBed", 720916 )
+ {}
+
+ // menu
+ void Scene00000( Entity::Player& player )
+ {
+ auto callback = [ this ]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )
+ {
+ if( param2 > 0 )
+ Scene00001( player, param2 );
+ };
+
+ player.eventPlay( getId(), 0, 0x2000, 0, 1, callback );
+ }
+
+ // lay down
+ void Scene00001( Entity::Player& player, uint16_t param )
+ {
+ auto callback = [ this ]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )
+ {
+ Scene00002( player, param2 );
+ };
+
+ player.eventPlay( getId(), 1, 0xF32E48F8, 0, 1, param, callback );
+ }
+
+ // logout
+ void Scene00002( Entity::Player& player, uint16_t param )
+ {
+ player.eventPlay( getId(), 2, 0xF32E48F8, 0, 1, param, nullptr );
+ }
+
+ // wake up
+ void Scene00100( Entity::Player& player )
+ {
+ auto callback = []( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )
+ {};
+
+ player.eventPlay( getId(), 100, 0x800, 0, 0, callback );
+ }
+
+ void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
+ {
+ Scene00000( player );
+ }
+
+ void onEnterZone( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override
+ {
+ Scene00100( player );
+ }
+};
+
+EXPORT_SCRIPTOBJECT( CmnDefInnBed )
\ No newline at end of file
diff --git a/scripts/native/CmnDef/CmnDefLinkShell.cpp b/scripts/native/CmnDef/CmnDefLinkShell.cpp
new file mode 100644
index 00000000..b85b2d9b
--- /dev/null
+++ b/scripts/native/CmnDef/CmnDefLinkShell.cpp
@@ -0,0 +1,60 @@
+#include "../ScriptObject.h"
+
+#define ACTION_CREATE 2
+#define ACTION_RENAME 3
+#define ACTION_REMOVE 4
+
+class CmnDefLinkShell : public EventScript
+{
+public:
+ CmnDefLinkShell() : EventScript( "CmnDefLinkShell", 0xB0006 )
+ {}
+
+ void Scene00001( Entity::Player& player )
+ {
+ auto callback = [ this ]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )
+ {
+ switch( param2 )
+ {
+ case ACTION_CREATE:
+ Scene00002( player );
+ break;
+
+ case ACTION_RENAME:
+ Scene00003( player );
+ break;
+
+ case ACTION_REMOVE:
+ Scene00004( player );
+ break;
+ }
+ };
+
+ player.eventPlay( getId(), 1, 0, 0, 0, callback );
+ }
+
+ // create linkshell
+ void Scene00002( Entity::Player& player )
+ {
+ player.eventPlay( getId(), 2, 0, 0, 0 );
+ }
+
+ // rename linkshell
+ void Scene00003( Entity::Player& player )
+ {
+ player.eventPlay( getId(), 3, 0, 0, 0 );
+ }
+
+ // remove linkshell
+ void Scene00004( Entity::Player& player )
+ {
+ player.eventPlay( getId(), 4, 0, 0, 0 );
+ }
+
+ void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
+ {
+ Scene00001( player );
+ }
+};
+
+EXPORT_SCRIPTOBJECT( CmnDefLinkShell )
\ No newline at end of file
diff --git a/scripts/native/CmnDef/HouFurOrchestrion.cpp b/scripts/native/CmnDef/HouFurOrchestrion.cpp
new file mode 100644
index 00000000..6544712c
--- /dev/null
+++ b/scripts/native/CmnDef/HouFurOrchestrion.cpp
@@ -0,0 +1,20 @@
+#include "../ScriptObject.h"
+
+class HouFurOrchestrionDef : public EventScript
+{
+public:
+ HouFurOrchestrionDef() : EventScript( "HouFurOrchestrionDef", 721226 )
+ {}
+
+ void Scene00000( Entity::Player& player )
+ {
+ player.eventPlay( getId(), 0, 0x2000, 0, 1 );
+ }
+
+ void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
+ {
+ Scene00000( player );
+ }
+};
+
+EXPORT_SCRIPTOBJECT( HouFurOrchestrionDef )
\ No newline at end of file
diff --git a/scripts/native/action/ActionSprint3.cpp b/scripts/native/action/ActionSprint3.cpp
new file mode 100644
index 00000000..d1312d03
--- /dev/null
+++ b/scripts/native/action/ActionSprint3.cpp
@@ -0,0 +1,15 @@
+#include "../ScriptObject.h"
+
+class ActionSprint3 : public ActionScript
+{
+public:
+ ActionSprint3() : ActionScript( "ActionSprint3", 3 )
+ {}
+
+ void onCastFinish( Core::Entity::Player& player, Core::Entity::Actor& targetActor ) override
+ {
+ player.addStatusEffectByIdIfNotExist( 50, 20000, player, 30 );
+ }
+};
+
+EXPORT_SCRIPTOBJECT( ActionSprint3 )
\ No newline at end of file
diff --git a/scripts/native/aetheryte/Aethernet.cpp b/scripts/native/aetheryte/Aethernet.cpp
index 51a8f927..d2ac491d 100644
--- a/scripts/native/aetheryte/Aethernet.cpp
+++ b/scripts/native/aetheryte/Aethernet.cpp
@@ -9,13 +9,13 @@
#define AETHERYTE_MENU_FAVORITE_POINT 4
#define AETHERYTE_MENU_FAVORITE_POINT_SECURITY_TOKEN 5
-class Aethernet : public QuestScript
+class Aethernet : public EventScript
{
public:
- Aethernet() : QuestScript( "Aethernet", EVENTSCRIPT_AETHERNET_ID )
+ Aethernet() : EventScript( "Aethernet", EVENTSCRIPT_AETHERNET_ID )
{}
- virtual void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId )
+ void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
{
if( player.isAetheryteRegistered( eventId & 0xFFFF ) )
{
diff --git a/scripts/native/aetheryte/Aetheryte.cpp b/scripts/native/aetheryte/Aetheryte.cpp
index 939c87ca..c4e0e0b0 100644
--- a/scripts/native/aetheryte/Aetheryte.cpp
+++ b/scripts/native/aetheryte/Aetheryte.cpp
@@ -10,13 +10,13 @@
#define AETHERYTE_MENU_FAVORITE_POINT 4
#define AETHERYTE_MENU_FAVORITE_POINT_SECURITY_TOKEN 5
-class Aetheryte : public QuestScript
+class Aetheryte : public EventScript
{
public:
- Aetheryte() : QuestScript( "Aetheryte", EVENTSCRIPT_AETHERYTE_ID )
+ Aetheryte() : EventScript( "Aetheryte", EVENTSCRIPT_AETHERYTE_ID )
{}
- virtual void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId )
+ void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override
{
if( player.isAetheryteRegistered( eventId & 0xFFFF ) )
{
diff --git a/scripts/native/opening/OpeningGridania.cpp b/scripts/native/opening/OpeningGridania.cpp
new file mode 100644
index 00000000..2a9e5e6b
--- /dev/null
+++ b/scripts/native/opening/OpeningGridania.cpp
@@ -0,0 +1,91 @@
+#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 )
+ {}
+
+ void Scene00000( Entity::Player& player )
+ {
+ auto callback = [ this ]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )
+ {
+ player.setOpeningSequence( 1 );
+ Scene00001( player );
+ };
+
+ player.eventPlay( getId(), 0, 0x04AC05, 0, 1, callback );
+ }
+
+ void Scene00001( Entity::Player& player )
+ {
+ player.eventPlay( getId(), 1, 0x2001, 1, 0x32 );
+ }
+
+ void Scene00020( Entity::Player& player )
+ {
+ player.eventPlay( getId(), 20, 0x2001, 0, 1 );
+ }
+
+ void Scene00030( Entity::Player& player )
+ {
+ player.eventPlay( getId(), 30, 0x2001, 0, 0 );
+ }
+
+ void Scene00040( Entity::Player& player )
+ {
+ auto callback = [ this ]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )
+ {
+ if( player.getOpeningSequence() == 2 )
+ {
+ // update the instance boundaries
+ Scene00030( player );
+ }
+ };
+ }
+
+ ///////////////////////////////
+
+ void onEnterZone( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override
+ {
+ if( player.getOpeningSequence() == 0 )
+ {
+ Scene00000( player );
+ }
+ else
+ {
+ Scene00040( player );
+ }
+ }
+
+ void onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) override
+ {
+ if( param1 == ERANGE_SEQ_1_CLOSED_1 || param1 == ERANGE_SEQ_1_CLOSED_2 )
+ {
+ Scene00020( player );
+ }
+ }
+};
+
+EXPORT_SCRIPTOBJECT( OpeningGridania )
\ No newline at end of file
diff --git a/scripts/native/opening/OpeningLimsa.cpp b/scripts/native/opening/OpeningLimsa.cpp
new file mode 100644
index 00000000..e69de29b
diff --git a/scripts/native/opening/OpeningUldah.cpp b/scripts/native/opening/OpeningUldah.cpp
new file mode 100644
index 00000000..e69de29b
diff --git a/scripts/native/skill/ActionSprint.cpp b/scripts/native/skill/ActionSprint.cpp
deleted file mode 100644
index 48e4a43e..00000000
--- a/scripts/native/skill/ActionSprint.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "../ScriptObject.h"
-
-class ActionSprint : public ActionScript
-{
-public:
- ActionSprint() : ActionScript( "ActionSprint", 3 )
- {}
-
- virtual void onCastFinish( Core::Entity::Player& player, Core::Entity::Actor& targetActor )
- {
- player.addStatusEffectByIdIfNotExist( 50, 20000, player, 30 );
- }
-};
-
-EXPORT_SCRIPTOBJECT( ActionSprint )
\ No newline at end of file
diff --git a/scripts/native/statuseffect/StatusSprint.cpp b/scripts/native/statuseffect/StatusSprint.cpp
deleted file mode 100644
index 93d595a8..00000000
--- a/scripts/native/statuseffect/StatusSprint.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "../ScriptObject.h"
-
-class StatusSprint : public StatusEffectScript
-{
-public:
- StatusSprint() : StatusEffectScript( "StatusSprint", 50 )
- {}
-
- virtual void onTick( Entity::Actor& actor ) override
- {
- if( actor.isPlayer() )
- actor.getAsPlayer()->sendDebug( "tick tock bitch" );
- }
-
- virtual void onApply( Entity::Actor& actor ) override
- {
- if( actor.isPlayer() )
- actor.getAsPlayer()->sendDebug( "status50 applied" );
- }
-
- virtual void onExpire( Entity::Actor& actor ) override
- {
- if( actor.isPlayer() )
- actor.getAsPlayer()->sendDebug( "status50 timed out" );
- }
-
-};
-
-EXPORT_SCRIPTOBJECT( StatusSprint )
\ No newline at end of file
diff --git a/src/servers/Server_Zone/Script/NativeScriptApi.h b/src/servers/Server_Zone/Script/NativeScriptApi.h
index 1a80e2e8..cf3d4eb2 100644
--- a/src/servers/Server_Zone/Script/NativeScriptApi.h
+++ b/src/servers/Server_Zone/Script/NativeScriptApi.h
@@ -93,16 +93,21 @@ public:
};
-class QuestScript : public ScriptObject
+class EventScript : public ScriptObject
{
public:
- QuestScript( std::string name, uint32_t questId ) :
+ EventScript( std::string name, uint32_t questId ) :
ScriptObject( name, questId, ScriptType::Quest )
{ }
virtual void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) { }
virtual void onNpcKill( uint32_t npcId, Entity::Player& player ) { }
virtual void onEmote( uint64_t actorId, uint32_t eventId, uint32_t emoteId, Entity::Player& player ) { }
+ virtual void onEnterZone( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) { }
+ virtual void onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) { }
+ virtual void onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) { }
+ virtual void onEventItem( Entity::Player& player, uint32_t eventItemId, uint32_t eventId, uint32_t castTime, uint64_t targetId ) { }
+ virtual void onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param, uint32_t catalogId ) { }
};
@@ -122,7 +127,6 @@ public:
{ }
virtual void onZoneInit() { }
- virtual void onEnterZone( Entity::Player& pPlayer, uint32_t eventId, uint16_t param1, uint16_t param2 ) { }
};
#endif
\ No newline at end of file
diff --git a/src/servers/Server_Zone/Script/NativeScriptManager.cpp b/src/servers/Server_Zone/Script/NativeScriptManager.cpp
index 6ee29848..be7a29a7 100644
--- a/src/servers/Server_Zone/Script/NativeScriptManager.cpp
+++ b/src/servers/Server_Zone/Script/NativeScriptManager.cpp
@@ -24,10 +24,10 @@ namespace Core {
return script->second;
}
- QuestScript* NativeScriptManager::getQuestScript( uint32_t questId )
+ EventScript* NativeScriptManager::getEventScript( uint32_t questId )
{
- auto script = m_questScripts.find( questId );
- if( script == m_questScripts.end() )
+ auto script = m_eventScripts.find( questId );
+ if( script == m_eventScripts.end() )
return nullptr;
return script->second;
@@ -59,7 +59,10 @@ namespace Core {
auto script = m_loader.getScriptObject( module->handle );
if( !script )
+ {
+ m_loader.unloadScript( module );
return false;
+ }
module->script = script;
module->script_name = script->getName();
@@ -74,7 +77,7 @@ namespace Core {
m_actionScripts[ script->getId() ] = dynamic_cast< ActionScript* >( script );
break;
case ScriptType::Quest:
- m_questScripts[ script->getId() ] = dynamic_cast< QuestScript* >( script );
+ m_eventScripts[ script->getId() ] = dynamic_cast< EventScript* >( script );
break;
case ScriptType::BattleNpc:
m_battleNpcScripts[ script->getId() ] = dynamic_cast< BattleNpcScript* >( script );
@@ -113,7 +116,7 @@ namespace Core {
removeValueFromMap< uint32_t, ActionScript* >( ptr, m_actionScripts );
break;
case ScriptType::Quest:
- removeValueFromMap< uint32_t, QuestScript* >( ptr, m_questScripts );
+ removeValueFromMap< uint32_t, EventScript* >( ptr, m_eventScripts );
break;
case ScriptType::BattleNpc:
removeValueFromMap< uint32_t, BattleNpcScript* >( ptr, m_battleNpcScripts );
diff --git a/src/servers/Server_Zone/Script/NativeScriptManager.h b/src/servers/Server_Zone/Script/NativeScriptManager.h
index 8068d4ec..cdfb436c 100644
--- a/src/servers/Server_Zone/Script/NativeScriptManager.h
+++ b/src/servers/Server_Zone/Script/NativeScriptManager.h
@@ -20,7 +20,7 @@ namespace Scripting {
protected:
std::unordered_map< uint32_t, StatusEffectScript* > m_statusEffectScripts;
std::unordered_map< uint32_t, ActionScript* > m_actionScripts;
- std::unordered_map< uint32_t, QuestScript* > m_questScripts;
+ std::unordered_map< uint32_t, EventScript* > m_eventScripts;
std::unordered_map< uint32_t, BattleNpcScript* > m_battleNpcScripts;
std::unordered_map< uint32_t, ZoneScript* > m_zoneScripts;
@@ -31,7 +31,7 @@ namespace Scripting {
StatusEffectScript* getStatusEffectScript( uint32_t statusId );
ActionScript* getActionScript( uint32_t actionId );
- QuestScript* getQuestScript( uint32_t questId );
+ EventScript* getEventScript( uint32_t questId );
BattleNpcScript* getBattleNpcScript( uint32_t npcId );
ZoneScript* getZoneScript( uint32_t zoneId );
diff --git a/src/servers/Server_Zone/Script/ScriptInfo.h b/src/servers/Server_Zone/Script/ScriptInfo.h
index 2c4560ec..a81f7570 100644
--- a/src/servers/Server_Zone/Script/ScriptInfo.h
+++ b/src/servers/Server_Zone/Script/ScriptInfo.h
@@ -13,17 +13,19 @@ typedef void* ModuleHandle;
namespace Core {
namespace Scripting {
- class ScriptInfo
- {
- public:
- ScriptInfo() = default;
+ class ScriptInfo
+ {
+ public:
+ ScriptInfo() = default;
- std::string library_name;
- std::string script_name;
- ModuleHandle handle;
- ScriptObject* script;
- ScriptType type;
- };
+ std::string library_name;
+ std::string library_path;
+
+ std::string script_name;
+ ModuleHandle handle;
+ ScriptObject* script;
+ ScriptType type;
+ };
}
}
diff --git a/src/servers/Server_Zone/Script/ScriptLoader.cpp b/src/servers/Server_Zone/Script/ScriptLoader.cpp
index 159f6e12..9e08e52a 100644
--- a/src/servers/Server_Zone/Script/ScriptLoader.cpp
+++ b/src/servers/Server_Zone/Script/ScriptLoader.cpp
@@ -1,11 +1,15 @@
#include "ScriptLoader.h"
#include
+#include
+#include "ServerZone.h"
+
#include
#include
#include
extern Core::Logger g_log;
+extern Core::ServerZone g_serverZone;
Core::Scripting::ScriptLoader::ScriptLoader()
{}
@@ -51,11 +55,16 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st
return nullptr;
}
+ // copy to temp dir
+ boost::filesystem::path cacheDir( f.parent_path() /= g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.CachePath", "./cache/" ) );
+ boost::filesystem::create_directories( cacheDir );
+ boost::filesystem::path dest( cacheDir /= f.filename().string() );
+ boost::filesystem::copy_file( f, dest, boost::filesystem::copy_option::overwrite_if_exists );
#ifdef _WIN32
- ModuleHandle handle = LoadLibrary( path.c_str() );
+ ModuleHandle handle = LoadLibrary( dest.string().c_str() );
#else
- ModuleHandle handle = dlopen( path.c_str(), RTLD_LAZY );
+ ModuleHandle handle = dlopen( dest.string().c_str(), RTLD_LAZY );
#endif
if( !handle )
@@ -70,6 +79,7 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st
auto info = new ScriptInfo;
info->handle = handle;
info->library_name = f.stem().string();
+ info->library_path = dest.string();
m_scriptMap.insert( std::make_pair( f.stem().string(), info ) );
@@ -110,10 +120,18 @@ bool Core::Scripting::ScriptLoader::unloadScript( ModuleHandle handle )
{
if( it->second->handle == handle )
{
- delete it->second;
+ auto info = it->second;
m_scriptMap.erase( it );
- return unloadModule( handle );
+ if( unloadModule( handle ) )
+ {
+ // remove cached file
+ boost::filesystem::remove( info->library_path );
+
+ return true;
+ }
+
+ return false;
}
}
diff --git a/src/servers/Server_Zone/Script/ScriptManager.cpp b/src/servers/Server_Zone/Script/ScriptManager.cpp
index 0b2b57e1..0ee843e6 100644
--- a/src/servers/Server_Zone/Script/ScriptManager.cpp
+++ b/src/servers/Server_Zone/Script/ScriptManager.cpp
@@ -39,15 +39,13 @@ bool Core::Scripting::ScriptManager::init()
{
std::set< std::string > files;
- loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.ScriptPath", "./compiledscripts/" ),
+ loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ),
files, m_nativeScriptManager->getModuleExtension() );
for( auto itr = files.begin(); itr != files.end(); ++itr )
{
auto& path = *itr;
- g_log.debug( "got module: " + path );
-
m_nativeScriptManager->loadScript( path );
}
@@ -124,7 +122,7 @@ bool Core::Scripting::ScriptManager::onTalk( Entity::Player& player, uint64_t ac
scriptId = EVENTSCRIPT_AETHERNET_ID;
}
- auto script = m_nativeScriptManager->getQuestScript( scriptId );
+ auto script = m_nativeScriptManager->getEventScript( scriptId );
if( script )
{
player.sendDebug( "Calling: " + objName + "." + eventName );
@@ -159,11 +157,11 @@ bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, u
std::string eventName = "onEnterTerritory";
std::string objName = Event::getEventName( eventId );
- auto script = m_nativeScriptManager->getZoneScript( player.getZoneId() );
+ player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) );
+
+ auto script = m_nativeScriptManager->getEventScript( eventId );
if( script )
{
- player.sendDebug( "Calling: " + objName + "." + eventName );
-
player.eventStart( player.getId(), eventId, Event::Event::EnterTerritory, 0, player.getZoneId() );
script->onEnterZone( player, eventId, param1, param2 );
@@ -179,30 +177,22 @@ bool Core::Scripting::ScriptManager::onEnterTerritory( Entity::Player& player, u
bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint32_t eventId, uint32_t param1,
float x, float y, float z )
{
-// std::string eventName = "onWithinRange";
-// std::string objName = Event::getEventName( eventId );
-//
-// try
-// {
-// // Get object from engine
-// auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) );
-//
-// player.sendDebug( "Calling: " + objName + "." + eventName );
-//
-// player.eventStart( player.getId(), eventId, Event::Event::WithinRange, 1, param1 );
-//
-// auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, uint32_t,
-// float, float, float ) > >( eventName );
-// fn( obj, eventId, player, param1, x, y, z );
-//
-// player.checkEvent( eventId );
-// }
-// catch( std::exception& e )
-// {
-// player.sendDebug( e.what() );
-// return false;
-// }
-// return true;
+
+ std::string eventName = "onWithinRange";
+ std::string objName = Event::getEventName( eventId );
+ player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) + " p1: " + std::to_string( param1 ) );
+
+ auto script = m_nativeScriptManager->getEventScript( eventId );
+ if( script )
+ {
+ player.eventStart( player.getId(), eventId, Event::Event::WithinRange, 1, param1 );
+
+ script->onWithinRange( player, eventId, param1, x, y, z );
+
+ player.checkEvent( eventId );
+
+ return true;
+ }
return false;
}
@@ -210,30 +200,21 @@ bool Core::Scripting::ScriptManager::onWithinRange( Entity::Player& player, uint
bool Core::Scripting::ScriptManager::onOutsideRange( Entity::Player& player, uint32_t eventId, uint32_t param1,
float x, float y, float z )
{
-// std::string eventName = "onOutsideRange";
-// std::string objName = Event::getEventName( eventId );
-//
-// try
-// {
-// // Get object from engine
-// auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) );
-//
-// player.sendDebug( "Calling: " + objName + "." + eventName );
-//
-// player.eventStart( player.getId(), eventId, Event::Event::OutsideRange, 1, param1 );
-//
-// auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&, uint32_t,
-// float, float, float ) > >( eventName );
-// fn( obj, eventId, player, param1, x, y, z );
-//
-// player.checkEvent( eventId );
-// }
-// catch( std::exception& e )
-// {
-// player.sendDebug( e.what() );
-// return false;
-// }
-// return true;
+ std::string eventName = "onOutsideRange";
+ std::string objName = Event::getEventName( eventId );
+ player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) );
+
+ auto script = m_nativeScriptManager->getEventScript( eventId );
+ if( script )
+ {
+ player.eventStart( player.getId(), eventId, Event::Event::WithinRange, 1, param1 );
+
+ script->onOutsideRange( player, eventId, param1, x, y, z );
+
+ player.checkEvent( eventId );
+
+ return true;
+ }
return false;
}
@@ -244,7 +225,7 @@ bool Core::Scripting::ScriptManager::onEmote( Entity::Player& player, uint64_t a
std::string eventName = "onEmote";
std::string objName = Event::getEventName( eventId );
- auto script = m_nativeScriptManager->getQuestScript( eventId );
+ auto script = m_nativeScriptManager->getEventScript( eventId );
if( script )
{
player.sendDebug( "Calling: " + objName + "." + eventName );
@@ -321,20 +302,13 @@ bool Core::Scripting::ScriptManager::onEventHandlerReturn( Entity::Player& playe
bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId,
uint16_t subEvent, uint16_t param, uint32_t catalogId )
{
-// std::string eventName = Event::getEventName( eventId ) + "_TRADE";
-//
-// try
-// {
-// auto fn = m_pChaiHandler->eval< std::function< void( Entity::Player&, uint32_t,
-// uint16_t, uint16_t, uint32_t ) > >( eventName );
-// fn( player, eventId, subEvent, param, catalogId );
-// }
-// catch( ... )
-// {
-// return false;
-// }
-//
-// return true;
+ auto script = m_nativeScriptManager->getEventScript( eventId );
+ if( script )
+ {
+ script->onEventHandlerTradeReturn( player, eventId, subEvent, param, catalogId );
+
+ return true;
+ }
return false;
}
@@ -342,28 +316,20 @@ bool Core::Scripting::ScriptManager::onEventHandlerTradeReturn( Entity::Player&
bool Core::Scripting::ScriptManager::onEventItem( Entity::Player& player, uint32_t eventItemId,
uint32_t eventId, uint32_t castTime, uint64_t targetId )
{
-// std::string eventName = "onEventItem";
-// std::string objName = Event::getEventName( eventId );
-//
-// try
-// {
-// auto obj = m_pChaiHandler->eval( Event::getEventName( eventId ) );
-//
-// player.sendDebug( "Calling: " + objName + "." + eventName );
-//
-// player.eventStart( targetId, eventId, Event::Event::Item, 0, 0 );
-//
-// auto fn = m_pChaiHandler->eval< std::function< void( chaiscript::Boxed_Value &, uint32_t, Entity::Player&,
-// uint32_t, uint32_t, uint64_t ) > >( eventName );
-// fn( obj, eventId, player, eventItemId, castTime, targetId );
-// }
-// catch( std::exception& e )
-// {
-// player.sendNotice( e.what() );
-// return false;
-// }
-//
-// return true;
+ std::string eventName = "onEventItem";
+ std::string objName = Event::getEventName( eventId );
+ player.sendDebug( "Calling: " + objName + "." + eventName + " - " + std::to_string( eventId ) );
+
+ auto script = m_nativeScriptManager->getEventScript( eventId );
+ if( script )
+ {
+ player.eventStart( targetId, eventId, Event::Event::Item, 0, 0 );
+
+ script->onEventItem( player, eventItemId, eventId, castTime, targetId );
+
+ return true;
+ }
+
return false;
}
@@ -381,7 +347,7 @@ bool Core::Scripting::ScriptManager::onMobKill( Entity::Player& player, uint16_t
uint16_t questId = activeQuests->c.questId;
- auto script = m_nativeScriptManager->getQuestScript( questId );
+ auto script = m_nativeScriptManager->getEventScript( questId );
if( script )
{
std::string objName = Event::getEventName( 0x00010000 | questId );