public void Load() { if (IsLoaded) { return; } if (IsUnloaded) { throw new InvalidOperationException("Cannot reload object once it's unloaded"); } if ((NumGlommed > 0) || (ObjectSizeInFile > 0)) { byte[] buffer; if (IsCompressed) { int dataLen = 8 * NumGlommed + ObjectSizeInFile; int maxLen = dataLen + 8; buffer = new byte[maxLen]; // Decompress DataBuffer using (var ms = new System.IO.MemoryStream(DataBuffer)) using (var istream = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(ms, new ICSharpCode.SharpZipLib.Zip.Compression.Inflater(false))) { int readBytes = istream.Read(buffer, 0, maxLen); Zeroes = readBytes - dataLen; //istream.Read(buffer, 0, 0xF); } } else { string path = String.Format("/resources/systemgenerated/prototypes/{0}.node", this.Id); TorLib.File protoFile = TorLib.Assets.FindFile(path); using (var fs = protoFile.Open()) using (var br = new GomBinaryReader(fs, Encoding.UTF8)) { br.ReadBytes(NodeDataOffset); buffer = br.ReadBytes(ObjectSizeInFile); Zeroes = 0; } } // Load data from decompressed buffer using (var ms = new System.IO.MemoryStream(buffer)) using (var br = new GomBinaryReader(ms)) { ms.Position = Zeroes; this.GlommedClasses = new List <DomClass>(); for (var glomIdx = 0; glomIdx < NumGlommed; glomIdx++) { var glomClassId = br.ReadUInt64(); var glomClass = DataObjectModel.Get <DomClass>(glomClassId); this.GlommedClasses.Add(glomClass); } this._data = ScriptObjectReader.ReadObject(this.DomClass, br); } //FirstBytes = buffer.Take(0xF).ToArray(); } this.DataBuffer = null; // Since we're loaded, we don't need to hold on to the compressed data anymore IsLoaded = true; }
private static void ReadAllItems(GomBinaryReader br, long offset) { while (true) { // Begin Reading Gom Definitions int defLength = br.ReadInt32(); // Length == 0 means we've read them all! if (defLength == 0) { break; } //short defFlags = br.ReadInt16(); //int defType = (defFlags >> 3) & 0x7; byte[] defBuffer = new byte[defLength]; int defZero = br.ReadInt32(); // 4 blank bytes ulong defId = br.ReadUInt64(); // 8-byte type ID short defFlags = br.ReadInt16(); // 16-bit flag field int defType = (defFlags >> 3) & 0x7; //var defData = br.ReadBytes(defLength - 6); var defData = br.ReadBytes(defLength - 18); Buffer.BlockCopy(defData, 0, defBuffer, 18, defData.Length); using (var memStream = new System.IO.MemoryStream(defBuffer)) using (var defReader = new GomBinaryReader(memStream, Encoding.UTF8)) { DomTypeLoaders.IDomTypeLoader loader; if (typeLoaderMap.TryGetValue(defType, out loader)) { var domType = loader.Load(defReader); domType.Id = defId; DomTypeMap.Add(domType.Id, domType); if (String.IsNullOrEmpty(domType.Name)) { string storedTypeName; if (StoredNameMap.TryGetValue(domType.Id, out storedTypeName)) { domType.Name = storedTypeName; } } AddToNameLookup(domType); } else { throw new InvalidOperationException(String.Format("No loader for DomType 0x{1:X} as offset 0x{0:X}", offset, defType)); } } // Read the required number of padding bytes int padding = ((8 - (defLength & 0x7)) & 0x7); if (padding > 0) { br.ReadBytes(padding); } offset = offset + defLength + padding; } }