Exemple #1
0
        internal GMFile(GMFileContent f)
        {
            Content = f;

            General = SectionReader.GetGeneralInfo(f);
            Options = SectionReader.GetOptionInfo(f);

            Sound        = Utils.UintRange(0, f.Sounds->Count).Select(i => SectionReader.GetSoundInfo(f, i)).ToArray();
            Sprites      = Utils.UintRange(0, f.Sprites->Count).Select(i => SectionReader.GetSpriteInfo(f, i)).ToArray();
            Backgrounds  = Utils.UintRange(0, f.Backgrounds->Count).Select(i => SectionReader.GetBgInfo(f, i)).ToArray();
            Paths        = Utils.UintRange(0, f.Paths->Count).Select(i => SectionReader.GetPathInfo(f, i)).ToArray();
            Scripts      = Utils.UintRange(0, f.Scripts->Count).Select(i => SectionReader.GetScriptInfo(f, i)).ToArray();
            Fonts        = Utils.UintRange(0, f.Fonts->Count).Select(i => SectionReader.GetFontInfo(f, i)).ToArray();
            Objects      = Utils.UintRange(0, f.Objects->Count).Select(i => SectionReader.GetObjectInfo(f, i)).ToArray();
            Rooms        = Utils.UintRange(0, f.Rooms->Count).Select(i => SectionReader.GetRoomInfo(f, i)).ToArray();
            TexturePages = Utils.UintRange(0, f.TexturePages->Count).Select(i => SectionReader.GetTexPageInfo(f, i)).ToArray();
            Code         = Utils.UintRange(0, f.Code->Count).Select(i => Disassembler.DisassembleCode(f, i)).ToArray();
            Strings      = Utils.UintRange(0, f.Strings->Count).Select(i => SectionReader.GetStringInfo(f, i)).ToArray();
            Textures     = Utils.UintRange(0, f.Textures->Count).Select(i => SectionReader.GetTextureInfo(f, i)).ToArray();
            Audio        = Utils.UintRange(0, f.Audio->Count).Select(i => SectionReader.GetAudioInfo(f, i)).ToArray();

            AudioSoundMap = new Dictionary <uint, uint>();
            for (uint i = 0; i < Sound.Length; i++)
            {
                var s = Sound[i];

                if ((s.IsEmbedded || s.IsCompressed) && s.AudioId != -1)
                {
                    AudioSoundMap[(uint)s.AudioId] = i;
                }
            }

            var vars = General.IsOldBCVersion ? SectionReader.GetRefDefs(f, f.Variables) : SectionReader.GetRefDefsWithOthers(f, f.Variables);
            var fns  = General.IsOldBCVersion ? SectionReader.GetRefDefs(f, f.Functions) : SectionReader.GetRefDefsWithLength(f, f.Functions);

            RefData = new RefData
            {
                Variables = vars,
                Functions = fns,

                VarAccessors  = Disassembler.GetReferenceTable(f, vars),
                FuncAccessors = Disassembler.GetReferenceTable(f, fns)
            };
        }
Exemple #2
0
        internal GMFile(GMFileContent f)
        {
            Content = f;

            var orderList = new List <SectionHeaders>(f.HeaderOffsets.Length);

            foreach (long headerOffset in f.HeaderOffsets)
            {
                SectionHeaders tag = ((SectionHeader *)((byte *)f.Form + headerOffset))->Identity;
                if (tag != SectionHeaders.Form)
                {
                    orderList.Add(tag);
                }
            }
            ChunkOrder = orderList.ToArray();

            if (f.General != null)
            {
                General = SectionReader.GetGeneralInfo(f);
            }
            if (f.Options != null)
            {
                Options = SectionReader.GetOptionInfo(f);
            }
            if (f.Globals != null)
            {
                Globals = SectionReader.GetGlobalInfo(f);
            }

            Sound = MkLazyArr(f.Sounds, i => SectionReader.GetSoundInfo(f, i));

            if (f.TexturePages != null)
            {
                var toil = SectionReader.BuildTPAGOffsetIndexLUT(f);
                Sprites = MkLazyArr(f.Sprites, i => SectionReader.GetSpriteInfo(f, i, toil));
            }

            Backgrounds  = MkLazyArr(f.Backgrounds, i => SectionReader.GetBgInfo(f, i));
            Paths        = MkLazyArr(f.Paths, i => SectionReader.GetPathInfo(f, i));
            Scripts      = MkLazyArr(f.Scripts, i => SectionReader.GetScriptInfo(f, i));
            Fonts        = MkLazyArr(f.Fonts, i => SectionReader.GetFontInfo(f, i));
            Objects      = MkLazyArr(f.Objects, i => SectionReader.GetObjectInfo(f, i));
            Rooms        = MkLazyArr(f.Rooms, i => SectionReader.GetRoomInfo(f, i));
            TexturePages = MkLazyArr(f.TexturePages, i => SectionReader.GetTexPageInfo(f, i));
            Code         = MkLazyArr(f.Code, i => Disassembler.DisassembleCode(f, i));
            Strings      = MkLazyArr(f.Strings, i => SectionReader.GetStringInfo(f, i));
            Textures     = MkLazyArr(f.Textures, i => SectionReader.GetTextureInfo(f, i));
            Audio        = MkLazyArr(f.Audio, i => SectionReader.GetAudioInfo(f, i));
            AudioGroups  = MkLazyArr(f.AudioGroup, i => SectionReader.GetAudioGroupInfo(f, i));
            Extensions   = MkLazyArr(f.Extensions, i => SectionReader.GetExtensionInfo(f, i));
            Shaders      = MkLazyArr(f.Shaders, i => SectionReader.GetShaderInfo(f, i));
            Timelines    = MkLazyArr(f.Timelines, i => SectionReader.GetTimelineInfo(f, i));

            AudioSoundMap = new Dictionary <uint, uint>();
            if (f.Sounds != null)
            {
                for (uint i = 0; i < Sound.Length; i++)
                {
                    var s = Sound[i];

                    if ((s.IsEmbedded || s.IsCompressed) && s.AudioID != -1 && s.GroupID == 0)
                    {
                        AudioSoundMap[(uint)s.AudioID] = i;
                    }
                }
            }

            if (f.General == null)
            {
                return;
            }

            try
            {
                // TODO: do this in a better way
                var vars = General.IsOldBCVersion
                    ? SectionReader.GetRefDefs(f, f.Variables)
                    : SectionReader.GetRefDefsWithOthers(f, f.Variables);
                var fns = General.IsOldBCVersion
                    ? SectionReader.GetRefDefs(f, f.Functions)
                    : SectionReader.GetRefDefsWithLength(f, f.Functions);

                var varacc = Disassembler.GetReferenceTable(f, vars);
                var fnacc  = Disassembler.GetReferenceTable(f, fns);

                RefData = new RefData
                {
                    Variables     = vars,
                    Functions     = fns,
                    VarAccessors  = varacc,
                    FuncAccessors = fnacc
                };

                if (f.Functions->Entries.NameOffset * 12 < f.Functions->Header.Size)
                {
                    FunctionLocals = SectionReader.GetFunctionLocals(f, f.Functions);
                }
                if (f.Variables != null && !General.IsOldBCVersion)
                {
                    VariableExtra = new uint[]
                    {
                        ((uint *)&f.Variables->Entries)[0],
                        ((uint *)&f.Variables->Entries)[1],
                        ((uint *)&f.Variables->Entries)[2]
                    }
                }
                ;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Warning: Can't figure out RefDef pairs. Exception:");
                Console.Error.WriteLine(e);
            }
        }