// PLUGIN_API is only to be used for callbacks. All existing callbacks at this time
// are shown below. Remove the ones your plugin does not use. Always use Initialize
// and Shutdown for setup and cleanup, do NOT do it in DllMain.
#include "../MQ2Plugin.h"
PreSetup("MQ2Reward");
VOID AutoReward(PSPAWNINFO pChar, PCHAR szLine);
VOID AcceptReward(CXWnd *pWnd);
CHAR szBuffer[MAX_STRING] = {0};
bool debug = false;
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
DebugSpewAlways("Initializing MQ2Reward");
AddCommand("/reward",AutoReward);
}
// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
DebugSpewAlways("Shutting down MQ2Reward");
RemoveCommand("/reward");
}
VOID AutoReward(PSPAWNINFO pChar, PCHAR szLine)
{
CHAR szArg1[MAX_STRING] = {0};
CHAR szArg2[MAX_STRING] = {0};
GetArg(szArg1, szLine, 1);
int arg1 = atoi(szArg1) - 1;
CHAR cxStr[MAX_STRING] = {0};
CXStr Str;
if (arg1 < 0) {
sprintf(szBuffer, "Illegal option index: '%s'.", szArg1);
WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
return;
}
CHAR descr[MAX_STRING] = {0};
sprintf(descr, "option index: %s", szArg1);
if (debug) {
sprintf(szBuffer, "Trying to find reward at %s.", descr);
WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
}
// Parent TabWindow PageTemplate
CXWnd *pWnd1 = (CXWnd*)FindMQ2Window("RewardSelectionWnd")->pFirstChildWnd->pFirstChildWnd;
BOOL found = false;
while (pWnd1) {
if (((PCSIDLWND)pWnd1)->Show) {
CListWnd *pListOpt = (CListWnd*)((CSidlScreenWnd*)(pWnd1->GetChildItem("RewardSelectionOptionList")));
pListOpt->SetCurSel(arg1);
AcceptReward(pWnd1);
found = true;
}
pWnd1 = (CXWnd*)pWnd1->pNextSiblingWnd;
}
if ( ! found )
{
sprintf(szBuffer, "Could not find reward at %s.", descr);
WriteChatColor(szBuffer,USERCOLOR_DEFAULT);
}
}
VOID AcceptReward(CXWnd *pWnd)
{
if (debug) {
WriteChatColor("Clicking 'Select Option' button.",USERCOLOR_DEFAULT);
}
CXWnd *pButton = pWnd->GetChildItem("RewardSelectionChooseButton");
CXRect rect = pButton->GetScreenRect();
CXPoint pt = rect.CenterPoint();
pButton->HandleLButtonDown(&pt,0);
pButton->HandleLButtonUp(&pt,0);
}