Ejemplo n.º 1
0
        /// <summary>
        /// ファイルからデータをロード
        /// </summary>
        public static void LoadData()
        {
            if(System.IO.File.Exists(@SAVEFILE)){
                using(var fs = System.IO.File.Open(@SAVEFILE,System.IO.FileMode.Open)){
                    // バイナリリーダ作成
                    var br = new System.IO.BinaryReader(fs);

                    // Read data
                    Global.isStageOpened[(int)StageID.Stage1] = br.ReadBoolean();
                    Global.isStageOpened[(int)StageID.Stage2] = br.ReadBoolean();
                    Global.isStageOpened[(int)StageID.Stage3] = br.ReadBoolean();

                    Global.characterLevel = br.ReadInt32();
                    Global.characterExp = br.ReadInt32();

                    br.Close();
                }
            }else{
                Global.isStageOpened[(int)StageID.Stage1] = true;
                Global.isStageOpened[(int)StageID.Stage2] = false;
                Global.isStageOpened[(int)StageID.Stage3] = false;

                Global.characterLevel = 1;
                Global.characterExp = 0;
            }
        }
Ejemplo n.º 2
0
 //変化があった場合のバイナリ読みこみ
 protected virtual void ReadChanged(System.IO.BinaryReader reader)
 {
     Target.SetActive(reader.ReadBoolean());
     reader.ReadRectTransfom(RectTransform);
 }
 /// <summary>
 ///Deserializes BlobTrackerCalibrateState
 ///</summary>
 ///<param name="reader">the reader from which to deserialize</param>
 ///<returns>deserialized BlobTrackerCalibrateState</returns>
 public virtual object Deserialize(System.IO.BinaryReader reader)
 {
     this._Processing = reader.ReadBoolean();
     this._Shutdown   = reader.ReadBoolean();
     return(this);
 }
Ejemplo n.º 4
0
 public override void Read(ref System.IO.BinaryReader stream)
 {
     what = stream.ReadBoolean();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Load state
 /// </summary>
 /// <param name="stream">The stream that should be used to read data</param>
 public virtual void LoadState(System.IO.BinaryReader stream)
 {
     readMode     = stream.ReadBoolean();
     PCMIRQenable = stream.ReadBoolean();
     irqTrip      = stream.ReadBoolean();
 }
Ejemplo n.º 6
0
 /// <summary>
 ///Deserializes LegoMazeDriverState
 ///</summary>
 ///<param name="reader">the reader from which to deserialize</param>
 ///<returns>deserialized LegoMazeDriverState</returns>
 public virtual object Deserialize(System.IO.BinaryReader reader)
 {
     this._MotorEnabled = reader.ReadBoolean();
     return(this);
 }
Ejemplo n.º 7
0
Archivo: Column.cs Proyecto: vebin/BD2
 public static Column Deserialize(Frontend fb, byte[] chunkID, byte[] buffer)
 {
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream (buffer)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
             return new Column (fb, chunkID, BR.ReadString (), fb.ValueSerializer.IDToType (BR.ReadByte ()), BR.ReadBoolean (), BR.ReadInt64 ());
         }
     }
 }
Ejemplo n.º 8
0
        public Int32 Reset()
        {
            if ((mStream == null) || (mReader == null))
            {
                return(AResult.AE_FAIL);
            }

            mStream.Position = 0;
            if ((mStream.Length - mStream.Position) < (sizeof(Boolean) + sizeof(Int32)))
            {
                return(AResult.AE_FAIL);
            }

            mIsLittleEndian = mReader.ReadBoolean();
            mReader.ReadInt32();

            return(AResult.AS_OK);
        }
Ejemplo n.º 9
0
Archivo: Column.cs Proyecto: vebin/BD2
 public static Column Deserialize(byte[] bytes)
 {
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
             return new Column (new Guid (BR.ReadBytes (16)), BR.ReadString (), BR.ReadBoolean (), BR.ReadInt64 (), BR.ReadString ());
         }
     }
 }
Ejemplo n.º 10
0
 public override void loadState(System.IO.BinaryReader reader)
 {
     base.loadState(reader);
     canSee = reader.ReadBoolean();
 }
Ejemplo n.º 11
0
        public static void Read(this IPathCommand command, System.IO.BinaryReader reader)
        {
            switch (command.Type)
            {
            case CommandType.MoveTo:
            {
                MoveTo pCommand = command as MoveTo;
                pCommand.X = reader.ReadDouble();
                pCommand.Y = reader.ReadDouble();
            }
            break;

            case CommandType.LineTo:
            {
                LineTo pCommand = command as LineTo;
                pCommand.X = reader.ReadDouble();
                pCommand.Y = reader.ReadDouble();
            }
            break;

            case CommandType.CurveTo:
            {
                CurveTo pCommand = command as CurveTo;
                pCommand.ControlStart = reader.ReadPoint();
                pCommand.ControlEnd   = reader.ReadPoint();
                pCommand.End          = reader.ReadPoint();
            }
            break;

            case CommandType.SmoothCurveTo:
            {
                SmoothCurveTo pCommand = command as SmoothCurveTo;
                pCommand.ControlEnd = reader.ReadPoint();
                pCommand.End        = reader.ReadPoint();
            }
            break;

            case CommandType.EllipticalArcTo:
            {
                EllipticalArcTo pCommand = command as EllipticalArcTo;
                pCommand.Size           = new Size(reader.ReadDouble(), reader.ReadDouble());
                pCommand.End            = reader.ReadPoint();
                pCommand.RotationAngle  = reader.ReadDouble();
                pCommand.IsLargeArc     = reader.ReadBoolean();
                pCommand.SweepDirection = (reader.ReadBoolean() == false ? SweepDirection.Counterclockwise : SweepDirection.Clockwise);
            }
            break;

            case CommandType.QuadraticBeizerCurveTo:
            {
                QuadraticBeizerCurveTo pCommand = command as QuadraticBeizerCurveTo;
                pCommand.Control = reader.ReadPoint();
                pCommand.End     = reader.ReadPoint();
            }
            break;

            case CommandType.SmoothQuadraticBeizerCurveTo:
            {
                SmoothQuadraticBeizerCurveTo pCommand = command as SmoothQuadraticBeizerCurveTo;
                pCommand.End = reader.ReadPoint();
            }
            break;

            case CommandType.ClosePath:
            {
                // Do nothing
            }
            break;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Читает P-объект из бинарного ридера, начиная с текущего места
        /// </summary>
        /// <param name="typ"></param>
        /// <param name="br"></param>
        /// <returns></returns>
        public static object GetPO(PType typ, System.IO.BinaryReader br)
        {
            switch (typ.Vid)
            {
            case PTypeEnumeration.none: return(null);

            case PTypeEnumeration.boolean: return(br.ReadBoolean());

            case PTypeEnumeration.integer: return(br.ReadInt32());

            case PTypeEnumeration.longinteger: return(br.ReadInt64());

            case PTypeEnumeration.real: return(br.ReadDouble());

            case PTypeEnumeration.@byte: return(br.ReadByte());

            case PTypeEnumeration.fstring:
            {
                //int len = ((PTypeFString)typ).Length;
                int    size = ((PTypeFString)typ).Size;
                byte[] arr  = new byte[size];
                arr = br.ReadBytes(size);
                string s = System.Text.Encoding.Unicode.GetString(arr);
                return(s);
            }

            case PTypeEnumeration.sstring:
            {
                //int len = br.ReadInt32();
                //char[] chrs = br.ReadChars(len);
                //return new string(chrs);
                return(br.ReadString());
            }

            case PTypeEnumeration.record:
            {
                PTypeRecord r_tp   = (PTypeRecord)typ;
                object[]    fields = new object[r_tp.Fields.Length];
                for (int i = 0; i < r_tp.Fields.Length; i++)
                {
                    fields[i] = GetPO(r_tp.Fields[i].Type, br);
                }
                return(fields);
            }

            case PTypeEnumeration.sequence:
            {
                PTypeSequence mts  = (PTypeSequence)typ;
                PType         tel  = mts.ElementType;
                long          llen = br.ReadInt64();
                object[]      els  = new object[llen];
                for (long ii = 0; ii < llen; ii++)
                {
                    els[ii] = GetPO(tel, br);
                }
                return(els);
            }

            case PTypeEnumeration.union:
            {
                PTypeUnion mtu = (PTypeUnion)typ;
                int        v   = br.ReadByte();
                PType      mt  = mtu.Variants[v].Type;
                return(new object[] { v, GetPO(mt, br) });
            }

            default: throw new Exception("Err in TPath Get(): type is not implemented " + typ.Vid);
            }
        }
Ejemplo n.º 13
0
        private void LoadGroupObject(BinaryReader reader, int key, Dictionary<int, object> objects)
        {
            var comparer = ObjectReferenceEqualityComparer<object>.Default;

            int typeKey = reader.ReadInt32();
            if (typeKey == 0)
            {
                // this is a string, nothing more to load
                reader.ReadString();
                return;
            }

            string typeName = (string)objects[typeKey];
            if (typeName == typeof(bool).FullName)
            {
                // nothing more to load
                reader.ReadBoolean();
                return;
            }
            else if (typeName == typeof(TemplateToken).FullName || typeName == typeof(CommonToken).FullName)
            {
                // nothing more to load
                int channel = reader.ReadInt32();
                int charPositionInLine = reader.ReadInt32();
                int line = reader.ReadInt32();
                int startIndex = reader.ReadInt32();
                int stopIndex = reader.ReadInt32();
                string text = reader.ReadString();
                int tokenIndex = reader.ReadInt32();
                int type = reader.ReadInt32();
                return;
            }
            else if (typeName == typeof(CompiledTemplate).FullName)
            {
                CompiledTemplate compiledTemplate = (CompiledTemplate)objects[key];
                string name = reader.ReadString();
                string prefix = reader.ReadString();
                string template = reader.ReadString();
                int templateDefStartTokenObject = reader.ReadInt32();
                bool hasFormalArgs = reader.ReadBoolean();
                int nativeGroupObject = reader.ReadInt32();
                bool isRegion = reader.ReadBoolean();
                Template.RegionType regionDefType = (Template.RegionType)reader.ReadInt32();
                bool isAnonSubtemplate = reader.ReadBoolean();

                compiledTemplate.TemplateDefStartToken = (IToken)objects[templateDefStartTokenObject];
                compiledTemplate.NativeGroup = this;

                int formalArgsLength = reader.ReadInt32();
                if (formalArgsLength >= 0)
                {
                    List<FormalArgument> formalArguments = new List<FormalArgument>(formalArgsLength);

                    for (int i = 0; i < formalArgsLength; i++)
                    {
                        int formalArgObject = reader.ReadInt32();
                        formalArguments.Add((FormalArgument)objects[formalArgObject]);
                    }

                    compiledTemplate.FormalArguments = formalArguments;
                }

                int stringsLength = reader.ReadInt32();
                for (int i = 0; i < stringsLength; i++)
                    reader.ReadString();

                int instrsLength = reader.ReadInt32();
                if (instrsLength >= 0)
                    reader.ReadBytes(instrsLength);

                int codeSize = reader.ReadInt32();

                int sourceMapLength = reader.ReadInt32();
                for (int i = 0; i < sourceMapLength; i++)
                {
                    int start = reader.ReadInt32();
                    int length = reader.ReadInt32();
                }

                return;
            }
            else if (typeName == typeof(FormalArgument).FullName)
            {
                FormalArgument formalArgument = (FormalArgument)objects[key];
                string name = reader.ReadString();
                int index = reader.ReadInt32();
                IToken defaultValueToken = (IToken)objects[reader.ReadInt32()];
                int defaultValueObject = reader.ReadInt32();
                int compiledDefaultValue = reader.ReadInt32();

                formalArgument.DefaultValue = objects[defaultValueObject];
                formalArgument.CompiledDefaultValue = (CompiledTemplate)objects[compiledDefaultValue];
            }
            else if (typeName == typeof(Template).FullName)
            {
                Template template = (Template)objects[key];

                int implObject = reader.ReadInt32();
                template.impl = (CompiledTemplate)objects[implObject];

                int localsCount = reader.ReadInt32();
                if (localsCount >= 0)
                {
                    template.locals = new object[localsCount];
                    for (int i = 0; i < localsCount; i++)
                    {
                        int localObject = reader.ReadInt32();
                        template.locals[i] = objects[localObject];
                    }
                }

                int groupObject = reader.ReadInt32();
                template.Group = (TemplateGroup)objects[groupObject];

                return;
            }
            else if (typeName == typeof(TemplateGroupFile).FullName)
            {
                bool isDefaultGroup = reader.ReadBoolean();
                return;
            }
            else if (typeName == typeof(TemplateGroup).FullName)
            {
                bool isDefaultGroup = reader.ReadBoolean();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 14
0
        private object CreateGroupObject(BinaryReader reader, int key, Dictionary<int, object> objects)
        {
            var comparer = ObjectReferenceEqualityComparer<object>.Default;

            int typeKey = reader.ReadInt32();
            if (typeKey == 0)
            {
                // this is a string
                return reader.ReadString();
            }

            string typeName = (string)objects[typeKey];
            if (typeName == typeof(bool).FullName)
            {
                return reader.ReadBoolean();
            }
            else if (typeName == typeof(TemplateToken).FullName || typeName == typeof(CommonToken).FullName)
            {
                int channel = reader.ReadInt32();
                int charPositionInLine = reader.ReadInt32();
                int line = reader.ReadInt32();
                int startIndex = reader.ReadInt32();
                int stopIndex = reader.ReadInt32();
                string text = reader.ReadString();
                int tokenIndex = reader.ReadInt32();
                int type = reader.ReadInt32();
                CommonToken token = new CommonToken(type, text)
                {
                    Channel = channel,
                    CharPositionInLine = charPositionInLine,
                    Line = line,
                    StartIndex = startIndex,
                    StopIndex = stopIndex,
                    TokenIndex = tokenIndex,
                };

                return token;
            }
            else if (typeName == typeof(CompiledTemplate).FullName)
            {
                CompiledTemplate compiledTemplate = new CompiledTemplate();
                compiledTemplate.Name = reader.ReadString();
                compiledTemplate.Prefix = reader.ReadString();
                compiledTemplate.Template = reader.ReadString();
                int templateDefStartTokenObject = reader.ReadInt32();
                compiledTemplate.HasFormalArgs = reader.ReadBoolean();
                int nativeGroupObject = reader.ReadInt32();
                compiledTemplate.IsRegion = reader.ReadBoolean();
                compiledTemplate.RegionDefType = (Template.RegionType)reader.ReadInt32();
                compiledTemplate.IsAnonSubtemplate = reader.ReadBoolean();

                int formalArgsLength = reader.ReadInt32();
                if (formalArgsLength > 0)
                {
                    for (int i = 0; i < formalArgsLength; i++)
                    {
                        int formalArgObject = reader.ReadInt32();
                    }
                }

                int stringsLength = reader.ReadInt32();
                if (stringsLength >= 0)
                {
                    compiledTemplate.strings = new string[stringsLength];
                    for (int i = 0; i < stringsLength; i++)
                        compiledTemplate.strings[i] = reader.ReadString();
                }

                int instrsLength = reader.ReadInt32();
                if (instrsLength >= 0)
                    compiledTemplate.instrs = reader.ReadBytes(instrsLength);

                compiledTemplate.codeSize = reader.ReadInt32();

                int sourceMapLength = reader.ReadInt32();
                if (sourceMapLength >= 0)
                {
                    compiledTemplate.sourceMap = new Interval[sourceMapLength];
                    for (int i = 0; i < sourceMapLength; i++)
                    {
                        int start = reader.ReadInt32();
                        int length = reader.ReadInt32();
                        if (length >= 0)
                            compiledTemplate.sourceMap[i] = new Interval(start, length);
                    }
                }

                return compiledTemplate;
            }
            else if (typeName == typeof(FormalArgument).FullName)
            {
                string name = reader.ReadString();
                int index = reader.ReadInt32();
                IToken defaultValueToken = (IToken)objects[reader.ReadInt32()];
                int defaultValueObject = reader.ReadInt32();
                int compiledDefaultValue = reader.ReadInt32();

                FormalArgument formalArgument = new FormalArgument(name, defaultValueToken);
                formalArgument.Index = index;

                return formalArgument;
            }
            else if (typeName == typeof(Template).FullName)
            {
                int implObject = reader.ReadInt32();

                int localsCount = reader.ReadInt32();
                for (int i = 0; i < localsCount; i++)
                {
                    int localObject = reader.ReadInt32();
                }

                int groupObject = reader.ReadInt32();

                TemplateGroup group = this;
                Template template = new Template(group);
                return template;
            }
            else if (typeName == typeof(TemplateGroupFile).FullName)
            {
                bool isDefaultGroup = reader.ReadBoolean();
                if (!isDefaultGroup)
                    return this;
                else
                    throw new NotSupportedException();
            }
            else if (typeName == typeof(TemplateGroup).FullName)
            {
                bool isDefaultGroup = reader.ReadBoolean();
                if (isDefaultGroup)
                    return TemplateGroup.DefaultGroup;
                else
                    throw new NotSupportedException();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 15
0
 public override void LoadState(System.IO.BinaryReader stream)
 {
     base.LoadState(stream);
     irqEnable  = stream.ReadBoolean();
     irqCounter = stream.ReadInt32();
 }
Ejemplo n.º 16
0
 public override void loadState(System.IO.BinaryReader reader)
 {
     base.loadState(reader);
     direction = new Vector2(reader.ReadSingle(), reader.ReadSingle());
     active    = reader.ReadBoolean();
 }
Ejemplo n.º 17
0
 //UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
 public virtual void  readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf)
 {
     data = in_Renamed.ReadBoolean();
 }
Ejemplo n.º 18
0
 public override void LoadState(System.IO.BinaryReader stream)
 {
     base.LoadState(stream);
     enableReg = stream.ReadBoolean();
     vromReg   = stream.ReadInt32();
 }
Ejemplo n.º 19
0
        public static JSONNode Deserialize(System.IO.BinaryReader aReader)
        {
            JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();

            switch (type)
            {
            case JSONBinaryTag.Array:
            {
                int       count = aReader.ReadInt32();
                JSONArray tmp   = new JSONArray();
                for (int i = 0; i < count; i++)
                {
                    tmp.Add(Deserialize(aReader));
                }
                return(tmp);
            }

            case JSONBinaryTag.Class:
            {
                int       count = aReader.ReadInt32();
                JSONClass tmp   = new JSONClass();
                for (int i = 0; i < count; i++)
                {
                    string key = aReader.ReadString();
                    var    val = Deserialize(aReader);
                    tmp.Add(key, val);
                }
                return(tmp);
            }

            case JSONBinaryTag.Value:
            {
                return(new JSONData(aReader.ReadString()));
            }

            case JSONBinaryTag.IntValue:
            {
                return(new JSONData(aReader.ReadInt32()));
            }

            case JSONBinaryTag.DoubleValue:
            {
                return(new JSONData(aReader.ReadDouble()));
            }

            case JSONBinaryTag.BoolValue:
            {
                return(new JSONData(aReader.ReadBoolean()));
            }

            case JSONBinaryTag.FloatValue:
            {
                return(new JSONData(aReader.ReadSingle()));
            }

            default:
            {
                throw new Exception("Error deserializing JSON. Unknown tag: " + type);
            }
            }
        }
Ejemplo n.º 20
0
 public override void Deserialize(System.IO.BinaryReader reader)
 {
     base.Deserialize(reader);
     _hasWon = reader.ReadBoolean();
 }
Ejemplo n.º 21
0
 public static Column Deserialize(FrontendInstanceBase fib, byte[] chunkID, byte[] buffer)
 {
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream(buffer)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader(MS)) {
             return(new Column(fib, BR.ReadBytes(32), chunkID, BR.ReadString(), ((Frontend)fib.Frontend).ValueDeserializer.IDToType(BR.ReadByte()), BR.ReadBoolean(), BR.ReadInt64()));
         }
     }
 }
Ejemplo n.º 22
0
        public static Entity ReadFrom(System.IO.BinaryReader reader)
        {
            int id       = reader.ReadInt32();
            int?playerId = null;

            if (reader.ReadBoolean())
            {
                playerId = reader.ReadInt32();
            }

            Model.EntityType entityType;
            switch (reader.ReadInt32())
            {
            case 0:
                entityType = Model.EntityType.Wall;
                break;

            case 1:
                entityType = Model.EntityType.House;
                break;

            case 2:
                entityType = Model.EntityType.BuilderBase;
                break;

            case 3:
                entityType = Model.EntityType.BuilderUnit;
                break;

            case 4:
                entityType = Model.EntityType.MeleeBase;
                break;

            case 5:
                entityType = Model.EntityType.MeleeUnit;
                break;

            case 6:
                entityType = Model.EntityType.RangedBase;
                break;

            case 7:
                entityType = Model.EntityType.RangedUnit;
                break;

            case 8:
                entityType = Model.EntityType.Resource;
                break;

            case 9:
                entityType = Model.EntityType.Turret;
                break;

            default:
                throw new System.Exception("Unexpected tag value");
            }

            Vec2Int position = Model.Vec2Int.ReadFrom(reader);
            int     health   = reader.ReadInt32();
            bool    active   = reader.ReadBoolean();
            var     result   = new Entity(id, playerId, entityType, position, health, active);

            return(result);
        }
Ejemplo n.º 23
0
        public static Entity ReadFrom(System.IO.BinaryReader reader)
        {
            var result = new Entity();

            result.Id = reader.ReadInt32();
            if (reader.ReadBoolean())
            {
                result.PlayerId = reader.ReadInt32();
            }
            else
            {
                result.PlayerId = null;
            }
            switch (reader.ReadInt32())
            {
            case 0:
                result.EntityType = Model.EntityType.Wall;
                break;

            case 1:
                result.EntityType = Model.EntityType.House;
                break;

            case 2:
                result.EntityType = Model.EntityType.BuilderBase;
                break;

            case 3:
                result.EntityType = Model.EntityType.BuilderUnit;
                break;

            case 4:
                result.EntityType = Model.EntityType.MeleeBase;
                break;

            case 5:
                result.EntityType = Model.EntityType.MeleeUnit;
                break;

            case 6:
                result.EntityType = Model.EntityType.RangedBase;
                break;

            case 7:
                result.EntityType = Model.EntityType.RangedUnit;
                break;

            case 8:
                result.EntityType = Model.EntityType.Resource;
                break;

            case 9:
                result.EntityType = Model.EntityType.Turret;
                break;

            default:
                throw new System.Exception("Unexpected tag value");
            }
            result.Position = Model.Vec2Int.ReadFrom(reader);
            result.Health   = reader.ReadInt32();
            result.Active   = reader.ReadBoolean();
            return(result);
        }
Ejemplo n.º 24
0
        public static PlayerView ReadFrom(System.IO.BinaryReader reader)
        {
            int  myId                 = reader.ReadInt32();
            int  mapSize              = reader.ReadInt32();
            bool fogOfWar             = reader.ReadBoolean();
            int  entityPropertiesSize = reader.ReadInt32();
            var  entityProperties     = new System.Collections.Generic.Dictionary <Model.EntityType, Model.EntityProperties>(entityPropertiesSize);

            for (int i = 0; i < entityPropertiesSize; i++)
            {
                Model.EntityType entityPropertiesKey;
                switch (reader.ReadInt32())
                {
                case 0:
                    entityPropertiesKey = Model.EntityType.Wall;
                    break;

                case 1:
                    entityPropertiesKey = Model.EntityType.House;
                    break;

                case 2:
                    entityPropertiesKey = Model.EntityType.BuilderBase;
                    break;

                case 3:
                    entityPropertiesKey = Model.EntityType.BuilderUnit;
                    break;

                case 4:
                    entityPropertiesKey = Model.EntityType.MeleeBase;
                    break;

                case 5:
                    entityPropertiesKey = Model.EntityType.MeleeUnit;
                    break;

                case 6:
                    entityPropertiesKey = Model.EntityType.RangedBase;
                    break;

                case 7:
                    entityPropertiesKey = Model.EntityType.RangedUnit;
                    break;

                case 8:
                    entityPropertiesKey = Model.EntityType.Resource;
                    break;

                case 9:
                    entityPropertiesKey = Model.EntityType.Turret;
                    break;

                default:
                    throw new System.Exception("Unexpected tag value");
                }

                Model.EntityProperties entityPropertiesValue;
                entityPropertiesValue = Model.EntityProperties.ReadFrom(reader);
                entityProperties.Add(entityPropertiesKey, entityPropertiesValue);
            }

            int maxTickCount     = reader.ReadInt32();
            int maxPathfindNodes = reader.ReadInt32();
            int currentTick      = reader.ReadInt32();

            Player[] players = new Model.Player[reader.ReadInt32()];
            for (int i = 0; i < players.Length; i++)
            {
                players[i] = Model.Player.ReadFrom(reader);
            }

            Entity[] entities = new Model.Entity[reader.ReadInt32()];
            for (int i = 0; i < entities.Length; i++)
            {
                entities[i] = Model.Entity.ReadFrom(reader);
            }

            var result = new PlayerView(
                myId,
                mapSize,
                fogOfWar,
                entityProperties,
                maxTickCount,
                maxPathfindNodes,
                currentTick,
                players,
                entities);

            return(result);
        }
Ejemplo n.º 25
0
 public override void LoadState(System.IO.BinaryReader stream)
 {
     base.LoadState(stream);
     chr_mode = stream.ReadBoolean();
 }
Ejemplo n.º 26
0
        public override object Deserialize(System.IO.BinaryReader binaryReader)
        {
            bool hasValue = binaryReader.ReadBoolean();

            if (!hasValue)
            {
                return(null);
            }
            int typeID = binaryReader.ReadByte();

            switch (typeID)
            {
            case 1:
                return(binaryReader.ReadBoolean());

            case 2:
                return(binaryReader.ReadByte());

            case 128:
                return(binaryReader.ReadSByte());

            case 3:
                return(binaryReader.ReadInt16());

            case 129:
                return(binaryReader.ReadUInt16());

            case 4:
                return(binaryReader.ReadInt32());

            case 130:
                return(binaryReader.ReadUInt32());

            case 5:
                return(binaryReader.ReadInt64());

            case 131:
                return(binaryReader.ReadUInt64());

            case 9:
                return(binaryReader.ReadDouble());

            case 16:
                return(binaryReader.ReadString());

            case 144:
                return(binaryReader.ReadChar());

            case 24:
                return(new DateTime(binaryReader.ReadInt64()));

            case 32:
                return(new Guid(binaryReader.ReadBytes(16)));

            case 36:
                return(binaryReader.ReadBytes(binaryReader.ReadInt32()));

            default:
                throw new Exception(string.Format("Serialization for type <{0}> is not supported", typeID));
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// 读bool
 /// </summary>
 /// <returns></returns>
 public bool ReadBool()
 {
     return(reader.ReadBoolean());
 }
Ejemplo n.º 28
0
 public static PollNewChunksRequestMessage Deserialize(byte[] bytes)
 {
     Guid id;
     bool metaOnly;
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
             id = new Guid (BR.ReadBytes (16));
             metaOnly = BR.ReadBoolean ();
         }
     }
     return new PollNewChunksRequestMessage (id, metaOnly);
 }
Ejemplo n.º 29
0
 public void loadState(System.IO.BinaryReader reader)
 {
     _life   = reader.ReadSingle();
     maxlife = reader.ReadSingle();
     isGod   = reader.ReadBoolean();
 }
Ejemplo n.º 30
0
 public bool Read(ref bool val, string name = null)
 {
     val = _reader.ReadBoolean();
     return(true);
 }
            /// <summary>
            /// reads a file and populates the map receiver instance.
            /// </summary>
            /// <returns></returns>
            public static bool Read_pachm(out Mapping.PachMapReceiver[] Map)
            {
                System.Windows.Forms.OpenFileDialog of = new System.Windows.Forms.OpenFileDialog();
                of.DefaultExt = ".pachm";
                of.AddExtension = true;
                of.Filter = "Pachyderm Mapping Data File (*.pachm)|*.pachm|" + "All Files|";
                if (of.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    Map = null;
                    return false;
                }
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(of.FileName, System.IO.FileMode.Open));
                //1. Write calculation type. (string)
                string CalcType = sr.ReadString();
                if (CalcType != "Type;Map_Data" && CalcType != "Type;Map_Data_NoDir") throw new Exception("Map Data File Expected");
                bool Directional = (CalcType == "Type;Map_Data");

                //2. Write the number of samples in each histogram. (int)
                int SampleCT = (int)sr.ReadUInt32();
                //3. Write the sample rate. (int)
                int SampleRate = (int)sr.ReadUInt32();
                //4. Write the number of Receivers (int)
                int Rec_CT = (int)sr.ReadUInt32();
                //4.5 Write the version number
                double version = 1.1;
                double rev = 0;
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                int s_ct=1;
                Rhino.Geometry.Mesh Map_Mesh = new Rhino.Geometry.Mesh();
                Map = new Mapping.PachMapReceiver[1];
                //Map[0] = new Pach_Map_Receiver();
                //double[] Rho_C = null;
                double[] delay;

                do
                {
                    switch (sr.ReadString())
                    {
                        case "Version":
                            //Pach1.7 = Versioning functionality added.
                            string v = sr.ReadString();
                            version = double.Parse(v.Substring(0, 3));
                            rev = int.Parse(v.Split(new char[1] { '.' })[3]);
                            break;
                        case "Mesh Information":
                            //6. Announce Mesh Vertices (string)
                            //Write the number of vertices & faces (int) (int)
                            if (sr.ReadString() != "Mesh Vertices") throw new Exception("Mesh Vertices Expected");

                            int VC = (int)sr.ReadUInt32();
                            int FC = (int)sr.ReadUInt32();
                            for (int i = 0; i < VC; i++)
                            {
                                //Write Vertex: (double) (double) (double)
                                Map_Mesh.Vertices.Add(new Rhino.Geometry.Point3d(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()));
                            }

                            //7. Announce Mesh Faces (string)
                            if (sr.ReadString() != "Mesh Faces") throw new Exception("Mesh Faces Expected");

                            for (int i = 0; i < FC; i++)
                            {
                                // Write mesh vertex indices: (int) (int) (int) (int)
                                Map_Mesh.Faces.AddFace((int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32());
                            }
                            break;
                        case "Sources":
                            //7.5: Announce the number of sources.
                            s_ct = sr.ReadInt32();
                            delay = new double[s_ct];
                            Map = new Mapping.PachMapReceiver[s_ct];
                            //7.5a Announce the type of source.

                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s] = new Mapping.PachMapReceiver();
                                Map[s].CutOffTime = (double)SampleCT / (double)SampleRate;
                                Map[s].SampleCT = SampleCT;
                                Map[s].SampleRate = SampleRate;
                                Map[s].Map_Mesh = Map_Mesh;
                                Map[s].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[s].SrcType = sr.ReadString();
                                //4.4 Source delay (ms)
                                if (version > 2.0 || (version == 2.0 && rev >= 1))
                                {
                                    delay[s] = sr.ReadDouble();
                                }
                            }
                            break;
                        case "SourceswLoc":
                            //7.5: Announce the number of sources.
                            s_ct = sr.ReadInt32();
                            delay = new double[s_ct];
                            Map = new Mapping.PachMapReceiver[s_ct];
                            //7.5a Announce the type of source.

                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s] = new Mapping.PachMapReceiver();
                                Map[s].CutOffTime = (double)SampleCT / (double)SampleRate * 1000;
                                Map[s].SampleCT = SampleCT;
                                Map[s].SampleRate = SampleRate;
                                Map[s].Map_Mesh = Map_Mesh;
                                Map[s].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[s].Src = new Rhino.Geometry.Point3d(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                                Map[s].SrcType = sr.ReadString();
                                //4.4 Source delay (ms)
                                if (version > 2.0 || (version == 2.0 && rev >= 1))
                                {
                                    delay[s] = sr.ReadDouble();
                                }
                            }
                            break;
                        case "Receiver Hit Data":
                            if (Map[0] == null)
                            {
                                Map = new Mapping.PachMapReceiver[1];
                                Map[0] = new Mapping.PachMapReceiver();
                                Map[0].CutOffTime = (double)SampleCT / (double)SampleRate;
                                Map[0].SampleRate = SampleRate;
                                Map[0].SampleCT = SampleCT;
                                Map[0].Map_Mesh = Map_Mesh;
                                Map[0].Rec_List = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                                Map[0].SrcType = "Geodesic";
                            }

                            //8. Announce that the following data pertains to the receiver histograms (string)
                            //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                            bool vert_Receiver = sr.ReadBoolean();
                            for (int s = 0; s < s_ct; s++)
                            {
                                Map[s].Rec_Vertex = vert_Receiver;
                                for (int i = 0; i < Map[s].Rec_List.Length; i++)
                                {
                                    //for version 1.7 and up, write direct sound arrival time.
                                    //Write Receiver Index (int)
                                    int j = (int)sr.ReadUInt32();
                                    //Write Direct Sound Arrival Time.
                                    double Direct_Time;
                                    if (version >= 1.7) Direct_Time = sr.ReadDouble(); else Direct_Time = (Utilities.PachTools.RPttoHPt(Map[s].Src) - Map[s].Rec_List[i].H_Origin).Length() / 343f;
                                    //Write Impedance of Air
                                    double Rho_C = version >= 2.0 ? sr.ReadDouble() : 400;

                                    if (vert_Receiver)
                                    {
                                        Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(Map_Mesh.Vertices[i], new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                    }
                                    else
                                    {
                                        Rhino.Geometry.Point3d RecLoc = Map_Mesh.Faces.GetFaceCenter(i);
                                        Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(new Rhino.Geometry.Point3f((float)RecLoc.X, (float)RecLoc.Y, (float)RecLoc.Z), new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                    }

                                    for (int Octave = 0; Octave < 8; Octave++)
                                    {
                                        //Write Octave (int)
                                        int Oct_out = (int)sr.ReadUInt32();
                                        if (Oct_out != Octave) throw new Exception(string.Format("Octave {0} Expected", Octave));
                                        double[] Hist = Map[s].Rec_List[i].GetEnergyHistogram(Octave);
                                        if (Directional)
                                        {
                                            if (version < 1.7)
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                            else
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                        else
                                        {
                                            if (version < 1.7)
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                            else
                                            {
                                                for (int e = 0; e < SampleCT; e++)
                                                    Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0,0,0), Octave);
                                            }
                                        }
                                    }
                                    if (sr.ReadString() != "End_Receiver_Hits") throw new Exception("End of Receiver Hits Expected");
                                }
                            }
                            break;
                        case "End_of_File":
                            sr.Close();
                            return true;
                    }
                } while (true);
                throw new Exception("Unsuccessful Read");
            }
Ejemplo n.º 32
0
 public override bool BinaryReadValue(System.IO.BinaryReader reader)
 {
     return(reader.ReadBoolean());
 }
Ejemplo n.º 33
0
        public static BuildProperties ReadFrom(System.IO.BinaryReader reader)
        {
            var result = new BuildProperties();

            result.Options = new Model.EntityType[reader.ReadInt32()];
            for (int i = 0; i < result.Options.Length; i++)
            {
                switch (reader.ReadInt32())
                {
                case 0:
                    result.Options[i] = Model.EntityType.Wall;
                    break;

                case 1:
                    result.Options[i] = Model.EntityType.House;
                    break;

                case 2:
                    result.Options[i] = Model.EntityType.BuilderBase;
                    break;

                case 3:
                    result.Options[i] = Model.EntityType.BuilderUnit;
                    break;

                case 4:
                    result.Options[i] = Model.EntityType.MeleeBase;
                    break;

                case 5:
                    result.Options[i] = Model.EntityType.MeleeUnit;
                    break;

                case 6:
                    result.Options[i] = Model.EntityType.RangedBase;
                    break;

                case 7:
                    result.Options[i] = Model.EntityType.RangedUnit;
                    break;

                case 8:
                    result.Options[i] = Model.EntityType.Resource;
                    break;

                case 9:
                    result.Options[i] = Model.EntityType.Turret;
                    break;

                default:
                    throw new System.Exception("Unexpected tag value");
                }
            }
            if (reader.ReadBoolean())
            {
                result.InitHealth = reader.ReadInt32();
            }
            else
            {
                result.InitHealth = null;
            }
            return(result);
        }
Ejemplo n.º 34
0
 public static PollChunksRequestMessage Deserialize(byte[] bytes)
 {
     Guid id;
     Guid chunkIDs;
     bool requestData;
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
             id = new Guid (BR.ReadBytes (16));
             chunkIDs = new Guid (BR.ReadBytes (16));
             requestData = BR.ReadBoolean ();
         }
     }
     return new PollChunksRequestMessage (id, chunkIDs, requestData);
 }
Ejemplo n.º 35
0
        public RecievePacket handleData(System.IO.BinaryReader br, System.IO.BinaryWriter bw, System.Net.Sockets.TcpClient client)
        {
            //online bool, name,realname,,avatar,playcount,totalscore,mode,currentsong,currentchart, accuracy, level
            bool online = br.ReadBoolean();

            if (online)
            {
                //Console.WriteLine("name:" + br.ReadString());
                //Console.WriteLine("pc:" + br.ReadInt32());
                string   user       = br.ReadString();
                string   rn         = br.ReadString();
                string   avatar     = br.ReadString();
                int      pc         = br.ReadInt32();
                int      totalscore = br.ReadInt32();
                PlayMode pm         = (PlayMode)br.ReadInt32();
                string   cs         = br.ReadString();
                string   cc         = br.ReadString();
                float    acc        = br.ReadSingle();//float
                int      lvl        = br.ReadInt32();
                lock (User.users)
                {
                    if (User.users.ContainsKey(user))
                    {
                        User.users[user].Name           = user;
                        User.users[user].RealName       = rn;
                        User.users[user].Avatar         = avatar;
                        User.users[user].Playcount      = pc;
                        User.users[user].TotalScore     = totalscore;
                        User.users[user].Mode           = pm;
                        User.users[user].CurrentSong    = cs;
                        User.users[user].CurrentChart   = cs;
                        User.users[user].Accuracy       = acc;
                        User.users[user].Level          = lvl;
                        User.users[user].UpdateGraphics = true;
                    }
                    else
                    {
                        User u = new User()
                        {
                            Name         = user,
                            RealName     = rn,
                            Avatar       = avatar,
                            Playcount    = pc,
                            TotalScore   = totalscore,
                            Mode         = pm,
                            CurrentSong  = cs,
                            CurrentChart = cc,
                            Accuracy     = acc,
                            Level        = lvl
                        };


                        User.users.Add(user, u);
                        u.UpdateGraphics = true;
                    }
                    Console.WriteLine("added/modified {0} score is {1}", user, totalscore);
                }
            }
            else
            {
                string removeuser = br.ReadString();
                lock (User.users)
                {
                    if (User.users.ContainsKey(removeuser))
                    {
                        Console.WriteLine("removed {0}", removeuser);
                        Console.WriteLine(User.users.Remove(removeuser) + " at removing " + removeuser);
                    }
                    else
                    {
                        Console.WriteLine("no key userhandler.cs");
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 36
0
        public static Material LoadMaterial(System.IO.BinaryReader bs)
        {
            var result = new Material();

            bool neutral_material_color = true;

            result.checksum      = bs.ReadUInt32();
            result.name_checksum = bs.ReadUInt32();
            var passes = bs.ReadUInt32();

            result.AlphaCutoff = bs.ReadUInt32();

            result.sorted              = bs.ReadBoolean();
            result.draw_order          = bs.ReadSingle();
            result.single_sided        = bs.ReadBoolean();
            result.no_backface_culling = bs.ReadBoolean();

            result.zbias = bs.ReadInt32();

            result.grassify = bs.ReadBoolean();
            if (result.grassify)
            {
                result.grass_height = bs.ReadSingle();
                result.grass_layers = bs.ReadInt32();
            }

            float w = bs.ReadSingle();

            if (w > 0)
            {
                result.specular_colour = new System.Numerics.Vector4(bs.ReadSingle(), bs.ReadSingle(), bs.ReadSingle(), w);
            }
            else
            {
                result.specular_colour = new System.Numerics.Vector4(0f, 0f, 0f, w);
            }

            var materials = new List <MaterialTexture>();

            for (var i = 0; i < passes; i++)
            {
                System.UInt32 TextureChecksum = 0;
                var           texture         = new MaterialTexture();
                TextureChecksum    = bs.ReadUInt32();
                texture.flags      = bs.ReadUInt32();
                texture.has_colour = bs.ReadBoolean();
                texture.colour     = new System.Numerics.Vector3(bs.ReadSingle(), bs.ReadSingle(), bs.ReadSingle());
                texture.reg_alpha  = bs.ReadUInt64();

                if (neutral_material_color)
                {
                    if (texture.colour.X != 0.5 && texture.colour.Y != 0.5 && texture.colour.Z != 0.5)
                    {
                        neutral_material_color = false;
                    }
                }


                texture.u_addressing = bs.ReadUInt32();
                texture.v_addressing = bs.ReadUInt32();

                texture.envmap_tiling  = new System.Numerics.Vector2(bs.ReadSingle(), bs.ReadSingle());
                texture.filtering_mode = bs.ReadUInt32();

                //read uv wibble, vc wibble, colour wibble...
                if ((texture.flags & (uint)EMaterialFlag.MATFLAG_UV_WIBBLE) != 0)
                {
                    texture.uvWibbleParams = new UVWibbleParams();

                    texture.uvWibbleParams.UVel       = bs.ReadSingle();
                    texture.uvWibbleParams.VVel       = bs.ReadSingle();
                    texture.uvWibbleParams.UFrequency = bs.ReadSingle();
                    texture.uvWibbleParams.VFrequency = bs.ReadSingle();
                    texture.uvWibbleParams.UAmplitude = bs.ReadSingle();
                    texture.uvWibbleParams.VAmplitude = bs.ReadSingle();
                    texture.uvWibbleParams.UPhase     = bs.ReadSingle();
                    texture.uvWibbleParams.VPhase     = bs.ReadSingle();
                }

                if (i == 0 && (texture.flags & (uint)EMaterialFlag.MATFLAG_VC_WIBBLE) != 0)
                {
                    texture.vcWibbleParams = new List <VCWibbleParams>();
                    System.UInt32 num_sequences = bs.ReadUInt32();
                    for (var x = 0; x < num_sequences; x++)
                    {
                        var           vcWibbleParam = new VCWibbleParams();
                        System.UInt32 num_keys      = bs.ReadUInt32();
                        System.Int32  phase         = bs.ReadInt32();
                        vcWibbleParam.phase = phase;

                        List <VCWibbleKeyframe> keyframes = new List <VCWibbleKeyframe>();
                        for (var j = 0; j < num_keys; j++)
                        {
                            VCWibbleKeyframe frame = new VCWibbleKeyframe();
                            frame.time   = bs.ReadInt32();
                            frame.colour = new System.Numerics.Vector4(bs.ReadByte(), bs.ReadByte(), bs.ReadByte(), bs.ReadByte());
                            keyframes.Add(frame);
                        }
                        vcWibbleParam.keyframes = keyframes;
                        texture.vcWibbleParams.Add(vcWibbleParam);
                    }
                }

                if ((texture.flags & (uint)EMaterialFlag.MATFLAG_PASS_TEXTURE_ANIMATES) != 0)
                {
                    texture.textureWibbleParams = new sTextureWibbleParams();
                    texture.textureWibbleParams.num_keyframes  = bs.ReadInt32();
                    texture.textureWibbleParams.period         = bs.ReadInt32();
                    texture.textureWibbleParams.num_iterations = bs.ReadInt32();
                    texture.textureWibbleParams.phase          = bs.ReadInt32();

                    var keyframes = new List <sTextureWibbleKeyframe>();
                    for (var x = 0; x < texture.textureWibbleParams.num_keyframes; ++x)
                    {
                        var frame = new sTextureWibbleKeyframe();
                        frame.time    = bs.ReadUInt32();
                        frame.texture = bs.ReadUInt32();

                        if (x == 0)
                        {
                            TextureChecksum = frame.texture;
                        }
                        keyframes.Add(frame);
                    }

                    texture.textureWibbleParams.keyframes = keyframes;
                }



                texture.MMAG = bs.ReadUInt32();
                texture.MMIN = bs.ReadUInt32();
                texture.K    = bs.ReadUInt32();
                texture.L    = bs.ReadUInt32();

                texture.Checksum = TextureChecksum;
                materials.Add(texture);
            }

            /*if (neutral_material_color && materials.Count > 0)
             * {
             *  materials[0].flags |= (uint)EMaterialFlag.MATFLAG_NO_MAT_COL_MOD;
             * }
             * else if (neutral_material_color)
             * {
             *  System.Diagnostics.Debugger.Break();
             * }
             *
             * if (result.specular_colour.W > 0.0f && materials.Count > 0)
             * {
             *  materials[0].flags |= (uint)EMaterialFlag.MATFLAG_SPECULAR;
             * } else if(result.specular_colour.W > 0.0f)
             * {
             *  System.Diagnostics.Debugger.Break();
             * }*/

            result.materialTextures = materials;


            return(result);
        }
Ejemplo n.º 37
0
        void OnReceive(DebugMessageType type, byte[] buffer)
        {
            if (clientSocket == null || clientSocket.Disconnected)
            {
                return;
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer);
            System.IO.BinaryReader br = new System.IO.BinaryReader(ms);

            switch (type)
            {
            case DebugMessageType.CSAttach:
            {
                SendAttachResult();
            }
            break;

            case DebugMessageType.CSBindBreakpoint:
            {
                CSBindBreakpoint msg = new Protocol.CSBindBreakpoint();
                msg.BreakpointHashCode = br.ReadInt32();
                msg.IsLambda           = br.ReadBoolean();
                msg.TypeName           = br.ReadString();
                msg.MethodName         = br.ReadString();
                msg.StartLine          = br.ReadInt32();
                msg.EndLine            = br.ReadInt32();
                TryBindBreakpoint(msg);
            }
            break;

            case DebugMessageType.CSDeleteBreakpoint:
            {
                CSDeleteBreakpoint msg = new Protocol.CSDeleteBreakpoint();
                msg.BreakpointHashCode = br.ReadInt32();
                ds.DeleteBreakpoint(msg.BreakpointHashCode);
            }
            break;

            case DebugMessageType.CSExecute:
            {
                CSExecute msg = new Protocol.CSExecute();
                msg.ThreadHashCode = br.ReadInt32();
                ds.ExecuteThread(msg.ThreadHashCode);
            }
            break;

            case DebugMessageType.CSStep:
            {
                CSStep msg = new CSStep();
                msg.ThreadHashCode = br.ReadInt32();
                msg.StepType       = (StepTypes)br.ReadByte();
                ds.StepThread(msg.ThreadHashCode, msg.StepType);
            }
            break;

            case DebugMessageType.CSResolveVariable:
            {
                CSResolveVariable msg = new CSResolveVariable();
                msg.ThreadHashCode = br.ReadInt32();
                msg.Variable       = ReadVariableReference(br);
                VariableInfo info;
                try
                {
                    object res;
                    info = ds.ResolveVariable(msg.ThreadHashCode, msg.Variable, out res);
                }
                catch (Exception ex)
                {
                    info = VariableInfo.GetException(ex);
                }
                SendSCResolveVariableResult(info);
            }
            break;

            case DebugMessageType.CSResolveIndexAccess:
            {
                CSResolveIndexer msg = new CSResolveIndexer();
                msg.ThreadHashCode = br.ReadInt32();
                msg.Body           = ReadVariableReference(br);
                msg.Index          = ReadVariableReference(br);

                VariableInfo info;
                try
                {
                    object res;
                    info = ds.ResolveIndexAccess(msg.ThreadHashCode, msg.Body, msg.Index, out res);
                }
                catch (Exception ex)
                {
                    info = VariableInfo.GetException(ex);
                }
                SendSCResolveVariableResult(info);
            }
            break;

            case DebugMessageType.CSEnumChildren:
            {
                int thId   = br.ReadInt32();
                var parent = ReadVariableReference(br);

                VariableInfo[] info = null;
                try
                {
                    info = ds.EnumChildren(thId, parent);
                }
                catch (Exception ex)
                {
                    info = new VariableInfo[] { VariableInfo.GetException(ex) };
                }
                SendSCEnumChildrenResult(info);
            }
            break;
            }
        }
Ejemplo n.º 38
0
            /// <summary>
            /// reads a file and populates the map receiver instance.
            /// </summary>
            /// <returns></returns>
            public static bool Read_pachm(string path, ref Mapping.PachMapReceiver[] Map)
            {
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(path, System.IO.FileMode.Open));
                //1. Write calculation type. (string)
                string CalcType = sr.ReadString();

                if (CalcType != "Type;Map_Data" && CalcType != "Type;Map_Data_NoDir")
                {
                    throw new Exception("Map Data File Expected");
                }
                bool Directional = (CalcType == "Type;Map_Data");

                //2. Write the number of samples in each histogram. (int)
                int SampleCT = (int)sr.ReadUInt32();
                //3. Write the sample rate. (int)
                int SampleRate = (int)sr.ReadUInt32();
                //4. Write the number of Receivers (int)
                int Rec_CT = (int)sr.ReadUInt32();
                //4.5 Write the version number
                double version = 1.1;
                double rev     = 0;
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                int s_ct = 1;

                Rhino.Geometry.Mesh Map_Mesh = new Rhino.Geometry.Mesh();
                Map = new Mapping.PachMapReceiver[1];
                //Map[0] = new Pach_Map_Receiver();
                //double[] Rho_C = null;
                double[] delay;

                do
                {
                    switch (sr.ReadString())
                    {
                    case "Version":
                        //Pach1.7 = Versioning functionality added.
                        string v = sr.ReadString();
                        version = double.Parse(v.Substring(0, 3));
                        rev     = int.Parse(v.Split(new char[1] {
                            '.'
                        })[3]);
                        break;

                    case "Mesh Information":
                        //6. Announce Mesh Vertices (string)
                        //Write the number of vertices & faces (int) (int)
                        if (sr.ReadString() != "Mesh Vertices")
                        {
                            throw new Exception("Mesh Vertices Expected");
                        }

                        int VC = (int)sr.ReadUInt32();
                        int FC = (int)sr.ReadUInt32();
                        for (int i = 0; i < VC; i++)
                        {
                            //Write Vertex: (double) (double) (double)
                            Map_Mesh.Vertices.Add(new Rhino.Geometry.Point3d(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()));
                        }

                        //7. Announce Mesh Faces (string)
                        if (sr.ReadString() != "Mesh Faces")
                        {
                            throw new Exception("Mesh Faces Expected");
                        }

                        for (int i = 0; i < FC; i++)
                        {
                            // Write mesh vertex indices: (int) (int) (int) (int)
                            Map_Mesh.Faces.AddFace((int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32());
                        }
                        break;

                    case "Sources":
                        //7.5: Announce the number of sources.
                        s_ct  = sr.ReadInt32();
                        delay = new double[s_ct];
                        Map   = new Mapping.PachMapReceiver[s_ct];
                        //7.5a Announce the type of source.

                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s]            = new Mapping.PachMapReceiver();
                            Map[s].CutOffTime = (double)SampleCT / (double)SampleRate;
                            Map[s].SampleCT   = SampleCT;
                            Map[s].SampleRate = SampleRate;
                            Map[s].Map_Mesh   = Map_Mesh;
                            Map[s].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[s].SrcType    = sr.ReadString();
                            //4.4 Source delay (ms)
                            if (version > 2.0 || (version == 2.0 && rev >= 1))
                            {
                                delay[s] = sr.ReadDouble();
                            }
                            Map[s].SWL = new double[8];
                            if (version > 2.0 || (version == 2.0 && rev >= 2))
                            {
                                for (int j = 0; j < 8; j++)
                                {
                                    Map[s].SWL[j] = sr.ReadDouble();                            //v.2.0.0.2
                                }
                            }
                            else
                            {
                                Map[s].SWL = new double[8] {
                                    120, 120, 120, 120, 120, 120, 120, 120
                                }
                            };
                        }
                        break;

                    case "SourceswLoc":
                        //7.5: Announce the number of sources.
                        s_ct  = sr.ReadInt32();
                        delay = new double[s_ct];
                        Map   = new Mapping.PachMapReceiver[s_ct];
                        //7.5a Announce the type of source.

                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s]            = new Mapping.PachMapReceiver();
                            Map[s].CutOffTime = (double)SampleCT / (double)SampleRate * 1000;
                            Map[s].SampleCT   = SampleCT;
                            Map[s].SampleRate = SampleRate;
                            Map[s].Map_Mesh   = Map_Mesh;
                            Map[s].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[s].Src        = new Rhino.Geometry.Point3d(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                            Map[s].SrcType    = sr.ReadString();
                            //4.4 Source delay (ms)
                            if (version > 2.0 || (version == 2.0 && rev >= 1))
                            {
                                delay[s] = sr.ReadDouble();
                            }
                            Map[s].SWL = new double[8];
                            if (version > 2.0 || (version == 2.0 && rev >= 2))
                            {
                                for (int j = 0; j < 8; j++)
                                {
                                    Map[s].SWL[j] = sr.ReadDouble();                            //v.2.0.0.2
                                }
                            }
                            else
                            {
                                Map[s].SWL = new double[8] {
                                    120, 120, 120, 120, 120, 120, 120, 120
                                }
                            };
                        }
                        break;

                    case "Receiver Hit Data":
                        if (Map[0] == null)
                        {
                            Map               = new Mapping.PachMapReceiver[1];
                            Map[0]            = new Mapping.PachMapReceiver();
                            Map[0].CutOffTime = (double)SampleCT / (double)SampleRate;
                            Map[0].SampleRate = SampleRate;
                            Map[0].SampleCT   = SampleCT;
                            Map[0].Map_Mesh   = Map_Mesh;
                            Map[0].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[0].SrcType    = "Geodesic";
                        }

                        //8. Announce that the following data pertains to the receiver histograms (string)
                        //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                        bool vert_Receiver = sr.ReadBoolean();
                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s].Rec_Vertex = vert_Receiver;
                            for (int i = 0; i < Map[s].Rec_List.Length; i++)
                            {
                                //for version 1.7 and up, write direct sound arrival time.
                                //Write Receiver Index (int)
                                int j = (int)sr.ReadUInt32();
                                //Write Direct Sound Arrival Time.
                                double Direct_Time;
                                if (version >= 1.7)
                                {
                                    Direct_Time = sr.ReadDouble();
                                }
                                else
                                {
                                    Direct_Time = (Utilities.PachTools.RPttoHPt(Map[s].Src) - Map[s].Rec_List[i].H_Origin).Length() / 343f;
                                }
                                //Write Impedance of Air
                                double Rho_C = version >= 2.0 ? sr.ReadDouble() : 400;

                                if (vert_Receiver)
                                {
                                    Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(Map_Mesh.Vertices[i], new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                }
                                else
                                {
                                    Rhino.Geometry.Point3d RecLoc = Map_Mesh.Faces.GetFaceCenter(i);
                                    Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(new Rhino.Geometry.Point3f((float)RecLoc.X, (float)RecLoc.Y, (float)RecLoc.Z), new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                }

                                for (int Octave = 0; Octave < 8; Octave++)
                                {
                                    //Write Octave (int)
                                    int Oct_out = (int)sr.ReadUInt32();
                                    if (Oct_out != Octave)
                                    {
                                        throw new Exception(string.Format("Octave {0} Expected", Octave));
                                    }
                                    double[] Hist = Map[s].Rec_List[i].GetEnergyHistogram(Octave);
                                    if (Directional)
                                    {
                                        if (version < 1.7)
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                        else
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (version < 1.7)
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                        }
                                        else
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                        }
                                    }
                                }
                                if (sr.ReadString() != "End_Receiver_Hits")
                                {
                                    throw new Exception("End of Receiver Hits Expected");
                                }
                            }
                        }
                        break;

                    case "End_of_File":
                        sr.Close();
                        return(true);
                    }
                } while (true);
                throw new Exception("Unsuccessful Read");
            }
 public static TransparentStreamCanReadResponseMessage Deserialize(byte[] buffer)
 {
     if (buffer == null)
         throw new ArgumentNullException ("buffer");
     Guid streamID;
     Guid requestID;
     bool canRead;
     Exception exception;
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream (buffer)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
             streamID = new Guid (BR.ReadBytes (16));
             requestID = new Guid (BR.ReadBytes (16));
             canRead = BR.ReadBoolean ();
             if (MS.ReadByte () == 1) {
                 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ();
                 object deserializedObject = BF.Deserialize (MS);
                 if (deserializedObject is Exception) {
                     exception = (Exception)deserializedObject;
                 } else {
                     throw new Exception ("buffer contains an object of invalid type, expected System.Exception.");
                 }
             } else
                 exception = null;
         }
     }
     return new TransparentStreamCanReadResponseMessage (streamID, requestID, canRead, exception);
 }
Ejemplo n.º 40
0
Archivo: Row.cs Proyecto: vebin/BD2
 public static Row Deserialize(byte[] bytes)
 {
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
             byte[] columnSet = BR.ReadBytes (32);
             int FieldCount = BR.ReadInt32 ();
             object[] fields = new object[FieldCount];
             ColumnSet cs = css [columnSet];
             if (cs.Columns.Length != fields.Length)
                 throw new Exception ();
             for (int n = 0; n != fields.Length; n++) {
                 bool Null = BR.ReadBoolean ();
                 if (Null) {
                     fields [n] = null;
                     continue;
                 }
                 switch (cs.Columns [n].TFQN) {
                 case "System.Byte[]":
                     fields [n] = BR.ReadBytes (BR.ReadInt32 ());
                     break;
                 case "System.Byte":
                     fields [n] = BR.ReadByte ();
                     break;
                 case "System.SByte":
                     fields [n] = BR.ReadSByte ();
                     break;
                 case "System.Int16":
                     fields [n] = BR.ReadInt16 ();
                     break;
                 case "System.UInt16":
                     fields [n] = BR.ReadUInt16 ();
                     break;
                 case "System.Int32":
                     fields [n] = BR.ReadInt32 ();
                     break;
                 case "System.UInt32":
                     fields [n] = BR.ReadUInt32 ();
                     break;
                 case "System.Int64":
                     fields [n] = BR.ReadInt64 ();
                     break;
                 case "System.UInt64":
                     fields [n] = BR.ReadUInt64 ();
                     break;
                 case "System.Single":
                     fields [n] = BR.ReadSingle ();
                     break;
                 case "System.Double":
                     fields [n] = BR.ReadDouble ();
                     break;
                 case "System.String":
                     fields [n] = BR.ReadString ();
                     break;
                 case "System.Char":
                     fields [n] = BR.ReadChar ();
                     break;
                 case "System.Boolean":
                     fields [n] = BR.ReadBoolean ();
                     break;
                 case "System.DateTime":
                     fields [n] = new DateTime (BR.ReadInt64 ());
                     break;
                 case "System.Guid":
                     fields [n] = new Guid (BR.ReadBytes (16));
                     break;
                 }
             }
             return new Row (cs, fields);
         }
     }
 }