protected virtual int WriteOutputStream(IntPtr buffer, int requestedBytes) { if (_deviceState == DeviceState.Stopped || _outputStreamEnded) { return((int)BASSStreamProc.BASS_STREAMPROC_END); } int read = ReadStream.Read(buffer, requestedBytes); if (read != -1) { return(read); } // We're done! // Play silence until playback has stopped to avoid any buffer underruns. read = _silence.Write(buffer, requestedBytes); // Set a flag so we call HandleOutputStreamEnded() only once. _outputStreamEnded = true; // Our input stream is finished, wait for device to end playback HandleOutputStreamAboutToEnd(); return(read); }
protected virtual int ReadBytes(byte[] buffer, int numberOfBytes) { var readBytes = ReadStream.Read(buffer, 0, numberOfBytes); Position += readBytes; return(readBytes); }
public void PlayGambatteMovie(string filename) { byte[] file = File.ReadAllBytes(filename); ReadStream movie = new ReadStream(file); Debug.Assert(movie.u8() == 0xfe, "The specified file was not a gambatte movie."); Debug.Assert(movie.u8() == 0x01, "The specified gambatte movie was of an incorrect version."); int stateSize = movie.u24be(); byte[] state = movie.Read(stateSize); LoadState(state); while (movie.Position < file.Length) { long samples = movie.u32be(); byte input = movie.u8(); if (input == 0xff) { HardReset(); } else { CurrentJoypad = (Joypad)input; while (samples > 0) { samples -= RunFor((int)Math.Min(samples, SamplesPerFrame)); } } } }
public GscSpecies(Gsc game, ReadStream data, ReadStream name) // Names are padded to 10 length using terminator characters. { Game = game; Name = game.Charmap.Decode(name.Read(10)); Id = data.u8(); BaseHP = data.u8(); BaseAttack = data.u8(); BaseDefense = data.u8(); BaseSpeed = data.u8(); BaseSpecialAttack = data.u8(); BaseSpecialDefense = data.u8(); Type1 = (GscType)data.u8(); Type2 = (GscType)data.u8(); CatchRate = data.u8(); BaseExp = data.u8(); Item1 = data.u8(); Item2 = data.u8(); GenderRatio = data.u8(); Unknown1 = data.u8(); HatchCycles = data.u8(); Unknown2 = data.u8(); FrontSpriteWidth = data.Nybble(); FrontSpriteHeight = data.Nybble(); data.Seek(4); // 4 unused bytes GrowthRate = (GrowthRate)data.u8(); EggGroup1 = (GscEggGroup)data.Nybble(); EggGroup2 = (GscEggGroup)data.Nybble(); data.Seek(8); // TODO: HMs/TMs }
public int ReadUInt32() { EnsureObjectNotDisposed(); var data = new byte[4]; ReadStream.Read(data, 0, 4); return(BitConverter.ToInt32(data, 0)); }
public ushort ReadUInt16() { EnsureObjectNotDisposed(); var data = new byte[2]; ReadStream.Read(data, 0, 2); return(BitConverter.ToUInt16(data, 0)); }
public static void Decode(ReadStream data, Bitmap dest) { PNGHeader header = data.Struct <PNGHeader>(true); Debug.Assert(header.Signature == PNGSignature, "Specified file was not a PNG file."); ReadStream idatStream = new ReadStream(); while (true) { PNGChunkHeader chunkHeader = data.Struct <PNGChunkHeader>(true); string chunkType = Encoding.ASCII.GetString(chunkHeader.Type, 4); byte[] chunkBytes = data.Read(chunkHeader.Length); ReadStream chunkData = new ReadStream(chunkBytes); PNGChunkFooter chunkFooter = data.Struct <PNGChunkFooter>(true); Debug.Assert(Crc32(chunkHeader.ToBytes().Concat(chunkBytes).ToArray(), 4) == chunkFooter.CRC, chunkType + " chunk's CRC mismatched!"); switch (chunkType) { case "IHDR": PNGIHDR ihdr = chunkData.Struct <PNGIHDR>(true); Debug.Assert(ihdr.BitDepth == 8 && ihdr.ColorType == 6 && ihdr.CompressionMethod == 0 && ihdr.FilterMethod == 0 && ihdr.InterlaceMethod == 0, "The specified PNG file uses an unsupported format."); dest.Width = ihdr.Width; dest.Height = ihdr.Height; dest.Pixels = new byte[ihdr.Width * ihdr.Height * 4]; break; case "IDAT": idatStream.Write(chunkData.Read(chunkHeader.Length)); break; case "IEND": idatStream.Seek(0, SeekOrigin.Begin); PNGIDATHeader idatHeader = idatStream.Struct <PNGIDATHeader>(true); byte[] idatData; PNGIDATFooter idatFooter; using (MemoryStream target = new MemoryStream()) using (DeflateStream decompressionStream = new DeflateStream(idatStream, CompressionMode.Decompress)) { decompressionStream.CopyTo(target); idatData = target.ToArray(); idatStream.Seek(-4); idatFooter = idatStream.Struct <PNGIDATFooter>(true); } Debug.Assert(idatFooter.CheckValue == Alder32(idatData), "IDAT chunk compression check value mismatch!"); int scanlineSize = dest.Width * 4; for (int scanline = 0; scanline < dest.Height; scanline++) { int offset = scanline * scanlineSize; Array.Copy(idatData, offset + scanline + 1, dest.Pixels, offset, scanlineSize); } return; } } }
public static void Decode(ReadStream data, Bitmap dest) { BMPHeader header = data.Struct <BMPHeader>(); Debug.Assert(header.Signature == BMPSignature, "Specified file was not a BMP file."); Debug.Assert(header.Size == InfoHeaderSize, "The BMP file contains an unsupported info header."); Debug.Assert(header.Compression == 0, "Only uncompressed BMP files are supported."); Debug.Assert(header.BitsPerPixel == 32, "Only 32-bit colors are supported."); Debug.Assert(header.FileSize - header.DataOffset == header.Width * header.Height * 4, "The BMP file is missing pixel data."); dest.Width = header.Width; dest.Height = header.Height; dest.Pixels = RemapData(data.Read(dest.Width * dest.Height * 4), dest.Width, dest.Height); }
public override int Read(byte[] buffer, int offset, int count) { int res = ReadStream.Read(buffer, offset, count); if (LogStream != null) { if (res > 0) { LogStream.Write(buffer, offset, res); } } return(res); }
public RbyTileset(Rby game, byte id, ReadStream data) { Game = game; Id = id; Bank = data.u8(); BlockPointer = data.u16le(); GfxPointer = data.u16le(); CollisionPointer = data.u16le(); CounterTiles = data.Read(3); GrassTile = data.u8(); data.Seek(1); TilePairCollisionsLand = new List <int>(); TilePairCollisionsWater = new List <int>(); LandPermissions = new PermissionSet(); LandPermissions.AddRange(game.ROM.From((game.IsYellow ? 0x01 : 0x00) << 16 | CollisionPointer).Until(0xff, false)); WaterPermissions = new PermissionSet(); WaterPermissions.Add(0x14); WaterPermissions.Add(0x32); if (id == 14) { WaterPermissions.Add(0x48); } WarpTiles = game.ROM.From(3 << 16 | game.ROM.u16le(game.SYM["WarpTileIDPointers"] + id * 2)).Until(0xff, false); ReadStream stream = game.ROM.From("DoorTileIDPointers"); DoorTiles = new byte[0]; for (; ;) { byte tileset = stream.u8(); ushort pointer = stream.u16le(); if (tileset == 0xff) { break; } if (tileset == Id) { DoorTiles = game.ROM.From(6 << 16 | pointer).Until(0x00, false); } } }
private byte[] ReadData(int count) { EnsureObjectNotDisposed(); using (var memory = new MemoryStream()) { while (count > 0) { var sc = (EncryptedStreamControl)ReadUInt16(); if (sc != EncryptedStreamControl.Data) { throw new ReadSecureChannelException("Stream read wrong stream control command received"); } var dataLen = ReadUInt16(); var encData = new byte[dataLen]; int nread = ReadStream.Read(encData, 0, encData.Length); if (nread != dataLen) { throw new ReadSecureChannelException("Stream readed unexpected block length"); } byte[] data; try { data = (ReadCipher != null) ? ReadCipher.Decrypt(encData) : encData; } catch (Exception e) { throw new ReadSecureChannelException(e, "Stream decrypt failed"); } memory.Write(data, 0, data.Length); count -= data.Length; } if (count != 0) { throw new ReadSecureChannelException("Stream total readed bytes is incorrect"); } return(memory.ToArray()); } }
private void ReceiveMessageFromWPF() { listener = new TcpListener(mediatorAddress); listener.Start(); byte[] bytes = new byte[256]; string data = null; ReadStream = client.GetStream(); int i; while ((i = ReadStream.Read(bytes, 0, bytes.Length)) != 0) { data = (Encoding.UTF8.GetString(bytes, 0, i)).ToUpper(); byte[] msg = Encoding.UTF8.GetBytes(data); ReadStream.Write(msg, 0, msg.Length); } richTextBox1.Text = ReadStream.ToString(); client.Close(); }
public override int Read(byte[] buffer, int offset, int count) { return(ReadStream.Read(buffer, offset, count)); }
public static void Literal(ReadStream compressed, List <byte> decompressed, int length) { // Copy 'length' bytes directly to the decompressed stream. decompressed.AddRange(compressed.Read(length)); }
public DetailedState(byte[] state) { ReadStream data = new ReadStream(state); Debug.Assert(data.u24be() == 0xff0201, "Not a gambatte savestate"); int snapshotSize = data.u24be(); SnapShot = data.Read(snapshotSize); while (data.Position < state.Length) { string label = ""; byte character; while ((character = data.u8()) != 0x00) { label += Convert.ToChar(character); } int size = data.u24be(); long startPos = data.Position; switch (label) { case "cc": CycleCounter = data.u32be(); break; case "pc": PC = data.u16be(); break; case "sp": SP = data.u16be(); break; case "a": A = data.u8(); break; case "b": B = data.u8(); break; case "c": C = data.u8(); break; case "d": D = data.u8(); break; case "e": E = data.u8(); break; case "f": F = data.u8(); break; case "h": H = data.u8(); break; case "l": L = data.u8(); break; case "op": Opcode = data.u8(); break; case "fetched": Fetched = data.boolean(); break; case "skip": Skip = data.boolean(); break; case "halt": Halted = data.boolean(); break; case "vram": VRAM = data.Read(size); break; case "sram": SRAM = data.Read(size); break; case "wram": WRAM = data.Read(size); break; case "hram": HRAM = data.Read(size); break; case "ldivup": DivLastUpdate = data.u32be(); break; case "ltimaup": TimaLastUpdate = data.u32be(); break; case "tmatime": TmaTime = data.u32be(); break; case "serialt": NextSerialTime = data.u32be(); break; case "lodmaup": LastOamDmaUpdate = data.u32be(); break; case "minintt": MinIntTime = data.u32be(); break; case "unhaltt": UnhaltTime = data.u32be(); break; case "rombank": RomBank = data.u16be(); break; case "dmasrc": DmaSource = data.u16be(); break; case "dmadst": DmaDestination = data.u16be(); break; case "rambank": RamBank = data.u8(); break; case "odmapos": OamDmaPos = data.u8(); break; case "hlthdma": HaltHdmaState = data.u8(); break; case "ime": IME = data.boolean(); break; case "sramon": EnableRam = data.boolean(); break; case "mbclock": MbcLockup = data.boolean(); break; case "rambmod": RamBankMode = data.u8(); break; case "hdma": HdmaTransfer = data.boolean(); break; case "bios": BiosMode = data.boolean(); break; case "stopped": Stopped = data.boolean(); break; case "huc3ram": Huc3RAMFlag = data.u8(); break; case "sgbsys": SgbSystemColors = data.ReadBE(size / 2); break; case "sgbcols": SgbColors = data.ReadBE(size / 2); break; case "sgbattr": SgbAttributes = data.Read(size); break; case "sgbpkt": SgbPacket = data.Read(size); break; case "sgbcmd": SgbCommand = data.Read(size); break; case "sgbxfer": SgbTransfer = data.u8(); break; case "sgbcmdi": SgbCommandIndex = data.u8(); break; case "sgbjoyi": SgbJoypadIndex = data.u8(); break; case "sgbjoym": SgbJoypadMask = data.u8(); break; case "sgbpend": SgbPending = data.u8(); break; case "sgbpc": SgbPendingCount = data.u8(); break; case "sgbmask": SgbMask = data.u8(); break; case "dmgcols": DmgColorsBgr15 = data.ReadBE(size / 2); break; case "bgp": BgPaletteData = data.Read(size); break; case "objp": ObjPaletteData = data.Read(size); break; case "sposbuf": OamReaderBuffer = data.Read(size); break; case "spszbuf": OamReaderSzBuffer = data.ReadBools(size); break; case "spattr": SpAttribList = data.Read(size); break; case "spbyte0": SpByte0List = data.Read(size); break; case "spbyte1": SpByte1List = data.Read(size); break; case "vcycles": VideoCycles = data.u32be(); break; case "edM0tim": EnableDisplayM0Time = data.u32be(); break; case "m0time": LastM0Time = data.u16be(); break; case "nm0irq": NextM0Irq = data.u16be(); break; case "bgtw": BgTileWord = data.u16be(); break; case "bgntw": BgnTileWord = data.u16be(); break; case "winypos": WinYPos = data.u8(); break; case "xpos": XPos = data.u8(); break; case "endx": EndX = data.u8(); break; case "ppur0": PPUReg0 = data.u8(); break; case "ppur1": PPUReg1 = data.u8(); break; case "bgatrb": BgAttrib = data.u8(); break; case "bgnatrb": BgnAttrib = data.u8(); break; case "ppustat": PPUState = data.u8(); break; case "nsprite": NextSprite = data.u8(); break; case "csprite": CurrentSprite = data.u8(); break; case "lyc": LYC = data.u8(); break; case "m0lyc": M0LYC = data.u8(); break; case "oldwy": OldWy = data.u8(); break; case "windraw": WinDrawState = data.u8(); break; case "wscx": wSCX = data.u8(); break; case "wemastr": weMaster = data.boolean(); break; case "lcdsirq": PendingLcdstatIrq = data.boolean(); break; case "iscgb": IsCgb = data.boolean(); break; case "spucntr": SPUCycleCounter = data.u32be(); break; case "spucntl": SPULastUpdate = data.u8(); break; case "swpcntr": SweepCounter = data.u32be(); break; case "swpshdw": SweepShadow = data.u16be(); break; case "swpneg": SweepNeg = data.boolean(); break; case "dut1ctr": Duty1NextPosUpdate = data.u32be(); break; case "dut1pos": Duty1Pos = data.u8(); break; case "dut1hi": Duty1High = data.boolean(); break; case "env1ctr": Env1Counter = data.u32be(); break; case "env1vol": Env1Volume = data.u8(); break; case "len1ctr": Len1Counter = data.u32be(); break; case "len1val": Len1LengthCounter = data.u16be(); break; case "nr10": Nr10 = data.u8(); break; case "nr13": Nr13 = data.u8(); break; case "nr14": Nr14 = data.u8(); break; case "c1mastr": Ch1Master = data.boolean(); break; case "dut2ctr": Duty2NextPosUpdate = data.u32be(); break; case "dut2pos": Duty2Pos = data.u8(); break; case "dut2hi": Duty2High = data.boolean(); break; case "env2ctr": Env2Counter = data.u32be(); break; case "env2vol": Env2Volume = data.u8(); break; case "len2ctr": Len2Counter = data.u32be(); break; case "len2val": Len2LengthCounter = data.u16be(); break; case "nr23": Nr23 = data.u8(); break; case "nr24": Nr24 = data.u8(); break; case "c2mastr": Ch2Master = data.boolean(); break; case "waveram": WaveRAM = data.Read(size); break; case "len3ctr": Len3Counter = data.u32be(); break; case "len3val": Len3LengthCounter = data.u16be(); break; case "wavectr": WaveCounter = data.u32be(); break; case "lwavrdt": WaveLastReadTime = data.u32be(); break; case "wavepos": WavePos = data.u8(); break; case "wavsmpl": WaveSampleBuffer = data.u8(); break; case "nr33": Nr33 = data.u8(); break; case "nr34": Nr34 = data.u8(); break; case "c3mastr": Ch3Master = data.boolean(); break; case "lfsrctr": LFSRCounter = data.u32be(); break; case "lfsrreg": LFSRReg = data.u16be(); break; case "env4ctr": Env4Counter = data.u32be(); break; case "env4vol": Env4Volume = data.u8(); break; case "len4ctr": Len4Counter = data.u32be(); break; case "len4val": Len4LengthCounter = data.u16be(); break; case "nr44": Nr44 = data.u8(); break; case "c4mastr": Ch4Master = data.boolean(); break; case "timesec": Seconds = data.u32be(); break; case "timelts": LastTimeSec = data.u32be(); break; case "timeltu": LastTimeUSec = data.u32be(); break; case "timelc": LastCycles = data.u32be(); break; case "rtchalt": RTCHaltTime = data.u32be(); break; case "rtcdh": RTCDataDh = data.u8(); break; case "rtcdl": RTCDataDl = data.u8(); break; case "rtch": RTCDataH = data.u8(); break; case "rtcm": RTCDataM = data.u8(); break; case "rtcs": RTCDataS = data.u8(); break; case "rtclld": RTCLastLatchData = data.boolean(); break; case "h3haltt": HuC3HaltTime = data.u32be(); break; case "h3datat": HuC3DataTime = data.u32be(); break; case "h3writt": HuC3WritingTime = data.u32be(); break; case "h3halt": HuC3Halted = data.boolean(); break; case "h3shft": HuC3Shift = data.u8(); break; case "h3rv": HuC3RamValue = data.u8(); break; case "h3mf": HuC3ModeFlag = data.u8(); break; case "h3ircy": HuC3IrBaseCycle = data.u32be(); break; case "h3irac": HuC3IrReceivingPulse = data.boolean(); break; default: Console.WriteLine("Unhandled label: " + label); data.Seek(size); break; } long endPos = data.Position; Debug.Assert(endPos - startPos == size, "Read incorrect number of bytes of label " + label); } }