Example #1
0
        private void exportAsObjToolStripMenuItem_Click(object sender, EventArgs e)
        {
            byte[]         data = BF2FileSystem.GetFileFromNode(tv2.SelectedNode);
            string         path = BF2FileSystem.GetPathFromNode(tv2.SelectedNode);
            string         name = Path.GetFileNameWithoutExtension(path) + ".obj";
            string         ext  = Path.GetExtension(path);
            SaveFileDialog dlg  = new SaveFileDialog();

            dlg.FileName = name;
            dlg.Filter   = "*.obj|*.obj";
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                switch (ext)
                {
                case ".staticmesh":
                    ExporterObj.Export(new BF2StaticMesh(data), dlg.FileName, toolStripComboBox1.SelectedIndex);
                    break;

                case ".bundledmesh":
                    ExporterObj.Export(new BF2BundledMesh(data), dlg.FileName, toolStripComboBox1.SelectedIndex);
                    break;

                case ".skinnedmesh":
                    ExporterObj.Export(new BF2SkinnedMesh(data), dlg.FileName, toolStripComboBox1.SelectedIndex);
                    break;

                case ".collisionmesh":
                    ExporterObj.Export(new BF2CollisionMesh(data), dlg.FileName);
                    break;
                }
                Log.WriteLine(dlg.FileName + " exported.");
            }
        }
Example #2
0
        private void tv1_DoubleClick(object sender, EventArgs e)
        {
            if (tv1.SelectedNode == null)
            {
                return;
            }
            byte[] data = BF2FileSystem.GetFileFromNode(tv1.SelectedNode);
            if (data == null)
            {
                return;
            }
            string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv1.SelectedNode)).ToLower();

            switch (ending)
            {
            case ".inc":
            case ".xml":
            case ".txt":
            case ".con":
            case ".tweak":
                TextEditor te = new TextEditor();
                te.rtb1.Text = Encoding.ASCII.GetString(data);
                te.ShowDialog();
                if (te._exitOk)
                {
                    BF2FileSystem.SetFileFromNode(tv1.SelectedNode, Encoding.ASCII.GetBytes(te.rtb1.Text));
                }
                break;
            }
        }
Example #3
0
        private void contextMenuMeshes_Opening(object sender, CancelEventArgs e)
        {
            exportAsObjToolStripMenuItem.Enabled = true;
            if (tv2.SelectedNode == null)
            {
                exportAsObjToolStripMenuItem.Enabled = false;
                return;
            }
            byte[] data = BF2FileSystem.GetFileFromNode(tv2.SelectedNode);
            if (data == null)
            {
                exportAsObjToolStripMenuItem.Enabled = false;
                return;
            }
            string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv2.SelectedNode)).ToLower();

            switch (ending)
            {
            case ".staticmesh":
            case ".skinnedmesh":
            case ".bundledmesh":
            case ".collisionmesh":
                break;

            default:
                exportAsObjToolStripMenuItem.Enabled = false;
                return;
            }
        }
Example #4
0
        private static Texture2D FindRoadTexture(string templateName)
        {
            Texture2D result = null;

            BF2FileSystem.BF2FSEntry e = BF2FileSystem.FindEntryFromIngamePath("objects\\roads\\Splines\\" + templateName + ".con");
            if (e == null)
            {
                return(result);
            }
            byte[] data = BF2FileSystem.GetFileFromZip(e.zipFile, e.inZipPath);
            if (data == null)
            {
                return(result);
            }
            List <string> lines   = new List <string>(Encoding.ASCII.GetString(data).Split('\n'));
            string        texName = Helper.FindLineStartingWith(lines, "RoadTemplateTexture.SetTextureFile");

            if (texName == null)
            {
                return(result);
            }
            texName = texName.Split(' ')[1].Replace("\"", "").Trim() + ".dds";
            result  = engine.textureManager.FindTextureByPath(texName);
            if (result == null)
            {
                result = engine.defaultTexture;
            }
            return(result);
        }
Example #5
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;
            }
        }
Example #6
0
 private void RefreshTrees()
 {
     tv1.Nodes.Clear();
     tv1.Nodes.Add(BF2FileSystem.MakeFSTree());
     tv2.Nodes.Clear();
     tv2.Nodes.Add(BF2FileSystem.MakeFSTreeFiltered(new string[] { ".staticmesh", ".bundledmesh", ".skinnedmesh", ".collisionmesh" }));
     tv3.Nodes.Clear();
     tv3.Nodes.Add(BF2HUDLoader.MakeTree());
     listBox1.Items.Clear();
     foreach (string objname in BF2Level.MakeList())
     {
         listBox1.Items.Add(objname);
     }
 }
Example #7
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string         name = Path.GetFileName(BF2FileSystem.GetPathFromNode(tv1.SelectedNode));
            string         ext  = Path.GetExtension(name);
            OpenFileDialog dlg  = new OpenFileDialog();

            dlg.FileName = name;
            dlg.Filter   = "*" + ext + "|*" + ext;
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                BF2FileSystem.SetFileFromNode(tv1.SelectedNode, File.ReadAllBytes(dlg.FileName));
                Log.WriteLine(dlg.FileName + " imported.");
            }
        }
Example #8
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);
        }
Example #9
0
        public Texture2D FindTextureByPath(string path)
        {
            if (loadedTextures.ContainsKey(path))
            {
                return(loadedTextures[path]);
            }
            BF2FileSystem.BF2FSEntry e = BF2FileSystem.FindEntryFromIngamePath(path.Replace("/", "\\"));
            if (e == null)
            {
                return(null);
            }
            byte[] data = BF2FileSystem.GetFileFromZip(e.zipFile, e.inZipPath);
            if (data == null)
            {
                return(null);
            }
            string ext      = Path.GetExtension(e.inFSPath).ToLower();
            string tmpfile  = "tmp" + ext;
            string tmpfile2 = "tmp.png";

            if (File.Exists(tmpfile2))
            {
                File.Delete(tmpfile2);
            }
            File.WriteAllBytes(tmpfile, data);
            Texture2D result = null;

            switch (ext)
            {
            case ".dds":
                Helper.ConvertToPNG("tmp.dds");
                if (File.Exists(tmpfile2))
                {
                    System.Drawing.Bitmap bmp = Helper.LoadBitmapUnlocked(tmpfile2);
                    result = CreateTexture2DFromBitmap(engine.device, CreateWICBitmapFromGDI(bmp));
                    bmp.Dispose();
                    File.Delete(tmpfile2);
                }
                break;
            }
            File.Delete(tmpfile);
            if (result != null)
            {
                Log.WriteLine("[BF2 TM] Loaded texture " + path);
                loadedTextures.Add(path, result);
            }
            return(result);
        }
Example #10
0
        public static void Load(string filename)
        {
            Log.WriteLine("[BF2 HL]  running \"" + filename + "\"...");
            BF2FileSystem.BF2FSEntry e = BF2FileSystem.FindEntryFromIngamePath(filename);
            if (e == null)
            {
                return;
            }
            byte[] data = BF2FileSystem.GetFileFromZip(e.zipFile, e.inZipPath);
            if (data == null)
            {
                Log.WriteLine("[BF2 HL]  ERROR file not found!");
                return;
            }
            string basePath = Path.GetDirectoryName(filename) + "\\";

            string[] lines = SplitBinText(data);
            int      count = 0;

            foreach (string line in lines)
            {
                count++;
                string[] parts;
                string   tmp = line.ToLower();
                if (tmp.Trim() == "")
                {
                    continue;
                }
                if (tmp.StartsWith("rem"))
                {
                    continue;
                }
                if (tmp.StartsWith("run"))
                {
                    parts = line.Split(' ');
                    Load(basePath + parts[1].Replace("\"", "").Replace("/", "\\"));
                }
                else if (tmp.StartsWith("hudbuilder"))
                {
                    BF2HUDBuilder.ProcessLine(line, count);
                }
                else if (tmp.StartsWith("hudmanager"))
                {
                    BF2HUDManager.ProcessLine(line, count);
                }
            }
        }
Example #11
0
 private static void LoadTerrain()
 {
     Log.WriteLine("[BF2 LL] Loading terrain...");
     BF2FileSystem.BF2FSEntry e = BF2FileSystem.FindEntryFromIngamePath("Levels\\" + name + "\\terraindata.raw");
     if (e == null)
     {
         return;
     }
     byte[] data = BF2FileSystem.GetFileFromZip(e.zipFile, e.inZipPath);
     if (data == null)
     {
         return;
     }
     terrain = new BF2Terrain(data);
     terrain.ConvertForEngine(engine);
     engine.terrain = terrain.ro;
 }
Example #12
0
        private void PickMesh()
        {
            if (tv2.SelectedNode == null)
            {
                return;
            }
            engineMeshExplorer.ClearScene();
            byte[] data = BF2FileSystem.GetFileFromNode(tv2.SelectedNode);
            if (data == null)
            {
                return;
            }
            string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv2.SelectedNode)).ToLower();

            switch (ending)
            {
            case ".staticmesh":
                BF2StaticMesh stm = new BF2StaticMesh(data);
                engineMeshExplorer.objects.AddRange(stm.ConvertForEngine(engineMeshExplorer, toolStripButton3.Checked, toolStripComboBox1.SelectedIndex));
                break;

            case ".bundledmesh":
                BF2BundledMesh bm = new BF2BundledMesh(data);
                engineMeshExplorer.objects.AddRange(bm.ConvertForEngine(engineMeshExplorer, toolStripButton3.Checked, toolStripComboBox1.SelectedIndex));
                break;

            case ".skinnedmesh":
                BF2SkinnedMesh skm = new BF2SkinnedMesh(data);
                engineMeshExplorer.objects.AddRange(skm.ConvertForEngine(engineMeshExplorer, toolStripButton3.Checked, toolStripComboBox1.SelectedIndex));
                break;

            case ".collisionmesh":
                BF2CollisionMesh cm = new BF2CollisionMesh(data);
                engineMeshExplorer.objects.AddRange(cm.ConvertForEngine(engineMeshExplorer));
                break;

            default:
                RenderObject o = new RenderObject(engineMeshExplorer.device, RenderObject.RenderType.TriListWired, engineMeshExplorer.defaultTexture, engineMeshExplorer);
                o.InitGeometry();
                engineMeshExplorer.objects.Add(o);
                break;
            }
            engineMeshExplorer.ResetCameraDistance();
        }
Example #13
0
        private static void LoadRoadObjects()
        {
            Log.WriteLine("[BF2 LL] Loading roads...");
            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;
            }
            string[] lines = Encoding.ASCII.GetString(data).Split('\n');
            int      pos   = 0;
            int      count = 0;

            while (pos < lines.Length)
            {
                Log.SetProgress(0, lines.Length, pos);
                List <string> objectInfos = new List <string>();
                while (lines[pos].Trim() != "")
                {
                    objectInfos.Add(lines[pos++].Trim());
                }
                LoadRoadObject(objectInfos);
                pos++;
                if (count++ > 10)
                {
                    count = 0;
                    GC.Collect();
                }
            }
            Vector3 center = Vector3.Zero;

            foreach (BF2LevelObject lo in objects)
            {
                center += lo.position;
            }
            center       /= objects.Count();
            engine.CamPos = center;
            Log.SetProgress(0, lines.Length, 0);
        }
Example #14
0
 private void MainForm_Activated(object sender, EventArgs e)
 {
     if (init)
     {
         return;
     }
     BF2FileSystem.Load();
     BF2HUDLoader.Init();
     Log.WriteLine("Done. Loaded " + (BF2FileSystem.clientFS.Count() + BF2FileSystem.serverFS.Count()) + " files");
     RefreshTrees();
     engineMeshExplorer               = new Engine3D(pic2);
     engineLevelExplorer              = new Engine3D(pic3);
     BF2Level.engine                  = engineLevelExplorer;
     engineLevelExplorer.renderLevel  = true;
     renderTimerMeshes.Enabled        = true;
     renderTimerLevel.Enabled         = true;
     toolStripComboBox1.SelectedIndex = 0;
     init = true;
 }
Example #15
0
        private static BF2StaticMesh LoadStaticMesh(List <string> infos, BF2LevelObject lo)
        {
            string geoTemplate = Helper.FindLineStartingWith(infos, "GeometryTemplate.create");

            if (geoTemplate == null)
            {
                return(null);
            }
            string[] parts        = geoTemplate.Split(' ');
            string   templateName = parts[2].Trim() + ".staticmesh";

            BF2FileSystem.BF2FSEntry entry = BF2FileSystem.FindFirstEntry(templateName);
            byte[] data = BF2FileSystem.GetFileFromEntry(entry);
            if (data == null)
            {
                return(null);
            }
            lo._data = data;
            return(new BF2StaticMesh(data));
        }
Example #16
0
        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            if (tv1.SelectedNode == null)
            {
                e.Cancel = true;
                return;
            }
            byte[] data = BF2FileSystem.GetFileFromNode(tv1.SelectedNode);
            if (data == null)
            {
                e.Cancel = true;
                return;
            }
            string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv1.SelectedNode)).ToLower();

            switch (ending)
            {
            default:

                break;
            }
        }
Example #17
0
        private void mountLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LevelSelect ls = new LevelSelect();

            ls.basepath = BF2FileSystem.basepath + "Levels\\";
            ls.ShowDialog();
            if (ls._exitOK)
            {
                mountLevelToolStripMenuItem.Enabled = false;
                isLoading       = true;
                consoleBox.Text = "";
                BF2FileSystem.Load();
                BF2FileSystem.LoadLevel(ls.result);
                BF2Level.engine = engineLevelExplorer;
                BF2Level.name   = ls.result;
                BF2Level.Load();
                Log.WriteLine("Done. Loaded " + (BF2FileSystem.clientFS.Count() + BF2FileSystem.serverFS.Count()) + " files");
                RefreshTrees();
                isLoading = false;
                saveChangesToolStripMenuItem.Enabled    =
                    mountLevelToolStripMenuItem.Enabled = true;
            }
        }
Example #18
0
        private void tv1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            byte[] data = BF2FileSystem.GetFileFromNode(tv1.SelectedNode);
            if (data == null)
            {
                return;
            }
            string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv1.SelectedNode)).ToLower();

            rtb1.Visible         =
                hb1.Visible      =
                    pic1.Visible = false;
            switch (ending)
            {
            case ".inc":
            case ".xml":
            case ".txt":
            case ".con":
            case ".tweak":
                rtb1.Visible = true;
                rtb1.Text    = Encoding.ASCII.GetString(data);
                break;

            case ".png":
                pic1.Visible = true;
                pic1.Image   = new Bitmap(new MemoryStream(data));
                break;

            case ".tga":
                File.WriteAllBytes("temp.tga", data);
                Helper.ConvertToPNG("temp.tga");
                pic1.Visible = true;
                if (File.Exists("temp.png"))
                {
                    pic1.Image = new Bitmap(new MemoryStream(File.ReadAllBytes("temp.png")));
                    File.Delete("temp.png");
                }
                else
                {
                    pic1.Image  = null;
                    pic1.Height = pic1.Width = 1;
                }
                File.Delete("temp.tga");
                break;

            case ".dds":
                File.WriteAllBytes("temp.dds", data);
                Helper.ConvertToPNG("temp.dds");
                pic1.Visible = true;
                if (File.Exists("temp.png"))
                {
                    pic1.Image = new Bitmap(new MemoryStream(File.ReadAllBytes("temp.png")));
                    File.Delete("temp.png");
                }
                else
                {
                    pic1.Image  = null;
                    pic1.Height = pic1.Width = 1;
                }
                File.Delete("temp.dds");
                break;

            default:
                hb1.Visible      = true;
                hb1.ByteProvider = new DynamicByteProvider(data);
                break;
            }
        }
Example #19
0
        private static void LoadRoadObject(List <string> infos)
        {
            string objectName = Helper.FindLineStartingWith(infos, "object.create");

            if (objectName == null)
            {
                return;
            }
            string meshName = Helper.FindLineStartingWith(infos, "object.geometry.loadMesh");

            if (meshName == null)
            {
                return;
            }
            string  position = Helper.FindLineStartingWith(infos, "object.absolutePosition");
            Vector3 pos      = Vector3.Zero;
            Vector3 rot      = Vector3.Zero;

            if (position != null)
            {
                pos = Helper.ParseVector3(position.Split(' ')[1]);
            }
            objectName = objectName.Split(' ')[1];
            meshName   = meshName.Split(' ')[1];
            BF2LevelObject lo          = null;
            bool           foundCached = false;

            foreach (BF2LevelObject obj in objects)
            {
                if (obj._template == meshName && obj.type == BF2LevelObject.BF2LOTYPE.Road)
                {
                    lo            = new BF2LevelObject(pos, rot, obj.type);
                    lo._template  = meshName;
                    lo._name      = objectName;
                    lo._data      = obj._data.ToArray();
                    lo.properties = infos;
                    switch (obj.type)
                    {
                    case BF2LevelObject.BF2LOTYPE.Road:
                        BF2Mesh mesh = new BF2Mesh(lo._data);
                        if (mesh == null)
                        {
                            return;
                        }
                        Texture2D tex = FindRoadTexture(lo._name);
                        lo.meshes = mesh.ConvertForEngine(engine, tex);
                        foreach (RenderObject ro in lo.meshes)
                        {
                            ro.transform = lo.transform;
                        }
                        lo._valid   = true;
                        foundCached = true;
                        break;
                    }
                    break;
                }
            }
            if (!foundCached)
            {
                lo = new BF2LevelObject(pos, rot, BF2LevelObject.BF2LOTYPE.Road);
                BF2FileSystem.BF2FSEntry entry = BF2FileSystem.FindFirstEntry(meshName);
                lo._data = BF2FileSystem.GetFileFromEntry(entry);
                if (lo._data == null)
                {
                    return;
                }
                lo._template  = meshName;
                lo._name      = objectName;
                lo.properties = infos;
                BF2Mesh mesh = new BF2Mesh(lo._data);
                if (mesh == null)
                {
                    return;
                }
                Texture2D tex = FindRoadTexture(lo._name);
                lo.meshes = mesh.ConvertForEngine(engine, tex);
                foreach (RenderObject ro in lo.meshes)
                {
                    ro.transform = lo.transform;
                }
                lo._valid = true;
            }
            if (lo != null && lo._valid)
            {
                objects.Add(lo);
            }
        }
Example #20
0
        private static void LoadStaticObject(List <string> infos)
        {
            string templateName = Helper.FindLineStartingWith(infos, "Object.create");

            if (templateName == null)
            {
                return;
            }
            string  position = Helper.FindLineStartingWith(infos, "Object.absolutePosition");
            string  rotation = Helper.FindLineStartingWith(infos, "Object.rotation");
            Vector3 pos      = Vector3.Zero;
            Vector3 rot      = Vector3.Zero;

            if (position != null)
            {
                pos = Helper.ParseVector3(position.Split(' ')[1]);
            }
            if (rotation != null)
            {
                rot = Helper.ParseVector3(rotation.Split(' ')[1]);
            }
            templateName = templateName.Split(' ')[1] + ".con";
            BF2LevelObject lo          = null;
            bool           foundCached = false;

            foreach (BF2LevelObject obj in objects)
            {
                if (obj._template == templateName && obj.type == BF2LevelObject.BF2LOTYPE.StaticObject)
                {
                    lo            = new BF2LevelObject(pos, rot, obj.type);
                    lo._template  = templateName;
                    lo._name      = templateName;
                    lo._data      = obj._data.ToArray();
                    lo.properties = infos;
                    switch (obj.type)
                    {
                    case BF2LevelObject.BF2LOTYPE.StaticObject:
                        BF2StaticMesh stm = new BF2StaticMesh(lo._data);
                        if (stm == null)
                        {
                            return;
                        }
                        lo.staticMeshes = stm.ConvertForEngine(engine, true, 0);
                        foreach (RenderObject ro in lo.staticMeshes)
                        {
                            ro.transform = lo.transform;
                        }
                        lo._valid   = true;
                        foundCached = true;
                        break;
                    }
                    break;
                }
            }
            if (!foundCached)
            {
                BF2FileSystem.BF2FSEntry entry = BF2FileSystem.FindFirstEntry(templateName);
                byte[] data = BF2FileSystem.GetFileFromEntry(entry);
                if (data == null)
                {
                    return;
                }
                List <string> infosObject = new List <string>(Encoding.ASCII.GetString(data).Split('\n'));
                string        geoTemplate = Helper.FindLineStartingWith(infosObject, "GeometryTemplate.create");
                if (geoTemplate == null)
                {
                    return;
                }
                string[] parts = geoTemplate.Split(' ');
                switch (parts[1].ToLower())
                {
                case "staticmesh":
                    lo            = new BF2LevelObject(pos, rot, BF2LevelObject.BF2LOTYPE.StaticObject);
                    lo._template  = templateName;
                    lo._name      = templateName;
                    lo.properties = infos;
                    BF2StaticMesh stm = LoadStaticMesh(infosObject, lo);
                    if (stm == null)
                    {
                        return;
                    }
                    lo.staticMeshes = stm.ConvertForEngine(engine, true, 0);
                    foreach (RenderObject ro in lo.staticMeshes)
                    {
                        ro.transform = lo.transform;
                    }
                    lo._valid = true;
                    break;
                }
            }
            if (lo != null && lo._valid)
            {
                objects.Add(lo);
            }
        }
Example #21
0
        private void exportALLAsObjToolStripMenuItem_Click(object sender, EventArgs e)
        {
            exportALLAsObjToolStripMenuItem.Enabled = false;
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string basePath = fbd.SelectedPath + "\\";
                pb1.Maximum = BF2FileSystem.clientFS.Count;
                int count = 0;
                foreach (BF2FileSystem.BF2FSEntry entry in BF2FileSystem.clientFS)
                {
                    pb1.Value = count++;
                    try
                    {
                        string ending = Path.GetExtension(entry.inFSPath).ToLower();
                        switch (ending)
                        {
                        case ".staticmesh":
                        case ".bundledmesh":
                        case ".skinnedmesh":
                        case ".collisionmesh":
                            break;

                        default:
                            continue;
                        }
                        string path = basePath + Path.GetDirectoryName(entry.inFSPath);
                        byte[] data = BF2FileSystem.GetFileFromEntry(entry);
                        if (data == null)
                        {
                            continue;
                        }
                        switch (ending)
                        {
                        case ".staticmesh":
                            CheckAndMakeDir(path);
                            path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath);
                            Log.WriteLine("Exporting \"" + path + ".staticmesh\"...");
                            BF2StaticMesh stm = new BF2StaticMesh(data);
                            for (int i = 0; i < stm.geomat.Count; i++)
                            {
                                ExporterObj.Export(stm, path + ".lod" + i + ".obj", i);
                            }
                            break;

                        case ".bundledmesh":
                            CheckAndMakeDir(path);
                            path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath);
                            Log.WriteLine("Exporting \"" + path + ".bundledmesh\"...");
                            BF2BundledMesh bm = new BF2BundledMesh(data);
                            for (int i = 0; i < bm.geomat.Count; i++)
                            {
                                ExporterObj.Export(bm, path + ".lod" + i + ".obj", i);
                            }
                            break;

                        case ".skinnedmesh":
                            CheckAndMakeDir(path);
                            path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath);
                            Log.WriteLine("Exporting \"" + path + ".skinnedmesh\"...");
                            BF2SkinnedMesh skm = new BF2SkinnedMesh(data);
                            for (int i = 0; i < skm.geomat.Count; i++)
                            {
                                ExporterObj.Export(skm, path + ".lod" + i + ".obj", i);
                            }
                            break;

                        case ".collisionmesh":
                            CheckAndMakeDir(path);
                            path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath);
                            Log.WriteLine("Exporting \"" + path + ".bundledmesh\"...");
                            ExporterObj.Export(new BF2CollisionMesh(data), path + ".obj");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine("ERROR: " + ex.Message);
                    }
                    Application.DoEvents();
                }
                pb1.Value = 0;
                exportALLAsObjToolStripMenuItem.Enabled = true;
            }
        }