Exemplo n.º 1
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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);
        }