예제 #1
0
        public List <GameTitleDbEntry> GetCoreDbRootGameTitleEntries()
        {
            var output = new List <GameTitleDbEntry>();

            if (!File.Exists(_resourceService.GetGameTitleDbResource()))
            {
                return(output);
            }

            var t = new ParamFile();

            t.Open(_resourceService.GetGameTitleDbResource());

            var dbRoot = t.Root.Nodes[HEX_CAT_DBROOT] as ParamList;

            foreach (var node in dbRoot.Nodes)
            {
                var rootEntry = node as ParamStruct;
                output.Add(new GameTitleDbEntry()
                {
                    UiGameTitleId = GetNodeParamValueHash40(rootEntry, HEX_UI_GAMETITLE_ID),
                    UiSeriesId    = GetNodeParamValueHash40(rootEntry, HEX_UI_SERIES_ID),
                    NameId        = GetNodeParamValue <string>(rootEntry, HEX_NAME_ID),
                    Release       = GetNodeParamValue <int>(rootEntry, HEX_RELEASE),
                    Unk1          = GetNodeParamValue <bool>(rootEntry, 0x1c38302364)
                });
            }

            return(output);
        }
예제 #2
0
파일: PrcCrypto.cs 프로젝트: dj0817/YesWeDo
        public XmlDocument DisassembleEncrypted(string fileLocation, string labelsFileLocation = "")
        {
            labelName = labelsFileLocation;

            if (!string.IsNullOrEmpty(labelName))
            {
                try
                {
                    if (hashToStringLabels == null)
                    {
                        hashToStringLabels = LabelIO.GetHashStringDict(labelName);
                    }
                }
                catch (Exception ex)
                {
                    UiHelper.PopUpMessage(ex.Message);
                    return(new XmlDocument());
                }
            }

            file = new ParamFile();
            file.Open(fileLocation);

            xml = new XmlDocument();
            xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
            xml.AppendChild(ParamStruct2Node(file.Root));

            return(xml);
        }
예제 #3
0
        public List <BgmDbRootEntry> GetCoreDbRootBgmEntries()
        {
            var output = new List <BgmDbRootEntry>();

            if (!File.Exists(_resourceService.GetBgmDbResource()))
            {
                return(output);
            }

            var t = new ParamFile();

            t.Open(_resourceService.GetBgmDbResource());

            var dbRoot = t.Root.Nodes[HEX_CAT_DBROOT] as ParamList;

            foreach (var node in dbRoot.Nodes)
            {
                var rootEntry = node as ParamStruct;
                output.Add(new BgmDbRootEntry()
                {
                    UiBgmId       = GetNodeParamValueHash40(rootEntry, HEX_UI_BGM_ID),
                    StreamSetId   = GetNodeParamValueHash40(rootEntry, HEX_STREAM_SET_ID),
                    Rarity        = GetNodeParamValueHash40(rootEntry, HEX_RARITY),
                    RecordType    = GetNodeParamValueHash40(rootEntry, HEX_RECORD_TYPE),
                    UiGameTitleId = GetNodeParamValueHash40(rootEntry, HEX_UI_GAMETITLE_ID),
                    NameId        = GetNodeParamValue <string>(rootEntry, HEX_NAME_ID),
                    SaveNo        = GetNodeParamValue <short>(rootEntry, HEX_SAVE_NO),
                    TestDispOrder = GetNodeParamValue <short>(rootEntry, HEX_TEST_DISP_ORDER),
                    MenuValue     = GetNodeParamValue <int>(rootEntry, HEX_MENU_VALUE),
                    ShopPrice     = GetNodeParamValue <uint>(rootEntry, HEX_SHOP_PRICE),
                });
            }

            return(output);
        }
예제 #4
0
        public bool GenerateGameTitlePrcFile(List <GameTitleDbNewEntry> gameTitleEntries, string outputFilePath)
        {
            var coreGameSeries = _coreGameTitleDb.Select(p => p.UiSeriesId).Distinct().ToList();
            var releaseIndex   = _coreGameTitleDb.OrderByDescending(p => p.Release).First().Release + 1;

            var t = new ParamFile();

            t.Open(_resourceService.GetGameTitleDbResource());
            var dbRoot = t.Root.Nodes[HEX_CAT_DBROOT] as ParamList;

            foreach (var gameTitleEntry in gameTitleEntries)
            {
                var uiSeriesId = gameTitleEntry.UiSeriesId;
                if (!coreGameSeries.Contains(gameTitleEntry.UiSeriesId))
                {
                    uiSeriesId = Constants.InternalIds.GameSeriesIdDefault;
                }

                var newEntry = dbRoot.Nodes[0].Clone() as ParamStruct;
                SetNodeParamValue(newEntry, HEX_UI_GAMETITLE_ID, gameTitleEntry.UiGameTitleId);
                SetNodeParamValue(newEntry, HEX_UI_SERIES_ID, uiSeriesId);
                SetNodeParamValue(newEntry, HEX_NAME_ID, gameTitleEntry.NameId);
                SetNodeParamValue(newEntry, HEX_RELEASE, releaseIndex);
                dbRoot.Nodes.Add(newEntry);
                releaseIndex++;
            }

            t.Save(outputFilePath);

            return(true);
        }
        public ParamFile OpenParamFile(string inputFile)
        {
            var t = new ParamFile();

            t.Open(inputFile);
            return(t);
        }
예제 #6
0
        public T ReadPrcFile <T>(string inputFile) where T : new()
        {
            //Validate file
            if (!File.Exists(inputFile))
            {
                throw new Exception($"PRC File does not exist: {inputFile}");
            }

            //Open file
            var t = new ParamFile();

            t.Open(inputFile);

            //Init object
            var outputObj = new T();

            //Parse recursively
            ReadPrc(t.Root, outputObj, null);

            return(outputObj);
        }
예제 #7
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args).WithParsed((o) =>
            {
                if (!Directory.Exists(o.InputPath))
                {
                    Console.WriteLine($"Directory '{o.InputPath}' does not exist");
                    return;
                }

                if (!File.Exists(o.InputParamLabelsFile))
                {
                    Console.WriteLine($"File '{o.InputParamLabelsFile}' does not exist");
                    return;
                }

                Directory.CreateDirectory(o.OutputPath);

                var filesPrc = Directory.GetFiles(o.InputPath, "*.prc", SearchOption.AllDirectories).ToList();
                filesPrc.AddRange(Directory.GetFiles(o.InputPath, "*.stprm", SearchOption.AllDirectories));
                filesPrc.AddRange(Directory.GetFiles(o.InputPath, "*.stdat", SearchOption.AllDirectories));
                var dictHashes      = GetParamLabels(o.InputParamLabelsFile);
                var outputUncracked = new List <CsvEntry>();

                foreach (var file in filesPrc)
                {
                    var inputFileRelative = file.TrimStart(o.InputPath);
                    var outputFile        = Path.Combine(o.OutputPath, inputFileRelative.TrimStart('\\').Replace('\\', Path.DirectorySeparatorChar) + ".csv");
                    Directory.CreateDirectory(Path.GetDirectoryName(outputFile));

                    var output = new List <CsvEntry>();
                    var t      = new ParamFile();
                    t.Open(file);

                    if (o.TrackUncracked)
                    {
                        ParseStruct(outputUncracked, t.Root.Nodes, dictHashes, inputFileRelative, string.Empty, string.Empty, o.TrackUncracked);
                    }
                    else
                    {
                        ParseStruct(output, t.Root.Nodes, dictHashes, inputFileRelative, string.Empty, string.Empty, o.TrackUncracked);
                    }

                    if (!o.TrackUncracked)
                    {
                        using (var writer = new StreamWriter(outputFile))
                        {
                            using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
                            {
                                csv.WriteHeader <CsvEntry>();
                                csv.NextRecord();
                                foreach (var record in output)
                                {
                                    csv.WriteRecord(record);
                                    csv.NextRecord();
                                }
                            }
                        }
                    }
                }

                if (o.TrackUncracked)
                {
                    var groupedKeys = outputUncracked.Where(p => p.KeyHexa != null && p.KeyLabel.StartsWith("0x")).GroupBy(p => p.KeyLabel).Select(p => new CsvEntryUncracked()
                    {
                        Hex        = p.Key,
                        KeyOrValue = "Key",
                        FilePaths  = string.Join(" | ", p.Select(p2 => p2.FilePath).Distinct().Take(10))
                    });
                    var groupedValues = outputUncracked.Where(p => p.ValueHexa != null && p.ValueLabel.StartsWith("0x")).GroupBy(p => p.ValueLabel).Select(p => new CsvEntryUncracked()
                    {
                        Hex        = p.Key,
                        KeyOrValue = "Value",
                        FilePaths  = string.Join(" | ", p.Select(p2 => p2.FilePath).Distinct().Take(10))
                    });
                    var grouped = new List <CsvEntryUncracked>();
                    grouped.AddRange(groupedKeys);
                    grouped.AddRange(groupedValues);

                    //Double check
                    foreach (var group in grouped)
                    {
                        var test = GetHexaLabel(dictHashes, Convert.ToUInt64(group.Hex, 16));
                        if (!test.StartsWith("0x"))
                        {
                            Console.WriteLine("uncracked_hashes_grouped.csv");
                        }
                    }

                    //Generate uncracked_hashes_grouped.csv
                    using (var writer = new StreamWriter("uncracked_hashes_grouped.csv"))
                    {
                        using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
                        {
                            csv.WriteHeader <CsvEntryUncracked>();
                            csv.NextRecord();
                            foreach (var record in grouped)
                            {
                                csv.WriteRecord(record);
                                csv.NextRecord();
                            }
                        }
                    }

                    //Generate uncracked_hashes.csv
                    using (var writer = new StreamWriter("uncracked_hashes.csv"))
                    {
                        using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
                        {
                            csv.WriteHeader <CsvEntry>();
                            csv.NextRecord();
                            foreach (var record in outputUncracked)
                            {
                                csv.WriteRecord(record);
                                csv.NextRecord();
                            }
                        }
                    }
                }
            });
        }
예제 #8
0
        public bool GenerateBgmPrcFile(List <BgmDbNewEntry> bgmEntries, string outputFilePath)
        {
            var saveNoIndex        = (short)(_coreBgmDb.OrderByDescending(p => p.SaveNo).First().SaveNo + 1);
            var testDispOrderIndex = (short)(_coreBgmDb.OrderByDescending(p => p.TestDispOrder).First().TestDispOrder + 1);
            var menuValueIndex     = _coreBgmDb.OrderByDescending(p => p.MenuValue).First().MenuValue + 1;

            var t = new ParamFile();

            t.Open(_resourceService.GetBgmDbResource());

            //DBROOT
            var dbRoot = t.Root.Nodes[HEX_CAT_DBROOT] as ParamList;

            foreach (var bgmEntry in bgmEntries)
            {
                var newEntry = dbRoot.Nodes[1].Clone() as ParamStruct;
                SetNodeParamValue(newEntry, HEX_UI_BGM_ID, bgmEntry.UiBgmId);
                SetNodeParamValue(newEntry, HEX_STREAM_SET_ID, bgmEntry.StreamSetId);
                SetNodeParamValue(newEntry, HEX_RARITY, bgmEntry.Rarity);
                SetNodeParamValue(newEntry, HEX_RECORD_TYPE, bgmEntry.RecordType);
                SetNodeParamValue(newEntry, HEX_UI_GAMETITLE_ID, bgmEntry.UiGameTitleId);
                SetNodeParamValue(newEntry, HEX_NAME_ID, bgmEntry.NameId);
                //SetNodeParamValue(newEntry, HEX_SAVE_NO, saveNoIndex);
                SetNodeParamValue(newEntry, HEX_TEST_DISP_ORDER, testDispOrderIndex);
                SetNodeParamValue(newEntry, HEX_MENU_VALUE, menuValueIndex);
                SetNodeParamValue(newEntry, HEX_SHOP_PRICE, (uint)0);
                dbRoot.Nodes.Add(newEntry);
                saveNoIndex++;
                testDispOrderIndex++;
                menuValueIndex++;
            }

            //STREAM_SET
            var streamSet = t.Root.Nodes[HEX_CAT_STREAM_SET] as ParamList;

            foreach (var bgmEntry in bgmEntries)
            {
                var newEntry = streamSet.Nodes[0].Clone() as ParamStruct;
                SetNodeParamValue(newEntry, HEX_STREAM_SET_ID, bgmEntry.StreamSetId);
                SetNodeParamValue(newEntry, HEX_INFO0, bgmEntry.Info0);
                streamSet.Nodes.Add(newEntry);
            }

            //ASSIGNED_INFO
            var assignedInfo = t.Root.Nodes[HEX_CAT_ASSIGNED_INFO] as ParamList;

            foreach (var bgmEntry in bgmEntries)
            {
                var newEntry = assignedInfo.Nodes[0].Clone() as ParamStruct;
                SetNodeParamValue(newEntry, HEX_INFO_ID, bgmEntry.InfoId);
                SetNodeParamValue(newEntry, HEX_STREAM_ID, bgmEntry.StreamId);
                assignedInfo.Nodes.Add(newEntry);
            }

            //STREAM_PROPERTY
            var streamProperty = t.Root.Nodes[HEX_CAT_STREAM_PROPERTY] as ParamList;

            foreach (var bgmEntry in bgmEntries)
            {
                var newEntry = streamProperty.Nodes[0].Clone() as ParamStruct;
                SetNodeParamValue(newEntry, HEX_STREAM_ID, bgmEntry.StreamId);
                SetNodeParamValue(newEntry, HEX_DATA_NAME0, bgmEntry.DataName0);
                streamProperty.Nodes.Add(newEntry);
            }

            //BGM PLAYLIST (QUICK & DIRTY)
            foreach (var bgmEntry in bgmEntries)
            {
                if (bgmEntry.Playlists == null)
                {
                    continue;
                }
                foreach (var playlist in bgmEntry.Playlists)
                {
                    var playlistId = playlist.Id;
                    if (!playlistId.StartsWith("bgm"))
                    {
                        _logger.LogWarning("The playlist_id for song '{Song}' must start with 'bgm', skipping...", bgmEntry.ToneName);
                        continue;
                    }

                    var hexValue = Hash40Util.StringToHash40(playlistId);

                    ParamList   bgmPlaylist = null;
                    ParamStruct newEntry    = null;
                    //If the playlist doesn't exist...
                    if (!t.Root.Nodes.ContainsKey(hexValue))
                    {
                        var playlistToClone = t.Root.Nodes[HEX_PLAYLIST_EXAMPLE] as ParamList;
                        bgmPlaylist = playlistToClone.Clone() as ParamList;

                        t.Root.Nodes.Add(hexValue, bgmPlaylist);
                        if (bgmPlaylist.Nodes.Count > 1)
                        {
                            bgmPlaylist.Nodes.RemoveRange(1, bgmPlaylist.Nodes.Count - 1);
                            newEntry = bgmPlaylist.Nodes[0] as ParamStruct;
                        }
                    }
                    else
                    {
                        bgmPlaylist = t.Root.Nodes[hexValue] as ParamList;
                        newEntry    = bgmPlaylist.Nodes[0].Clone() as ParamStruct;
                        bgmPlaylist.Nodes.Add(newEntry);
                    }

                    //Add song
                    SetNodeParamValue(newEntry, HEX_UI_BGM_ID, bgmEntry.UiBgmId);
                    for (int i = 0; i <= 15; i++)
                    {
                        SetNodeParamValue(newEntry, string.Format(HEX_ORDERNBR, i), (short)(bgmPlaylist.Nodes.Count));
                        SetNodeParamValue(newEntry, string.Format(HEX_INCIDENCENBR, i), (ushort)500);
                    }
                }
            }

            t.Save(outputFilePath);

            return(true);
        }
예제 #9
0
        static void Main(string[] args)
        {
            stopwatch = new Stopwatch();
            bool   helpPrinted = false;
            string input       = null;
            string output      = null;

            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-d":
                        mode = BuildMode.Disassemble;
                        break;

                    case "-a":
                        mode = BuildMode.Assemble;
                        break;

                    case "-h":
                    case "-help":
                        Console.WriteLine(HelpText);
                        helpPrinted = true;
                        break;

                    case "-o":
                        output = args[++i];
                        break;

                    case "-l":
                        labelName = args[++i];
                        break;

                    default:
                        input = args[i];
                        break;
                    }
                }
                if (input == null || mode == BuildMode.Invalid)
                {
                    if (!helpPrinted)
                    {
                        Console.WriteLine(HelpText);
                    }
                    return;
                }
                if (mode == BuildMode.Disassemble)
                {
                    if (string.IsNullOrEmpty(output))
                    {
                        output = Path.GetFileNameWithoutExtension(input) + ".xml";
                    }
                    hashToStringLabels = new OrderedDictionary <ulong, string>();
                    if (!string.IsNullOrEmpty(labelName))
                    {
                        hashToStringLabels = LabelIO.GetHashStringDict(labelName);
                    }

                    Console.WriteLine("Initializing...");
                    stopwatch.Start();
                    file = new ParamFile();
                    file.Open(input);

                    Console.WriteLine("Disassembling...");
                    xml = new XmlDocument();
                    xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
                    xml.AppendChild(ParamStruct2Node(file.Root));
                    XmlWriterSettings settings = new XmlWriterSettings()
                    {
                        Indent = true
                    };
                    XmlWriter writer  = XmlWriter.Create(output, settings);
                    var       dirname = Path.GetDirectoryName(output);
                    if (!string.IsNullOrEmpty(dirname))
                    {
                        Directory.CreateDirectory(dirname);
                    }
                    xml.Save(writer);

                    stopwatch.Stop();
                    Console.WriteLine("Finished in {0} seconds", stopwatch.Elapsed.TotalSeconds);
                }
                else
                {
                    if (string.IsNullOrEmpty(output))
                    {
                        output = Path.GetFileNameWithoutExtension(input) + ".prc";
                    }
                    stringToHashLabels = new OrderedDictionary <string, ulong>();
                    if (!string.IsNullOrEmpty(labelName))
                    {
                        stringToHashLabels = LabelIO.GetStringHashDict(labelName);
                    }

                    Console.WriteLine("Initializing...");
                    stopwatch.Start();
                    xml = new XmlDocument();
                    xml.Load(input);
                    file = new ParamFile(Node2ParamStruct(xml.DocumentElement));

                    Console.WriteLine("Assembling...");
                    var dirname = Path.GetDirectoryName(output);
                    if (!string.IsNullOrEmpty(dirname))
                    {
                        Directory.CreateDirectory(dirname);
                    }
                    file.Save(output);

                    stopwatch.Stop();
                    Console.WriteLine("Finished in {0} seconds", stopwatch.Elapsed.TotalSeconds);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (e.InnerException == null)
                {
                    Console.WriteLine(e.StackTrace);
                }
                else
                {
                    Console.WriteLine(e.InnerException.StackTrace);
                }
            }
        }