Ejemplo n.º 1
0
        private void resourceLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            this.EditorData.GraphicsPaths.Add("art\\misc");
            this.EditorData.GraphicsPaths.Add("art\\items");
            this.EditorData.GraphicsPaths.Add("art\\tiles");
            this.EditorData.GraphicsPaths.Add("art\\misc");
            this.EditorData.GraphicsPaths.Add("art\\walls");
            this.EditorData.GraphicsPaths.Add("art\\door");
            this.EditorData.GraphicsPaths.Add("art\\scenery");

            Stream          stream;
            BinaryFormatter formatter = new BinaryFormatter();

            stream = null;

            this.BeginInvoke((MethodInvoker) delegate
            {
                frmLoading = new frmLoading();
                frmLoading.ShowDialog();

                int count = mapperSettings.Paths.DataFiles.Count;

                if (!File.Exists("./critters.dat"))
                {
                    count++;
                }
                if (!File.Exists("./items.dat"))
                {
                    count++;
                }

                frmLoading.SetFilesNum(count);
            });


            if (File.Exists("./critters.dat"))
            {
                stream      = File.OpenRead("./critters.dat");
                critterData = (CritterData)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                List <string> crFiles = new List <string>(Directory.GetFiles(mapperSettings.Paths.CritterProtos));

                this.BeginInvoke((MethodInvoker) delegate
                {
                    frmLoading.SetNextFile(mapperSettings.Paths.CritterProtos);
                    frmLoading.SetResourceNum(crFiles.Count);
                });

                foreach (string file in crFiles)
                {
                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        frmLoading.SetNextResource(file);
                    });

                    int  pid    = 0;
                    int  crType = 0;
                    bool parse  = false;
                    foreach (var line in File.ReadAllLines(file))
                    {
                        if (line == "[Critter proto]")
                        {
                            if (parse)
                            {
                                critterData.crProtos[pid] = crType;
                            }
                        }
                        parse = true;
                        if (!parse)
                        {
                            continue;
                        }
                        if (line.StartsWith("Pid="))
                        {
                            pid = int.Parse(line.Split('=')[1]);
                        }
                        if (line.StartsWith("ST_BASE_CRTYPE="))
                        {
                            crType = int.Parse(line.Split('=')[1]);
                        }
                    }
                }

                char[] delim = { '\t', ' ' };
                foreach (var line in File.ReadAllLines(mapperSettings.Paths.CritterTypes))
                {
                    if (!line.StartsWith("@"))
                    {
                        continue;
                    }
                    var toks = line.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                    critterData.crTypeGraphic[int.Parse(toks[1])] = toks[2];
                }
                if (mapperSettings.Performance.CacheResources)
                {
                    stream = File.Create("./critters.dat");
                    formatter.Serialize(stream, critterData);
                }
            }

            if (File.Exists("./items.dat"))
            {
                stream = File.OpenRead("./items.dat");
                items  = (List <ItemProto>)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                MSGParser FOObj = new MSGParser(mapperSettings.Paths.FOOBJ);
                FOObj.Parse();

                string itemslst = mapperSettings.Paths.ItemProtos + "\\items.lst";

                if (!File.Exists(itemslst))
                {
                    MessageBox.Show("No " + itemslst + " , unable to load item protos.", "No items.lst", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    List <string> protFiles = new List <string>(File.ReadAllLines(itemslst));

                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        frmLoading.SetNextFile(itemslst);
                        frmLoading.SetResourceNum(protFiles.Count);
                    });

                    foreach (string file in protFiles)
                    {
                        this.BeginInvoke((MethodInvoker) delegate { frmLoading.SetNextResource(file); });
                        protoParser.LoadProtosFromFile(mapperSettings.Paths.ItemProtos + file, "1.0", FOObj, items, null);
                    }
                }
                if (mapperSettings.Performance.CacheResources)
                {
                    stream = File.Create("./items.dat");
                    formatter.Serialize(stream, items);
                }
            }

            foreach (var item in items)
            {
                EditorData.itemsPid[item.ProtoId] = item;
            }

            if (File.Exists("./graphics.dat"))
            {
                stream = File.OpenRead("./graphics.dat");
                Frms   = (Dictionary <String, FalloutFRM>)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                if (mapperSettings.Paths.DataFiles == null || mapperSettings.Paths.DataFiles.Count == 0)
                {
                    MessageBox.Show("No datafiles specified, unable to load graphics!");
                    frmPaths.ShowDialog();
                }

                if (mapperSettings.Paths.DataFiles != null || mapperSettings.Paths.DataFiles.Count != 0)
                {
                    List <string> crFiles = new List <string>();
                    foreach (var crType in critterData.crTypeGraphic.Values)
                    {
                        crFiles.Add("art\\critters\\" + crType.ToUpper() + "AA.FRM"); // Idle anim
                        crFiles.Add("art\\critters\\" + crType.ToLower() + "aa.frm");
                    }

                    foreach (string dataFile in mapperSettings.Paths.DataFiles)
                    {
                        string ext = Path.GetExtension(dataFile).ToLower();
                        if (ext != ".dat" && ext != ".zip")
                        {
                            MessageBox.Show("Unknown datafile extension : " + dataFile);
                            continue;
                        }
                        if (ext == ".dat")
                        {
                            LoadDat(dataFile, crFiles, transparency);
                        }
                        else
                        {
                            LoadZip(dataFile, crFiles, transparency);
                        }
                    }

                    if (mapperSettings.Performance.CacheResources)
                    {
                        stream = File.Create("./graphics.dat");
                        formatter.Serialize(stream, Frms);
                    }
                }
            }

            showLoadMaps();

            if (stream != null)
            {
                stream.Close();
            }
        }
Ejemplo n.º 2
0
        private void resourceLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            this.EditorData.GraphicsPaths.Add("art\\misc");
            this.EditorData.GraphicsPaths.Add("art\\items");
            this.EditorData.GraphicsPaths.Add("art\\tiles");
            this.EditorData.GraphicsPaths.Add("art\\misc");
            this.EditorData.GraphicsPaths.Add("art\\walls");
            this.EditorData.GraphicsPaths.Add("art\\door");
            this.EditorData.GraphicsPaths.Add("art\\scenery");

            Stream stream;
            BinaryFormatter formatter = new BinaryFormatter();

            stream = null;

            this.BeginInvoke((MethodInvoker)delegate
            {
                frmLoading = new frmLoading();
                frmLoading.ShowDialog();

                int count = mapperSettings.Paths.DataFiles.Count;

                if (!File.Exists("./critters.dat")) count++;
                if (!File.Exists("./items.dat")) count++;

                frmLoading.SetFilesNum(count);
            });

            if (File.Exists("./critters.dat"))
            {
                stream = File.OpenRead("./critters.dat");
                critterData = (CritterData)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                List<string> crFiles = new List<string>(Directory.GetFiles(mapperSettings.Paths.CritterProtos));

                this.BeginInvoke((MethodInvoker)delegate
                {
                    frmLoading.SetNextFile(mapperSettings.Paths.CritterProtos);
                    frmLoading.SetResourceNum(crFiles.Count);
                });

                foreach (string file in crFiles)
                {
                    this.BeginInvoke((MethodInvoker)delegate
                    {
                        frmLoading.SetNextResource(file);
                    });

                    int pid = 0;
                    int crType = 0;
                    bool parse = false;
                    foreach (var line in File.ReadAllLines(file))
                    {
                        if (line == "[Critter proto]")
                            if (parse)
                                critterData.crProtos[pid] = crType;
                        parse = true;
                        if (!parse) continue;
                        if (line.StartsWith("Pid="))
                            pid = int.Parse(line.Split('=')[1]);
                        if (line.StartsWith("ST_BASE_CRTYPE="))
                            crType = int.Parse(line.Split('=')[1]);
                    }
                }

                char[] delim = { '\t', ' ' };
                foreach (var line in File.ReadAllLines(mapperSettings.Paths.CritterTypes))
                {
                    if (!line.StartsWith("@")) continue;
                    var toks = line.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                    critterData.crTypeGraphic[int.Parse(toks[1])] = toks[2];
                }
                if (mapperSettings.Performance.CacheResources)
                {
                    stream = File.Create("./critters.dat");
                    formatter.Serialize(stream, critterData);
                }
            }

            if (File.Exists("./items.dat"))
            {
                stream = File.OpenRead("./items.dat");
                items = (List<ItemProto>)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                MSGParser FOObj = new MSGParser(mapperSettings.Paths.FOOBJ);
                FOObj.Parse();

                string itemslst = mapperSettings.Paths.ItemProtos + "\\items.lst";

                if (!File.Exists(itemslst))
                {
                    MessageBox.Show("No " + itemslst + " , unable to load item protos.", "No items.lst", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    List<string> protFiles = new List<string>(File.ReadAllLines(itemslst));

                    this.BeginInvoke((MethodInvoker)delegate
                    {
                        frmLoading.SetNextFile(itemslst);
                        frmLoading.SetResourceNum(protFiles.Count);
                    });

                    foreach (string file in protFiles)
                    {
                        this.BeginInvoke((MethodInvoker)delegate { frmLoading.SetNextResource(file); });
                        protoParser.LoadProtosFromFile(mapperSettings.Paths.ItemProtos + file, "1.0", FOObj, items, null);
                    }
                }
                if (mapperSettings.Performance.CacheResources)
                {
                    stream = File.Create("./items.dat");
                    formatter.Serialize(stream, items);
                }
            }

            foreach (var item in items)
                EditorData.itemsPid[item.ProtoId] = item;

            if (File.Exists("./graphics.dat"))
            {
                stream = File.OpenRead("./graphics.dat");
                Frms = (Dictionary<String, FalloutFRM>)formatter.Deserialize(stream);
                stream.Close();
            }
            else
            {
                if (mapperSettings.Paths.DataFiles == null || mapperSettings.Paths.DataFiles.Count == 0)
                {
                    MessageBox.Show("No datafiles specified, unable to load graphics!");
                    frmPaths.ShowDialog();
                }

                if (mapperSettings.Paths.DataFiles != null || mapperSettings.Paths.DataFiles.Count != 0)
                {

                    List<string> crFiles = new List<string>();
                    foreach (var crType in critterData.crTypeGraphic.Values)
                    {
                        crFiles.Add("art\\critters\\" + crType.ToUpper() + "AA.FRM"); // Idle anim
                        crFiles.Add("art\\critters\\" + crType.ToLower() + "aa.frm");
                    }

                    foreach (string dataFile in mapperSettings.Paths.DataFiles)
                    {
                        string ext = Path.GetExtension(dataFile).ToLower();
                        if (ext != ".dat" && ext != ".zip")
                        {
                            MessageBox.Show("Unknown datafile extension : " + dataFile);
                            continue;
                        }
                        if (ext == ".dat")
                            LoadDat(dataFile, crFiles, transparency);
                        else
                            LoadZip(dataFile, crFiles, transparency);
                    }

                    if (mapperSettings.Performance.CacheResources)
                    {
                        stream = File.Create("./graphics.dat");
                        formatter.Serialize(stream, Frms);
                    }
                }
            }

            showLoadMaps();

            if (stream != null) stream.Close();
        }
Ejemplo n.º 3
0
        public bool LoadDat(string DatPath, List <string> crFiles, Color Transparency)
        {
            DatReaderError status;
            DAT            loadedDat = DATReader.ReadDat(DatPath, out status);

            if (status.Error != DatError.Success)
            {
                MessageBox.Show("Error loading " + DatPath + ": " + Environment.NewLine + status.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            List <DATFile> files = new List <DATFile>();

            foreach (string path in this.EditorData.GraphicsPaths)
            {
                files.AddRange(loadedDat.GetFilesByPattern(path));

                // Critters to load
                foreach (var crType in critterData.crTypeGraphic.Values)
                {
                    var file = loadedDat.GetFileByName("art\\critters\\" + crType.ToUpper() + "AA.FRM"); // Idle anim
                    if (file == null)
                    {
                        file = loadedDat.GetFileByName("art\\critters\\" + crType.ToLower() + "aa.frm");
                    }
                    if (file == null)
                    {
                        continue;
                    }
                    files.Add(file);
                }
            }

            this.BeginInvoke((MethodInvoker) delegate {
                frmLoading.SetNextFile(Path.GetFileName(DatPath));
                frmLoading.SetResourceNum(files.Count);
            });

            foreach (DATFile file in files)
            {
                this.BeginInvoke((MethodInvoker) delegate { frmLoading.SetNextResource(file.FileName); });

                string ext = Path.GetExtension(file.FileName).ToLower();
                if (!(ext == ".frm" || ext == ".png"))
                {
                    continue;
                }

                byte[] data = file.GetData();
                if (data == null)
                {
                    WriteLog("Error opening " + file.FileName + ": " + file.ErrorMsg);
                    continue;
                }

                if (ext == ".frm")
                {
                    var frm = FalloutFRMLoader.LoadFRM(data, Transparency);
                    frm.FileName       = file.Path.ToLower();
                    Frms[frm.FileName] = frm;
                }
                else
                {
                    System.ComponentModel.TypeConverter tc = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Bitmap));
                    Bitmap bitmap = (Bitmap)tc.ConvertFrom(data);
                }
            }
            loadedDat.Close();
            return(true);
        }