how to parse npc from media.pk2 files

03/03/2015 07:48 fakeheader#1
Hello
I am working on a nice project but I neee help parsing npc data from the text files

I want to
get npc of each town from text files
get type of npc ... like blacksmith and etc
Get npc shop content


so can anyone help?
03/03/2015 10:55 magicanoo#2
Check Zbot's source code. It grabs information from text files after being extracted from the media.pk2.
03/03/2015 19:55 fakeheader#3
i did but its not working i need to make it generic for all servers and because some server has custom npc so i need to find a way to extract the content and the shop type
03/04/2015 09:40 Devsome#4
Quote:
Originally Posted by fakeheader View Post
i did but its not working i need to make it generic for all servers and because some server has custom npc so i need to find a way to extract the content and the shop type
Then just loop them all with the Method of zBot , otherwise rewrite it du avoid the errors
03/04/2015 10:02 fakeheader#5
well .... zbot has its static values for each town ... and it doesnt have alex npc ... anyway i solved the problem using the the expression ... like npc_wc_ so wc is western china then if the string have _smith then its black smith and thanks to fox564 for this solution, thanks for your time
03/07/2015 18:14 zeteris#6
Quote:
Originally Posted by fakeheader View Post
well .... zbot has its static values for each town ... and it doesnt have alex npc ... anyway i solved the problem using the the expression ... like npc_wc_ so wc is western china then if the string have _smith then its black smith and thanks to fox564 for this solution, thanks for your time

Just load them from the client textdata it's not that hard.

Hint: don't use CodeName128 to parse anything.
03/08/2015 17:58 fakeheader#7
Thank you for your answer but here is my problem
in zbot there is no alex npc in the parse and also you made other npc static
so what if the client have custom npc names how would I auto buy pots for example
thats why I need to make it generic
03/08/2015 20:21 Royalblade*#8
Quote:
Originally Posted by fakeheader View Post
Thank you for your answer but here is my problem
in zbot there is no alex npc in the parse and also you made other npc static
so what if the client have custom npc names how would I auto buy pots for example
thats why I need to make it generic
GGWP; You just wasted a lot of time.

1st: Parse SingleSpawn & GroupSpawn
You get, NPCObjectID, XYZ from them.

Then you need to load up a few txt files, get the item locations via this.


Quote:
Originally Posted by Royalblade* View Post
This won't be useful for the general people here. However, when somebody else goes n makes a bot in future, this will save up tons of brainfuck.

However, if you do find a better way to do this, go ahead and post it.

This is strictly speaking only for Type 8 @ 0xB034, since the rest is entirely different.
All those people making alchemy bots etc.. this is highly useful for you :p

EDIT: For shit like this:

First create this function
PHP Code:
CREATE FUNCTION _getTabIndex(@NPCID INT, @TabCodename VARCHAR(128))
RETURNS INT
AS
BEGIN
    
DECLARE @Index INT;

    
SELECT    @Index tabindex
    FROM    
(
            
SELECT    ROW_NUMBER() OVER (ORDER BY tab.RefTabGroupCodeName ASCtab.ID ASC)-1 tabindextab.CodeName128
            FROM    _RefShopTab tab
            JOIN    _RefMappingShopWithTab maptab ON tab
.RefTabGroupCodeName maptab.RefTabGroupCodeName
            JOIN    _RefShop shop ON maptab
.RefShopCodeName shop.CodeName128
            JOIN    _RefMappingShopGroup mapshop ON shop
.CodeName128 mapshop.RefShopCodeName
            JOIN    _RefShopGroup shopgroup ON mapshop
.RefShopGroupCodeName shopgroup.CodeName128
            JOIN    _Refobjcommon R ON shopgroup
.RefNPCCodeName R.CodeName128
            WHERE    R
.ID = @NPCID
            
q
    WHERE    q
.CodeName128 = @TabCodename
    
RETURN @Index
END 

Then run this and create your npcshoplist. You need to parse NPCs via single/groupspawn beforehand though, otherwise you cant get the NPC ID.

PHP Code:

SELECT    npc
.ID as NPCID,.dbo._getTabIndex(npc.ID,goods.RefTabCodeNameTabIDItem.id as ItemIDgoods.SlotIndex  ,scrap.Data
FROM    _RefShopGoods goods
JOIN    _RefShopTab tab ON goods
.RefTabCodeName tab.CodeName128
JOIN    _RefMappingShopWithTab maptab ON tab
.RefTabGroupCodeName maptab.RefTabGroupCodeName
JOIN    _RefShop shop ON maptab
.RefShopCodeName shop.CodeName128
JOIN    _RefMappingShopGroup mapgroup ON shop
.CodeName128 mapgroup.RefShopCodeName
JOIN    _RefShopGroup shopgroup ON mapgroup
.RefShopGroupCodeName shopgroup.CodeName128
JOIN    _Refobjcommon npc ON shopgroup
.RefNPCCodeName npc.CodeName128
JOIN    _RefPackageItem package ON goods
.RefPackageItemCodeName package.CodeName128
JOIN    _RefScrapOfPackageItem scrap ON package
.CodeName128 scrap.RefPackageItemCodeName
JOIN    _Refobjcommon item ON scrap
.RefItemCodeName item.CodeName128
WHERE npc
.ID 2073
ORDER BY tab
.RefTabGroupCodeName  ASCtab.ID ASC 

THEN it would be properly dynamic. But you don't need anything like XYZ from CharData.txt
03/09/2015 00:08 Devsome#9
You can also use like royalblade says ParseSingleSpawn and if type is a NPC then build a function e.g ParseNPC
Old sro-r ParseNPC stuff

Code:
public static int ParseNPC(object opacket, object xresult, bool groupspawn)
{
	Packet packet = (Packet)opacket;
	SpawnData result = (SpawnData)xresult;
	int startpos = (int)packet.data.pointer - 4; 
	//try
	//{
		result.UniqueId = packet.data.ReadDWORD();

		result.xSec = packet.data.ReadBYTE();
		result.ySec = packet.data.ReadBYTE();
		result.X = packet.data.ReadSINGLE();
		result.Z = packet.data.ReadSINGLE();
		result.Y = packet.data.ReadSINGLE();
		packet.data.ReadWORD(); //angle

		result.XCoord = Functions.GetXCoord((int)result.X, result.xSec);
		result.YCoord = Functions.GetYCoord((int)result.Y, result.ySec);

		result.distance = Functions.CalcDistance(result.XCoord, result.YCoord);

		byte haveDest = packet.data.ReadBYTE();
		byte movingType = packet.data.ReadBYTE();
		if (haveDest == 0x01)
		{
			result.DestXSec = packet.data.ReadBYTE();
			result.DestYSec = packet.data.ReadBYTE();

			if (result.DestYSec == 0x80)
			{
				packet.data.ReadSignedDWORD();
				packet.data.ReadSignedDWORD();
				packet.data.ReadSignedDWORD();
			}
			else
			{
				result.DestX = packet.data.ReadSignedWORD();
				result.DestZ = packet.data.ReadSignedWORD();
				result.DestY = packet.data.ReadSignedWORD();
			}
		}
		else
		{
			packet.data.ReadBYTE();
			packet.data.ReadWORD();
		}


		result.DeathFlag = packet.data.ReadBYTE();
		packet.data.ReadBYTE(); //movement flag
		packet.data.ReadBYTE(); //berserk gauge
		packet.data.ReadBYTE(12); //walk speeds

		byte skillcount = packet.data.ReadBYTE();
		for (int s = 0; s < skillcount; s++)
		{
			uint skillid = Functions.ReverseNumber(packet.data.ReadDWORD()); // ID
			packet.data.ReadDWORD(); // SKILL UNIQUE ID

			foreach (SkillData sd in Main.Skills)
			{
				if (sd.ID == skillid)
				{
					if (Functions.extraByte(sd.pk2name) == true)
						packet.data.ReadBYTE();
					break;
				}
			}
		}

		byte action = packet.data.ReadBYTE();

		if (action == 2)
			packet.data.ReadDWORD();
		else if (action != 0x00)
			packet.data.ReadBYTE(packet.data.ReadBYTE());

		Main.UpdateSpawns(result, true);
	//}

	//catch
	//{
	//    string packetasstring = "S->C(" + packet.Opc.ToString("X4") + ") ";
	//    foreach (byte b in packet.ToByteArray())
	//    {
	//        packetasstring += b.ToString("X2");
	//    }


	//    System.IO.File.AppendAllText(System.Environment.CurrentDirectory + "\\err_npc.txt", packetasstring + "\r\n" + "Pos:" + packet.data.pointer.ToString() + " LEN:" + packet.data.len.ToString() + " START POS:" + startpos.ToString() + " MODEL:" + result.model.ToString("X8") + "\r\n");

	//}

	return packet.data.pointer;

}
Update 00:29
You can also parse it with the Media.pk2

[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
03/09/2015 00:25 fakeheader#10
Thanks alot
03/09/2015 00:30 Devsome#11
Just check my Update.
You're welcome, just don't copy & paste.
Try it on your own :awesome:
03/09/2015 16:28 fakeheader#12
I have already made my single/group spawn parser functions
I will just try to modify your function and make it more dynamic
thanks again