Exemple #1
0
        public static int Main(string[] args)
        {
            if (args.Length >= 2 && (args[0] == "--parse-script" || args[0] == "--parse-book"))
            {
                using (var fs = new HyoutaUtils.Streams.DuplicatableFileStream(args[1])) {
                    var funcs = ScriptParser.Parse(fs.CopyToByteArrayStreamAndDispose(), args[0] == "--parse-book");

                    using (var outfs = new FileStream(args.Length > 2 ? args[2] : args[1] + ".txt", FileMode.Create)) {
                        foreach (var func in funcs)
                        {
                            outfs.WriteUTF8(func.Name);
                            outfs.WriteUTF8("\n");
                            outfs.WriteUTF8("\n");
                            foreach (var op in func.Ops)
                            {
                                outfs.WriteUTF8(op);
                                outfs.WriteUTF8("\n");
                            }
                            outfs.WriteUTF8("\n");
                            outfs.WriteUTF8("\n");
                        }
                    }
                }
                return(0);
            }

            if (args.Length == 1 && args[0] == "__gen_voice_checks")
            {
                t_voice_tbl.CheckVoiceTable(
                    Path.Combine(SenCommonPaths.Sen1SteamDir, "data/text/dat_us/t_voice.tbl"),
                    Path.Combine(SenCommonPaths.Sen1SteamDir, "data/voice/wav"),
                    Path.Combine(SenCommonPaths.Sen1SteamDir, "voice_check_english.txt")
                    );
                t_voice_tbl.CheckVoiceTable(
                    Path.Combine(SenCommonPaths.Sen1SteamDir, "data/text/dat/t_voice.tbl"),
                    Path.Combine(SenCommonPaths.Sen1SteamDir, "data/voice/wav_jp"),
                    Path.Combine(SenCommonPaths.Sen1SteamDir, "voice_check_japanese.txt")
                    );
                t_voice_tbl.CheckVoiceTable(
                    Path.Combine(SenCommonPaths.Sen2SteamDir, "data/text/dat_us/t_voice.tbl"),
                    Path.Combine(SenCommonPaths.Sen2SteamDir, "data/voice/wav"),
                    Path.Combine(SenCommonPaths.Sen2SteamDir, "voice_check_english.txt")
                    );
                t_voice_tbl.CheckVoiceTable(
                    Path.Combine(SenCommonPaths.Sen2SteamDir, "data/text/dat/t_voice.tbl"),
                    Path.Combine(SenCommonPaths.Sen2SteamDir, "data/voice_jp/wav"),
                    Path.Combine(SenCommonPaths.Sen2SteamDir, "voice_check_japanese.txt")
                    );
                return(0);
            }

            if (args.Length == 0)
            {
                Console.WriteLine("No path to directory given.");
                return(-1);
            }

            string path = args[0];

            if (!Directory.Exists(path))
            {
                Console.WriteLine($"No directory found at {path}.");
                return(-1);
            }

            int sengame;

            if (File.Exists(System.IO.Path.Combine(path, "Sen1Launcher.exe")))
            {
                sengame = 1;
            }
            else if (File.Exists(System.IO.Path.Combine(path, "Sen2Launcher.exe")))
            {
                sengame = 2;
            }
            else
            {
                Console.WriteLine($"Failed to detect whether {path} is CS1 or 2.");
                return(-1);
            }

            FilenameFix.FixupIncorrectEncodingInFilenames(path, sengame, true, new CliProgressReporter());
            FileStorage storage = FileModExec.InitializeAndPersistFileStorage(path, sengame == 1 ? Sen1KnownFiles.Files : Sen2KnownFiles.Files, new CliProgressReporter())?.Storage;

            if (storage == null)
            {
                Console.WriteLine($"Failed to initialize file storage from {path}.");
                return(-1);
            }

            PatchResult result;

            if (sengame == 1)
            {
                var mods = new List <FileMod>();
                mods.AddRange(Sen1Mods.GetExecutableMods(
                                  removeTurboSkip: true,
                                  allowR2NotebookShortcut: true,
                                  turboKey: 0xA,
                                  fixTextureIds: true,
                                  correctLanguageVoiceTables: true,
                                  disableMouseCapture: true,
                                  disablePauseOnFocusLoss: true
                                  ));
                mods.AddRange(Sen1Mods.GetAssetMods());
                result = FileModExec.ExecuteMods(path, storage, mods, new CliProgressReporter());
            }
            else
            {
                var mods = new List <FileMod>();
                mods.AddRange(Sen2Mods.GetExecutableMods(
                                  removeTurboSkip: true,
                                  patchAudioThread: true,
                                  audioThreadDivisor: 1000,
                                  patchBgmQueueing: true,
                                  correctLanguageVoiceTables: true,
                                  disableMouseCapture: true,
                                  disablePauseOnFocusLoss: true
                                  ));
                mods.AddRange(Sen2Mods.GetAssetMods());
                result = FileModExec.ExecuteMods(path, storage, mods, new CliProgressReporter());
            }

            if (!result.AllSuccessful)
            {
                Console.WriteLine($"Failed to patch CS{sengame} at {path}.");
                return(-1);
            }

            Console.WriteLine($"Successfully patched CS{sengame} at {path}.");
            return(0);
        }
Exemple #2
0
            public void Cs1GameInit()
            {
                int  CurrentProgress       = 0;
                int  TotalProgress         = 4;
                bool shouldAutoCloseWindow = true;

                try {
                    Progress.Message("Checking Sen1Launcher.exe...", CurrentProgress++, TotalProgress);
                    using (var fs = new HyoutaUtils.Streams.DuplicatableFileStream(Sen1LauncherPath)) {
                        SHA1 hash = ChecksumUtils.CalculateSHA1ForEntireStream(fs);
                        if (hash != new SHA1(0x8dde2b39f128179aul, 0x0beb3301cfd56a98ul, 0xc0f98a55u))
                        {
                            Progress.Error("Selected file does not appear to be Sen1Launcher.exe of version 1.6.");
                            Progress.Finish(false);
                            return;
                        }
                    }
                } catch (Exception ex) {
                    Progress.Error("Error while validating Sen1Launcher.exe: " + ex.Message);
                    Progress.Finish(false);
                    return;
                }

                try {
                    Path = System.IO.Path.GetDirectoryName(Sen1LauncherPath);
                    Progress.Message("Checking if we have encoding errors in filenames...", CurrentProgress++, TotalProgress);
                    if (FilenameFix.FixupIncorrectEncodingInFilenames(Path, 1, false, Progress))
                    {
                        if (!FilenameFix.FixupIncorrectEncodingInFilenames(Path, 1, true, Progress))
                        {
                            Progress.Error("Failed to fix encoding errors in filenames, attempting to proceed anyway...");
                            shouldAutoCloseWindow = false;
                        }
                    }
                    Progress.Message("Initializing patch data...", CurrentProgress++, TotalProgress);
                    var files = Sen1KnownFiles.Files;
                    Progress.Message("Initializing game data...", CurrentProgress++, TotalProgress);
                    var storageInit = FileModExec.InitializeAndPersistFileStorage(Path, files, Progress);
                    Storage = storageInit?.Storage;
                    if (storageInit == null || storageInit.Errors.Count != 0)
                    {
                        shouldAutoCloseWindow = false;
                    }
                } catch (Exception ex) {
                    Progress.Error("Error while initializing CS1 patch/game data: " + ex.Message);
                    Progress.Finish(false);
                    return;
                }

                ShouldProceedToPatchOptionWindow = Path != null && Storage != null;
                if (shouldAutoCloseWindow)
                {
                    Progress.Message("Initialized CS1 data, proceeding to patch options...", CurrentProgress, TotalProgress);
                }
                else
                {
                    Progress.Message("", CurrentProgress, TotalProgress);
                    if (ShouldProceedToPatchOptionWindow)
                    {
                        Progress.Error(
                            "Encountered problems while initializing CS1 data. "
                            + "Closing this window will proceed to the patch options anyway, but be aware that some patches may not work correctly. "
                            + "It is recommended to verify the game files using Steam or GOG Galaxy's build-in feature to do so, or to reinstall the game. "
                            + "Please also ensure you're trying to patch a compatible version of the game. (XSEED release version 1.6; other game versions are not compatible)"
                            );
                    }
                    else
                    {
                        Progress.Error(
                            "Unrecoverable issues while initializing CS1 data. "
                            + "Please ensure SenPatcher has read and write access to the selected game directory, then try again."
                            );
                    }
                }
                Progress.Finish(shouldAutoCloseWindow);
            }