public void WriteOffset(int rel, ByteBuilder bb) { IsOffsetWrited = true; if (Reference != null) { TargetOffset = Reference.Address; } int val = TargetOffset; if (Relative) { val -= rel; } switch (Size) { case 1: bb.SetByte(Address, (byte)val); break; case 2: bb.SetShortBE(Address, (ushort)val); break; default: throw new NotImplementedException(); } }
public void SetFont(SCIFont spr) { ushort cnt = (ushort)(spr.Frames.Count & 0xFFFF); ByteBuilder bb = new ByteBuilder(); bb.AddByte(0); bb.AddShortLE(cnt); bb.AddShortLE(spr.FontHeight); bb.AddByte(0); for (int i = 0; i < cnt; i++) { bb.AddShortLE(0); } byte bit; byte bitMask; for (int i = 0; i < cnt; i++) { SpriteFrame frm = spr[i]; byte w = (byte)frm.Width; byte h = (byte)frm.Height; ushort offset = (ushort)bb.Position; bb.SetShortBE(6 + i * 2, offset); bb.AddByte(w); bb.AddByte(h); for (int y = 0; y < frm.Height; y++) { bit = 0; bitMask = 0; for (int x = 0; x < frm.Width; x++) { if (frm[x, y] == 1) { bitMask |= (byte)(1 << (7 - bit)); } bit++; if (bit == 8) { bit = 0; bb.AddByte(bitMask); bitMask = 0; } } if (bit != 0) { bb.AddByte(bitMask); } } } SaveTranslate(bb.GetArray()); }
public override byte[] GetPatch() { ushort cnt = (ushort)(_font.Frames.Count & 0xFFFF); ByteBuilder bb = new ByteBuilder(); bb.AddByte(0); bb.AddShortLE(cnt); bb.AddShortLE(_font.FontHeight); bb.AddByte(0); for (int i = 0; i < cnt; i++) { bb.AddShortLE(0); } byte bit; byte bitMask; for (int i = 0; i < cnt; i++) { SpriteFrame frm = _font[i]; byte w = (byte)frm.Width; byte h = (byte)frm.Height; ushort offset = (ushort)bb.Position; bb.SetShortBE(6 + i * 2, offset); bb.AddByte(w); bb.AddByte(h); for (int y = 0; y < frm.Height; y++) { bit = 0; bitMask = 0; for (int x = 0; x < frm.Width; x++) { if (frm[x, y] == 1) { bitMask |= (byte)(1 << (7 - bit)); } bit++; if (bit == 8) { bit = 0; bb.AddByte(bitMask); bitMask = 0; } } if (bit != 0) { bb.AddByte(bitMask); } } } return(bb.GetArray()); }
public override void WriteText(ByteBuilder bb, object data, GameEncoding encoding) { ushort textOffset = (ushort)bb.Position; var bytes = encoding.GetBytes(Text); bb.AddBytes(bytes); bb.AddByte(0); bb.SetShortBE((int)data, textOffset); }
public byte[] GetBytes() { ByteBuilder bb = new ByteBuilder(); foreach (Section sec in Sections) { bb.AddShortBE((ushort)sec.Type); int sizePos = bb.Position; bb.AddShortBE(0); sec.Write(bb); int endPos = bb.Position; bb.SetShortBE(sizePos, (ushort)(endPos - sizePos + 2)); } foreach (Section sec in Sections) { sec.WriteOffsets(bb); } bb.AddShortBE(0); return(bb.GetArray()); }
private void SaveV3(List <MessageRecord> messages, ByteBuilder bb) { bb.AddIntBE(header); int endOffset = bb.Position; bb.AddShortBE(0); bb.AddShortBE((ushort)messages.Count); object[] extra = new object[messages.Count]; for (int i = 0; i < messages.Count; i++) { extra[i] = messages[i].WriteHeader(bb); } for (int i = 0; i < messages.Count; i++) { messages[i].WriteText(bb, extra[i], GameEncoding); } bb.SetShortBE(endOffset, (ushort)(bb.Position - endOffset)); }
protected override void WriteExt(ByteBuilder bb) { bb.WritePicAbsCoord(ref _coord); var sizePos = bb.Position; bb.AddShortBE(0); // Потом вернемся, чтобы записать размер данных bb.AddShortBE(Width); bb.AddShortBE(Height); bb.AddShortBE(0); bb.AddByte(_transpCol); bb.AddByte(0); WriteImageData(bb); var endPos = bb.Position; var size = endPos - sizePos - 2; if (size > 0xffff) { throw new FormatException("Too big image data"); } bb.SetShortBE(sizePos, (ushort)size); }