Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 14.06.2007, 13:27   #1
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default [SHARE] knowledge about good times (C1++ 32-bit stuff)

eng: IF someone interested, let me know, i'll continue, otherwise i'll stop =)
this thread if just for people who wanna some info about internals of any EXTenders, how it works, why it works, etc showing my sources of one of my oldy C1->C4 dll as an example

or maybe someone still working on one of C1++ projects, so maybe it will be helpful

rus: ЕСЛИ это кому-нить интересно, дайте знать, иначе ну его нах =)
эта ветка для людей, кому интересно, что же там внутри у всяких там экстендеров, как и почему это работает и т.д. на примере исходников одной из стареньких моих C1->C4 дллок

или кто-нить до сих пор работает над одним из C1++ прожектом, и это может оказаться полезным


trouble: when party leader leave world (disconnects), party destructs and dies under mobs =), but in C4 leader rights should be transfered to another member
проблема: когда пати лидер дисконнектится, пати распадается и обычно умирает под мобами =), а в C4 права лидера должны передаваться другому члену.

Code:
#include "Globals.h"
#include "Creature.h"
#include "Party.h"
#include "Callbacks.h"
#include "SafeObjects.h"

void __stdcall PartyLeaderLeaveWorld(CCreature* pUser, CParty* pParty)
{
	if (pParty==NULL || pUser==NULL) return;

	bool ok=false;

	if (SO_VALID_USER(pUser)==false)
	{
		CLog_AddW(CLOG,2,L"PartyLeaderLeaveWorld SAFEOBJECT CHECKPOINT");
		pParty->Dismiss();
		return;
	}

	//CLog_AddW(CLOG,0,L"PartyLeaderLeaveWorld FIRED");
	if (pParty->GetMemberCount()>2)
	{
		//members count>2 we can translate leader rights to another
		CMemberList MemberList;
		ZeroMemory(&MemberList, sizeof(CMemberList));
		pParty->GetAllMembers(&MemberList);
		if (MemberList.ppUserBegin!=NULL)
		{
			int nCount = (int)(MemberList.ppUserEnd - MemberList.ppUserBegin);
			for (int i=0;i<nCount;i++)
			{
				CCreature *pMember = MemberList.ppUserBegin[i];
				if (pUser!=NULL && pMember!=NULL && pUser->nObjectID != pMember->nObjectID)
				{
					//change leader
					pParty->ChangePartyLeader(pMember);
					//withdraw old leader
					pParty->Withdraw(pUser);
					ok=true;
					break;
				}
			}
		}
		else
		{
			//memberlist error - dismiss
			pParty->Dismiss();
		}

		if (ok==false)
		{
			//fail somewhy
			pParty->Dismiss();
		}

		MemberList.Cleanup();

	}
	else
	{
		//no more members - just dismiss party
		pParty->Dismiss();
	}
}

//callback from address 0x004FBD94
void __declspec(naked) CB_PartyLeaderLeaveWorld()
{
	__asm
	{
		pushad
		push edi //party
		push esi //user
		call PartyLeaderLeaveWorld
		popad
		push 004FBD99h
		retn
	}
}

void CParty::ChangePartyLeader(CCreature *pUser)
{
	if (SO_VALID_USER(pUser)==false)
	{
		CLog_AddW(CLOG,2,L"CParty::ChangePartyLeader SAFEOBJECTS CHECKPOINT");
		return;
	}
	SetMaster(pUser);
	CMemberList MemberList;
	ZeroMemory(&MemberList, sizeof(CMemberList));
	GetAllMembers(&MemberList);
	if (MemberList.ppUserBegin==NULL) 
	{
		CLog_AddW(CLOG,2,L"CParty::ChangePartyLeader No Members Error");
		return;
	}
	int nCount = (int)(MemberList.ppUserEnd - MemberList.ppUserBegin);
	//first round
	for (int i=0; i<nCount; i++)
	{
		CCreature *pMember = MemberList.ppUserBegin[i];
		if (pUser!=NULL && pMember!=NULL && pMember->pUserSocket !=NULL)
		{
			//delete all small windows
			pMember->pUserSocket->Send("c",0x50);
			//update small party window
			OpenAllWindowPacket(pMember);
		}
	}
	//second round, restore all abnormals and send text message
	for (int i=0; i<nCount; i++)
	{
		CCreature *pMember = MemberList.ppUserBegin[i];
		if (pUser!=NULL && pMember!=NULL && pMember->pUserSocket !=NULL)
		{
			//update abnormals
			pMember->SendAbnormalStatusInfo();
			//send messsage
			SP_SM_TEXT_TEXT(pMember->pUserSocket,SM_S1_BECOME_PARTY_LEADER,pUser->Data->szName);
		}
	}
	MemberList.Cleanup();
}
humordwarf is offline  
Old 14.06.2007, 13:42   #2
Constantin
Архивный участник
 
Join Date: Jun 2007
Posts: 9
Default

Yes i would like to show me your stuff and explane me all about C1 servers. I start as Dev first time in L2c4 Retail files, so i want realy learn about C1 files.
Constantin is offline  
Old 14.06.2007, 13:45   #3
hel
Архивный участник
 
Join Date: Apr 2006
Posts: 729
Default

Continue, of course.
I'm learning c++ and interested in it.
hel is offline  
Old 14.06.2007, 13:49   #4
Corund
Архивный участник
 
Join Date: Dec 2006
Posts: 60
Default

<rus>
Это всегда интересно - я вообще для С1 на дельфи длл писал, с переходом на С4 пришлось почти с нуля учить С++.
[набравшись наглости] - заголовочные файлы к этому примеру входят в список документов, с которых сняли гриф секретности? :-)
зы. надо бы и по английски какую-нибудь стандартную фигню написать - не принимай близко к сердцу :-)
</rus>

Excellent !!!! Good stuff!!! keep going ahead!!! :-)
Corund is offline  
Old 14.06.2007, 13:51   #5
Constantin
Архивный участник
 
Join Date: Jun 2007
Posts: 9
Default

Maybe guys u have fix for HELP.html for c1 servers?
Constantin is offline  
Old 14.06.2007, 14:03   #6
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

SO_VALID_USER - simple thing that checks given pointer and checks if its really poits to valid User class
0x00602C04 - offset of User virtual functions, same for all users
its good when u not sure and wanna reinsure %)

SafeObjects.h
Code:
#pragma once

class CCreature;

inline bool SO_VALID_USER(CCreature *pUser)
{
	DWORD *p = (DWORD *)pUser;
	if (p==NULL) return false;
	DWORD a = (DWORD)p;
	if (a<0x1000000) return false;
	a = *p;
	if (a!=0x00602C04) return false;
	return true;
}
humordwarf is offline  
Old 14.06.2007, 14:15   #7
Constantin
Архивный участник
 
Join Date: Jun 2007
Posts: 9
Default

Nice thanks.
Constantin is offline  
Old 14.06.2007, 14:20   #8
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

globals - common stuff of extender

CLog_AddW() - unicode version of CLog:Add
CLog_AddA() - ansi version of CLog::Add
Assemble() - packet assembler
Disassemble() - packet disassembler
all these 4 functions points into original c1 l2server.exe

g_Cfg - global class that contain settings readed from .ini
g_Console - global class for console output
g_GM_Allowed - can any GM login/use commands

SC_LoadBlockedItems() - load list of IDs that can not be placed on shortcut panel
SC_ItemInBlockList() - checks if item can me placed on shortcut panel
....... as i remember this list was used to remove enchant scrolls from shortcuts... %)

GM_LoadAllowedChars() - load list of char names that able to be GM
GM_CharAllowed() - checks if given char name can use GM commands

globals.h
Code:
#pragma once

#define ABS true
#define PROJECT_NAME "L2SERVER.DLL HD v1.15 ABS_EE"
#define __BUILD_TIME__ __TIMESTAMP__

#include <windows.h>
#include <tchar.h>
#include <atlstr.h>

#define EXPORT extern "C" __declspec (dllexport)

#include "ui.h"

#define MAX_CLASS 127

#define MAX_PARTY_MEMBER_COUNT 9

//интерфейсное
EXPORT CConfig *g_Cfg;
EXPORT CConsole *g_Console;

EXPORT bool g_GM_Allowed;

typedef INT ( *ASSEMBLE )( UCHAR *pBuff, INT nBuffLen, const CHAR *pFormat, ... );
EXPORT ASSEMBLE Assemble;
typedef UCHAR* ( *DISASSEMBLE )( const UCHAR *pBuff, const CHAR* pFormat, ... );
EXPORT DISASSEMBLE Disassemble;

#define CLOG 0x18AA81D8
typedef INT ( *CLOG_ADDW )( DWORD g_CLog,int nLogType, WCHAR *szText, ... );
EXPORT CLOG_ADDW CLog_AddW;
typedef INT ( *CLOG_ADDA )( DWORD g_CLog,int nLogType, CHAR *szText, ... );
EXPORT CLOG_ADDA CLog_AddA;

//ShortCuts
bool SC_LoadBlockedItems();
bool SC_ItemInBlockList(int nID);

//GM
bool GM_LoadAllowedChars();
bool GM_CharAllowed(WCHAR *pCharName);

#include "ClientPackets.h"
#include "Patcher.h"
globals.cpp
Code:
#include "Globals.h"
#include <AtlStr.h>

ASSEMBLE Assemble = ( ASSEMBLE )0x0053AFA0;
DISASSEMBLE Disassemble = ( DISASSEMBLE )0x00539DD0;

CLOG_ADDA CLog_AddA = (CLOG_ADDA)(0x0053EE60);
CLOG_ADDW CLog_AddW = (CLOG_ADDW)(0x0053EEE0);

WCHAR *g_szTimeStamp;

int SC_NumberOfBlockedItems;
int SC_BlockedItems[1000];
bool SC_ItemInBlockList(int nID)
{
	for (int i=0; i<SC_NumberOfBlockedItems; i++)
	{
		if (SC_BlockedItems[i]==nID) return true;
	}
	return false;
}
bool SC_LoadBlockedItems()
{
	CStringA t;
	CStringA s = g_Cfg->GetString("ShortCut:BlockItemList","0");
	s.Trim();
	int nCurPos = 0;
	SC_NumberOfBlockedItems = 0;
	t = s.Tokenize(" ",nCurPos);
	while (t != "")
	{
		int id = atol(t);
		if (id>0)
		{
			SC_BlockedItems[SC_NumberOfBlockedItems++] = id;
		}
		t = s.Tokenize(" ",nCurPos);
	}
	/*for (int i=0; i<SC_NumberOfBlockedItems; i++)
	{
		printf("Blocked %i\n",SC_BlockedItems[i]);
	}*/
	return true;
}


int GM_NumberOfAllowedChars;
CStringW GM_AllowedChar[100];

bool GM_CharAllowed(WCHAR *pCharName)
{
	for (int i=0; i<GM_NumberOfAllowedChars; i++)
	{
		if (GM_AllowedChar[i].CompareNoCase(pCharName)==0) return true;
	}
	return false;
}

bool GM_LoadAllowedChars()
{
	CStringA t;
	CStringA s = g_Cfg->GetString("GM:AllowedCharList","");
	s.Trim();
	int nCurPos = 0;
	SC_NumberOfBlockedItems = 0;
	t = s.Tokenize(" ",nCurPos);
	while (t != "")
	{
		GM_AllowedChar[GM_NumberOfAllowedChars++] = t;
		t = s.Tokenize(" ",nCurPos);
	}
	for (int i=0; i<GM_NumberOfAllowedChars; i++)
	{
		printf("Allowed GM: %S\n",GM_AllowedChar[i]);
	}
	return true;
}
humordwarf is offline  
Old 14.06.2007, 14:26   #9
hel
Архивный участник
 
Join Date: Apr 2006
Posts: 729
Default

omg...i can't even understand, what is virtual user functions (is it point, where dll may call server functions, or is it one function, which operate with users? -_-).

...going to google.
hel is offline  
Old 14.06.2007, 14:36   #10
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

Quote:
Originally Posted by hel View Post
omg...i can't even understand, what is virtual user functions (is it point, where dll may call server functions, or is it one function, which operate with users? -_-).

...going to google.
yeah, try to search about c++ static, virtual "reserved words" =)

but i'll try to explain:

Code:
class CSomeClass
{
public:
  int n1;
  int n2;
  void DoSomething();
};
offset of n1 == 0
offset of n2 == 4

BUT

Code:
class CSomeClass
{
public:
  int n1;
  int n2;
  virtual void DoSomething();
};
offset of n1 == 4
offset of n2 == 8
and at zero offset there is pointer to array of virtual functions

so, almost every c++ class inside l2server has virtual functions and they are all different.. CCreature - one address, CNPC - another, User - 0x00602C04

so we can check by dword (qword in x64) value at offset 0 what this class is.
humordwarf is offline  
Old 14.06.2007, 15:25   #11
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

troubles:
1. when ur weight too high, u can not move, but can when u on strider
2. when u trading, u can go away too far and then confirm
проблемы:
1. при большом весе нельзя двигаться, но на страйдере почему-то можно
2. при передаче вещей можно убежать далеко, а затем только подтвердить

packet 0x01 handler fix this bugs

CP_01_MoveBackwardToLocation.cpp
Code:
#include "Globals.h"
#include "Creature.h"
#include "Structs.h"
#include "Item.h"
#include "ServerPackets.h"
#include "Trade.h"


UCHAR CP_01_MoveBackwardToLocation(CUserSocket *pUserSocket, UCHAR *pPacket)
{
	//int nX, nY, nZ;
	//int nToX, nToY, nToZ;

	//Disassemble(pPacket,"dddddd",&nX,&nY,&nZ,&nToX,&nToY,&nToZ);
	
	CCreature *pUser= pUserSocket->pUser;
	if (pUser==NULL) return 1; //handled

	//cant move if CTrade object created (trading)
	if (pUser->pTrade != NULL && pUser->pTrade->bIsInTrade)
	{
		SP_SM_TEXT(pUserSocket,SM_CANT_MOVE_IN_THIS_STATE);
		SP_ACTION_FAILED(pUserSocket);
		return 1; //handled
	}

	//cant move on strider/wyiern if your weight>70%
	if (pUser->GetMountType()!=0)
	{
		int nCurW = (int)pUser->GetCurrentWeight();
		int nMaxW = (int)pUser->GetMaxWeight();
		if (nMaxW<=0)
		{
			CLog_AddW(CLOG,2,L"WOW! CP_01_MoveBackwardToLocation: MaxWeight<=0 User=%s",pUser->Data->szName);
			nMaxW = 1;
		}

		int nPerc = 100*nCurW/nMaxW;
		if (nPerc>70)
		{
			SP_SM_TEXT(pUserSocket,SM_CANT_MOVE_WEIGHT_TOO_GREAT);
			SP_ACTION_FAILED(pUserSocket);
			return 1; //handled
		}
	}

	//in all other cases pass work to l2server
	return 0; //unhandled
}
humordwarf is offline  
Old 14.06.2007, 15:25   #12
hel
Архивный участник
 
Join Date: Apr 2006
Posts: 729
Default

humordwarf:
mm... you want to tell, that 0 offset of class has pointer, which point to array of all virtual functions at this class and so_valid_user checks, if this pointer assigned to NULL, then it's user not exist (*pUser points to disconnected user?), right?
anyway thank you for explain and keep sources and comments going.
hel is offline  
Old 14.06.2007, 15:33   #13
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

Quote:
Originally Posted by hel View Post
humordwarf:
if this pointer assigned to NULL, then it's user not exist (*pUser points to disconnected user?), right?
i repeat, this is just to be sure, that pointer points (omg) to correct data.
in given case - to correct User class, not to CNPC, not to CPet, not to any other
humordwarf is offline  
Old 14.06.2007, 15:49   #14
hel
Архивный участник
 
Join Date: Apr 2006
Posts: 729
Default

humordwarf:
weheh.. i don't completely understand (i think it's just hard to explain it), but i'll try to find more info about this and thank you again, your posts are usefull even for me.
maybe sometime i'll create my great dll for l2server. %)
respect.
hel is offline  
Old 19.06.2007, 01:34   #15
mcrabben7
Архивный участник
 
Join Date: Apr 2006
Posts: 461
Default

Go HD Keep rocking.
mcrabben7 is offline  
Old 19.06.2007, 04:56   #16
smeli
Архивный участник
 
Join Date: Apr 2006
Posts: 181
Default

Yeah, we need this project

<ru>
da da, prodolzhaite pozhaluista
</ru>
smeli is offline  
Old 19.06.2007, 05:26   #17
tpuNIsher
Архивный участник
 
Join Date: Mar 2006
Posts: 685
Default

I can't describe my respect for HD, thanks HD, again :P
tpuNIsher is offline  
Old 19.06.2007, 11:30   #18
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

ok.. next...

ServerPackets.h - some definitions for server->client packets
Code:
#pragma once

#define SP_AUTOSS(pSocket,nItemID,nCommand) pSocket->Send("chdd",0xFE,0x12,nItemID,nCommand)

//system messages
#define SP_ID_SYSTEMMESSAGE 0x64
#define SP_SM_NUMBER 1

//=== COMMON MESSAGES ===
//"Nothing happened."
#define SM_NOTHING_HAPPENED 61

//"Target is not found in the game."
#define SM_TARGET_NOT_FOUND 0x91

//===WEIGHT===
// "You cannot move. Your item weight is too great. "
#define SM_CANT_MOVE_WEIGHT_TOO_GREAT 0x22B

//22C "You cannot move in this state."
#define SM_CANT_MOVE_IN_THIS_STATE 0x22C


//=== SOUL/SPIRITSHOT RELATED ===
//"Soulshot does not match weapon grade."
#define SM_SS_NOT_MATCH_WEAPON 0x151 
//"Not enough soulshots."
#define SM_NOT_ENOUGH_SS 0x152
//"Cannot use soulshots."
#define SM_CANT_USE_SS 0x153
//"Spiritshot does not match weapon grade."
#define SM_SPS_NOT_MATCH_WEAPON 0x212
//"Not enough spiritshots."
#define SM_NOT_ENOUGH_SPS 0x213
//"Cannot use spiritshots."
#define SM_CANT_USE_SPS 0x214
//"The use of $s1 will now be automated."
#define SM_USE_S1_AUTOMATED 0x599
//"The automatic use of $s1 will now be cancelled."
#define SM_USE_S1_CANCELED 0x59A

//=== PARTY RELATED ===
//"Wrong target has been invited."
#define SM_WRONG_TARGET_INVITED 0x98
//"$s1 is a member of another party and cannot be invited."
#define SM_S1_MEMBER_OF_ANOTHER_PARTY 0xA0
//"Only the leader can give out invitations."
#define SM_ONLY_LEADER_CAN_GIVE_INVITATIONS 0x9A
//"Party is full."
#define SM_PARTY_IS_FULL 0x9B
//"Waiting for another reply."
#define SM_WAITING_FOR_REPLY 0xA4
//"$s1 is busy. Please try again later."
#define SM_S1_IS_BUSY 0x99
//"Only a party leader can transfer one's rights to another player."
#define SM_ONLY_PARTY_LEADER_CAN_TRANSFER_RIGHTS 0x577
//"You can transfer rights only to another party member."
#define SM_YOU_CAN_TRANSFER_RIGHT_ONLY_TO_ANOTHER_MEMBER 0x57A
//"$s1 has become a party leader."
#define SM_S1_BECOME_PARTY_LEADER 0x568

//=== BLOCKLIST ===
//"$s1  has placed you on his/her Ignore List."
#define SM_S1_HAS_PLACED_YOU_ON_INGNORE_LIST 0x26C

//macros for system messages
#define SP_SM_TEXT(pSocket,nSM) pSocket->Send("cdd",SP_ID_SYSTEMMESSAGE,nSM,0)
#define SP_SM_TEXT_TEXT(pSocket,nSM,szText) pSocket->Send("cdddS",SP_ID_SYSTEMMESSAGE,nSM,1,0,szText)
#define SP_SM_TEXT_NUMBER3(pSocket,nSM,n1,n2,n3) pSocket->Send("cdddddddd",SP_ID_SYSTEMMESSAGE,nSM,3,1,n1,1,n2,1,n3)
#define SP_SM_TEXT_ITEM(pSocket,nSM,nItemID) pSocket->Send("cdddd",SP_ID_SYSTEMMESSAGE,nSM,1,3,nItemID)

//join party packet
#define SP_SM_JOIN_PARTY(pSocket,nResponse) pSocket->Send("cd",0x3A,nResponse)
//AskJoinParty
#define SP_ASK_JOIN_PARTY(pSocket,szRequestorName,nItemDistribution) pSocket->Send("cSd",0x39,szRequestorName,nItemDistribution)

//ActionFailed
#define SP_ACTION_FAILED(pSocket) pSocket->Send("c",0x25)


//status update stuff
#define SP_STATUS_UPDATE 0x0E
#define STATUS_LEVEL 0x01
#define STATUS_EXP 0x02
#define STATUS_STR 0x03
#define STATUS_DEX 0x04
#define STATUS_CON 0x05
#define STATUS_INT 0x06
#define STATUS_WIT 0x07
#define STATUS_MEN 0x08
#define STATUS_CUR_HP 0x09
#define STATUS_MAX_HP 0x0a
#define STATUS_CUR_MP 0x0b
#define STATUS_MAX_MP 0x0c
#define STATUS_SP 0x0d
#define STATUS_CUR_LOAD 0x0e
#define STATUS_MAX_LOAD 0x0f
#define STATUS_P_ATK 0x11
#define STATUS_ATK_SPD 0x12
#define STATUS_P_DEF 0x13
#define STATUS_EVASION 0x14
#define STATUS_ACCURACY 0x15
#define STATUS_CRITICAL 0x16
#define STATUS_M_ATK 0x17
#define STATUS_CAST_SPD 0x18
#define STATUS_M_DEF 0x19
#define STATUS_PVP_FLAG 0x1a
#define STATUS_KARMA 0x1b
#define STATUS_CUR_CP 0x21
#define STATUS_MAX_CP 0x22
humordwarf is offline  
Old 19.06.2007, 11:37   #19
humordwarf
Архивный участник
 
Join Date: Feb 2006
Posts: 453
Default

some /loc related stuff

little bit unoptimized, but works fine... as i remember...

Settings.h
Code:
#pragma once

#include <atlstr.h>

bool Settings_Load();
CString Settings_GetRestartTownName(int nCurrentX, int nCurrentY);
Settings.cpp
Code:
#include "Settings.h"

#define MAXTOWN 50

int LastTown;
int RestartPoints[100][100];
CString TownNames[MAXTOWN];

CString Settings_GetRestartTownName(int nCurrentX, int nCurrentY)
{
	int cRestartMapX = (( (nCurrentX+0x50000) >> 15 ) + 10) & 0x1F; 
	int cRestartMapY = (( (nCurrentY+0x40000) >> 15 ) + 10) & 0x1F; 
	int cTown = RestartPoints[cRestartMapX][cRestartMapY];
	if (cTown>=0 && cTown<MAXTOWN)
	{
		return  TownNames[cTown];
	}
	else
	{
		//s.Format(L"x=%i y=%i mx=%i my=%i town=%i",nCurrentX,nCurrentY,cRestartMapX,cRestartMapY,cTown);
		return L"error";
	}
}

bool Settings_Load()
{
	for (int x=0; x<100; x++)
		for (int y=0; y<100; y++)
			RestartPoints[x][y] = -1;

	WCHAR* FileName = L"..\\script\\setting.txt";
	WCHAR s[0x100] = L"12345";
	FILE *f;

	if (_wfopen_s(&f,FileName,L"rb")!=0)
	{
		printf("File [%ls] not found!",FileName);
		return false;
	}

	USHORT nUnicodeID;
	fread(&nUnicodeID,2,1,f);

	if (nUnicodeID!=0xFEFF)
	{
		printf("Bad [%ls] format!",FileName);
		fclose(f);
		return false;
	}

	bool restart_point_begin = false;
	bool point_begin = false;
	int restart_index = 0;

	while (!feof(f))
	{
		if (fgetws(s,0x100,f)==NULL)
		{
			printf("Bad [%ls] format!",FileName);
			fclose(f);
			return false;
		}

		CStringW w = s;
		w.Trim();

		if (w.GetLength()==0) continue;

		if (w==L"restart_point_begin")
		{
			restart_point_begin = true;
			continue;
		}

		if (w==L"restart_point_end")
		{
			restart_point_begin = false;
			break;
		}

		if (restart_point_begin)
		{
			if (w==L"point_begin")
			{
				point_begin = true;
				LastTown = restart_index++;
				if (restart_index>MAXTOWN)
				{
					printf("Too many restart towns inside [%ls]!\n",FileName);
					fclose(f);
					return false;
				}
				continue;
			}
			if (w==L"point_end")
			{
				point_begin = false;
				continue;
			}
			if (point_begin)
			{
				CString field = L"point_name=";
				if (w.Left(field.GetLength())== field)
				{
					int CurPos = 0;
					CStringW t = w.Tokenize(L"=",CurPos);
					t = w.Tokenize(L"=",CurPos);
					t.Remove(L'[');
					t.Remove(L']');
					w = t;
					TownNames[LastTown] = w;
					continue;
				}
				if (w.Left(4) == L"map=")
				{
					int x,y;
					if (swscanf_s(w,L"map={%d;%d}",&x,&y)!=2||x<0||x>99||y<0||y>99)
					{
						printf("Bad [%ls] format!\n",FileName);
						fclose(f);
						return false;
					}
					//printf("%i %i_%i\n",LastTown,x,y);
					RestartPoints[x][y] = LastTown;
					continue;
				}
			}
		}
	}
	fclose(f);
	printf("Settings: %i restart towns found\n",LastTown+1);

	return true;
}
CP_AA_RequestUserCommand.cpp
Code:
#include <windows.h>
#include "Globals.h"
#include "Creature.h"
#include "Settings.h"
#include "ServerPackets.h"

UCHAR CP_AA_RequestUserCommand(CUserSocket *pUserSocket, UCHAR *pPacket)
{
	int nCommand;
	Disassemble(pPacket,"d",&nCommand);
	switch (nCommand)
	{
	case 0: // loc
		{
			CCreature *pUser = pUserSocket->pUser;
			if (pUser)
			{
				int nMsgNo;
				CString s = Settings_GetRestartTownName((int)pUser->Data->vLocation.X,(int)pUser->Data->vLocation.Y);
				if (s.CompareNoCase(L"talking_island_town")==0)
				{
					nMsgNo = 0x38E;
				}
				else if (s.CompareNoCase(L"gludin_town")==0)
				{
					nMsgNo = 0x38F;
				}
				else if (s.CompareNoCase(L"gludio_castle_town")==0)
				{
					nMsgNo = 0x390;
				}
				else if (s.CompareNoCase(L"elf_town")==0)
				{
					nMsgNo = 0x392;
				}
				else if (s.CompareNoCase(L"darkelf_town")==0)
				{
					nMsgNo = 0x393;
				}
				else if (s.CompareNoCase(L"dion_castle_town")==0)
				{
					nMsgNo = 0x394;
				}
				else if (s.CompareNoCase(L"floran_town")==0)
				{
					nMsgNo = 0x395;
				}
				else if (s.CompareNoCase(L"giran_castle_town")==0)
				{
					nMsgNo = 0x396;
				}
				else if (s.CompareNoCase(L"orc_town")==0)
				{
					nMsgNo = 0x398;
				}
				else if (s.CompareNoCase(L"dwarf_town")==0)
				{
					nMsgNo = 0x399;
				}
				else if (s.CompareNoCase(L"oren_castle_town")==0)
				{
					nMsgNo = 0x39A;
				}
				else if (s.CompareNoCase(L"hunter_town")==0)
				{
					nMsgNo = 0x39B;
				}
				else if (s.CompareNoCase(L"aden_town")==0)
				{
					nMsgNo = 0x39C;
				}
				else if (s.CompareNoCase(L"aden_coliseum")==0)
				{
					nMsgNo = 0x39D;
				}
				else if (s.CompareNoCase(L"giran_habor")==0)
				{
					nMsgNo = 0x397;
				}
				else if (s.CompareNoCase(L"heine_town")==0)
				{
					nMsgNo = 0x39E;
				}
				else
				{
					nMsgNo = 0x391; //Near the Neutral Zone
				}

				SP_SM_TEXT_NUMBER3(pUserSocket, nMsgNo,
					(int)pUser->Data->vLocation.X,
					(int)pUser->Data->vLocation.Y,
					(int)pUser->Data->vLocation.Z);


				//pUserSocket->SendSystemMessage(L"HD",s.GetBuffer());
				return 1; //handled;
			}
		}
		return 1; //handled
	default:
		return 0; //unhandled
	}
}
humordwarf is offline  
Old 19.06.2007, 16:16   #20
Sdw
Архивный участник
 
Join Date: Sep 2005
Posts: 150
Default

Well, may I just say thanks ? It's very usefull, and it seems that I can make something by myself now that's I understand better the system. I'm just lacking time, and it's a crucial things. So what you do here is really important, it spare me some time to study and see how things are working in L2server.

There is just one things I can't get in the last one,

Code:
(( (nCurrentX+0x50000) >> 15 ) + 10) & 0x1F;
What are you doing here ?

EDIT : Figurd it out ! Thanks anyway.
Sdw is offline  
Old 21.06.2007, 13:33   #21
GeNtOo
Архивный участник
 
Join Date: Jan 2006
Posts: 69
Default

respect 4 HD
GeNtOo is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 17:12.