Beispiel #1
0
        public static LuaResult Compile(
            StaticMetaTables staticTables,
            string source,
            dynamic globals = null,
            string name = null)
        {
            var result = new LuaResult();
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            try
            {
                var stream = new ANTLRStringStream(source);
                var lexer = new ChunkLexer(stream);
                var tokenStream = new CommonTokenStream(lexer);
                var parser = new ChunkParser(tokenStream);

                var r = parser.chunk();
                result.Errors.AddRange(parser.Errors);

                Expression e;
                var scope = Scope.NewTopLevelScop();
                var chunk = new Chunk();
                result.Errors.AddRange(chunk.Generate(staticTables, scope, r.Tree, out e));

                var fnExp = Expression.Lambda<Func<Table, object>>(e, scope.Env.GlobalParameter);
                result.Chunk = new CompiledChunk(fnExp.Compile(), globals ?? new Table(), name);
            }
            finally
            {
                stopwatch.Stop();
                result.ElapsedTime = stopwatch.Elapsed;
                result.Success = !result.Errors.ContainsError();
            }
            return result;
        }
Beispiel #2
0
        public virtual IEnumerable <Chunk> GetChunks(ColorScheme style, DocumentLine line, int offset, int length)
        {
            SpanParser  spanParser  = CreateSpanParser(line, null);
            ChunkParser chunkParser = CreateChunkParser(spanParser, style, line);
            Chunk       result      = chunkParser.GetChunks(chunkParser.lineOffset, line.Length);

            if (SemanticRules != null)
            {
                foreach (SemanticRule sematicRule in SemanticRules)
                {
                    sematicRule.Analyze(doc, line, result, offset, offset + length);
                }
            }
            if (result != null)
            {
                // crop to begin
                if (result.Offset < offset)
                {
                    while (result != null && result.EndOffset < offset)
                    {
                        result = result.Next;
                    }
                    if (result != null)
                    {
                        int endOffset = result.EndOffset;
                        result.Offset = offset;
                        result.Length = endOffset - offset;
                    }
                }
            }
            while (result != null)
            {
                // crop to end
                if (result.EndOffset >= offset + length)
                {
                    result.Length = offset + length - result.Offset;
                    result.Next   = null;
                    if (result.Length < 0)
                    {
                        result.Length = 0;
                        yield break;
                    }
                }
                yield return(result);

                result = result.Next;
            }
        }
Beispiel #3
0
        public virtual Chunk GetChunks(Document doc, ColorSheme style, LineSegment line, int offset, int length)
        {
            SpanParser  spanParser  = CreateSpanParser(doc, this, line, null);
            ChunkParser chunkParser = CreateChunkParser(spanParser, doc, style, this, line);
            Chunk       result      = chunkParser.GetChunks(chunkParser.lineOffset, line.EditableLength);

            if (SemanticRules != null)
            {
                foreach (SemanticRule sematicRule in SemanticRules)
                {
                    sematicRule.Analyze(doc, line, result, offset, offset + length);
                }
            }
            if (result != null)
            {
                // crop to begin
                if (result.Offset != offset)
                {
                    while (result != null && result.EndOffset < offset)
                    {
                        result = result.Next;
                    }
                    if (result != null)
                    {
                        int endOffset = result.EndOffset;
                        result.Offset = offset;
                        result.Length = endOffset - offset;
                    }
                }

                if (result != null && offset + length != chunkParser.lineOffset + line.EditableLength)
                {
                    // crop to end
                    Chunk cur = result;
                    while (cur != null && cur.EndOffset < offset + length)
                    {
                        cur = cur.Next;
                    }
                    if (cur != null)
                    {
                        cur.Length = offset + length - cur.Offset;
                        cur.Next   = null;
                    }
                }
            }

            return(result);
        }
Beispiel #4
0
        public void ShouldConcatDecompressCompressAndThenSplitImage()
        {
            string       filePath       = @"../../../Data/lena.png";
            List <Chunk> chunks         = PNGFile.Read(filePath);
            List <Chunk> parsedChunks   = ChunkParser.Parse(chunks);
            int          firstIdatIndex = parsedChunks.TakeWhile(chunk => !IsIDAT(chunk)).Count();
            List <IDAT>  idats          = parsedChunks.Where(IsIDAT).Select(chunk => (IDAT)chunk).ToList();

            byte[]       bytes             = IDATConverter.ConcatToBytes(idats);
            byte[]       decompressedBytes = ZlibCompression.Decompress(bytes);
            byte[]       compressedBytes   = ZlibCompression.Compress(decompressedBytes);
            List <Chunk> resultIdats       = IDATConverter.SplitToIDATs(compressedBytes).Select(idat => (Chunk)idat).ToList();
            List <Chunk> resultChunks      = parsedChunks.Where(chunk => !IsIDAT(chunk)).ToList();

            resultChunks.InsertRange(firstIdatIndex, resultIdats);
            PNGFile.Write(@"../../../Data/lenaCompressed.png", resultChunks);
        }
			public override void Analyze(TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
			{
				// Check line start
				int o = line.Offset;
				char c = '\0';
				for (; o < line.EndOffset && char.IsWhiteSpace(c = doc.GetCharAt(o)); o++) ;

				if (c != '-' && c != '#')
					return;

				DSyntax.Document = doc;
				var spanParser = new SpanParser(DSyntax, new CloneableStack<Span>());
				var chunkP = new ChunkParser(DSyntax, spanParser, Ide.IdeApp.Workbench.ActiveDocument.Editor.ColorStyle, line);

				var n = chunkP.GetChunks(startOffset, endOffset - startOffset);
				if (n == null)
					return;
				startChunk.Next = n;
				startChunk.Length = n.Offset - startChunk.Offset;
			}
Beispiel #6
0
        //Engine file constructor
        public Level(string enginePath)
        {
            path = Path.GetDirectoryName(enginePath);

            // Engine elements
            using (EngineParser engineParser = new EngineParser(enginePath))
            {
                game = engineParser.GetGameType();

                //REMOVE THESE ASAP!!!!!111
                renderDefBytes   = engineParser.GetRenderDefBytes();
                collBytesEngine  = engineParser.GetCollisionBytes();
                billboardBytes   = engineParser.GetBillboardBytes();
                soundConfigBytes = engineParser.GetSoundConfigBytes();

                LOGGER.Debug("Parsing skybox...");
                skybox = engineParser.GetSkyboxModel();
                LOGGER.Debug("Success");

                LOGGER.Debug("Parsing moby models...");
                mobyModels = engineParser.GetMobyModels();
                LOGGER.Debug("Added {0} moby models", mobyModels.Count);

                LOGGER.Debug("Parsing tie models...");
                tieModels = engineParser.GetTieModels();
                LOGGER.Debug("Added {0} tie models", tieModels.Count);

                LOGGER.Debug("Parsing shrub models...");
                shrubModels = engineParser.GetShrubModels();
                LOGGER.Debug("Added {0} shrub models", shrubModels.Count);

                LOGGER.Debug("Parsing weapons...");
                gadgetModels = engineParser.GetGadgets();
                LOGGER.Debug("Added {0} weapons", gadgetModels.Count);

                LOGGER.Debug("Parsing textures...");
                textures = engineParser.GetTextures();
                LOGGER.Debug("Added {0} textures", textures.Count);

                LOGGER.Debug("Parsing ties...");
                ties = engineParser.GetTies(tieModels);
                LOGGER.Debug("Added {0} ties", ties.Count);

                LOGGER.Debug("Parsing Shrubs...");
                shrubs = engineParser.GetShrubs(shrubModels);
                LOGGER.Debug("Added {0} shrubs", shrubs.Count);

                LOGGER.Debug("Parsing Lights...");
                lights = engineParser.GetLights();
                LOGGER.Debug("Added {0} lights", lights.Count);

                LOGGER.Debug("Parsing terrain elements...");
                terrainEngine = engineParser.GetTerrainModel();
                LOGGER.Debug("Added {0} terrain elements", terrainEngine.fragments.Count);

                LOGGER.Debug("Parsing player animations...");
                playerAnimations = engineParser.GetPlayerAnimations((MobyModel)mobyModels[0]);
                LOGGER.Debug("Added {0} player animations", playerAnimations.Count);

                uiElements = engineParser.GetUiElements();
                LOGGER.Debug("Added {0} ui elements", uiElements.Count);

                lightConfig        = engineParser.GetLightConfig();
                textureConfigMenus = engineParser.GetTextureConfigMenu();

                collisionEngine = engineParser.GetCollisionModel();

                unk3 = engineParser.GetUnk3Bytes();
                unk4 = engineParser.GetUnk4Bytes();
                unk5 = engineParser.GetUnk5Bytes();
                unk8 = engineParser.GetUnk8Bytes();
                unk9 = engineParser.GetUnk9Bytes();
            }


            // Gameplay elements
            using (GameplayParser gameplayParser = new GameplayParser(game, path + @"/gameplay_ntsc"))
            {
                LOGGER.Debug("Parsing Level variables...");
                levelVariables = gameplayParser.GetLevelVariables();

                LOGGER.Debug("Parsing mobs...");
                mobs = gameplayParser.GetMobies(mobyModels);
                LOGGER.Debug("Added {0} mobs", mobs.Count);

                LOGGER.Debug("Parsing splines...");
                splines = gameplayParser.GetSplines();
                LOGGER.Debug("Added {0} splines", splines.Count);

                LOGGER.Debug("Parsing languages...");
                english   = gameplayParser.GetEnglish();
                ukenglish = gameplayParser.GetUkEnglish();
                french    = gameplayParser.GetFrench();
                german    = gameplayParser.GetGerman();
                spanish   = gameplayParser.GetSpanish();
                italian   = gameplayParser.GetItalian();
                japanese  = gameplayParser.GetJapanese();
                korean    = gameplayParser.GetKorean();

                LOGGER.Debug("Parsing other gameplay assets...");
                unk6  = gameplayParser.GetUnk6();
                unk7  = gameplayParser.GetUnk7();
                unk12 = gameplayParser.GetUnk12();
                unk13 = gameplayParser.GetUnk13();
                unk14 = gameplayParser.GetUnk14();
                unk16 = gameplayParser.GetUnk16();
                unk17 = gameplayParser.GetUnk17();
                unk18 = gameplayParser.GetUnk18();

                tieData   = gameplayParser.GetTieData(ties.Count);
                shrubData = gameplayParser.GetShrubData(shrubs.Count);

                tieGroupData   = gameplayParser.GetTieGroups();
                shrubGroupData = gameplayParser.GetShrubGroups();

                areasData = gameplayParser.GetAreasData();

                directionalLights = gameplayParser.GetDirectionalLights();
                type0Cs           = gameplayParser.GetType0Cs();
                spheres           = gameplayParser.GetSpheres();
                cylinders         = gameplayParser.GetCylinders();
                type4Cs           = gameplayParser.GetType4Cs();
                type7Cs           = gameplayParser.GetType7Cs();
                type80s           = gameplayParser.GetType80();
                type88s           = gameplayParser.GetType88s();
                type50s           = gameplayParser.GetType50s();
                type5Cs           = gameplayParser.GetType5Cs();

                pVars       = gameplayParser.GetPvars(mobs);
                cuboids     = gameplayParser.GetCuboids();
                gameCameras = gameplayParser.GetGameCameras();

                mobyIds       = gameplayParser.GetMobyIds();
                tieIds        = gameplayParser.GetTieIds();
                shrubIds      = gameplayParser.GetShrubIds();
                occlusionData = gameplayParser.GetOcclusionData();
            }

            terrainChunks   = new List <Terrain>();
            collisionChunks = new List <Model>();
            collBytesChunks = new List <byte[]>();

            for (int i = 0; i < 5; i++)
            {
                var chunkPath = Path.Join(path, @"chunk" + i + ".ps3");
                if (!File.Exists(chunkPath))
                {
                    continue;
                }

                using (ChunkParser chunkParser = new ChunkParser(chunkPath, game))
                {
                    terrainChunks.Add(chunkParser.GetTerrainModels());
                    collisionChunks.Add(chunkParser.GetCollisionModel());
                    collBytesChunks.Add(chunkParser.GetCollBytes());
                }
            }

            List <string> armorPaths = ArmorHeader.FindArmorFiles(game, enginePath);

            armorModels   = new List <Model>();
            armorTextures = new List <List <Texture> >();

            foreach (string armor in armorPaths)
            {
                LOGGER.Debug("Looking for armor data in {0}", armor);
                List <Texture> tex;
                MobyModel      model;
                using (ArmorParser parser = new ArmorParser(game, armor))
                {
                    tex   = parser.GetTextures();
                    model = parser.GetArmor();
                }

                string vram = armor.Replace(".ps3", ".vram");

                using (VramParser parser = new VramParser(vram))
                {
                    parser.GetTextures(tex);
                }

                if (model != null)
                {
                    armorModels.Add(model);
                }

                armorTextures.Add(tex);
            }

            string gadgetPath = GadgetHeader.FindGadgetFile(game, enginePath);

            gadgetTextures = new List <Texture>();

            if (gadgetPath != "")
            {
                LOGGER.Debug("Looking for gadget data in {0}", gadgetPath);
                using (GadgetParser parser = new GadgetParser(game, gadgetPath))
                {
                    gadgetModels.AddRange(parser.GetModels());
                    gadgetTextures.AddRange(parser.GetTextures());
                }

                using (VramParser parser = new VramParser(gadgetPath.Replace(".ps3", ".vram")))
                {
                    parser.GetTextures(gadgetTextures);
                }
            }

            List <string> missionPaths = MissionHeader.FindMissionFiles(game, enginePath);

            missions = new List <Mission>();

            for (int i = 0; i < missionPaths.Count; i++)
            {
                string missionPath = missionPaths[i];
                string vramPath    = missionPath.Replace(".ps3", ".vram");

                if (!File.Exists(vramPath))
                {
                    LOGGER.Warn("Could not find .vram file for {0}", missionPath);
                    continue;
                }

                LOGGER.Debug("Looking for mission data in {0}", missionPath);

                Mission mission = new Mission(i);

                using (MissionParser parser = new MissionParser(game, missionPath))
                {
                    mission.models   = parser.GetModels();
                    mission.textures = parser.GetTextures();
                }

                using (VramParser parser = new VramParser(vramPath))
                {
                    parser.GetTextures(mission.textures);
                }

                missions.Add(mission);
            }

            using (VramParser vramParser = new VramParser(path + @"/vram.ps3"))
            {
                vramParser.GetTextures(textures);
            }

            LOGGER.Info("Level parsing done");
            valid = true;
        }