Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Need help with Dll

Newbie Spellweaver
Joined
Jul 2, 2016
Messages
93
Reaction score
9
Can someone take a look and tell me if the way I am trying to hook this is possible? Maybe help me a out a little.

Code:
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <Windows.h>
//#include <detours.h>
#include <vector>
#include <io.h>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <string>


#pragma comment(lib, "LunaLib.lib")
#include <KServer.h>
#include <KPlayer.h>
#include <KItem.h>
#include <LunaCore.h>


#pragma pack(1)


struct SItem {
	int Index;
	int Str;
	int Hp;
	int Int;
	int Wis;
	int Agi;
	int Pwr;
	int Explo;
	int PerEva;
	int PerDef;
	int DmgRed;
	int Acc;
	int Eva;
	int Spd;
	int Seconds;
};


std::vector<SItem> SItemVec;


void __fastcall hook_Use(int* itemptr, int* playerptr)
{
	auto_ptr<KServer> Server;
	auto_ptr<KPlayer> Player(new KPlayer(playerptr));
	auto_ptr<KItem> Item(new KItem(itemptr));


	if(Player->GetUID()){


	std::ifstream spawnitem;
    spawnitem.open("BuffItems.txt");
    std::string strTemp;
    std::string line;
    if(spawnitem.is_open())
	{
        while (std::getline(spawnitem,line,'(').good())
        {
                SItem buffItem;
                spawnitem >> strTemp >> buffItem.Index >> strTemp >> buffItem.Str >> strTemp >> buffItem.Hp >> strTemp >> buffItem.Int >> strTemp >> buffItem.Wis 
				>> strTemp >> buffItem.Agi >> strTemp >> buffItem.Pwr >> strTemp >> buffItem.Explo >> strTemp >> buffItem.PerEva >> strTemp >> buffItem.PerDef >> strTemp >> buffItem.DmgRed >> 
				strTemp >> buffItem.Acc >> strTemp >> buffItem.Eva >> strTemp >> buffItem.Spd >> strTemp >> buffItem.Seconds;
                SItemVec.push_back(buffItem);
        }
    }
    spawnitem.close();


	for(std::vector<SItem>::iterator it = SItemVec.begin(); it != SItemVec.end(); ++it) 
	{


		if(Item->GetIndex() == it->Index) {
			int strInt1 = 60;
			int hpInt1 = 61;
			int intInt1 = 62;
			int wisInt1 = 63;
			int agiInt1 = 64;
			int pwrInt1 = 51;
			int exploInt1 = 54;
			int perdefInt1 = 58;
			int perevaInt1 = 57;
			int dmgredInt1 = 52;
			int accInt1 = 56;
			int evaInt1 = 57;
			int spdInt1 = 12;


			int strInt2 = 0;
			int hpInt2 = 0;
			int intInt2 = 0;
			int wisInt2 = 0;
			int agiInt2 = 0;
			int pwrInt2 = 0;
			int exploInt2 = 0;
			int perdefInt2 = 0;
			int perevaInt2 = 0;
			int dmgredInt2 = 0;
			int accInt2 = 0;
			int evaInt2 = 0;
			int spdInt2 = 60;


			int BUFF1 = Server::CChar::CreateBuff(strInt1, it->Seconds, it->Str, strInt2);
			int BUFF2 = Server::CChar::CreateBuff(hpInt1, it->Seconds, it->Str, hpInt2);
			int BUFF3 = Server::CChar::CreateBuff(intInt1, it->Seconds, it->Str, intInt2);
			int BUFF4 = Server::CChar::CreateBuff(wisInt1, it->Seconds, it->Str, wisInt2);
			int BUFF5 = Server::CChar::CreateBuff(agiInt1, it->Seconds, it->Str, agiInt2);
			int BUFF6 = Server::CChar::CreateBuff(pwrInt1, it->Seconds, it->Str, pwrInt2);
			int BUFF7 = Server::CChar::CreateBuff(exploInt1, it->Seconds, it->Str, exploInt2);
			int BUFF8 = Server::CChar::CreateBuff(perdefInt1, it->Seconds, it->Str, perdefInt2);
			int BUFF9 = Server::CChar::CreateBuff(perevaInt1, it->Seconds, it->Str, perevaInt2);
			int BUFF10 = Server::CChar::CreateBuff(dmgredInt1, it->Seconds, it->Str, dmgredInt2);
			int BUFF11 = Server::CChar::CreateBuff(accInt1, it->Seconds, it->Str, accInt2);
			int BUFF12 = Server::CChar::CreateBuff(evaInt1, it->Seconds, it->Str, evaInt2);
			int BUFF13 = Server::CChar::CreateBuff(spdInt1, it->Seconds, it->Str, spdInt2);


			Server::CPlayer::AddBuff(playerptr, BUFF1);
			Server::CPlayer::AddBuff(playerptr, BUFF2);
			Server::CPlayer::AddBuff(playerptr, BUFF3);
			Server::CPlayer::AddBuff(playerptr, BUFF4);
			Server::CPlayer::AddBuff(playerptr, BUFF5);
			Server::CPlayer::AddBuff(playerptr, BUFF6);
			Server::CPlayer::AddBuff(playerptr, BUFF7);
			Server::CPlayer::AddBuff(playerptr, BUFF8);
			Server::CPlayer::AddBuff(playerptr, BUFF9);
			Server::CPlayer::AddBuff(playerptr, BUFF10);
			Server::CPlayer::AddBuff(playerptr, BUFF11);
			Server::CPlayer::AddBuff(playerptr, BUFF12);
			Server::CPlayer::AddBuff(playerptr, BUFF13);
		}
	}
	}
}


BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
	std::auto_ptr<LunaCore> Core(new LunaCore());
	std::auto_ptr<IMemory> Memory(new IMemory());


        //Server Exports
		Core->Init(ul_reason_for_call, EXPORTS_TYPE::_SERVER);
        
        //Engine Exports
        //Core->Init(ul_reason_for_call, EXPORTS_TYPE::_CLIENT);


    //Detour
	Core->Register(&(PVOID&)Server::CItem::Use, hook_Use);


    //Intercept
	Core->RegisterIntercept(IMemory::_I_CALL, (void*)0x0042CFB0, hook_Use, 6);


    //speed hack message
	Memory->Fill(0x00494A0E, IMemory::_I_NOP, 5);
	Memory->Fill(0x00494A90, IMemory::_I_NOP, 5);


	//egggrade no limit
	Memory->Fill(0x0042F215, IMemory::_I_NOP, 5);


	return Core->Run();
}
 
Newbie Spellweaver
Joined
Jul 2, 2016
Messages
93
Reaction score
9
Please guys im just learning but as i progress anything I do I am willing to make open source. I even plan on releasing a final version of the repack im making. I want to help this community grow again.
 
Upvote 0
Junior Spellweaver
Joined
Jan 1, 2007
Messages
149
Reaction score
7
Please guys im just learning but as i progress anything I do I am willing to make open source. I even plan on releasing a final version of the repack im making. I want to help this community grow again.

Most of the coders here quit. It's hard to find someone that will help you with this.
 
Upvote 0
Skilled Illusionist
Joined
Mar 20, 2009
Messages
374
Reaction score
378
Code:
#define START_DETOUR DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread());
#define END_DETOUR DetourTransactionCommit();


namespace CItemGeneral{
	static int(__thiscall *Use)(int* ItemPtr, int* PlayerPtr) = (int(__thiscall*)(int*, int*))0x0042CFB0;
}


signed int __fastcall CItemGeneral__Use(int* ItemPtr, void* _edx, int* Playerptr)
{
	UNREFERENCED_PARAMETER(_edx);
	auto_ptr<ItemUse> CheckIf(new ItemUse(ItemPtr, Playerptr));
	bool forward = (true);
	if (forward)
		forward = CheckIf->BuffItem();
	if (forward)
		return CItemGeneral::Use(ItemPtr, Playerptr);
	else
		return 1;
}


class ItemUse
{
private:
	int* pItem;
	KServer* Server;
	KCharacter* m_Player;
	KItem* m_Item;
	bool forward;
	void Setforward(bool forward){ this->forward = forward; }
public:
	bool BuffItem();
	ItemUse(int* Itemptr, int* Playerptr)
	{
		this->pItem = Itemptr;
		this->Server = new KServer();
		this->m_Player = new KCharacter((int)Playerptr);
		this->m_Item = new KItem((int)Itemptr);
		this->forward = true;
	}
	~ItemUse(){ delete Server; delete m_Player; delete m_Item; }
};




bool ItemUse::BuffItem()
{
	KBuffItem* pBuffItem = (KBuffItem*)ConfigDB::Get(ConfigDB_MT::MT_BUFFITEM, this->m_Item->GetIndex());
	if (pBuffItem){
		this->Setforward(false);

		if (pBuffItem->Remove){
			this->m_Item = NULL;
			if(!this->m_Player->RemoveItem(pBuffItem->ItemIndex, 1))
				return this->forward;
		}
	
		for (pBuffItem->It = pBuffItem->List.begin(); pBuffItem->It != pBuffItem->List.end(); pBuffItem->It++)
		{
			if (pBuffItem->It->Refresh){
				this->m_Player->CancelBuff(pBuffItem->It->Id);
				this->m_Player->Buff(pBuffItem->It->Id, (pBuffItem->It->Time * 60), pBuffItem->It->Stat);
			}
			else{
				if (!this->m_Player->FindBuff(pBuffItem->It->Id))
					this->m_Player->Buff(pBuffItem->It->Id, (pBuffItem->It->Time * 60), pBuffItem->It->Stat);
			}
		}


		int EffectRange = 15;
		if (pBuffItem->Effect[0])
			Server::CChar::WriteInRect(this->m_Player->GetnObject(), S2C_EFFECT, EffectRange, "db", Server::CBase::Id(this->m_Player->GetnObject()), pBuffItem->Effect[1]);
	}
	return this->forward;
}




BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){
	switch (ul_reason_for_call){
	case DLL_PROCESS_ATTACH:{
		START_DETOUR
			DetourAttach(&(PVOID&)CItemGeneral::Use, CItemGeneral__Use);
		END_DETOUR
			break;
	}
	case DLL_PROCESS_DETACH:{
		START_DETOUR
			DetourDetach(&(PVOID&)CItemGeneral::Use, CItemGeneral__Use);
		END_DETOUR
		break;
	}
	}
	return TRUE;
}





struct S_BuffInfo{
	int ItemIndex;
	int Id;
	int Time;
	int Stat;
	bool Refresh;
};

class KBuffItem : public ConfigDB_MT{
public:
	int ItemIndex;
	int Effect[2];
	bool Remove;
	vector<S_BuffInfo> List;
	vector<S_BuffInfo>::iterator It;
};



bool ConfigDB::CreateBuffItemDB()
{
	KConfig *Config = new KConfig;
	auto_ptr<KServerConsole> sCon;

	sCon->Write(TextColor::DARK_GREEN, "ConfigDB::CreateBuffItemDB");
	Config->Load("BuffItem", "./Config/BuffItem.txt");


	if (Config->IsLoaded("BuffItem"))
	{
		KConfigParser * MainSection = &Config->Get("BuffItem");
		for (unsigned int i = 0; i < MainSection->Size(); i++)
		{
			KConfigParser * FirstChild = MainSection->Get(i);
			if (!FirstChild->GetName().compare("BuffItem"))
			{
				KBuffItem *pBuffItem = new KBuffItem;
				for (unsigned int childs = 0; childs < FirstChild->Size(); childs++)
				{
					KConfigParser * ChildOfChild = FirstChild->Get(childs);

					if (!ChildOfChild->GetName().compare("Settings"))
					{
						for (unsigned int childs = 0; childs < ChildOfChild->Size(); childs++)
						{
							KConfigParser * ChildOfChilds = ChildOfChild->Get(childs);
							if (!ChildOfChilds->GetName().compare("Index"))
							{
								pBuffItem->ItemIndex = ChildOfChilds->GetInt(0);
							}
							else if (!ChildOfChilds->GetName().compare("Remove"))
							{
								pBuffItem->Remove = ChildOfChilds->GetBool(0);
							}
							else if (!ChildOfChilds->GetName().compare("Effect"))
							{
								pBuffItem->Effect[0] = ChildOfChilds->GetBool(0);
								pBuffItem->Effect[1] = ChildOfChilds->GetInt(1);
							}
						}
					}
					else if (!ChildOfChild->GetName().compare("List"))
					{
						for (unsigned int childs = 0; childs < ChildOfChild->Size(); childs++)
						{
							KConfigParser * ChildOfChilds = ChildOfChild->Get(childs);
							if (!ChildOfChilds->GetName().compare("Buff"))
							{
								S_BuffInfo buff;
								buff.ItemIndex = pBuffItem->ItemIndex;
								buff.Id = ChildOfChilds->GetInt(0);
								buff.Time = ChildOfChilds->GetInt(1);
								buff.Stat = ChildOfChilds->GetInt(2);
								buff.Refresh = ChildOfChilds->GetBool(3);
								pBuffItem->List.push_back(buff);
							}
						}
					}
				}
				g_mConfig[GenKey(ConfigDB_MT::MT_BUFFITEM, pBuffItem->ItemIndex)] = pBuffItem;
			}

		}
		return true;
	}
	return false;
}




BuffItem.txt
(BuffItem 
	(Settings
		(Index 8500)
		(Remove true)
		(Effect true 15)
	)
	(List 
		(Buff 36 30 10 true)
		(Buff 37 30 10 true)
		(Buff 46 30 10 true)
		(Buff 47 30 10 true)
		(Buff 48 30 10 true)
		(Buff 49 30 10 true)
		(Buff 50 30 10 false)
		(Buff 60 30 10 false)
		(Buff 61 30 10 false)
		(Buff 62 30 10 false)
		(Buff 63 30 10 false)
		(Buff 64 30 10 false)

	)
)
 
Upvote 0
Back
Top