Exemple #1
0
        private void GenerateBlocks()
        {
            return; // it can brake scripts so fak it

            for (int m = 0; m < ScriptContent.Length; m++)
            {
                try
                {
                    if (ScriptContent[m] == "{" && !ScriptContent[m - 1].Contains("func"))
                    {
                        int     methodStartIdx = m + 1;
                        int     end            = 0;
                        EMethod blockMethod    = new EMethod();
                        blockMethod.Name    = "Block_" + GlobalVars.RandomString(10);
                        blockMethod.Options = new List <string>()
                        {
                            "Hidden", "ESCRIPT"
                        };

                        for (int c = methodStartIdx; c < ScriptContent.Length; c++)
                        {
                            if (!ScriptContent[c].StartsWith("}"))
                            {
                                if (ScriptContent[c].Length <= 0)
                                {
                                    continue;
                                }
                                if (ScriptContent[c].StartsWith("//"))
                                {
                                    continue;
                                }

                                blockMethod.Code.Add(ScriptContent[c]);
                            }
                            else
                            {
                                end = c;
                                break;
                            }
                        }

                        GlobalVars.Methods.Add(blockMethod);
                        ScriptContent    = GlobalVars.RemoveEntries(ScriptContent, m + 1, end);
                        ScriptContent[m] = ScriptContent[m].Replace("{", blockMethod.Name);
                        Program.Debug($"Added block: {blockMethod.Name} at {m} line");
                    }
                }
                catch { }
            }
        }
Exemple #2
0
        private void GenerateMethods()
        {
            for (int m = 0; m < ScriptContent.Length; m++)//methods & labels & dirtycode
            {
                if (ScriptContent[m].Length <= 1)
                {
                    continue;
                }
                if (ScriptContent[m].StartsWith("//"))
                {
                    continue;
                }
                if (ScriptContent[m].StartsWith("func "))
                {
                    int methodStartIdx = 0;
                    if (ScriptContent[m + 1].StartsWith("{"))
                    {
                        methodStartIdx = m + 2;
                    }
                    EMethod thisMethod = new EMethod();
                    thisMethod.Name = ScriptContent[m].Remove(0, "func ".Length).Split(' ')[0];
                    try
                    {
                        var argList1         = ScriptContent[m].Remove(0, "func ".Length + thisMethod.Name.Length + 1);
                        var mth              = Cmd.GetMethodsInsideOfString(argList1);
                        var argListNoDefault = argList1;

                        foreach (var argStr in mth)
                        {
                            string fstr = "=" + argStr.text.ToString();
                            argListNoDefault = argListNoDefault.Replace(fstr, "");
                        }

                        var argList = argListNoDefault.Split(' ').ToList();

                        foreach (var arg in argList)
                        {
                            if (arg.StartsWith("(") && arg.EndsWith(")"))
                            {
                                thisMethod.Options.Add(arg.Remove(0, 1).Remove(arg.Length - 2, 1));
                                continue;
                            }
                            EMethodArgument argObj = new EMethodArgument();
                            argObj.Name = arg;
                            foreach (var argStr in mth)
                            {
                                string fstr = arg + "=" + argStr.text.ToString();
                                if (argList1.Contains(fstr))
                                {
                                    argObj.DefaultValue = argStr.text.ToString().Remove(0, 1).Remove(argStr.text.ToString().Length - 2, 1);
                                }
                                else
                                {
                                }
                            }
                            thisMethod.Arguments.Add(argObj);
                        }
                    }
                    catch
                    {
                        //EConsole.WriteLine($"ERROR PROCESSING {thisMethod.Name}!{Environment.NewLine}{ex.ToString()}", true, ConsoleColor.Red);
                    }

                    int end = 0;
                    for (int c = methodStartIdx; c < ScriptContent.Length; c++)
                    {
                        if (!ScriptContent[c].StartsWith("}") && !ScriptContent[m].StartsWith("//"))
                        {
                            ScriptContent[c] = GlobalVars.RemoveDirtFromString(ScriptContent[c]);

                            if (ScriptContent[c].Length <= 0)
                            {
                                continue;
                            }
                            if (ScriptContent[c].StartsWith("//"))
                            {
                                continue;
                            }

                            thisMethod.Code.Add(ScriptContent[c]);
                        }
                        else
                        {
                            end = c;
                            break;
                        }
                    }
                    m = end;

                    for (int x = 0; x < GlobalVars.Methods.Count; x++)
                    {
                        if (GlobalVars.Methods[x].Name == thisMethod.Name)
                        {
                            Program.Debug($"Overwriting exiting method ({thisMethod.Name})");
                            GlobalVars.Methods.Remove(GlobalVars.Methods[x]);
                        }
                    }

                    GlobalVars.Methods.Add(thisMethod);

                    Program.Debug("Added method: " + thisMethod.Name + ", line: " + m + 1, ConsoleColor.DarkGreen);


                    if (thisMethod.Arguments.Count >= 1)
                    {
                        Program.Debug("Arguments:");
                        foreach (var argument in thisMethod.Arguments)
                        {
                            Program.Debug($"\t{argument.Name} = {argument.DefaultValue}");
                        }
                    }

                    if (thisMethod.Options.Count >= 1)
                    {
                        Program.Debug("Options:");
                        foreach (var option in thisMethod.Options)
                        {
                            Program.Debug($"\t{option}");
                        }
                    }
                }
            }
        }