update
This commit is contained in:
parent
3adf8c207a
commit
ea52c2128b
@ -170,7 +170,7 @@ namespace EscudeTools
|
||||
// Add columns to the create table query
|
||||
foreach (var column in sheet.col)
|
||||
{
|
||||
createTableQuery.Append($"{column.name} {Utils.GetSQLiteColumnType(column.type, column.size)}, ");
|
||||
createTableQuery.Append($"{column.name} {Utils.GetSQLiteColumnType(column.type)}, ");
|
||||
}
|
||||
|
||||
createTableQuery.Remove(createTableQuery.Length - 2, 2); // Remove the last comma and space
|
||||
|
@ -114,9 +114,8 @@ namespace EscudeTools
|
||||
{
|
||||
static readonly byte[] lsfFileSignature = [0x4C, 0x53, 0x46, 0x00];
|
||||
static readonly byte[] lsfLayerSkipSignature = [0x00, 0x75, 0x6C, 0x00]; //flowchat部分的lsf块
|
||||
private static string WorkPath = string.Empty;
|
||||
private LsfData lsfData = new();
|
||||
private Dictionary<string, LsfData> lsfDataLookup = new();
|
||||
private Dictionary<string, LsfData> lsfDataLookup = [];
|
||||
|
||||
private bool preFetchInfo;
|
||||
|
||||
@ -158,7 +157,7 @@ namespace EscudeTools
|
||||
return lsfData; // 如果未找到,则返回 null
|
||||
}
|
||||
|
||||
private LsfFileHeader LoadLsfHeader(string path)
|
||||
private static LsfFileHeader LoadLsfHeader(string path)
|
||||
{
|
||||
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
if (fs.Length < 0x1C)
|
||||
|
@ -226,7 +226,7 @@ namespace EscudeTools
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LzwDecode(List<LzwEntry> lzwManifest, string output)
|
||||
private static void LzwDecode(List<LzwEntry> lzwManifest, string output)
|
||||
{
|
||||
foreach (var i in lzwManifest)
|
||||
{
|
||||
@ -244,19 +244,13 @@ namespace EscudeTools
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class LzwDecoder : IDisposable
|
||||
internal sealed class LzwDecoder(Stream input, int unpacked_size) : IDisposable
|
||||
{
|
||||
private MsbBitStream m_input;
|
||||
private byte[] m_output;
|
||||
private MsbBitStream m_input = new(input, true);
|
||||
private byte[] m_output = new byte[unpacked_size];
|
||||
|
||||
public byte[] Output { get { return m_output; } }
|
||||
|
||||
public LzwDecoder(Stream input, int unpacked_size)
|
||||
{
|
||||
m_input = new MsbBitStream(input, true);
|
||||
m_output = new byte[unpacked_size];
|
||||
}
|
||||
|
||||
public void Unpack()
|
||||
{
|
||||
int dst = 0;
|
||||
@ -320,9 +314,9 @@ namespace EscudeTools
|
||||
#endregion
|
||||
}
|
||||
|
||||
public bool Repack(string path, int version, bool useCustomKey = false, string customKeyProviderPath = "") //目前支持v2v1
|
||||
public bool Repack(string path, int version, string customKeyProviderPath = "") //目前支持v2v1
|
||||
{
|
||||
if (useCustomKey)
|
||||
if (customKeyProviderPath!="")
|
||||
LoadKey(customKeyProviderPath);
|
||||
ReadPItem(path);
|
||||
List<LzwEntry> lzwManifest = [];
|
||||
@ -330,78 +324,76 @@ namespace EscudeTools
|
||||
lzwManifest = JsonSerializer.Deserialize<List<LzwEntry>>(File.ReadAllText(Path.Combine(path, "lzwManifest.json"))) ?? [];
|
||||
m_seed = isLoaded ? LoadedKey : 2210579460;
|
||||
string outputPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileName(path) + ".bin");
|
||||
using (FileStream fs = new(outputPath, FileMode.Create))
|
||||
using (BinaryWriter bw = new(fs))
|
||||
using FileStream fs = new(outputPath, FileMode.Create);
|
||||
using BinaryWriter bw = new(fs);
|
||||
bw.Write(fileSignature);
|
||||
bw.Write(supportPackVersion[version - 1]);
|
||||
bw.Write(m_seed);
|
||||
m_count = (uint)pItem.Count;
|
||||
bw.Write(m_count ^ NextKey());
|
||||
EncodingProvider provider = CodePagesEncodingProvider.Instance;
|
||||
Encoding? shiftJis = provider.GetEncoding("shift-jis");
|
||||
if (version == 1) //未经测试
|
||||
{
|
||||
bw.Write(fileSignature);
|
||||
bw.Write(supportPackVersion[version - 1]);
|
||||
bw.Write(m_seed);
|
||||
m_count = (uint)pItem.Count;
|
||||
bw.Write(m_count ^ NextKey());
|
||||
EncodingProvider provider = CodePagesEncodingProvider.Instance;
|
||||
Encoding? shiftJis = provider.GetEncoding("shift-jis");
|
||||
if (version == 1) //未经测试
|
||||
long storeOffset = 0x10 + m_count * 0x88;
|
||||
for (int i = 0; i < m_count; i++)
|
||||
{
|
||||
long storeOffset = 0x10 + m_count * 0x88;
|
||||
for (int i = 0; i < m_count; i++)
|
||||
{
|
||||
byte[] strbytes = shiftJis.GetBytes(pItem[i].Name);
|
||||
byte[] result = new byte[80];
|
||||
int lengthToCopy = Math.Min(strbytes.Length, 78);
|
||||
Array.Copy(strbytes, result, lengthToCopy);
|
||||
bw.Write(result);
|
||||
bw.Write(storeOffset);
|
||||
uint size = pItem[i].Size;
|
||||
if (Utils.searchLzwEntryList(lzwManifest, pItem[i].Name) != -1)
|
||||
size = (uint)FakeCompress(File.ReadAllBytes(Path.Combine(path, pItem[i].Name))).Length;
|
||||
bw.Write(size);
|
||||
storeOffset += size;
|
||||
byte[] strbytes = shiftJis.GetBytes(pItem[i].Name);
|
||||
byte[] result = new byte[80];
|
||||
int lengthToCopy = Math.Min(strbytes.Length, 78);
|
||||
Array.Copy(strbytes, result, lengthToCopy);
|
||||
bw.Write(result);
|
||||
bw.Write(storeOffset);
|
||||
uint size = pItem[i].Size;
|
||||
if (Utils.SearchLzwEntryList(lzwManifest, pItem[i].Name) != -1)
|
||||
size = (uint)FakeCompress(File.ReadAllBytes(Path.Combine(path, pItem[i].Name))).Length;
|
||||
bw.Write(size);
|
||||
storeOffset += size;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
uint namesSize = (uint)pItem.Sum(e => e.Name.Length + 1);
|
||||
bw.Write(namesSize ^ NextKey());
|
||||
uint filenameOffset = 0;
|
||||
long storeOffset = 0x14 + m_count * 12 + namesSize;
|
||||
byte[] index = new byte[m_count * 12];
|
||||
int indexOffset = 0;
|
||||
for (int i = 0; i < m_count; i++)
|
||||
{
|
||||
uint namesSize = (uint)pItem.Sum(e => e.Name.Length + 1);
|
||||
bw.Write(namesSize ^ NextKey());
|
||||
uint filenameOffset = 0;
|
||||
long storeOffset = 0x14 + m_count * 12 + namesSize;
|
||||
byte[] index = new byte[m_count * 12];
|
||||
int indexOffset = 0;
|
||||
for (int i = 0; i < m_count; i++)
|
||||
{
|
||||
BitConverter.GetBytes(filenameOffset).CopyTo(index, indexOffset);
|
||||
indexOffset += 4;
|
||||
BitConverter.GetBytes(storeOffset).CopyTo(index, indexOffset);
|
||||
indexOffset += 4;
|
||||
uint size = pItem[i].Size;
|
||||
if (Utils.searchLzwEntryList(lzwManifest, pItem[i].Name) != -1)
|
||||
size = (uint)FakeCompress(File.ReadAllBytes(Path.Combine(path, pItem[i].Name))).Length;
|
||||
BitConverter.GetBytes(size).CopyTo(index, indexOffset);
|
||||
indexOffset += 4;
|
||||
filenameOffset += (uint)pItem[i].Name.Length + 1;
|
||||
storeOffset += size;
|
||||
}
|
||||
Decrypt(ref index);
|
||||
bw.Write(index);
|
||||
|
||||
foreach (Entry entry in pItem)
|
||||
{
|
||||
byte[] nameBytes = shiftJis.GetBytes(entry.Name);
|
||||
bw.Write(nameBytes);
|
||||
bw.Write((byte)0);
|
||||
}
|
||||
BitConverter.GetBytes(filenameOffset).CopyTo(index, indexOffset);
|
||||
indexOffset += 4;
|
||||
BitConverter.GetBytes(storeOffset).CopyTo(index, indexOffset);
|
||||
indexOffset += 4;
|
||||
uint size = pItem[i].Size;
|
||||
if (Utils.SearchLzwEntryList(lzwManifest, pItem[i].Name) != -1)
|
||||
size = (uint)FakeCompress(File.ReadAllBytes(Path.Combine(path, pItem[i].Name))).Length;
|
||||
BitConverter.GetBytes(size).CopyTo(index, indexOffset);
|
||||
indexOffset += 4;
|
||||
filenameOffset += (uint)pItem[i].Name.Length + 1;
|
||||
storeOffset += size;
|
||||
}
|
||||
Decrypt(ref index);
|
||||
bw.Write(index);
|
||||
|
||||
foreach (Entry entry in pItem)
|
||||
{
|
||||
byte[] data;
|
||||
if (Utils.searchLzwEntryList(lzwManifest, entry.Name) != -1)
|
||||
data = FakeCompress(File.ReadAllBytes(Path.Combine(path, entry.Name)));
|
||||
else
|
||||
data = File.ReadAllBytes(Path.Combine(path, entry.Name));
|
||||
|
||||
bw.Write(data);
|
||||
byte[] nameBytes = shiftJis.GetBytes(entry.Name);
|
||||
bw.Write(nameBytes);
|
||||
bw.Write((byte)0);
|
||||
}
|
||||
}
|
||||
foreach (Entry entry in pItem)
|
||||
{
|
||||
byte[] data;
|
||||
if (Utils.SearchLzwEntryList(lzwManifest, entry.Name) != -1)
|
||||
data = FakeCompress(File.ReadAllBytes(Path.Combine(path, entry.Name)));
|
||||
else
|
||||
data = File.ReadAllBytes(Path.Combine(path, entry.Name));
|
||||
|
||||
bw.Write(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -437,29 +429,27 @@ namespace EscudeTools
|
||||
//不压其实也没事
|
||||
public static byte[] FakeCompress(byte[] Data)
|
||||
{
|
||||
using (MemoryStream Stream = new())
|
||||
{
|
||||
byte[] Buffer = new byte[4];
|
||||
((uint)Utils.Reverse((uint)Data.Length)).WriteTo(Buffer, 0);
|
||||
Stream.WriteCString("acp");
|
||||
Stream.Write(Buffer, 0, Buffer.Length);
|
||||
using MemoryStream Stream = new();
|
||||
byte[] Buffer = new byte[4];
|
||||
((uint)Utils.Reverse((uint)Data.Length)).WriteTo(Buffer, 0);
|
||||
Stream.WriteCString("acp");
|
||||
Stream.Write(Buffer, 0, Buffer.Length);
|
||||
|
||||
BitWriter Writer = new(Stream);
|
||||
for (int i = 0; i < Data.Length; i++)
|
||||
BitWriter Writer = new(Stream);
|
||||
for (int i = 0; i < Data.Length; i++)
|
||||
{
|
||||
if (i > 0 && (i % 0x4000) == 0)
|
||||
{
|
||||
if (i > 0 && (i % 0x4000) == 0)
|
||||
{
|
||||
Writer.PutBit(true);
|
||||
Writer.PutBits(2);
|
||||
}
|
||||
Writer.PutBit(false);
|
||||
Writer.PutBits(Data[i]);
|
||||
Writer.PutBit(true);
|
||||
Writer.PutBits(2);
|
||||
}
|
||||
Writer.PutBit(true);
|
||||
Writer.PutBits(0);
|
||||
Writer.Flush();
|
||||
return Stream.ToArray();
|
||||
Writer.PutBit(false);
|
||||
Writer.PutBits(Data[i]);
|
||||
}
|
||||
Writer.PutBit(true);
|
||||
Writer.PutBits(0);
|
||||
Writer.Flush();
|
||||
return Stream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -105,7 +105,7 @@ namespace EscudeTools
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
|
||||
public static string GetSQLiteColumnType(ushort type, uint size)
|
||||
public static string GetSQLiteColumnType(ushort type)
|
||||
{
|
||||
if (type == 1)
|
||||
return "INTEGER";
|
||||
@ -197,37 +197,26 @@ namespace EscudeTools
|
||||
byte[] Arr = BitConverter.GetBytes(Data);
|
||||
Array.Reverse(Arr, 0, Arr.Length);
|
||||
string type = Data.GetType().FullName;
|
||||
switch (type)
|
||||
return type switch
|
||||
{
|
||||
case Const.INT8:
|
||||
case Const.UINT8:
|
||||
return Data;
|
||||
case Const.INT16:
|
||||
return BitConverter.ToInt16(Arr, 0);
|
||||
case Const.UINT16:
|
||||
return BitConverter.ToUInt16(Arr, 0);
|
||||
case Const.INT32:
|
||||
return BitConverter.ToInt32(Arr, 0);
|
||||
case Const.UINT32:
|
||||
return BitConverter.ToUInt32(Arr, 0);
|
||||
case Const.INT64:
|
||||
return BitConverter.ToInt64(Arr, 0);
|
||||
case Const.UINT64:
|
||||
return BitConverter.ToUInt64(Arr, 0);
|
||||
case Const.DOUBLE:
|
||||
return BitConverter.ToDouble(Arr, 0);
|
||||
case Const.FLOAT:
|
||||
return BitConverter.ToSingle(Arr, 0);
|
||||
default:
|
||||
throw new Exception("Unk Data Type.");
|
||||
}
|
||||
Const.INT8 or Const.UINT8 => Data,
|
||||
Const.INT16 => BitConverter.ToInt16(Arr, 0),
|
||||
Const.UINT16 => BitConverter.ToUInt16(Arr, 0),
|
||||
Const.INT32 => BitConverter.ToInt32(Arr, 0),
|
||||
Const.UINT32 => BitConverter.ToUInt32(Arr, 0),
|
||||
Const.INT64 => BitConverter.ToInt64(Arr, 0),
|
||||
Const.UINT64 => BitConverter.ToUInt64(Arr, 0),
|
||||
Const.DOUBLE => BitConverter.ToDouble(Arr, 0),
|
||||
Const.FLOAT => BitConverter.ToSingle(Arr, 0),
|
||||
_ => throw new Exception("Unk Data Type."),
|
||||
};
|
||||
}
|
||||
public static void WriteTo(uint Value, byte[] Binary, uint At)
|
||||
{
|
||||
BitConverter.GetBytes(Value).CopyTo(Binary, At);
|
||||
}
|
||||
|
||||
public static int searchLzwEntryList(List<LzwEntry> lle, string keyword)
|
||||
public static int SearchLzwEntryList(List<LzwEntry> lle, string keyword)
|
||||
{
|
||||
foreach (LzwEntry le in lle)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user