Skip to content

Commit

Permalink
Big Update
Browse files Browse the repository at this point in the history
New Call Method, more faster
  • Loading branch information
marcussacana committed Jul 2, 2018
1 parent d165d7b commit 47c8123
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 100 deletions.
56 changes: 47 additions & 9 deletions SRL/FileWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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("/", "\\");
Expand All @@ -380,6 +417,7 @@ private static void LoadConfig() {
Log("Custom Directory Loaded", true);
}


Log("Settings Loaded.", true);

if (Managed) {
Expand Down
18 changes: 16 additions & 2 deletions SRL/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions SRL/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
11 changes: 9 additions & 2 deletions SRL/Reloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion SRL/SRL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<DllExportOurILAsm>true</DllExportOurILAsm>
<DllExportLeaveIntermediateFiles>false</DllExportLeaveIntermediateFiles>
<DllExportTimeout>300000</DllExportTimeout>
<DllExportPeCheck>2</DllExportPeCheck>
<DllExportPeCheck>3</DllExportPeCheck>
</PropertyGroup>
<Import Project="$(SolutionDir)packages\DllExport.1.6.0\tools\net.r_eg.DllExport.targets" Condition="Exists('$(SolutionDir)packages\DllExport.1.6.0\tools\net.r_eg.DllExport.targets')" Label="8337224c9ad9e356" />
<Target Name="DllExportRestorePkg" BeforeTargets="PrepareForBuild">
Expand Down
16 changes: 10 additions & 6 deletions SRL/SRL.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[StringReloader]
InEncoding=Unicode
OutEncoding=Unicode
Encoding=Unicode
Wide=true
Debug=false
Delay=false
Expand All @@ -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
Expand All @@ -37,6 +33,7 @@ ReloadMaskArgs=true
CustomCredits=
LiteMode=false
RemoveViolations=true
AsianInput=false

[WordWrap]
Enable=false
Expand All @@ -54,4 +51,11 @@ TargetLang=EN
[Overlay]
Enabled=false
ShowNative=false
Padding=Top: 0|Bottom: 0|Left: 0|Rigth: 0
Padding=Top: 0|Bottom: 0|Left: 0|Rigth: 0

[Filter]
DenyList=@,§,$,_,<,>,/,[,]
QuoteList=<>,(),[],“”,[],《》,«»,「」,『』,【】,(),'',""
IgnoreList=
TrimList= ,%K,%LC,♪,%P
Sensitivity=3
Loading

0 comments on commit 47c8123

Please sign in to comment.