working version
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using static Program;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Text;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
//TEST REMOVE LATER
|
||||
string[] args = new string[] { "--all", "C:\\Users\\Lauren\\Desktop\\Ken Ga Kimi\\TEST", "C:\\Users\\Lauren\\Desktop\\Ken Ga Kimi\\TEST\\OUTPUT" };
|
||||
string[] args = new string[] { "--all", "C:\\Users\\Lauren\\Desktop\\Ken Ga Kimi\\PATCH\\EN Files", "C:\\Users\\Lauren\\Desktop\\Ken Ga Kimi\\PATCH\\EN Files\\OUTPUT" };
|
||||
|
||||
if (args.Length < 1)
|
||||
{
|
||||
@@ -187,7 +181,7 @@ class Program
|
||||
offset = RoundUpToNextMultipleOf4(offset);
|
||||
int size = BitConverter.ToInt32(data, offset);
|
||||
offset += 4;
|
||||
if (data[offset+1] == 255 && data[offset + 2] == 254) {
|
||||
if (data[offset] == 255 && data[offset + 1] == 254) {
|
||||
offset += 2;
|
||||
}
|
||||
//offset = RoundUpToNextMultipleOf4(offset);
|
||||
@@ -233,84 +227,86 @@ class Program
|
||||
}
|
||||
}
|
||||
List<string> searchStrings = new List<string>() {
|
||||
"\n@",
|
||||
"\n<voice name=",
|
||||
"\n<textboxtype type=\"monologue",
|
||||
"\n<textboxtype type=\"dialogue\">",
|
||||
"\n<monologue background=\"on\">",
|
||||
"@",
|
||||
"<voice name=",
|
||||
"<textboxtype type=\"monologue\">",
|
||||
"<textboxtype type=\"monologue2\">",
|
||||
"<textboxtype type=\"monologue3\">",
|
||||
"<monologue background=\"on\">",
|
||||
};
|
||||
List<(string, int)> stringPositions = FindStringPositions(script.ScriptText, searchStrings);
|
||||
List<(string, int)> stringPositions = FindStringPositions(script.ScriptText);
|
||||
List<(string, int)> filteredStringPositions = stringPositions
|
||||
.Where(pos => searchStrings.Any(s => pos.Item1.Contains(s)))
|
||||
.ToList();
|
||||
//Add length of data
|
||||
newAlr.AddRange(BitConverter.GetBytes(stringPositions.Count * 8));
|
||||
newAlr.AddRange(BitConverter.GetBytes(filteredStringPositions.Count * 8));
|
||||
|
||||
if (alr.ScriptTitle == "KEN_00_00_00_alr")
|
||||
{
|
||||
Console.WriteLine("Found KEN_00_00_00");
|
||||
}
|
||||
//position += 1;
|
||||
for (int i = 0; i < stringPositions.Count; i++)
|
||||
{
|
||||
newAlr.AddRange(BitConverter.GetBytes(stringPositions[i].Item2));
|
||||
newAlr.AddRange(BitConverter.GetBytes(position));
|
||||
if (stringPositions[i].Item1 != "\n@")
|
||||
if (searchStrings.Any(s => stringPositions[i].Item1.Contains(s)))
|
||||
{
|
||||
position += 1;
|
||||
newAlr.AddRange(BitConverter.GetBytes(stringPositions[i].Item2));
|
||||
newAlr.AddRange(BitConverter.GetBytes(position));
|
||||
var isNormalTag = searchStrings.Any(t => stringPositions[i].Item1.Contains(t));
|
||||
if (stringPositions[i].Item1.Contains("<voice name="))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (isNormalTag)
|
||||
{
|
||||
position += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Don't add to position if the previous string was a tag
|
||||
//Console.WriteLine("OOPS");
|
||||
}
|
||||
}
|
||||
else if (stringPositions[i].Item1 == "\n@" && i > 0 && stringPositions[i - 1].Item1 != "\n@")
|
||||
{
|
||||
//Don't add to position if the previous string was a tag
|
||||
}
|
||||
else if (stringPositions.Count == 1)
|
||||
{
|
||||
position += 1;
|
||||
}
|
||||
|
||||
}
|
||||
return newAlr.ToArray();
|
||||
}
|
||||
|
||||
public static List<(string SearchString, int Position)> FindStringPositions(byte[] scriptBytes, IEnumerable<string> searchStrings)
|
||||
public static List<(string SearchString, int Position)> FindStringPositions(byte[] scriptBytes)
|
||||
{
|
||||
var results = new List<(string, int)>();
|
||||
// Decode the script bytes to string for line analysis
|
||||
string scriptText = Encoding.Unicode.GetString(scriptBytes);
|
||||
|
||||
foreach (var search in searchStrings)
|
||||
// 1. Find all <...> tags not commented out
|
||||
var tagRegex = new System.Text.RegularExpressions.Regex(@"<[^>\r\n]+>");
|
||||
foreach (System.Text.RegularExpressions.Match match in tagRegex.Matches(scriptText))
|
||||
{
|
||||
byte[] searchBytes = Encoding.Unicode.GetBytes(search);
|
||||
int index = 0;
|
||||
while (index <= scriptBytes.Length - searchBytes.Length)
|
||||
{
|
||||
bool match = true;
|
||||
for (int j = 0; j < searchBytes.Length; j++)
|
||||
{
|
||||
if (scriptBytes[index + j] != searchBytes[j])
|
||||
{
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match)
|
||||
{
|
||||
// Find the character index in the string corresponding to this byte index
|
||||
int charIndex = Encoding.Unicode.GetString(scriptBytes, 0, index).Length;
|
||||
// Find the start of the line
|
||||
int lineStart = scriptText.LastIndexOf('\n', charIndex - 1);
|
||||
if (lineStart == -1) lineStart = 0; else lineStart++;
|
||||
int lineEnd = scriptText.IndexOf('\n', charIndex);
|
||||
if (lineEnd == -1) lineEnd = scriptText.Length;
|
||||
string line = scriptText.Substring(lineStart, lineEnd - lineStart).TrimStart();
|
||||
if (match.Value == "<pb>") continue; // Skip <pb> tags
|
||||
|
||||
// Only add if the line does NOT start with //
|
||||
if (!line.StartsWith("//"))
|
||||
{
|
||||
results.Add((search, index));
|
||||
}
|
||||
index += searchBytes.Length; // Move past this match
|
||||
}
|
||||
else
|
||||
{
|
||||
index++;
|
||||
}
|
||||
int lineStart = scriptText.LastIndexOf('\n', match.Index);
|
||||
if (lineStart == -1) lineStart = 0; else lineStart++;
|
||||
int lineEnd = scriptText.IndexOf('\n', match.Index);
|
||||
if (lineEnd == -1) lineEnd = scriptText.Length;
|
||||
string line = scriptText.Substring(lineStart, lineEnd - lineStart).TrimStart();
|
||||
|
||||
if (!line.StartsWith("//"))
|
||||
{
|
||||
int byteIndex = Encoding.Unicode.GetByteCount(scriptText.Substring(0, match.Index));
|
||||
results.Add((match.Value, byteIndex));
|
||||
}
|
||||
}
|
||||
// Sort by position in order of appearance
|
||||
|
||||
// 2. Find all lines that start with @ and are not commented out
|
||||
int currentIndex = 0;
|
||||
foreach (var line in scriptText.Split('\n'))
|
||||
{
|
||||
string trimmedLine = line.TrimStart();
|
||||
if (!trimmedLine.StartsWith("//") && trimmedLine.StartsWith("@"))
|
||||
{
|
||||
int byteIndex = Encoding.Unicode.GetByteCount(scriptText.Substring(0, currentIndex));
|
||||
results.Add((line, byteIndex));
|
||||
}
|
||||
currentIndex += line.Length + 1; // +1 for '\n'
|
||||
}
|
||||
return results.OrderBy(r => r.Item2).ToList();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user