Example #1
0
 public void Compile(GMAssets _assets, GMLCode _code)
 {
     Code = _code;
     if (Program.CompileVerbose)
     {
         RewriteTree(_code.Token);
         CompileProgram(_code.Token);
         Disasm(Program.Out);
     }
 }
Example #2
0
        public static void Save(GMAssets _assets, string _name)
        {
            ms_code.Clear();
            if (Program.RemoveDND)
            {
                _assets.RemoveDND();
                foreach (KeyValuePair <string, GMScript> script in _assets.Scripts)
                {
                    if (script.Value != null && !string.IsNullOrEmpty(script.Value.Script))
                    {
                        GMLCode code   = new GMLCode(_assets, script.Key, script.Value.Script, eGMLCodeType.eScript);
                        GML2VM  gML2VM = new GML2VM();
                        gML2VM.Compile(_assets, code);
                        ms_code.Add(gML2VM);
                    }
                }
                foreach (KeyValuePair <string, GMObject> @object in _assets.Objects)
                {
                    if (@object.Value != null)
                    {
                        foreach (IList <KeyValuePair <int, GMEvent> > @event in @object.Value.Events)
                        {
                            foreach (KeyValuePair <int, GMEvent> item in @event)
                            {
                                if (item.Value != null && item.Value.Actions != null && item.Value.Actions.Count > 0 && item.Value.Actions[0].Kind == eAction.ACT_CODE)
                                {
                                    GMLCode code2   = new GMLCode(_assets, @object.Key, item.Value.Actions[0].Args[0], eGMLCodeType.eEvent);
                                    GML2VM  gML2VM2 = new GML2VM();
                                    gML2VM2.Compile(_assets, code2);
                                    ms_code.Add(gML2VM2);
                                }
                            }
                        }
                    }
                }
                foreach (KeyValuePair <string, GMTimeLine> timeLine in _assets.TimeLines)
                {
                    if (timeLine.Value != null)
                    {
                        foreach (KeyValuePair <int, GMEvent> entry in timeLine.Value.Entries)
                        {
                            if (entry.Value != null && entry.Value.Actions != null && entry.Value.Actions.Count > 0 && entry.Value.Actions[0].Kind == eAction.ACT_CODE)
                            {
                                GMLCode code3   = new GMLCode(_assets, timeLine.Key, entry.Value.Actions[0].Args[0], eGMLCodeType.eEvent);
                                GML2VM  gML2VM3 = new GML2VM();
                                gML2VM3.Compile(_assets, code3);
                                ms_code.Add(gML2VM3);
                            }
                        }
                    }
                }
                foreach (GMTrigger trigger in _assets.Triggers)
                {
                    if (trigger != null)
                    {
                        GMLCode code4   = new GMLCode(_assets, trigger.Name, trigger.Condition, eGMLCodeType.eTrigger);
                        GML2VM  gML2VM4 = new GML2VM();
                        gML2VM4.Compile(_assets, code4);
                        ms_code.Add(gML2VM4);
                    }
                }
                foreach (KeyValuePair <string, GMRoom> room in _assets.Rooms)
                {
                    if (room.Value != null)
                    {
                        if (!string.IsNullOrEmpty(room.Value.Code))
                        {
                            GMLCode code5   = new GMLCode(_assets, room.Key, room.Value.Code, eGMLCodeType.eRoomCreate);
                            GML2VM  gML2VM5 = new GML2VM();
                            gML2VM5.Compile(_assets, code5);
                            ms_code.Add(gML2VM5);
                        }
                        foreach (GMInstance instance in room.Value.Instances)
                        {
                            if (!string.IsNullOrEmpty(instance.Code))
                            {
                                GMLCode code6   = new GMLCode(_assets, room.Key, instance.Code, eGMLCodeType.eRoomInstanceCreate);
                                GML2VM  gML2VM6 = new GML2VM();
                                gML2VM6.Compile(_assets, code6);
                                ms_code.Add(gML2VM6);
                            }
                        }
                    }
                }
            }
            ms_tpageSprites = new TexturePage(2, 2, 0, 0, Program.MachineType.TPageWidth, Program.MachineType.TPageHeight);
            ms_Waves.Clear();
            Program.Out.WriteLine("Saving IFF file... {0}", _name);
            List <string> list = new List <string>();

            if (Path.GetExtension(_name) == ".zip")
            {
                using (FileStream stream = File.Create(_name))
                {
                    ZipOutputStream zipOutputStream = new ZipOutputStream(stream);
                    zipOutputStream.PutNextEntry(string.Format("assets\\game{0}", Program.MachineType.Extension));
                    Save(_assets, zipOutputStream, list);
                    foreach (string item2 in list)
                    {
                        if (File.Exists(item2))
                        {
                            string entryName = Path.Combine("assets", Path.GetFileName(item2));
                            zipOutputStream.PutNextEntry(entryName);
                            byte[] array = File.ReadAllBytes(item2);
                            zipOutputStream.Write(array, 0, array.Length);
                        }
                    }
                    zipOutputStream.Close();
                }
            }
            else
            {
                using (FileStream stream2 = File.Create(_name))
                {
                    Save(_assets, stream2, list);
                }
            }
        }
Example #3
0
        public static void Compile(GMAssets _assets, GMLCode _code, TextWriter _sw)
        {
            ms_assets    = _assets;
            ms_code      = _code;
            ms_numErrors = 0;
            ms_error     = false;
            Console.WriteLine("Compiling - {0}", _code.Name);
            _sw.WriteLine("\n// #####################################################################################################");
            string[] array  = _code.Code.Split('\n');
            string[] array2 = array;
            foreach (string text in array2)
            {
                string text2 = text.Replace('\r', ' ');
                text2 = text2.Replace('\n', ' ');
                _sw.WriteLine("// {0}", text2);
            }
            ms_arguments.Clear();
            switch (_code.Type)
            {
            case eGMLCodeType.eRoomCreate:
                _sw.WriteLine("function {0}(_inst)", _code.Name);
                ms_thisName.Push("_inst");
                ms_otherName.Push("_inst");
                break;

            case eGMLCodeType.eScript:
            {
                GatherArgs(_code.Token);
                _sw.Write("function {0}( _inst, _other ", _code.Name);
                for (int j = 0; j < ms_arguments.Count; j++)
                {
                    string text3 = string.Format("argument{0}", j);
                    string value = string.Empty;
                    if (!ms_arguments.TryGetValue(text3, out value))
                    {
                        Error(string.Format("argument naming error, {0} arguments but no reference found to {1}", ms_arguments.Count, text3), _code.Token);
                    }
                    _sw.Write(", {0}", text3);
                }
                _sw.Write(")");
                ms_thisName.Push("_inst");
                ms_otherName.Push("_other");
                break;
            }

            case eGMLCodeType.eRoomInstanceCreate:
                _sw.WriteLine("function {0}( _inst )", _code.Name);
                ms_thisName.Push("_inst");
                ms_otherName.Push("_inst");
                break;

            case eGMLCodeType.eEvent:
            case eGMLCodeType.eTrigger:
                _sw.WriteLine("function {0}( _inst, _other )", _code.Name);
                ms_thisName.Push("_inst");
                ms_otherName.Push("_other");
                break;

            case eGMLCodeType.eConstant:
                _sw.WriteLine("function {0}()", _code.Name);
                ms_thisName.Push("");
                ms_otherName.Push("");
                break;
            }
            DummyStream  stream = new DummyStream();
            StreamWriter sw     = new StreamWriter(stream);
            int          num    = ms_unique;

            ms_locals.Clear();
            ms_arrays.Clear();
            ms_breakContext.Clear();
            ms_statements = 0;
            CompileProgram(_code.Token, sw);
            if (!ms_error)
            {
                ms_unique = num;
                ms_locals.Clear();
                ms_breakContext.Clear();
                ms_statements = 0;
                CompileProgram(_code.Token, _sw);
            }
            ms_thisName.Pop();
            ms_otherName.Pop();
        }
Example #4
0
        public static void Save(GMAssets _assets, string _name)
        {
            String InputFolder = Path.Combine(Program.OutputDir, "_iso_temp");

            _name = Path.Combine(Program.OutputDir, "_iso_temp", "PSP_GAME", "USRDIR", "games", "game.psp"); // Allways "game.psp"

            ms_code.Clear();
            if (Program.RemoveDND)
            {
                _assets.RemoveDND();
                foreach (KeyValuePair <string, GMScript> script in _assets.Scripts)
                {
                    if (script.Value != null && !string.IsNullOrEmpty(script.Value.Script))
                    {
                        GMLCode code   = new GMLCode(_assets, script.Key, script.Value.Script, eGMLCodeType.eScript);
                        GML2VM  gML2VM = new GML2VM();
                        gML2VM.Compile(_assets, code);
                        ms_code.Add(gML2VM);
                    }
                }
                foreach (KeyValuePair <string, GMObject> @object in _assets.Objects)
                {
                    if (@object.Value != null)
                    {
                        foreach (IList <KeyValuePair <int, GMEvent> > @event in @object.Value.Events)
                        {
                            foreach (KeyValuePair <int, GMEvent> item in @event)
                            {
                                if (item.Value != null && item.Value.Actions != null && item.Value.Actions.Count > 0 && item.Value.Actions[0].Kind == eAction.ACT_CODE)
                                {
                                    GMLCode code2   = new GMLCode(_assets, @object.Key, item.Value.Actions[0].Args[0], eGMLCodeType.eEvent);
                                    GML2VM  gML2VM2 = new GML2VM();
                                    gML2VM2.Compile(_assets, code2);
                                    ms_code.Add(gML2VM2);
                                }
                            }
                        }
                    }
                }
                foreach (KeyValuePair <string, GMTimeLine> timeLine in _assets.TimeLines)
                {
                    if (timeLine.Value != null)
                    {
                        foreach (KeyValuePair <int, GMEvent> entry in timeLine.Value.Entries)
                        {
                            if (entry.Value != null && entry.Value.Actions != null && entry.Value.Actions.Count > 0 && entry.Value.Actions[0].Kind == eAction.ACT_CODE)
                            {
                                GMLCode code3   = new GMLCode(_assets, timeLine.Key, entry.Value.Actions[0].Args[0], eGMLCodeType.eEvent);
                                GML2VM  gML2VM3 = new GML2VM();
                                gML2VM3.Compile(_assets, code3);
                                ms_code.Add(gML2VM3);
                            }
                        }
                    }
                }
                foreach (GMTrigger trigger in _assets.Triggers)
                {
                    if (trigger != null)
                    {
                        GMLCode code4   = new GMLCode(_assets, trigger.Name, trigger.Condition, eGMLCodeType.eTrigger);
                        GML2VM  gML2VM4 = new GML2VM();
                        gML2VM4.Compile(_assets, code4);
                        ms_code.Add(gML2VM4);
                    }
                }
                foreach (KeyValuePair <string, GMRoom> room in _assets.Rooms)
                {
                    if (room.Value != null)
                    {
                        if (!string.IsNullOrEmpty(room.Value.Code))
                        {
                            GMLCode code5   = new GMLCode(_assets, room.Key, room.Value.Code, eGMLCodeType.eRoomCreate);
                            GML2VM  gML2VM5 = new GML2VM();
                            gML2VM5.Compile(_assets, code5);
                            ms_code.Add(gML2VM5);
                        }
                        foreach (GMInstance instance in room.Value.Instances)
                        {
                            if (!string.IsNullOrEmpty(instance.Code))
                            {
                                GMLCode code6   = new GMLCode(_assets, room.Key, instance.Code, eGMLCodeType.eRoomInstanceCreate);
                                GML2VM  gML2VM6 = new GML2VM();
                                gML2VM6.Compile(_assets, code6);
                                ms_code.Add(gML2VM6);
                            }
                        }
                    }
                }
            }
            ms_tpageSprites = new TexturePage(2, 2, 0, 0, Program.MachineType.TPageWidth, Program.MachineType.TPageHeight);
            ms_Waves.Clear();
            Program.Out.WriteLine("Saving IFF file... {0}", _name);
            List <string> list = new List <string>();

            if (Path.GetExtension(_name) == ".zip")
            {
                using (FileStream stream = File.Create(_name))
                {
                    ZipOutputStream zipOutputStream = new ZipOutputStream(stream);
                    zipOutputStream.PutNextEntry(string.Format("assets\\game{0}", Program.MachineType.Extension));
                    Save(_assets, zipOutputStream, list);
                    foreach (string item2 in list)
                    {
                        if (File.Exists(item2))
                        {
                            string entryName = Path.Combine("assets", Path.GetFileName(item2));
                            zipOutputStream.PutNextEntry(entryName);
                            byte[] array = File.ReadAllBytes(item2);
                            zipOutputStream.Write(array, 0, array.Length);
                        }
                    }
                    zipOutputStream.Close();
                }
            }
            else
            {
                using (FileStream stream2 = File.Create(_name))
                {
                    Save(_assets, stream2, list);
                }
            }
            String ISOPath = Path.Combine(Program.OutputDir, Path.ChangeExtension(Program.Assets.FileName, "ISO"));

            Console.WriteLine("Building ISO");

            String UmiFile = Path.Combine(Program.OutputDir, "UmiFile.umi");
            String UflFile = Path.ChangeExtension(UmiFile, "ufl");

            UMDGEN.CreateUmi(UmiFile);
            UMDGEN.CreateUfl(UflFile, InputFolder);
            UMDGEN.CreateISO(UmiFile, Program.OutputDir);

            File.Delete(Path.Combine(Program.OutputDir, "UMD_AUTH.DAT"));
            File.Delete(Path.Combine(Program.OutputDir, "CONT_L0.IMG"));
            File.Delete(Path.Combine(Program.OutputDir, "MDI.IMG"));
            File.Delete(Path.Combine(Program.OutputDir, "UmiFile.ufl"));
            File.Delete(Path.Combine(Program.OutputDir, "UmiFile.umi"));
            if (File.Exists(ISOPath))
            {
                File.Delete(ISOPath);
            }

            File.Move(Path.Combine(Program.OutputDir, "USER_L0.IMG"), ISOPath);
            if (Directory.Exists(InputFolder))
            {
                Directory.Delete(InputFolder, true);
            }
            Console.WriteLine("Done!");

            MessageBox.Show("ISO Built @ " + ISOPath, "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }