#pragma once#include "stdafx.h"
#include "GoldPotionSystem.h"
#include "memory.h"
#include "GlobalStaticData.h"
CGoldPotionSystem g_GoldPotionSystem;
typedef void(WINAPI* CPlayer__AddDalant2)(CPlayer *_this, unsigned int dwPush, bool bApply);
CPlayer__AddDalant2 AddDalant2 = (CPlayer__AddDalant2)0x140055B00;
typedef void(WINAPI* CPlayer__AddGold2)(CPlayer *_this, unsigned int dwPush, bool bApply);
CPlayer__AddGold2 AddGold2 = (CPlayer__AddGold2)0x140055D30;
typedef void(WINAPI* CPlayer__AlterPvPCashBag2)(CPlayer *_this, long double dAlter, PVP_MONEY_ALTER_TYPE IOCode);
CPlayer__AlterPvPCashBag2 AlterPvPCashBag2 = (CPlayer__AlterPvPCashBag2)0x14005F990;
typedef int(WINAPI* Emb_AlterDurPoint)(CPlayer *_this, char byStorageCode, char byStorageIndex, int nAlter, bool bUpdate, bool bSend);
Emb_AlterDurPoint AlterDurPoint = (Emb_AlterDurPoint)0x140058A80;
typedef bool(WINAPI* CPlayer__SendMsg_AlterMoneyInform2)(CPlayer *_this, char byReasonCode);
CPlayer__SendMsg_AlterMoneyInform2 SendMsg_AlterMoneyInform2 = (CPlayer__SendMsg_AlterMoneyInform2)0x1400DF070;
typedef void(WINAPI* p_UsePotionItem)(CPlayer *_this, CPlayer *pTargetPlayer, _STORAGE_POS_INDIV *pItem);
p_UsePotionItem UsePotionItem = (p_UsePotionItem)0x1400AD4D0;
void CGoldPotionSystem::Initialize()
{
int LootNum,i;
char* LootStr="PotIndex%d";
char* MoneyMinStr="MoneyMin%d";
char* MoneyMaxStr="MoneyMax%d";
char* MoneyTypeStr="MoneyType%d";
char str[255];
INode2 tempStr;
this->Loot.clear();
LootNum = GetPrivateProfileIntA("Pot", "PotNum", 0, ".\\DLL\\GoldPotionSystem.ini");
for(i=0;i<LootNum;i++)
{
sprintf(str,LootStr,i);
tempStr.ItemIndex=GetPrivateProfileIntA("Pot", str, 0, ".\\DLL\\GoldPotionSystem.ini");
sprintf(str,MoneyMinStr,i);
tempStr.MoneyMin=GetPrivateProfileIntA("Pot", str, 0, ".\\DLL\\GoldPotionSystem.ini");
sprintf(str,MoneyMaxStr,i);
tempStr.MoneyMax=GetPrivateProfileIntA("Pot", str, 0, ".\\DLL\\GoldPotionSystem.ini");
sprintf(str,MoneyTypeStr,i);
tempStr.MoneyType=GetPrivateProfileIntA("Loot", str, 0, ".\\DLL\\GoldPotionSystem.ini");
this->Loot.push_back(tempStr);
}
WriteInstruction(0x140012ED6,(INT64)CPlayer__pc_UsePotionItem,0,0xE9);
}
int CGoldPotionSystem::SearchItem(unsigned int ItemIndex)
{
for(int i=0;i<this->Loot.size();i++)
{
if(this->Loot[i].ItemIndex==ItemIndex)
return i;
}
return -1;
}
#define RAND_MAX 2000000000
void __cdecl CPlayer__pc_UsePotionItem(CPlayer *_this, CPlayer *pTargetPlayer, _STORAGE_POS_INDIV *pItem)
{
_STORAGE_LIST::_db_con *pPotItem;
pPotItem = GetPtrFromSerial(&_this->m_Param.m_dbInven,pItem->wItemSerial);
int Index=g_GoldPotionSystem.SearchItem(pPotItem->m_wItemIndex);
if(Index!=-1)
{
srand(static_cast<unsigned>(time(0)));
//DWORD dwMoney = (GoldPotionSystem.Loot[Index].MoneyMin + (rand() % (GoldPotionSystem.Loot[Index].MoneyMax - GoldPotionSystem.Loot[Index].MoneyMin)))*pBox->m_Item.m_dwDur;
DWORD dwMoney = ((rand() * rand()) % (g_GoldPotionSystem.Loot[Index].MoneyMax - g_GoldPotionSystem.Loot[Index].MoneyMin)+g_GoldPotionSystem.Loot[Index].MoneyMin);
switch(g_GoldPotionSystem.Loot[Index].MoneyType)
{
case 0:
{
AddDalant2(_this,dwMoney,true);
SendMsg_AlterMoneyInform2(_this,0);break;
}
case 1:
{
AddGold2(_this,dwMoney,true);
SendMsg_AlterMoneyInform2(_this,0);break;
}
case 2:
{
AlterPvPCashBag2(_this,(long double)dwMoney,pm_kill);
break;
}
}
//AlterDurPoint(_this,pItem->byStorageCode,pItem->wItemSerial,-1,true,true);
UsePotionItem(_this,pTargetPlayer,pItem);
}
else
{
UsePotionItem(_this,pTargetPlayer,pItem);
}
}