解析&导出功能优化

This commit is contained in:
Chenx221 2024-10-16 01:42:42 +08:00
parent 767fce3dd9
commit cd926e361e
422 changed files with 104 additions and 86 deletions

View File

@ -146,6 +146,8 @@ namespace EscudeTools
public static string SetCommandStr(Command c, ScriptFile sf, ScriptMessage sm, ref int messIndex) public static string SetCommandStr(Command c, ScriptFile sf, ScriptMessage sm, ref int messIndex)
{ {
//__cdecl //__cdecl
//todo
//可考虑对pop进行进一步处理
switch (c.Instruction) switch (c.Instruction)
{ {
case INST_POP: case INST_POP:
@ -161,7 +163,7 @@ namespace EscudeTools
case INST_PUSH_RET: case INST_PUSH_RET:
return $"Push the return value"; return $"Push the return value";
case INST_PUSH_TEXT: case INST_PUSH_TEXT:
return $"Push a string: {sf.TextString[(uint)c.Parameter[0]]}"; return $"Push a string: {sf.TextString[(uint)c.Parameter]}";
case INST_PUSH_MESS: case INST_PUSH_MESS:
{ {
messIndex++; messIndex++;
@ -184,7 +186,7 @@ namespace EscudeTools
case INST_JMPZ: case INST_JMPZ:
return $"Conditional jump"; return $"Conditional jump";
case INST_CALL: case INST_CALL:
return $"Call function offset: {(uint)c.Parameter[0] + 1}"; return $"Call function offset: {(uint)c.Parameter + 1}";
case INST_RET: case INST_RET:
return $"Return"; return $"Return";
case INST_LOG_OR: case INST_LOG_OR:
@ -238,7 +240,7 @@ namespace EscudeTools
case INST_LINE: case INST_LINE:
return $"File line number"; return $"File line number";
case INST_PROC: case INST_PROC:
uint index = (uint)c.Parameter[0]; uint index = (uint)c.Parameter;
return $"Execute built-in function: {ProcNames[index]} {SetExtStr(c, sf)}"; return $"Execute built-in function: {ProcNames[index]} {SetExtStr(c, sf)}";
case INST_TEXT: case INST_TEXT:
messIndex++; messIndex++;
@ -250,7 +252,7 @@ namespace EscudeTools
private static string SetExtStr(Command c, ScriptFile sf) private static string SetExtStr(Command c, ScriptFile sf)
{ {
switch ((uint)c.Parameter[0]) switch ((uint)c.Parameter)
{ {
case 0: case 0:
{ {

View File

@ -4,10 +4,50 @@
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
ScriptManager smr = new(); if (Directory.Exists(args[0]))
smr.LoadScriptFile(args[0]); //加载.bin文件 {
smr.ExportDatabase(Path.GetDirectoryName(args[0])); string[] files = Directory.GetFiles(args[0], "*.bin");
return; foreach (string file in files)
{
ScriptManager smr = new();
//目前不支持二次加载
//Todo
//修复
if (smr.LoadScriptFile(file))
{
Console.WriteLine($"Load {file} Success");
}
else
{
Console.WriteLine($"Load {file} Failed");
return;
}
if (smr.ExportDatabase(Path.GetDirectoryName(args[0])))
Console.WriteLine("Export Database Success");
else
{
Console.WriteLine("Export Database Failed");
return;
}
if (smr.ExportMessDatabase(Path.GetDirectoryName(args[0])))
Console.WriteLine("Export Mess Database Success");
else
{
Console.WriteLine("Export Mess Database Failed");
return;
}
}
}
//ScriptManager smr = new();
//smr.LoadScriptFile(args[0]); //加载.bin文件
//smr.ExportDatabase(Path.GetDirectoryName(args[0]));
//smr.ExportMessDatabase(Path.GetDirectoryName(args[0]));
//return;
//if (Directory.Exists(args[0])) //if (Directory.Exists(args[0]))

View File

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

View File

@ -34,7 +34,7 @@ namespace EscudeTools
public uint Offset { get; set; } public uint Offset { get; set; }
public byte Instruction { get; set; } public byte Instruction { get; set; }
public string InstructionString { get; set; } public string InstructionString { get; set; }
public List<Object> Parameter { get; set; } public Object Parameter { get; set; }
public String Helper { get; set; } public String Helper { get; set; }
public bool IsProcSet { get; set; } public bool IsProcSet { get; set; }
} }
@ -70,7 +70,10 @@ namespace EscudeTools
{ {
if (!File.Exists(path)) if (!File.Exists(path))
return false; return false;
sf ??= new ScriptFile(); sf = new ScriptFile();
smEncrypted = false;
name = string.Empty;
messIndex = 0;
name = Path.GetFileNameWithoutExtension(path); name = Path.GetFileNameWithoutExtension(path);
using FileStream fs = new(path, FileMode.Open); using FileStream fs = new(path, FileMode.Open);
using BinaryReader br = new(fs); using BinaryReader br = new(fs);
@ -106,7 +109,6 @@ namespace EscudeTools
{ {
Command c = new() Command c = new()
{ {
Parameter = [],
Instruction = sf.Code[i++], Instruction = sf.Code[i++],
Offset = (uint)i, Offset = (uint)i,
IsProcSet = false IsProcSet = false
@ -116,7 +118,7 @@ namespace EscudeTools
c.InstructionString = Define.GetInstructionString(c.Instruction, out int paramNum); c.InstructionString = Define.GetInstructionString(c.Instruction, out int paramNum);
for (int j = 0; j < paramNum; j++) for (int j = 0; j < paramNum; j++)
{ {
c.Parameter.Add(Define.TyperHelper(c.Instruction, sf.Code, i)); c.Parameter = Define.TyperHelper(c.Instruction, sf.Code, i);
i += 4; i += 4;
} }
if (sm != null) if (sm != null)
@ -139,7 +141,7 @@ namespace EscudeTools
{ {
if (!File.Exists(path)) if (!File.Exists(path))
return false; return false;
sm ??= new ScriptMessage(); sm = new ScriptMessage();
using FileStream fs = new(path, FileMode.Open); using FileStream fs = new(path, FileMode.Open);
using BinaryReader br = new(fs); using BinaryReader br = new(fs);
byte[] head = br.ReadBytes(8); byte[] head = br.ReadBytes(8);
@ -245,16 +247,17 @@ namespace EscudeTools
public bool ExportMessDatabase(string? storePath) public bool ExportMessDatabase(string? storePath)
{ {
if (sm.Data == null) if (sf == null)
return false; return false;
if (sm == null)
return true;
storePath ??= Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new InvalidOperationException("Unable to determine the directory."); //导出位置 storePath ??= Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new InvalidOperationException("Unable to determine the directory."); //导出位置
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
return false; return false;
string targetPath = Path.Combine(storePath, name + "script_sm.db"); string targetPath = Path.Combine(storePath, "script_sm.db");
if (!File.Exists(targetPath)) if (!File.Exists(targetPath))
ExtractEmbeddedDatabase(targetPath); ExtractEmbeddedDatabase(targetPath);
//return SqliteProcess(sm, targetPath); return SqliteProcess(sm, targetPath);
throw new NotImplementedException();
} }
private bool SqliteProcess(ScriptFile sf, string path) private bool SqliteProcess(ScriptFile sf, string path)
@ -268,7 +271,7 @@ namespace EscudeTools
{ {
var result = checkTableCmd.ExecuteScalar(); var result = checkTableCmd.ExecuteScalar();
if (result != null) if (result != null)
return false; return true;
} }
string createTableQuery = $@" string createTableQuery = $@"
@ -276,6 +279,7 @@ namespace EscudeTools
Offset INTEGER, Offset INTEGER,
Instruction INTEGER, Instruction INTEGER,
InstructionString TEXT, InstructionString TEXT,
Parameter TEXT,
Helper TEXT Helper TEXT
);"; );";
@ -284,88 +288,60 @@ namespace EscudeTools
createTableCmd.ExecuteNonQuery(); createTableCmd.ExecuteNonQuery();
} }
string insertQuery = $"INSERT INTO {name} (Offset, Instruction, InstructionString, Helper) VALUES (@Offset, @Instruction, @InstructionString, @Helper);"; string insertQuery = $"INSERT INTO {name} (Offset, Instruction, InstructionString,Parameter, Helper) VALUES (@Offset, @Instruction, @InstructionString,@Parameter, @Helper);";
using (var insertCmd = new SqliteCommand(insertQuery, connection)) using var insertCmd = new SqliteCommand(insertQuery, connection);
foreach (var command in sf.Commands)
{ {
foreach (var command in sf.Commands) insertCmd.Parameters.Clear();
{ insertCmd.Parameters.AddWithValue("@Offset", command.Offset);
insertCmd.Parameters.Clear(); insertCmd.Parameters.AddWithValue("@Instruction", command.Instruction);
insertCmd.Parameters.AddWithValue("@Offset", command.Offset); insertCmd.Parameters.AddWithValue("@InstructionString", command.InstructionString);
insertCmd.Parameters.AddWithValue("@Instruction", command.Instruction); insertCmd.Parameters.AddWithValue("@Parameter", command.Parameter == null ? "" : command.Parameter.ToString());
insertCmd.Parameters.AddWithValue("@InstructionString", command.InstructionString); insertCmd.Parameters.AddWithValue("@Helper", command.Helper ?? "");
insertCmd.Parameters.AddWithValue("@Helper", command.Helper);
insertCmd.ExecuteNonQuery(); insertCmd.ExecuteNonQuery();
}
} }
return true; return true;
} }
//下面的没法用 private bool SqliteProcess(ScriptMessage sm, string path)
//private bool SqliteProcess(ScriptMessage sm, string path) {
//{ using SqliteConnection connection = new($"Data Source={path};");
// using SqliteConnection connection = new($"Data Source={path};"); connection.Open();
// connection.Open();
// using (SqliteCommand createTableCommand = connection.CreateCommand()) string checkTableExistsQuery = $"SELECT name FROM sqlite_master WHERE type='table' AND name='{name}';";
// {
// StringBuilder createTableQuery = new();
// createTableQuery.Append($"CREATE TABLE IF NOT EXISTS {smName} (");
// // Add columns to the create table query using (var checkTableCmd = new SqliteCommand(checkTableExistsQuery, connection))
// foreach (var column in sheet.col) {
// { var result = checkTableCmd.ExecuteScalar();
// createTableQuery.Append($"{column.name} {GetSQLiteColumnType(column.type)}, "); if (result != null)
// } return true;
}
// createTableQuery.Remove(createTableQuery.Length - 2, 2); // Remove the last comma and space string createTableQuery = $@"
// createTableQuery.Append(");"); CREATE TABLE {name} (
DataString TEXT
);";
// createTableCommand.CommandText = createTableQuery.ToString(); using (var createTableCmd = new SqliteCommand(createTableQuery, connection))
// createTableCommand.ExecuteNonQuery(); {
// } createTableCmd.ExecuteNonQuery();
}
// using SqliteCommand insertDataCommand = connection.CreateCommand(); string insertQuery = $"INSERT INTO {name} (DataString) VALUES (@DataString);";
// StringBuilder insertDataQuery = new();
// insertDataQuery.Append($"INSERT INTO {sheet.name} (");
// // Add column names to the insert data query using var insertCmd = new SqliteCommand(insertQuery, connection);
// foreach (var column in sheet.col) foreach (var ds in sm.DataString)
// { {
// insertDataQuery.Append($"{column.name}, "); insertCmd.Parameters.Clear();
// } insertCmd.Parameters.AddWithValue("@DataString", ds ?? "");
insertCmd.ExecuteNonQuery();
}
// insertDataQuery.Remove(insertDataQuery.Length - 2, 2); // Remove the last comma and space return true;
// insertDataQuery.Append(") VALUES ("); }
// // Add parameter placeholders to the insert data query
// for (int i = 0; i < sheet.cols; i++)
// {
// insertDataQuery.Append($"@param{i}, ");
// }
// insertDataQuery.Remove(insertDataQuery.Length - 2, 2); // Remove the last comma and space
// insertDataQuery.Append(");");
// insertDataCommand.CommandText = insertDataQuery.ToString();
// // Add data parameters to the insert data command
// for (int i = 0; i < sheet.records.values.Length; i++)
// {
// var record = (Record)sheet.records.values[i];
// for (int j = 0; j < sheet.cols; j++)
// {
// var parameter = new SqliteParameter($"@param{j}", record.values[j]);
// insertDataCommand.Parameters.Add(parameter);
// }
// insertDataCommand.ExecuteNonQuery();
// insertDataCommand.Parameters.Clear();
// }
// return true;
//}
private static string GetSQLiteColumnType(ushort type) private static string GetSQLiteColumnType(ushort type)
{ {

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More