Example #1
0
        public GMLCode(GMAssets _assets, string _name, string _code, eGMLCodeType _type)
        {
            Name = _name.Replace(' ', '_').Replace('\t', '_');
            Code = _code;
            Type = _type;
            List <GMLError> _errors = null;

            Token  = GMLCompile.Compile(_assets, Name, Code, out _errors);
            Errors = _errors;
        }
Example #2
0
        public void Compile(GMAssets _assets)
        {
            switch (Kind)
            {
            case eAction.ACT_VARIABLE:
                if (Relative)
                {
                    Code = Code + Args[0] + " += " + Args[1];
                }
                else
                {
                    Code = Code + Args[0] + " = " + Args[1];
                }
                Kind = eAction.ACT_NORMAL;
                Args.Clear();
                break;

            case eAction.ACT_CODE:
                Code = Args[0];
                Kind = eAction.ACT_NORMAL;
                Args.Clear();
                if (Program.RemoveDND)
                {
                    List <GMLError> _errors            = null;
                    bool            inhibitErrorOutput = Program.InhibitErrorOutput;
                    Program.InhibitErrorOutput = true;
                    GMLCompile.Compile(_assets, "test_compile", Code, out _errors);
                    Program.InhibitErrorOutput = inhibitErrorOutput;
                    if (_errors.Count > 0)
                    {
                        foreach (GMLError item2 in _errors)
                        {
                            eErrorKind kind = item2.Kind;
                            if (kind == eErrorKind.Warning_Unclosed_Comment)
                            {
                                Code += "*/";
                            }
                        }
                    }
                }
                break;
            }
            if (IsQuestion && ExeType == eExecuteTypes.EXE_CODE)
            {
                Name = string.Format("__script{0}__", countScript);
                GMScript value = new GMScript(Code);
                KeyValuePair <string, GMScript> item = new KeyValuePair <string, GMScript>(Name, value);
                _assets.Scripts.Add(item);
                countScript++;
                ExeType = eExecuteTypes.EXE_FUNCTION;
            }
        }
Example #3
0
        private static int Main(string[] _args)
        {
            Trace.Write("------------ {1} {0} --------------", Assembly.GetExecutingAssembly().GetName().Version.ToString(), Assembly.GetExecutingAssembly().GetName().Name);

            /*if (!Debugger.IsAttached)
             * {
             *      AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
             * }*/
            //Unlike yoyogames. i see NO issue with running a debugger here :D
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            GMLCompile.Test();
            GMLCompile.Code_Init();
            HTMLRunner             = "C:\\source\\GameMaker\\Runner\\HTML5\\scripts";
            Verbose                = false;
            CompileVerbose         = false;
            Out                    = Console.Out;
            SplashOmit             = true;
            TextureType            = new eTexType[2];
            SeparateOpaqueAndAlpha = false;
            DisplaySortedTextures  = false;
            RemoveDND              = true;
            CenterHTML5Game        = false;
            NoCache                = false;
            HTMLRunner             = string.Empty;
            NoIndexHTML            = false;
            TextureGroups          = new Dictionary <string, List <string> >();
            DoObfuscate            = false;
            ObfuscateObfuscate     = true;
            ObfuscatePrettyPrint   = false;
            ObfuscateRemoveUnused  = true;
            ObfuscateEncodeStrings = true;
            LoadingBarName         = null;
            CustomLoadingScreen    = false;
            ExitCode               = 0;
            InhibitErrorOutput     = false;
            string PreObfuscateLib = string.Empty;

            TextureScale = 1;
            Studio       = false;
            m_options    = new OptionSet().Add("?|help", "display help usage", (Action <string>) delegate
            {
                ShowHelp();
            }).Add("m=|machine=", "set machine type (ios, psp, win, droid)", delegate(string m)
            {
                SetMachineType(m);
            }).Add("t=|tex=", "override opaque texture type (dxt,raw,pvr,png)", delegate(string s)
            {
                TextureType[0] = SetTextureType(s);
            })
                           .Add("at=|alphatex=", "override alpha texture type (dxt,raw,pvr,png)", delegate(string s)
            {
                TextureType[1] = SetTextureType(s);
            })
                           .Add("o=|outputDir=", "set output directory", delegate(string d)
            {
                OutputDir = d;
            })
                           .Add("w=|tpageWidth=", "set texture page width", delegate(int w)
            {
                TexturePageWidth = w;
            })
                           .Add("h=|tpageHeight=", "set texture page height", delegate(int h)
            {
                TexturePageHeight = h;
            })
                           .Add("wt|writeTextures", "optionally write textures generated to output directory", (Action <string>) delegate
            {
                WriteTextures = true;
            })
                           .Add("ww|writeWaves", "optionally write audio waves generated to output directory", (Action <string>) delegate
            {
                WriteTextures = true;
            })
                           .Add("so|splashOmit", "optionally disable writing of the Spash screen to output file", (Action <string>) delegate
            {
                SplashOmit = true;
            })
                           .Add("dst|DisplaySortedTextures", "optionally display sorted texture information", (Action <string>) delegate
            {
                DisplaySortedTextures = true;
            })
                           .Add("c|compile", "do not display gui compile only", (Action <string>) delegate
            {
                CompileOnly = true;
            })
                           .Add("s|separate", "separate the alpha and opaque textures (false by default)", (Action <string>) delegate
            {
                SeparateOpaqueAndAlpha = true;
            })
                           .Add("v|verbose", "output verbose debug info", (Action <string>) delegate
            {
                Verbose = true;
            })
                           .Add("nohtml", "do not output index.html", (Action <string>) delegate
            {
                NoIndexHTML = true;
            })
                           .Add("HTMLRunner=", "directory with HTML Runner (will be copied as scripts)", delegate(string d)
            {
                HTMLRunner = d;
            })
                           .Add("tg=|TextureGroup=", "Group resources onto texture pages comma param is a filename, file has format <groupname> : <comma delim list of resourcenames>, use # for comment (NOTE: entries MUST all be on the same line", delegate(string f)
            {
                string[] array4 = File.ReadAllLines(f);
                string[] array5 = array4;
                foreach (string text3 in array5)
                {
                    string text4 = text3.Trim().Replace(" ", "").Replace("\t", "");
                    if (!string.IsNullOrEmpty(text4) && !text4.StartsWith("#"))
                    {
                        string[] array6 = text4.Split(':');
                        if (array6.Length == 2)
                        {
                            string[] collection2 = array6[1].Split(',');
                            string key           = array6[0];
                            List <string> value  = new List <string>(collection2);
                            TextureGroups.Add(key, value);
                        }
                    }
                }
            })
                           .Add("to=|TextureOption=", "Set an option for a set of textures via <option> : <comma delimited list of resourcenames>. Valid options are: " + TextureOptions.ValidTextureOptions() + ")", delegate(string f)
            {
                string[] array  = File.ReadAllLines(f);
                string[] array2 = array;
                foreach (string text in array2)
                {
                    string text2 = text.Trim().Replace(" ", "").Replace("\t", "");
                    if (!string.IsNullOrEmpty(text2) && !text2.StartsWith("#"))
                    {
                        string[] array3 = text2.Split(':');
                        if (array3.Length == 2)
                        {
                            string[] collection     = array3[1].Split(',');
                            string optionName       = array3[0];
                            List <string> resources = new List <string>(collection);
                            TextureOptions.AddResourceOptions(optionName, resources);
                        }
                    }
                }
            })
                           .Add("nodnd", "remove any Drag and Drop (dnd)", (Action <string>) delegate
            {
                RemoveDND = true;
            })
                           .Add("obfuscate|ob", "obfuscate the Javascript output", (Action <string>) delegate
            {
                DoObfuscate = true;
            })
                           .Add("obfuscateDo=|obob=", "Really do the obfuscation (default true)", delegate(bool v)
            {
                ObfuscateObfuscate = v;
            })
                           .Add("obfuscatePrettyPrint=|obpp=", "when obfuscating Pretty Print the output (default false)", delegate(bool v)
            {
                ObfuscatePrettyPrint = v;
            })
                           .Add("obfuscateRemoveUnused=|obru=", "when obfuscating Remove Unused functions from the output (default true)", delegate(bool v)
            {
                ObfuscateRemoveUnused = v;
            })
                           .Add("obfuscateEncodeStrings=|obes=", "when obfuscating Encode strings in the output (default true)", delegate(bool v)
            {
                ObfuscateEncodeStrings = v;
            })
                           .Add("compileVerbose|cv", "switch on verbose mode when compiling the GML (default false)", (Action <string>) delegate
            {
                CompileVerbose = true;
            })
                           .Add("c_html5", "Center the HTML5 game in the browser", (Action <string>) delegate
            {
                CenterHTML5Game = true;
            })
                           .Add("nocache_html5", "Add the \"no cache\" option to the default index.html page", (Action <string>) delegate
            {
                NoCache = true;
            })
                           .Add("preObfuscateLib=|pob=", "Pre-Obfuscate a directory of JS files into a single file - keep GM public interface", delegate(string v)
            {
                PreObfuscateLib = v;
            })
                           .Add("textureScale=|ts=", "scale textures by an integer amount (default 1)", delegate(int v)
            {
                TextureScale = v;
            })
                           .Add("loadingbarcallback=", "Name of the loading bar callback function", delegate(string v)
            {
                LoadingBarName = v;
            })
                           .Add("customloadingimage", "Use the custom screen provided?", (Action <string>) delegate
            {
                CustomLoadingScreen = true;
            })
                           .Add("studio", "Enable Studio use...", (Action <string>) delegate
            {
                Studio = true;
            });
            List <string> list = m_options.Parse(_args);

            if (!string.IsNullOrEmpty(PreObfuscateLib))
            {
                DoPreObfuscateLib(PreObfuscateLib, OutputDir);
                return(ExitCode);
            }
            GMAssets gMAssets = null;

            foreach (string item in list)
            {
                if (File.Exists(item))
                {
                    gMAssets = Loader.Load(item);
                }
            }
            if (MachineType == null)
            {
                SetMachineType("ios");
            }
            if (gMAssets == null)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter           = "Exe files (*.exe, *.ios, *.psp, *.win, *.droid)|*.exe;*.ios;*.psp;*.win;*.droid|All files (*.*)|*.*";
                openFileDialog.FilterIndex      = 1;
                openFileDialog.RestoreDirectory = true;
                if (openFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return(-1);
                }
                gMAssets = Loader.Load(openFileDialog.FileName);
            }
            if (OutputDir == null)
            {
                if (gMAssets != null)
                {
                    OutputDir = Path.GetDirectoryName(gMAssets.FileName);
                }
            }
            Assets = gMAssets;
            if (!CompileOnly)
            {
                Application.Run(new Form1(gMAssets));
            }
            else
            {
                string extension = MachineType.Extension;
                if (Studio)
                {
                    extension = ".zip";
                }
                string name = Path.Combine(OutputDir, Path.ChangeExtension(Path.GetFileName(gMAssets.FileName), extension));
                switch (MachineType.OutputType)
                {
                case eOutputType.eWAD:
                    IFFSaver.Save(gMAssets, name);
                    break;

                case eOutputType.eHTML5:
                    HTML5Saver.Save(gMAssets, name);
                    break;
                }
            }
            return(ExitCode);
        }
Example #4
0
        private static void CompileSimpleVariable(GMLToken _tok, StringWriter _sw, bool _lvalue, out bool _setFunc, bool _inhibitExpansion)
        {
            string      text  = null;
            string      text2 = _tok.Text;
            GMLVariable value = null;

            if (!GMLCompile.ms_builtins.TryGetValue(text2, out value))
            {
                GMLCompile.ms_builtinsLocal.TryGetValue(text2, out value);
            }
            _setFunc = false;
            if (value != null)
            {
                if (_lvalue && value.setFunction != null)
                {
                    text2    = string.Format("{0}( ", value.setFunction);
                    _setFunc = true;
                }
                else if (!_lvalue && value.getFunction != null)
                {
                    text2 = string.Format("{0}()", value.getFunction);
                }
            }
            else
            {
                text2 = ms_varPrefix + text2;
            }
            text = text2;
            if (!_inhibitExpansion && _tok.Id < 100000 && GMLCompile.ms_builtins.TryGetValue(_tok.Text, out value) && !ms_arguments.TryGetValue(_tok.Text, out text))
            {
                string empty = string.Empty;
                empty = ((!(text2 == "argument_count")) ? string.Format("g_pBuiltIn.{0}", text2) : string.Format("({0}.arguments.length-2)", ms_code.Name));
                _sw.Write(empty);
            }
            else if (!_inhibitExpansion && ms_globals.TryGetValue(_tok.Text, out text))
            {
                string value2 = string.Format("global.{0}", text2);
                _sw.Write(value2);
            }
            else if (_inhibitExpansion || ms_locals.TryGetValue(text2, out text) || ms_arguments.TryGetValue(_tok.Text, out text) || string.IsNullOrEmpty(ms_thisName.Peek()))
            {
                _sw.Write(text);
            }
            else if (!_inhibitExpansion && GMLCompile.Find(ms_assets.Objects, _tok.Text) >= 0)
            {
                _sw.Write(GMLCompile.Find(ms_assets.Objects, _tok.Text).ToString());
            }
            else
            {
                string value3 = string.Format("{0}.{1}", ms_thisName.Peek(), text2);
                _sw.Write(value3);
            }
            bool   flag   = false;
            string value4 = "]";
            string text3  = string.Empty;

            if (_tok.Children.Count > 0)
            {
                string text4 = _sw.GetStringBuilder().ToString();
                if (text4 == "g_pBuiltIn.instance_id")
                {
                    _sw.GetStringBuilder().Length = 0;
                    _sw.Write("g_pBuiltIn.get_instance_id(");
                    value4 = ")";
                    flag   = true;
                }
                else if (text4 == "g_pBuiltIn.argument")
                {
                    _sw.GetStringBuilder().Length = 0;
                    _sw.Write("{0}.arguments[", ms_code.Name);
                    text3 = "2+";
                    flag  = true;
                }
                else
                {
                    int    num  = text4.LastIndexOf('.');
                    string arg  = (num < 0) ? "_inst" : text4.Substring(0, num);
                    string arg2 = (num < 0) ? text4 : text4.Substring(num + 1, text4.Length - (num + 1));
                    _sw.GetStringBuilder().Length = 0;
                    _setFunc = _lvalue;
                    if (_lvalue)
                    {
                        string value5 = string.Format("array_set_{0}D( {1}, \"__{2}__\" ", _tok.Children.Count, arg, arg2);
                        _sw.Write(value5);
                    }
                    else
                    {
                        string value6 = string.Format("array_get_{0}D( {1}, \"__{2}__\" ", _tok.Children.Count, arg, arg2);
                        _sw.Write(value6);
                    }
                }
            }
            ms_thisName.Pop();
            if (_tok.Token != eToken.eVariable)
            {
                return;
            }
            int num2 = 0;

            foreach (GMLToken child in _tok.Children)
            {
                if (!flag || num2 > 0)
                {
                    _sw.Write(", ");
                }
                if (!string.IsNullOrEmpty(text3))
                {
                    _sw.Write("{0} (", text3);
                }
                CompileExpression(child, _sw);
                if (!string.IsNullOrEmpty(text3))
                {
                    _sw.Write(")");
                }
                num2++;
            }
            if (_tok.Children.Count > 0)
            {
                if (flag)
                {
                    _sw.Write(value4);
                }
                else if (_lvalue)
                {
                    _sw.Write(",  ");
                }
                else
                {
                    _sw.Write(" ) ");
                }
            }
        }