예제 #1
0
        private static void SetupGame()
        {
            int selectedGameInput = -1;

            do
            {
                Console.WriteLine("Select Persona Game");

                // display list of available games as choices, starting at 1
                foreach (GameTitle game in Enum.GetValues(typeof(GameTitle)))
                {
                    Console.WriteLine($"{(int)game + 1}. {game}");
                }

                // save temp choice
                int tempChoice = ConsolePrompt.PromptInt("Game");

                // save and exit prompt if game choice is valid
                if (Enum.IsDefined(typeof(GameTitle), tempChoice - 1))
                {
                    selectedGameInput = tempChoice - 1;
                }
            }while (selectedGameInput < 0);

            GameTitle selectedGame = (GameTitle)selectedGameInput;

            currentGame = new GameProps(selectedGame);
        }
 public void Run(GameProps game)
 {
     if (!File.Exists(game.EncountFile))
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine($"[{Name}] Requires the game's ({game.Name}) ENCOUNT tbl!");
         Console.WriteLine($"Missing file: {game.EncountFile}");
         Console.ResetColor();
     }
     else
     {
         _currentGame = game;
         RunEncount();
     }
 }
        public void GeneratePatch(string outputFolder, GameProps game, ushort[] encountMusicIds)
        {
            List <PatchEdit> musicPatches = new List <PatchEdit>();

            for (int i = 0, total = encountMusicIds.Length; i < total; i++)
            {
                int    currentOffset     = (i * game.EntrySize) + game.StartingOffset;
                byte[] currentMusicBytes = BitConverter.GetBytes(encountMusicIds[i]);

                if (game.IsBigEndian)
                {
                    Array.Reverse(currentMusicBytes);
                }

                musicPatches.Add(new PatchEdit()
                {
                    tbl     = "ENCOUNT",
                    section = 0,
                    data    = PatchDataFormatter.ByteArrayToHexText(currentMusicBytes),
                    offset  = currentOffset
                });
            }

            Patch encountPatch = new Patch()
            {
                Version = 1,
                Patches = musicPatches.ToArray()
            };

            string patchFilePath = $@"{outputFolder}\EncountMusicPatches.tbp";

            // create sub tblpatches folder if missing
            if (!Directory.GetParent(patchFilePath).Exists)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(patchFilePath));
            }

            File.WriteAllText(patchFilePath, JsonSerializer.Serialize(encountPatch, new JsonSerializerOptions {
                WriteIndented = true
            }));
            //Console.WriteLine($"TBL Patch Created: {patchFilePath}");
        }
        public void Run(GameProps game)
        {
            PresetConfig config = new PresetConfig(new BGMEConfig(), new Dictionary <string, ushort>());

            // store list of encounter music ids
            ushort[] encountersMusicIds = new ushort[game.TotalEncounters()];

            // get preset file path
            string presetFile = SelectPresetFile();

            if (presetFile == null)
            {
                return;
            }

            try
            {
                string[] presetLines = File.ReadAllLines(presetFile);

                foreach (string line in presetLines)
                {
                    // skip comment lines
                    if (line.StartsWith("//") || line.Length < 3)
                    {
                        continue;
                    }

                    string[] lineArgs = line.Split("=");

                    string item    = lineArgs[0];
                    string command = lineArgs[1];

                    // parse command to get new music id
                    ushort newMusicId = ParseCommand(ref config, command);

                    // line is a collection command
                    if (lineArgs[0].StartsWith('.'))
                    {
                        string collection = item.Substring(1);
                        RunCollectionCommand(encountersMusicIds, collection, newMusicId);
                    }
                    // line is an alias command
                    else if (lineArgs[0].StartsWith('_'))
                    {
                        string setName = lineArgs[0];
                        RunAliasCommand(ref config, setName, newMusicId);
                    }
                    else
                    {
                        int encounterIndex = Int32.Parse(lineArgs[0]);

                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine("Direct Edit");
                        Console.ResetColor();
                        Console.WriteLine($"Encounter Index: {encounterIndex} Song Index: {newMusicId}");
                        encountersMusicIds[encounterIndex] = newMusicId;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.Write("Problem reading preset file! Enter any key to return to menu...");
                return;
            }

            try
            {
                // create preset tbl patches
                EmptyFolder(game.TblPatchesFolder);
                patchGenerator.GeneratePatch(game.TblPatchesFolder, game, encountersMusicIds);

                // create inaba patch for p4g
                if (game.Name == GameTitle.P4G)
                {
                    EmptyFolder(game.PatchesFolder);
                    config.BgmeConfig.BuildPatch(game.PatchesFolder);
                }

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Aemulus Package Created: {game.PackageFolder}");
                Console.ResetColor();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Problem creating package!");
            }
        }