尝试兼容旧作Sennagi

This commit is contained in:
Chenx221 2024-10-29 20:27:20 +08:00
parent 17550bb6b1
commit 5ca0fe2e9a
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
5 changed files with 128 additions and 64 deletions

View File

@ -4,9 +4,116 @@ namespace EscudeTools
{ {
public class ImageManager public class ImageManager
{ {
public static void ImgPreProcessNew(List<StTable> stts, Face[] faces, LsfManager lm, string outputDir)
{
var parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = 6 // 设置最大并行线程数
};
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<string> pendingListFnCopy = new(pendingListFn);
List<int> t = TableManagercs.ParseOptions(lsfData, o);
if (t.Count == 0)
continue;
foreach (int i in t)
{
pendingListFnCopy.Add(lsfData.lli[i].nameStr);
}
pendingListCopy.AddRange(t);
pendingListCopy = TableManagercs.OrderLayer(pendingListCopy, pendingListFnCopy);
if (!ImageManager.Process(lsfData, [.. pendingListCopy], targetFilename + $"_{n}.png"))
throw new Exception("Process Fail");
else
Console.WriteLine($"Export {stt.name}_{n} Success");
n++;
}
});
}
public static void ImgPreProcessOld(List<StTable> stts, LsfManager lm, string outputDir)
{
var parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = 6 // 设置最大并行线程数
};
Parallel.ForEach(stts, parallelOptions, stt =>
//foreach (var stt in stts)
{
if (stt.order == 0) //仅提取鉴赏中有的ST
return;
string targetFilename = Path.Combine(outputDir, stt.name);
LsfData? lsfData = lm.FindLsfDataByName(stt.file) ?? throw new Exception($"错误,未找到与{stt.file}对应的lsf数据");
List<int> faceAvailList = [];
List<string> faceAvailNameList = [];
for (int i = 0; i < lsfData.lli.Length; i++)
{
if (lsfData.lli[i].index == 1)
{
faceAvailList.Add(i);
faceAvailNameList.Add(lsfData.lli[i].nameStr);
}
}
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;
for (int k = 0; k < faceAvailList.Count; k++)
{
List<int> que = new(pendingList);
List<string> queStr = new(pendingListFn);
que.Add(faceAvailList[k]);
queStr.Add(faceAvailNameList[k]);
que = TableManagercs.OrderLayer(que, queStr);
if (!ImageManager.Process(lsfData, [.. que], targetFilename + $"_{n}.png"))
throw new Exception("Process Fail");
else
Console.WriteLine($"Export {stt.name}_{n} Success");
n++;
}
});
}
public static bool Process(LsfData ld, int[] n, string target) public static bool Process(LsfData ld, int[] n, string target)
{ {
//get base size
int height = ld.lfh.height, width = ld.lfh.width; int height = ld.lfh.height, width = ld.lfh.width;
using var baseImage = new MagickImage(MagickColors.Transparent, (uint)width, (uint)height); using var baseImage = new MagickImage(MagickColors.Transparent, (uint)width, (uint)height);
for (int i = 0; i < n.Length; i++) for (int i = 0; i < n.Length; i++)
@ -19,9 +126,9 @@ namespace EscudeTools
if (mode == 3) if (mode == 3)
{ {
overlayImage.Composite(baseImage, -1 * offsetX, -1 * offsetY, CompositeOperator.DstIn); overlayImage.Composite(baseImage, -1 * offsetX, -1 * offsetY, CompositeOperator.DstIn);
baseImage.Composite(overlayImage, offsetX, offsetY, CompositeOperator.Multiply);//原先就一条这个,发现处理透明时会有问题 baseImage.Composite(overlayImage, offsetX, offsetY, CompositeOperator.Multiply);//应该能解决透明度问题了
} }
else if (mode == 10) else if (mode == 10) //目前还没遇到过?
{ {
baseImage.Composite(overlayImage, offsetX, offsetY, CompositeOperator.Plus); baseImage.Composite(overlayImage, offsetX, offsetY, CompositeOperator.Plus);
} }
@ -34,10 +141,6 @@ namespace EscudeTools
return true; return true;
} }
//上面足够给Ev、St用了
//public static bool StProcess()
//{
// throw new NotImplementedException();
//}
} }
} }

View File

@ -42,7 +42,7 @@ namespace EscudeTools
public string pathStr; public string pathStr;
public string lsfName; public string lsfName;
} }
public class LsfFileHeader public class LsfFileHeader
{ {
//public uint signature; // Header signature (LSF) 0x46534C //public uint signature; // Header signature (LSF) 0x46534C

View File

@ -212,6 +212,7 @@ namespace EscudeTools
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();
int fieldCount = reader.FieldCount;
while (reader.Read()) while (reader.Read())
{ {
if (reader.IsDBNull(0) || string.IsNullOrEmpty(reader.GetString(0))) if (reader.IsDBNull(0) || string.IsNullOrEmpty(reader.GetString(0)))
@ -223,7 +224,7 @@ namespace EscudeTools
option = (reader["オプション_44"].ToString() ?? "").Split(' '), option = (reader["オプション_44"].ToString() ?? "").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("表情_14"), face = (uint)(fieldCount == 9 ? 0 : reader.GetInt32("表情_14")),
//id = (uint)reader.GetInt32(6), //id = (uint)reader.GetInt32(6),
//loc = (uint)reader.GetInt32(7), //loc = (uint)reader.GetInt32(7),
order = reader.GetInt32("CG鑑賞_14"), order = reader.GetInt32("CG鑑賞_14"),
@ -232,10 +233,14 @@ namespace EscudeTools
} }
} }
List<string> fa = []; List<string> fa = [];
bool legacyMode = false;
using (var command = new SqliteCommand($"SELECT * FROM {foundTN[1]};", connection)) using (var command = new SqliteCommand($"SELECT * FROM {foundTN[1]};", connection))
{ {
using var reader = command.ExecuteReader(); using var reader = command.ExecuteReader();
while (reader.Read()) int fieldCount = reader.FieldCount;
if (fieldCount <= 2)
legacyMode = true;
while (reader.Read() && !legacyMode)
{ {
if (reader.IsDBNull(0) || string.IsNullOrEmpty(reader.GetString(0))) if (reader.IsDBNull(0) || string.IsNullOrEmpty(reader.GetString(0)))
continue; continue;
@ -263,55 +268,10 @@ namespace EscudeTools
string outputDir = Path.Combine(Path.GetDirectoryName(v1), "Output"); string outputDir = Path.Combine(Path.GetDirectoryName(v1), "Output");
if (!Directory.Exists(outputDir)) if (!Directory.Exists(outputDir))
Directory.CreateDirectory(outputDir); Directory.CreateDirectory(outputDir);
if (legacyMode)
var parallelOptions = new ParallelOptions ImageManager.ImgPreProcessOld(stts, lm, outputDir);
{ else
MaxDegreeOfParallelism = 6 // 设置最大并行线程数 ImageManager.ImgPreProcessNew(stts, faces, lm, outputDir);
};
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<string> pendingListFnCopy = new(pendingListFn);
List<int> t = TableManagercs.ParseOptions(lsfData, o);
if (t.Count == 0)
continue;
foreach (int i in t)
{
pendingListFnCopy.Add(lsfData.lli[i].nameStr);
}
pendingListCopy.AddRange(t);
pendingListCopy = TableManagercs.OrderLayer(pendingListCopy, pendingListFnCopy);
if (!ImageManager.Process(lsfData, [.. pendingListCopy], targetFilename + $"_{n++}.png"))
throw new Exception("Process Fail");
else
Console.WriteLine($"Export {stt.name}_{n - 1} Success");
}
});
//}
} }
} }
@ -647,7 +607,7 @@ namespace EscudeTools
Console.WriteLine("Ignore the 001 files; the program will read them if needed."); Console.WriteLine("Ignore the 001 files; the program will read them if needed.");
Console.WriteLine("Must specify the type of script bin file to unpack."); Console.WriteLine("Must specify the type of script bin file to unpack.");
Console.WriteLine("Accepts the following types: 0, 1, 2."); Console.WriteLine("Accepts the following types: 0, 1, 2.");
Console.WriteLine("Type 0: Full; this creates script.db containing all .bin and .001 information."); Console.WriteLine("Type 0(unstable): Full; this creates script.db containing all .bin and .001 information.");
Console.WriteLine("Type 2: Exports only the text from bin; this creates script_text.db and many .dat files (non-text data)."); Console.WriteLine("Type 2: Exports only the text from bin; this creates script_text.db and many .dat files (non-text data).");
Console.WriteLine("Type 1: Exports only the text from 001; this creates script_sm.db containing all .001 information."); Console.WriteLine("Type 1: Exports only the text from 001; this creates script_sm.db containing all .001 information.");
Console.WriteLine(); Console.WriteLine();

View File

@ -1,7 +1,8 @@
{ {
"profiles": { "profiles": {
"EscudeTools": { "EscudeTools": {
"commandName": "Project" "commandName": "Project",
"commandLineArgs": "-s\r\n\"G:\\x221.local\\[231027][1231724][エスクード] 戦巫<センナギ> ―穢れた契りと神ころも― DL版 (files)\\戦巫〈センナギ〉―穢れた契りと神ころも―\\output\\st\\0\"\r\n\"G:\\x221.local\\[231027][1231724][エスクード] 戦巫<センナギ> ―穢れた契りと神ころも― DL版 (files)\\戦巫〈センナギ〉―穢れた契りと神ころも―\\output\\st\\db_graphics.db\""
} }
} }
} }

View File

@ -89,9 +89,9 @@ namespace EscudeTools
foreach (string item in layer_fn) foreach (string item in layer_fn)
{ {
string[] parts = item.Split("_"); string[] parts = item.Split("_");
if (parts.Length == 3) if (parts.Length >= 3)
{ {
if (int.TryParse(parts[2], out int number)) if (int.TryParse(parts[^1], out int number))
{ {
order.Add(number); order.Add(number);
} }