public LuaFunction(BinaryReader reader, LuaModule module) { Module = module; Source = module.ReadString(reader); LineDefined = module.ReadInt(reader); UpValueCount = reader.ReadByte(); ParameterCount = reader.ReadByte(); HasVariableArguments = reader.ReadByte() != 0; MaxStackSize = reader.ReadByte(); var lineInfoCount = module.ReadInt(reader); LineInfo = new Codex<int>(reader.ReadArrayInt32(lineInfoCount)); var localVariableCount = module.ReadInt(reader); LuaLocalVariable[] localVariables = new LuaLocalVariable[localVariableCount]; for (int index = 0; index < localVariableCount; index++) localVariables[index] = new LuaLocalVariable(reader, this); LocalVariables = new Codex<LuaLocalVariable>(localVariables); var upValueCount = module.ReadInt(reader); string[] upValues = new string[upValueCount]; for (int index = 0; index < upValueCount; index++) upValues[index] = module.ReadString(reader); UpValues = new Codex<string>(upValues); var constantCount = module.ReadInt(reader); Codex<object> constants = new Codex<object>(constantCount); Constants = constants; for (int index = 0; index < constantCount; index++) { LuaType type = (LuaType)reader.ReadByte(); switch (type) { case LuaType.Nil: break; case LuaType.Boolean: constants.Add(reader.ReadByte() != 0); break; case LuaType.Number: constants.Add(module.ReadNumber(reader)); break; case LuaType.String: constants.Add(module.ReadString(reader)); break; default: throw new NotSupportedException(); } } var functionCount = module.ReadInt(reader); LuaFunction[] functions = new LuaFunction[functionCount]; for (int index = 0; index < functionCount; index++) functions[index] = new LuaFunction(reader, index, this); Closures = new Codex<LuaFunction>(functions); var codeCount = module.ReadInt(reader); LuaInstruction[] code = new LuaInstruction[codeCount]; for (int index = 0; index < codeCount; index++) code[index] = new LuaInstruction(this, module.ReadInstructionCode(reader)); Instructions = new Codex<LuaInstruction>(code); }
internal Picture(AssetLoader loader) : base(loader) { BinaryReader reader = loader.Reader; ushort check = reader.ReadUInt16(); Codex <PictureInstruction> instructions = new Codex <PictureInstruction>(); Codex <PictureCel> cels = new Codex <PictureCel>(); if (check == 0x0E) // VGA picture { int celCount = reader.ReadUInt16(); Unknowns.ReadInt16s(reader, 1); // 0x2A int paletteOffset = reader.ReadInt32(); Dimensions = new Vector2i(reader.ReadUInt16(), reader.ReadUInt16()); reader.BaseStream.Position = paletteOffset; Palette = new Palette(loader); AddChild(Palette); for (int celIndex = 0; celIndex < celCount; celIndex++) { PictureCel cel = new PictureCel(this, celIndex, loader); cels.Add(cel); AddChild(cel); instructions.Add(new PictureInstruction.DrawCel(cel)); } } else { Dimensions = new Vector2i(320, 190); reader.BaseStream.Seek(-2, SeekOrigin.Current); byte[] data = reader.ReadBytes(checked ((int)reader.BaseStream.Length)); Stream stream = new MemoryStream(data, false); PicturePatternFlags patternFlags = PicturePatternFlags.None; byte patternNumber = 0; while (true) { PictureInstruction instruction = PictureInstruction.ReadInstruction(stream, ref patternFlags, ref patternNumber); instructions.Add(instruction); if (instruction.IsQuit) { break; } } } Cels = cels; Instructions = instructions; }
internal Palette(AssetLoader loader) : base(loader) { BinaryReader reader = loader.Reader; Unknowns.ReadBytes(reader, 25); // Offset 0-24 int firstIndex = reader.ReadByte(); // Offset 25-25 Unknowns.ReadBytes(reader, 3); // Offset 26-28 int count = reader.ReadUInt16(); // Offset 29-30 Unknowns.ReadBytes(reader, 1); // Offset 31-31 byte format = reader.ReadByte(); // Offset 32-32 Unknowns.ReadBytes(reader, 4); // Offset 33-36 // Offset 37 PaletteColor[] colors = new PaletteColor[count]; Colors = new ReadOnlyCollection <PaletteColor>(colors); FlatColors = new Codex <Color>(256); for (int index = 0; index < firstIndex; index++) { FlatColors.Add(Color.Purple); } for (int index = 0; index < count; index++) { PaletteColor color; switch (format) { case 0: // Variable (byte used, byte red, byte green, byte blue) color = new PaletteColor(reader.ReadByte() != 0, reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); break; case 1: // Constant (byte red, byte green, byte blue) color = new PaletteColor(reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); break; default: throw new NotImplementedException(); } colors[index] = color; FlatColors.Add(color); } PaletteAsset = new PaletteAsset(Manager, Name ?? "Palette", FlatColors); }
protected virtual void AddEntry(int gx, int gy, int idx) { var ui = UI; ui.EntryPoint = new Point2D(gx, gy); User.SendMessage("Select a rune book or recall rune to add to the Codex..."); Minimized = true; Refresh(true); ItemSelectTarget <Item> .Begin( User, (m, t) => { if (Codex.Add(User, t, ui.Category, true)) { Minimized = false; SelectEntry(gx, gy, idx, ui.Category.Entries[gx, gy]); } else { AddEntry(gx, gy, idx); } }, m => { Minimized = false; Refresh(true); }); }
internal Package(AssetLoader loader) : base(loader) { loader.MakeBigEndian(); BinaryReader reader = Reader = loader.Reader; ushort versionMajor = reader.ReadUInt16(); ushort versionMinor = reader.ReadUInt16(); reader.RequireZeroes(4); int stringCount = reader.ReadInt32(); Codex <PackageString> strings = new Codex <PackageString>(stringCount); for (int index = 0; index < stringCount; index++) { strings.Add(new PackageString(this, index, reader)); } Strings = strings; int fileCount = reader.ReadInt32(); for (int index = 0; index < fileCount; index++) { new PackageFile(this, index, loader); } }
public static void AddCodex(string fileName) { if (!String.IsNullOrEmpty(fileName)) { Codex.Add(fileName.ToLower()); } }
public Script(AssetManager manager, BinaryReader reader, string name) : base(manager, name) { long end = reader.BaseStream.Length; ExceptionEnd = ""; reader.Require(0x01011388); CodeAddressA = reader.ReadUInt16(); reader.Require((ushort)0x0101); CodeAddressB = reader.ReadUInt16(); reader.Require((ushort)0x0101); CodeAddressC = reader.ReadUInt16(); reader.Require((ushort)0x0101); CodeAddressD = reader.ReadUInt16(); reader.Require((ushort)0x0101); CodeAddressE = reader.ReadUInt16(); while (reader.BaseStream.Position < end) { try { var instruction = ScriptInstruction.Read(this, reader); InstructionsMutable.Add(instruction); } catch (Exception exception) { ExceptionEnd = string.Format("\r\n{0:X}: Exception: {1}\r\nStopping\r\n", reader.BaseStream.Position, exception); break; } } Link(); }
internal Object(Script script, ScriptBlock block, AssetLoader loader) : base(script, block) { var reader = loader.Reader; loader.Expect((ushort)0x1234); LocalVariableOffset = reader.ReadUInt16(); int functionSelectorListOffset = reader.ReadUInt16(); int variableSelectorCount = reader.ReadUInt16(); Codex <VariableSelector> variableSelectors = new Codex <VariableSelector>(variableSelectorCount); Variables = variableSelectors; for (int index = 0; index < variableSelectorCount; index++) { variableSelectors.Add(new VariableSelector(this, loader)); } int functionSelectorCount = reader.ReadUInt16(); Codex <FunctionSelector> functionSelectors = new Codex <FunctionSelector>(functionSelectorCount); Functions = functionSelectors; for (int index = 0; index < functionSelectorCount; index++) { functionSelectors.Add(new FunctionSelector(this, loader)); } loader.Expect((ushort)0); for (int index = 0; index < functionSelectorCount; index++) { functionSelectors[index].ReadCodeOffset(loader); } loader.ExpectPosition(block.EndOffset); }
internal View(AssetLoader loader) : base(loader) { using (BinaryReader reader = loader.Reader) { // 8-byte header var count = reader.ReadByte(); var flags = reader.ReadByte(); // Bit 0x80 means palette is set bool isCompressed = (flags & 0x40) == 0; ushort mirroredFlags = reader.ReadUInt16(); Unknowns.ReadInt16s(reader, 1); ushort paletteOffset = reader.ReadUInt16(); if (paletteOffset != 0 && paletteOffset != 0x100) { throw new NotImplementedException(); } for (int index = 0; index < count; index++) { reader.BaseStream.Position = 8 + index * 2; var animation = FindAnimation(loader, reader.ReadUInt16()); GroupsMutable.Add(new ViewGroup(animation, (mirroredFlags & (1 << index)) != 0)); } } }
internal MCP(AssetManager manager, AssetLoader loader) : base(manager, loader.Name) { var reader = loader.Reader; EndOffset = checked ((int)loader.Length); loader.Expect(Magic1 + 1); loader.Expect(Magic2); int table2Count = reader.ReadInt32(); int table2Offset = Table2Offset = reader.ReadInt32(); int table1Offset = Table1Offset = HeaderDataSize; int table1Count = (table2Offset - table1Offset) / MCPTable1.DataSize; reader.BaseStream.Position = table1Offset; var table1 = new Codex <MCPTable1>(table1Count); Table1 = table1; for (int index = 0; index < table1Count; index++) { table1.Add(new MCPTable1(this, index, loader)); } reader.BaseStream.Position = table2Offset; var table2 = new Codex <MCPTable2>(table2Count); Table2 = table2; for (int index = 0; index < table2Count; index++) { table2.Add(new MCPTable2(this, index, loader)); } }
internal Effect(AssetLoader loader) : base(loader) { var reader = loader.Reader; loader.ExpectMagic(Magic); loader.Expect(0x10000); loader.Expect(ContentStart); int offsetOffset = reader.ReadInt32(); int pointerCount = reader.ReadInt32(); HashSet<int> pointers = new HashSet<int>(); int functionCount = reader.ReadInt32(); HashSet<int> functions = new HashSet<int>(); loader.Position = offsetOffset; for (int index = 0; index < pointerCount; index++) pointers.Add(reader.ReadInt32()); for (int index = 0; index < functionCount; index++) functions.Add(reader.ReadInt32()); loader.Position = ContentStart; int tokenCount = (offsetOffset - ContentStart) / 4; Tokens = new Codex<EffectToken>(tokenCount); for (int index = 0; index < tokenCount; index++) Tokens.Add(new EffectToken(reader, pointers, functions)); for (int index = 0; index < tokenCount; index++) Tokens[index].Link(Tokens); Instructions = new Codex<EffectInstruction>(); for (int index = 0; index < tokenCount; ) Instructions.Add(new EffectInstruction(Tokens, ref index)); }
/// <summary>Add a background operation.</summary> /// <param name="name"></param> /// <param name="description"></param> /// <param name="callbacks"></param> /// <returns></returns> public BackgroundOperation AddBackgroundOperation(string name, string description, params BackgroundOperationCallback[] callbacks) { BackgroundOperation operation = new BackgroundOperation(this, name, description, callbacks); lock (BackgroundOperations) BackgroundOperations.Add(operation); return(operation); }
internal Module(AssetLoader loader) : base(loader) { loader.Progress = 0; Reader = loader.Reader; var tes4Record = new RecordHeader(Reader); tes4Record.RequireType("TES4"); using (RecordReader reader = tes4Record.OpenReader(Reader)) { while (reader.ReadField()) { switch (reader.Field.Type) { case "HEDR": reader.RequireFieldSize(12); Version = reader.ReadSingle(); RecordCount = reader.ReadInt32(); NextAvailableObjectId = reader.ReadFormId(); break; case "CNAM": Author = reader.ReadStringBody(); break; case "SNAM": Description = reader.ReadStringBody(); break; case "MAST": MastersMutable.Add(reader.ReadStringBody()); break; case "DATA": // File size of a MAST - always 0, probably vestigial. long fileSize = reader.ReadInt64OrInt32Body(); if (fileSize != 0) { throw new InvalidDataException(); } break; case "ONAM": OverridesMutable.Capacity = reader.Field.Size / 4; for (int index = 0, count = reader.Field.Size / 4; index < count; index++) { OverridesMutable.Add(reader.ReadFormId()); } break; case "INTV": InternalVersion = reader.ReadInt32Body(); break; case "INCC": InternalCC = reader.ReadInt32Body(); break; default: throw reader.UnknownFieldException(); } } } while (!loader.AtEnd) { loader.SetProgressToPosition(); AddChild(Group.ReadGroup(this)); } }
internal Picture(AssetLoader loader) : base(loader) { BinaryReader reader = loader.Reader; ushort check = reader.ReadUInt16(); Codex<PictureInstruction> instructions = new Codex<PictureInstruction>(); Codex<PictureCel> cels = new Codex<PictureCel>(); if (check == 0x0E) { // VGA picture int celCount = reader.ReadUInt16(); Unknowns.ReadInt16s(reader, 1); // 0x2A int paletteOffset = reader.ReadInt32(); Dimensions = new Vector2i(reader.ReadUInt16(), reader.ReadUInt16()); reader.BaseStream.Position = paletteOffset; Palette = new Palette(loader); AddChild(Palette); for (int celIndex = 0; celIndex < celCount; celIndex++) { PictureCel cel = new PictureCel(this, celIndex, loader); cels.Add(cel); AddChild(cel); instructions.Add(new PictureInstruction.DrawCel(cel)); } } else { Dimensions = new Vector2i(320, 190); reader.BaseStream.Seek(-2, SeekOrigin.Current); byte[] data = reader.ReadBytes(checked((int)reader.BaseStream.Length)); Stream stream = new MemoryStream(data, false); PicturePatternFlags patternFlags = PicturePatternFlags.None; byte patternNumber = 0; while (true) { PictureInstruction instruction = PictureInstruction.ReadInstruction(stream, ref patternFlags, ref patternNumber); instructions.Add(instruction); if (instruction.IsQuit) break; } } Cels = cels; Instructions = instructions; }
internal Script(AssetLoader loader) : base(loader) { ScriptSection block; while ((block = ScriptSection.Read(this, loader)) != null) { blocks.Add(block); } }
internal void ReadDetailLevels(AssetLoader loader, int dataOffset, ArrayBackedList <byte> bufferData) { var detailLevels = new Codex <ModelDetailLevel>(); DetailLevels = detailLevels; for (int index = 0; index < PartCount; index++) { detailLevels.Add(new ModelDetailLevel(this, index, loader, dataOffset, bufferData)); } }
internal Message(AssetLoader loader) : base(loader) { using (BinaryReader reader = loader.Reader) { Version = (MessageVersion)reader.ReadInt32(); int fileLength, addonOffset = -1; int count; Codex <MessageItem> items = new Codex <MessageItem>(); Items = items; switch (MajorVersion) { case 3: fileLength = reader.ReadUInt16() + 6; count = reader.ReadUInt16(); break; case 4: addonOffset = reader.ReadUInt16() + 6; Unknowns.ReadInt16s(reader, 1); count = reader.ReadUInt16(); break; case 5: addonOffset = reader.ReadInt32() + 6; count = reader.ReadUInt16(); break; default: throw new NotImplementedException("Unimplemented version " + Version); } for (int index = 0; index < count; index++) { MessageItem item = new MessageItem(this, index, loader); items.Add(item); AddChild(item); } foreach (MessageItem item in items) { item.ReadText(reader); } if (addonOffset >= 0) { reader.BaseStream.Position = addonOffset; foreach (MessageItem item in items) { item.ReadAddOn(reader); } } } }
/// <summary> /// Initialise the state. /// </summary> /// <param name="manager"></param> /// <param name="rootPath"></param> /// <param name="fileManager"></param> /// <param name="archive"></param> public State(AlexandriaManager manager, string rootPath, FileManager fileManager, Archive archive = null) : base(manager, rootPath, fileManager) { if (archive != null) { ArchivesMutable.Add(archive); } foreach (var path in Directory.EnumerateFiles(RootPath, "*.bhd5")) { } }
internal Strings(Script script, ScriptBlock block, AssetLoader loader) : base(script, block) { Codex <string> list = new Codex <string>(); Values = list; while (loader.Position < block.EndOffset) { list.Add(loader.Reader.ReadStringz(Encoding.ASCII)); } }
internal Locals(Script script, ScriptBlock block, AssetLoader loader) : base(script, block) { Codex <ushort> values = new Codex <ushort>(block.ContentSize / 2); Values = values; for (int index = 0; index < block.ContentSize / 2; index++) { values.Add(loader.Reader.ReadUInt16()); } }
/// <summary>Add a format to the collection of formats.</summary> /// <param name="format"></param> protected void AddFormat(AssetFormat format) { if (format == null) { throw new ArgumentNullException("format"); } if (format.Plugin != Plugin || FormatsMutable.Contains(format)) { throw new ArgumentException(format.Name + " cannot be added to " + Name + "."); } FormatsMutable.Add(format); }
/// <summary>Read the text resource.</summary> /// <param name="loader"></param> internal Text(AssetLoader loader) : base(loader) { BinaryReader reader = loader.Reader; long end = reader.BaseStream.Length; while (reader.BaseStream.Position < end) { string value = reader.ReadStringz(Encoding.ASCII); StringsMutable.Add(value); StringsWithId.Add(new KeyValuePair <int, string>(StringsMutable.Count - 1, value)); } }
internal Codex <MCGTable1> GetTable1Slice(int count, int offset) { if (offset < Table1Offset || offset + count * MCGTable1.DataSize > Table2Offset || (offset - Table1Offset) % MCGTable1.DataSize != 0) { throw new InvalidDataException(); } int start = (offset - Table1Offset) / MCGTable1.DataSize; Codex <MCGTable1> table = new Codex <MCGTable1>(count); for (int index = 0; index < count; index++) { table.Add(Table1[start + index]); } return(table); }
internal Message(AssetLoader loader) : base(loader) { using (BinaryReader reader = loader.Reader) { Version = (MessageVersion)reader.ReadInt32(); int fileLength, addonOffset = -1; int count; Codex<MessageItem> items = new Codex<MessageItem>(); Items = items; switch (MajorVersion) { case 3: fileLength = reader.ReadUInt16() + 6; count = reader.ReadUInt16(); break; case 4: addonOffset = reader.ReadUInt16() + 6; Unknowns.ReadInt16s(reader, 1); count = reader.ReadUInt16(); break; case 5: addonOffset = reader.ReadInt32() + 6; count = reader.ReadUInt16(); break; default: throw new NotImplementedException("Unimplemented version " + Version); } for (int index = 0; index < count; index++) { MessageItem item = new MessageItem(this, index, loader); items.Add(item); AddChild(item); } foreach (MessageItem item in items) item.ReadText(reader); if (addonOffset >= 0) { reader.BaseStream.Position = addonOffset; foreach (MessageItem item in items) item.ReadAddOn(reader); } } }
/// <summary>Add a game to this plugin.</summary> /// <param name="game">The game to add.</param> /// <exception cref="ArgumentNullException"><paramref name="game"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="game"/> is not part of this <see cref="AlexandriaPlugin"/>.</exception> /// <exception cref="ArgumentException"><paramref name="game"/> is already in this <see cref="AlexandriaPlugin"/>.</exception> protected void AddGame(Game game) { if (game == null) { throw new ArgumentNullException("game"); } if (game.Plugin != this) { throw new ArgumentException(game.Name + " is not part of this " + Name + "."); } if (GamesMutable.Contains(game)) { throw new ArgumentException(game.Name + " is already added to this " + Name + "."); } GamesMutable.Add(game); }
/// <summary> /// Add a game to the engine. /// </summary> /// <param name="game">The game to add.</param> protected void AddGame(Game game) { if (game == null) { throw new ArgumentNullException("game"); } if (GamesMutable.Contains(game)) { throw new ArgumentException(game.Name + " is already added to this " + Name + "."); } if (game.Engine != this) { throw new ArgumentException(game.Name + " does not have this " + Name + " as its Engine."); } GamesMutable.Add(game); }
/// <summary>Add an engine to this plugin.</summary> /// <param name="engine">The engine to add.</param> /// <exception cref="ArgumentNullException"><paramref name="engine"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="engine"/> is not part of this <see cref="AlexandriaPlugin"/>.</exception> /// <exception cref="ArgumentException"><paramref name="engine"/> is already in this <see cref="AlexandriaPlugin"/>.</exception> protected void AddEngine(Engine engine) { if (engine == null) { throw new ArgumentNullException("engine"); } if (engine.Plugin != this) { throw new ArgumentException(engine.Name + " is not part of this " + Name + "."); } if (EnginesMutable.Contains(engine)) { throw new ArgumentException(engine.Name + " is already added to this " + Name + "."); } EnginesMutable.Add(engine); }
internal ModelMesh(FolderAsset folder, int index, AssetLoader loader) : base(folder, index, loader) { var reader = loader.Reader; Unknowns.ReadInt32s(reader, 1); // 1? MaterialIndex = reader.ReadInt32(); reader.RequireZeroes(4 * 2); Unknowns.ReadInt32s(reader, 1); // 0 or 1, seems to be material-related but is not transparency; second seems bones-related int boneCount = reader.ReadInt32(); reader.RequireZeroes(4 * 1); int boneIndicesOffset = reader.ReadInt32(); PartCount = reader.ReadInt32(); int partIndicesOffset = reader.ReadInt32(); reader.Require(1); int indexOffset = reader.ReadInt32(); long reset = reader.BaseStream.Position; reader.BaseStream.Position = boneIndicesOffset; var bones = new Codex <ModelBone>(); Bones = bones; for (int i = 0; i < boneCount; i++) { bones.Add(Model.Bones[reader.ReadInt32()]); } // Read the part indices. reader.BaseStream.Position = partIndicesOffset; int partStart = PartStartIndex; for (int i = 0; i < PartCount; i++) { reader.Require(i + partStart); } reader.BaseStream.Position = indexOffset; reader.Require(Index); reader.BaseStream.Position = reset; }
internal ViewAnimation FindAnimation(AssetLoader loader, ushort offset) { BinaryReader reader = loader.Reader; foreach (var item in Animations) { if (item.DataOffset == offset) { return(item); } } reader.BaseStream.Position = offset; var animation = new ViewAnimation(this, loader); AnimationsMutable.Add(animation); return(animation); }
internal ViewCell FindCell(AssetLoader loader, ushort offset) { BinaryReader reader = loader.Reader; foreach (var item in Cells) { if (item.DataOffset == offset) { return(item); } } reader.BaseStream.Position = offset; var cell = new ViewCell(this, loader); CellsMutable.Add(cell); return(cell); }
internal Effect(AssetLoader loader) : base(loader) { var reader = loader.Reader; loader.ExpectMagic(Magic); loader.Expect(0x10000); loader.Expect(ContentStart); int offsetOffset = reader.ReadInt32(); int pointerCount = reader.ReadInt32(); HashSet <int> pointers = new HashSet <int>(); int functionCount = reader.ReadInt32(); HashSet <int> functions = new HashSet <int>(); loader.Position = offsetOffset; for (int index = 0; index < pointerCount; index++) { pointers.Add(reader.ReadInt32()); } for (int index = 0; index < functionCount; index++) { functions.Add(reader.ReadInt32()); } loader.Position = ContentStart; int tokenCount = (offsetOffset - ContentStart) / 4; Tokens = new Codex <EffectToken>(tokenCount); for (int index = 0; index < tokenCount; index++) { Tokens.Add(new EffectToken(reader, pointers, functions)); } for (int index = 0; index < tokenCount; index++) { Tokens[index].Link(Tokens); } Instructions = new Codex <EffectInstruction>(); for (int index = 0; index < tokenCount;) { Instructions.Add(new EffectInstruction(Tokens, ref index)); } }
internal ViewAnimation(View view, AssetLoader loader) : base(loader) { BinaryReader reader = loader.Reader; View = view; var cells = new Codex <ViewCell>(); Cells = cells; DataOffset = (ushort)reader.BaseStream.Position; var count = reader.ReadUInt16(); Unknowns.ReadInt16s(reader, 1); for (int index = 0; index < count; index++) { reader.BaseStream.Position = DataOffset + 4 + index * 2; cells.Add(view.FindCell(loader, reader.ReadUInt16())); } }
internal ModelVertexDeclaration(FolderAsset folder, int index, AssetLoader loader) : base(folder, index, loader) { var reader = loader.Reader; int count = reader.ReadInt32(); reader.RequireZeroes(4 * 2); int offset = reader.ReadInt32(); long reset = reader.BaseStream.Position; reader.BaseStream.Position = offset; var blocks = new Codex <ModelVertexAttribute>(); Attributes = blocks; for (int blockIndex = 0; blockIndex < count; blockIndex++) { blocks.Add(new ModelVertexAttribute(this, loader, blockIndex)); } reader.BaseStream.Position = reset; }
internal ModelMesh(FolderAsset folder, int index, AssetLoader loader) : base(folder, index, loader) { var reader = loader.Reader; Unknowns.ReadInt32s(reader, 1); // 1? MaterialIndex = reader.ReadInt32(); reader.RequireZeroes(4 * 2); Unknowns.ReadInt32s(reader, 1); // 0 or 1, seems to be material-related but is not transparency; second seems bones-related int boneCount = reader.ReadInt32(); reader.RequireZeroes(4 * 1); int boneIndicesOffset = reader.ReadInt32(); PartCount = reader.ReadInt32(); int partIndicesOffset = reader.ReadInt32(); reader.Require(1); int indexOffset = reader.ReadInt32(); long reset = reader.BaseStream.Position; reader.BaseStream.Position = boneIndicesOffset; var bones = new Codex<ModelBone>(); Bones = bones; for (int i = 0; i < boneCount; i++) bones.Add(Model.Bones[reader.ReadInt32()]); // Read the part indices. reader.BaseStream.Position = partIndicesOffset; int partStart = PartStartIndex; for (int i = 0; i < PartCount; i++) reader.Require(i + partStart); reader.BaseStream.Position = indexOffset; reader.Require(Index); reader.BaseStream.Position = reset; }
internal EffectInstruction(IList <EffectToken> tokens, ref int index) { Opcode = tokens[index++]; string format; if (Opcode.MaybeInt32 && InstructionFormats.TryGetValue(Opcode.AsInt32, out format)) { if (Opcode.AsInt32 == 0x85) { while (index < tokens.Count && !tokens[index].IsFunction) { OperandsMutable.Add(tokens[index++]); } } else if (Opcode.AsInt32 == 0x88) { while (index < tokens.Count) { OperandsMutable.Add(tokens[index++]); } } else { foreach (char operandType in format) { if (index >= tokens.Count) { Opcode.AddError("Expected '{0}'; end of tokens.", operandType); break; } if (tokens[index].IsFunction) { tokens[index].AddError("Last instruction expected '{0}', not a function.", operandType); break; } var operand = tokens[index++]; OperandsMutable.Add(operand); switch (operandType) { case 'i': if (!operand.MaybeInt32) { operand.AddError("Expected an integer."); } break; case 'p': if (!operand.MaybePointer) { operand.AddError("Expected a pointer."); } break; case 'z': if (!operand.IsZero) { operand.AddError("Expected zero."); } break; case 's': if (!operand.MaybeSingle) { operand.AddError("Expected a Single."); } break; } } } } else { Opcode.AddError("Opcode is unknown or invalid; operands are crap."); while (index < tokens.Count && !(tokens[index].MaybeInt32 && InstructionFormats.ContainsKey(tokens[index].AsInt32)) && !tokens[index].IsFunction) { OperandsMutable.Add(tokens[index++]); } } }
internal Rom(AssetLoader loader) : base(loader) { BinaryReader reader = Reader = loader.Reader; Codex<RomFile> files = new Codex<RomFile>(); Codex<RomFolder> folders = new Codex<RomFolder>(); Files = files; Folders = folders; GameTitle = Reader.ReadStringz(12, Encoding.ASCII); GameCode = Reader.ReadStringz(4, Encoding.ASCII); // Offset 0x10 MakerCode = Reader.ReadStringz(2, Encoding.ASCII); UnitCode = reader.ReadByte(); DeviceCode = reader.ReadByte(); CardSizeBase = reader.ReadByte(); loader.ExpectZeroes(1, 7); Unknowns.ReadInt32s(reader, 1); // Usually 0, Alice in Wonderland: 3 // Offset 0x20 PageSize = reader.ReadInt32(); // Usually (always?) 0x4000 Unknowns.ReadInt16s(reader, 2); // The Dark Spire: 0x800; Trauma Center: 0xF780 (-2176) loader.Expect(0x2000000); Unknowns.ReadInt32s(reader, 1); // The Dark Spire: 0x9BEF8; Trauma Center: 0x1DC518 // Offset 0x30 Unknowns.ReadInt32s(reader, 1); // Entry points? The Dark Spire: 0x152200; Trauma Center: 0x1E0600 loader.Expect(0x2380000); loader.Expect(0x2380000); Unknowns.ReadInt16s(reader, 1); // The Dark Spire: 0x6F28; Trauma Center: 0x6F24 loader.Expect((short)0x2); // Offset 0x40 int fileNameTableOffset = reader.ReadInt32(); int fileNameTableSize = reader.ReadInt32(); int fileSizeTableOffset = reader.ReadInt32(); int fileSizeTableSize = reader.ReadInt32(); // Offset 0x50 Unknowns.ReadInt32s(reader, 2, "Offset and size"); // Used in The Dark Spire, zeroes in Trauma Center. loader.ExpectZeroes(4, 2); // Offset 0x60 Unknowns.ReadInt32s(reader, 2); int iconAndTitleOffset = reader.ReadInt32(); Unknowns.ReadInt32s(reader, 1); // Offset 0x70 Unknowns.ReadInt32s(reader, 2); loader.ExpectZeroes(4, 2); // Offset 0x80 DataLength = reader.ReadInt32(); loader.Expect(PageSize); Unknowns.ReadInt32s(reader, 2); // The Dark Spire: 0x4B68; 0 in Trauma Center. ReadIconAndTitle(iconAndTitleOffset); if (fileNameTableOffset > 0) { int folderNamesOffset = reader.ReadInt32At(fileNameTableOffset); reader.BaseStream.Position = fileNameTableOffset; int folderCount = folderNamesOffset / 8; for (int index = 0; index < folderCount; index++) folders.Add(new RomFolder(this, index, reader)); byte[] folderNames = reader.ReadBytes(fileNameTableSize - folderNamesOffset); reader.BaseStream.Position = fileSizeTableOffset; int fileCount = fileSizeTableSize / 8; for (int index = 0; index < fileCount; index++) files.Add(new RomFile(this, index, reader)); folders[0].Sort(this, "Root", folderNamesOffset, folderNames); FolderAsset orphanedFolders = null, orphanedFiles = null; foreach (RomFolder folder in folders) { if (folder.Used) continue; if (orphanedFolders == null) orphanedFolders = new FolderAsset(this, "Orphaned folder[s]"); folder.Sort(this, folder.Name, folderNamesOffset, folderNames); } foreach (RomFile file in files) { if (file.Used) continue; if (orphanedFiles == null) orphanedFiles = new FolderAsset(this, "Orphaned file[s]"); file.Sort(orphanedFiles, file.Name); } } }
internal ViewAnimation(View view, AssetLoader loader) : base(loader) { BinaryReader reader = loader.Reader; View = view; var cells = new Codex<ViewCell>(); Cells = cells; DataOffset = (ushort)reader.BaseStream.Position; var count = reader.ReadUInt16(); Unknowns.ReadInt16s(reader, 1); for (int index = 0; index < count; index++) { reader.BaseStream.Position = DataOffset + 4 + index * 2; cells.Add(view.FindCell(loader, reader.ReadUInt16())); } }
internal Package(AssetLoader loader) : base(loader) { loader.MakeBigEndian(); BinaryReader reader = Reader = loader.Reader; ushort versionMajor = reader.ReadUInt16(); ushort versionMinor = reader.ReadUInt16(); reader.RequireZeroes(4); int stringCount = reader.ReadInt32(); Codex<PackageString> strings = new Codex<PackageString>(stringCount); for (int index = 0; index < stringCount; index++) strings.Add(new PackageString(this, index, reader)); Strings = strings; int fileCount = reader.ReadInt32(); for (int index = 0; index < fileCount; index++) new PackageFile(this, index, loader); }
internal ModelVertexDeclaration(FolderAsset folder, int index, AssetLoader loader) : base(folder, index, loader) { var reader = loader.Reader; int count = reader.ReadInt32(); reader.RequireZeroes(4 * 2); int offset = reader.ReadInt32(); long reset = reader.BaseStream.Position; reader.BaseStream.Position = offset; var blocks = new Codex<ModelVertexAttribute>(); Attributes = blocks; for (int blockIndex = 0; blockIndex < count; blockIndex++) blocks.Add(new ModelVertexAttribute(this, loader, blockIndex)); reader.BaseStream.Position = reset; }
internal Strings(Script script, ScriptBlock block, AssetLoader loader) : base(script, block) { Codex<string> list = new Codex<string>(); Values = list; while (loader.Position < block.EndOffset) list.Add(loader.Reader.ReadStringz(Encoding.ASCII)); }
internal Locals(Script script, ScriptBlock block, AssetLoader loader) : base(script, block) { Codex<ushort> values = new Codex<ushort>(block.ContentSize / 2); Values = values; for (int index = 0; index < block.ContentSize / 2; index++) values.Add(loader.Reader.ReadUInt16()); }
internal Palette(AssetLoader loader) : base(loader) { BinaryReader reader = loader.Reader; Unknowns.ReadBytes(reader, 25); // Offset 0-24 int firstIndex = reader.ReadByte(); // Offset 25-25 Unknowns.ReadBytes(reader, 3); // Offset 26-28 int count = reader.ReadUInt16(); // Offset 29-30 Unknowns.ReadBytes(reader, 1); // Offset 31-31 byte format = reader.ReadByte(); // Offset 32-32 Unknowns.ReadBytes(reader, 4); // Offset 33-36 // Offset 37 PaletteColor[] colors = new PaletteColor[count]; Colors = new ReadOnlyCollection<PaletteColor>(colors); FlatColors = new Codex<Color>(256); for (int index = 0; index < firstIndex; index++) FlatColors.Add(Color.Purple); for (int index = 0; index < count; index++) { PaletteColor color; switch (format) { case 0: // Variable (byte used, byte red, byte green, byte blue) color = new PaletteColor(reader.ReadByte() != 0, reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); break; case 1: // Constant (byte red, byte green, byte blue) color = new PaletteColor(reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); break; default: throw new NotImplementedException(); } colors[index] = color; FlatColors.Add(color); } PaletteAsset = new PaletteAsset(Manager, Name ?? "Palette", FlatColors); }
internal void ReadDetailLevels(AssetLoader loader, int dataOffset, ArrayBackedList<byte> bufferData) { var detailLevels = new Codex<ModelDetailLevel>(); DetailLevels = detailLevels; for (int index = 0; index < PartCount; index++) detailLevels.Add(new ModelDetailLevel(this, index, loader, dataOffset, bufferData)); }
internal Object(Script script, ScriptBlock block, AssetLoader loader) : base(script, block) { var reader = loader.Reader; loader.Expect((ushort)0x1234); LocalVariableOffset = reader.ReadUInt16(); int functionSelectorListOffset = reader.ReadUInt16(); int variableSelectorCount = reader.ReadUInt16(); Codex<VariableSelector> variableSelectors = new Codex<VariableSelector>(variableSelectorCount); Variables = variableSelectors; for (int index = 0; index < variableSelectorCount; index++) variableSelectors.Add(new VariableSelector(this, loader)); int functionSelectorCount = reader.ReadUInt16(); Codex<FunctionSelector> functionSelectors = new Codex<FunctionSelector>(functionSelectorCount); Functions = functionSelectors; for (int index = 0; index < functionSelectorCount; index++) functionSelectors.Add(new FunctionSelector(this, loader)); loader.Expect((ushort)0); for (int index = 0; index < functionSelectorCount; index++) functionSelectors[index].ReadCodeOffset(loader); loader.ExpectPosition(block.EndOffset); }