Exemplo n.º 1
0
        static void makeSoundArchive(string _sourceDirectory, string _destFile)
        {
            if (Directory.Exists(_sourceDirectory))
            {
                // Step 1 - Convert any .aac audio into .ogg
                if (Options.simpleConsoleOutput)
                {
                    Console.Out.WriteLine("Converting aac audio if present");
                }
                string[] _foundFiles = Directory.GetFiles(_sourceDirectory, "*", SearchOption.AllDirectories);
                for (int i = 0; i < _foundFiles.Length; ++i)
                {
                    _convertSingleSound(_foundFiles[i]);
                }

                // Step 2 - Make archive
                _foundFiles = Directory.GetFiles(_sourceDirectory, "*", SearchOption.AllDirectories);
                LegArchive _soundArchive = new LegArchive(_destFile, _sourceDirectory);
                if (Options.simpleConsoleOutput)
                {
                    Console.Out.WriteLine("Creating sound archive");
                }
                for (int i = 0; i < _foundFiles.Length; ++i)
                {
                    if (Path.GetExtension(_foundFiles[i]) != ".aac")
                    {
                        _soundArchive.addFile(_foundFiles[i]);
                    }
                }
                if (Options.simpleConsoleOutput)
                {
                    Console.Out.WriteLine("Writing filename table");
                }
                _soundArchive.finish();
            }
            else
            {
                if (Options.simpleConsoleOutput)
                {
                    Console.Out.WriteLine("{0} not exist, so skipping sound", _sourceDirectory);
                }
            }
        }
Exemplo n.º 2
0
        public static int Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            if (requiredFilesMissing())
            {
                return(1);
            }
            Console.Write("converting for Vita? (y/n): ");
            if (Console.ReadLine().Trim() == "y")
            {
                Console.WriteLine("Vita converting mode enabled");
                Options.doResizeGraphics = true;
                Options.useSoundArchive  = true;
                Options.screenWidth      = 960;
                Options.screenHeight     = 544;
            }
            else
            {
                Console.WriteLine("generic platform mode");
                Options.doResizeGraphics = false;
                Options.useSoundArchive  = false;
            }
            String _bonusScript = pickBonusScript();

            // ArcUnpacker extracts depending on filename
            Options.extractedImagesLocation  = "./MGD jpn~/";
            Options.extractedScriptsLocation = "./MSE~/";
            Options.extractedBGMLocation     = "./BGM~/";
            Options.extractedVoiceLocation   = "./VOICE~/";
            Options.extractedSELocation      = "./SE~/";
            //
            Options.finalImagesLocation       = Options.streamingAssetsFolder + "CG/";
            Options.finalScriptsLocation      = Options.streamingAssetsFolder + "Scripts/";
            Options.finalSoundArchiveLocation = Options.streamingAssetsFolder + "SEArchive.legArchive";
            if (!Options.useSoundArchive)
            {
                Options.finalBGMLocation   = Options.streamingAssetsFolder + "BGM/";
                Options.finalSELocation    = Options.streamingAssetsFolder + "SE/";
                Options.finalVoiceLocation = Options.streamingAssetsFolder + "voice/";
            }
            Console.Out.WriteLine("Making StreamingAssets directories...");
            Directory.CreateDirectory(Options.streamingAssetsFolder);
            Directory.CreateDirectory(Options.finalImagesLocation);
            Directory.CreateDirectory(Options.finalScriptsLocation);
            if (!Options.useSoundArchive)
            {
                Directory.CreateDirectory(Options.finalBGMLocation);
                Directory.CreateDirectory(Options.finalSELocation);
                Directory.CreateDirectory(Options.finalVoiceLocation);
            }
            // extract assts
            if (!(args.Length >= 1 && args[0] == "--noextract"))
            {
                // Extract scripts with fallback
                Console.Out.Write("Extracting scripts, ");
                if (File.Exists("./MSE"))
                {
                    Console.Out.WriteLine("./MSE");
                    ArcUnpacker.unpackToDirectory("./MSE");
                }
                else
                {
                    Options.extractedScriptsLocation = "./MSD~/";
                    Console.Out.WriteLine("./MSD");
                    ArcUnpacker.unpackToDirectory("./MSD");
                }

                // Extract english graphics with fallback
                if (File.Exists("./MGD jpn"))
                {
                    Console.Out.WriteLine("Extracting graphics, ./MGD jpn");
                    ArcUnpacker.unpackToDirectory("./MGD jpn");
                }
                else if (File.Exists("./MGD"))
                {
                    Options.extractedImagesLocation = "./MGD~/";
                    Console.Out.WriteLine("Extracting graphics, ./MGD");
                    ArcUnpacker.unpackToDirectory("./MGD");
                }
                // Extract other stuff
                Console.Out.WriteLine("Extracting voices, ./VOICE");
                ArcUnpacker.unpackToDirectory("./VOICE");
                Console.Out.WriteLine("Extracting BGM, ./BGM");
                ArcUnpacker.unpackToDirectory("./BGM");
                Console.Out.WriteLine("Extracting SE, ./SE");
                ArcUnpacker.unpackToDirectory("./SE");

                // do a little bit of fixing of the mgd extraction.
                // does not resize any graphics or anything horrible like that
                GraphicsConverter.convertMGD(Options.extractedImagesLocation);
            }
            if (_bonusScript != null)
            {
                Console.WriteLine("running " + _bonusScript);
                runBonusScript(_bonusScript);
            }
            Console.Out.WriteLine("Converting scripts...");
            //PresetFileMaker _myPresetFileMaker = new PresetFileMaker();
            string[] _scriptFileList = Directory.GetFiles(Options.extractedScriptsLocation);
            if (_scriptFileList.Length == 0)
            {
                Console.Out.WriteLine("no scripts found in " + Options.extractedScriptsLocation);
                return(1);
            }
            int  i;
            bool _alreadyFoundMainScript = false;

            Array.Sort(_scriptFileList);
            for (i = 0; i < _scriptFileList.Length; i++)
            {
                if (Path.GetExtension(_scriptFileList[i]).ToLower() == ".msd")
                {
                    Console.Out.WriteLine(Path.GetFileNameWithoutExtension(_scriptFileList[i]));
                    bool _isValid = ScriptConverter.ConvertScript(_scriptFileList[i], (_alreadyFoundMainScript ? Options.finalScriptsLocation + Path.GetFileNameWithoutExtension(_scriptFileList[i]) + ".scr" : Options.finalScriptsLocation + "main.scr"), (i != _scriptFileList.Length - 1 ?Path.GetFileNameWithoutExtension(_scriptFileList[i + 1]) + ".scr" : null));
                    if (_isValid)
                    {
                        _alreadyFoundMainScript = true;
                    }
                }
            }
            // if enabled, resize the graphics and save the resized version to the appropriate location
            if (Options.doResizeGraphics)
            {
                Console.Out.WriteLine("Resizing graphics...");
                GraphicsConverter.resizeGraphics(Options.extractedImagesLocation, Options.finalImagesLocation, Options.screenWidth, Options.screenHeight);
            }
            if (Options.useSoundArchive)
            {
                // HACK - This will not support subdirectories because I'm lazy and they aren't needed. This note is only here for me if I come back years later trying to port the second game, or something, which could have subdirectories.
                Console.Out.WriteLine("Creating sound archive...");
                LegArchive _soundArchive = new LegArchive(Options.finalSoundArchiveLocation);
                lazyAddLegarchive(_soundArchive, Options.extractedVoiceLocation);
                lazyAddLegarchive(_soundArchive, Options.extractedBGMLocation);
                lazyAddLegarchive(_soundArchive, Options.extractedSELocation);
                _soundArchive.finish();
            }
            else
            {
                Console.Out.WriteLine("Moving from extraction directories to StreamingAssets directories...");
                MoveDirToDir(Options.extractedBGMLocation, Options.finalBGMLocation);
                MoveDirToDir(Options.extractedSELocation, Options.finalSELocation);
                MoveDirToDir(Options.extractedVoiceLocation, Options.finalVoiceLocation);
                // if we didn't resize the graphics, we need to move the original extracted ones
                if (!Options.doResizeGraphics)
                {
                    MoveDirToDir(Options.extractedImagesLocation, Options.finalImagesLocation);
                }
            }

            Console.Out.WriteLine("Deleting extraction directories...");
            Directory.Delete(Options.extractedBGMLocation, true);
            Directory.Delete(Options.extractedImagesLocation, true);
            Directory.Delete(Options.extractedScriptsLocation, true);
            Directory.Delete(Options.extractedSELocation, true);
            Directory.Delete(Options.extractedVoiceLocation, true);

            Console.Out.WriteLine("Moving included assets to StreamingAssets...");
            CopyDirToDir("./Stuff/", Options.streamingAssetsFolder);

            Console.Out.WriteLine("Creating isvnds file.");
            File.Create(Options.streamingAssetsFolder + "isvnds").Dispose();

            // Because this is a generic converter for multiple games, I can't have them all having the same preset filename or folder name.
            // The user chooses the name of the folder and preset file
            string _userPresetFilename = null;

            while (String.IsNullOrEmpty(_userPresetFilename))
            {
                Console.WriteLine("=====\n=====\nGive this game a unique name without special characters\n=====\n=====");
                _userPresetFilename = Console.ReadLine().MakeFilenameFriendly();
            }

            /*
             * Console.Out.WriteLine("Making preset...");
             * //_myPresetFileMaker.writePresetFile(Options.streamingAssetsFolder+_userPresetFilename);
             * StreamWriter _myStreamWriter = new StreamWriter(new FileStream(Options.streamingAssetsFolder+"includedPreset.txt",FileMode.Create));
             * _myStreamWriter.WriteLine(_userPresetFilename);
             * _myStreamWriter.Dispose();
             */

            Console.Out.WriteLine("Renaming StreamingAssets directory...");
            bool _couldRename = true;

            do
            {
                try{
                    Directory.Move(Options.streamingAssetsFolder, "./" + _userPresetFilename);
                }catch (Exception e) {
                    Console.Out.WriteLine(e.ToString() + "\nFailed to rename directory, retrying in 3 seconds.");
                    System.Threading.Thread.Sleep(3000);
                    _couldRename = false;
                }
            }while(_couldRename == false);

            Console.Out.WriteLine("Done.");
            return(0);
        }