diff --git a/SRL/FileWorker.cs b/SRL/FileWorker.cs index 0235601..d0e2d94 100644 --- a/SRL/FileWorker.cs +++ b/SRL/FileWorker.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Drawing; using System.IO; +using System.Linq; using System.Text; using System.Threading; @@ -117,13 +118,20 @@ private static void LoadConfig() { ReloadMaskParameters = false; LiteMode = false; RemoveIlegals = false; + AsianInput = false; + QuoteList = new Quote[0]; + Sensitivity = 3; + DenyList = new string[0]; + IgnoreList = new string[0]; SRLSettings Settings; OverlaySettings OverlaySettings; WordwrapSettings WordwrapSettings; + FilterSettings FilterSettings; AdvancedIni.FastOpen(out Settings, IniPath); AdvancedIni.FastOpen(out OverlaySettings, IniPath); AdvancedIni.FastOpen(out WordwrapSettings, IniPath); + AdvancedIni.FastOpen(out FilterSettings, IniPath); Log(Initialized ? "Reloading Settings..." : "Loading Settings...", true); @@ -161,9 +169,9 @@ private static void LoadConfig() { Warning("The Multithread Settings Changed - Restart Required"); } - if (!string.IsNullOrWhiteSpace(Settings.DenyChars)) { + if (!string.IsNullOrWhiteSpace(FilterSettings.DenyList)) { Log("Custom Denied Chars List Loaded...", true); - DenyChars = Settings.DenyChars; + DenyList = FilterSettings.DenyList.Split(','); } if (Settings.TrimRangeMismatch) { @@ -195,6 +203,11 @@ private static void LoadConfig() { MultipleDatabases = true; } + if (Settings.AsianInput) { + Log("Asian Text Mode Enabled...", true); + AsianInput = true; + } + if (Settings.WindowHook) { Log("Enabling Window Reloader...", true); new Thread(() => WindowHook()).Start(); @@ -345,29 +358,53 @@ private static void LoadConfig() { SpecialLineBreaker = true; } - if (!string.IsNullOrEmpty(Settings.MatchIgnore)) { + if (!string.IsNullOrEmpty(FilterSettings.IgnoreList)) { Log("Using Custom Ignore List...", true); MatchDel = new string[0]; - foreach (string str in Settings.MatchIgnore.Split(',')) + foreach (string str in FilterSettings.IgnoreList.Split(',')) if (str.Trim().StartsWith("0x")) { - string Del = System.Text.Encoding.UTF8.GetString(ParseHex(str.Trim())); + string Del = Encoding.UTF8.GetString(ParseHex(str.Trim())); AppendArray(ref MatchDel, Del, true); } else AppendArray(ref MatchDel, str.Replace(BreakLineFlag, "\n").Replace(ReturnLineFlag, "\r"), true); } - if (!string.IsNullOrEmpty(Settings.TrimChars)) { + if (!string.IsNullOrEmpty(FilterSettings.TrimList)) { Log("Using Custom Trim List...", true); TrimChars = new string[0]; - foreach (string str in Settings.TrimChars.Split(',')) { + foreach (string str in FilterSettings.TrimList.Split(',')) { if (str.Trim().StartsWith("0x")) { - - string Trim = System.Text.Encoding.UTF8.GetString(ParseHex(str.Trim())); + string Trim = Encoding.UTF8.GetString(ParseHex(str.Trim())); AppendArray(ref TrimChars, Trim, true); } else AppendArray(ref TrimChars, str.Replace(BreakLineFlag, "\n").Replace(ReturnLineFlag, "\r"), true); } } + if (!string.IsNullOrEmpty(FilterSettings.QuoteList)) { + Log("Using Custom Quotes...", true); + foreach (string str in FilterSettings.TrimList.Split(',')) { + if (string.IsNullOrEmpty(str)) + continue; + AppendArray(ref QuoteList, new Quote() { + Start = str.First(), + End = str.Last() + }, true); + Ranges.Add(new Range() { + Min = str.First(), + Max = str.First() + }); + Ranges.Add(new Range() { + Min = str.Last(), + Max = str.Last() + }); + } + } + + if (FilterSettings.Sensitivity != 2) { + Log("Dialogue Sensitivity Level Changed to {0}", true, FilterSettings.Sensitivity); + Sensitivity = FilterSettings.Sensitivity; + } + if (!string.IsNullOrWhiteSpace(Settings.WorkDirectory)) { CustomDir = Settings.WorkDirectory.TrimStart(' ', '\\', '/').Replace("/", "\\"); @@ -380,6 +417,7 @@ private static void LoadConfig() { Log("Custom Directory Loaded", true); } + Log("Settings Loaded.", true); if (Managed) { diff --git a/SRL/Main.cs b/SRL/Main.cs index 2897a44..f9d02fa 100644 --- a/SRL/Main.cs +++ b/SRL/Main.cs @@ -5,8 +5,10 @@ namespace SRL { public partial class StringReloader { + [DllExport] - public static IntPtr Process(IntPtr Target) { + public static IntPtr Process(IntPtr Target) => ProcessInternal(Target); + private static IntPtr ProcessInternal(IntPtr Target) { again:; int Tries = 0; try { @@ -62,7 +64,7 @@ public static IntPtr Process(IntPtr Target) { LastInput = Input; if (ShowNonReloads) { - //TrimWorker(ref Reloaded, Input); //To Translation It's Better Turn This Off. + TrimWorker(ref Reloaded, Input); //To Translation It's Better Turn This Off. UpdateOverlay(Reloaded); } @@ -127,6 +129,18 @@ public static IntPtr Service(IntPtr hWnd, IntPtr hInst, IntPtr hCmdLine, int nCm return IntPtr.Zero; } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate IntPtr ProcDelegate(IntPtr Target); + private static ProcDelegate DirectProc = new ProcDelegate(ProcessInternal); + + [DllExport] + public static IntPtr GetDirectProcess() { + try { + DirectRequested = true; + return Marshal.GetFunctionPointerForDelegate(DirectProc); + } catch { return IntPtr.Zero; } + } + public static string ProcessManaged(string Text) { Managed = true; IntPtr Ptr = Marshal.StringToHGlobalAuto(Text); diff --git a/SRL/Properties/AssemblyInfo.cs b/SRL/Properties/AssemblyInfo.cs index afbfab6..e2c51f6 100644 --- a/SRL/Properties/AssemblyInfo.cs +++ b/SRL/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // É possível especificar todos os valores ou usar como padrão os Números de Build e da Revisão // usando o '*' como mostrado abaixo: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyFileVersion("2.0.0.0")] diff --git a/SRL/Reloader.cs b/SRL/Reloader.cs index 8e3c287..4c311e9 100644 --- a/SRL/Reloader.cs +++ b/SRL/Reloader.cs @@ -113,11 +113,13 @@ internal static string StrMap(string Input, IntPtr InputPtr, bool Native) { if (TLIB != null) { Str = TrimString(Input); if (IsDialog(Str)) { + string Ori = MergeLines(Str); string TL = null; if (Online) { try { + Log("Translating: \"{0}\"", true, Str); TL = TLIB.Call("TLIB.Google", "Translate", Ori, SourceLang, TargetLang); } catch { Log("Connection Failed, Disabling MTL for 30m", true); @@ -128,6 +130,9 @@ internal static string StrMap(string Input, IntPtr InputPtr, bool Native) { if (!Online) return Input; + if (SimplfyMatch(Ori) == SimplfyMatch(TL)) + TL = Ori; + if (Str != TL) AppendLst(Str, TL, MTLCache); @@ -137,9 +142,7 @@ internal static string StrMap(string Input, IntPtr InputPtr, bool Native) { if (!Native) TL = ReplaceChars(TL); - Log("\"{0}\" Automatically Translated.", true, Str); AddEntry(SimplfyMatch(Str), TL); - return TL; } } @@ -188,6 +191,10 @@ internal static void Init() { Log("Debug Mode Enabled..."); } + if (!DirectRequested) + Warning("You are using SRL through the old function, it is recommended to use GetDirectProcess"); + + if (File.Exists(BaseDir + "EncodingModifier.cs")) { Log("Enabling Encoding Modifier...", true); try { diff --git a/SRL/SRL.csproj b/SRL/SRL.csproj index 8357f21..728532f 100644 --- a/SRL/SRL.csproj +++ b/SRL/SRL.csproj @@ -103,7 +103,7 @@ true false 300000 - 2 + 3 diff --git a/SRL/SRL.ini b/SRL/SRL.ini index 65d8b1d..da17bf7 100644 --- a/SRL/SRL.ini +++ b/SRL/SRL.ini @@ -1,6 +1,5 @@ [StringReloader] -InEncoding=Unicode -OutEncoding=Unicode +Encoding=Unicode Wide=true Debug=false Delay=false @@ -17,11 +16,8 @@ AntiCrash=false FreeOnExit=true TrimRangeMismatch=true AcceptableRanges=0-9A-Za-zÀ-ÃÇ-ÎÓ-ÕÚ-Ûà-ãç-îó-õú-û。-゚ !?~., -MatchIgnore= -TrimChars= ,<,(,[,“,[,《,«,「,『,【,],”,],》,»,」,』,】,),>,‘,’,〃,″,~,~,―,-,%K,%LC,♪,%P NoTrim=false BreakLine= -DenyChars=@,§,$,_,<,>,/,[,] Multithread=true WindowHook=false Invalidate=false @@ -37,6 +33,7 @@ ReloadMaskArgs=true CustomCredits= LiteMode=false RemoveViolations=true +AsianInput=false [WordWrap] Enable=false @@ -54,4 +51,11 @@ TargetLang=EN [Overlay] Enabled=false ShowNative=false -Padding=Top: 0|Bottom: 0|Left: 0|Rigth: 0 \ No newline at end of file +Padding=Top: 0|Bottom: 0|Left: 0|Rigth: 0 + +[Filter] +DenyList=@,§,$,_,<,>,/,[,] +QuoteList=<>,(),[],“”,[],《》,«»,「」,『』,【】,(),'',"" +IgnoreList= +TrimList= ,%K,%LC,♪,%P +Sensitivity=3 \ No newline at end of file diff --git a/SRL/StringWorker.cs b/SRL/StringWorker.cs index 694ad1e..9c8f4ad 100644 --- a/SRL/StringWorker.cs +++ b/SRL/StringWorker.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using System.Runtime.InteropServices; using System.Text; -using System.Text.RegularExpressions; namespace SRL { partial class StringReloader { @@ -766,72 +766,178 @@ internal static byte[] ParseHex(string Hex) { /// The String /// Internal Parameter, don't change it. /// If looks a dialog, return true, else return false. - static bool IsDialog(string Str, bool Trim = false) { + static bool IsDialog(string String) { if (!DialogCheck || LiteMode) return true; - string String = TrimString(Str); - - if (SpecialLineBreaker) - String = String.Replace(GameLineBreaker, "\n"); - - bool Status = !string.IsNullOrWhiteSpace(String); - Status &= !string.IsNullOrWhiteSpace(TrimString(String).Trim('.', '?', '!')); - int Process = 0; - string Minified = SimplfyMatch(String); - while (Status) { - switch (Process) { - default: - goto ExitWhile; - case 0: - Status = !ContainsOR(Minified, DenyChars); - break; - case 1: - Status = NumberLimiter(String, String.Length / 4); - break; - case 2: - Status = Minified.Length >= 3 || EndsWithOr(String, ".,!,?") || String.StartsWith("."); - break; - case 3: - Status = String.Contains(((char)32).ToString()) || String.StartsWith("."); - break; - case 4: - if (String.Length > 3) { - if (String[String.Length - 4] == '.' && !String.Substring(String.Length - 3, 3).Contains(".")) { - Status = false; - } - } - break; - case 5: - Status = ContainsOR(String.ToLower(), "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,x,w,y,z"); - break; - case 6: - if (Ranges != null) { - uint Miss = 0; - foreach (char c in Minified) { - if (!InRange(c)) - Miss++; - } - if (Miss > Minified.Length/2) - Status = false; + if (string.IsNullOrWhiteSpace(String)) + return false; + + string Str = String; + foreach (string Ignore in IgnoreList) + Str = Str.Replace(Ignore, ""); + + Str = Str.Replace(GameLineBreaker, "\n"); + + + string[] Words = Str.Split(' '); + + int Spaces = Str.Where(x => x == ' ' || x == '\t').Count(); + int Pontuations = Str.Where(x => ".,!?".IndexOf(x) >= 0).Count(); + int WordCount = Words.Where(x => x.Length >= 2 && !string.IsNullOrWhiteSpace(x)).Count(); + int Specials = Str.Where(x => char.IsSymbol(x)).Count(); + Specials += Str.Where(x => char.IsPunctuation(x)).Count() - Pontuations; + + int Uppers = Str.Where(x => char.IsUpper(x)).Count(); + int Latim = Str.Where(x => x >= 'A' && x <= 'z').Count(); + int Numbers = Str.Where(x => x >= '0' && x <= '9').Count(); + int JapChars = Str.Where(x => (x >= '、' && x <= 'ヿ') || (x >= '。' && x <= 'ン')).Count(); + int Kanjis = Str.Where(x => x >= '一' && x <= '龯').Count(); + + + bool IsCaps = GetLineCase(Str) == Case.Upper; + bool IsJap = JapChars + Kanjis > Latim; + + + //More Points = Don't Looks a Dialogue + //Less Points = Looks a Dialogue + int Points = 0; + + if (Str.Length > 4) { + string ext = Str.Substring(Str.Length - 4, 4); + try { + if (System.IO.Path.GetExtension(ext).Trim('.').Length == 3) + Points += 2; + } catch { } + } + + bool BeginQuote = false; + Quote? LineQuotes = null; + foreach (Quote Quote in QuoteList) { + BeginQuote |= Str.StartsWith(Quote.Start.ToString()); + + if (Str.StartsWith(Quote.Start.ToString()) && Str.EndsWith(Quote.End.ToString())) { + Points -= 2; + LineQuotes = Quote; + break; + } else if (Str.StartsWith(Quote.Start.ToString()) || Str.EndsWith(Quote.End.ToString())) { + Points--; + LineQuotes = Quote; + break; + } + } + + char Last = (LineQuotes == null ? Str.Last() : Str.TrimEnd(LineQuotes.Value.End).Last()); + if (IsJap && (new char[] { '。', '?', '!', '…', '、' }).Contains(Last)) + Points -= 2; + + char[] PontuationList = new char[] { '.', '?', '!', '…', ',' }; + if (!IsJap && (PontuationList).Contains(Last)) + Points -= 2; + + if (!IsJap) { + foreach (string Word in Words) { + int WNumbers = Word.Where(c => char.IsNumber(c)).Count(); + int WLetters = Word.Where(c => char.IsLetter(c)).Count(); + if (WLetters > 0 && WNumbers > 0) { + Points += 2; + } + if (Word.Trim(PontuationList).Where(c => PontuationList.Contains(c)).Count() != 0) { + Points += 2; + } + } + } + + if (!BeginQuote && !char.IsLetter(Str.First())) + Points += 2; + + if (Specials > WordCount) + Points++; + + if ((Pontuations == 0) && (WordCount <= 2) && !IsJap) + Points++; + + if (Uppers > Pontuations + 2 && !IsCaps) + Points++; + + if (Spaces > WordCount * 2) + Points++; + + if (IsJap && Spaces == 0) + Points--; + + if (!IsJap && Spaces == 0) + Points += 2; + + if (WordCount <= 2 && Numbers != 0) + Points++; + + if (Str.Length <= 3 && !IsJap) + Points++; + + if (Numbers >= Str.Length) + Points++; + + if (IsJap && Kanjis / 2 > JapChars) + Points--; + + if (IsJap && JapChars > Kanjis) + Points--; + + if (IsJap && Latim != 0) + Points += 2; + + if (IsJap && Pontuations != 0) + Points++; + + if (IsJap != AsianInput) + return false; + + return Points < Sensitivity; + } + public enum Case { + Lower, Upper, Normal, Title + } + public static Case GetLineCase(string String) { + string[] Words = String.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); + Case[] WordsCase = new Case[Words.Length]; + for (int x = 0; x < Words.Length; x++) { + string Word = Words[x]; + for (int i = 0; i < Word.Length; i++) { + char Char = Word[i]; + if (Char > 0x8000) + return Case.Normal; + + if (i == 0) { + if (char.IsLetter(Char) && char.IsUpper(Char)) { + WordsCase[x] = (x == 0 || (char.IsPunctuation(Words[x - 1].Last()))) ? Case.Normal : Case.Title; + } else { + WordsCase[x] = Case.Lower; } + } else { + if (char.IsUpper(Char)) + WordsCase[x] = Case.Upper; break; - case 7: - int cCount = CountChars(Minified); - Status = !(Minified.Length < 6 && cCount < 6); - break; + } } - Process++; } - ExitWhile: - ; - if (!Status && !Trim) { - return IsDialog(String, true); - } - return Status; + int Titles = (from x in WordsCase where x == Case.Title select x).Count(); + int Upper = (from x in WordsCase where x == Case.Upper select x).Count(); + int Normal = (from x in WordsCase where x == Case.Normal select x).Count(); + int Lower = (from x in WordsCase where x == Case.Lower select x).Count(); + + if (Titles > Normal && Titles > Upper && Titles > Lower) + return Case.Title; + if (Upper > Titles && Upper > Normal && Upper > Lower) + return Case.Upper; + if (Lower > Titles && Lower > Upper && Lower > Normal) + return Case.Normal; + + return Case.Normal; } + static int CountChars(string Str) { List Chars = new List(); foreach (var chr in Str) { diff --git a/SRL/Types.cs b/SRL/Types.cs index 4a45d54..48b0d00 100644 --- a/SRL/Types.cs +++ b/SRL/Types.cs @@ -23,6 +23,10 @@ internal static void AppendArray(ref T[] Arr, T Val, bool CheckDouble = false NArr[Arr.Length] = Val; Arr = NArr; } + internal struct Quote { + public char Start; + public char End; + } #pragma warning disable 649 struct SRLData3 { @@ -167,9 +171,6 @@ struct SRLSettings { [FieldParmaters(DefaultValue = false, Name = "Multithread;DisablePipe")] public bool Multithread; - [FieldParmaters(DefaultValue = null, Name = "DenyChars;NoChars")] - public string DenyChars; - [FieldParmaters(DefaultValue = false, Name = "TrimRangeMismatch;TrimRange")] public bool TrimRangeMismatch; @@ -211,13 +212,6 @@ struct SRLSettings { [FieldParmaters(DefaultValue = null, Name = "BreakLine;GameBreakLine")] public string GameLineBreaker; - - [FieldParmaters(DefaultValue = null, Name = "MatchIgnore;IgnoreMatchs")] - public string MatchIgnore; - - [FieldParmaters(DefaultValue = null, Name = "TrimChars;TrimStrings")] - public string TrimChars; - [FieldParmaters(DefaultValue = null, Name = "WorkingDir;WorkDir;DataDir")] public string WorkDirectory; @@ -235,6 +229,9 @@ struct SRLSettings { [FieldParmaters(DefaultValue = false, Name = "RemoveIlegals;RemoveViolation;RemoveViolations;RemoveOutputViolation")] public bool RemoveViolations; + + [FieldParmaters(DefaultValue = false, Name = "AsianInput;FromAsian;JapaneseInput;FromJapanese")] + public bool AsianInput; } [FieldParmaters(Name = "WordWrap")] @@ -272,6 +269,20 @@ public struct OverlaySettings { [FieldParmaters(DefaultValue = null, Name = "Padding")] public string Padding; } + + [FieldParmaters(Name = "Filter")] + internal struct FilterSettings { + [FieldParmaters(DefaultValue = "", Name = "DenyList")] + public string DenyList; + [FieldParmaters(DefaultValue = "", Name = "IgnoreList")] + public string IgnoreList; + [FieldParmaters(DefaultValue = "", Name = "QuoteList")] + public string QuoteList; + [FieldParmaters(DefaultValue = "", Name = "TrimList")] + public string TrimList; + [FieldParmaters(DefaultValue = 2, Name = "Sensitivity")] + public int Sensitivity; + } #pragma warning restore 649 } } diff --git a/SRL/Variables.cs b/SRL/Variables.cs index 2f21bb8..ec0c756 100644 --- a/SRL/Variables.cs +++ b/SRL/Variables.cs @@ -93,6 +93,7 @@ struct Range { static bool ReloadMaskParameters = false; static bool LiteMode = false; static bool RemoveIlegals = false; + static bool AsianInput = false; static bool OverlayEnabled = false; @@ -109,6 +110,11 @@ struct Range { static int LogStack = 0; static int CursorX, CursorY; + + static string[] DenyList; + static string[] IgnoreList; + static Quote[] QuoteList; + static int Sensitivity; #if DEBUG static float LastDPI; @@ -132,6 +138,8 @@ struct Range { static DotNetVM EncodingModifier = null; static DotNetVM StringModifier = null; static DotNetVM Overlay = null; + + static bool DirectRequested = false; static string[] Replaces = new string[0]; static string TLMap => BaseDir + "Strings.srl"; @@ -153,7 +161,6 @@ struct Range { static BinaryReader PipeReader = null; static BinaryWriter PipeWriter = null; - static int LastDBID = 0; static int DBID = 0; static List> Databases = null; @@ -300,20 +307,13 @@ private static bool GameStarted() { return false; } } - + static Thread SettingsWatcher = null; static string[] MatchDel = new string[] { "\r", "\\r", "\n", "\\n", " ", "_r", "―", "-", "*", "♥", "①", "♪" }; - static string[] TrimChars = new string[] { - " ", "'", "<", "(", "[", "“", "[", "《", "«", - "「", "『", "【", "]", "”", "]", "》", - "»", "」", "』", "】", ")", ">", "‘", "’", "〃", "″", - "~", "~", "―", "-", "%K", "%LC", "♪", "%P" - }; - - static string DenyChars = "@,§,$,_,<,>,/,[,],#"; + static string[] TrimChars = new string[] { "%K", "%LC", "♪", "%P" }; } } diff --git a/SRLUnity/SRLUnity.csproj b/SRLUnity/SRLUnity.csproj index 0f139c9..9f52657 100644 --- a/SRLUnity/SRLUnity.csproj +++ b/SRLUnity/SRLUnity.csproj @@ -36,7 +36,6 @@ bin\x86\Debug\ TRACE;DEBUG;x86 full - x86 prompt MinimumRecommendedRules.ruleset diff --git a/packages/DllExport.1.6.0/gcache/metalib/SRL/DllExport.dll b/packages/DllExport.1.6.0/gcache/metalib/SRL/DllExport.dll index 2c67190..1e5891e 100644 Binary files a/packages/DllExport.1.6.0/gcache/metalib/SRL/DllExport.dll and b/packages/DllExport.1.6.0/gcache/metalib/SRL/DllExport.dll differ