mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-09-26 23:40:46 +00:00
Fix string writting issue in LOCFileWriter and updated LOCFile "API
This commit is contained in:
@@ -13,7 +13,7 @@ namespace PckStudio.Classes.IO.LOC
|
||||
|
||||
public static LOCFile Read(Stream stream)
|
||||
{
|
||||
return new LOCFileReader().ReadFile(stream);
|
||||
return new LOCFileReader().ReadFromStream(stream);
|
||||
}
|
||||
|
||||
private LOCFileReader() : base(false)
|
||||
@@ -21,7 +21,7 @@ namespace PckStudio.Classes.IO.LOC
|
||||
_file = new LOCFile();
|
||||
}
|
||||
|
||||
private LOCFile ReadFile(Stream stream)
|
||||
private LOCFile ReadFromStream(Stream stream)
|
||||
{
|
||||
int loc_type = ReadInt(stream);
|
||||
int language_count = ReadInt(stream);
|
||||
@@ -30,16 +30,16 @@ namespace PckStudio.Classes.IO.LOC
|
||||
for (int i = 0; i < language_count; i++)
|
||||
{
|
||||
string language = ReadString(stream);
|
||||
ReadInt(stream); // unknown value
|
||||
_file.Languages.Add(language);
|
||||
ReadInt(stream); // padding ???
|
||||
}
|
||||
for (int i = 0; i < language_count; i++)
|
||||
{
|
||||
ReadInt(stream);
|
||||
stream.ReadByte();
|
||||
if (0 < ReadInt(stream))
|
||||
stream.ReadByte();
|
||||
string language = ReadString(stream);
|
||||
if (!_file.Languages.Contains(language))
|
||||
throw new Exception("language not found");
|
||||
throw new KeyNotFoundException(nameof(language));
|
||||
int count = ReadInt(stream);
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
@@ -51,20 +51,20 @@ namespace PckStudio.Classes.IO.LOC
|
||||
return _file;
|
||||
}
|
||||
|
||||
internal List<string> ReadKeys(Stream stream)
|
||||
private List<string> ReadKeys(Stream stream)
|
||||
{
|
||||
stream.ReadByte(); // unknown
|
||||
bool useUniqueIds = Convert.ToBoolean(stream.ReadByte());
|
||||
int keyCount = ReadInt(stream);
|
||||
List<string> keys = new List<string>(keyCount);
|
||||
for (int i = 0; i < keyCount; i++)
|
||||
{
|
||||
string key = ReadString(stream);
|
||||
string key = useUniqueIds ? ReadInt(stream).ToString("X08") : ReadString(stream);
|
||||
keys.Add(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
internal string ReadString(Stream stream)
|
||||
private string ReadString(Stream stream)
|
||||
{
|
||||
int length = ReadShort(stream);
|
||||
return ReadString(stream, length, Encoding.UTF8);
|
||||
|
||||
Reference in New Issue
Block a user