mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-09-26 20:20: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);
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace PckStudio.Classes.IO.LOC
|
||||
|
||||
private void WriteToStream(Stream stream, int type)
|
||||
{
|
||||
if (_locfile == null) throw new ArgumentNullException("Loc File is null");
|
||||
if (_locfile == null) throw new ArgumentNullException(nameof(_locfile));
|
||||
WriteInt(stream, type);
|
||||
WriteInt(stream, _locfile.Languages.Count);
|
||||
if (type == 2) WriteLocKeys(stream);
|
||||
@@ -34,7 +34,7 @@ namespace PckStudio.Classes.IO.LOC
|
||||
|
||||
private void WriteLocKeys(Stream stream)
|
||||
{
|
||||
stream.WriteByte(0);
|
||||
stream.WriteByte(0); // dont use stringIds(ints)
|
||||
WriteInt(stream, _locfile.LocKeys.Count);
|
||||
foreach (var key in _locfile.LocKeys.Keys)
|
||||
WriteString(stream, key);
|
||||
@@ -42,19 +42,20 @@ namespace PckStudio.Classes.IO.LOC
|
||||
|
||||
private void WriteLanguages(Stream stream)
|
||||
{
|
||||
foreach (var language in _locfile.Languages)
|
||||
_locfile.Languages.ForEach(language =>
|
||||
{
|
||||
WriteString(stream, language);
|
||||
WriteInt(stream, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void WriteLanguageEntries(Stream stream, int type)
|
||||
{
|
||||
foreach (var language in _locfile.Languages)
|
||||
_locfile.Languages.ForEach(language =>
|
||||
{
|
||||
WriteInt(stream, 0x1337);
|
||||
stream.WriteByte(0);
|
||||
WriteInt(stream, 0x6D696B75); // :P
|
||||
stream.WriteByte(0); // <- only write when the previous written int was >0
|
||||
|
||||
WriteString(stream, language);
|
||||
WriteInt(stream, _locfile.LocKeys.Keys.Count);
|
||||
foreach(var locKey in _locfile.LocKeys.Keys)
|
||||
@@ -62,12 +63,12 @@ namespace PckStudio.Classes.IO.LOC
|
||||
if (type == 0) WriteString(stream, locKey);
|
||||
WriteString(stream, _locfile.LocKeys[locKey][language]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
internal void WriteString(Stream stream, string s)
|
||||
private void WriteString(Stream stream, string s)
|
||||
{
|
||||
WriteShort(stream, (short)s.Length);
|
||||
WriteShort(stream, Convert.ToInt16(Encoding.UTF8.GetByteCount(s)));
|
||||
WriteString(stream, s, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user