diff --git a/NHSE.Core/Save/Files/MainSave.cs b/NHSE.Core/Save/Files/MainSave.cs index 8ff08f3..2d765cf 100644 --- a/NHSE.Core/Save/Files/MainSave.cs +++ b/NHSE.Core/Save/Files/MainSave.cs @@ -190,17 +190,9 @@ public void SetAcreBytes(ReadOnlySpan data) public const int MapDesignNone = 0xF800; - public ushort[] GetMapDesignTiles() - { - var slice = Data.Slice(Offsets.MyDesignMap, 112 * 96 * sizeof(ushort)); - return MemoryMarshal.Cast(slice).ToArray(); - } - - public void SetMapDesignTiles(ReadOnlySpan value) - { - var cast = MemoryMarshal.Cast(value); - cast.CopyTo(Data[Offsets.MyDesignMap..]); - } + public Memory MapDesignTileData => Raw.Slice(Offsets.MyDesignMap, 112 * 96 * sizeof(ushort)); + public ushort[] GetMapDesignTiles() => MemoryMarshal.Cast(MapDesignTileData.Span).ToArray(); + public void SetMapDesignTiles(ReadOnlySpan value) => MemoryMarshal.Cast(value).CopyTo(MapDesignTileData.Span); private const int FieldItemLayerSize = MapGrid.MapTileCount32x32 * Item.SIZE; private const int FieldItemFlagSize = MapGrid.MapTileCount32x32 / 8; // bitflags diff --git a/NHSE.Core/Structures/Misc/Reaction.cs b/NHSE.Core/Structures/Misc/Reaction.cs index 2e43487..9c7e1cf 100644 --- a/NHSE.Core/Structures/Misc/Reaction.cs +++ b/NHSE.Core/Structures/Misc/Reaction.cs @@ -5,89 +5,89 @@ /// public enum Reaction : byte { - None, - Happiness, // Smiling - Laughter, // Laughing - Joy, // HappyFlower - Love, // Love - Glee, // HappyDance - UNUSED_6, // Anger (Unused) - Aggravation, // Outraged - UNUSED_8, // Outrage (Unused) - Worry, // Worried - Sighing, // Sighing - Thought, // Thinking - Sadness, // SadSpiral - Distress, // Frantic - Sorrow, // Crying - Amazed, // Shocked - Surprise, // Aha - UNUSED_17, // Disbelief (Unused) - Shocked, // Surprised - Cold_Chill, // ColdChill - Fearful, // Shaking - Agreement, // Nodding - Inspiration, // IdeaBulb - Curiosity, // QuestionMark - Heartbreak, // BrokenHeart - Sleepy, // Sleepy - Bashfulness, // Blushing - Resignation, // OhGeez - Mischief, // Scheming - Delight, // Clapping - Sneezing, // Sneezing - Encouraging, // Cheering - Greetings, // Greeting - Pride, // SmugFace - UNUSED_34, // Sweating (Unused) - Smirking, // Grin - Sheepishness, // WrySmile - UNUSED_37, // Smile (Unused) - UNUSED_38, // Sunniness (Unused) - Shyness, // Hesitate - Disagreement, // Negative - Mistaken, // Oops - Flourish, // Dance - Daydreaming, // AbsentMindedness - Showmanship, // Shaki - Dozing, // Sleep - UNUSED_46, // Shrunk Funk Shuffle (Unused) - Intense, // Silent - Pleased, // Hello - UNUSED_49, // Distress without the hand movements? (Unused) - UNUSED_50, // Smiling and rubbing cheek (Unused) - UNUSED_51, // Poking hands together (Unused) - UNUSED_52, // Intense but frowning (Unused) - UNUSED_53, // Amazed with smaller particles (Unused) - Apologetic, // Apologize - Confident, // Assent - UNUSED_56, // Talking (Unused) - UNUSED_57, // Clapping with no expression (Makes you stand up if sitting down) (Unused) - Bewilderment, // Pardon - UNUSED_59, // Greetings with no sound or expression (Unused) + None = 0, + Happiness = 1, // Smiling + Laughter = 2, // Laughing + Joy = 3, // HappyFlower + Love = 4, // Love + Glee = 5, // HappyDance + UNUSED_6 = 6, // Anger (Unused) + Aggravation = 7, // Outraged + UNUSED_8 = 8, // Outrage (Unused) + Worry = 9, // Worried + Sighing = 10, // Sighing + Thought = 11, // Thinking + Sadness = 12, // SadSpiral + Distress = 13, // Frantic + Sorrow = 14, // Crying + Amazed = 15, // Shocked + Surprise = 16, // Aha + UNUSED_17 = 17, // Disbelief (Unused) + Shocked = 18, // Surprised + Cold_Chill = 19, // ColdChill + Fearful = 20, // Shaking + Agreement = 21, // Nodding + Inspiration = 22, // IdeaBulb + Curiosity = 23, // QuestionMark + Heartbreak = 24, // BrokenHeart + Sleepy = 25, // Sleepy + Bashfulness = 26, // Blushing + Resignation = 27, // OhGeez + Mischief = 28, // Scheming + Delight = 29, // Clapping + Sneezing = 30, // Sneezing + Encouraging = 31, // Cheering + Greetings = 32, // Greeting + Pride = 33, // SmugFace + UNUSED_34 = 34, // Sweating (Unused) + Smirking = 35, // Grin + Sheepishness = 36, // WrySmile + UNUSED_37 = 37, // Smile (Unused) + UNUSED_38 = 38, // Sunniness (Unused) + Shyness = 39, // Hesitate + Disagreement = 40, // Negative + Mistaken = 41, // Oops + Flourish = 42, // Dance + Daydreaming = 43, // AbsentMindedness + Showmanship = 44, // Shaki + Dozing = 45, // Sleep + UNUSED_46 = 46, // Shrunk Funk Shuffle (Unused) + Intense = 47, // Silent + Pleased = 48, // Hello + UNUSED_49 = 49, // Distress without the hand movements? (Unused) + UNUSED_50 = 50, // Smiling and rubbing cheek (Unused) + UNUSED_51 = 51, // Poking hands together (Unused) + UNUSED_52 = 52, // Intense but frowning (Unused) + UNUSED_53 = 53, // Amazed with smaller particles (Unused) + Apologetic = 54, // Apologize + Confident = 55, // Assent + UNUSED_56 = 56, // Talking (Unused) + UNUSED_57 = 57, // Clapping with no expression (Makes you stand up if sitting down) (Unused) + Bewilderment = 58, // Pardon + UNUSED_59 = 59, // Greetings with no sound or expression (Unused) - Scare, // AddPrank - Haunt, // AddScaring - SitDown, // AddSitDown - Yoga, // AddYoga - HereYouGo, // AddHereYouGo - WorkOut, // AddGymnastics - TakeAPicture, // AddTakePictures - SniffSniff, // AddSmell - Tada, // AddPraise - WaveGoodbye, // AddWaveHands - Excited, // AddExcited + Scare = 60, // AddPrank + Haunt = 61, // AddScaring + SitDown = 62, // AddSitDown + Yoga = 63, // AddYoga + HereYouGo = 64, // AddHereYouGo + WorkOut = 65, // AddGymnastics + TakeAPicture = 66, // AddTakePictures + SniffSniff = 67, // AddSmell + Tada = 68, // AddPraise + WaveGoodbye = 69, // AddWaveHands + Excited = 70, // AddExcited - Confetti, // (Festivale DLC) - Viva, // (Festivale DLC) - LetsGo, // (Festivale DLC) - FeelinIt, // (Festivale DLC) + Confetti = 71, // (Festivale DLC) + Viva = 72, // (Festivale DLC) + LetsGo = 73, // (Festivale DLC) + FeelinIt = 74, // (Festivale DLC) - UNUSED_75, // Gullivar about to come alive (Unused) - UNUSED_76, // Intense shake action (Unused) - UNUSED_77, // Literally the "roll safe" meme (google it) (Unused) - UNUSED_78, // Leave it to me! (Unused) - UNUSED_79, // K.K. Slider Sitting (Unused) - UNUSED_80, // K.K. nodding while sitting (Unused) - UNUSED_81, // K.K. thinking while sitting (Unused) + UNUSED_75 = 75, // Gullivar about to come alive (Unused) + UNUSED_76 = 76, // Intense shake action (Unused) + UNUSED_77 = 77, // Literally the "roll safe" meme (google it) (Unused) + UNUSED_78 = 78, // Leave it to me! (Unused) + UNUSED_79 = 79, // K.K. Slider Sitting (Unused) + UNUSED_80 = 80, // K.K. nodding while sitting (Unused) + UNUSED_81 = 81, // K.K. thinking while sitting (Unused) } \ No newline at end of file diff --git a/NHSE.Parsing/GameMSBTDumper.cs b/NHSE.Parsing/GameMSBTDumper.cs index fac6f96..9ec121d 100644 --- a/NHSE.Parsing/GameMSBTDumper.cs +++ b/NHSE.Parsing/GameMSBTDumper.cs @@ -7,6 +7,33 @@ namespace NHSE.Parsing; public static class GameMSBTDumper { + /// + /// Dumps everything the program uses to the provided , using the provided . + /// + /// Source of files. + /// Destination folder where the dumps will be saved. + /// Convert all files to CSV for easy viewing. + /// Delimiter when exporting the files + public static void UpdateDumps(string root, string dest, bool csv = true, char delim = '\t') + { + if (csv) + UpdateCSV(root, Path.Combine(dest, "csv"), delim); + } + + public static void UpdateCSV(string root, string dest, char delim = '\t') + { + Directory.CreateDirectory(dest); + var files = Directory.GetFiles(root, "*.msbt", SearchOption.AllDirectories); + foreach (var file in files) + { + var relative = Path.GetRelativePath(root, file); + var outPath = Path.Combine(dest, relative + ".csv"); + Directory.CreateDirectory(Path.GetDirectoryName(outPath)!); + var csvData = MSBTUtil.GetCSV(file, delim); + File.WriteAllLines(outPath, csvData); + } + } + public static string[] GetItemListResource(string msgPath, string language) { var list = GetItemList(msgPath, language); diff --git a/NHSE.Parsing/MSBT/MSBTUtil.cs b/NHSE.Parsing/MSBT/MSBTUtil.cs index 6c0b4fa..6fa53c4 100644 --- a/NHSE.Parsing/MSBT/MSBTUtil.cs +++ b/NHSE.Parsing/MSBT/MSBTUtil.cs @@ -16,6 +16,31 @@ public static void DebugDumpLines(this MSBT obj) public static IEnumerable GetOrderedLines(string path, int indexBias = 0) => new MSBT(File.ReadAllBytes(path)).GetOrderedLines(indexBias); + public static IEnumerable GetCSV(string path, int indexBias = 0, char delim = '\t') + { + var obj = new MSBT(File.ReadAllBytes(path)); + var sorted = obj.LBL1.Labels + .Where(z => !z.Name.EndsWith("_pl")) + .OrderBy(z => z.Index); + foreach (var x in sorted) + { + var index = x.Index; + var name = x.Name; + var strings = obj.TXT2.Strings; + var line = GetStringIndex(index, strings, obj); + yield return $"{index + indexBias}{delim}\"{name}\"{delim}\"{line.Replace("\"", "\"\"")}\""; + } + } + + private static string GetStringIndex(uint index, List strings, MSBT obj) + { + if (index >= strings.Count) + return $"INVALID INDEX?? {index}"; + var data = strings[(int)index]; + var line = data.ToString(obj.FileEncoding).TrimEnd('\0'); + return line; + } + public static IEnumerable GetOrderedLines(this MSBT obj, int indexBias = 0) { var sorted = obj.LBL1.Labels diff --git a/NHSE.Tests/DumpTests.cs b/NHSE.Tests/DumpTests.cs index 5b602b1..a829e2e 100644 --- a/NHSE.Tests/DumpTests.cs +++ b/NHSE.Tests/DumpTests.cs @@ -29,5 +29,7 @@ public static void DumpMSBT() Assert.SkipUnless(Directory.Exists(dump), "Dump not found, skip."); // skip this test if not properly configured for this test GameMSBTDumperNHSE.Dump(folder, dump, MessageDumpFormat); + + GameMSBTDumper.UpdateDumps(dump, dump); } } \ No newline at end of file