初步支持读取Script

不支持导出,sf中Data暂不支持解析
This commit is contained in:
Chenx221 2024-10-14 23:10:48 +08:00
parent ec42590b0e
commit 71e99f86d4
3 changed files with 61 additions and 28 deletions

View File

@ -4,33 +4,40 @@
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
if (Directory.Exists(args[0])) ScriptManager smr = new();
{ smr.LoadScriptFile(args[0]);
string[] files = Directory.GetFiles(args[0], "db_*.bin"); if(args.Length == 2)
DatabaseManager dm = new(); smr.LoadScriptMess(args[1]);
foreach (string file in files) return;
{
if (dm.LoadDatabase(file))
{
Console.WriteLine($"Load {file} Success");
}
else
{
Console.WriteLine($"Load {file} Failed");
return;
}
if (dm.ExportDatabase(0, Path.GetDirectoryName(args[0])))
Console.WriteLine("Export Database Success");
else
{
Console.WriteLine("Export Database Failed");
return;
}
} //if (Directory.Exists(args[0]))
//{
// string[] files = Directory.GetFiles(args[0], "db_*.bin");
// DatabaseManager dm = new();
// foreach (string file in files)
// {
// if (dm.LoadDatabase(file))
// {
// Console.WriteLine($"Load {file} Success");
// }
// else
// {
// Console.WriteLine($"Load {file} Failed");
// return;
// }
} // if (dm.ExportDatabase(0, Path.GetDirectoryName(args[0])))
// Console.WriteLine("Export Database Success");
// else
// {
// Console.WriteLine("Export Database Failed");
// return;
// }
// }
//}
// if (args.Length == 0 || args.Length > 2) // if (args.Length == 0 || args.Length > 2)

View File

@ -2,7 +2,7 @@
"profiles": { "profiles": {
"EscudeTools": { "EscudeTools": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "G:\\x221.local\\lab\\db" "commandLineArgs": "G:\\x221.local\\lab\\a_prologue_01.bin \r\nG:\\x221.local\\lab\\a_prologue_01.001"
} }
} }
} }

View File

@ -7,10 +7,11 @@ namespace EscudeTools
{ {
public class ScriptMessage public class ScriptMessage
{ {
public byte[] Data { get; set; } // MESS領域 (消息区域) public byte[] Data { get; set; } // MESS領域 (消息区域) //这个还不知道怎么解析成人能看懂的
public uint Size { get; set; } // MESS領域サイズ (消息区域大小) public uint Size { get; set; } // MESS領域サイズ (消息区域大小)
public List<uint> Offset { get; set; } // MESSオフセット (消息偏移) public List<uint> Offset { get; set; } // MESSオフセット (消息偏移)
public uint Count { get; set; } // MESS数 (消息数量) public uint Count { get; set; } // MESS数 (消息数量)
public string[] DataString { get; set; } // 给人看的Data内容
} }
public class ScriptFile public class ScriptFile
@ -24,6 +25,7 @@ namespace EscudeTools
public uint TextCount { get; set; } // TEXT数 (文本数量) public uint TextCount { get; set; } // TEXT数 (文本数量)
public uint MessCount { get; set; } // MESS数 (消息数量) public uint MessCount { get; set; } // MESS数 (消息数量)
public string[] TextString { get; set; } // 给人看的Text内容
} }
public class ScriptManager public class ScriptManager
@ -72,6 +74,11 @@ namespace EscudeTools
sf.TextOffset[i] = br.ReadUInt32(); sf.TextOffset[i] = br.ReadUInt32();
} }
sf.Text = br.ReadBytes((int)sf.TextSize); sf.Text = br.ReadBytes((int)sf.TextSize);
sf.TextString = new string[sf.TextCount];
for (int i = 0; i < sf.TextCount; i++)
{
sf.TextString[i] = ReadStringFromTextData(sf.Text, (int)sf.TextOffset[i]);
}
return true; return true;
} }
@ -103,7 +110,7 @@ namespace EscudeTools
sm.Offset.Add(br.ReadUInt32()); sm.Offset.Add(br.ReadUInt32());
} }
byte[] encryptData = br.ReadBytes((int)sm.Size); byte[] encryptData = br.ReadBytes((int)sm.Size);
for (int i = 0; i <= encryptData.Length; i++) for (int i = 0; i < encryptData.Length; i++)
{ {
encryptData[i] ^= 0x55; encryptData[i] ^= 0x55;
} }
@ -147,6 +154,11 @@ namespace EscudeTools
} }
} }
} }
sm.DataString = new string[sm.Count];
for (int i = 0; i < sm.Count; i++)
{
sm.DataString[i] = ReadStringFromTextData(sm.Data, (int)sm.Offset[i]);
}
return true; return true;
} }
@ -341,5 +353,19 @@ namespace EscudeTools
}; };
throw new NotImplementedException(); throw new NotImplementedException();
} }
private static string ReadStringFromTextData(byte[] sheet_text, int offset)
{
List<byte> stringBytes = [];
for (int i = offset; i < sheet_text.Length && sheet_text[i] != 0x00; i++)
{
stringBytes.Add(sheet_text[i]);
}
EncodingProvider provider = CodePagesEncodingProvider.Instance;
Encoding? shiftJis = provider.GetEncoding("shift-jis");
return shiftJis == null
? throw new InvalidOperationException("Shift-JIS encoding not supported.")
: shiftJis.GetString(stringBytes.ToArray());
}
} }
} }