Commit 758fdd68 authored by Red Bot's avatar Red Bot

crash fix for test

parent 1d49a0ae
......@@ -26,6 +26,7 @@ PreSetup("MQ2ItemDisplay");
#include "ISXEQItemDisplay.h"
#endif
using namespace std;
bool gCompareTip = false;
bool gLootButton = true;
bool gLucyButton = true;
typedef struct _ButtonInfo
......@@ -304,6 +305,117 @@ bool ItemInfoManager::doValidateURI(Window *wnd, const char *uri)
// Function: ItemDisplayHook
// Description: Our Item display hook
// ***************************************************************************
PCONTENTS pOldCont = 0;
class CCompareTipWnd;
CCompareTipWnd *pCompareTipWnd=0;
class CCompareTipWnd : public CSidlScreenWnd
{
public:
CCompareTipWnd(CXStr *screenpiece):CSidlScreenWnd(0,screenpiece,-1,1,0)
{
CreateChildrenFromSidl();
pXWnd()->Show(1,1);
ReplacevfTable();
CloseOnESC=0;
}
CCompareTipWnd(char *screenpiece):CSidlScreenWnd(0,&CXStr(screenpiece),-1,1,0)
{
CreateChildrenFromSidl();
//pXWnd()->Show(1,1);
ReplacevfTable();
CloseOnESC=0;
SetWndNotification(CCompareTipWnd);
Display=(CStmlWnd*)GetChildItem("CT_Display");
this->Faded = true;
this->ZLayer = 100;
this->Alpha = 0xfa;
this->BGColor = 0xFF000000;
this->BGType = 1;
#if !defined(EMU)
this->bClickThrough = 1;
#endif
}
~CCompareTipWnd()
{
RemovevfTable();
}
int WndNotification(CXWnd *pWnd, unsigned int Message, void *unknown)
{
return CSidlScreenWnd::WndNotification(pWnd,Message,unknown);
}
void ReplacevfTable()
{
OldvfTable=((_CSIDLWND*)this)->pvfTable;
PCSIDLWNDVFTABLE NewvfTable=new CSIDLWNDVFTABLE;
memcpy(NewvfTable,OldvfTable,sizeof(CSIDLWNDVFTABLE));
((_CSIDLWND*)this)->pvfTable=NewvfTable;
}
void RemovevfTable()
{
PCSIDLWNDVFTABLE NewvfTable=((_CSIDLWND*)this)->pvfTable;
((_CSIDLWND*)this)->pvfTable=OldvfTable;
delete NewvfTable;
}
void SetvfTable(DWORD index, DWORD value)
{
DWORD* vtable=(DWORD*)((_CSIDLWND*)this)->pvfTable;
vtable[index]=value;
}
/*0x218*/ CStmlWnd *Display;
/*0x22C*/ PCSIDLWNDVFTABLE OldvfTable;
};
int CanIUseThisItem(PITEMINFO pItem)
{
if (PCHARINFO2 pChar2 = GetCharInfo2()) {
if (!pChar2->Class)
return -1;
DWORD ClassMask = (1 << (pChar2->Class - 1));
if ((ClassMask & pItem->Classes) == 0)
return -2;
return 1;
}
return -1;
}
template <unsigned int _Size>char* GetSlots(PITEMINFO pItem,char(&_Buffer)[_Size])
{
DWORD cmp = pItem->EquipSlots;
for (int N = 0; N < 32; N++)
{
if (cmp&(1 << N))
{
strcat_s(_Buffer, _Size, szItemSlot[N]);
strcat_s(_Buffer, _Size, " ");
}
}
return _Buffer;
}
PCONTENTS GetEquippedSlot(PCONTENTS pCont)
{
if (PITEMINFO pItem = GetItemFromContents(pCont))
{
DWORD cmp = pItem->EquipSlots;
for (int N = 0; N < 32; N++)
{
if (cmp&(1 << N))
{
if (PCHARINFO2 pChar2 = GetCharInfo2())
{
if (PCONTENTS pInvSlot = pChar2->pInventoryArray->InventoryArray[N])
{
return pInvSlot;
}
}
}
}
}
return NULL;
}
class ItemDisplayHook
{
typedef enum {None = 0, Clicky, Proc, Worn, Focus, Scroll, Focus2, Mount, Illusion, Familiar} SEffectType;
......@@ -1485,11 +1597,79 @@ public:
}
return AboutToShow_Trampoline();
}
static void PrintItem(PCONTENTS pCont,PCONTENTS pEquipped)
{
if (PITEMINFO pItem = GetItemFromContents(pCont))
{
if (CanIUseThisItem(pItem))
{
if (PITEMINFO pItem2 = GetItemFromContents(pEquipped))
{
CXPoint pt;
pt.X = EQADDR_MOUSE->X + 5;
pt.Y = EQADDR_MOUSE->Y + 5;
((CXWnd *)pCompareTipWnd)->Move(pt);
pCompareTipWnd->ZLayer = 0;
((CStmlWnd*)pCompareTipWnd->Display)->SetSTMLText("", 1, 0);
((CStmlWnd*)pCompareTipWnd->Display)->ForceParseNow();
CHAR szTemp[MAX_STRING] = { 0 };
CHAR szTemp2[MAX_STRING] = { 0 };
DWORD realcolor = 0xFF00FF00;// ConColorToARGB(argbcolor) & 0x00FFFFFF;
sprintf_s(szTemp, "<c \"#FFFF00\">%s<br></c><c \"#FFFFFF\">%s %s </c><br>", pItem->Name, pItem->Lore ? "[Lore]" : "", pItem->NoDrop ? "" : "[No Drop]");
((CStmlWnd*)pCompareTipWnd->Display)->SetSTMLText(szTemp, 1, 0);
sprintf_s(szTemp, "<c \"#FFFF00\">%s<br></c>", GetSlots(pItem, szTemp2));
((CStmlWnd*)pCompareTipWnd->Display)->AppendSTML(szTemp);
DWORD color = 0xFF0000;
int ACStat = pItem->AC - pItem2->AC;
if (ACStat > 0)
color = 0x00FF00;
sprintf_s(szTemp, "<c \"#FFFFFF\">Rec Level: </c><c \"#00FF00\">%d</c><c \"#FFFFFF\">&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;AC: </c><c \"#%06X\">%d</c><br>", pItem->RequiredLevel,color, ACStat);
((CStmlWnd*)pCompareTipWnd->Display)->AppendSTML(szTemp);
((CStmlWnd*)pCompareTipWnd->Display)->ForceParseNow();
pCompareTipWnd->dShow = 1;
}
}
}
}
int CInvSlotWnd_DrawTooltipTramp(const CXWnd *pwnd) const;
int CInvSlotWnd_DrawTooltipDetour(const CXWnd *pwnd) const
{
if (gCompareTip)
{
if (CInvSlotWnd*wnd = (CInvSlotWnd*)this)
{
PCONTENTS pCont = 0;
if (wnd->pEQInvSlot) {
wnd->pEQInvSlot->GetItemBase(&pCont);
}
if (pCont && pCont != pOldCont) {
pOldCont = pCont;
if (PITEMINFO pItem = GetItemFromContents(pCont))
{
if (pCompareTipWnd && pCompareTipWnd->Display)
{
if (PCONTENTS pEquipped = GetEquippedSlot(pCont))
{
PrintItem(pCont, pEquipped);
}
}
WriteChatf("CInvSlotWnd_DrawTooltipDetour called for %s", pItem->Name);
}
}
}
}
return CInvSlotWnd_DrawTooltipTramp(pwnd);
}
};
ItemDisplayHook::SEffectType ItemDisplayHook::eEffectType = None;
bool ItemDisplayHook::bNoSpellTramp = false;
DETOUR_TRAMPOLINE_EMPTY(int ItemDisplayHook::CInvSlotWnd_DrawTooltipTramp(const CXWnd *pwnd) const);
DETOUR_TRAMPOLINE_EMPTY(int ItemDisplayHook::WndNotification_Trampoline(CXWnd*, unsigned __int32, void*));
DETOUR_TRAMPOLINE_EMPTY(bool ItemDisplayHook::AboutToShow_Trampoline(void));
#ifdef EMU
......@@ -1542,8 +1722,6 @@ void ItemDisplayCmd(PSPAWNINFO pChar, PCHAR szLine)
WriteChatf("Usage: /itemdisplay LucyButton optional:off/on");
return;
}
CHAR Filename[MAX_STRING] = {0};
sprintf_s(Filename,"%s\\MacroQuest.ini",gszINIPath);
CHAR szArg1[MAX_STRING] = { 0 };
CHAR szArg2[MAX_STRING] = { 0 };
......@@ -1568,7 +1746,7 @@ void ItemDisplayCmd(PSPAWNINFO pChar, PCHAR szLine)
}
WriteChatf("Display of the %s is now \ay%s\ax.",szArg1, (gLootButton ? "Enabled" : "Disabled"));
_itoa_s(gLootButton, szArg1, 10);
WritePrivateProfileString("ItemDisplay","LootButton",szArg1,Filename);
WritePrivateProfileString("Settings","LootButton",szArg1,INIFileName);
for (std::map<CButtonWnd*, ButtonInfo>::iterator i = ButtonMap.begin(); i != ButtonMap.end();) {
if (i->second.ID == 1) {
i->first->Destroy();
......@@ -1590,7 +1768,7 @@ void ItemDisplayCmd(PSPAWNINFO pChar, PCHAR szLine)
}
WriteChatf("Display of the %s is now \ay%s\ax.",szArg1, (gLucyButton ? "Enabled" : "Disabled"));
_itoa_s(gLucyButton, szArg1, 10);
WritePrivateProfileString("ItemDisplay","LucyButton",szArg1,Filename);
WritePrivateProfileString("Settings","LucyButton",szArg1,INIFileName);
for (std::map<CButtonWnd*, ButtonInfo>::iterator i = ButtonMap.begin(); i != ButtonMap.end();) {
if (i->second.ID == 2) {
i->first->Destroy();
......@@ -1604,6 +1782,16 @@ void ItemDisplayCmd(PSPAWNINFO pChar, PCHAR szLine)
}
}
}
else if (!_stricmp(szArg1, "Compare")) {
if (bToggle) {
gCompareTip = !gCompareTip;
}else {
gCompareTip = bon;
}
WriteChatf("Display of Compare Tip is now \ay%s\ax.", (gCompareTip ? "Enabled" : "Disabled"));
_itoa_s(gCompareTip, szArg1, 10);
WritePrivateProfileString("Settings","CompareTip",szArg1,INIFileName);
}
}
void AddLootFilter(PSPAWNINFO pChar, PCHAR szLine)
{
......@@ -2648,28 +2836,14 @@ template <unsigned int _Size> void AddGearScores_CheckItems(PCONTENTS pSlot,ITEM
}
}
int CanIUseThisItem(PCONTENTS pSlot, ITEMINFO *pItem)
{
if (PCHARINFO2 pChar2 = GetCharInfo2()) {
if (!pChar2->Class)
return -1;
DWORD ClassMask = (1 << (pChar2->Class - 1));
if ((ClassMask & pItem->Classes) == 0)
return -2;
return 1;
}
return -1;
}
template <unsigned int _Size> void AddGearScores(PCONTENTS pSlot,ITEMINFO *pItem, CHAR(&out)[_Size],char *br)
template <unsigned int _Size> void AddGearScores(PCONTENTS pSlot,PITEMINFO pItem, CHAR(&out)[_Size],char *br)
{
static ULONGLONG lastTick = 0;
ReportBestStr[0] = 0;
ReportBestSlot[0] = 0;
ReportBestName[0] = 0;
if (CanIUseThisItem(pSlot,pItem)<1) return ;
if (CanIUseThisItem(pItem)<1)
return;
ClearAttribListScores();
CurrScore = CalcItemGearScore(pItem);
......@@ -2700,6 +2874,33 @@ template <unsigned int _Size> void AddGearScores(PCONTENTS pSlot,ITEMINFO *pItem
}
}
VOID DestroyCompareTipWnd()
{
if (pCompareTipWnd)
{
//SaveWindowSettings((PCSIDLWND)pCompareTipWnd);
delete pCompareTipWnd;
pCompareTipWnd=0;
}
}
void CreateCompareTipWnd()
{
try {
if (pCompareTipWnd) {
return;
}
if (pSidlMgr->FindScreenPieceTemplate("CompareTipWnd")) {
if(pCompareTipWnd = new CCompareTipWnd("CompareTipWnd")) {
Sleep(0);
//LoadWindowSettings((PCSIDLWND)pToolTipWnd);
}
}
}
catch(...) {
MessageBox(NULL,"CRAP! in CreateCompareTipWnd","An exception occured",MB_OK);
}
}
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
......@@ -2712,6 +2913,7 @@ PLUGIN_API VOID InitializePlugin(VOID)
pGearScoreType = new MQ2GearScoreType;
gLootButton = 1==GetPrivateProfileInt("Settings","LootButton",1,INIFileName);
gLucyButton = 1==GetPrivateProfileInt("Settings","LucyButton",1,INIFileName);
gCompareTip = 1==GetPrivateProfileInt("Settings","CompareTip",0,INIFileName);
#ifndef EMU
EzDetourwName(CItemDisplayWnd__WndNotification,&ItemDisplayHook::WndNotification_Detour,&ItemDisplayHook::WndNotification_Trampoline,"CItemDisplayWnd__WndNotification");
......@@ -2732,8 +2934,16 @@ PLUGIN_API VOID InitializePlugin(VOID)
pDisplayItemType = new MQ2DisplayItemType;
AddMQ2Data("DisplayItem", dataLastItem);
AddMQ2Data("GearScore",dataGearScore);
AddXMLFile("MQUI_CompareTipWnd.xml");
EzDetourwName(CInvSlotWnd__DrawTooltip, &ItemDisplayHook::CInvSlotWnd_DrawTooltipDetour, &ItemDisplayHook::CInvSlotWnd_DrawTooltipTramp,"CInvSlotWnd__DrawTooltip");
if (gGameState == GAMESTATE_INGAME)
ReadProfile(GetCharInfo()->Name,FALSE);
{
ReadProfile(GetCharInfo()->Name, FALSE);
CreateCompareTipWnd();
}
}
PLUGIN_API VOID SetGameState(DWORD GameState)
......@@ -2748,6 +2958,7 @@ PLUGIN_API VOID ShutdownPlugin(VOID)
DebugSpewAlways("Shutting down MQ2ItemDisplay");
// Remove commands, macro parameters, hooks, etc.
RemoveDetour(CInvSlotWnd__DrawTooltip);
RemoveDetour(CItemDisplayWnd__SetSpell);
RemoveDetour(CItemDisplayWnd__UpdateStrings);
#ifndef EMU
......@@ -2778,6 +2989,7 @@ PLUGIN_API VOID ShutdownPlugin(VOID)
CloseHandle(hDisplayItemLock);
hDisplayItemLock = 0;
}
DestroyCompareTipWnd();
}
PLUGIN_API void OnCleanUI()
{
......@@ -2787,6 +2999,7 @@ PLUGIN_API void OnCleanUI()
}
ButtonMap.clear();
#endif
DestroyCompareTipWnd();
}
PLUGIN_API void OnReloadUI()
......@@ -2797,6 +3010,9 @@ PLUGIN_API void OnReloadUI()
}
ButtonMap.clear();
#endif
if (GetGameState() == GAMESTATE_INGAME && pCharSpawn) {
CreateCompareTipWnd();
}
}
#define LINK_LEN 55
......@@ -2839,5 +3055,12 @@ PLUGIN_API DWORD OnIncomingChat(PCHAR Line, DWORD Color)
}
}
return 0;
}
}
PLUGIN_API VOID OnPulse(VOID)
{
if (GetGameState() == GAMESTATE_INGAME)
{
CreateCompareTipWnd();
}
}
#endif
......@@ -162,7 +162,6 @@ int __cdecl GetLabelFromEQ_Detour(int EQType, class CXStr *out, bool *arg3, unsi
}
return ret;
}
BOOL bTrimnames = 0;
// CLabelHook::Draw_Detour
class CLabelHook {
......
......@@ -1750,37 +1750,39 @@ EQLIB_OBJECT void CContextMenuManager::CreateDefaultMenu(void);
class CScreenPieceTemplate
{
public:
PVOID vfTable;
ArrayClass2_RO<unsigned __int32> RuntimeTypes;
PCXSTR Name;
unsigned __int32 ParamObjectID;
PCXSTR ScreenID;
unsigned __int32 Font;
bool bRelativePosition;
bool bAutoStretchVertical;
bool bAutoStretchHorizontal;
bool bTopAnchorToTop;
bool bBottomAnchorToTop;
bool bLeftAnchorToLeft;
bool bRightAnchorToLeft;
int TopOffset;
int BottomOffset;
int LeftOffset;
int RightOffset;
int MinVSize;
int MinHSize;
int MaxVSize;
int MaxHSize;
RECT Rect;
PCXSTR Text;
D3DCOLOR TextColor;
D3DCOLOR DisabledColor;
D3DCOLOR EnabledColor;
bool bUseInLayoutHorizontal;
bool bUseInLayoutVertical;
D3DCOLOR BackgroundTextureTint;
D3DCOLOR DisabledBackgroundTextureTint;
/*0x00*/ PVOID vfTable;
/*0x04*/ ArrayClass2_RO<unsigned __int32> RuntimeTypes;
/*0x20*/ PCXSTR Name;
/*0x24*/ unsigned __int32 ParamObjectID;
/*0x28*/ PCXSTR ScreenID;
/*0x2c*/ unsigned __int32 Font;
/*0x30*/ bool bRelativePosition;
/*0x31*/ bool bAutoStretchVertical;
/*0x32*/ bool bAutoStretchHorizontal;
/*0x33*/ bool bTopAnchorToTop;
/*0x34*/ bool bBottomAnchorToTop;
/*0x35*/ bool bLeftAnchorToLeft;
/*0x36*/ bool bRightAnchorToLeft;
/*0x38*/ int TopOffset;
/*0x3c*/ int BottomOffset;
/*0x40*/ int LeftOffset;
/*0x44*/ int RightOffset;
/*0x48*/ int MinVSize;
/*0x4c*/ int MinHSize;
/*0x50*/ int MaxVSize;
/*0x54*/ int MaxHSize;
/*0x58*/ RECT Rect;
/*0x68*/ PCXSTR Text;
/*0x6c*/ D3DCOLOR TextColor;
/*0x70*/ D3DCOLOR DisabledColor;
/*0x74*/ D3DCOLOR EnabledColor;
/*0x78*/ bool bUseInLayoutHorizontal;
/*0x79*/ bool bUseInLayoutVertical;
/*0x7c*/ D3DCOLOR BackgroundTextureTint;
#if !defined(EMU)
/*0x80*/ D3DCOLOR DisabledBackgroundTextureTint;
/*0x84*/
#endif
EQLIB_OBJECT CScreenPieceTemplate::CScreenPieceTemplate(class CParamScreenPiece *);
EQLIB_OBJECT bool CScreenPieceTemplate::IsType(unsigned __int32)const;
EQLIB_OBJECT class CXStr CScreenPieceTemplate::GetName(void)const;
......@@ -1793,19 +1795,22 @@ EQLIB_OBJECT CScreenPieceTemplate::~CScreenPieceTemplate(void);
class CControlTemplate : public CScreenPieceTemplate
{
public:
unsigned __int32 StyleBits;
BYTE SizableMask;
bool bEscapable;
PCXSTR Tooltip;
CXWndDrawTemplate *pDrawTemplate;
PCXSTR Controller;
void *pLayoutStrategyTemplate;//CLayoutStrategyTemplate
/*0x84*/ unsigned __int32 StyleBits;
/*0x88*/ BYTE SizableMask;
/*0x89*/ bool bEscapable;
/*0x8c*/ PCXSTR Tooltip;
/*0x90*/ CXWndDrawTemplate *pDrawTemplate;
/*0x94*/ PCXSTR Controller;
/*0x98*/ void *pLayoutStrategyTemplate;//CLayoutStrategyTemplate
/*0x9c*/
EQLIB_OBJECT CControlTemplate::CControlTemplate(class CParamControl *);
// virtual
EQLIB_OBJECT CControlTemplate::~CControlTemplate(void);
//EQLIB_OBJECT void * CControlTemplate::`scalar deleting destructor'(unsigned int);
//EQLIB_OBJECT void * CControlTemplate::`vector deleting destructor'(unsigned int);
};
class HasATimer
{
UINT Timer;
......@@ -3402,38 +3407,40 @@ EQLIB_OBJECT CKeyCXStrValueInt32::CKeyCXStrValueInt32(void);
//size 0x200 see 8D5699 in Aug 10 2017 Live -eqmule
//size 0x210 see 8DCE59 in Sep 11 2017 Test -eqmule
//size 0x200 see 668D5B in Oct 17 2017 Live -eqmule
//size 0x1e4 see 86BFC9 in rof2 -eqmule
class CLabelWnd// : public CXWnd
{
public:
EQLIB_OBJECT CLabelWnd::CLabelWnd(CXWnd *pParent, unsigned __int32 ID, const CXRect *rect);
/*0x000*/ PCXWNDVFTABLE pvfTable;
/*0x004*/ CXW_NO_VTABLE
/*0x1e0*/ bool bNoWrap;
/*0x1e1*/ bool bAlignRight;
/*0x1e2*/ bool bAlignCenter;
/*0x1e4*/ int xOffset;
/*0x1e8*/ bool bResizeHeightToText;
/*0x004*/ CXW_NO_VTABLE //rof2
/*0x1e0*/ bool bNoWrap; /*0x1d8*/
/*0x1e1*/ bool bAlignRight; /*0x1d9*/
/*0x1e2*/ bool bAlignCenter; /*0x1da*/
/*0x1e4*/ int xOffset; /*0x1dc*/
/*0x1e8*/ bool bResizeHeightToText; /*0x1e0*/
#ifndef EMU
/*0x1ec*/ int Unknown0x1ec;
/*0x1f0*/ PCXSTR Text;
/*0x1f4*/ int Unknown0x1f4;
/*0x1f8*/ bool Unknown0x1f8;
/*0x1fc*/ int Unknown0x1fc;
/*0x200*/
/*0x200*/ /*0x1e4*/
#endif
};
//CLabel__CLabel_x
//size is 0x208 see 79C989 in Aug 10 2017 Live -eqmule
//size is 0x218 see 7A3819 in Sep 11 2017 Test -eqmule
//size 0x208 see 7A5739 in Oct 17 2017 Live -eqmule
//size 0x1e8 see 755709 in Rof2 -eqmule
class CLabel : public CLabelWnd
{
public:
/*0x200*/ int EQType;
public: //rof2
/*0x200*/ int EQType; /*0x1e4*/
#ifndef EMU
/*0x204*/ int Unknown0x204;
#endif
/*0x208*/
/*0x208*/ /*0x1e8*/
EQLIB_OBJECT CLabel::CLabel(class CXWnd *pParent,unsigned __int32 id,CXRect *rect,int eqtype = 0);
EQLIB_OBJECT void CLabel::SetAlignCenter(bool);
EQLIB_OBJECT void CLabel::SetAlignRight(bool);
......
......@@ -97,7 +97,7 @@ extern CRITICAL_SECTION gPluginCS;
//we default to LIVE though...
#else
//define LIVE, TEST, BETA or EMU here depending on which eqgame you are building for. -eqmule sep 27 2014
#define LIVE
#define TEST
#endif
#if defined(LIVE)
#include "eqgame.h"
......
......@@ -43,7 +43,7 @@ GNU General Public License for more details.
#define __AC2_x 0x5C3F0F
#define __AC3_x 0x5CAD9F
#define __AC4_x 0x5CEC20
#define __AC5_x 0x5D4E50
#define __AC5_x 0x5D4E60
#define __AC6_x 0x5D93A2
#define __AC7_x 0x5C3980
#define __AC1_Data 0x11111111
......
Jun 18 2018 by eqmule
- Added support for emu mq2labels plugin
Jun 16 2018 by eqmule
- Fixed a bug for TEST
Jun 13 2018 by eqmule
- Fixed ITEMINFO for TEST
- Fixed invslot charm
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment