void LoadResource(BinaryReader reader, ResType type, ushort idx) { bool dynamic = false; switch (type) { case ResType.Inventory: case ResType.String: case ResType.Verb: case ResType.VerbImage: case ResType.ActorName: case ResType.ScaleTable: case ResType.Temp: case ResType.FlObject: case ResType.Matrix: case ResType.ObjectName: dynamic = true; break; } if (dynamic) { int size = reader.ReadInt32(); var ptr = reader.ReadBytes(size); //Console.WriteLine("Type: {0}, Index: {1}, Data: {2}", type, idx, size); switch (type) { case ResType.Inventory: { var index = reader.ReadUInt16(); _inventory[idx] = index; _invData[idx] = new ObjectData(index); var br = new BinaryReader(new MemoryStream(ptr)); br.BaseStream.Seek(18, SeekOrigin.Begin); var offset = br.ReadByte(); br.BaseStream.Seek(offset, SeekOrigin.Begin); // read name var name = new List<byte>(); var c = br.ReadByte(); while (c != 0) { name.Add(c); c = br.ReadByte(); } _invData[idx].Name = name.ToArray(); // read script _invData[idx].Script.Data = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position)); // read verb table br.BaseStream.Seek(19, SeekOrigin.Begin); if (Game.Version == 8) { while (true) { var id = br.ReadInt32(); var off = br.ReadInt32(); if (id == 0) break; _invData[idx].ScriptOffsets.Add(id, off); } _invData[idx].Script.Offset = _invData[idx].ScriptOffsets.Count * 8 + 4; } else { while (true) { var id = br.ReadByte(); var off = br.ReadUInt16(); if (id == 0) break; _invData[idx].ScriptOffsets.Add(id, off); } _invData[idx].Script.Offset = _invData[idx].ScriptOffsets.Count * 3 + 1 + 8; } } break; case ResType.ActorName: { Actors[idx].Name = ptr; } break; case ResType.ObjectName: { var index = reader.ReadUInt16(); _newNames[index] = ptr; } break; case ResType.Matrix: { if (idx == 1) { // BOXM _boxMatrix.Clear(); _boxMatrix.AddRange(ptr); } else if (idx == 2) { // BOXD var br = new BinaryReader(new MemoryStream(ptr)); var numBoxes = br.ReadByte(); _boxes = new Box[numBoxes]; for (int i = 0; i < numBoxes; i++) { var box = new Box(); box.Ulx = br.ReadInt16(); box.Uly = br.ReadInt16(); box.Urx = br.ReadInt16(); box.Ury = br.ReadInt16(); box.Lrx = br.ReadInt16(); box.Lry = br.ReadInt16(); box.Llx = br.ReadInt16(); box.Lly = br.ReadInt16(); box.Mask = br.ReadByte(); box.Flags = (BoxFlags)br.ReadByte(); box.Scale = br.ReadUInt16(); if (Game.Version == 8) { box.ScaleSlot = br.ReadByte(); } _boxes[i] = box; } } } break; case ResType.Verb: { Verbs[idx].Text = ptr; } break; case ResType.VerbImage: { var br = new BinaryReader(new MemoryStream(ptr)); Verbs[idx].ImageWidth = br.ReadUInt16(); Verbs[idx].ImageHeight = br.ReadUInt16(); var imgSize = (int)(br.BaseStream.Length - 4); Verbs[idx].ImageData = new ImageData{ Data = br.ReadBytes(imgSize) }; } break; case ResType.String: { _strings[idx] = ptr; } break; } } // else // { // Console.WriteLine("Type: {0}", type); // } }
void ResetRoomSubBlocks() { // Reset room color for V1 zak if (Game.Version <= 1) Gdi.RoomPalette[0] = 0; _boxMatrix.Clear(); _boxMatrix.AddRange(roomData.BoxMatrix); for (int i = 0; i < _scaleSlots.Length; i++) { _scaleSlots[i] = new ScaleSlot(); } for (int i = 1; i <= roomData.Scales.Length; i++) { var scale = roomData.Scales[i - 1]; if (Game.Version == 8 || scale.Scale1 != 0 || scale.Y1 != 0 || scale.Scale2 != 0 || scale.Y2 != 0) { SetScaleSlot(i, 0, scale.Y1, scale.Scale1, 0, scale.Y2, scale.Scale2); } } Array.Clear(_extraBoxFlags, 0, _extraBoxFlags.Length); _boxes = new Box[roomData.Boxes.Count]; for (int i = 0; i < roomData.Boxes.Count; i++) { var box = roomData.Boxes[i]; _boxes[i] = new Box { Flags = box.Flags, Llx = box.Llx, Lly = box.Lly, Lrx = box.Lrx, Lry = box.Lry, Mask = box.Mask, Scale = box.Scale, ScaleSlot = box.ScaleSlot, Ulx = box.Ulx, Uly = box.Uly, Urx = box.Urx, Ury = box.Ury }; } Array.Copy(roomData.ColorCycle, _colorCycle, roomData.ColorCycle.Length); Gdi.RoomChanged(CurrentRoomData); }