System.IO.BinaryReader.ReadString()

Here are the examples of the csharp api System.IO.BinaryReader.ReadString() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

827 Examples 7

19 Source : SimpleJSON.cs
with MIT License
from 734843327

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.Clreplaced:
			{
				int count = aReader.ReadInt32();				
				JSONClreplaced tmp = new JSONClreplaced();
				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);
			}
			}
		}

19 Source : IPCSupport.cs
with GNU General Public License v3.0
from 9E4ECDDE

public static SerializedBoneData FromByteArray(byte[] array)
            {
                using (MemoryStream memoryStream = new MemoryStream(array))
                {
                    using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))
                    {
                        SerializedBoneData boneData = new SerializedBoneData();
                        boneData.name = binaryReader.ReadString();
                        boneData.damping = binaryReader.ReadSingle();
                        boneData.elasticity = binaryReader.ReadSingle();
                        boneData.stiffness = binaryReader.ReadSingle();
                        boneData.inert = binaryReader.ReadSingle();
                        boneData.radius = binaryReader.ReadSingle();
                        boneData.endLength = binaryReader.ReadSingle();
                        boneData.endOffset = new float3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        boneData.gravity = new float3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        boneData.force = new float3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        return boneData;

                    }
                }
            }

19 Source : IPCSupport.cs
with GNU General Public License v3.0
from 9E4ECDDE

public static AvatarBones FromByteArray(byte[] array)
            {
                using (MemoryStream memoryStream = new MemoryStream(array))
                {
                    using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))
                    {
                        AvatarBones boneList = new AvatarBones();
                        boneList.name = binaryReader.ReadString();
                        boneList.boneCount = binaryReader.ReadInt32();
                        boneList.bones = new SerializedBoneData[boneList.boneCount];
                        for (int i = 0; i < boneList.boneCount; i++)
                        {
                            boneList.bones[i] = SerializedBoneData.FromByteArray(binaryReader.ReadBytes(binaryReader.ReadInt32()));
                        }
                        return boneList;
                    }
                }
            }

19 Source : UmaTPose.cs
with Apache License 2.0
from A7ocin

private SkeletonBone DeSerializeSkeletonBone(BinaryReader br)
	    {
	        var res = new SkeletonBone();
	        res.name = br.ReadString();
	        res.position = DeserializeVector3(br);
	        res.rotation = DeSerializeQuaternion(br);
	        res.scale = DeserializeVector3(br);
	        br.ReadInt32();
	        return res;
	    }

19 Source : UmaTPose.cs
with Apache License 2.0
from A7ocin

private HumanBone DeSerializeHumanBone(BinaryReader br)
	    {
	        var res = new HumanBone();
	        res.boneName = br.ReadString();
	        res.humanName = br.ReadString();
	        res.limit = DeSerializeHumanLimit(br);
	        return res;
	    }

19 Source : InputAnimationSerializationUtils.cs
with Apache License 2.0
from abist-co-ltd

public static void ReadMarkerList(BinaryReader reader, List<InputAnimationMarker> markers)
        {
            markers.Clear();
            int count = reader.ReadInt32();
            markers.Capacity = count;
            for (int i = 0; i < count; ++i)
            {
                var marker = new InputAnimationMarker();
                marker.time = reader.ReadSingle();
                marker.name = reader.ReadString();
                markers.Add(marker);
            }
        }

19 Source : SerializableCacheItemPolicy.cs
with Apache License 2.0
from acarteas

public static SerializableCacheItemPolicy Deserialize(BinaryReader reader, long streamLength)
        {
            // Can't even check for the magic version number; return empty policy.
            if (streamLength < sizeof(ulong))
                return new SerializableCacheItemPolicy();

            try
            {
                var version = reader.ReadUInt64();
                if (version != CACHE_VERSION)
                    // Just return an empty policy if we read an invalid one.
                    // This is likely the older "BinaryFormatter"-serialized policy.
                    return new SerializableCacheItemPolicy();

                return new SerializableCacheItemPolicy {
                    AbsoluteExpiration = new DateTimeOffset(DateTime.FromBinary(reader.ReadInt64()),
                                                            TimeSpan.FromMilliseconds(reader.ReadDouble())),
                    // Don't clobber absolute by using sliding's setter; set the private value instead.
                    _slidingExpiration = TimeSpan.FromMilliseconds(reader.ReadDouble()),
                    Key = reader.ReadString(),
                };
            }
            catch (Exception error)
            {
                if (error is EndOfStreamException
                    || error is IOException
                    || error is ObjectDisposedException)
                {
                    // Just return an empty policy if we failed to read.
                    return new SerializableCacheItemPolicy();
                }
                // Didn't expect this error type; rethrow it.
                throw;
            }
        }

19 Source : StarterArea.cs
with GNU Affero General Public License v3.0
from ACEmulator

public void Unpack(BinaryReader reader)
        {
            Name = reader.ReadString();

            Locations.UnpackSmartArray(reader);
        }

19 Source : GearCG.cs
with GNU Affero General Public License v3.0
from ACEmulator

public void Unpack(BinaryReader reader)
        {
            Name            = reader.ReadString();
            ClothingTable   = reader.ReadUInt32();
            WeenieDefault   = reader.ReadUInt32();
        }

19 Source : SexCG.cs
with GNU Affero General Public License v3.0
from ACEmulator

public void Unpack(BinaryReader reader)
        {
            Name            = reader.ReadString();
            Scale           = reader.ReadUInt32();
            SetupID         = reader.ReadUInt32();
            SoundTable      = reader.ReadUInt32();
            IconImage       = reader.ReadUInt32();
            BasePalette     = reader.ReadUInt32();
            SkinPalSet      = reader.ReadUInt32();
            PhysicsTable    = reader.ReadUInt32();
            MotionTable     = reader.ReadUInt32();
            CombatTable     = reader.ReadUInt32();

            BaseObjDesc.Unpack(reader);

            HairColorList.UnpackSmartArray(reader);
            HairStyleList.UnpackSmartArray(reader);
            EyeColorList.UnpackSmartArray(reader);
            EyeStripList.UnpackSmartArray(reader);
            NoseStripList.UnpackSmartArray(reader);
            MouthStripList.UnpackSmartArray(reader);

            HeadgearList.UnpackSmartArray(reader);
            ShirtList.UnpackSmartArray(reader);
            PantsList.UnpackSmartArray(reader);
            FootwearList.UnpackSmartArray(reader);
            ClothingColorsList.UnpackSmartArray(reader);
        }

19 Source : TabooTableEntry.cs
with GNU Affero General Public License v3.0
from ACEmulator

public void Unpack(BinaryReader reader)
        {
            Unknown1 = reader.ReadUInt32();
            Unknown2 = reader.ReadUInt16();

            uint count = reader.ReadUInt32();

            for (int i = 0; i < count; i++)
                BannedPatterns.Add(reader.ReadString());
        }

19 Source : TemplateCG.cs
with GNU Affero General Public License v3.0
from ACEmulator

public void Unpack(BinaryReader reader)
        {
            Name            = reader.ReadString();
            IconImage       = reader.ReadUInt32();
            replacedle           = reader.ReadUInt32();
            // Attributes
            Strength        = reader.ReadUInt32();
            Endurance       = reader.ReadUInt32();
            Coordination    = reader.ReadUInt32();
            Quickness       = reader.ReadUInt32();
            Focus           = reader.ReadUInt32();
            Self            = reader.ReadUInt32();

            NormalSkillsList.UnpackSmartArray(reader);
            PrimarySkillsList.UnpackSmartArray(reader);
        }

19 Source : HeritageGroupCG.cs
with GNU Affero General Public License v3.0
from ACEmulator

public void Unpack(BinaryReader reader)
        {
            Name                = reader.ReadString();
            IconImage           = reader.ReadUInt32();
            SetupID             = reader.ReadUInt32();
            EnvironmentSetupID  = reader.ReadUInt32();
            AttributeCredits    = reader.ReadUInt32();
            SkillCredits        = reader.ReadUInt32();

            PrimaryStartAreas.UnpackSmartArray(reader);
            SecondaryStartAreas.UnpackSmartArray(reader);
            Skills.UnpackSmartArray(reader);
            Templates.UnpackSmartArray(reader);
            reader.BaseStream.Position++; // 0x01 byte here. Not sure what/why, so skip it!
            Genders.UnpackSmartArray(reader);
        }

19 Source : DbgDecoder.cs
with GNU General Public License v3.0
from Aekras1a

private void btnDecode_Click(object sender, EventArgs e)
        {
            var mapFile = txtMap.Text;
            if(string.IsNullOrEmpty(txtMap.Text))
            {
                MessageBox.Show("Select a Debug Map file.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var mapData = File.ReadAllBytes(mapFile);

            ulong token;
            if(!ulong.TryParse(txtToken.Text, NumberStyles.HexNumber, null, out token))
            {
                MessageBox.Show("Enter a valid Debug Token.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var stream = new MemoryStream(mapData);
            var aes = new AesManaged();
            aes.IV = aes.Key = Convert.FromBase64String("UkVwAyrARLAy4GmQLL860w==");
            var reader = new BinaryReader(
                new DeflateStream(
                    new CryptoStream(stream, aes.CreateDecryptor(), CryptoStreamMode.Read),
                    CompressionMode.Decompress
                )
            );

            var key = modInv((uint) token | 1);

            var doreplacedents = new List<string>();
            var count = reader.ReadUInt32();
            for(uint i = 0; i < count; i++)
                doreplacedents.Add(reader.ReadString());

            string dbg;
            try
            {
                var ip = (uint) ((token >> 32) * key);
                while(true)
                {
                    var offset = reader.ReadUInt32();
                    var len = reader.ReadUInt32();
                    var docId = reader.ReadUInt32();
                    var lineNo = reader.ReadUInt32();

                    if(ip >= offset && ip <= offset + len)
                    {
                        dbg = string.Format("Line {0} at {1}", lineNo, doreplacedents[(int) docId]);
                        break;
                    }
                }
            }
            catch
            {
                dbg = "Debug info not found.";
            }
            txtInfo.Text = dbg;
        }

19 Source : Pack.cs
with Apache License 2.0
from aequabit

public object[] Deserialize(byte[] data)
    {
        MemoryStream Stream = new MemoryStream(data);
        BinaryReader Reader = new BinaryReader(Stream, Encoding.UTF8);
        List<object> Items = new List<object>();
        byte Current = 0;
        byte Count = Reader.ReadByte();

        for (int I = 0; I <= Count - 1; I++)
        {
            Current = Reader.ReadByte();

            switch (Current)
            {
                case 0:
                    Items.Add(Reader.ReadBoolean());
                    break;
                case 1:
                    Items.Add(Reader.ReadByte());
                    break;
                case 2:
                    Items.Add(Reader.ReadBytes(Reader.ReadInt32()));
                    break;
                case 3:
                    Items.Add(Reader.ReadChar());
                    break;
                case 4:
                    Items.Add(Reader.ReadString().ToCharArray());
                    break;
                case 5:
                    Items.Add(Reader.ReadDecimal());
                    break;
                case 6:
                    Items.Add(Reader.ReadDouble());
                    break;
                case 7:
                    Items.Add(Reader.ReadInt32());
                    break;
                case 8:
                    Items.Add(Reader.ReadInt64());
                    break;
                case 9:
                    Items.Add(Reader.ReadSByte());
                    break;
                case 10:
                    Items.Add(Reader.ReadInt16());
                    break;
                case 11:
                    Items.Add(Reader.ReadSingle());
                    break;
                case 12:
                    Items.Add(Reader.ReadString());
                    break;
                case 13:
                    Items.Add(Reader.ReadUInt32());
                    break;
                case 14:
                    Items.Add(Reader.ReadUInt64());
                    break;
                case 15:
                    Items.Add(Reader.ReadUInt16());
                    break;
                case 16:
                    Items.Add(DateTime.FromBinary(Reader.ReadInt64()));
                    break;
            }
        }

        Reader.Close();
        return Items.ToArray();
    }

19 Source : ByteCommond.cs
with Mozilla Public License 2.0
from agebullhu

public static bool SkipEmpty(BinaryReader reader, byte type)
        {
            switch ((int)type)
            {
                case 0:
                    return false;
                case 255:
                    reader.ReadChar();
                    break;
                case 254:
                    reader.ReadString();
                    break;
                default:
                    reader.BaseStream.Position += type;
                    break;
            }
            return true;
        }

19 Source : Snapshot.cs
with GNU General Public License v3.0
from aiportal

[Obsolete]
		public Snapshot FromBinary(byte[] bs)
		{		
			using (MemoryStream ms = new MemoryStream(bs))
			using (BinaryReader br = new BinaryReader(ms))
			{
				byte[] version = br.ReadBytes(4);

				Snapshot ss = new Snapshot();
				ss.SessionId = new Guid(br.ReadBytes(16)).ToString("n");
				ss.SnapshotId = new Guid(br.ReadBytes(16)).ToString("n");
				ss.SnapTime = DateTime.FromBinary(br.ReadInt64());

				ss.ProcessId = br.ReadInt32();
				ss.ProcessName = br.ReadString();
				ss.FileName = br.ReadString();

				ss.WindowHandle = br.ReadInt32();
				ss.WindowRect = new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
				ss.Windowreplacedle = br.ReadString();
				ss.WindowUrl = br.ReadString();

				ss.ControlText = br.ReadString();
				ss.InputText = br.ReadString();

				//ss.Mouse = new MouseState()
				//{
				//    ClickOption = (MouseClickOption)br.ReadInt32(),
				//    X = br.ReadInt32(),
				//    Y = br.ReadInt32(),
				//};

				ss.IsGrayScale = br.ReadBoolean();
				int imageLen = br.ReadInt32();
				ss.ImageData = br.ReadBytes(imageLen);
				int eventsLen = br.ReadInt32();
				ss.EventsData = br.ReadBytes(eventsLen);

				return ss;
			}
		}

19 Source : SessionInfo.cs
with GNU General Public License v3.0
from aiportal

public static SessionInfo FromBinary(byte[] bs)
		{
			using (MemoryStream ms = new MemoryStream(bs))
			using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8))
			{
				byte[] version = br.ReadBytes(4);

				SessionInfo si = new SessionInfo();
				si.SessionId = new Guid(br.ReadBytes(16)).ToString("n");
				si.CreateTime = DateTime.FromBinary(br.ReadInt64());	// 8 bytes.
				si.Domain = br.ReadString();
				si.UserName = br.ReadString();
				si.ClientName = br.ReadString();
				si.ClientAddress = br.ReadString();
				return si;
			}
		}

19 Source : IOEntry.cs
with Apache License 2.0
from aloneguid

public void AppendAttributesFromByteArray(byte[] data)
      {
         if(data == null)
            return;

         using(var ms = new MemoryStream(data))
         {
            using(var b = new BinaryReader(ms, Encoding.UTF8, true))
            {
               byte version = b.ReadByte();  //to be used with versioning
               if(version != 1)
               {
                  throw new ArgumentException($"version {version} is not supported", nameof(data));
               }

               int count = b.ReadInt32();
               if(count > 0)
               {
                  for(int i = 0; i < count; i++)
                  {
                     string key = b.ReadString();
                     string value = b.ReadString();

                     Metadata[key] = value;
                  }
               }
            }
         }
      }

19 Source : SccProjectMap.SccExcluded.cs
with Apache License 2.0
from AmpScm

public void SerializeSccExcludeData(System.IO.Stream store, bool writeData)
        {
            ClearSolutionInfo(); // Force the right data
            string baseDir = SolutionDirectory;

            if (writeData)
            {
                if (_sccExcluded.Count == 0)
                    return;

                using (BinaryWriter bw = new BinaryWriter(store))
                {
                    bw.Write(_sccExcluded.Count);

                    foreach (string path in _sccExcluded)
                    {
                        if (baseDir != null)
                            bw.Write(SvnItem.MakeRelative(baseDir, path));
                        else
                            bw.Write(path);
                    }
                }
            }
            else
            {
                if (store.Length == 0)
                    return;

                using (BinaryReader br = new BinaryReader(store))
                {
                    int count = br.ReadInt32();

                    while (count-- > 0)
                    {
                        string path = br.ReadString();

                        try
                        {
                            if (baseDir != null)
                                path = SvnTools.GetNormalizedFullPath(Path.Combine(baseDir, path));
                            else
                                path = SvnTools.GetNormalizedFullPath(path);

                            if (!_sccExcluded.Contains(path))
                                _sccExcluded.Add(path);
                        }
                        catch { }
                    }
                }
            }
        }

19 Source : AnkhSvnPackage.SolutionProperties.cs
with Apache License 2.0
from AmpScm

private void LoadPendingChanges(Stream storageStream)
        {
            IFileStatusMonitor monitor = GetService<IFileStatusMonitor>();

            if (monitor == null)
                return;

            using (BinaryReader br = new BinaryReader(storageStream))
            {
                int n = br.ReadInt32();
                List<string> files = new List<string>();

                for (int i = 0; i < n; i++)
                {
                    files.Add(br.ReadString());
                }

                monitor.ScheduleMonitor(files);
            }
        }

19 Source : SvnSccProvider.Enlistment.cs
with Apache License 2.0
from AmpScm

private void ReadTranslateUserData(Stream store)
        {
            _translateDataLoaded = true;
            if (store.Length < 2 * sizeof(int))
                return;

            using (BinaryReader br = new BinaryReader(store))
            {
                int version = br.ReadInt32(); // The enlist version used to write the data
                int requiredVersion = br.ReadInt32(); // All enlist versions older then this should ignore all data

                if ((requiredVersion > TranslateSerializerVersion) || version < MinSupportedTranslateSerializerVersion)
                    return; // Older versions (we) should ignore this data

                string oldSolutionDir = br.ReadString();
                string slnDir = RawSolutionDirectory ?? oldSolutionDir;
                int nItems = br.ReadInt32();

                for (int iItem = 0; iItem < nItems; iItem++)
                {
                    int nStrings = br.ReadInt32();
                    string[] strings = new string[nStrings];

                    for (int iString = 0; iString < nStrings; iString++)
                    {
                        bool relative = br.ReadBoolean();

                        string path = br.ReadString();

                        if (relative)
                            path = Path.Combine(slnDir, path);

                        strings[iString] = path;
                    }

                    if (strings.Length >= 3)
                    {
                        SccTranslatePathInfo tpi = new SccTranslatePathInfo(strings[0], strings[1], strings[2]);

                        if (!_translationMap.ContainsKey(tpi.SolutionPath))
                        {
                            _translationMap[tpi.SolutionPath] = tpi;

                            if (tpi.SolutionPath != tpi.EnlistmentUNCPath)
                                _trueNameMap[tpi.EnlistmentUNCPath] = tpi.SolutionPath;
                        }
                    }
                }
            }
        }

19 Source : StringArrayIO.cs
with Apache License 2.0
from AnkiUniversal

public static string[] ReadArray(BinaryReader dataInput)
        {
            try
            {
                int length = dataInput.ReadRawInt32();

                string[] array = new string[length];

                for (int i = 0; i < length; i++)
                {
                    array[i] = dataInput.ReadString();
                }

                return array;
            }
            catch (Exception ex)
            {
                throw new IOException("StringArrayIO.ReadArray: " + ex.Message);
            }
        }

19 Source : DeserializerStream.cs
with GNU General Public License v3.0
from anotak

public void Begin()
		{
			// First 4 bytes are reserved for the offset of the strings table
			stringtablepos = reader.ReadInt32();
			stream.Seek(stringtablepos, SeekOrigin.Begin);
			
			// Read the strings
			List<string> strings = new List<string>();
			while(stream.Position < (int)stream.Length)
				strings.Add(reader.ReadString());
			stringstable = strings.ToArray();

			// Back to start
			stream.Seek(4, SeekOrigin.Begin);
		}

19 Source : NmsBytesMessage.cs
with Apache License 2.0
from apache

public string ReadString()
        {
            InitializeReading();
            try
            {
                return dataIn.ReadString();
            }
            catch (EndOfStreamException e)
            {
                throw NMSExceptionSupport.CreateMessageEOFException(e);
            }
            catch (IOException e)
            {
                throw NMSExceptionSupport.CreateMessageFormatException(e);
            }
        }

19 Source : PrimitiveMap.cs
with Apache License 2.0
from apache

public static IDictionary UnmarshalPrimitiveMap(BinaryReader dataIn)
        {
            int size = dataIn.ReadInt32();
            if (size < 0)
            {
                return null;
            }

            IDictionary answer = new Hashtable(size);
            for (int i = 0; i < size; i++)
            {
                String name = dataIn.ReadString();
                answer[name] = UnmarshalPrimitive(dataIn);
            }

            return answer;
        }

19 Source : StringReader.cs
with MIT License
from Apostolique

public override string Read(Stream input, Context context) {
            using (System.IO.BinaryReader br = new System.IO.BinaryReader(input)) {
                return br.ReadString();
            }
        }

19 Source : Binary_filetype.cs
with GNU Affero General Public License v3.0
from arklumpus

public static IEnumerable<TreeNode> OpenFile(string fileName, List<(string, Dictionary<string, object>)> moduleSuggestions, Action<double> progressAction, Func<RSAParameters?, bool> askForCodePermission)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
			
			List<Attachment> attachments = new List<Attachment>();

            if (BinaryTree.HasValidTrailer(fs, true))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(fs, System.Text.Encoding.UTF8, true))
                    {
                        fs.Seek(-12, SeekOrigin.End);
                        long labelAddress = reader.ReadInt64();
                        fs.Seek(labelAddress - 8, SeekOrigin.Begin);
                        long dataLength = reader.ReadInt64();
                        if (dataLength > 11)
                        {
                            fs.Seek(labelAddress - 8 - dataLength, SeekOrigin.Begin);
                            string header = reader.ReadString();
							string serializedModules = null; 
							
                            if (header == "#TreeViewer")
                            {
                                serializedModules = reader.ReadString();

                                if (reader.BaseStream.Position - (labelAddress - 8 - dataLength) < dataLength)
                                {
                                    try
                                    {
                                        header = reader.ReadString();
                                    }
                                    catch { }
                                }
                            }


                            if (header == "#Attachments")
                            {
                                int attachmentCount = reader.ReadInt32();

                                for (int i = 0; i < attachmentCount; i++)
                                {
                                    Attachment att = ReadAttachment(reader, fileName);
									attachments.Add(att);
                                    moduleSuggestions.Add(("@Attachment", new Dictionary<string, object>() { { "Attachment", att } }));
                                }
                            }
							
							if (serializedModules != null)
							{
								List<List<(string, Dictionary<string, object>)>> modules = ModuleUtils.DeserializeModules(serializedModules, attachments, askForCodePermission);

                                if (modules[0].Count > 0)
                                {
                                    moduleSuggestions[0] = modules[0][0];
                                }

                                if (modules[2].Count > 0)
                                {
                                    moduleSuggestions[1] = modules[2][0];
                                }

                                for (int i = 0; i < modules[1].Count; i++)
                                {
                                    moduleSuggestions.Add(modules[1][i]);
                                }

                                for (int i = 0; i < modules[3].Count; i++)
                                {
                                    moduleSuggestions.Add(modules[3][i]);
                                }
							}
                        }
                    }
                }
                catch { }

                fs.Seek(0, SeekOrigin.Begin);

                return new TreeCollection(fs);
            }
            else
            {
                return BinaryTree.ParseTrees(fs, progressAction: progressAction);
            }
        }

19 Source : Binary_filetype.cs
with GNU Affero General Public License v3.0
from arklumpus

private static Attachment ReadAttachment(BinaryReader reader, string fileName)
        {
            string name = reader.ReadString();

            int flagCount = reader.ReadInt32();

            bool storeInMemory = false;
            bool cacheResults = false;

            for (int i = 0; i < flagCount; i++)
            {
                bool flag = reader.ReadBoolean();

                if (i == 0)
                {
                    storeInMemory = flag;
                }
                else if (i == 1)
                {
                    cacheResults = flag;
                }
            }

            int length = reader.ReadInt32();

            if (storeInMemory)
            {
                byte[] data = reader.ReadBytes(length);

                Stream ms = new MemoryStream(data);

                return new Attachment(name, cacheResults, storeInMemory, ref ms);
            }
            else
            {
                long streamStart = reader.BaseStream.Position;

                return new Attachment(name, cacheResults, fileName, streamStart, length);
            }
        }

19 Source : Serializer.cs
with GNU General Public License v3.0
from Artentus

private static void ReadList(BinaryReader reader, JsonWriter writer)
        {
            writer.WriteStartObject();

            uint count = reader.ReadUInt32();
            for (int i = 0; i < count; i++)
            {
                reader.ReadString(); // List is dictionary with empty keys
                ReadPropertyTree(reader, writer);
            }

            writer.WriteEndObject();
        }

19 Source : Serializer.cs
with GNU General Public License v3.0
from Artentus

private static void ReadDictionary(BinaryReader reader, JsonWriter writer)
        {
            writer.WriteStartObject();

            uint count = reader.ReadUInt32();
            for (int i = 0; i < count; i++)
            {
                writer.WritePropertyName(reader.ReadString());
                ReadPropertyTree(reader, writer);
            }

            writer.WriteEndObject();
        }

19 Source : Serializer.cs
with GNU General Public License v3.0
from Artentus

private static void ReadPropertyTree(BinaryReader reader, JsonWriter writer)
        {
            var type = (PropertyTreeType)reader.ReadByte();
            reader.ReadByte(); // Reserved

            switch (type)
            {
                case PropertyTreeType.None:
                    break;

                case PropertyTreeType.Bool:
                    writer.WriteValue(reader.ReadBoolean());
                    break;

                case PropertyTreeType.Number:
                    writer.WriteValue(reader.ReadDouble());
                    break;

                case PropertyTreeType.String:
                    writer.WriteValue(reader.ReadString());
                    break;

                case PropertyTreeType.List:
                    ReadList(reader, writer);
                    break;

                case PropertyTreeType.Dictionary:
                    ReadDictionary(reader, writer);
                    break;

                default:
                    throw new SerializerException($"Found unknown type {type} in property tree.");
            }
        }

19 Source : NpcRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
	{
		while (reader.BaseStream.Position < header.DataEndPos)
		{
			var type = (SubRecordType)reader.ReadInt32();
			var size = reader.ReadInt32();

			switch (type)
			{
				case SubRecordType.Id:
					name = reader.ReadString(size);
					break;
				case SubRecordType.Model:
					model = reader.ReadString(size);
					break;
				case SubRecordType.Name:
					fullName = reader.ReadString(size);
					break;
				case SubRecordType.RaceName:
					race = Record.GetRecord<Race>(reader.ReadString(size));
					break;

				// Npc's have this even if they are part of no faction, so it needs to be checked if empty first
				case SubRecordType.Anam:
					string fac = reader.ReadString(size);
					faction = string.IsNullOrEmpty(fac) ? null : faction = Record.GetRecord<Faction>(fac);
					break;
				case SubRecordType.BodyName:
					head = BodyPartRecord.Get(reader.ReadString(size));
					break;
				case SubRecordType.CreatureName:
					clreplacedId = Record.GetRecord<ClreplacedRecord>(reader.ReadString(size));
					break;
				case SubRecordType.KeyName:
					hair = BodyPartRecord.Get(reader.ReadString(size));
					break;
				case SubRecordType.NpcData:
					npcData = new NpcRecordData(reader, size);
					break;
				case SubRecordType.Flag:
					npcFlags = (NpcFlags)reader.ReadInt32();
					break;
				case SubRecordType.InventoryItem:
					items.Add(new InventoryItem(reader));
					break;
				case SubRecordType.NpcSpell:
					spells.Add(Record.GetRecord<SpellRecord>(reader.ReadString(size)));
					break;
				case SubRecordType.AiData:
					aiData = new AiData(reader);
					break;
				case SubRecordType.AiWanderData:
					wanderData = new WanderData(reader);
					break;
				case SubRecordType.AiTravelData:
					travelData = new TravelData(reader);
					break;
				case SubRecordType.AiFollowData:
					followData = new FollowData(reader);
					break;
				case SubRecordType.AiEscortData:
					escortData = new EscortData(reader);
					break;
				case SubRecordType.ContainerData:
					cellEscortFollow = reader.ReadString(size);
					break;
				case SubRecordType.AiActivateData:
					activateData = new ActivateData(reader);
					break;
				case SubRecordType.DoorData:
					destinationData.Add(DoorExitData.Create(reader));
					break;
				case SubRecordType.DoorName:
					destinations.Add(reader.ReadString(size));
					break;
				case SubRecordType.Scale:
					scale = reader.ReadSingle();
					break;
				case SubRecordType.Script:
					script = Script.Get(reader.ReadString(size));
					break;
			}
		}
	}

19 Source : CreatureRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
	{
		while (reader.BaseStream.Position < header.DataEndPos)
		{
			var type = (SubRecordType)reader.ReadInt32();
			var size = reader.ReadInt32();

			switch (type)
			{
				case SubRecordType.Id:
					name = reader.ReadString(size);
					break;
				case SubRecordType.Model:
					model = reader.ReadString(size);
					break;
				case SubRecordType.Name:
					fullName = reader.ReadString(size);
					break;
				case SubRecordType.Script:
					script = Script.Get(reader.ReadString(size));
					break;
				case SubRecordType.AiData:
					aiData = new AiData(reader);
					break;
				case SubRecordType.AiActivateData:
					activateData = new ActivateData(reader);
					break;
				case SubRecordType.AiEscortData:
					escortData = new EscortData(reader);
					break;
				case SubRecordType.AiFollowData:
					followData = new FollowData(reader);
					break;
				case SubRecordType.AiTravelData:
					travelData = new TravelData(reader);
					break;
				case SubRecordType.AiWanderData:
					wanderData = new WanderData(reader);
					break;
				case SubRecordType.CreatureName:
					soundGeneratorName = reader.ReadString(size);
					break;
				case SubRecordType.InventoryItem:
					items.Add(new InventoryItem(reader));
					break;
				case SubRecordType.NpcSpell:
					spells.Add(Record.GetRecord<SpellRecord>(reader.ReadString(size)));
					break;
				case SubRecordType.Scale:
					scale = reader.ReadSingle();
					break;
				case SubRecordType.NpcData:
					data = new CreatureData(reader);
					break;
				case SubRecordType.Flag:
					flags = (CreatureFlags)reader.ReadInt32();
					break;
			}
		}

		// Use the record id for sound generation if no SoundGeneratorName is specified
		if (soundGeneratorName == null)
		{
			soundGeneratorName = name;
		}
	}

19 Source : Race.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Id:
						name = reader.ReadString(size);
						break;
					case SubRecordType.Name:
						fullName = reader.ReadString(size);
						break;
					case SubRecordType.RaceData:
						raceData = new RaceData(reader);
						break;
					case SubRecordType.NpcSpell:
						powers.Add(Record.GetRecord<SpellRecord>(reader.ReadString(size)));
						break;
					case SubRecordType.Description:
						description = reader.ReadString(size);
						break;
				}
			}
		}

19 Source : DialogRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Id:
						name = reader.ReadString(size);
						break;
					case SubRecordType.Data:
						dialogueType = (DialogType)reader.ReadByte();
						break;
				}
			}

			// Add the dialog type to a cache so there are less items to iterate over
			switch (dialogueType)
			{
				case DialogType.Topic:
					TopicCache.Add(name, this);
					break;
				case DialogType.Voice:
					VoiceCache.Add(name, this);
					break;
				case DialogType.Greeting:
					GreetingCache.Add(name, this);
					break;
				case DialogType.Persuasion:
					PersuasionCache.Add(name, this);
					break;
				case DialogType.Journal:
					JournalCache.Add(name, this);
					break;
			}

			currentDialogueInfo = infoRecords;
		}

19 Source : InfoRecord.cs
with GNU General Public License v3.0
from arycama

public void Initialize(BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.InfoName:
						infoName = reader.ReadString(size);
						break;
					case SubRecordType.PreviousName:
						previousInfoId = reader.ReadString(size);
						break;
					case SubRecordType.NextName:
						nextInfoId = reader.ReadString(size);
						break;
					case SubRecordType.Data:
						infoData = new InfoRecordData(reader);
						break;
					case SubRecordType.ObjectName:
						character = Record.GetRecord<CreatableRecord>(reader.ReadString(size));
						break;
					case SubRecordType.RaceName:
						race = Record.GetRecord<Race>(reader.ReadString(size));
						break;
					case SubRecordType.CreatureName:
						clreplacedId = Record.GetRecord<ClreplacedRecord>(reader.ReadString(size));
						break;
					case SubRecordType.Name:
						var contents = reader.ReadString(size);
						if (contents != "FFFF")
							faction = Record.GetRecord<Faction>(contents);
						break;
					case SubRecordType.Anam:
						cell = reader.ReadString(size);
						break;
					case SubRecordType.DoorName:
						playerFaction = Record.GetRecord<Faction>(reader.ReadString(size));
						break;
					case SubRecordType.Id:
						response = reader.ReadString(size);
						break;
					case SubRecordType.SoundName:
						soundClip = reader.ReadString(size);
						break;
					case SubRecordType.JournalName:
						journalName = reader.ReadByte();
						break;
					case SubRecordType.JournalFinished:
						journalFinished = reader.ReadByte();
						break;
					case SubRecordType.JournalRestart:
						journalRestart = reader.ReadByte();
						break;
					case SubRecordType.ScriptVariable:
						scriptVariables.Add(new ScriptVariable(reader, size));
						break;
					case SubRecordType.IntValue:
						scriptVariables.Last().IntValue = reader.ReadInt32();
						break;
					case SubRecordType.FloatValue:
						scriptVariables.Last().FloatValue = reader.ReadSingle();
						break;
					case SubRecordType.BodyName:
						result = reader.ReadString(size);
						break;
				}
			}

			DialogRecord.currentDialogueInfo.Add(this);
		}

19 Source : Faction.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
		{
			Faction reactionFaction = null;

			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Id:
						name = reader.ReadString(size);
						factionDictionary[name] = this;
						break;
					case SubRecordType.Name:
						fullName = reader.ReadString(size);
						break;
					case SubRecordType.RankName:
						ranks.Add(reader.ReadString(size));
						break;
					case SubRecordType.FactionData:
						factionData = new FactionData(reader);
						break;
					case SubRecordType.Anam:
						reactionFaction = GetReactionFaction(reader, size);
						break;
					case SubRecordType.IntValue:
						var reactionValue = reader.ReadInt32();
						var factionReaction = new FactionReaction(reactionFaction, reactionValue);
						reactions.Add(factionReaction);
						break;
				}
			}
		}

19 Source : Faction.cs
with GNU General Public License v3.0
from arycama

private Faction GetReactionFaction(System.IO.BinaryReader reader, int size)
		{
			var reactionFactionName = reader.ReadString(size);
			Faction reactionFaction;
			if (factionDictionary.TryGetValue(reactionFactionName, out reactionFaction))
			{
				return reactionFaction;
			}

			return Record.GetRecord<Faction>(reactionFactionName);
		}

19 Source : BirthSignRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(BinaryReader reader, RecordHeader header)
	{
		while (reader.BaseStream.Position < header.DataEndPos)
		{
			var type = (SubRecordType)reader.ReadInt32();
			var size = reader.ReadInt32();

			switch (type)
			{
				case SubRecordType.Description:
					description = reader.ReadString(size);
					break;
				case SubRecordType.Id:
					name = reader.ReadString(size);
					break;
				case SubRecordType.Name:
					fullName = reader.ReadString(size);
					break;
				case SubRecordType.NpcSpell:
					spells.Add(reader.ReadString(size));
					break;
				case SubRecordType.Texture:
					texture = reader.ReadString(size);
					break;
			}
		}
	}

19 Source : MagicEffectRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Index:
						index = (MagicEffectType)reader.ReadInt32();
						name = index.ToString();
						break;
					case SubRecordType.MagicEffectData:
						magicEffectData = new MagicEffectData(reader);
						break;
					case SubRecordType.ItemTexture:
						{
							var texture = BsaFileReader.LoadTexture("icons/" + reader.ReadString(size)) as Texture2D;
							var rect = new Rect(0, 0, texture.width, texture.height);
							var pivot = new Vector2(0.5f, 0.5f);
							itemTexture = Sprite.Create(texture, rect, pivot);
							break;
						}
					case SubRecordType.ParticleTexture:
						{
							var texture = BsaFileReader.LoadTexture("textures/" + reader.ReadString(size)) as Texture2D;
							var rect = new Rect(0, 0, texture.width, texture.height);
							var pivot = new Vector2(0.5f, 0.5f);
							particleTexture = Sprite.Create(texture, rect, pivot);
							break;
						}
					case SubRecordType.MagicCastVisual:
						castVisual = reader.ReadString(size);
						break;
					case SubRecordType.MagicBoltVisual:
						boltVisual = reader.ReadString(size);
						break;
					case SubRecordType.MagicHitVisual:
						hitVisual = reader.ReadString(size);
						break;
					case SubRecordType.MagicAreaVisual:
						areaVisual = reader.ReadString(size);
						break;
					case SubRecordType.Description:
						description = reader.ReadString(size);
						break;
					case SubRecordType.MagicCastSound:
						castSound = reader.ReadString(size);
						break;
					case SubRecordType.MagicBoltsound:
						boltSound = reader.ReadString(size);
						break;
					case SubRecordType.MagicHitSound:
						hitSound = reader.ReadString(size);
						break;
					case SubRecordType.MagicAreaSound:
						areaSound = reader.ReadString(size);
						break;
				}
			}

			records.Add(index, this);
		}

19 Source : Region.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
	{
		while (reader.BaseStream.Position < header.DataEndPos)
		{
			var type = (SubRecordType)reader.ReadInt32();
			var size = reader.ReadInt32();

			switch (type)
			{
				case SubRecordType.Id:
					name = reader.ReadString(size);
					break;
				case SubRecordType.Name:
					fullName = reader.ReadString(size);
					break;
				case SubRecordType.WeatherData:
					weatherData = new WeatherData(reader, size);
					break;
				case SubRecordType.BodyName:
					sleepCreature = Record.GetRecord<LeveledCreatureRecord>(reader.ReadString(size));
					break;
				case SubRecordType.CreatureName:
					mapColor = reader.ReadColor32();
					break;
				case SubRecordType.SoundName:
					sounds.Add(new SoundName(reader, size));
					break;
			}
		}
	}

19 Source : SoundGenerator.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
	{
		while (reader.BaseStream.Position < header.DataEndPos)
		{
			var subRecordType = (SubRecordType)reader.ReadInt32();
			var size = reader.ReadInt32();

			switch (subRecordType)
			{
				case SubRecordType.Id:
					name = reader.ReadString(size);
					break;
				case SubRecordType.Data:
					type = (SoundGeneratorType)reader.ReadInt32();
					break;
				case SubRecordType.SoundName:
					sound = Record.GetRecord<SoundRecord>(reader.ReadString(size));
					break;
				case SubRecordType.CreatureName:
					creature = Record.GetRecord<CreatureRecord>(reader.ReadString(size));
					break;
				default:
					throw new NotImplementedException(subRecordType.ToString());
			}
		}
	}

19 Source : SoundRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(BinaryReader reader, RecordHeader header)
	{
		while (reader.BaseStream.Position < header.DataEndPos)
		{
			var type = (SubRecordType)reader.ReadInt32();
			var size = reader.ReadInt32();

			switch (type)
			{
				case SubRecordType.Id:
					name = reader.ReadString(size);
					break;
				case SubRecordType.Name:
					audioClip = SoundManager.LoadAudio(reader.ReadString(size));
					break;
				case SubRecordType.Data:
					data = new SoundRecordData(reader);
					break;
			}
		}
	}

19 Source : BodyPartRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Id:
						name = reader.ReadString(size);
						break;
					case SubRecordType.Model:
						Model = reader.ReadString(size);
						break;
					case SubRecordType.Name:
						race = Record.GetRecord<Race>(reader.ReadString(size));
						break;
					case SubRecordType.BodyData:
						data = new BodyPartData(reader);
						break;
				}
			}

			data.SetBodyPart(race, this);
		}

19 Source : LeveledCreatureRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Id:
						name = reader.ReadString(size);
						break;
					case SubRecordType.Data:
						calculateFromAllLevelsLessThanPCsLevel = reader.ReadInt32();
						break;
					case SubRecordType.NextName:
						chanceNone = reader.ReadByte();
						break;
					case SubRecordType.Index:
						index = reader.ReadInt32();
						break;
					case SubRecordType.CreatureName:
						creatureNames.Add(reader.ReadString(size));
						break;
					case SubRecordType.IntValue:
						pcLevel.Add(reader.ReadInt16());
						break;
				}
			}
		}

19 Source : ClassRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Id:
						name = reader.ReadString(size);
						break;
					case SubRecordType.Name:
						fullName = reader.ReadString(size);
						break;
					case SubRecordType.ClreplacedData:
						clreplacedData = new ClreplacedData(reader);
						break;
					case SubRecordType.Description:
						description = reader.ReadString(size);
						break;
				}
			}
		}

19 Source : Global.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Id:
						name = reader.ReadString(size);
						break;
					case SubRecordType.Name:
						globalType = (GlobalType)reader.ReadByte();
						break;
					case SubRecordType.FloatValue:
						value = reader.ReadSingle();
						break;
				}
			}
		}

19 Source : SkillRecord.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
		{
			while (reader.BaseStream.Position < header.DataEndPos)
			{
				var type = (SubRecordType)reader.ReadInt32();
				var size = reader.ReadInt32();

				switch (type)
				{
					case SubRecordType.Index:
						index = (CharacterSkill)reader.ReadInt32();
						break;
					case SubRecordType.SkillData:
						skillData = new SkillData(reader);
						break;
					case SubRecordType.Description:
						description = reader.ReadString(size);
						break;
				}
			}
		}

19 Source : Tes3Record.cs
with GNU General Public License v3.0
from arycama

public override void Initialize(BinaryReader reader, RecordHeader header)
	{
		while (reader.BaseStream.Position < header.DataEndPos)
		{
			var type = (SubRecordType)reader.ReadInt32();
			var size = reader.ReadInt32();

			switch (type)
			{
				case SubRecordType.Tes3Header:
					tes3Header = new Tes3Header(reader);
					break;
				case SubRecordType.MasterFile:
					masterFileName = reader.ReadString(size);
					break;
				case SubRecordType.Data:
					previousMasterFileSize = reader.ReadInt64();
					break;
			}
		}
	}

See More Examples