Reputation: 23
Lets say I have to patch few files of the core, example:
src/server/game/Handlers/MiscHandler.cpp
+code line 1
+code line 2
+code line 3
src/server/game/Handlers/ChatHandler.cpp
+code line 1
+code line 2
+code line 3
Can I implement these patches into a module? If it's possible, could you please post an example, how can be done, so I can get the idea?
Thank you!
Just to mention that I've already seen the module skeleton repo, I can see that there is a src/ folder with two files - loader.h and Player.cpp, but other than than, not sure how proceed.
Upvotes: 1
Views: 1562
Reputation: 61994
Yes, it's possible. When writing a module you use the existing hooks that are available in AzerothCore. If you need a hook that is not existing yet, you can simply create it and send a PR to AzerothCore.
I needed to create a very simple module that sends the player a warning whenever he/she leaves the BG queue after being invited to join.
This is the code of my module, very basic:
void OnBattlegroundDesertion(Player* player, const BattlegroundDesertionType type) override
{
if (sConfigMgr->GetBoolDefault(DESERTION_ENABLED_CONFIG, false))
{
switch (type)
{
case BG_DESERTION_TYPE_LEAVE_QUEUE:
case BG_DESERTION_TYPE_NO_ENTER_BUTTON:
ChatHandler(player->GetSession()).PSendSysMessage("%s", sConfigMgr->GetStringDefault(WARNING_TEXT_CONFIG, "").c_str());
break;
default:
break;
}
}
}
the full source code of the module is available here: https://github.com/azerothcore/mod-desertion-warnings
Looks very easy right? Especially if you had that OnBattlegroundDesertion
method that gave me what I needed (the Player
and the BattlegroundDesertionType
).
There was only one problem... the hook OnBattlegroundDesertion
didn't exist before!
But it's ok, I just had to implement it in the core, and this is the PR that does the job:
https://github.com/azerothcore/azerothcore-wotlk/pull/4619
As you can see it's just a matter of creating the method in ScriptMgr.h
and ScriptMgr.cpp
(the same way other hook-methods are created) and then call it around the core whenever I needed it.
Upvotes: 0