Example #1
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteH(writer, (int)(Npc.Target as Player).UID);
            WriteH(writer, 0); // skill id
            WriteD(writer, Attack.Results[0]); // Damage 1

            WriteD(writer, Attack.Results[1]); // Damage 2
            WriteD(writer, Attack.Results[2]); // Damage 3
            WriteD(writer, Attack.Results[3]); // Damage 4
            WriteD(writer, Attack.Results[4]); // Damage 5
            WriteD(writer, 0); // skill id

            WriteD(writer, Attack.AttackAction); // FLD_EFFERT
            WriteF(writer, Npc.Position.X);
            WriteF(writer, Npc.Position.Z);
            WriteF(writer, Npc.Position.Y);
            WriteC(writer, 4);
            WriteC(writer, (byte)Attack.Count); // The number of attacks

            WriteH(writer, 0);
            WriteD(writer, Npc.Target.LifeStats.Hp); // Finally blood
            WriteD(writer, 0);
            WriteD(writer, 0);
            WriteD(writer, 0);
            WriteD(writer, 0);
            WriteD(writer, 0);

            writer.Seek(2, SeekOrigin.Begin);
            WriteH(writer, (int)Npc.UID);
            writer.Seek(0, SeekOrigin.End);
        }
Example #2
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteC(writer, (byte)Id);

            writer.Seek(2, SeekOrigin.Begin);
            WriteH(writer, (int)Player.UID);
            writer.Seek(0, SeekOrigin.End);
        }
Example #3
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteB(writer, Data);

            writer.Seek(4, SeekOrigin.Begin);
            WriteH(writer, Opcode);
            writer.Seek(0, SeekOrigin.End);
        }
Example #4
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteD(writer, 0);

            writer.Seek(2, SeekOrigin.Begin);
            if (Creature is Player)
                WriteH(writer, (int)(Creature as Player).UID);
            else if (Creature is Npc)
                WriteH(writer, (int)(Creature as Npc).UID);
            writer.Seek(0, SeekOrigin.End);
        }
Example #5
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteD(writer, 1);
            WriteD(writer, Count);
            WriteD(writer, MaxCount);
            WriteD(writer, 1);

            writer.Seek(2, SeekOrigin.Begin);
            WriteH(writer, (int)Player.UID);
            writer.Seek(0, SeekOrigin.End);
        }
Example #6
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteF(writer, Creature.Position.X);
            WriteF(writer, Creature.Position.Y);
            WriteF(writer, Creature.Position.Z);

            WriteD(writer, -1);
            WriteD(writer, MoveStyle);
            WriteF(writer, Creature.Position.X);
            WriteD(writer, (Creature as Npc).LifeStats.Hp);

            writer.Seek(2, SeekOrigin.Begin);
            WriteH(writer, (int)(Creature as Npc).UID);
            writer.Seek(0, SeekOrigin.End);
        }
        public async override Task<bool> InstallPackageAsync(Packaging.Core.PackageIdentity packageIdentity, System.IO.Stream packageStream,
            INuGetProjectContext nuGetProjectContext, CancellationToken token)
        {
            if (!packageStream.CanSeek)
            {
                throw new ArgumentException(NuGet.ProjectManagement.Strings.PackageStreamShouldBeSeekable);
            }

            nuGetProjectContext.Log(MessageLevel.Info, Strings.InstallingPackage, packageIdentity);

            packageStream.Seek(0, SeekOrigin.Begin);
            var zipArchive = new ZipArchive(packageStream);
            PackageReader packageReader = new PackageReader(zipArchive);
            var packageSupportedFrameworks = packageReader.GetSupportedFrameworks();
            var projectFrameworks = _project.GetSupportedFrameworksAsync(token)
                .Result
                .Select(f => NuGetFramework.Parse(f.FullName));

            var args = new Dictionary<string, object>();
            args["Frameworks"] = projectFrameworks.Where(
                projectFramework =>
                    IsCompatible(projectFramework, packageSupportedFrameworks)).ToArray();
            await _project.InstallPackageAsync(
                new NuGetPackageMoniker
                {
                    Id = packageIdentity.Id,
                    Version = packageIdentity.Version.ToNormalizedString()
                },
                args,
                logger: null,
                progress: null,
                cancellationToken: token);
            return true;
        }
		public static bool CompareStream(System.IO.Stream input, System.IO.Stream output)
		{
			if (!input.CanRead)
				throw new ArgumentException("input stream cannot be read", "input");
			if (!input.CanSeek)
				throw new ArgumentException("input stream cannot seek", "input");
			if (!output.CanRead)
				throw new ArgumentException("output stream cannot be read", "output");
			if (!output.CanSeek)
				throw new ArgumentException("output stream cannot seek", "output");
			if (input == output)
				throw new ArgumentException("cannot compare the same stream as input");

			input.Seek(0, SeekOrigin.Begin);
			output.Seek(0, SeekOrigin.Begin);

			for (;;)
			{
				int i = input.ReadByte();
				int o = output.ReadByte();
				if (i == -1 && o == -1)			//end of both
					return true;
				else if (i == -1 || o == -1)	//end of one but not the other
					return false;
				else if (i != o)				//different bytes
					return false;
			}
		}
Example #9
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteC(writer, (byte)Type);

            if (IsSystemMessage)
                WriteSN(writer, "System");
            else
                WriteSN(writer, Player.PlayerData.Name);

            WriteB(writer, new byte[7]);
            WriteS(writer, Message);

            writer.Seek(2, SeekOrigin.Begin);
            WriteH(writer, (int)((IsSystemMessage) ? 0 : Player.UID));
            writer.Seek(0, SeekOrigin.End);
        }
Example #10
0
        private bool LoadFile( System.IO.Stream File )
        {
            byte[] outsizebytes = new byte[4];
            File.Seek( 0x04, System.IO.SeekOrigin.Begin );
            File.Read( outsizebytes, 0, 4 );
            uint OutSize = BitConverter.ToUInt32( outsizebytes, 0 );

            byte[] compFile = new byte[(int)File.Length - 0x10];
            File.Seek( 0x10, System.IO.SeekOrigin.Begin );
            File.Read( compFile, 0, (int)File.Length - 0x10 );

            byte[] decompFile = Ionic.Zlib.ZlibStream.UncompressBuffer( compFile );
            ExtractedFile = decompFile;

            File.Close();
            return true;
        }
Example #11
0
 public static byte[] toByteArray(System.IO.Stream stream)
 {
     byte[] bytes = new byte[stream.Length];
     stream.Read(bytes, 0, bytes.Length);
     // 设置当前流的位置为流的开始
     stream.Seek(0, SeekOrigin.Begin);
     return bytes;
 }
Example #12
0
 public static void Skip(int skipval, System.IO.Stream instream, long positionlessthan)
 {
     while (instream.ReadByte() == 0 && instream.Position < positionlessthan)
     {
     }
     if (instream.Position < positionlessthan)
         instream.Seek(-1, System.IO.SeekOrigin.Current);
 }
Example #13
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            for (int i = 0; i < 30; i++)
            {
                if (Player.Inventory.EquipItems.ContainsKey(i) && i <= 15)
                {
                    var item = Player.Inventory.GetEquipItem(i);
                    WriteItemInfo(writer, item);
                }
                else
                    WriteB(writer, new byte[88]);
            }

            writer.Seek(2, SeekOrigin.Begin);
            WriteH(writer, (int)Player.UID);
            writer.Seek(0, SeekOrigin.End);
        }
Example #14
0
 public Command Receive(ref System.IO.MemoryStream stream, ref IPEndPoint ipendpoint)
 {
     var receiveBytes = UDP.Receive(ref ipendpoint);
     stream.SetLength(0); // Очистка потока
     stream.Write(receiveBytes, 0, receiveBytes.Length);
     stream.Seek(0, System.IO.SeekOrigin.Begin);
     return (m_biFormatter.Deserialize(stream) as Command);
 }
Example #15
0
 public override void ParseObject(System.IO.Stream _input, string _contentType, long _contentLength, string _fileName, string _targetFileName, string _fieldName)
 {
     FileStream stream = new FileStream(_targetFileName, FileMode.CreateNew);
     var res = new byte[_input.Length];
     _input.Seek(0, SeekOrigin.Begin);
     _input.Read(res, 0, res.Length);
     stream.Write(res, 0, res.Length);
     stream.Close();
 }
Example #16
0
        protected internal static long FindSignature(System.IO.Stream s, int SignatureToFind)
        {
            long startingPosition = s.Position;

            int BATCH_SIZE = 1024;
            byte[] targetBytes = new byte[4];
            targetBytes[0] = (byte) (SignatureToFind >> 24);
            targetBytes[1] = (byte) ((SignatureToFind & 0x00FF0000) >> 16);
            targetBytes[2] = (byte) ((SignatureToFind & 0x0000FF00) >> 8);
            targetBytes[3] = (byte) (SignatureToFind & 0x000000FF);
            byte[] batch = new byte[BATCH_SIZE];
            int n = 0;
            bool success = false;
            do
            {
                n = s.Read(batch, 0, batch.Length);
                if (n != 0)
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (batch[i] == targetBytes[3])
                        {
                            s.Seek(i - n, System.IO.SeekOrigin.Current);
                            int sig = ReadSignature(s);
                            success = (sig == SignatureToFind);
                            if (!success) s.Seek(-3, System.IO.SeekOrigin.Current);
                            break; // out of for loop
                        }
                    }
                }
                else break;
                if (success) break;
            } while (true);
            if (!success)
            {
                s.Seek(startingPosition, System.IO.SeekOrigin.Begin);
                return -1;  // or throw?
            }

            // subtract 4 for the signature.
            long bytesRead = (s.Position - startingPosition) - 4 ;
            // number of bytes read, should be the same as compressed size of file            
            return bytesRead;   
        }
Example #17
0
        public static byte[] StreamToBytes(System.IO.Stream Stream)
        {
            if (Stream == null) return null;

            byte[] buffer = null;
            if (Stream.Position > 0 && Stream.CanSeek) Stream.Seek(0, System.IO.SeekOrigin.Begin);
            buffer = new byte[Stream.Length];
            Stream.Read(buffer, 0, (int)buffer.Length);
            return buffer;
        }
Example #18
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteD(writer, 2);

            WriteF(writer, X1);
            WriteF(writer, Z1);
            WriteF(writer, Y1);

            WriteF(writer, X2);
            WriteF(writer, Z2);
            WriteF(writer, Y2);

            WriteD(writer, 1);
            WriteF(writer, Distance);
            WriteD(writer, Target);

            writer.Seek(2, SeekOrigin.Begin);
            WriteH(writer, (int)Player.UID);
            writer.Seek(0, SeekOrigin.End);
        }
Example #19
0
		internal static ZipDirEntry Read(System.IO.Stream s, bool TurnOnDebug) {

			int signature = GodLesZ.Library.Xna.WindowLibrary.External.Zip.Shared.ReadSignature(s);
			// return null if this is not a local file header signature
			if (SignatureIsNotValid(signature)) {
				s.Seek(-4, System.IO.SeekOrigin.Current);
				if (TurnOnDebug)
					System.Console.WriteLine("  ZipDirEntry::Read(): Bad signature ({0:X8}) at position {1}", signature, s.Position);
				return null;
			}

			byte[] block = new byte[42];
			int n = s.Read(block, 0, block.Length);
			if (n != block.Length)
				return null;

			int i = 0;
			ZipDirEntry zde = new ZipDirEntry();

			zde._Debug = TurnOnDebug;
			zde._VersionMadeBy = (short)(block[i++] + block[i++] * 256);
			zde._VersionNeeded = (short)(block[i++] + block[i++] * 256);
			zde._BitField = (short)(block[i++] + block[i++] * 256);
			zde._CompressionMethod = (short)(block[i++] + block[i++] * 256);
			zde._LastModDateTime = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
			zde._Crc32 = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
			zde._CompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
			zde._UncompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;

			zde._LastModified = GodLesZ.Library.Xna.WindowLibrary.External.Zip.Shared.PackedToDateTime(zde._LastModDateTime);

			Int16 filenameLength = (short)(block[i++] + block[i++] * 256);
			Int16 extraFieldLength = (short)(block[i++] + block[i++] * 256);
			Int16 commentLength = (short)(block[i++] + block[i++] * 256);
			Int16 diskNumber = (short)(block[i++] + block[i++] * 256);
			Int16 internalFileAttrs = (short)(block[i++] + block[i++] * 256);
			Int32 externalFileAttrs = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
			Int32 Offset = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;

			block = new byte[filenameLength];
			n = s.Read(block, 0, block.Length);
			zde._FileName = GodLesZ.Library.Xna.WindowLibrary.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);

			zde._Extra = new byte[extraFieldLength];
			n = s.Read(zde._Extra, 0, zde._Extra.Length);

			block = new byte[commentLength];
			n = s.Read(block, 0, block.Length);
			zde._Comment = GodLesZ.Library.Xna.WindowLibrary.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);

			return zde;
		}
 public void Save(string file, System.IO.MemoryStream contents)
 {
     using (System.IO.IsolatedStorage.IsolatedStorageFile isoStorage = GetISOStorage())
     {
         using (var writer = new System.IO.IsolatedStorage.IsolatedStorageFileStream(file, System.IO.FileMode.Create, isoStorage))
         {
             if (contents.CanSeek && contents.Position > 0) contents.Seek(0, SeekOrigin.Begin);
             byte[] data = contents.ToArray();
             writer.Write(data, 0, data.Length);
             writer.Close();
         }
     }
 }
Example #21
0
 // Create a local report for Report.rdlc, load the data,
 //    export the report to an .emf file, and print it.
 public void PrintDataSource(DataTable dt, IEnumerable<ReportParameter> param, System.Drawing.Printing.PrinterSettings ps, ref System.IO.MemoryStream ReportDefinition)
 {
     LocalReport report = new LocalReport();
     this.ps = ps;
     //report.ReportPath = @"Examine.rdlc";
     ReportDefinition.Seek(0, SeekOrigin.Begin);
     report.LoadReportDefinition(ReportDefinition);
     report.DataSources.Add(new ReportDataSource("BossCom_RecordPatient", dt));
     report.SetParameters(param);
     Export(report);
     m_currentPageIndex = 0;
     Print();
 }
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        public DocumentOutput AddDocumentOutput(int documentId, string type, int status, System.IO.Stream file)
        {
            if (this._dbContainer == null)
                throw new EntityManagerException("Nu suntem conectati la baza de date!");

            file.Seek(0, System.IO.SeekOrigin.Begin);
            /*citim tot ce este in buffer*/
            byte[] buffer = new byte[file.Length];
            file.Read(buffer, 0, (int)file.Length);

            return this.AddDocumentOutput(documentId, type, status,
                Encoding.UTF8.GetString(buffer, 0, buffer.Length));
        }
        public void CreateProjectSourceFile(System.IO.Stream stream)
        {
            string dirPath = Path.GetDirectoryName(fullPath);
            if(!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            stream.Seek(0, SeekOrigin.Begin);
            using (FileStream fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write))
            {
                stream.CopyTo(fileStream);
            }
        }
Example #24
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            WriteD(writer, 1);

            WriteH(writer, (int)Npc.UID);
            WriteH(writer, (int)Npc.UID);

            WriteH(writer, Npc.NpcId);

            WriteD(writer, 1);

            WriteD(writer, Npc.LifeStats.Hp);
            WriteD(writer, Npc.MaxHp);

            WriteF(writer, Npc.Position.X);
            WriteF(writer, Npc.Position.Z);
            WriteF(writer, Npc.Position.Y);

            WriteD(writer, 0x40800000);

            WriteF(writer, Npc.SpawnTemplate.Face1);
            WriteF(writer, Npc.SpawnTemplate.Face2);

            WriteF(writer, Npc.Position.X);
            WriteF(writer, Npc.Position.Z);
            WriteF(writer, Npc.Position.Y);

            WriteD(writer, 0);
            WriteD(writer, 0);
            WriteD(writer, 0x0C);
            WriteD(writer, 0);

            writer.Seek(2, SeekOrigin.Begin);
            WriteH(writer, (int)Npc.UID);
            writer.Seek(0, SeekOrigin.End);
        }
Example #25
0
        public static string GuessEndOfLineMark( System.IO.Stream  stream, string defaultEoL )
        {
            if( !stream.CanSeek )
                return defaultEoL;

            string eol = defaultEoL;
            long   pos = stream.Position;
            try
            {
                stream.Seek( 0L, System.IO.SeekOrigin.Begin );
                var reader = new System.IO.StreamReader( stream, Encoding.UTF8, true, 4096 );

                char [] buf    = new char[ 512 ];
                int     offset = 0;
                for(int i = 0;  i < 20; ++i )
                {
                    reader.Read( buf, offset, 512 - offset );
                    offset = 1;

                    int     foundAt = Array.IndexOf( buf, '\n' );
                    if( foundAt == -1 )
                        continue;

                    eol = (foundAt > 0 && buf[ foundAt - 1 ] == '\r')
                            ? "\r\n"
                            : "\n";
                    break;
                }
            }
            finally
            {
                stream.Seek( pos, System.IO.SeekOrigin.Begin );
            }

            return eol;
        }
Example #26
0
        /// <summary>
        /// Reads data from a stream until the end is reached. The
        /// data is returned as a byte array. An IOException is
        /// thrown if any of the underlying IO calls fail.
        /// </summary>
        /// <param name="stream">The stream to read data from</param>
        /// <param name="initialLength">The initial buffer length</param>
        public static byte[] ReadFully(System.IO.Stream stream, long initialLength)
        {
            // reset pointer just in case
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            // If we've been passed an unhelpful initial length, just
            // use 32K.
            if (initialLength < 1)
            {
                initialLength = 32768;
            }

            byte[] buffer = new byte[initialLength];
            int read = 0;

            int chunk;
            while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0)
            {
                read += chunk;

                // If we've reached the end of our buffer, check to see if there's
                // any more information
                if (read == buffer.Length)
                {
                    int nextByte = stream.ReadByte();

                    // End of stream? If so, we're done
                    if (nextByte == -1)
                    {
                        return buffer;
                    }

                    // Nope. Resize the buffer, put in the byte we've just
                    // read, and continue
                    byte[] newBuffer = new byte[buffer.Length * 2];
                    Array.Copy(buffer, newBuffer, buffer.Length);
                    newBuffer[read] = (byte)nextByte;
                    buffer = newBuffer;
                    read++;
                }
            }
            // Buffer is now too big. Shrink it.
            byte[] ret = new byte[read];
            Array.Copy(buffer, ret, read);
            return ret;
        }
Example #27
0
        protected override void InternalSend(System.IO.Stream messageBody)
        {
            string message;
            
            try
            {
                
                System.IO.StreamReader sr = new System.IO.StreamReader(messageBody);
                messageBody.Seek(0, System.IO.SeekOrigin.Begin);
                message = string.Format(CultureInfo.InvariantCulture, "ClusterId={0}, ClusterMemberId={1}, Message={2}", ClusterMemberInfo.ClusterID, ClusterMemberInfo.ClusterMemberID, sr.ReadToEnd());
            }
            catch (Exception ex) //TODO: catch block
            {
                message = "[an exception has been thrown: " + ex.Message + "]";
            }

            //System.Diagnostics.Trace.WriteLine(string.Concat("ClusterMessage in TraceChannel: ", message));
        }
        protected override long OnExecute(System.IO.FileStream targetStream, long sizeHint)
        {
            sizeHint = sizeHint/ReductionFactor;

            var readBuffer  = new byte[ReadSize];
            var randomizer  = new Random();

            while (readEntries.Any())
            {
                var index       = randomizer.Next(0, readEntries.Count);
                var readEntry   = readEntries[index];

                targetStream.Seek((long) index*(long) ReadSize, SeekOrigin.Begin);
                targetStream.Read(readBuffer, 0, readEntry.Item1);

                readEntries.RemoveAt(index);
            }

            return sizeHint;
        }
        private static bool WriteXyzHeadVer01( System.IO.Stream stream, XyzHeadReader xyzHead )
        {
            if ( stream == null )
                throw new ArgumentNullException( "stream" );

            if ( xyzHead == null )
                throw new ArgumentNullException( "xyzHead" );

            byte[] byteULong = new byte[8];

            // 00 ~ 03: 标识符号 : 是否是XYZ的标识(写入)
            stream.Write( xyzHead.Tag, 0, xyzHead.Tag.Length );

            // 03 ~ 04: XYZ文件版本号(写入)
            stream.WriteByte( (byte)xyzHead.Version );

            // 04 ~ 05: XYZ文件内实体名称的加密方式 ( 0 为无加密, 1... 为其它加密方式 )(写入)
            stream.WriteByte( (byte)xyzHead.EncryptType );

            // 05 ~ 13: 主评论信息的文件偏移(写入)
            xyzHead.CommentOffset.ToArrayInByte( ref byteULong, 0 );
            stream.Write( byteULong, 0, byteULong.Length );

            // 13 ~ 21: 第一个XYZ文件内实体的文件偏移(写入)
            xyzHead.FirstEntryOffset.ToArrayInByte( ref byteULong, 0 );
            stream.Write( byteULong, 0, byteULong.Length );

            // XYZ文件内实体评论的信息(写入)
            if ( xyzHead.CommentReader == null  )
            {
                if ( xyzHead.CommentOffset > 0 )
                    throw new ArgumentException( "xyzHead.CommentReader == null && xyzHead.CommentOffset > 0 error!", "xyzComment.CommentReader & xyzComment.CommentOffset" );
                else
                    return true;
            }

            stream.Seek( (long)xyzHead.CommentOffset, SeekOrigin.Begin );
            XyzCommentWriter.WriteComment( stream, xyzHead.CommentReader );

            return true;
        }
Example #30
0
        public override bool IsCorrectFormat(System.IO.FileStream fs)
        {
            System.IO.BinaryReader _brdrReader = new System.IO.BinaryReader(fs);

            // Make sure file size > 4100 (data begins after a 4100-byte header).
            if (fs.Length <= 4100)
            {
                return false;
            }

            // Datatype field in header ONLY can be 0~3
            // We can finde the datatype at offset 108 according to the file spec.
            fs.Seek(108, System.IO.SeekOrigin.Begin);

            DataType _dtDataType = (DataType)_brdrReader.ReadInt16();
            if (_dtDataType < DataType.SPE_DATA_FLOAT || _dtDataType > DataType.SPE_DATA_UINT)
            {
                return false;
            }
            return true;
        }