mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-02 11:54:33 +00:00
Update some minor stuff in Reader/Writer classes
This commit is contained in:
@@ -20,8 +20,8 @@ namespace PckStudio.Classes.IO.ARC
|
||||
private ConsoleArchive ReadFromStream(Stream stream)
|
||||
{
|
||||
ConsoleArchive _archive = new ConsoleArchive();
|
||||
int NumberOfFiles = ReadInt(stream);
|
||||
for(int i = 0; i < NumberOfFiles; i++)
|
||||
int numberOfFiles = ReadInt(stream);
|
||||
for(int i = 0; i < numberOfFiles; i++)
|
||||
{
|
||||
string name = ReadString(stream);
|
||||
int pos = ReadInt(stream);
|
||||
@@ -41,9 +41,9 @@ namespace PckStudio.Classes.IO.ARC
|
||||
{
|
||||
long originalPOS = stream.Position;
|
||||
if (stream.Seek(position, SeekOrigin.Begin) != position) throw new Exception();
|
||||
byte[] bytes = ReadBytes(stream, size);
|
||||
byte[] data = ReadBytes(stream, size);
|
||||
if (stream.Seek(originalPOS, SeekOrigin.Begin) != originalPOS) throw new Exception();
|
||||
return bytes;
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace PckStudio.Classes.IO.ARC
|
||||
private void WriteToStream(Stream stream)
|
||||
{
|
||||
WriteInt(stream, _archive.Count);
|
||||
int currentOffset = 4 + _archive.Keys.ToArray().Sum(key => 10 + key.Length);
|
||||
int currentOffset = 4 + _archive.Keys.Sum(key => 10 + key.Length);
|
||||
foreach (var pair in _archive)
|
||||
{
|
||||
int size = pair.Value.Length;
|
||||
@@ -40,10 +40,10 @@ namespace PckStudio.Classes.IO.ARC
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteString(Stream stream, string String)
|
||||
private void WriteString(Stream stream, string s)
|
||||
{
|
||||
WriteShort(stream, (short)String.Length);
|
||||
WriteString(stream, String, Encoding.UTF8);
|
||||
WriteShort(stream, (short)s.Length);
|
||||
WriteString(stream, s, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
using PckStudio.Classes.Utils;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PckStudio.Classes.IO.GRF
|
||||
{
|
||||
@@ -85,7 +86,7 @@ namespace PckStudio.Classes.IO.GRF
|
||||
{
|
||||
ReadStringLookUpTable(stream);
|
||||
string Name = GetString(stream);
|
||||
Console.WriteLine($"[{nameof(GRFFile)}] Root Name: {Name}");
|
||||
Debug.WriteLine("[{0}] Root Name: {1}", nameof(GRFFile), Name);
|
||||
ReadGameRuleHierarchy(stream, _file.Root);
|
||||
}
|
||||
|
||||
@@ -103,9 +104,9 @@ namespace PckStudio.Classes.IO.GRF
|
||||
|
||||
private void ReadStringLookUpTable(Stream stream)
|
||||
{
|
||||
int name_count = ReadInt(stream);
|
||||
StringLookUpTable = new List<string>(name_count);
|
||||
for (int i = 0; i < name_count; i++)
|
||||
int tableSize = ReadInt(stream);
|
||||
StringLookUpTable = new List<string>(tableSize);
|
||||
for (int i = 0; i < tableSize; i++)
|
||||
{
|
||||
string s = ReadString(stream);
|
||||
StringLookUpTable.Add(s);
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace PckStudio.Classes.IO.LOC
|
||||
|
||||
private void WriteLanguages(Stream stream, int type)
|
||||
{
|
||||
_locfile.Languages.ForEach(language =>
|
||||
foreach(var language in _locfile.Languages)
|
||||
{
|
||||
WriteString(stream, language);
|
||||
|
||||
@@ -58,12 +58,12 @@ namespace PckStudio.Classes.IO.LOC
|
||||
}
|
||||
|
||||
WriteInt(stream, size);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private void WriteLanguageEntries(Stream stream, int type)
|
||||
{
|
||||
_locfile.Languages.ForEach(language =>
|
||||
foreach (var language in _locfile.Languages)
|
||||
{
|
||||
WriteInt(stream, 0x6D696B75); // :P
|
||||
stream.WriteByte(0); // <- only write when the previous written int was >0
|
||||
@@ -75,7 +75,7 @@ namespace PckStudio.Classes.IO.LOC
|
||||
if (type == 0) WriteString(stream, locKey);
|
||||
WriteString(stream, _locfile.LocKeys[locKey][language]);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private void WriteString(Stream stream, string s)
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace PckStudio.Classes.IO
|
||||
private PCKFile _file;
|
||||
private List<string> LUT;
|
||||
|
||||
|
||||
public static PCKFile Read(Stream stream, bool isLittleEndian)
|
||||
{
|
||||
return new PCKFileReader(isLittleEndian).ReadFromStream(stream);
|
||||
@@ -24,7 +23,7 @@ namespace PckStudio.Classes.IO
|
||||
private PCKFile ReadFromStream(Stream stream)
|
||||
{
|
||||
int pck_type = ReadInt(stream);
|
||||
if (pck_type > 0xf00000) // 03 00 00 00 == true
|
||||
if (pck_type > 0xf0_00_00) // 03 00 00 00 == true
|
||||
throw new OverflowException(nameof(pck_type));
|
||||
_file = new PCKFile(pck_type);
|
||||
ReadLookUpTable(stream);
|
||||
@@ -62,7 +61,8 @@ namespace PckStudio.Classes.IO
|
||||
|
||||
private void ReadFileContents(Stream stream)
|
||||
{
|
||||
_file.Files.ForEach( file => {
|
||||
foreach (var file in _file.Files)
|
||||
{
|
||||
int property_count = ReadInt(stream);
|
||||
for (; 0 < property_count; property_count--)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ namespace PckStudio.Classes.IO
|
||||
file.properties.Add((key, value));
|
||||
}
|
||||
stream.Read(file.data, 0, file.size);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private string ReadString(Stream stream)
|
||||
|
||||
@@ -42,11 +42,11 @@ namespace PckStudio.Classes.IO
|
||||
private void WriteLookUpTable(Stream stream)
|
||||
{
|
||||
WriteInt(stream, LUT.Count);
|
||||
LUT.ForEach(entry =>
|
||||
for(int i = 0; i < LUT.Count; i++)
|
||||
{
|
||||
WriteInt(stream, LUT.IndexOf(entry));
|
||||
WriteString(stream, entry);
|
||||
});
|
||||
WriteInt(stream, i);
|
||||
WriteString(stream, LUT[i]);
|
||||
};
|
||||
if (LUT.Contains("XMLVERSION"))
|
||||
WriteInt(stream, 0x1337); // :^)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user