From ec70727d1cd10c9e8953faaa283638c2f5f02e68 Mon Sep 17 00:00:00 2001 From: Asval Date: Mon, 10 Jun 2019 16:30:56 +0200 Subject: [PATCH] it's readable now --- FModel/FModel.csproj | 2 +- FModel/Methods/LocRes/TempStringFinder.cs | 58 +++++++++++++---------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/FModel/FModel.csproj b/FModel/FModel.csproj index c54ace5e..624fcd27 100644 --- a/FModel/FModel.csproj +++ b/FModel/FModel.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {8FABCD3A-9D55-4B54-B237-B259D815DEB8} - WinExe + Exe FModel FModel v4.7.1 diff --git a/FModel/Methods/LocRes/TempStringFinder.cs b/FModel/Methods/LocRes/TempStringFinder.cs index 155bca0a..9f45e17d 100644 --- a/FModel/Methods/LocRes/TempStringFinder.cs +++ b/FModel/Methods/LocRes/TempStringFinder.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -16,37 +17,46 @@ namespace FModel /// private static string StringFinder(string filepath) { - StringBuilder sb = new StringBuilder(); - List LocalizedStringArray = new List(); + var dict = new Dictionary(); using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.GetEncoding(1252))) { byte[] MagicNumber = reader.ReadBytes(16); byte VersionNumber = reader.ReadByte(); - //Console.WriteLine("VersionNumber: " + VersionNumber); long LocalizedStringArrayOffset = -1; LocalizedStringArrayOffset = reader.ReadInt64(); - //Console.WriteLine("LocalizedStringArrayOffset: " + LocalizedStringArrayOffset); - - uint EntriesCount = reader.ReadUInt32(); - //Console.WriteLine("EntriesCount: " + EntriesCount); - - uint NamespaceCount = reader.ReadUInt32(); - //Console.WriteLine("NamespaceCount: " + NamespaceCount); - - reader.BaseStream.Position = LocalizedStringArrayOffset; - - readCleanString(reader, LocalizedStringArray); - - foreach (string s in LocalizedStringArray) + if (LocalizedStringArrayOffset != -1) { - sb.Append(s.Replace("\0", string.Empty) + "\n"); + long CurrentFileOffset = reader.BaseStream.Position; + + reader.BaseStream.Seek(LocalizedStringArrayOffset, SeekOrigin.Begin); + int arrayLength = reader.ReadInt32(); + Console.WriteLine("arrayLength: " + arrayLength); + + reader.BaseStream.Seek(LocalizedStringArrayOffset, SeekOrigin.Begin); + + string[] LocalizedStringArray = new string[arrayLength]; + for (int i = 0; i < LocalizedStringArray.Length; i++) + { + if (!dict.ContainsKey("key " + i)) + { + dict.Add("key " + i, readCleanString(reader)); + } + } + + reader.BaseStream.Seek(CurrentFileOffset, SeekOrigin.Begin); } + + /*uint NamespaceCount = reader.ReadUInt32(); + Console.WriteLine("NamespaceCount: " + NamespaceCount); + + uint KeyCount = reader.ReadUInt32(); + Console.WriteLine("KeyCount: " + KeyCount);*/ } - return sb.ToString(); + return JsonConvert.SerializeObject(dict, Formatting.Indented); } /// @@ -54,7 +64,7 @@ namespace FModel /// /// /// - private static void readCleanString(BinaryReader reader, List allMyStrings) + private static string readCleanString(BinaryReader reader) { reader.ReadInt32(); int stringLength = 0; @@ -67,18 +77,16 @@ namespace FModel { byte[] data = reader.ReadBytes((-1 - stringLength) * 2); reader.ReadBytes(2); - allMyStrings.Add(Encoding.Unicode.GetString(data)); + return Encoding.Unicode.GetString(data); } else if (stringLength == 0) { - return; + return ""; } else { - allMyStrings.Add(Encoding.GetEncoding(1252).GetString(reader.ReadBytes(stringLength))); + return Encoding.GetEncoding(1252).GetString(reader.ReadBytes(stringLength)).TrimEnd('\0'); } - - readCleanString(reader, allMyStrings); } public static string locresOpenFile(string defaultPath)