View Single Post
Old 25.09.2006, 12:39   #13
mcrabben7
Архивный участник
 
Join Date: Apr 2006
Posts: 461
Default

Well I am going to share a small little learning addition to this project. You can use this when working on ANY sort of DLL project, but this one is for the L2Server in particular. This style of code I am about to show you can be used on retail C4 DLLs as well, just change the order of the variables. Anyways, here it is.

Class User:
Code:
#include "Shared.h"
#include "CSharedData.h"

#ifndef _USER_
	#define _USER_

class User
{
public:
	//Class Functions

	//User();

	//CParty * GetParty();
	typedef CParty * (__thiscall *USER_GET_PARTY) ();
	USER_GET_PARTY GetParty = (USER_GET_PARTY)0x004417E0;

	//Not sure if the next 3 functions are __cdecl or __stdcall

	//void SendUserInfo(User * pUser, bool GMUserInfo);
	typedef void (__stdcall *USER_SEND_USER_INFO) (User * pUser, bool GMUserInfo);
	USER_SEND_USER_INFO SendUserInfo = (USER_SEND_USER_INFO)0x004FE0E0;

	//void SendCharInfo(User * pUser, bool NPCCharInfo);
	typedef void (__stdcall *USER_SEND_CHAR_INFO) (User * pUser, bool NPCCharInfo);
	USER_SEND_CHAR_INFO SendCharInfo = (USER_SEND_CHAR_INFO)0x004FEDD0;

	//void UseItem(User * pUser, CItem * pItem);
	typedef void (__stdcall *USER_USE_ITEM) (User * pUser, CItem * pItem);
	USER_USE_ITEM UseItem = (USER_USE_ITEM)0x004EDF70;

	//~User();

protected:
	//Class Variables

	DWORD _unknown[5];
	DWORD CHAR_ID;  // = 20;				//0x14
	DWORD OBJECT_ID;  // = 24;				//0x18
	DWORD _unknown2[634];
	DWORD INFECTED_SKILLS;  // = 2564;		//0xA04	//Unconfirmed
	DWORD _unknown3[342];
	DWORD NPC_INDEX;  // = 3936;			//0xF60
	DWORD _unknown4[268];
	CSharedData * SHARED_DATA; // = 5012		//0x1394
	DWORD _unknown5[392];
	CSocket * USER_SOCKET;  // = 6584;			//0x19B8
}

#endif // _USER_
Class CSharedData:
Code:
#include "Shared.h"

#ifndef _CSHAREDDATA_
	#define _CSHAREDDATA_

class CSharedData
{
public:
	//Class Functions

	//no functions?

protected:
	//Class Variables

	DWORD _unknown; // = 0;
	DWORD _unknown2; // = 4;
	double X_LOC;  // = 8;				//0x08
	double Y_LOC;  // = 16;				//0x10
	double Z_LOC;  // = 24;				//0x18
	DWORD _unknown3[4]; // = 28;
	DWORD NPC_INDEX;  // = 44;			//0x2C
	DWORD _unknown4[15]; // = 48
	DWORD IS_PLAYER;  // = 108;			//0x6C
	DWORD IS_ALIVE;  // = 112;			//0x70
	DWORD _unknown5[8]; // = 116;
	DWORD RACE;  // = 148;				//0x94
	DWORD CLASS_ID;  // = 152;			//0x98
	DWORD _unknown6; // = 156
	DWORD NAME;  // = 160;				//0xA0
	DWORD _unknown7[8];

	//If needed, we can use this to link to the ExUser for this User
	//ExUser can even be made into a class later, as well as the other files.
	ExUser * EX_USER;  // = 196;			//0xC4

	DWORD _unknown8[12];
	DWORD SP;  // = 248;				//0x
	DWORD _unknown9[17];
	DWORD INT;  // = 320;				//0x140
	DWORD STR;  // = 324;				//0x144
	DWORD CON;  // = 328;				//0x148
	DWORD MEN;  // = 332;				//0x14C
	DWORD DEX;  // = 336;				//0x150
	DWORD WIT;  // = 340;				//0x154
	double HP;  // = 344;				//0x158
	DWORD _unknown10; // = 348;
	double MP;  // = 352;				//0x15C
	DWORD _unknown11[2]; // = 356;
	DWORD MOVE_TYPE;  // = 364;			//0x	(0;  // = Walk, 1;  // = Run)
	DWORD STAND_TYPE;  // = 368;		//0x	(0;  // = Sitting, 1;  // = Standing, 2;  // = PrivateStore)
	DWORD _unknown12[3]; // = 372;
	DWORD TARGET_INDEX;  // = 384;		//0x	
	DWORD TARGET_ID;  // = 388;			//0x	Target's objectID
	DWORD _unknown13[5]; // = 392;
	DWORD KARMA;  // = 412;				//0x
	DWORD _unknown14[62]; // = 416;
	DWORD PLEDGE_ID;  // = 664;			//0x
	DWORD _unknown15; // = 668;
	DWORD IS_PLEDGE_MASTER;  // = 672;	//0x
	DWORD _unknown16[18]; // = 676;
	DWORD MOUNT;  // = 748;				//0x	(0;  // = None, 1;  // = Strider, 2;  // = Wyvern)
	DWORD _unknown17[34]; // = 752;
	DWORD LEVEL;  // = 888;				//0x
	DWORD _unknown18[27]; // = 892;
	double MAX_HP;  // = 1000;			//0x
	DWORD _unknown19[155]; // = 1004;
	DWORD WEIGHT_POINT;  // = 1624;		//0x
}

#endif // _CSHAREDDATA_
Example Usage (Rewritten RefreshAutoSS):
Code:
/*Example usage:

void AutoSS::RefreshAutoSS(User * pUser, WORD itemID)
{
	//CCrashLog::AddLog("void AutoSS::RefreshAutoSS(User * pUser, WORD itemID)");

	//if the item passed is a valid ID
	if( itemID != 0 )
	{
		if(pUser != NULL)
		{
			if( !pUser->bPrivateStore && !pUser->bActiveRequest && pUser->bIsAlive )
			{
				//Find the item in the player's inventory
				CItem * pItem = CInventory::FindFirstItemByClassID(pUser->pInventory, itemID);

				if(pItem != NULL)
				{
					//Use the requested item so their SS is charged
					User::UseItem(pItem);
				}
			}
		}
	}
}

*/
You can download these C++ header files in the RAR below. They are NOT complete, since if you look inside the Aie_creature_names file I attached above, it has a lot of CSharedData variables labeled with their byte offsets. Inventory and some other things can be found in my code. If I was still working on this project, I would rewrite the entire thing with classes like so. In the end it would be very neat, easy to code, and all the ugly hooking and other hack programming would be hidden away. It'd almost be like coding normal

Hope the classes example is helpful to some people. BTW, I didn't compile or test these at all, but they should be ok...assuming you do all the other code changes you'd have to do *laughs*

Вложения из исходного сообщения (сами файлы в копии отсутствуют):
L2ServerClasses.rar — 2492 байт
mcrabben7 is offline