Ejemplo n.º 1
0
        internal static IOptimizator[] SearchOptimizators(string Filter)
        {
            var Optimizators = new IOptimizator[0];

            foreach (string PluginPath in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, Filter))
            {
                try {
                    string Content = File.ReadAllText(PluginPath, System.Text.Encoding.UTF8);
                    Content = Content.Replace("IPlugin", "IOptimizator");

                    int IO = Content.Substring(0, Content.IndexOf("class")).IndexOf("using ");
                    if (IO < 0)
                    {
                        IO = 0;
                    }

                    Content = Content.Substring(0, IO) +
                              "using TLBOT.Optimizator;\n" +
                              Content.Substring(IO);
                    try {
                        DotNetVM VM      = new DotNetVM(Content, DotNetVM.Language.CSharp);
                        Type[]   Classes = VM.Assembly.GetTypes().Where(x => typeof(IOptimizator).IsAssignableFrom(x)).ToArray();

                        foreach (Type Class in Classes)
                        {
                            IOptimizator Plugin = (IOptimizator)Activator.CreateInstance(Class);
                            Optimizators = Optimizators.AppendArray(Plugin);
                        }
                    } catch (Exception ex) {
                        MessageBox.Show(ex.ToString(), string.Format("TLBOT 2 - {0} Error", System.IO.Path.GetFileName(PluginPath)), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                } catch { }
            }
            return(Optimizators);
        }
Ejemplo n.º 2
0
 public PluginCreator(PluginInfo Info, PluginHandler Handler)
 {
     VM     = Handler.VM;
     Name   = Info.Name;
     Type   = Info.Type;
     Filter = Info.Extensions;
     Class  = Handler.ImportPath.Split('>').First();
     InitializeWithScript = Handler.InitializeWithScript;
 }
Ejemplo n.º 3
0
        private string[] TryImport(string Plugin, byte[] Script)
        {
            ExportPath = Ini.GetConfig("Plugin", "Export;Exp;export;exp", Plugin, true);
            ImportPath = Ini.GetConfig("Plugin", "Import;Imp;import;imp", Plugin, true);
            string CustomSource = Ini.GetConfig("Plugin", "File;file;Archive;archive;Arc;arc", Plugin, false);

#if MONO
            string Path        = System.IO.Path.GetDirectoryName(Plugin) + "/",
                   SourcePath  = System.IO.Path.GetDirectoryName(Plugin) + "/",
                   SourcePath2 = System.IO.Path.GetDirectoryName(Plugin) + "/";
#else
            string Path        = System.IO.Path.GetDirectoryName(Plugin) + "\\",
                   SourcePath  = System.IO.Path.GetDirectoryName(Plugin) + "\\",
                   SourcePath2 = System.IO.Path.GetDirectoryName(Plugin) + "\\";
#endif

            if (!string.IsNullOrWhiteSpace(CustomSource))
            {
                Path        += CustomSource + ".dll";
                SourcePath  += CustomSource + ".cs";
                SourcePath2 += CustomSource + ".vb";
            }
            else
            {
                Path        += System.IO.Path.GetFileNameWithoutExtension(Plugin) + ".dll";
                SourcePath  += System.IO.Path.GetFileNameWithoutExtension(Plugin) + ".cs";
                SourcePath2 += System.IO.Path.GetFileNameWithoutExtension(Plugin) + ".vb";
            }

            //Initialize Plugin
            bool InitializeWithScript = Ini.GetConfig("Plugin", "Initialize;InputOnCreate;initialize;inputoncreate", Plugin, false).ToLower() == "true";
            if (File.Exists(SourcePath))
            {
                this.Plugin = new DotNetVM(File.ReadAllText(SourcePath, Encoding.UTF8), DotNetVM.Language.CSharp);
            }
            else if (File.Exists(SourcePath2))
            {
                this.Plugin = new DotNetVM(File.ReadAllText(SourcePath2, Encoding.UTF8), DotNetVM.Language.VisualBasic);
            }
            else
            {
                this.Plugin = new DotNetVM(File.ReadAllBytes(Path));
            }

            //Import
            Lastest = Plugin;
            string[] Imp = ImportPath.Split('>');
            if (InitializeWithScript)
            {
                this.Plugin.StartInstance(Imp[0], Script);
                return((string[])this.Plugin.Call(Imp[0], Imp[1]));
            }
            return((string[])this.Plugin.Call(Imp[0], Imp[1], Script));
        }
Ejemplo n.º 4
0
        private async Task <string[]> TryImport(PluginInfo Plugin, byte[] Script)
        {
            if (string.IsNullOrWhiteSpace(Plugin.File))
            {
                return(null);
            }

            if (!string.IsNullOrWhiteSpace(Plugin.Dependencies))
            {
                foreach (string Dependencie in Plugin.Dependencies.Split(';'))
                {
                    try
                    {
                        byte[] DepData = await Download(Dependencie);

                        System.Reflection.Assembly.Load(DepData);
                    }
                    catch { }
                }
            }

            var Handler = await GetPluginHandler(Plugin);

            this.Plugin = Handler.VM;

            ImportPath = Handler.ImportPath;
            ExportPath = Handler.ExportPath;
            bool InitializeWithScript = Handler.InitializeWithScript;

            //Import
            Lastest = Plugin;
            string[] Imp = ImportPath.Split('>');
            if (InitializeWithScript)
            {
                this.Plugin.StartInstance(Imp[0], Script);
                return((string[])this.Plugin.Call(Imp[0], Imp[1]));
            }
            return((string[])this.Plugin.Call(Imp[0], Imp[1], Script));
        }
Ejemplo n.º 5
0
        private string[] TryImport(string Plugin, byte[] Script)
        {
            ExportPath = Ini.GetConfig("Plugin", "Export;Exp;export;exp", Plugin, true);
            ImportPath = Ini.GetConfig("Plugin", "Import;Imp;import;imp", Plugin, true);
            string CustomSource = Ini.GetConfig("Plugin", "File;file;Archive;archive;Arc;arc", Plugin, false);

            string Path        = System.IO.Path.GetDirectoryName(Plugin) + "/",
                   SourcePath  = System.IO.Path.GetDirectoryName(Plugin) + "/",
                   SourcePath2 = System.IO.Path.GetDirectoryName(Plugin) + "/";


            if (!string.IsNullOrWhiteSpace(CustomSource))
            {
                Path        += CustomSource + ".dll";
                SourcePath  += CustomSource + ".cs";
                SourcePath2 += CustomSource + ".vb";
            }
            else
            {
                Path        += System.IO.Path.GetFileNameWithoutExtension(Plugin) + ".dll";
                SourcePath  += System.IO.Path.GetFileNameWithoutExtension(Plugin) + ".cs";
                SourcePath2 += System.IO.Path.GetFileNameWithoutExtension(Plugin) + ".vb";
            }

            DateTime Source1Time = DateTime.MinValue;
            DateTime Source2Time = DateTime.MinValue;
            DateTime DLLTime     = DateTime.MinValue;

            if (File.Exists(SourcePath))
            {
                Source1Time = new FileInfo(SourcePath).LastWriteTimeUtc;
            }
            if (File.Exists(SourcePath2))
            {
                Source2Time = new FileInfo(SourcePath2).LastWriteTimeUtc;
            }
            if (File.Exists(Path))
            {
                DLLTime = new FileInfo(Path).LastWriteTimeUtc;
            }

            string Source = null;

#if DebugPlugin
            bool Debug = true;
#else
            bool Debug = false;
#endif

            //Initialize Plugin
            bool InitializeWithScript = Ini.GetConfig("Plugin", "Initialize;InputOnCreate;initialize;inputoncreate", Plugin, false).ToLower() == "true";
            if (File.Exists(SourcePath) && Source1Time > Source2Time && Source1Time > DLLTime)
            {
                this.Plugin = new DotNetVM(File.ReadAllText(SourcePath, Encoding.UTF8), DotNetVM.Language.CSharp, Path, Debug);
                Source      = SourcePath;
            }
            else if (File.Exists(SourcePath2) && Source2Time > Source1Time && Source2Time > DLLTime)
            {
                this.Plugin = new DotNetVM(File.ReadAllText(SourcePath2, Encoding.UTF8), DotNetVM.Language.VisualBasic, Path, Debug);
                Source      = SourcePath2;
            }
            else
            {
                this.Plugin = new DotNetVM(File.ReadAllBytes(Path));
            }

            //Import
            Lastest = Plugin;
            string[] Imp = ImportPath.Split('>');
            if (InitializeWithScript)
            {
                this.Plugin.StartInstance(Imp[0], Script);
                return((string[])this.Plugin.Call(Imp[0], Imp[1]));
            }
            return((string[])this.Plugin.Call(Imp[0], Imp[1], Script));
        }
Ejemplo n.º 6
0
        internal static void Init()
        {
            try {
                if (Initialized)
                {
                    Log("Ops, Initialization Requested... But, is already initialized...", true);
                    return;
                }

                if (!CloseEventAdded)
                {
                    CloseEventAdded = true;
                    AppDomain.CurrentDomain.ProcessExit += ProcessOver;
                    new Thread(ShowLoading).Start();
                }

                CheckArguments();
                if (Debugging)
                {
                    Log(ConsoleColor.Green, "Strings Reloads - v" + SRLVersion, true);
                    Log(ConsoleColor.Green, "Soft-Translation Engine - By Marcussacana", true);
                    Log(ConsoleColor.Green, "Debug Mode Enabled...", true);
                }
                LoadConfig();

                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 {
                        DotNetVM VM = new DotNetVM(File.ReadAllText(BaseDir + "EncodingModifier.cs", Encoding.UTF8));
                        EncodingModifier = VM;
                        Log("Encoding Modifier Compiled", true);
                    } catch (Exception ex) {
                        Error("Failed to compile the Encoding Modifier\n===========\n{0}\n===========\n{1}", ex.Message, ex.Source);
                    }
                }

                if (File.Exists(BaseDir + "StringModifier.cs"))
                {
                    Log("Enabling String Modifier...", true);
                    try {
                        DotNetVM VM = new DotNetVM(File.ReadAllText(BaseDir + "StringModifier.cs", Encoding.UTF8));
                        StringModifier = VM;
                        Log("String Modifier Compiled", true);
                    } catch (Exception ex) {
                        Error("Failed to compile the String Modifier\n===========\n{0}\n===========\n{1}", ex.Message, ex.Source);
                    }
                }

                //I Implement This to prevent
                if (!PECSVal(File.ReadAllBytes(SrlDll)))
                {
#if DEBUG
                    Warning("SRL Engine - Unauthenticated Debug Build");
#else
                    Error("SRL Engine - Unauthenticated Public Build");
                    return;
#endif
                }

                if (File.Exists(OEDP) && Overlay == null)
                {
                    Overlay = new DotNetVM(File.ReadAllBytes(OEDP));
                    Log("Overlay Enabled.", true);
                }

                if (File.Exists(TLDP) && TLIB == null)
                {
                    AdvancedIni.FastOpen(out MTLSettings Settings, IniPath);
                    if (Settings.Enabled)
                    {
                        SourceLang  = Settings.SourceLang;
                        TargetLang  = Settings.TargetLang;
                        MassiveMode = Settings.MassiveMode;
                        TLIB        = new DotNetVM(File.ReadAllBytes(TLDP));
                        Log("Machine Translation Enabled", true);
                    }
                }

                if (!File.Exists(TLMap) || Ini.GetConfig(CfgName, "Rebuild", IniPath, false).ToLower() == "true")
                {
                    Log("Unabled to load the {0}", true, TLMap);
                    bool ContainsSplitedList = Directory.GetFiles(BaseDir, Path.GetFileName(string.Format(TLMapSrcMsk, "*"))).Length != 0;

                    if (File.Exists(TLMapSrc) || ContainsSplitedList)
                    {
                        Log("Compiling String Reloads, Please Wait...");
                        CompileStrMap();
                    }
                    else
                    {
                        NoDatabase = true;
                        StrRld     = CreateDictionary();
                        Warning("Can't Compile Strings because the SRL don't found any LST.");
                    }
                }

                if (!NoDatabase)
                {
                    LoadData();
                    InstallIntroInjector();
                }

                if (Debugging && File.Exists(TLMapSrc))
                {
                    Log("Loading Dumped Data...");

                    var Strs = new List <string>();
                    var Ign  = new List <string>();
                    ReadDump(TLMapSrc, ref Strs, ref Ign, true);

                    foreach (string str in Strs)
                    {
                        AddMissed(SimplfyMatch(str));
                    }

                    Log("Dumped Data Loaded, {0} Entries Loaded.", false, Strs.Count);
                }

                if (TLIB != null && File.Exists(MTLCache))
                {
                    Log("Loading MTL Cache...", true);
                    List <string> Ori = new List <string>();
                    List <string> TL  = new List <string>();
                    ReadDump(MTLCache, ref Ori, ref TL);

                    for (int i = 0; i < Ori.Count; i++)
                    {
                        string Match = SimplfyMatch(Ori[i]);
                        if (AllowDuplicates || !ContainsKey(Match))
                        {
                            AddEntry(Match, ReplaceChars(TL[i]));
                        }
                    }
                }
            } catch (Exception ex) {
                Error("Failed to Initialize...");
                PreserveStackTrace(ex);
                throw ex;
            }
        }