View Single Post
Old 07.06.2006, 12:25   #17
RipperX
Архивный участник
 
Join Date: Dec 2005
Posts: 242
Default

Quote:
Originally Posted by testdude
well, for those who are interested in making their own dll's, i got some stuff too ;o
Code:
int RequestMakeMacroPacket(DWORD hSocket, unsigned char* hBuffer)
{
	DWORD id;
	unsigned char icon;
	unsigned char count;
	wchar_t name[255];
	wchar_t desc[255];
	wchar_t acr[255];

	unsigned char buf[4095];
	unsigned char entry;
	unsigned char type;
	DWORD skill;
	unsigned char shortcut;
	wchar_t cmd[1023];
	bool bEditMode = false;

	MACRO *pMacroAux;

	int charId = GetCharIDFromSocket(hSocket);
	if (charId == NULL)
		return 1;

	Disassemble(hBuffer, FMT_REQUEST_MAKE_MACRO_MAIN, &id, 64, name, 64, desc, 64, acr, &icon, &count, 4095, buf);
	

	unsigned short i;
	for (i = 0; i < pInfoTable[charId]->macro_list.size(); i++)
	{
		if (pInfoTable[charId]->macro_list[i]->id == id)
		{
			bEditMode = true;

			break;
		}
	}

	pInfoTable[charId]->macro_rev++;

	if (bEditMode)
		pMacroAux = pInfoTable[charId]->macro_list[i];
	else
		pMacroAux = (MACRO *)malloc(sizeof(MACRO));
 
	pMacroAux->id = id;
	pMacroAux->count = count;
	pMacroAux->icon = icon;

	if (bEditMode)
	{
		pMacroAux->name = (wchar_t *)realloc(pMacroAux->name, (wcslen(name)+2) * sizeof(wchar_t));
		pMacroAux->desc = (wchar_t *)realloc(pMacroAux->desc, (wcslen(desc)+2) * sizeof(wchar_t));
		pMacroAux->acr = (wchar_t *)realloc(pMacroAux->acr, (wcslen(acr)+2) * sizeof(wchar_t));
	}	
	else
	{
		pMacroAux->name = (wchar_t *)malloc((wcslen(name)+2) * sizeof(wchar_t));
		pMacroAux->desc = (wchar_t *)malloc((wcslen(desc)+2) * sizeof(wchar_t));
		pMacroAux->acr = (wchar_t *)malloc((wcslen(acr)+2) * sizeof(wchar_t));
	}

	wcscpy(pMacroAux->name, name);
	wcscpy(pMacroAux->desc, desc);
	wcscpy(pMacroAux->acr, acr);

	if (bEditMode)
	{
		for (short j = 0; j < pMacroAux->count; j++)
			free(pMacroAux->cmds[j].cmd);

		free(pMacroAux->cmds);
	}

	pMacroAux->cmds = (MACRO_CMD *)malloc(sizeof(MACRO_CMD)*count);

	size_t x = 0;
	for (short i = 0; i < count; i++)
	{
		Disassemble(buf + x, FMT_REQUEST_MAKE_MACRO_ELEM, &entry, &type, &skill, &shortcut, 1023, cmd);

		pMacroAux->cmds[i].cmd = (wchar_t *)malloc((wcslen(cmd)+2) * sizeof(wchar_t));
		wcscpy(pMacroAux->cmds[i].cmd, cmd);
		
		pMacroAux->cmds[i].id = id;
		pMacroAux->cmds[i].shortcut = shortcut;
		pMacroAux->cmds[i].skill = skill;
		pMacroAux->cmds[i].type = type;
		
		x += ((wcslen(cmd) + 1)*sizeof(wchar_t) + 1 + 1 + 4 + 1);
	}

	if (!bEditMode)
		pInfoTable[charId]->macro_list.push_back(pMacroAux);

	SendMacroList(charId);

	return 0;
}
its part of an old project i was working on with some friends that kinda died as the lead coder went MIA >.> 100% C++, no ASM cos i hate it, pInfoTable struct contains main info needed about a char, stored by charid for easy lookup if anyone was wondering :P hope it helps someone ^.^
Amazing, MACRO struct is defined inside L2Server ?
thx in advance.
RipperX is offline