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); } }