diff --git a/StringReloads/Engine/SRL.cs b/StringReloads/Engine/SRL.cs index 367290b..87b2f57 100644 --- a/StringReloads/Engine/SRL.cs +++ b/StringReloads/Engine/SRL.cs @@ -248,11 +248,15 @@ private void TriggerFlags(LSTFlag[] Flags) { } internal List HasMatchLocks = new List(); - public bool HasMatch(string String) => HasMatch(null, String); + internal bool HasMatch(string String) => HasMatch(null, String); public bool HasMatch(IMatch This, string String) { + bool Locked = false; if (This != null && !HasMatchLocks.Contains(This)) + { HasMatchLocks.Add(This); + Locked = true; + } foreach (var Match in Matchs) { @@ -261,13 +265,13 @@ public bool HasMatch(IMatch This, string String) var Rst = Match.HasMatch(String); if (Rst) { - if (HasMatchLocks.Contains(This)) + if (HasMatchLocks.Contains(This) && Locked) HasMatchLocks.Remove(This); return true; } } - if (HasMatchLocks.Contains(This)) + if (HasMatchLocks.Contains(This) && Locked) HasMatchLocks.Remove(This); return false; @@ -277,8 +281,12 @@ public bool HasMatch(IMatch This, string String) public bool HasValue(string String) => HasValue(null, String); public bool HasValue(IMatch This, string String) { + bool Locked = false; if (This != null && !HasValueLocks.Contains(This)) + { HasValueLocks.Add(This); + Locked = true; + } foreach (var Match in Matchs) { @@ -287,27 +295,31 @@ public bool HasValue(IMatch This, string String) var Rst = Match.HasValue(String); if (Rst) { - if (HasValueLocks.Contains(This)) + if (HasValueLocks.Contains(This) && Locked) HasValueLocks.Remove(This); return true; } } - if (HasValueLocks.Contains(This)) + if (HasValueLocks.Contains(This) && Locked) HasValueLocks.Remove(This); return false; } internal List MatchStringLocks = new List(); - public LSTEntry? MatchString(string String) => MatchString(null, String); + internal LSTEntry? MatchString(string String) => MatchString(null, String); public LSTEntry? MatchString(IMatch This, string String) { if (string.IsNullOrWhiteSpace(String)) return null; + bool Locked = false; if (This != null && !MatchStringLocks.Contains(This)) + { MatchStringLocks.Add(This); + Locked = true; + } foreach (var Match in Matchs) { @@ -316,26 +328,30 @@ public bool HasValue(IMatch This, string String) var Rst = Match.MatchString(String); if (Rst != null) { - if (MatchStringLocks.Contains(This)) + if (MatchStringLocks.Contains(This) && Locked) MatchStringLocks.Remove(This); return Rst; } } - if (MatchStringLocks.Contains(This)) + if (MatchStringLocks.Contains(This) && Locked) MatchStringLocks.Remove(This); return null; } internal List ResolveRemapLocks = new List(); - public char ResolveRemap(char Char) => ResolveRemap(null, Char); + internal char ResolveRemap(char Char) => ResolveRemap(null, Char); public char ResolveRemap(IMatch This, char Char) { if (!Initialized) Initializer.Initialize(this); + bool Locked = false; if (This != null && !ResolveRemapLocks.Contains(This)) + { ResolveRemapLocks.Add(This); + Locked = true; + } foreach (var Match in Matchs) { @@ -344,22 +360,26 @@ public char ResolveRemap(IMatch This, char Char) var Rst = Match.ResolveRemap(Char); if (Rst != null) { - if (ResolveRemapLocks.Contains(This)) + if (ResolveRemapLocks.Contains(This) && Locked) ResolveRemapLocks.Remove(This); return Rst.Value; } } - if (ResolveRemapLocks.Contains(This)) + if (ResolveRemapLocks.Contains(This) && Locked) ResolveRemapLocks.Remove(This); return Char; } - public FontRemap? ResolveRemap(string Face, int Width, int Height, uint Charset) => ResolveRemap(null, Face, Width, Height, Charset); + internal FontRemap? ResolveRemap(string Face, int Width, int Height, uint Charset) => ResolveRemap(null, Face, Width, Height, Charset); public FontRemap? ResolveRemap(IMatch This, string Face, int Width, int Height, uint Charset) { + bool Locked = false; if (This != null && !ResolveRemapLocks.Contains(This)) + { ResolveRemapLocks.Add(This); + Locked = true; + } foreach (var Match in Matchs) { @@ -368,13 +388,13 @@ public char ResolveRemap(IMatch This, char Char) var Rst = Match.ResolveRemap(Face, Width, Height, Charset); if (Rst != null) { - if (ResolveRemapLocks.Contains(This)) + if (ResolveRemapLocks.Contains(This) && Locked) ResolveRemapLocks.Remove(This); return Rst.Value; } } - if (ResolveRemapLocks.Contains(This)) + if (ResolveRemapLocks.Contains(This) && Locked) ResolveRemapLocks.Remove(This); return null; diff --git a/StringReloads/Engine/String/Extensions.cs b/StringReloads/Engine/String/Extensions.cs index a3971cf..662cc44 100644 --- a/StringReloads/Engine/String/Extensions.cs +++ b/StringReloads/Engine/String/Extensions.cs @@ -229,7 +229,8 @@ public static bool IsDialogue(this string String, int? Caution = null, bool UseA if ((UseDB ?? Config.Default.Filter.UseDB) && EntryPoint.SRL.HasMatch(String)) return true; - string Str = String.Trim(); + + string Str = String.Trim(); Str = Str.Replace(Config.Default.BreakLine, "\n"); foreach (string Ignore in IgnoreList) @@ -247,6 +248,8 @@ public static bool IsDialogue(this string String, int? Caution = null, bool UseA if (UseAcceptableRange && CharacterRanges.TotalMissmatch(Str, Config.Default.Filter.AcceptableRange) > 0) return false; + string[] ScriptPatterns = new string[] { "!=", "<=", ">=", "==", "+=", "-=", "->", "//", ");", "*-", "null", "&&", "||" }; + string[] Words = Str.Split(' '); char[] PontuationJapList = new char[] { '。', '?', '!', '…', '、', '―' }; @@ -307,7 +310,7 @@ public static bool IsDialogue(this string String, int? Caution = null, bool UseA } try { - char Last = (LineQuotes == null ? Str.Last() : Str.TrimEnd(LineQuotes.Value.End).Last()); + char Last = (LineQuotes == null ? Str.Last() : Str.TrimEnd(LineQuotes?.End ?? ' ').Last()); if (IsJap && PontuationJapList.Contains(Last)) Points -= 3; @@ -318,7 +321,7 @@ public static bool IsDialogue(this string String, int? Caution = null, bool UseA catch { } try { - char First = (LineQuotes == null ? Str.First() : Str.TrimEnd(LineQuotes.Value.Start).First()); + char First = (LineQuotes == null ? Str.First() : Str.TrimEnd(LineQuotes?.Start ?? ' ').First()); if (IsJap && PontuationJapList.Contains(First)) Points -= 3; @@ -330,21 +333,39 @@ public static bool IsDialogue(this string String, int? Caution = null, bool UseA if (!IsJap) { + int NumberOnly = 0; + int LetterOnly = 0; foreach (string Word in Words) { int WNumbers = Word.Where(c => char.IsNumber(c)).Count(); int WLetters = Word.Where(c => char.IsLetter(c)).Count(); + int WNumSpecials = Word.Where(c => c == ',' || c == '.').Count(); + + WLetters -= WNumSpecials; + if (WLetters > 0 && WNumbers > 0) { Points += 2; } + + if (WLetters <= 0 && WNumbers > 0) + NumberOnly++; + if (WNumbers <= 0 && WLetters > 0) + LetterOnly++; + if (Word.Trim(PontuationList).Where(c => PontuationList.Contains(c)).Count() != 0) { Points += 2; } } + + if (NumberOnly > LetterOnly) + Points += NumberOnly > LetterOnly * 2 ? 2 : 1; } + if (string.IsNullOrWhiteSpace(Str.Trim().Trim(Str.First()))) + Points = 3;//Discard pontuation checks + if (!BeginQuote && !char.IsLetter(Str.First())) Points += 2; @@ -369,24 +390,51 @@ public static bool IsDialogue(this string String, int? Caution = null, bool UseA if (Spaces > WordCount * 2) Points++; - if (Uppers > Spaces + 1 && !IsCaps) - Points++; - if (IsJap && Spaces == 0) Points--; if (!IsJap && Spaces == 0) Points += 2; - if (WordCount <= 2 && Numbers != 0 && !Config.Default.Filter.AllowNumbers) + if (WordCount <= 2 && Numbers != 0) Points += (int)(Str.PercentOf(Numbers) / 10); if (Str.Length <= 3 && !IsJap) Points++; - if (Numbers >= (IsJap ? Kanjis + JapChars : Latim)) + if (Numbers >= Str.Length) Points += 3; + foreach (var Pattern in ScriptPatterns) + { + if (Str.ToLowerInvariant().Replace(" ", "").Contains(Pattern)) + Points += 2; + } + + //Detect dots followed of a non space character + if (!IsJap && Str.Trim().TrimEnd('.').Contains(".")) + { + var Count = Str.Trim().TrimEnd('.').Split('.').Skip(1).Count(x => !string.IsNullOrEmpty(x) && !char.IsWhiteSpace(x.FirstOrDefault())); + if (Count > 0) + Points++; + } + + if (!IsJap && WordCount == 1 && char.IsUpper(Str.First()) && !char.IsPunctuation(Str.TrimEnd().Last())) + Points++; + + if (!IsJap && WordCount == 1 && !char.IsUpper(Str.First())) + Points++; + + if (Words.Where(x => x.Skip(1).Where(y => char.IsUpper(y)).Count() > 1 + && x.Where(y => char.IsLower(y)).Count() > 1).Any()) + Points++; + + if (!IsJap && char.IsUpper(Str.TrimStart().First()) && char.IsPunctuation(Str.TrimEnd().Last())) + Points--; + + if (!char.IsPunctuation(Str.TrimEnd().Last())) + Points++; + if (IsJap && Kanjis / 2 > JapChars) Points--; @@ -411,6 +459,7 @@ public static bool IsDialogue(this string String, int? Caution = null, bool UseA if (Str.Trim().Trim(Str.Trim().First()) == string.Empty) Points += 2; + if (IsJap != Config.Default.Filter.FromAsian) return false; diff --git a/StringReloads/Engine/Unmanaged/Alloc.cs b/StringReloads/Engine/Unmanaged/Alloc.cs index 13ff891..30173a3 100644 --- a/StringReloads/Engine/Unmanaged/Alloc.cs +++ b/StringReloads/Engine/Unmanaged/Alloc.cs @@ -6,7 +6,7 @@ namespace StringReloads.Engine.Unmanaged { - unsafe static class Alloc + public unsafe static class Alloc { const uint HEAP_ZERO_MEMORY = 0x00000008; public static void* CreateHeap(byte[] Data) {