Ejemplo n.º 1
0
 public void AddChildToList(MapDataStoreNode child)
 {
     if (ChildrenList == null)
     {
         ChildrenList = new List <MapDataStoreNode>();
     }
     ChildrenList.Add(child);
 }
Ejemplo n.º 2
0
        public void Load(byte[] data, RpfFileEntry entry)
        {
            FileEntry = entry;

            MemoryStream ms = new MemoryStream(data);
            BinaryReader br = new BinaryReader(ms);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; (i < 100) && (i < data.Length); i++)
            {
                //read version string.
                byte b = data[i];
                if (b == 0)
                {
                    break;
                }
                sb.Append((char)b);
            }
            string versionstr = sb.ToString();

            sb.Clear();
            int           lastn       = 0;
            int           lspos       = 0;
            uint          structcount = 0;
            uint          modlen;
            bool          indates             = false;
            List <string> lines               = new List <string>();
            var           dates               = new List <CacheFileDate>();
            var           allMapNodes         = new List <MapDataStoreNode>();
            var           allCInteriorProxies = new List <CInteriorProxy>();
            var           allBoundsStoreItems = new List <BoundsStoreItem>();

            for (int i = 100; i < data.Length; i++)
            {
                byte b = data[i];
                if (b == 0)
                {
                    break;
                }
                if (b == 0xA)
                {
                    lastn = i;
                    string line = sb.ToString();
                    lines.Add(line);
                    switch (line)
                    {
                    case "<fileDates>":
                        indates = true;
                        break;

                    case "</fileDates>":
                        indates = false;
                        break;

                    case "<module>":
                        break;

                    case "</module>":
                        break;

                    case "fwMapDataStore":
                        ms.Position = i + 1;
                        modlen      = br.ReadUInt32();
                        structcount = modlen / 64;
                        lspos       = i + (int)modlen + 5;
                        while (ms.Position < lspos)
                        {
                            allMapNodes.Add(new MapDataStoreNode(br));
                        }
                        //if (allMapNodes.Count != structcount)
                        //{ }//test fail due to variable length struct
                        i += (int)(modlen + 4);
                        break;

                    case "CInteriorProxy":
                        ms.Position = i + 1;
                        modlen      = br.ReadUInt32();
                        structcount = modlen / 104;
                        lspos       = i + (int)modlen + 5;
                        while (ms.Position < lspos)
                        {
                            allCInteriorProxies.Add(new CInteriorProxy(br));
                        }
                        if (allCInteriorProxies.Count != structcount)
                        {
                        }      //all pass here
                        i += (int)(modlen + 4);
                        break;

                    case "BoundsStore":
                        ms.Position = i + 1;
                        modlen      = br.ReadUInt32();
                        structcount = modlen / 32;
                        lspos       = i + (int)modlen + 5;
                        while (ms.Position < lspos)
                        {
                            allBoundsStoreItems.Add(new BoundsStoreItem(br));
                        }
                        if (allBoundsStoreItems.Count != structcount)
                        {
                        }      //all pass here
                        i += (int)(modlen + 4);
                        break;

                    default:
                        if (!indates)
                        {
                        }       //just testing
                        else
                        {
                            dates.Add(new CacheFileDate(line));    //eg: 2740459947 130680580712018938 8944
                        }
                        break;
                    }

                    sb.Clear();
                }
                else
                {
                    sb.Append((char)b);
                }
            }
            FileDates           = dates.ToArray();
            AllMapNodes         = allMapNodes.ToArray();
            AllCInteriorProxies = allCInteriorProxies.ToArray();
            AllBoundsStoreItems = allBoundsStoreItems.ToArray();

            MapNodeDict = new Dictionary <uint, MapDataStoreNode>();
            var rootMapNodes = new List <MapDataStoreNode>();

            foreach (var mapnode in AllMapNodes)
            {
                MapNodeDict[mapnode.Name] = mapnode;
                if (mapnode.ParentName == 0)
                {
                    rootMapNodes.Add(mapnode);
                }
                if (mapnode.UnkExtra != null)
                {
                }  //notsure what to do with this
            }
            foreach (var mapnode in AllMapNodes)
            {
                MapDataStoreNode pnode;
                if (MapNodeDict.TryGetValue(mapnode.ParentName, out pnode))
                {
                    pnode.AddChildToList(mapnode);
                }
                else if ((mapnode.ParentName != 0))
                {
                }
            }
            foreach (var mapnode in AllMapNodes)
            {
                mapnode.ChildrenListToArray();
            }
            RootMapNodes = rootMapNodes.ToArray();



            BoundsStoreDict = new Dictionary <MetaHash, BoundsStoreItem>();
            foreach (BoundsStoreItem item in AllBoundsStoreItems)
            {
                BoundsStoreItem mbsi = null;
                if (BoundsStoreDict.TryGetValue(item.Name, out mbsi))
                {
                }
                BoundsStoreDict[item.Name] = item;
            }

            //InteriorProxyDict = new Dictionary<MetaHash, CInteriorProxy>();
            foreach (CInteriorProxy prx in AllCInteriorProxies)
            {
                //CInteriorProxy mprx = null;
                //if (InteriorProxyDict.TryGetValue(prx.Name, out mprx))
                //{ }
                //InteriorProxyDict[prx.Name] = prx;//can't do this! multiples with same name different pos


                MapDataStoreNode mnode = null;
                if (MapNodeDict.TryGetValue(prx.Parent, out mnode))
                {
                    mnode.AddInteriorToList(prx);
                }
                else
                {
                }
            }
            foreach (var mapnode in AllMapNodes)
            {
                mapnode.InteriorProxyListToArray();
            }


            br.Dispose();
            ms.Dispose();
        }