Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussacana committed May 11, 2023
1 parent 9664133 commit 8bfd401
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 23 deletions.
48 changes: 34 additions & 14 deletions StringReloads/Engine/SRL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,15 @@ private void TriggerFlags(LSTFlag[] Flags) {
}

internal List<object> HasMatchLocks = new List<object>();
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)
{
Expand All @@ -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;
Expand All @@ -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)
{
Expand All @@ -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<object> MatchStringLocks = new List<object>();
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)
{
Expand All @@ -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<object> ResolveRemapLocks = new List<object>();
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)
{
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down
65 changes: 57 additions & 8 deletions StringReloads/Engine/String/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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[] { '。', '?', '!', '…', '、', '―' };
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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--;

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion StringReloads/Engine/Unmanaged/Alloc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8bfd401

Please sign in to comment.