public T Load <T>(string resourceType, int resourceId, IDictionary <string, object> parameters) where T : Resource { var cacheKey = string.Format("{0}_{1}", resourceType, resourceId); if (!this.cache.ContainsKey(cacheKey)) { if (this.loaders.ContainsKey(resourceType)) { var loader = this.loaders[resourceType]; ResourceIndexEntry roomReference; if (resourceType == "ROOM") { roomReference = new ResourceIndexEntry((byte)resourceId, 0); } else { roomReference = FindIndexFromResourceId(resourceType, resourceId); } // Find the room offset var roomOffset = this.roomsIndexList[roomReference.RoomId]; // Change the position of the stream this.dataFileReader.BaseStream.Position = roomOffset; if (resourceType != "ROOM") { this.dataFileReader.BaseStream.Seek(roomReference.Offset, SeekOrigin.Current); } // Load the resource var resource = loader.LoadResourceData(dataFileReader, cacheKey, parameters); // Add the created resource to the cache this.cache.Add(cacheKey, resource); // Return the resource return((T)resource); } else { throw new InvalidOperationException(string.Format("No resource loaders for blockType '{0}' were found.", resourceType)); } } else { return((T)this.cache[cacheKey]); } }
private ResourceIndexEntry[] ReadResourceReferenceList(ScummBinaryReader reader, ref ushort itemsCount) { itemsCount = reader.ReadUInt16(); var resourceReferenceList = new ResourceIndexEntry[itemsCount]; var roomIdList = new byte[itemsCount]; for (int i = 0; i < itemsCount; i++) { roomIdList[i] = reader.ReadByte(); } for (int i = 0; i < itemsCount; i++) { var resourceOffset = reader.ReadUInt32(); resourceReferenceList[i] = new ResourceIndexEntry(roomIdList[i], resourceOffset); } return(resourceReferenceList); }