View Single Post
Old 10.07.2006, 10:01   #25
mcrabben7
Архивный участник
 
Join Date: Apr 2006
Posts: 461
Default

I'll share the Party functionality fix, since I got some parts of the fix from files out there.

It's all in assembly, since that was the easiest way to do it, considering how I have to keep everything in certain registers and all. I could do it all in C++, but, more effort than it is worth.

Code:
const DWORD * TEMPLATE_GET_USER = (DWORD *)0x00517B90;
const DWORD * TEMPLATE_GET_USER2 = (DWORD *)0x0058C8B6;
const DWORD * TEMPLATE_GET_USER3 = (DWORD *)0x00406970;
const DWORD * TEMPLATE_GET_USER4 = (DWORD *)0x0041E4D0;
Code:
// Fixes the RequestParty functionality in C4 by converting the
// charName string passed in the packet back into an ObjectID.
//
// Parameters:
// DWORD * pBuffer - address of the packet sent by the client
//
void RequestPartyFix(DWORD * pBuffer)
{
	__asm
	{
		mov		ebx, pBuffer
		lea		esi, [ebx+1]
		push	esi
		call	FindUserByCharName
		or		eax, eax
		jz		UserNotFound
		mov		ecx, [eax+18h]
		//Start String Loop
		push	ecx
		add		ebx, 1			//set ebx to point to the first wchar in the string
		xor		eax, eax
		xor		ecx, ecx
	StringLoop:
		cmp		ecx, 16			//if we have searched for 16 characters, give up.
		je		EndStringLoop	//jump so we prevent a buffer overrun attack
		mov		ax, [ebx]		//copy our wchar value
		add		ebx, 2			//move our pointer to the next wchar in the string
		add		ecx, 1
		cmp		ax, 0			//see if this is the null-terminated part of the string
		jnz		StringLoop		//if not, loop and keep searching
	EndStringLoop:
		pop		ecx
		//End String Loop
		mov		eax, [ebx]		//copy lootType
		mov		ebx, pBuffer
		mov		[ebx+1], ecx			//mov objectID to pBuffer+1
		mov		[ebx+5], eax			//mov lootType to pBuffer+5
		mov		word ptr [ebx+9], 0599h
		//mov		word ptr [ebx+9], 0		//zero out pBuffer+9
		mov		word ptr [ebx-2], 0Bh	//set packet length to 11 bytes
		jmp		RequestPartyFixExit
	UserNotFound:
		xor		eax, eax
		mov		[ebx+1], eax
		mov		[ebx+5], eax
	RequestPartyFixExit:
	}
}

// Converts a charName into a character User struct by finding
// a User struct for that charName.  ObjectID is inside of it.
//
// Parameters:
// DWORD * charName - address of a wstring name (offset wchar * charName)
//
Naked DWORD * FindUserByCharName(DWORD * charName)
{
	__asm
	{
		PUSH EBP
		MOV EBP,ESP
		ADD ESP,-4Ch
		PUSH EBX
		PUSH EDI
		PUSH ESI
		LEA EAX,DWORD PTR SS:[EBP-4Ch]	//our 64 byte buffer
		PUSH EAX
		PUSH DWORD PTR SS:[EBP+8h]		//charName
		CALL TEMPLATE_GET_USER
		ADD ESP,8h
		SUB ESP,124h
		MOV ESI,ESP
		XOR EBX,EBX
		MOV DWORD PTR DS:[ESI+120h],8Bh
		MOV DWORD PTR DS:[ESI+11Ch],EBX
		MOV WORD PTR DS:[ESI+4h],BX
		LEA EDX,DWORD PTR SS:[EBP-4Ch]	//our 64 byte buffer
		PUSH EDX
		CALL TEMPLATE_GET_USER2
		ADD ESP,4
		MOV ECX,ESI
		MOV EDX,EAX
		LEA EAX,DWORD PTR SS:[EBP-4Ch]	//our 64 byte buffer
		PUSH EDX
		PUSH EAX
		CALL TEMPLATE_GET_USER3
		MOV ECX,16922550h
		LEA EAX,DWORD PTR SS:[EBP-0Ch]	//our 12 byte objectID holder
		PUSH EAX
		CALL TEMPLATE_GET_USER4
		MOV EAX,DWORD PTR SS:[EBP-0Ch]	//return our User struct (pUser)
		POP ESI
		POP EDI
		POP EBX
		LEAVE
		RETN 4
	}
}
Code:
// Fixes the AskjoinParty packet that is sent to the client.
// Will send the charName instead of the objectID, as well
// as the proper loot type.
Naked void AskJoinPartyPacketFix()
{
	__asm
	{
		mov     ecx, [ebp-14h]
		mov     edx, [esi+0F54h]
		lea     edx, [edx+0A0h]
		push    ecx					//loot type
		push    edx					//charName
		push    4Bh					//packet header
		push    FORMAT_JOINPARTY	//format 'cSd'
		push    eax					//pSocket
		call	CSOCKET_SEND
		add     esp, 20				//fix our stack pointer
		push    510A4Dh
		retn
	}
}
This has 100% working party invites. It shows the player name inviting you, as well as the correct loot type.

If someone has my code, the RequestPartyFix is called from the correct case (0x29) and will automatically fix the packet. The other fix for the AskJoinPartyPacket should be easy to find if you know how to search for packet functions in the L2Server. If not, there are tools and files out there to help you.



A note to everyone: I still want to help everyone out there with more code, but at the same time, I will not force myself to code for so much time, only to give it all away. I know a lot of people here want to learn, and that is why this thread was started. So you can learn. There are lots of examples in my older versions, as well as code snippets throughout this thread.

The DLL is just barely mature enough to finally be used live, coupled with the correct EXE. It has been running well, which is nice. The couple of us that work on this project hope to keep working on this as we go, and see how it all comes along.
mcrabben7 is offline