Пример #1
0
        public static void Init()
        {
            if (!NpcPos.LoadFile("Data\\npcpos.bin.json"))
            {
                throw new FileNotFoundException("Missing npcpos.bin.json file.");
            }

            _parsedNpcs = new Dictionary <uint, SendUnitSpawn>();
            _parsedNpcs.Clear();
            var filePaths = Directory.GetDirectories(Path + "Npcs\\").SelectMany(dir => Directory.GetFiles(dir, "*.json")).ToList();

            foreach (var file in filePaths)
            {
                var tData = File.ReadAllText(file);
                var temp  = JsonConvert.DeserializeObject <SendUnitSpawn>(tData);
                if (!_parsedNpcs.ContainsKey(temp.ConnectionId))
                {
                    _parsedNpcs.Add(temp.ConnectionId, temp);
                }
            }

            var storeTypeData = File.ReadAllText(StoreTypePath);

            _storeType = JsonConvert.DeserializeObject <List <ushort> >(storeTypeData) ?? new List <ushort>();
        }
Пример #2
0
        public static void ParseNpcToFile(byte[] data)
        {
            var temp = new SendUnitSpawn();

            using (var ms = new MemoryStream(data))
                using (var stream = new BinaryReader(ms, Encoding))
                {
                    stream.ReadInt32();
                    temp.ConnectionId = stream.ReadUInt16();
                    stream.ReadUInt16();
                    stream.ReadInt32();
                    temp.Name        = Encoding.GetString(stream.ReadBytes(16)).Trim('\u0000');
                    temp.Hair        = stream.ReadUInt16();
                    temp.Face        = stream.ReadUInt16();
                    temp.Helmet      = stream.ReadUInt16();
                    temp.Armor       = stream.ReadUInt16();
                    temp.Gloves      = stream.ReadUInt16();
                    temp.Pants       = stream.ReadUInt16();
                    temp.Weapon      = stream.ReadUInt16();
                    temp.Shield      = stream.ReadUInt16();
                    temp.Refinements = stream.ReadBytes(12);
                    temp.CoordX      = stream.ReadSingle();
                    temp.CoordY      = stream.ReadSingle();
                    temp.Rotation    = stream.ReadInt16();
                    stream.ReadUInt16();
                    temp.Hp        = stream.ReadInt32();
                    temp.Mp        = stream.ReadInt32();
                    temp.MaxHp     = stream.ReadInt32();
                    temp.MaxMp     = stream.ReadInt32();
                    temp.Unk       = stream.ReadUInt16();
                    temp.SpawnType = stream.ReadByte();
                    temp.Width     = stream.ReadByte();
                    temp.Chest     = stream.ReadByte();
                    temp.Leg       = stream.ReadByte();
                    temp.ConId     = stream.ReadUInt16();
                    temp.Unk2      = stream.ReadInt16();
                    stream.ReadUInt16();
                    for (var i = 0; i < 60; i++)
                    {
                        var tBuff = stream.ReadUInt16();
                        if (tBuff > 0)
                        {
                            temp.Buffs.Add(tBuff);
                        }
                    }

                    for (var i = 0; i < 120; i++)
                    {
                        var tUnk = stream.ReadUInt16();
                        if (tUnk > 0)
                        {
                            temp.Unk3.Add(tUnk);
                        }
                    }

                    temp.Title = Encoding.GetString(stream.ReadBytes(32)).Trim('\u0000');
                    stream.ReadInt32();
                    temp.Unk4 = stream.ReadUInt16();
                }

            if (!ushort.TryParse(temp.Name, out var npcId))
            {
                return;
            }

            temp.NpcId  = npcId;
            temp.NpcIdX = NpcPos.GetNpcIdX(temp.NpcId);

            var pathFile = NpcPos.IsStaticNpc(npcId)
                ? $"{Path}Npcs\\{temp.NpcId}\\UnitData.json"
                : $"{Path}Npcs\\NonStatic\\{temp.NpcId}\\UnitData.json";

            SaveToFile(pathFile, temp);
        }