Beispiel #1
0
 public void AddEntity(WORLD_ENTITY WE)
 {
     ENTITIES.Add(WE);
 }
Beispiel #2
0
        public VMF LoadVMF(string path, string[] SOURCES)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }

            var newvmf = new VMF();

            using (var vmf = new StreamReader(path))
            {
                string line;
                while ((line = vmf.ReadLine()) != null)
                {
                    string[] keyXvalue = line.TrimStart().Replace("\"", "").Split(' ');
                    if (keyXvalue.Length > 1)
                    {
                        if (cSOLID != null)
                        {
                            if (cSIDE != null)
                            {
                                switch (keyXvalue[0])
                                {
                                case "id":
                                    cSIDE.id = keyXvalue[1];
                                    break;

                                case "material":
                                    cSIDE.MATERIAL = keyXvalue[1];
                                    newvmf.AddMaterial("materials\\" + keyXvalue[1].Replace('/', '\\').ToLower() + ".vmt");
                                    break;
                                }
                            }
                        }

                        if (cENTITY != null)
                        {
                            switch (keyXvalue[0])
                            {
                            case "id":
                                cENTITY.id = keyXvalue[1];
                                break;

                            case "classname":
                                cENTITY.classname = keyXvalue[1];
                                break;

                            case "material":
                                cENTITY.material = keyXvalue[1];
                                break;

                            case "model":
                                cENTITY.model = keyXvalue[1];
                                break;

                            case "targetname":
                                cENTITY.targetname = keyXvalue[1];
                                break;

                            case "message":
                                cENTITY.message = keyXvalue[1];
                                break;

                            case "effect_name":
                                cENTITY.effect_name = keyXvalue[1];
                                break;
                            }
                        }
                    }
                    else
                    {
                        switch (keyXvalue[0])
                        {
                        case "versioninfo":

                            break;

                        case "visgroups":

                            break;

                        case "viewsettings":

                            break;

                        case "world":

                            break;

                        case "solid":
                            if (cSOLID != null)
                            {
                                newvmf.AddSolid(cSOLID);
                            }

                            cSOLID  = new WORLD_SOLID();
                            cENTITY = null;
                            break;

                        case "side":
                            if (cSIDE != null)
                            {
                                cSOLID.AddSide(cSIDE);
                            }

                            cSIDE   = new WORLD_SOLID_SIDE();
                            cENTITY = null;
                            break;

                        case "entity":
                            if (cSIDE != null)
                            {
                                cSOLID.AddSide(cSIDE);
                            }

                            if (cSOLID != null)
                            {
                                newvmf.AddSolid(cSOLID);
                            }

                            if (cENTITY != null)
                            {
                                newvmf.AddEntity(cENTITY);
                            }

                            cENTITY = new WORLD_ENTITY();
                            cSOLID  = null;
                            cSIDE   = null;

                            break;

                        case "cameras":
                            if (cSIDE != null)
                            {
                                cSOLID.AddSide(cSIDE);
                            }

                            if (cSOLID != null)
                            {
                                newvmf.AddSolid(cSOLID);
                            }

                            if (cENTITY != null)
                            {
                                newvmf.AddEntity(cENTITY);
                            }

                            cENTITY = null;
                            cSOLID  = null;
                            cSIDE   = null;

                            break;
                        }
                    }
                }

                foreach (WORLD_ENTITY ENT in newvmf.GetEntities())
                {
                    switch (ENT.classname)
                    {
                    case "prop_detail":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_door_rotating":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_dynamic":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_dynamic_ornament":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_physics_override":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_physics_multiplayer":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_physics":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_dynamic_override":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_thumper":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_static":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_scalable":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_ragdoll":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_vehicle":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "prop_vehicle_airboat":
                        newvmf.AddModel(ENT.model);
                        break;

                    case "ambient_generic":
                        newvmf.AddSounds("sound\\" + ENT.message);
                        break;

                    case "color_correction":
                        newvmf.AddColorCorrection(ENT.targetname);
                        break;

                    case "info_particle_system":
                        newvmf.AddPArticle(ENT.effect_name);
                        break;
                    }
                }

                vmf.Close();
            }

            foreach (var MODEL in newvmf.GetModels())
            {
                bool MODEL_FOUND = false;
                foreach (string SOURCE_PATH in SOURCES)
                {
                    string FULL_MODEL_PATH = SOURCE_PATH + "\\" + MODEL;
                    if (verbose)
                    {
                        Console.WriteLine($"MODEL : {FULL_MODEL_PATH}");
                    }
                    if (File.Exists(FULL_MODEL_PATH))
                    {
                        MODEL_FOUND = true;

                        var MDL = LoadMDL(FULL_MODEL_PATH);
                        foreach (var MAT in MDL.materials)
                        {
                            newvmf.AddMaterial(MAT);
                        }
                    }
                }

                if (!MODEL_FOUND && !MISSING_MODELS.Contains(MODEL))
                {
                    MISSING_MODELS.Add(MODEL);
                }
            }

            foreach (var MATERIAL in newvmf.GetMaterials())
            {
                bool MATERIAL_FOUND = false;
                foreach (string SOURCE_PATH in SOURCES)
                {
                    string FULL_MATERIAL_PATH = SOURCE_PATH + "\\" + MATERIAL;
                    if (verbose)
                    {
                        Console.WriteLine($"MATERIAL : {FULL_MATERIAL_PATH}");
                    }
                    if (File.Exists(FULL_MATERIAL_PATH))
                    {
                        MATERIAL_FOUND = true;

                        var MDL = LoadVMT(FULL_MATERIAL_PATH);
                        foreach (var TEX in MDL.TEXTURES)
                        {
                            string FULL_TEXTURE_PATH = SOURCE_PATH + "\\" + "materials\\" + TEX.Replace("/", "\\");
                            bool   TEXTURE_FOUND     = false;
                            if (File.Exists(FULL_TEXTURE_PATH))
                            {
                                if (verbose)
                                {
                                    Console.WriteLine($"TEXTURE : {FULL_TEXTURE_PATH}");
                                }

                                TEXTURE_FOUND = true;
                                newvmf.AddTextures("materials\\" + TEX.Replace("/", "\\"));
                            }

                            if (!TEXTURE_FOUND && !MISSING_TEXTURES.Contains("materials\\" + TEX.Replace("/", "\\")))
                            {
                                MISSING_TEXTURES.Add("materials\\" + TEX.Replace("/", "\\"));
                            }
                        }
                    }
                }

                if (!MATERIAL_FOUND && !MISSING_MATERIALS.Contains(MATERIAL))
                {
                    MISSING_MATERIALS.Add(MATERIAL);
                }
            }

            return(newvmf);
        }