コード例 #1
0
        public static void GetMaps(string modpath, Dictionary <string, MapItem> mapslist, GameHandler.GetMapInfoDelegate getmapinfo)
        {
            string[] zipfiles = Directory.GetFiles(modpath, "*.pk3");
            foreach (string file in zipfiles)
            {
                if (!file.EndsWith(".pk3", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                using (var arc = ZipFile.OpenRead(file))
                {
                    foreach (var e in arc.Entries)
                    {
                        if (!GameHandler.Current.EntryIsMap(e.FullName, mapslist))
                        {
                            continue;
                        }
                        string  mapname = Path.GetFileNameWithoutExtension(e.Name);
                        MapItem mapitem;

                        if (getmapinfo != null)
                        {
                            using (var stream = e.Open())
                            {
                                var wrapper = new DeflateStreamWrapper((DeflateStream)stream, e.Length);
                                using (var reader = new BinaryReader(wrapper))
                                    mapitem = getmapinfo(mapname, reader, restype);
                            }
                        }
                        else
                        {
                            mapitem = new MapItem(mapname, restype);
                        }

                        // Add to collection
                        mapslist.Add(mapname, mapitem);
                    }
                }
            }
        }
コード例 #2
0
        public static void GetMaps(string modpath, Dictionary <string, MapItem> mapslist, GameHandler.GetMapInfoDelegate getmapinfo)
        {
            string[] pakfiles = Directory.GetFiles(modpath, "*.pak");
            foreach (string file in pakfiles)
            {
                if (!file.EndsWith(".pak", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                using (FileStream stream = File.OpenRead(file))
                {
                    using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII))
                    {
                        // Read header
                        string id = reader.ReadStringExactLength(4);
                        if (id != "PACK")
                        {
                            continue;
                        }

                        int ftoffset = reader.ReadInt32();
                        int ftsize   = reader.ReadInt32() / 64;

                        // Read file table
                        reader.BaseStream.Position = ftoffset;
                        for (int i = 0; i < ftsize; i++)
                        {
                            string entry  = reader.ReadStringExactLength(56).Trim();     // Read entry name
                            int    offset = reader.ReadInt32();
                            reader.BaseStream.Position += 4;                             // Skip unrelated stuff

                            if (!GameHandler.Current.EntryIsMap(entry, mapslist))
                            {
                                continue;
                            }
                            string  mapname = Path.GetFileNameWithoutExtension(entry);
                            MapItem mapitem;

                            if (getmapinfo != null)
                            {
                                // Store position
                                long curpos = reader.BaseStream.Position;

                                // Go to data location
                                reader.BaseStream.Position = offset;
                                mapitem = getmapinfo(mapname, reader, restype);

                                // Restore position
                                reader.BaseStream.Position = curpos;
                            }
                            else
                            {
                                mapitem = new MapItem(mapname, restype);
                            }

                            // Add to collection
                            mapslist.Add(mapname, mapitem);
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static void GetMaps(string modpath, Dictionary <string, MapItem> mapslist, GameHandler.GetMapInfoDelegate getmapinfo)
        {
            DirectoryInfo mapdir = new DirectoryInfo(Path.Combine(modpath, "maps"));

            if (!mapdir.Exists)
            {
                return;
            }

            // Get the map files
            string[] mapnames = Directory.GetFiles(mapdir.FullName, "*.bsp");
            foreach (string file in mapnames)
            {
                if (!GameHandler.Current.EntryIsMap(file, mapslist))
                {
                    continue;
                }
                string  mapname = Path.GetFileNameWithoutExtension(file);
                MapItem mapitem;

                if (getmapinfo != null)
                {
                    using (FileStream stream = File.OpenRead(file))
                        using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII))
                            mapitem = getmapinfo(mapname, reader, restype);
                }
                else
                {
                    mapitem = new MapItem(mapname, restype);
                }

                // Add to collection
                mapslist.Add(mapname, mapitem);
            }
        }