예제 #1
0
        private void importLevelFromToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (BF2Level.name == "")
            {
                MessageBox.Show("Please mount a level first");
                return;
            }
            string         target = BF2FileSystem.basepath + "Levels\\" + BF2Level.name + "\\";
            OpenFileDialog d      = new OpenFileDialog();

            d.Filter = "bf2editor.exe|bf2editor.exe";
            if (d.ShowDialog() == DialogResult.OK)
            {
                string source = Path.GetDirectoryName(d.FileName) + "\\mods\\bfp4f\\Levels\\" + BF2Level.name + "\\";
                if (!Directory.Exists(source))
                {
                    Log.WriteLine("Cant find source folder \"" + source + "\"");
                    return;
                }
                Log.WriteLine("Importing Level from \"" + source + "\" to \"" + target + "\"...");
                string[] files = Directory.GetFiles(source, "*.*", SearchOption.AllDirectories);
                pb1.Maximum = files.Length;
                int count = 0;
                foreach (string file in files)
                {
                    pb1.Value = count++;
                    string shortname = file.Substring(source.Length);
                    BF2FileSystem.BF2FSEntry entry = BF2FileSystem.FindEntryFromIngamePath(shortname);
                    if (entry == null)
                    {
                        Log.WriteLine("Cant find \"" + shortname + "\"");
                        continue;
                    }
                    if (!entry.zipFile.ToLower().Contains("\\levels\\") || file.ToLower().EndsWith("ambientobjects.con"))
                    {
                        Log.WriteLine("Skipping \"" + file + "\"");
                        continue;
                    }
                    byte[] data = File.ReadAllBytes(file);
                    if (file.ToLower().EndsWith("staticobjects.con"))
                    {
                        Log.WriteLine("Processing \"" + shortname + "\"...");
                        data = ProcessStaticObjects(File.ReadAllLines(file));
                    }
                    BF2FileSystem.SetFileFromEntry(entry, data);
                    Log.WriteLine("Importing \"" + shortname + "\" into \"" + Path.GetFileName(entry.zipFile) + "\"");
                }
                Log.WriteLine("Done.");
                pb1.Value = 0;
            }
        }
예제 #2
0
        public static void SaveRoadObjects()
        {
            BF2FileSystem.BF2FSEntry e = BF2FileSystem.FindEntryFromIngamePath("Levels\\" + name + "\\CompiledRoads.con");
            if (e == null)
            {
                return;
            }
            byte[] data = BF2FileSystem.GetFileFromZip(e.zipFile, e.inZipPath);
            if (data == null)
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            foreach (BF2LevelObject lo in objects)
            {
                if (lo.type == BF2LevelObject.BF2LOTYPE.Road)
                {
                    bool foundPosition = false;
                    foreach (string line in lo.properties)
                    {
                        if (line.StartsWith("object.absoluteposition"))
                        {
                            string s = "object.absoluteposition ";
                            s += lo.position.X.ToString().Replace(',', '.') + "/";
                            s += lo.position.Y.ToString().Replace(',', '.') + "/";
                            s += lo.position.Z.ToString().Replace(',', '.');
                            sb.AppendLine(s);
                            foundPosition = true;
                        }
                        else
                        {
                            sb.AppendLine(line);
                        }
                    }
                    if (!foundPosition)
                    {
                        string s = "object.absoluteposition ";
                        s += lo.position.X.ToString().Replace(',', '.') + "/";
                        s += lo.position.Y.ToString().Replace(',', '.') + "/";
                        s += lo.position.Z.ToString().Replace(',', '.');
                        sb.AppendLine(s);
                    }
                    sb.AppendLine();
                }
            }
            sb.AppendLine();
            byte[] dataNew = Encoding.ASCII.GetBytes(sb.ToString());
            BF2FileSystem.SetFileFromEntry(e, dataNew);
        }