Пример #1
0
        public static void ExportLevels(string[] astr, int nVersion)
        {
            // Get tile size

            Size sizTile = new Size(0, 0);

            sizTile.Width  = int.Parse(astr[1]);
            sizTile.Height = sizTile.Width;

            // Get depth

            int nDepth = Int32.Parse(astr[2]);

            // Get background threshold

            double nAreaBackgroundThreshold = double.Parse(astr[3]);

            // Background luminance multiplier

            double nLuminanceMultBackground = double.Parse(astr[4]);

            // Background saturation multiplier

            double nSaturationMultBackground = double.Parse(astr[5]);

            // Foreground luminance multiplier

            double nLuminanceMultForeground = double.Parse(astr[6]);

            // Foreground saturation multiplier

            double nSaturationMultForeground = double.Parse(astr[7]);

            // Palette directory

            string strPalDir = astr[8];

            // Get output directory

            string strDir = Path.GetFullPath(astr[9]);

            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (int n = 9; n < astr.Length; n++)
            {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT  = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            // Attempt to process these level doc
            ArrayList alsTileSets = new ArrayList();

            foreach (string strFile in alsFiles)
            {
                Console.Write("Loading " + strFile + "...");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                {
                    throw new Exception("Could not load level doc " + strFile);
                }
                Console.Write(" Done.\n");

                // Size this template collection if necessary

                TemplateDoc tmpd = lvld.GetTemplateDoc();
                if (sizTile.Width != tmpd.TileSize.Width || sizTile.Height != tmpd.TileSize.Height)
                {
                    TemplateTools.ScaleTemplates(tmpd, sizTile);
                }

                // Get appropriate TileSet, or make one if this map
                // uses a new tile collection
                TileSet tset = null;
                foreach (TileSet tsetT in alsTileSets)
                {
                    if (tsetT.TileCollectionFileName == Path.GetFileName(lvld.GetTemplateDoc().GetPath()))
                    {
                        tset = tsetT;
                        break;
                    }
                }

                // Create new tile set if none found
                if (tset == null)
                {
                    string strTcPath = lvld.GetTemplateDoc().GetPath();
                    string strTcName = Path.GetFileNameWithoutExtension(strTcPath);
                    string strTcDir  = Path.GetDirectoryName(strTcPath);
                    string strT3     = strTcDir + Path.DirectorySeparatorChar + strPalDir + Path.DirectorySeparatorChar + strTcName;
                    tset = new TileSet(lvld.GetTemplateDoc(), Path.GetFileName(strTcPath), strT3, nDepth, sizTile);
                    alsTileSets.Add(tset);
                }

                // Get and save a tile map for this level
                string strTmap     = Path.GetFileName(lvld.GetPath().Replace(".ld", ".tmap"));
                string strFileTmap = strDir + Path.DirectorySeparatorChar + strTmap;
                Console.Write("Creating & writing " + strFileTmap + "...");
                TileMap tmap = TileMap.CreateFromImage(tset, lvld.GetMapBitmap(tmpd.TileSize, tmpd, true), tmpd.TileSize);
                tmap.Save(strFileTmap);
                Console.Write(" Done.\n");

                // Get and save terrain map for this level
                string strTrmap     = Path.GetFileName(lvld.GetPath().Replace(".ld", ".trmap"));
                string strFileTrmap = strDir + Path.DirectorySeparatorChar + strTrmap;
                Console.Write("Creating & writing " + strFileTrmap + "...");
                TerrainMap trmap = new TerrainMap(lvld.GetTerrainMap(tmpd.TileSize, tmpd, false));
                trmap.Save(strFileTrmap);
                Console.Write(" Done.\n");

                // Save .ini for this level doc
                string strFileIni = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile).Replace(".ld", ".lvl");
                Console.Write("Writing " + strFileIni + "...");
                lvld.SaveIni(strFileIni, nVersion, strTmap, strTrmap, tset.PalBinFileName);
                Console.Write(" Done.\n");
                lvld.Dispose();
            }

            // Now write out tilesets
            foreach (TileSet tset in alsTileSets)
            {
                // Save tile set
                string strFileTset = strDir + Path.DirectorySeparatorChar + tset.FileName;
                Console.Write("Creating & writing " + strFileTset + ", " + tset.Count.ToString() + " tiles...");
                tset.Save(strFileTset);
                tset.SaveMini(strFileTset, nAreaBackgroundThreshold, nLuminanceMultBackground, nSaturationMultBackground, nLuminanceMultForeground, nSaturationMultForeground);
                Console.Write(" Done.\n");
            }
        }
Пример #2
0
        public static void ExportLevels(string[] astr, int nVersion)
        {
            // Get tile size

            Size sizTile = new Size(0, 0);
            sizTile.Width = int.Parse(astr[1]);
            sizTile.Height = sizTile.Width;

            // Get depth

            int nDepth = Int32.Parse(astr[2]);

            // Get background threshold

            double nAreaBackgroundThreshold = double.Parse(astr[3]);

            // Background luminance multiplier

            double nLuminanceMultBackground = double.Parse(astr[4]);

            // Background saturation multiplier

            double nSaturationMultBackground = double.Parse(astr[5]);

            // Foreground luminance multiplier

            double nLuminanceMultForeground = double.Parse(astr[6]);

            // Foreground saturation multiplier

            double nSaturationMultForeground = double.Parse(astr[7]);

            // Palette directory

            string strPalDir = astr[8];

            // Get output directory

            string strDir = Path.GetFullPath(astr[9]);

            // Expand filespecs
            ArrayList alsFiles = new ArrayList();
            for (int n = 9; n < astr.Length; n++) {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                    strDirT = ".";
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            // Attempt to process these level doc
            ArrayList alsTileSets = new ArrayList();
            foreach (string strFile in alsFiles) {
                Console.Write("Loading " + strFile + "...");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                    throw new Exception("Could not load level doc " + strFile);
                Console.Write(" Done.\n");

                // Size this template collection if necessary

                TemplateDoc tmpd = lvld.GetTemplateDoc();
                if (sizTile.Width != tmpd.TileSize.Width || sizTile.Height != tmpd.TileSize.Height)
                    TemplateTools.ScaleTemplates(tmpd, sizTile);

                // Get appropriate TileSet, or make one if this map
                // uses a new tile collection
                TileSet tset = null;
                foreach (TileSet tsetT in alsTileSets) {
                    if (tsetT.TileCollectionFileName == Path.GetFileName(lvld.GetTemplateDoc().GetPath())) {
                        tset = tsetT;
                        break;
                    }
                }

                // Create new tile set if none found
                if (tset == null) {
                    string strTcPath = lvld.GetTemplateDoc().GetPath();
                    string strTcName = Path.GetFileNameWithoutExtension(strTcPath);
                    string strTcDir = Path.GetDirectoryName(strTcPath);
                    string strT3 = strTcDir + Path.DirectorySeparatorChar + strPalDir + Path.DirectorySeparatorChar + strTcName;
                    tset = new TileSet(lvld.GetTemplateDoc(), Path.GetFileName(strTcPath), strT3, nDepth, sizTile);
                    alsTileSets.Add(tset);
                }

                // Get and save a tile map for this level
                string strTmap = Path.GetFileName(lvld.GetPath().Replace(".ld", ".tmap"));
                string strFileTmap = strDir + Path.DirectorySeparatorChar + strTmap;
                Console.Write("Creating & writing " + strFileTmap + "...");
                TileMap tmap = TileMap.CreateFromImage(tset, lvld.GetMapBitmap(tmpd.TileSize, tmpd, true), tmpd.TileSize);
                tmap.Save(strFileTmap);
                Console.Write(" Done.\n");

                // Get and save terrain map for this level
                string strTrmap = Path.GetFileName(lvld.GetPath().Replace(".ld", ".trmap"));
                string strFileTrmap = strDir + Path.DirectorySeparatorChar + strTrmap;
                Console.Write("Creating & writing " + strFileTrmap + "...");
                TerrainMap trmap = new TerrainMap(lvld.GetTerrainMap(tmpd.TileSize, tmpd, false));
                trmap.Save(strFileTrmap);
                Console.Write(" Done.\n");

                // Save .ini for this level doc
                string strFileIni = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile).Replace(".ld", ".lvl");
                Console.Write("Writing " + strFileIni + "...");
                lvld.SaveIni(strFileIni, nVersion, strTmap, strTrmap, tset.PalBinFileName);
                Console.Write(" Done.\n");
                lvld.Dispose();
            }

            // Now write out tilesets
            foreach (TileSet tset in alsTileSets) {
                // Save tile set
                string strFileTset = strDir + Path.DirectorySeparatorChar + tset.FileName;
                Console.Write("Creating & writing " + strFileTset + ", " + tset.Count.ToString() + " tiles...");
                tset.Save(strFileTset);
                tset.SaveMini(strFileTset, nAreaBackgroundThreshold, nLuminanceMultBackground, nSaturationMultBackground, nLuminanceMultForeground, nSaturationMultForeground);
                Console.Write(" Done.\n");
            }
        }
Пример #3
0
        public static void SaveExpansionPdb(string strFile, Document[] adoc, string strVersion)
        {
            // First save all level docs

            //annoying
            //DocManager.SaveAllModified(typeof(LevelDoc));

            // Remember active document

            LevelDoc lvldActive = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            // Save documents adoc in an expansion .pdb. Expansion .pdbs need:
            // - .lvl, .tmap, .trmap, but not .tsets since these come from game .pdbs
            // - need a version.txt
            // - need an if demo trigger check "inserted" at save time
            // - .pdb needs WARI creator, ADD1 type
            // - data should be compressed for obfuscation purposes

            PdbPacker pdbp = new PdbPacker();

            // Add version.txt

            byte[] abT = new byte[strVersion.Length + 1];
            for (int n = 0; n < strVersion.Length; n++)
            {
                abT[n] = (byte)strVersion[n];
            }
            abT[abT.Length - 1] = 0;
            pdbp.Add(new PdbPacker.File("version.txt", abT));

            // Load res.h from embedded resource in prep for pre-process

            System.Reflection.Assembly ass = typeof(GobImage).Module.Assembly;
            Stream stmResDotH = ass.GetManifestResourceStream("m.EmbeddedResources." + "res.h");

            if (stmResDotH == null)
            {
                throw new Exception("Cannot load res.h");
            }

            // Compile levels

            Random    rand        = new Random();
            ArrayList alsTileSets = new ArrayList();

            foreach (LevelDoc lvld in adoc)
            {
                // Need to do this unfortunately; some of the "saving" code relies on what the "active" document
                // is!!

                DocManager.SetActiveDocument(typeof(LevelDoc), lvld);

                TemplateDoc tmpd = lvld.GetTemplateDoc();

                // Get appropriate TileSet, or make one if this map
                // uses a new tile collection

                TileSet tset = null;
                foreach (TileSet tsetT in alsTileSets)
                {
                    if (tsetT.TemplateDoc == tmpd)
                    {
                        tset = tsetT;
                        break;
                    }
                }

                // Create new tile set if none found

                if (tset == null)
                {
                    tset = new TileSet(tmpd, tmpd.GetName() + ".tset");
                    alsTileSets.Add(tset);
                }

#if false
                // Generate base file name for this level (this is never user-visible, but it should be
                // as unique as possible

                char[] achBase = new char[16];
                for (int n = 0; n < achBase.Length; n++)
                {
                    int nT = rand.Next() % (26 + 10);
                    if (nT < 26)
                    {
                        achBase[n] = (char)(nT + 97);
                    }
                    else
                    {
                        achBase[n] = (char)(nT + 48 - 26);
                    }
                }
                if (lvld.MaxPlayers > 1)
                {
                    achBase[0] = 'm';
                    achBase[1] = '_';
                }
                string strBase = new String(achBase);
#else
                // This isn't unique which can cause problems due to how packfiles work.
                // Could change packfile api to accept .pdb parameter.
                // Note1: set next mission action requires predictable filename
                // Note2: mission sorting is based on filename, not title
                // Could put lots of "support" in to fix these problems, or just ship
                // it like this.
                //
                // Hack: filename length 29
                // Maximum extension on filename: 7

                string strBase = lvld.Title;
                if (strBase.Length > 29 - 7)
                {
                    strBase = strBase.Substring(0, 29 - 7);
                }

                // If multiplayer, add "m_" to the name by losing the last two characters
                // so sort order is preserved

                if (lvld.MaxPlayers > 1)
                {
                    strBase = "m_" + strBase.Substring(0, strBase.Length - 2);
                }
#endif

                // Get tile map file for this level

                MemoryStream stmTmap = new MemoryStream();
                TileMap      tmap    = TileMap.CreateFromImage(tset, lvld.GetMapBitmap(tmpd.TileSize, tmpd, true), tmpd.TileSize);
                tmap.Save(stmTmap);
                string strTmap = strBase + ".tmap";
                pdbp.Add(new PdbPacker.File(strTmap, stmTmap.ToArray()));
                stmTmap.Close();

                // Get the terrain map file for this level

                MemoryStream stmTRmap = new MemoryStream();
                TerrainMap   trmap    = new TerrainMap(lvld.GetTerrainMap(tmpd.TileSize, tmpd, false));
                trmap.Save(stmTRmap);
                string strTRmap = strBase + ".trmap";
                pdbp.Add(new PdbPacker.File(strTRmap, stmTRmap.ToArray()));
                stmTRmap.Close();

                // Save .ini file for this level doc

                MemoryStream stmLvld = new MemoryStream();
                lvld.SaveIni(stmLvld, -1, strTmap, strTRmap, tmpd.GetName() + ".palbin", true);

                // Pre-process

                stmLvld.Seek(0, SeekOrigin.Begin);
                MemoryStream stmPreprocessed = Misc.PreprocessStream(stmLvld, stmResDotH);
                stmPreprocessed.Seek(0, SeekOrigin.Begin);
                Ini iniPreProcessed = new Ini(stmPreprocessed);

                MemoryStream stmLvldPreProcessedBinary = new MemoryStream();
                iniPreProcessed.SaveBinary(stmLvldPreProcessedBinary);
                stmLvldPreProcessedBinary.Close();

                string strLvlName = lvld.OutputFilename;
                if (strLvlName == null)
                {
                    strLvlName = strBase + ".lvl";
                }
                pdbp.Add(new PdbPacker.File(strLvlName, stmLvldPreProcessedBinary.ToArray()));
                stmLvldPreProcessedBinary.Close();
            }
            stmResDotH.Close();

            // Restore active document

            if (lvldActive != null)
            {
                DocManager.SetActiveDocument(typeof(LevelDoc), lvldActive);
            }

            // Now save out pdb

            pdbp.Save(strFile, "WARI", "ADD2");
        }
Пример #4
0
        public static void SaveExpansionPdb(string strFile, Document[] adoc, string strVersion)
        {
            // First save all level docs

            //annoying
            //DocManager.SaveAllModified(typeof(LevelDoc));

            // Remember active document

            LevelDoc lvldActive = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));

            // Save documents adoc in an expansion .pdb. Expansion .pdbs need:
            // - .lvl, .tmap, .trmap, but not .tsets since these come from game .pdbs
            // - need a version.txt
            // - need an if demo trigger check "inserted" at save time
            // - .pdb needs WARI creator, ADD1 type
            // - data should be compressed for obfuscation purposes

            PdbPacker pdbp = new PdbPacker();

            // Add version.txt

            byte[] abT = new byte[strVersion.Length + 1];
            for (int n = 0; n < strVersion.Length; n++)
                abT[n] = (byte)strVersion[n];
            abT[abT.Length - 1] = 0;
            pdbp.Add(new PdbPacker.File("version.txt", abT));

            // Load res.h from embedded resource in prep for pre-process

            System.Reflection.Assembly ass = typeof(GobImage).Module.Assembly;
            Stream stmResDotH = ass.GetManifestResourceStream("m.EmbeddedResources." + "res.h");
            if (stmResDotH == null)
                throw new Exception("Cannot load res.h");

            // Compile levels

            Random rand = new Random();
            ArrayList alsTileSets = new ArrayList();
            foreach (LevelDoc lvld in adoc) {
                // Need to do this unfortunately; some of the "saving" code relies on what the "active" document
                // is!!

                DocManager.SetActiveDocument(typeof(LevelDoc), lvld);

                TemplateDoc tmpd = lvld.GetTemplateDoc();

                // Get appropriate TileSet, or make one if this map
                // uses a new tile collection

                TileSet tset = null;
                foreach (TileSet tsetT in alsTileSets) {
                    if (tsetT.TemplateDoc == tmpd) {
                        tset = tsetT;
                        break;
                    }
                }

                // Create new tile set if none found

                if (tset == null) {
                    tset = new TileSet(tmpd, tmpd.GetName() + ".tset");
                    alsTileSets.Add(tset);
                }

            #if false
                // Generate base file name for this level (this is never user-visible, but it should be
                // as unique as possible

                char[] achBase = new char[16];
                for (int n = 0; n < achBase.Length; n++) {
                    int nT = rand.Next() % (26 + 10);
                    if (nT < 26) {
                        achBase[n] = (char)(nT + 97);
                    } else {
                        achBase[n] = (char)(nT + 48 - 26);
                    }
                }
                if (lvld.MaxPlayers > 1) {
                    achBase[0] = 'm';
                    achBase[1] = '_';
                }
                string strBase = new String(achBase);
            #else
                // This isn't unique which can cause problems due to how packfiles work.
                // Could change packfile api to accept .pdb parameter.
                // Note1: set next mission action requires predictable filename
                // Note2: mission sorting is based on filename, not title
                // Could put lots of "support" in to fix these problems, or just ship
                // it like this.
                //
                // Hack: filename length 29
                // Maximum extension on filename: 7

                string strBase = lvld.Title;
                if (strBase.Length > 29 - 7)
                    strBase = strBase.Substring(0, 29 - 7);

                // If multiplayer, add "m_" to the name by losing the last two characters
                // so sort order is preserved

                if (lvld.MaxPlayers > 1)
                    strBase = "m_" + strBase.Substring(0, strBase.Length - 2);
            #endif

                // Get tile map file for this level

                MemoryStream stmTmap = new MemoryStream();
                TileMap tmap = TileMap.CreateFromImage(tset, lvld.GetMapBitmap(tmpd.TileSize, tmpd, true), tmpd.TileSize);
                tmap.Save(stmTmap);
                string strTmap = strBase + ".tmap";
                pdbp.Add(new PdbPacker.File(strTmap, stmTmap.ToArray()));
                stmTmap.Close();

                // Get the terrain map file for this level

                MemoryStream stmTRmap = new MemoryStream();
                TerrainMap trmap = new TerrainMap(lvld.GetTerrainMap(tmpd.TileSize, tmpd, false));
                trmap.Save(stmTRmap);
                string strTRmap = strBase + ".trmap";
                pdbp.Add(new PdbPacker.File(strTRmap, stmTRmap.ToArray()));
                stmTRmap.Close();

                // Save .ini file for this level doc

                MemoryStream stmLvld = new MemoryStream();
                lvld.SaveIni(stmLvld, -1, strTmap, strTRmap, tmpd.GetName() + ".palbin", true);

                // Pre-process

                stmLvld.Seek(0, SeekOrigin.Begin);
                MemoryStream stmPreprocessed = Misc.PreprocessStream(stmLvld, stmResDotH);
                stmPreprocessed.Seek(0, SeekOrigin.Begin);
                Ini iniPreProcessed = new Ini(stmPreprocessed);

                MemoryStream stmLvldPreProcessedBinary = new MemoryStream();
                iniPreProcessed.SaveBinary(stmLvldPreProcessedBinary);
                stmLvldPreProcessedBinary.Close();

                string strLvlName = lvld.OutputFilename;
                if (strLvlName == null) {
                    strLvlName = strBase + ".lvl";
                }
                pdbp.Add(new PdbPacker.File(strLvlName, stmLvldPreProcessedBinary.ToArray()));
                stmLvldPreProcessedBinary.Close();
            }
            stmResDotH.Close();

            // Restore active document

            if (lvldActive != null)
                DocManager.SetActiveDocument(typeof(LevelDoc), lvldActive);

            // Now save out pdb

            pdbp.Save(strFile, "WARI", "ADD2");
        }