Compare commits

..

No commits in common. "6d8cb84ab4aa099962f9a4842efe749c2c26e371" and "22ca8d0b34207f2470e5608487fcdf5966bc52f9" have entirely different histories.

6 changed files with 50 additions and 208 deletions

View File

@ -1,7 +1,6 @@
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Xml.Linq;
namespace EscudeTools namespace EscudeTools
{ {
@ -170,7 +169,7 @@ namespace EscudeTools
// Add columns to the create table query // Add columns to the create table query
foreach (var column in sheet.col) 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 createTableQuery.Remove(createTableQuery.Length - 2, 2); // Remove the last comma and space
@ -178,7 +177,6 @@ namespace EscudeTools
createTableCommand.CommandText = createTableQuery.ToString(); createTableCommand.CommandText = createTableQuery.ToString();
createTableCommand.ExecuteNonQuery(); createTableCommand.ExecuteNonQuery();
} }
using SqliteCommand insertDataCommand = connection.CreateCommand(); using SqliteCommand insertDataCommand = connection.CreateCommand();
@ -297,7 +295,7 @@ namespace EscudeTools
reader.Read(); reader.Read();
if (reader.GetFieldType(1) == typeof(int)) if (reader.GetFieldType(1) == typeof(int))
{ {
flag2 = reader.GetInt32(1) == 0; flag2 = reader.GetInt32(1)==0;
} }
else if (reader.GetFieldType(1) == typeof(string)) else if (reader.GetFieldType(1) == typeof(string))
{ {
@ -311,7 +309,7 @@ namespace EscudeTools
{ {
if (types[i] != 4) if (types[i] != 4)
continue; continue;
if (textOffset == 0 && flag2) if (textOffset == 0&&flag2)
{ {
textOffset++; textOffset++;
flag = false; flag = false;
@ -348,7 +346,7 @@ namespace EscudeTools
} }
int index1 = textMulti.IndexOf(tableName[..^3]); int index1 = textMulti.IndexOf(tableName[..^3]);
textMulti.Add(tableName[..^3]); textMulti.Add(tableName[..^3]);
if (index1 == -1) if(index1 == -1)
{ {
text.Add(tableName[..^3]);//表名 text.Add(tableName[..^3]);//表名
textOffset1.Add(textOffset); textOffset1.Add(textOffset);

View File

@ -4,7 +4,7 @@ namespace EscudeTools
{ {
public class ImageManager public class ImageManager
{ {
public static bool Process(LsfData ld, int[] n, string target) public static bool EvProcess(LsfData ld, int[] n, string target)
{ {
//get base size //get base size
int height = ld.lfh.height, width = ld.lfh.width; int height = ld.lfh.height, width = ld.lfh.width;
@ -16,28 +16,15 @@ namespace EscudeTools
int offsetX = ld.lli[n[i]].rect.left; int offsetX = ld.lli[n[i]].rect.left;
int offsetY = ld.lli[n[i]].rect.top; int offsetY = ld.lli[n[i]].rect.top;
int mode = ld.lli[n[i]].mode; int mode = ld.lli[n[i]].mode;
if (mode == 3) baseImage.Composite(overlayImage, offsetX, offsetY, (mode == 3) ? CompositeOperator.Multiply : ((mode == 10) ? CompositeOperator.Plus : CompositeOperator.Over));
{
overlayImage.Composite(baseImage, -1 * offsetX, -1 * offsetY, CompositeOperator.DstIn);
baseImage.Composite(overlayImage, offsetX, offsetY, CompositeOperator.Multiply);//原先就一条这个,发现处理透明时会有问题
}
else if (mode == 10)
{
baseImage.Composite(overlayImage, offsetX, offsetY, CompositeOperator.Plus);
}
else
{
baseImage.Composite(overlayImage, offsetX, offsetY, CompositeOperator.Over);
}
} }
baseImage.Write(target); baseImage.Write(target);
return true; return true;
} }
//上面足够给Ev、St用了 public static bool STProcess()
//public static bool StProcess() {
//{ throw new NotImplementedException();
// throw new NotImplementedException(); }
//}
} }
} }

View File

@ -148,13 +148,6 @@ namespace EscudeTools
public LsfData? FindLsfDataByName(string name) public LsfData? FindLsfDataByName(string name)
{ {
lsfDataLookup.TryGetValue(name.ToLower(), out var lsfData); lsfDataLookup.TryGetValue(name.ToLower(), out var lsfData);
//c**,为什么会有错字?
if (name == "08_Syuichi" && lsfData == null)
lsfDataLookup.TryGetValue("08_syuuichi", out lsfData);
return lsfData; // 如果未找到,则返回 null return lsfData; // 如果未找到,则返回 null
} }

View File

@ -6,7 +6,6 @@ namespace EscudeTools
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
//批量处理EV/ST
if (Directory.Exists(args[0]) && File.Exists(args[1])) if (Directory.Exists(args[0]) && File.Exists(args[1]))
//if (File.Exists(args[0])) //if (File.Exists(args[0]))
{ {
@ -14,9 +13,9 @@ namespace EscudeTools
using SqliteConnection connection = new($"Data Source={graphicsDBPath};"); using SqliteConnection connection = new($"Data Source={graphicsDBPath};");
connection.Open(); connection.Open();
List<string> tableNames = []; List<string> tableNames = [];
string[] foundTN = new string[3]; string[] foundTN = new string[2];
List<int> tableIds = []; List<int> tableIds = [];
bool found1 = false, found2 = false, found3 = false; bool found1 = false, found2 = false;
using (var command = new SqliteCommand("SELECT name FROM sqlite_master WHERE type='table';", connection)) using (var command = new SqliteCommand("SELECT name FROM sqlite_master WHERE type='table';", connection))
using (var reader = command.ExecuteReader()) using (var reader = command.ExecuteReader())
{ {
@ -34,16 +33,11 @@ namespace EscudeTools
foundTN[1] = tableName; foundTN[1] = tableName;
found2 = true; found2 = true;
} }
else if (tableName.StartsWith("表情"))
{
foundTN[2] = tableName;
found3 = true;
}
tableNames.Add(tableName); tableNames.Add(tableName);
tableIds.Add(id++); tableIds.Add(id++);
} }
} }
if (!(found1 && found2 && found3)) //这里的代码未经测试 if (!(found1 && found2))
{ {
for (int i = 0; i < tableNames.Count; i++) for (int i = 0; i < tableNames.Count; i++)
Console.WriteLine($"{tableIds[i]}: {tableNames[i]}"); Console.WriteLine($"{tableIds[i]}: {tableNames[i]}");
@ -91,33 +85,10 @@ namespace EscudeTools
return; return;
} }
} }
if (!found3)
{
Console.WriteLine("自动识别失败请选择存放表情信息的数据表ID: ");
string? input = Console.ReadLine();
if (int.TryParse(input, out int userInputId))
{
if (userInputId >= 0 && userInputId < tableIds.Count)
{
foundTN[2] = tableNames[userInputId];
}
else
{
Console.WriteLine("Invalid ID.");
return;
}
}
else
{
Console.WriteLine("Invalid input. Please enter a valid number.");
return;
}
}
} }
List<EvTable> evts = []; List<EvTable> evts = [];
List<StTable> stts = []; List<StTable> stts = [];
Face[] faces = new Face[32];
using (var command = new SqliteCommand($"SELECT * FROM {foundTN[0]};", connection)) using (var command = new SqliteCommand($"SELECT * FROM {foundTN[0]};", connection))
{ {
using var reader = command.ExecuteReader(); using var reader = command.ExecuteReader();
@ -154,7 +125,7 @@ namespace EscudeTools
option = reader.GetString(2).Split(' '), option = reader.GetString(2).Split(' '),
coverd = (uint)reader.GetInt32(3), coverd = (uint)reader.GetInt32(3),
filter = (uint)reader.GetInt32(4), filter = (uint)reader.GetInt32(4),
face = (uint)reader.GetInt32(5), color = (uint)reader.GetInt32(5),
id = (uint)reader.GetInt32(6), id = (uint)reader.GetInt32(6),
loc = (uint)reader.GetInt32(7), loc = (uint)reader.GetInt32(7),
order = reader.GetInt32(8), order = reader.GetInt32(8),
@ -162,22 +133,6 @@ namespace EscudeTools
}); });
} }
} }
using (var command = new SqliteCommand($"SELECT * FROM {foundTN[2]};", connection))
{
using var reader = command.ExecuteReader();
while (reader.Read())
{
if (reader.IsDBNull(0) || string.IsNullOrEmpty(reader.GetString(0)))
continue;
for (int i = 0; i < faces.Length; i++)
{
if (faces[i] == null)
faces[i] = new Face();
if (reader.GetInt32(2 + i) == 1)
faces[i].faceOptions.Add(reader.GetString(1));
}
}
}
string[] files = Directory.GetFiles(args[0], "*.lsf", SearchOption.AllDirectories); string[] files = Directory.GetFiles(args[0], "*.lsf", SearchOption.AllDirectories);
LsfManager lm = new(); LsfManager lm = new();
@ -198,88 +153,38 @@ namespace EscudeTools
{ {
MaxDegreeOfParallelism = 6 // 设置最大并行线程数 MaxDegreeOfParallelism = 6 // 设置最大并行线程数
}; };
// //ST //表情还要另取?
// Parallel.ForEach(stts, parallelOptions, stt =>
// //foreach (StTable stt in stts)
// {
// if (stt.order == 0) //仅提取鉴赏中有的ST
// return;
// //continue;
// string targetFilename = Path.Combine(outputDir, stt.name); //最后保存可用的文件名
// LsfData? lsfData = lm.FindLsfDataByName(stt.file) ?? throw new Exception($"错误,未找到与{stt.file}对应的lsf数据");
// List<int> pendingList = [];
// List<string> pendingListFn = [];
// foreach (string o in stt.option)
// {
// List<int> t = TableManagercs.ParseOptions(lsfData, o);
// if (t.Count == 0)
// continue;
// pendingList.AddRange(t);
// foreach (int i in t)
// {
// pendingListFn.Add(lsfData.lli[i].nameStr);
// }
// }
// pendingList = TableManagercs.OrderLayer(pendingList, pendingListFn);
// int n = 0;
// foreach (string o in faces[(int)stt.face].faceOptions)
// {
// List<int> pendingListCopy = new(pendingList);
// List<int> t = TableManagercs.ParseOptions(lsfData, o);
// if (t.Count == 0)
// continue;
// pendingListCopy.AddRange(t);
// if (File.Exists(targetFilename + $"_{n++}.png"))
// continue;
// if (!ImageManager.Process(lsfData, [.. pendingListCopy], targetFilename + $"_{n++}.png"))
// throw new Exception("Process Fail");
// else
// Console.WriteLine($"Export {stt.name}_{n - 1} Success");
// }
// });
////}
//EV
Parallel.ForEach(evts, parallelOptions, evt => Parallel.ForEach(evts, parallelOptions, evt =>
//foreach (EvTable evt in evts) //foreach (EvTable evt in evts)
{ {
if (evt.order == 0) //仅提取鉴赏中有的CG if (evt.order == 0) //仅提取鉴赏中有的CG
return; return;
//continue; //continue;
string targetFilename = Path.Combine(outputDir, evt.name + ".png"); //最后保存可用的文件名 string targetFilename = Path.Combine(outputDir, evt.name + ".png"); //最后保存可用的文件名(这里还没有后缀)
LsfData lsfData = lm.FindLsfDataByName(evt.file) ?? throw new Exception("Something Wrong"); LsfData lsfData = lm.FindLsfDataByName(evt.file) ?? throw new Exception("Something Wrong");
List<int> pendingList = []; List<int> pendingList = [];
List<string> pendingListFn = [];
foreach (string o in evt.option) foreach (string o in evt.option)
{ {
List<int> t = TableManagercs.ParseOptions(lsfData, o); int t = TableManagercs.ParseOptions(lsfData, o);
if (t.Count == 0) if (t == -1)
continue; continue;
pendingList.AddRange(t); pendingList.Add(t);
foreach (int i in t)
{
pendingListFn.Add(lsfData.lli[i].nameStr);
}
} }
pendingList = TableManagercs.OrderLayer(pendingList, pendingListFn);
if (pendingList[0] != 0) if (pendingList[0] != 0)
pendingList.Insert(0, 0); pendingList.Insert(0, 0);
if (!ImageManager.Process(lsfData, [.. pendingList], targetFilename)) if (!ImageManager.EvProcess(lsfData, [.. pendingList], targetFilename))
throw new Exception("Process Fail"); throw new Exception("Process Fail");
else else
Console.WriteLine($"Export {evt.name} Success"); Console.WriteLine($"Export {evt.name} Success");
}); });
//} //}
} }
//// 批量读取lsf文件 //// 批量读取lsf文件
//if (Directory.Exists(args[0])) //if (Directory.Exists(args[0]))
//{ //{
@ -440,7 +345,7 @@ namespace EscudeTools
//} //}
////导出db_*.bin
//if (Directory.Exists(args[0])) //if (Directory.Exists(args[0]))
//{ //{
// string[] files = Directory.GetFiles(args[0], "db_*.bin"); // string[] files = Directory.GetFiles(args[0], "db_*.bin");
@ -496,7 +401,8 @@ namespace EscudeTools
// Console.WriteLine(" -s <filepath> Same as <filepath>"); // Console.WriteLine(" -s <filepath> Same as <filepath>");
// Console.WriteLine(" -h Display help info"); // Console.WriteLine(" -h Display help info");
//} //}
}
}
} }
} }

View File

@ -22,19 +22,15 @@ namespace EscudeTools
public string[] option; public string[] option;
public uint coverd; public uint coverd;
public uint filter; public uint filter;
public uint face; public uint color;
public uint id; public uint id;
public uint loc; public uint loc;
public int order; public int order;
public uint link; public uint link;
} }
public class Face
{
public List<string> faceOptions = []; //face options str ↓需要解析
}
public class TableManagercs public class TableManagercs
{ {
public static List<int> ParseOptions(LsfData ld, string input) public static int ParseOptions(LsfData ld, string input)
{ {
// 正则表达式匹配 p*:* 格式 // 正则表达式匹配 p*:* 格式
Regex regex = new(@"p(\d+):(\d+)"); Regex regex = new(@"p(\d+):(\d+)");
@ -54,52 +50,19 @@ namespace EscudeTools
} }
} }
} }
List<int> tmp = [];
List<string> tmpS = [];
for (int i = 0; i < ld.lli.Length; i++) for (int i = 0; i < ld.lli.Length; i++)
{ {
if (ld.lli[i].index == 0 && ld.lli[i].state == 0) if (ld.lli[i].index == 0 && ld.lli[i].state == 0)
{ {
if (ld.lli[i].index == results[0] && ld.lli[i].state + 1 == results[1]) if (ld.lli[i].index == results[0] && ld.lli[i].state + 1 == results[1])
{ return i;
tmpS.Add(ld.lli[i].nameStr);
tmp.Add(i);
}
} }
else if (ld.lli[i].index == results[0] && ld.lli[i].state == results[1]) if (ld.lli[i].index == results[0] && ld.lli[i].state == results[1])
{ return i;
tmpS.Add(ld.lli[i].nameStr);
tmp.Add(i);
}
} }
if (tmp.Count == 0) //一般可以忽略这个警告
Console.WriteLine($"[WARN] Found invalid index:state data {results[0]}:{results[1]} in {ld.lsfName}, may be a bug?"); //一般可以忽略这个警告 Console.WriteLine($"[WARN] Found invalid index:state data {results[0]}:{results[1]} in {ld.lsfName}, may be a bug?");
return tmp; return -1;
}
//根据文件名序号重新为组合顺序进行排序,解决某些长发角色合成的问题
public static List<int> OrderLayer(List<int> layer, List<string> layer_fn)
{
List<int> order = [];
foreach (string item in layer_fn)
{
string[] parts = item.Split("_");
if (parts.Length == 3)
{
if (int.TryParse(parts[2], out int number))
{
order.Add(number);
}
}
}
List<int> sortedTmp = layer.Select((value, index) => new { Value = value, Index = order[index] })
.OrderBy(x => x.Index)
.Select(x => x.Value)
.ToList();
return sortedTmp;
} }
public static int ParseCharactor(string input) public static int ParseCharactor(string input)

View File

@ -76,26 +76,21 @@ namespace EscudeTools
stream.CopyTo(fileStream); stream.CopyTo(fileStream);
} }
public static string GetSQLiteColumnType(ushort type, uint size) public static string GetSQLiteColumnType(ushort type)
{ {
if (type == 1) return type switch
return "INTEGER"; {
//else if (type == 4 && size == 4) // int
// return "TEXT"; 0x1 => "INTEGER",
else // float
return "TEXT"; 0x2 => "REAL",
//return type switch // string
//{ 0x3 => "TEXT",
// // int // bool
// 0x1 => "INTEGER", 0x4 => "INTEGER",
// // float _ => throw new NotSupportedException($"Unsupported column type: {type}"),
// 0x2 => "REAL", };
// // string throw new NotImplementedException();
// 0x3 => "TEXT",
// // bool
// 0x4 => "INTEGER",
// _ => throw new NotSupportedException($"Unsupported column type: {type}"),
//};
} }
public static bool ISKANJI(byte x) public static bool ISKANJI(byte x)
@ -128,16 +123,16 @@ namespace EscudeTools
}; };
} }
public static byte RotByteR(byte v, int count) public static byte RotByteR (byte v, int count)
{ {
count &= 7; count &= 7;
return (byte)(v >> count | v << (8 - count)); return (byte)(v >> count | v << (8-count));
} }
public static byte RotByteL(byte v, int count) public static byte RotByteL (byte v, int count)
{ {
count &= 7; count &= 7;
return (byte)(v << count | v >> (8 - count)); return (byte)(v << count | v >> (8-count));
} }
} }
} }