Ejemplo n.º 1
0
        public ModInfo(string modFolder)
        {
            this.ModFolder = FilesFinder.FixPath(modFolder);
            L = Lua.luaL_newstate();
            Lua.luaL_openlibs(L);
            CLua.TraceDoString(L, 0, Resources.luastuff);

            ProcessResources();
            ProcessExplosions();
            ProcessWeapons();
        }
Ejemplo n.º 2
0
        void ProcessResources()
        {
            var     resourcesPath = ModFolder + "\\gamedata\\resources.lua";
            dynamic resources     = CLua.TraceDoString(L, 1, File.ReadAllText(resourcesPath))[0];

            ProjectileTextures = new Dictionary <string, string>();
            var textures = resources.GetField("graphics").GetField("projectiletextures");

            foreach (var kvp in textures.Values)
            {
                ProjectileTextures.Add(kvp.Key.Value, FilesFinder.FixPath(ModFolder + "/bitmaps/" + textures.GetField(kvp.Key.Value).Value));
            }
        }
Ejemplo n.º 3
0
 static FilesFinder()
 {
     L = Lua.luaL_newstate();
     Lua.luaL_openlibs(L);
     CLua.TraceDoString(L, 0, Resources.luastuff);
 }
Ejemplo n.º 4
0
        void ProcessUnitFile()
        {
            customExplosions = new List <string>();
            var modelFileNames = new List <string>();
            var soundNames     = new List <string>();

            dynamic unitTable  = CLua.TraceDoString(L, 1, File.ReadAllText(unitFilePath))[0].GetField(unitName);
            var     objectName = unitTable.GetField("objectname");

            modelFileNames.Add(objectName.Value);
            buildpic = FixPath(mod.ModFolder + "/unitpics/" + unitTable.GetField("buildpic").Value);
            var sfxTypes = unitTable.GetField("sfxtypes");

            if (sfxTypes is LuaTable)
            {
                var explosionGenerators = sfxTypes.GetField("explosiongenerators");
                if (explosionGenerators is LuaTable)
                {
                    foreach (var kvp in explosionGenerators.Values)
                    {
                        var value = kvp.Value.Value;
                        if (value.StartsWith("custom:"))
                        {
                            customExplosions.Add(value.Substring(7, value.Length - 7).ToLower());
                        }
                    }
                }
            }
            string explodeAs = unitTable.GetField("explodeas").Value.ToLower();

            if (mod.WeaponExplosions.ContainsKey(explodeAs))
            {
                customExplosions.Add(mod.WeaponExplosions[explodeAs]);
                weaponFiles.Add(mod.WeaponFiles[explodeAs]);
            }
            else
            {
                customExplosions.Add(explodeAs);
            }


            var weaponDefs = unitTable.GetField("weapondefs");

            if (weaponDefs is LuaTable)
            {
                foreach (var kvp in weaponDefs.Values)
                {
                    var weaponDef          = kvp.Value;
                    var explosionGenerator = weaponDef.GetField("explosiongenerator");
                    if (explosionGenerator != null)
                    {
                        var value = explosionGenerator.Value;
                        if (value.StartsWith("custom:"))
                        {
                            customExplosions.Add(value.Substring(7, value.Length - 7).ToLower());
                        }
                    }
                    var cegTag = weaponDef.GetField("cegtag");
                    if (cegTag != null)
                    {
                        customExplosions.Add(cegTag.Value.ToLower());
                    }
                    var model = weaponDef.GetField("model");
                    if (model != null)
                    {
                        modelFileNames.Add(model.Value);
                    }
                    var soundHit = weaponDef.GetField("soundhit");
                    if (soundHit != null)
                    {
                        soundNames.Add(soundHit.Value);
                    }
                    var soundStart = weaponDef.GetField("soundstart");
                    if (soundStart != null)
                    {
                        soundNames.Add(soundStart.Value);
                    }
                    for (var i = 1; i <= 10; i++)
                    {
                        var texture = weaponDef.GetField("texture" + i);
                        if (texture != null)
                        {
                            customTextures.Add(texture.Value.ToLower());
                        }
                    }
                }
            }

            var groundDecalType = unitTable.GetField("buildinggrounddecaltype");

            if (groundDecalType is LuaString)
            {
                groundDecal = mod.ModFolder + "/unittextures/" + groundDecalType.Value;
            }

            var scriptField = unitTable.GetField("script");

            if (scriptField is LuaString)
            {
                scripts.Add(mod.ModFolder + "/scripts/" + scriptField.Value);
            }
            else
            {
                scripts.Add(FixPath(mod.ModFolder + "/scripts/" + unitName + ".cob"));
            }
            if (scripts.First().ToLower().EndsWith(".cob"))
            {
                var bosPath = scripts.First().ToLower().Replace(".cob", ".bos");
                if (File.Exists(bosPath))
                {
                    scripts.Add(FixPath(bosPath));
                }
            }

            var featureDefs = unitTable.GetField("featuredefs");

            if (featureDefs is LuaTable)
            {
                foreach (var kvp in featureDefs.Values)
                {
                    modelFileNames.Add(kvp.Value.GetField("object").Value.ToLower());
                }
            }

            foreach (var fileName in modelFileNames)
            {
                var n = fileName.ToLower();
                if (!n.Contains('.'))
                {
                    n += ".3do";
                }
                n = mod.ModFolder + "/Objects3d/" + n;
                models.Add(n);
                if (n.EndsWith(".s3o"))
                {
                    texturesS3o.AddRange(GetS3oTextures(n).Select(t => mod.ModFolder + "/unittextures/" + t).Select(FixPath));
                }
                if (n.EndsWith(".3do"))
                {
                    var allTextures = Directory.GetFiles(mod.ModFolder + "/unittextures", "*", SearchOption.AllDirectories).Where(p => !p.Contains(".svn")).Select(FixPath).ToArray();

                    var textures = Get3doTextures(n);
                    foreach (var textureName in textures)
                    {
                        var found = false;
                        foreach (var file in allTextures)
                        {
                            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
                            if (textureName == fileNameWithoutExtension || textureName + "00" == fileNameWithoutExtension)
                            {
                                textures3do.Add(FixPath(file));
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            Debug.WriteLine("not found: " + textureName);
                        }
                    }
                }
            }
            texturesS3o = texturesS3o.Distinct().Select(FixPath).ToList();
            models      = models.Distinct().Select(FixPath).ToList();
            var soundFiles = Directory.GetFiles(mod.ModFolder + "/sounds", "*", SearchOption.AllDirectories).Where(p => !p.Contains(".svn")).Select(FixPath).ToArray();

            foreach (var soundName in soundNames)
            {
                foreach (var soundFile in soundFiles)
                {
                    if (Path.GetFileNameWithoutExtension(soundFile).ToUpper() == Path.GetFileNameWithoutExtension(soundName).ToUpper())
                    {
                        sounds.Add(FixPath(soundFile));
                    }
                }
            }
        }
Ejemplo n.º 5
0
        void ProcessExplosions()
        {
            var texturePairs  = new List <TexturePair>();
            var filePairs     = new List <FilePair>();
            var spawners      = new List <SpawnerPair>();
            var effectsFolder = ModFolder + "\\effects";

            foreach (var file in Directory.GetFiles(effectsFolder, "*.lua"))
            {
                dynamic explosions = CLua.TraceDoString(L, 1, File.ReadAllText(file))[0];
                foreach (var explosion in explosions.Values)
                {
                    filePairs.Add(new FilePair(explosion.Key.Value, file));

                    foreach (var effect in explosion.Value.Values)
                    {
                        if (effect.Value is LuaTable && effect.Value.GetField("class") != null)
                        {
                            if (effect.Value.GetField("class").Value == "CExpGenSpawner")
                            {
                                var explosionGenerator = effect.Value.GetField("properties").GetField("explosiongenerator").Value.ToLower();
                                if (explosionGenerator.StartsWith("custom:"))
                                {
                                    explosionGenerator = explosionGenerator.Substring(7, explosionGenerator.Length - 7).ToLower();
                                }
                                spawners.Add(new SpawnerPair(explosion.Key.Value, explosionGenerator));
                            }
                            else if (effect.Value.GetField("class").Value == "CBitmapMuzzleFlame")
                            {
                                texturePairs.Add(new TexturePair(explosion.Key.Value, effect.Value.GetField("properties").GetField("fronttexture").Value.ToLower()));
                                texturePairs.Add(new TexturePair(explosion.Key.Value, effect.Value.GetField("properties").GetField("sidetexture").Value.ToLower()));
                            }
                            else if (effect.Value.GetField("class").Value == "CSimpleParticleSystem")
                            {
                                texturePairs.Add(new TexturePair(explosion.Key.Value, effect.Value.GetField("properties").GetField("texture").Value.ToLower()));
                            }
                            else if (effect.Value.GetField("class").Value == "CSimpleGroundFlash")
                            {
                                texturePairs.Add(new TexturePair(explosion.Key.Value, effect.Value.GetField("properties").GetField("texture").Value.ToLower()));
                            }
                            else if (effect.Value.GetField("class").Value == "heatcloud")
                            {
                                texturePairs.Add(new TexturePair(explosion.Key.Value, effect.Value.GetField("properties").GetField("texture").Value.ToLower()));
                            }
                        }
                    }
                }
            }

            var dependencies = filePairs.Select(p => p.ExplosionName).Distinct().Select(n => GetExplosionDependencies(n, texturePairs, spawners, filePairs)).ToArray();

            // var dupes = filePairs.GroupBy(p => p.ExplosionName).Where(g => g.Count() > 1).ToArray();
            //foreach (var dupe in dupes)
            //{
            //    Debug.WriteLine("====== " + dupe.Key + " ==========");
            //    foreach (var d in dupe) Debug.WriteLine(d.FilePath);
            //}

            // var dupes = dependencies.GroupBy(p => p.Name).Where(g => g.Count() > 1).ToArray();
            ExplosionTextures = dependencies.ToDictionary(d => d.Name, d => d.Textures.Select(FilesFinder.FixPath).ToArray());
            ExplosionFiles    = dependencies.ToDictionary(d => d.Name, d => d.Files.Select(FilesFinder.FixPath).ToArray());
        }