protected override void ReadContent(ByteReader reader) { this.Nodes = new Dictionary<ushort, IndexNode>(this.ItemCount); for (var i = 0; i < this.ItemCount; i++) { var index = reader.ReadUInt16(); var levels = reader.ReadByte(); var node = new IndexNode(levels); node.Page = this; node.Position = new PageAddress(this.PageID, index); node.KeyLength = reader.ReadUInt16(); node.Key = reader.ReadBsonValue(node.KeyLength); node.DataBlock = reader.ReadPageAddress(); for (var j = 0; j < node.Prev.Length; j++) { node.Prev[j] = reader.ReadPageAddress(); node.Next[j] = reader.ReadPageAddress(); } this.Nodes.Add(node.Position.Index, node); } }
public void read(byte[] bytes, ByteReader byteReader = null) { ByteReader reader = byteReader == null ? new ByteReader(bytes) : byteReader; key = reader.ReadString(); value = reader.ReadString(); }
private static BoneMotion GetBoneMotion(ByteReader io) { // ? var motion=new BoneMotion(); motion.BoneName=io.GetSJIS(15); motion.FrameNum=io.GetUInt(); motion.Position=io.GetVector3(); motion.Rotation=io.GetVector4(); var bezierParams=new byte[64]; io.GetBytes(ref bezierParams); return motion; }
public static Model loadFromPath(string path) { var io=new ByteReader(File.ReadAllBytes(path)); var model=new Model(); model.Magic=io.GetAscii(30); model.ModelName=io.GetSJIS(20); int boneMotionCount=io.GetInt(); model.BoneMotions=Enumerable.Range(1, boneMotionCount).Select(_ =>GetBoneMotion(io)).ToArray(); return model; }
public unsafe byte* Read(ByteReader r, HttpRawRequest request) { // field-value = *( field-content / obs-fold ) // field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] // field-vchar = VCHAR / obs-text // obs-fold = CRLF 1*( SP / HTAB ) // obs-text = %x80-FF byte* pValueEnd = r.Position; while (r.Next().IsVcharOrObsTextOrSpaceOrTab()) if (!r.Current.IsSpaceOrHtab()) pValueEnd = r.Position; byte c = r.Current; if (c == '\r' && r.Next() == '\n') return pValueEnd; throw new BadRequestException(); }
private void Start() { #if !UNITY_METRO // Check for overridden localization data. var localizationFilePath = Application.persistentDataPath + "/Localization.txt"; FileInfo localizationFile = new FileInfo(localizationFilePath); if (localizationFile.Exists) { Debug.Log("Found localization file at " + localizationFilePath); using (var fileStream = localizationFile.OpenRead()) { using (var binaryReader = new BinaryReader(fileStream)) { var bytes = binaryReader.ReadBytes((int)localizationFile.Length); var nguiByteReader = new ByteReader(bytes); var localizationData = nguiByteReader.ReadDictionary(); Localization.Set("TestLanguage", localizationData); return; } } } #endif // Get current system language. SystemLanguage systemLanguage = Application.systemLanguage; Debug.Log(string.Format("System Language: {0}", systemLanguage)); // Check if available, otherwise fallback to English. TextAsset textAsset = Resources.Load(systemLanguage.ToString(), typeof(TextAsset)) as TextAsset; if (textAsset == null) { systemLanguage = SystemLanguage.English; Debug.Log(string.Format("Using fallback language: {0}", systemLanguage)); } Localization.language = systemLanguage.ToString(); }
protected override void ReadContent(ByteReader reader) { this.DataBlocks = new Dictionary<ushort, DataBlock>(ItemCount); for (var i = 0; i < ItemCount; i++) { var block = new DataBlock(); block.Page = this; block.Position = new PageAddress(this.PageID, reader.ReadUInt16()); block.ExtendPageID = reader.ReadUInt32(); for (var j = 0; j < CollectionIndex.INDEX_PER_COLLECTION; j++) { block.IndexRef[j] = reader.ReadPageAddress(); } var size = reader.ReadUInt16(); block.Data = reader.ReadBytes(size); this.DataBlocks.Add(block.Position.Index, block); } }
public XCCM(byte[] rawData) : base(rawData) { var reader = new ByteReader(); Climate = reader.ReadBytes <byte[]>(base.Data, base.Size); }
private static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false) { if (bytes == null) { return false; } ByteReader byteReader = new ByteReader(bytes); BetterList<string> betterList = byteReader.ReadCSV(); if (betterList.size < 2) { return false; } if (!merge || betterList.size - 1 != Localization.mLanguage.Length) { merge = false; Localization.mDictionary.Clear(); } betterList[0] = "KEY"; Localization.mLanguages = new string[betterList.size - 1]; for (int i = 0; i < Localization.mLanguages.Length; i++) { Localization.mLanguages[i] = betterList[i + 1]; } while (betterList != null) { Localization.AddCSV(betterList, !merge); betterList = byteReader.ReadCSV(); } return true; }
internal override void ReadBody(ByteReader reader) { this.Slot = reader.ReadByte(); this.ItemsInSlot = reader.ReadByte(); this.SpellCharges = reader.ReadByte(); }
public void ProcessCurrentBuffer(byte[] currentBuffer, StateObject state) { Socket clientSocket = state.ClientSocket; if (state.ConnectionBuffer.Length == 0) { state.ConnectionBuffer = currentBuffer; } else { byte[] oldConnectionBuffer = state.ConnectionBuffer; state.ConnectionBuffer = new byte[oldConnectionBuffer.Length + currentBuffer.Length]; Array.Copy(oldConnectionBuffer, state.ConnectionBuffer, oldConnectionBuffer.Length); Array.Copy(currentBuffer, 0, state.ConnectionBuffer, oldConnectionBuffer.Length, currentBuffer.Length); } // we now have all SMB message bytes received so far in state.ConnectionBuffer int bytesLeftInBuffer = state.ConnectionBuffer.Length; while (bytesLeftInBuffer >= 4) { // The packet is either Direct TCP transport packet (which is an NBT Session Message // Packet) or an NBT packet. int bufferOffset = state.ConnectionBuffer.Length - bytesLeftInBuffer; byte flags = ByteReader.ReadByte(state.ConnectionBuffer, bufferOffset + 1); int trailerLength = (flags & 0x01) << 16 | BigEndianConverter.ToUInt16(state.ConnectionBuffer, bufferOffset + 2); int packetLength = 4 + trailerLength; if (flags > 0x01) { #if DEBUG Log("[{0}] Invalid NBT flags", DateTime.Now.ToString("HH:mm:ss:ffff")); #endif state.ClientSocket.Close(); return; } if (packetLength > bytesLeftInBuffer) { break; } else { byte[] packetBytes = new byte[packetLength]; Array.Copy(state.ConnectionBuffer, bufferOffset, packetBytes, 0, packetLength); ProcessPacket(packetBytes, state); bytesLeftInBuffer -= packetLength; if (!clientSocket.Connected) { // Do not continue to process the buffer if the other side closed the connection return; } } } if (bytesLeftInBuffer > 0) { byte[] newReceiveBuffer = new byte[bytesLeftInBuffer]; Array.Copy(state.ConnectionBuffer, state.ConnectionBuffer.Length - bytesLeftInBuffer, newReceiveBuffer, 0, bytesLeftInBuffer); state.ConnectionBuffer = newReceiveBuffer; } else { state.ConnectionBuffer = new byte[0]; } }
/// <summary> /// Load the specified CSV file. /// </summary> static bool LoadCSV (byte[] bytes, TextAsset asset, bool merge = false) { if (bytes == null) return false; ByteReader reader = new ByteReader(bytes); // The first line should contain "KEY", followed by languages. BetterList<string> header = reader.ReadCSV(); // There must be at least two columns in a valid CSV file if (header.size < 2) return false; header.RemoveAt(0); string[] languagesToAdd = null; if (string.IsNullOrEmpty(mLanguage)) localizationHasBeenSet = false; // Clear the dictionary if (!localizationHasBeenSet || (!merge && !mMerging) || mLanguages == null || mLanguages.Length == 0) { mDictionary.Clear(); mLanguages = new string[header.size]; if (!localizationHasBeenSet) { mLanguage = PlayerPrefs.GetString("Language", header[0]); localizationHasBeenSet = true; } for (int i = 0; i < header.size; ++i) { mLanguages[i] = header[i]; if (mLanguages[i] == mLanguage) mLanguageIndex = i; } } else { languagesToAdd = new string[header.size]; for (int i = 0; i < header.size; ++i) languagesToAdd[i] = header[i]; // Automatically resize the existing languages and add the new language to the mix for (int i = 0; i < header.size; ++i) { if (!HasLanguage(header[i])) { int newSize = mLanguages.Length + 1; #if UNITY_FLASH string[] temp = new string[newSize]; for (int b = 0, bmax = arr.Length; b < bmax; ++b) temp[b] = mLanguages[b]; mLanguages = temp; #else System.Array.Resize(ref mLanguages, newSize); #endif mLanguages[newSize - 1] = header[i]; Dictionary<string, string[]> newDict = new Dictionary<string, string[]>(); foreach (KeyValuePair<string, string[]> pair in mDictionary) { string[] arr = pair.Value; #if UNITY_FLASH temp = new string[newSize]; for (int b = 0, bmax = arr.Length; b < bmax; ++b) temp[b] = arr[b]; arr = temp; #else System.Array.Resize(ref arr, newSize); #endif arr[newSize - 1] = arr[0]; newDict.Add(pair.Key, arr); } mDictionary = newDict; } } } Dictionary<string, int> languageIndices = new Dictionary<string, int>(); for (int i = 0; i < mLanguages.Length; ++i) languageIndices.Add(mLanguages[i], i); // Read the entire CSV file into memory for (;;) { BetterList<string> temp = reader.ReadCSV(); if (temp == null || temp.size == 0) break; if (string.IsNullOrEmpty(temp[0])) continue; AddCSV(temp, languagesToAdd, languageIndices); } if (!mMerging && onLocalize != null) { mMerging = true; OnLocalizeNotification note = onLocalize; onLocalize = null; note(); onLocalize = note; mMerging = false; } return true; }
protected override void ReadContent(ByteReader reader) { var info = reader.ReadString(HEADER_INFO.Length); var ver = reader.ReadByte(); if (info != HEADER_INFO) throw LiteException.InvalidDatabase(); if (ver != FILE_VERSION) throw LiteException.InvalidDatabaseVersion(ver); this.ChangeID = reader.ReadUInt16(); this.FreeEmptyPageID = reader.ReadUInt32(); this.LastPageID = reader.ReadUInt32(); this.DbVersion = reader.ReadUInt16(); this.Password = reader.ReadBytes(this.Password.Length); // read page collections references (position on end of page) var cols = reader.ReadByte(); for (var i = 0; i < cols; i++) { this.CollectionPages.Add(reader.ReadString(), reader.ReadUInt32()); } }
internal ContentTypeReader[] LoadAssetReaders() { #pragma warning disable 0219, 0649 // Trick to prevent the linker removing the code, but not actually execute the code if (falseflag) { // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** // This forces the classes not to be optimized out when deploying to iDevices var hByteReader = new ByteReader(); var hSByteReader = new SByteReader(); var hDateTimeReader = new DateTimeReader(); var hDecimalReader = new DecimalReader(); var hBoundingSphereReader = new BoundingSphereReader(); var hBoundingFrustumReader = new BoundingFrustumReader(); var hRayReader = new RayReader(); var hCharListReader = new ListReader<Char>(); var hRectangleListReader = new ListReader<Rectangle>(); var hRectangleArrayReader = new ArrayReader<Rectangle>(); var hVector3ListReader = new ListReader<Vector3>(); var hStringListReader = new ListReader<StringReader>(); var hIntListReader = new ListReader<Int32>(); var hSpriteFontReader = new SpriteFontReader(); var hTexture2DReader = new Texture2DReader(); var hCharReader = new CharReader(); var hRectangleReader = new RectangleReader(); var hStringReader = new StringReader(); var hVector2Reader = new Vector2Reader(); var hVector3Reader = new Vector3Reader(); var hVector4Reader = new Vector4Reader(); var hCurveReader = new CurveReader(); var hIndexBufferReader = new IndexBufferReader(); var hBoundingBoxReader = new BoundingBoxReader(); var hMatrixReader = new MatrixReader(); var hBasicEffectReader = new BasicEffectReader(); var hVertexBufferReader = new VertexBufferReader(); var hAlphaTestEffectReader = new AlphaTestEffectReader(); var hEnumSpriteEffectsReader = new EnumReader<Graphics.SpriteEffects>(); var hArrayFloatReader = new ArrayReader<float>(); var hArrayVector2Reader = new ArrayReader<Vector2>(); var hListVector2Reader = new ListReader<Vector2>(); var hArrayMatrixReader = new ArrayReader<Matrix>(); var hEnumBlendReader = new EnumReader<Graphics.Blend>(); var hNullableRectReader = new NullableReader<Rectangle>(); var hEffectMaterialReader = new EffectMaterialReader(); var hExternalReferenceReader = new ExternalReferenceReader(); var hSoundEffectReader = new SoundEffectReader(); var hSongReader = new SongReader(); } #pragma warning restore 0219, 0649 int numberOfReaders; // The first content byte i read tells me the number of content readers in this XNB file numberOfReaders = _reader.Read7BitEncodedInt(); contentReaders = new ContentTypeReader[numberOfReaders]; // For each reader in the file, we read out the length of the string which contains the type of the reader, // then we read out the string. Finally we instantiate an instance of that reader using reflection for (int i = 0; i < numberOfReaders; i++) { // This string tells us what reader we need to decode the following data // string readerTypeString = reader.ReadString(); string originalReaderTypeString = _reader.ReadString(); Func<ContentTypeReader> readerFunc; if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc)) { contentReaders[i] = readerFunc(); } else { //System.Diagnostics.Debug.WriteLine(originalReaderTypeString); // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); var l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { try { contentReaders[i] = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; } catch (TargetInvocationException ex) { // If you are getting here, the Mono runtime is most likely not able to JIT the type. // In particular, MonoTouch needs help instantiating types that are only defined in strings in Xnb files. throw new InvalidOperationException( "Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " + "with the following failed type string: " + originalReaderTypeString); } } else throw new ContentLoadException( "Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: " + originalReaderTypeString + " (" + readerTypeString + ")"); } // I think the next 4 bytes refer to the "Version" of the type reader, // although it always seems to be zero int typeReaderVersion = _reader.ReadInt32(); } return contentReaders; }
public ConstructionJobInstance(IBlockJobSettings settings, Vector3Int position, ItemTypes.ItemType type, ByteReader reader) : base(settings, position, type, reader) { StoredItemCount = reader.ReadVariableInt(); }
/// <summary> /// Load the specified CSV file. /// </summary> static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false) { if (bytes == null) { return(false); } ByteReader reader = new ByteReader(bytes); // The first line should contain "KEY", followed by languages. BetterList <string> header = reader.ReadCSV(); // There must be at least two columns in a valid CSV file if (header.size < 2) { return(false); } header.RemoveAt(0); string[] languagesToAdd = null; if (string.IsNullOrEmpty(mLanguage)) { localizationHasBeenSet = false; } // Clear the dictionary if (!localizationHasBeenSet || (!merge && !mMerging) || mLanguages == null || mLanguages.Length == 0) { mDictionary.Clear(); mLanguages = new string[header.size]; if (!localizationHasBeenSet) { mLanguage = PlayerPrefs.GetString("Language", header[0]); localizationHasBeenSet = true; } for (int i = 0; i < header.size; ++i) { mLanguages[i] = header[i]; if (mLanguages[i] == mLanguage) { mLanguageIndex = i; } } } else { languagesToAdd = new string[header.size]; for (int i = 0; i < header.size; ++i) { languagesToAdd[i] = header[i]; } // Automatically resize the existing languages and add the new language to the mix for (int i = 0; i < header.size; ++i) { if (!HasLanguage(header[i])) { int newSize = mLanguages.Length + 1; #if UNITY_FLASH string[] temp = new string[newSize]; for (int b = 0, bmax = arr.Length; b < bmax; ++b) { temp[b] = mLanguages[b]; } mLanguages = temp; #else System.Array.Resize(ref mLanguages, newSize); #endif mLanguages[newSize - 1] = header[i]; Dictionary <string, string[]> newDict = new Dictionary <string, string[]>(); foreach (KeyValuePair <string, string[]> pair in mDictionary) { string[] arr = pair.Value; #if UNITY_FLASH temp = new string[newSize]; for (int b = 0, bmax = arr.Length; b < bmax; ++b) { temp[b] = arr[b]; } arr = temp; #else System.Array.Resize(ref arr, newSize); #endif arr[newSize - 1] = arr[0]; newDict.Add(pair.Key, arr); } mDictionary = newDict; } } } Dictionary <string, int> languageIndices = new Dictionary <string, int>(); for (int i = 0; i < mLanguages.Length; ++i) { languageIndices.Add(mLanguages[i], i); } // Read the entire CSV file into memory for (;;) { BetterList <string> temp = reader.ReadCSV(); if (temp == null || temp.size == 0) { break; } if (string.IsNullOrEmpty(temp[0])) { continue; } AddCSV(temp, languagesToAdd, languageIndices); } if (!mMerging && onLocalize != null) { mMerging = true; OnLocalizeNotification note = onLocalize; onLocalize = null; note(); onLocalize = note; mMerging = false; } return(true); }
/// <summary> /// Set the localization data directly. /// </summary> static public void Set(string languageName, byte[] bytes) { ByteReader reader = new ByteReader(bytes); Set(languageName, reader.ReadDictionary()); }
/// <summary> /// Load the specified asset and activate the localization. /// </summary> static public void Load(TextAsset asset) { ByteReader reader = new ByteReader(asset); Set(asset.name, reader.ReadDictionary()); }
public AVFX(byte[] rawData) : base(rawData) { var reader = new ByteReader(); AreaVisual = reader.ReadBytes <string>(Data, Size); }
public QueryFileAltNameInfo(byte[] buffer, int offset) { uint fileNameLength = LittleEndianReader.ReadUInt32(buffer, ref offset); FileName = ByteReader.ReadUTF16String(buffer, ref offset, (int)(fileNameLength / 2)); }
public MachinistNight(IBlockJobSettings settings, Pipliz.Vector3Int position, ItemTypes.ItemType type, ByteReader reader) : base(settings, position, type, reader) { }
public override void DoRead(ByteReader BR) { throw new NotImplementedException(); }
public WrapperReader(ByteReader reader) { theReader = reader; }
public MAST(byte[] rawData) : base(rawData) { var reader = new ByteReader(); Filename = reader.ReadBytes <string>(base.Data, base.Size); }
internal ContentTypeReader[] LoadAssetReaders() { #pragma warning disable 0219, 0649 // Trick to prevent the linker removing the code, but not actually execute the code if (falseflag) { // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** // This forces the classes not to be optimized out when deploying to iDevices var hByteReader = new ByteReader(); var hSByteReader = new SByteReader(); var hDateTimeReader = new DateTimeReader(); var hDecimalReader = new DecimalReader(); var hBoundingSphereReader = new BoundingSphereReader(); var hBoundingFrustumReader = new BoundingFrustumReader(); var hRayReader = new RayReader(); var hCharListReader = new ListReader<Char>(); var hRectangleListReader = new ListReader<Rectangle>(); var hVector3ListReader = new ListReader<Vector3>(); var hStringListReader = new ListReader<StringReader>(); var hSpriteFontReader = new SpriteFontReader(); var hTexture2DReader = new Texture2DReader(); var hCharReader = new CharReader(); var hRectangleReader = new RectangleReader(); var hStringReader = new StringReader(); var hVector2Reader = new Vector2Reader(); var hVector3Reader = new Vector3Reader(); var hVector4Reader = new Vector4Reader(); var hCurveReader = new CurveReader(); var hIndexBufferReader = new IndexBufferReader(); var hBoundingBoxReader = new BoundingBoxReader(); var hMatrixReader = new MatrixReader(); var hBasicEffectReader = new BasicEffectReader(); var hVertexBufferReader = new VertexBufferReader(); var hAlphaTestEffectReader = new AlphaTestEffectReader(); } #pragma warning restore 0219, 0649 int numberOfReaders; // The first content byte i read tells me the number of content readers in this XNB file numberOfReaders = _reader.Read7BitEncodedInt(); contentReaders = new ContentTypeReader[numberOfReaders]; // For each reader in the file, we read out the length of the string which contains the type of the reader, // then we read out the string. Finally we instantiate an instance of that reader using reflection for (int i = 0; i < numberOfReaders; i++) { // This string tells us what reader we need to decode the following data // string readerTypeString = reader.ReadString(); string originalReaderTypeString = _reader.ReadString(); // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); Type l_readerType = Type.GetType(readerTypeString); if(l_readerType !=null) contentReaders[i] = (ContentTypeReader)Activator.CreateInstance(l_readerType,true); else throw new ContentLoadException("Could not find matching content reader of type " + originalReaderTypeString + " (" + readerTypeString + ")"); // I think the next 4 bytes refer to the "Version" of the type reader, // although it always seems to be zero int typeReaderVersion = _reader.ReadInt32(); } return contentReaders; }
public override void Handle(ByteReader data) { object target; if (targetTransformer != null) { target = targetTransformer.Reader.DynamicInvoke(SyncSerialization.ReadSyncObject(data, targetTransformer.NetworkType)); } else { target = ReadTarget(data); } if (targetType != null && target == null) { MpLog.Debug($"SyncMethod {this} read target null"); return; } if (!instancePath.NullOrEmpty()) { target = target.GetPropertyOrField(instancePath); } var args = new object[argTypes.Length]; for (int i = 0; i < argTypes.Length; i++) { if (argTransformers[i] == null) { args[i] = SyncSerialization.ReadSyncObject(data, argTypes[i]); } } for (int i = 0; i < argTypes.Length; i++) { if (argTransformers[i] is { } trans) { args[i] = trans.Reader.DynamicInvoke(SyncSerialization.ReadSyncObject(data, trans.NetworkType)); } } if (cancelIfAnyArgNull && args.Any(a => a == null)) { return; } if (context.HasFlag(SyncContext.MapSelected) && cancelIfNoSelectedMapObjects && Find.Selector.selected.Count == 0) { return; } if (context.HasFlag(SyncContext.WorldSelected) && cancelIfNoSelectedWorldObjects && Find.WorldSelector.selected.Count == 0) { return; } beforeCall?.Invoke(target, args); MpLog.Debug($"Invoked {method} on {target} with {args.Length} params {args.ToStringSafeEnumerable()}"); methodDelegate.Invoke(target, args); afterCall?.Invoke(target, args); }
/// <summary> /// Reload the font data. /// </summary> static public void Load (BMFont font, string name, byte[] bytes) { font.Clear(); if (bytes != null) { ByteReader reader = new ByteReader(bytes); char[] separator = new char[] { ' ' }; while (reader.canRead) { string line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) break; string[] split = line.Split(separator, System.StringSplitOptions.RemoveEmptyEntries); int len = split.Length; if (split[0] == "char") { // Expected data style: // char id=13 x=506 y=62 width=3 height=3 xoffset=-1 yoffset=50 xadvance=0 page=0 chnl=15 int channel = (len > 10) ? GetInt(split[10]) : 15; if (len > 9 && GetInt(split[9]) > 0) { Debug.LogError("Your font was exported with more than one texture. Only one texture is supported by NGUI.\n" + "You need to re-export your font, enlarging the texture's dimensions until everything fits into just one texture."); break; } if (len > 8) { int id = GetInt(split[1]); BMGlyph glyph = font.GetGlyph(id, true); if (glyph != null) { glyph.x = GetInt(split[2]); glyph.y = GetInt(split[3]); glyph.width = GetInt(split[4]); glyph.height = GetInt(split[5]); glyph.offsetX = GetInt(split[6]); glyph.offsetY = GetInt(split[7]); glyph.advance = GetInt(split[8]); glyph.channel = channel; } else Debug.Log("Char: " + split[1] + " (" + id + ") is NULL"); } else { Debug.LogError("Unexpected number of entries for the 'char' field (" + name + ", " + split.Length + "):\n" + line); break; } } else if (split[0] == "kerning") { // Expected data style: // kerning first=84 second=244 amount=-5 if (len > 3) { int first = GetInt(split[1]); int second = GetInt(split[2]); int amount = GetInt(split[3]); BMGlyph glyph = font.GetGlyph(second, true); if (glyph != null) glyph.SetKerning(first, amount); } else { Debug.LogError("Unexpected number of entries for the 'kerning' field (" + name + ", " + split.Length + "):\n" + line); break; } } else if (split[0] == "common") { // Expected data style: // common lineHeight=64 base=51 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=1 redChnl=4 greenChnl=4 blueChnl=4 if (len > 5) { font.charSize = GetInt(split[1]); font.baseOffset = GetInt(split[2]); font.texWidth = GetInt(split[3]); font.texHeight = GetInt(split[4]); int pages = GetInt(split[5]); if (pages != 1) { Debug.LogError("Font '" + name + "' must be created with only 1 texture, not " + pages); break; } } else { Debug.LogError("Unexpected number of entries for the 'common' field (" + name + ", " + split.Length + "):\n" + line); break; } } else if (split[0] == "page") { // Expected data style: // page id=0 file="textureName.png" if (len > 2) { font.spriteName = GetString(split[2]).Replace("\"", ""); font.spriteName = font.spriteName.Replace(".png", ""); font.spriteName = font.spriteName.Replace(".tga", ""); } } } } }
public void HasEnded_ReadsZeroBytes_NotEnded() { ByteReader byteReader = new ByteReader(new byte[] { 1, 2, 3 }, 8, 8); Assert.AreEqual(false, byteReader.HasEnded()); }
/// <summary> /// Load the specified asset and activate the localization. /// </summary> static public void Load (TextAsset asset) { ByteReader reader = new ByteReader(asset); Set(asset.name, reader.ReadDictionary()); }
internal override void ReadBody(ByteReader reader) { this.Position = reader.ReadVector3(); }
private static Type ReadFieldOrPropType(Module context, ByteReader br) { Universe u = context.universe; switch (br.ReadByte()) { case Signature.ELEMENT_TYPE_BOOLEAN: return(u.System_Boolean); case Signature.ELEMENT_TYPE_CHAR: return(u.System_Char); case Signature.ELEMENT_TYPE_I1: return(u.System_SByte); case Signature.ELEMENT_TYPE_U1: return(u.System_Byte); case Signature.ELEMENT_TYPE_I2: return(u.System_Int16); case Signature.ELEMENT_TYPE_U2: return(u.System_UInt16); case Signature.ELEMENT_TYPE_I4: return(u.System_Int32); case Signature.ELEMENT_TYPE_U4: return(u.System_UInt32); case Signature.ELEMENT_TYPE_I8: return(u.System_Int64); case Signature.ELEMENT_TYPE_U8: return(u.System_UInt64); case Signature.ELEMENT_TYPE_R4: return(u.System_Single); case Signature.ELEMENT_TYPE_R8: return(u.System_Double); case Signature.ELEMENT_TYPE_STRING: return(u.System_String); case Signature.ELEMENT_TYPE_SZARRAY: return(ReadFieldOrPropType(context, br).MakeArrayType()); case 0x55: return(ReadType(context, br)); case 0x50: return(u.System_Type); case 0x51: return(u.System_Object); default: throw new BadImageFormatException(); } }
private static CustomAttributeTypedArgument ReadFixedArg(Module context, ByteReader br, Type type) { Universe u = context.universe; if (type == u.System_String) { return(new CustomAttributeTypedArgument(type, br.ReadString())); } else if (type == u.System_Boolean) { return(new CustomAttributeTypedArgument(type, br.ReadByte() != 0)); } else if (type == u.System_Char) { return(new CustomAttributeTypedArgument(type, br.ReadChar())); } else if (type == u.System_Single) { return(new CustomAttributeTypedArgument(type, br.ReadSingle())); } else if (type == u.System_Double) { return(new CustomAttributeTypedArgument(type, br.ReadDouble())); } else if (type == u.System_SByte) { return(new CustomAttributeTypedArgument(type, br.ReadSByte())); } else if (type == u.System_Int16) { return(new CustomAttributeTypedArgument(type, br.ReadInt16())); } else if (type == u.System_Int32) { return(new CustomAttributeTypedArgument(type, br.ReadInt32())); } else if (type == u.System_Int64) { return(new CustomAttributeTypedArgument(type, br.ReadInt64())); } else if (type == u.System_Byte) { return(new CustomAttributeTypedArgument(type, br.ReadByte())); } else if (type == u.System_UInt16) { return(new CustomAttributeTypedArgument(type, br.ReadUInt16())); } else if (type == u.System_UInt32) { return(new CustomAttributeTypedArgument(type, br.ReadUInt32())); } else if (type == u.System_UInt64) { return(new CustomAttributeTypedArgument(type, br.ReadUInt64())); } else if (type == u.System_Type) { return(new CustomAttributeTypedArgument(type, ReadType(context, br))); } else if (type == u.System_Object) { return(ReadFixedArg(context, br, ReadFieldOrPropType(context, br))); } else if (type.IsArray) { int length = br.ReadInt32(); if (length == -1) { return(new CustomAttributeTypedArgument(type, null)); } Type elementType = type.GetElementType(); CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length]; for (int i = 0; i < length; i++) { array[i] = ReadFixedArg(context, br, elementType); } return(new CustomAttributeTypedArgument(type, array)); } else if (type.IsEnum) { return(new CustomAttributeTypedArgument(type, ReadFixedArg(context, br, type.GetEnumUnderlyingTypeImpl()).Value)); } else { throw new InvalidOperationException(); } }
public static void Set(string languageName, byte[] bytes) { ByteReader byteReader = new ByteReader(bytes); Localization.Set(languageName, byteReader.ReadDictionary()); }
private static IList <CustomAttributeTypedArgument> ReadConstructorArguments(Module context, ByteReader br, ConstructorInfo constructor) { MethodSignature sig = constructor.MethodSignature; int count = sig.GetParameterCount(); List <CustomAttributeTypedArgument> list = new List <CustomAttributeTypedArgument>(count); for (int i = 0; i < count; i++) { list.Add(ReadFixedArg(context, br, sig.GetParameterType(i))); } return(list.AsReadOnly()); }
/// <summary> /// Load the specified asset and activate the localization. /// </summary> public void Load (TextAsset asset) { ByteReader reader = new ByteReader(asset); Set(asset.name, reader.ReadDictionary()); OnLocalizationChanged(); }
public byte* Read(ByteReader r, HttpRawRequest request) { // Transfer-Encoding = *( "," OWS ) transfer-coding *( OWS "," [ OWS transfer-coding ] ) // transfer-coding = "chunked" / "compress" / "deflate" / "gzip" / transfer-extension // transfer-extension = token *( OWS ";" OWS transfer-parameter ) // transfer-parameter = token BWS "=" BWS ( token / quoted-string ) int hashCode = 0; byte c = r.Current; byte mappedC = c.MapTchar(); if (mappedC != 0 || c == ',') { while (true) { if (c == ',') { // skip '*( "," OWS )' do { c = r.Next(); } while (c == ',' || c.IsSpaceOrHtab()); mappedC = c.MapTchar(); } if (mappedC != c) { if (c == '\r') { if (r.Next() == '\n') { // TODO: return correct pointers throw new NotImplementedException(); } throw new BadRequestException(); } if (mappedC == 0) throw new BadRequestException(); r.ReplaceCurrent(mappedC); } // read 'token' var tc = new TransferCoding(); tc.Name.Value.Start = r.Position; do { hashCode = NativeByteArray.MixHash(hashCode, c = r.Next()); } while (c.IsTchar()); tc.Name.HashCode = hashCode; tc.Name.Value.End = r.Position; while (c.IsSpaceOrHtab()) c = r.Next(); if (c == '\r') { if (r.Next() == '\n') { // TODO: return correct pointers throw new NotImplementedException(); } throw new BadRequestException(); } if (c == ';') { do { c = r.Next(); } while (c.IsSpaceOrHtab()); do { // TODO: read token if (c.IsSpaceOrHtab()) { do { c = r.Next(); } while (c.IsSpaceOrHtab()); } if (c != '=') throw new BadRequestException(); do { c = r.Next(); } while (c.IsSpaceOrHtab()); // TODO: read token or quoted-string if (c.IsSpaceOrHtab()) { // TODO: save off pPos before whitespace do { c = r.Next(); } while (c.IsSpaceOrHtab()); } } while (c == ';'); } else if (c != ',') { throw new BadRequestException(); } } } throw new BadRequestException(); }
internal ContentTypeReader[] LoadAssetReaders(ContentReader reader) { #pragma warning disable 0219, 0649 // Trick to prevent the linker removing the code, but not actually execute the code if (falseflag) { // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** // This forces the classes not to be optimized out when deploying to iDevices var hByteReader = new ByteReader(); var hSByteReader = new SByteReader(); var hDateTimeReader = new DateTimeReader(); var hDecimalReader = new DecimalReader(); var hBoundingSphereReader = new BoundingSphereReader(); var hBoundingFrustumReader = new BoundingFrustumReader(); var hRayReader = new RayReader(); var hCharListReader = new ListReader<Char>(); var hRectangleListReader = new ListReader<Rectangle>(); var hRectangleArrayReader = new ArrayReader<Rectangle>(); var hVector3ListReader = new ListReader<Vector3>(); var hStringListReader = new ListReader<StringReader>(); var hIntListReader = new ListReader<Int32>(); var hSpriteFontReader = new SpriteFontReader(); var hTexture2DReader = new Texture2DReader(); var hCharReader = new CharReader(); var hRectangleReader = new RectangleReader(); var hStringReader = new StringReader(); var hVector2Reader = new Vector2Reader(); var hVector3Reader = new Vector3Reader(); var hVector4Reader = new Vector4Reader(); var hCurveReader = new CurveReader(); var hIndexBufferReader = new IndexBufferReader(); var hBoundingBoxReader = new BoundingBoxReader(); var hMatrixReader = new MatrixReader(); var hBasicEffectReader = new BasicEffectReader(); var hVertexBufferReader = new VertexBufferReader(); var hAlphaTestEffectReader = new AlphaTestEffectReader(); var hEnumSpriteEffectsReader = new EnumReader<Graphics.SpriteEffects>(); var hArrayFloatReader = new ArrayReader<float>(); var hArrayVector2Reader = new ArrayReader<Vector2>(); var hListVector2Reader = new ListReader<Vector2>(); var hArrayMatrixReader = new ArrayReader<Matrix>(); var hEnumBlendReader = new EnumReader<Graphics.Blend>(); var hNullableRectReader = new NullableReader<Rectangle>(); var hEffectMaterialReader = new EffectMaterialReader(); var hExternalReferenceReader = new ExternalReferenceReader(); var hSoundEffectReader = new SoundEffectReader(); var hSongReader = new SongReader(); var hModelReader = new ModelReader(); var hInt32Reader = new Int32Reader(); // At the moment the Video class doesn't exist // on all platforms... Allow it to compile anyway. #if ANDROID || IOS || MONOMAC || (WINDOWS && !OPENGL) || (WINRT && !WINDOWS_PHONE) var hVideoReader = new VideoReader(); #endif } #pragma warning restore 0219, 0649 // The first content byte i read tells me the number of content readers in this XNB file var numberOfReaders = reader.Read7BitEncodedInt(); var contentReaders = new ContentTypeReader[numberOfReaders]; var needsInitialize = new BitArray(numberOfReaders); _contentReaders = new Dictionary<Type, ContentTypeReader>(numberOfReaders); // Lock until we're done allocating and initializing any new // content type readers... this ensures we can load content // from multiple threads and still cache the readers. lock (_locker) { // For each reader in the file, we read out the length of the string which contains the type of the reader, // then we read out the string. Finally we instantiate an instance of that reader using reflection for (var i = 0; i < numberOfReaders; i++) { // This string tells us what reader we need to decode the following data // string readerTypeString = reader.ReadString(); string originalReaderTypeString = reader.ReadString(); Func<ContentTypeReader> readerFunc; if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc)) { contentReaders[i] = readerFunc(); needsInitialize[i] = true; } else { //System.Diagnostics.Debug.WriteLine(originalReaderTypeString); // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); var l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { ContentTypeReader typeReader; if (!_contentReadersCache.TryGetValue(l_readerType, out typeReader)) { try { typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; } catch (TargetInvocationException ex) { // If you are getting here, the Mono runtime is most likely not able to JIT the type. // In particular, MonoTouch needs help instantiating types that are only defined in strings in Xnb files. throw new InvalidOperationException( "Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " + "with the following failed type string: " + originalReaderTypeString, ex); } needsInitialize[i] = true; _contentReadersCache.Add(l_readerType, typeReader); } contentReaders[i] = typeReader; } else throw new ContentLoadException( "Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: " + originalReaderTypeString + " (" + readerTypeString + ")"); } var targetType = contentReaders[i].TargetType; if (targetType != null) _contentReaders.Add(targetType, contentReaders[i]); // I think the next 4 bytes refer to the "Version" of the type reader, // although it always seems to be zero reader.ReadInt32(); } // Initialize any new readers. for (var i = 0; i < contentReaders.Length; i++) { if (needsInitialize.Get(i)) contentReaders[i].Initialize(this); } } // lock (_locker) return contentReaders; }
public OKResponsePage(ByteReader br, TextReader tr, String fileName) : base(br, tr, fileName) { commonOK(); }
private static IList <CustomAttributeNamedArgument> ReadNamedArguments(Module context, ByteReader br, int named, Type type, bool required) { List <CustomAttributeNamedArgument> list = new List <CustomAttributeNamedArgument>(named); for (int i = 0; i < named; i++) { byte fieldOrProperty = br.ReadByte(); Type fieldOrPropertyType = ReadFieldOrPropType(context, br); if (fieldOrPropertyType.__IsMissing && !required) { return(null); } string name = br.ReadString(); CustomAttributeTypedArgument value = ReadFixedArg(context, br, fieldOrPropertyType); MemberInfo member; switch (fieldOrProperty) { case 0x53: member = GetField(context, type, name, fieldOrPropertyType); break; case 0x54: member = GetProperty(context, type, name, fieldOrPropertyType); break; default: throw new BadImageFormatException(); } list.Add(new CustomAttributeNamedArgument(member, value)); } return(list.AsReadOnly()); }
public override void DoRead(ByteReader BR) { SelectedUnitIndex = BR.ReadInt32(); }
public HTTPResponse(ByteReader br, TextReader tr, String fileName) : this() { KeyValuePair<string, ContentReader> reader = contentTypes[ fileName.Substring(fileName.LastIndexOf('.')).ToLower()]; attributes.Add("Content-Type", reader.Key); reader.Value(br, tr, fileName, ref attributes, this); }
private HmtxTable(ByteReader reader) { _reader = reader; }
// Add some non-zero constants to the mix. public void AddConstantsToTDB(RandoopConfiguration config) { foreach (SimpleTypeValues vs in config.simpleTypeValues) { Type type = Type.GetType(vs.simpleType); if (type == null) { throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file."); } foreach (FileName fn in vs.fileNames) { string fileName = fn.fileName; if (!File.Exists(fileName)) { throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName); } if (type.Equals(typeof(sbyte))) { SByteReader r = new SByteReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(sbyte), o)); } else if (type.Equals(typeof(byte))) { ByteReader r = new ByteReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(byte), o)); } else if (type.Equals(typeof(short))) { ShortReader r = new ShortReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(short), o)); } else if (type.Equals(typeof(ushort))) { UshortReader r = new UshortReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(ushort), o)); } else if (type.Equals(typeof(int))) { IntReader r = new IntReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(int), o)); } else if (type.Equals(typeof(uint))) { UintReader r = new UintReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(uint), o)); } else if (type.Equals(typeof(long))) { LongReader r = new LongReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(long), o)); } else if (type.Equals(typeof(ulong))) { UlongReader r = new UlongReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(ulong), o)); } else if (type.Equals(typeof(char))) { CharReader r = new CharReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(char), o)); } else if (type.Equals(typeof(float))) { FloatReader r = new FloatReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(float), o)); } else if (type.Equals(typeof(double))) { DoubleReader r = new DoubleReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(double), o)); } else if (type.Equals(typeof(bool))) { BoolReader r = new BoolReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(bool), o)); } else if (type.Equals(typeof(decimal))) { DecimalReader r = new DecimalReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(decimal), o)); } else { if (!type.Equals(typeof(string))) { throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file."); } Common.StringReader r = new Common.StringReader(); foreach (object o in r.Read(fileName)) this.AddPlan(Plan.Constant(typeof(string), o)); } } } }
public static HmtxTable ParseHmtx(ByteReader reader) { return(new HmtxTable(reader)); }
protected override void ReadContent(ByteReader reader) { this.CollectionName = reader.ReadString(); this.FreeDataPageID = reader.ReadUInt32(); var uintCount = reader.ReadUInt32(); // read as uint (4 bytes) foreach (var index in this.Indexes) { index.Field = reader.ReadString(); index.HeadNode = reader.ReadPageAddress(); index.TailNode = reader.ReadPageAddress(); index.FreeIndexPageID = reader.ReadUInt32(); index.Options.Unique = reader.ReadBoolean(); index.Options.IgnoreCase = reader.ReadBoolean(); index.Options.TrimWhitespace = reader.ReadBoolean(); index.Options.EmptyStringToNull = reader.ReadBoolean(); index.Options.RemoveAccents = reader.ReadBoolean(); } // be compatible with v2_beta var longCount = reader.ReadInt64(); this.DocumentCount = Math.Max(uintCount, longCount); }
internal override void ReadBody(ByteReader reader) { this.UnitNetID = reader.ReadUInt32(); }
internal ContentTypeReader[] LoadAssetReaders(ContentReader reader) { #pragma warning disable 0219, 0649 /* Trick to prevent the linker removing the code, but not actually execute the code * FIXME: Do we really need this in FNA? */ if (falseflag) { /* Dummy variables required for it to work on iDevices ** DO NOT DELETE ** * This forces the classes not to be optimized out when deploying to iDevices */ ByteReader hByteReader = new ByteReader(); SByteReader hSByteReader = new SByteReader(); DateTimeReader hDateTimeReader = new DateTimeReader(); DecimalReader hDecimalReader = new DecimalReader(); BoundingSphereReader hBoundingSphereReader = new BoundingSphereReader(); BoundingFrustumReader hBoundingFrustumReader = new BoundingFrustumReader(); RayReader hRayReader = new RayReader(); ListReader<char> hCharListReader = new ListReader<Char>(); ListReader<Rectangle> hRectangleListReader = new ListReader<Rectangle>(); ArrayReader<Rectangle> hRectangleArrayReader = new ArrayReader<Rectangle>(); ListReader<Vector3> hVector3ListReader = new ListReader<Vector3>(); ListReader<StringReader> hStringListReader = new ListReader<StringReader>(); ListReader<int> hIntListReader = new ListReader<Int32>(); SpriteFontReader hSpriteFontReader = new SpriteFontReader(); Texture2DReader hTexture2DReader = new Texture2DReader(); CharReader hCharReader = new CharReader(); RectangleReader hRectangleReader = new RectangleReader(); StringReader hStringReader = new StringReader(); Vector2Reader hVector2Reader = new Vector2Reader(); Vector3Reader hVector3Reader = new Vector3Reader(); Vector4Reader hVector4Reader = new Vector4Reader(); CurveReader hCurveReader = new CurveReader(); IndexBufferReader hIndexBufferReader = new IndexBufferReader(); BoundingBoxReader hBoundingBoxReader = new BoundingBoxReader(); MatrixReader hMatrixReader = new MatrixReader(); BasicEffectReader hBasicEffectReader = new BasicEffectReader(); VertexBufferReader hVertexBufferReader = new VertexBufferReader(); AlphaTestEffectReader hAlphaTestEffectReader = new AlphaTestEffectReader(); EnumReader<Microsoft.Xna.Framework.Graphics.SpriteEffects> hEnumSpriteEffectsReader = new EnumReader<Graphics.SpriteEffects>(); ArrayReader<float> hArrayFloatReader = new ArrayReader<float>(); ArrayReader<Vector2> hArrayVector2Reader = new ArrayReader<Vector2>(); ListReader<Vector2> hListVector2Reader = new ListReader<Vector2>(); ArrayReader<Matrix> hArrayMatrixReader = new ArrayReader<Matrix>(); EnumReader<Microsoft.Xna.Framework.Graphics.Blend> hEnumBlendReader = new EnumReader<Graphics.Blend>(); NullableReader<Rectangle> hNullableRectReader = new NullableReader<Rectangle>(); EffectMaterialReader hEffectMaterialReader = new EffectMaterialReader(); ExternalReferenceReader hExternalReferenceReader = new ExternalReferenceReader(); SoundEffectReader hSoundEffectReader = new SoundEffectReader(); SongReader hSongReader = new SongReader(); } #pragma warning restore 0219, 0649 /* The first content byte i read tells me the number of * content readers in this XNB file. */ int numberOfReaders = reader.Read7BitEncodedInt(); ContentTypeReader[] newReaders = new ContentTypeReader[numberOfReaders]; BitArray needsInitialize = new BitArray(numberOfReaders); contentReaders = new Dictionary<Type, ContentTypeReader>(numberOfReaders); /* Lock until we're done allocating and initializing any new * content type readers... this ensures we can load content * from multiple threads and still cache the readers. */ lock (locker) { /* For each reader in the file, we read out the * length of the string which contains the type * of the reader, then we read out the string. * Finally we instantiate an instance of that * reader using reflection. */ for (int i = 0; i < numberOfReaders; i += 1) { /* This string tells us what reader we * need to decode the following data. */ string originalReaderTypeString = reader.ReadString(); Func<ContentTypeReader> readerFunc; if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc)) { newReaders[i] = readerFunc(); needsInitialize[i] = true; } else { // Need to resolve namespace differences string readerTypeString = originalReaderTypeString; readerTypeString = PrepareType(readerTypeString); Type l_readerType = Type.GetType(readerTypeString); if (l_readerType != null) { ContentTypeReader typeReader; if (!contentReadersCache.TryGetValue(l_readerType, out typeReader)) { try { typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; } catch (TargetInvocationException ex) { /* If you are getting here, the Mono runtime * is most likely not able to JIT the type. * In particular, MonoTouch needs help * instantiating types that are only defined * in strings in Xnb files. */ throw new InvalidOperationException( "Failed to get default constructor for ContentTypeReader. " + "To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " + "with the following failed type string: " + originalReaderTypeString, ex ); } needsInitialize[i] = true; contentReadersCache.Add(l_readerType, typeReader); } newReaders[i] = typeReader; } else { throw new ContentLoadException( "Could not find ContentTypeReader Type. " + "Please ensure the name of the Assembly that " + "contains the Type matches the assembly in the full type name: " + originalReaderTypeString + " (" + readerTypeString + ")" ); } } contentReaders.Add(newReaders[i].TargetType, newReaders[i]); /* I think the next 4 bytes refer to the "Version" of the type reader, * although it always seems to be zero. */ reader.ReadInt32(); } // Initialize any new readers. for (int i = 0; i < newReaders.Length; i += 1) { if (needsInitialize.Get(i)) { newReaders[i].Initialize(this); } } } // lock (locker) return newReaders; }
public override void Load(ByteReader reader) { RejectedPacketNumber = reader.GetUInt32(); }
/// <summary> /// Load the specified CSV file. /// </summary> static bool LoadCSV (byte[] bytes, TextAsset asset, bool merge = false) { if (bytes == null) return false; ByteReader reader = new ByteReader(bytes); // The first line should contain "KEY", followed by languages. BetterList<string> temp = reader.ReadCSV(); // There must be at least two columns in a valid CSV file if (temp.size < 2) return false; // Clear the dictionary if (!merge || temp.size - 1 != mLanguage.Length) { merge = false; mDictionary.Clear(); } temp[0] = "KEY"; mLanguages = new string[temp.size - 1]; for (int i = 0; i < mLanguages.Length; ++i) mLanguages[i] = temp[i + 1]; // Read the entire CSV file into memory while (temp != null) { AddCSV(temp, !merge); temp = reader.ReadCSV(); } return true; }
/// <summary> /// Reload the font data. /// </summary> static public void Load (BMFont font, string name, byte[] bytes) { font.Clear(); if (bytes != null) { ByteReader reader = new ByteReader(bytes); char[] separator = new char[] { ' ' }; while (reader.canRead) { string line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) break; string[] split = line.Split(separator, System.StringSplitOptions.RemoveEmptyEntries); if (split[0] == "char") { // Expected data style: // char id=13 x=506 y=62 width=3 height=3 xoffset=-1 yoffset=50 xadvance=0 page=0 chnl=15 if (split.Length > 8) { int id = GetInt(split[1]); BMGlyph glyph = font.GetGlyph(id, true); if (glyph != null) { glyph.x = GetInt(split[2]); glyph.y = GetInt(split[3]); glyph.width = GetInt(split[4]); glyph.height = GetInt(split[5]); glyph.offsetX = GetInt(split[6]); glyph.offsetY = GetInt(split[7]); glyph.advance = GetInt(split[8]); } else Debug.Log("Char: " + split[1] + " (" + id + ") is NULL"); } else { Debug.LogError("Unexpected number of entries for the 'char' field (" + name + ", " + split.Length + "):\n" + line); break; } } else if (split[0] == "kerning") { // Expected data style: // kerning first=84 second=244 amount=-5 if (split.Length > 3) { int first = GetInt(split[1]); int second = GetInt(split[2]); int amount = GetInt(split[3]); BMGlyph glyph = font.GetGlyph(second, true); if (glyph != null) glyph.SetKerning(first, amount); } else { Debug.LogError("Unexpected number of entries for the 'kerning' field (" + name + ", " + split.Length + "):\n" + line); break; } } else if (split[0] == "common") { // Expected data style: // common lineHeight=64 base=51 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=1 redChnl=4 greenChnl=4 blueChnl=4 if (split.Length > 5) { font.charSize = GetInt(split[1]); font.baseOffset = GetInt(split[2]); font.texWidth = GetInt(split[3]); font.texHeight = GetInt(split[4]); int pages = GetInt(split[5]); if (pages != 1) { Debug.LogError("Font '" + name + "' must be created with only 1 texture, not " + pages); break; } } else { Debug.LogError("Unexpected number of entries for the 'common' field (" + name + ", " + split.Length + "):\n" + line); break; } } else if (split[0] == "page") { // Expected data style: // page id=0 file="textureName.png" if (split.Length > 2) { font.spriteName = GetString(split[2]).Replace("\"", ""); font.spriteName = font.spriteName.Replace(".png", ""); font.spriteName = font.spriteName.Replace(".tga", ""); } } } } }
internal ContentTypeReader[] LoadAssetReaders() { if (ContentTypeReaderManager.falseflag) { ByteReader byteReader = new ByteReader(); SByteReader sbyteReader = new SByteReader(); DateTimeReader dateTimeReader = new DateTimeReader(); DecimalReader decimalReader = new DecimalReader(); BoundingSphereReader boundingSphereReader = new BoundingSphereReader(); BoundingFrustumReader boundingFrustumReader = new BoundingFrustumReader(); RayReader rayReader = new RayReader(); ListReader<char> listReader1 = new ListReader<char>(); ListReader<Rectangle> listReader2 = new ListReader<Rectangle>(); ArrayReader<Rectangle> arrayReader1 = new ArrayReader<Rectangle>(); ListReader<Vector3> listReader3 = new ListReader<Vector3>(); ListReader<StringReader> listReader4 = new ListReader<StringReader>(); ListReader<int> listReader5 = new ListReader<int>(); SpriteFontReader spriteFontReader = new SpriteFontReader(); Texture2DReader texture2Dreader = new Texture2DReader(); CharReader charReader = new CharReader(); RectangleReader rectangleReader = new RectangleReader(); StringReader stringReader = new StringReader(); Vector2Reader vector2Reader = new Vector2Reader(); Vector3Reader vector3Reader = new Vector3Reader(); Vector4Reader vector4Reader = new Vector4Reader(); CurveReader curveReader = new CurveReader(); IndexBufferReader indexBufferReader = new IndexBufferReader(); BoundingBoxReader boundingBoxReader = new BoundingBoxReader(); MatrixReader matrixReader = new MatrixReader(); BasicEffectReader basicEffectReader = new BasicEffectReader(); VertexBufferReader vertexBufferReader = new VertexBufferReader(); AlphaTestEffectReader testEffectReader = new AlphaTestEffectReader(); EnumReader<SpriteEffects> enumReader1 = new EnumReader<SpriteEffects>(); ArrayReader<float> arrayReader2 = new ArrayReader<float>(); ArrayReader<Vector2> arrayReader3 = new ArrayReader<Vector2>(); ListReader<Vector2> listReader6 = new ListReader<Vector2>(); ArrayReader<Matrix> arrayReader4 = new ArrayReader<Matrix>(); EnumReader<Blend> enumReader2 = new EnumReader<Blend>(); NullableReader<Rectangle> nullableReader = new NullableReader<Rectangle>(); EffectMaterialReader effectMaterialReader = new EffectMaterialReader(); ExternalReferenceReader externalReferenceReader = new ExternalReferenceReader(); } int length = this._reader.Read7BitEncodedInt(); this.contentReaders = new ContentTypeReader[length]; for (int index = 0; index < length; ++index) { string str = this._reader.ReadString(); Func<ContentTypeReader> func; if (ContentTypeReaderManager.typeCreators.TryGetValue(str, out func)) { this.contentReaders[index] = func(); } else { string typeName = ContentTypeReaderManager.PrepareType(str); Type type = Type.GetType(typeName); if (type != (Type) null) { try { this.contentReaders[index] = ContentExtensions.GetDefaultConstructor(type).Invoke((object[]) null) as ContentTypeReader; } catch (TargetInvocationException ex) { throw new InvalidOperationException("Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() with the following failed type string: " + str); } } else throw new ContentLoadException("Could not find matching content reader of type " + str + " (" + typeName + ")"); } this._reader.ReadInt32(); } return this.contentReaders; }
protected override void ReadBody(ByteReader reader) { this.Position = reader.ReadVector3(); }
public SkillFile(CTF.File ctf, string filename) { FileName = filename; var br = new ByteReader(File.ReadAllBytes(FileName)); if (br.STRING() != FileID) { throw new Exception("Invalid file format."); } var messages = new List<CTF.Message>(); foreach (var msg in ctf.Messages) { if (msg.SubCategory.Category.Name != "Skills") { continue; } messages.Add(msg); } var skill_count = br.UINT(); Skills = new List<Skill>(); for (int i = 0; i < skill_count; i++) { var s = new Skill(); s.Type = (SkillType)br.BYTE(); var message_id = br.STRING(); if (message_id == "") { Skills.Add(null); br.Skip(39); continue; } var class_id = br.STRING(); foreach (var message in messages) { if (message.SubCategory.ID == uint.Parse(class_id) && message.ID == uint.Parse(message_id)) { s.Message = message; break; } } if (s.Message == null) { throw new Exception("Failed to find message."); } s.IconIndex = br.UINT(); s.ProjectileAnimation = br.USHORT(); s.CharacterAnimation = br.UINT(); s.Honor = br.INT(); s.Level = br.UINT(); s.CharacterType = br.BYTE(); var mana = br.UINT(); if (mana > 1000000000) { s.ManaUsageStyle = ManaUsageStyle.Percentage; s.ManaUsage = mana - 1000000000; } else { s.ManaUsageStyle = ManaUsageStyle.Fixed; s.ManaUsage = mana; } var range = br.SHORT(); if (range > 10000) { s.IsAOE = true; s.Range = (short)(range - 10000); } else { s.IsAOE = false; s.Range = range; } s.NeedsTarget = br.BYTE(); s.Unused1 = br.BYTE(); s.Unused2 = br.BYTE(); s.Unused3 = br.BYTE(); s.EffectType = br.BYTE(); s.Multiplier = br.UINT(); s.Unknown5 = br.UINT(); Skills.Add(s); } }
private static string ReadString(ByteReader br) { return(Encoding.UTF8.GetString(br.ReadBytes(br.ReadCompressedUInt()))); }
/// <summary> /// Set the localization data directly. /// </summary> static public void Set (string languageName, byte[] bytes) { ByteReader reader = new ByteReader(bytes); Set(languageName, reader.ReadDictionary()); }
internal static bool ReadFieldMarshal(Module module, int token, out FieldMarshal fm) { fm = new FieldMarshal(); foreach (int i in module.FieldMarshal.Filter(token)) { ByteReader blob = module.GetBlob(module.FieldMarshal.records[i].NativeType); fm.UnmanagedType = (UnmanagedType)blob.ReadCompressedUInt(); if (fm.UnmanagedType == UnmanagedType.LPArray) { fm.ArraySubType = (UnmanagedType)blob.ReadCompressedUInt(); if (fm.ArraySubType == NATIVE_TYPE_MAX) { fm.ArraySubType = null; } if (blob.Length != 0) { fm.SizeParamIndex = (short)blob.ReadCompressedUInt(); if (blob.Length != 0) { fm.SizeConst = blob.ReadCompressedUInt(); if (blob.Length != 0 && blob.ReadCompressedUInt() == 0) { fm.SizeParamIndex = null; } } } } else if (fm.UnmanagedType == UnmanagedType.SafeArray) { if (blob.Length != 0) { fm.SafeArraySubType = (VarEnum)blob.ReadCompressedUInt(); if (blob.Length != 0) { fm.SafeArrayUserDefinedSubType = ReadType(module, blob); } } } else if (fm.UnmanagedType == UnmanagedType.ByValArray) { fm.SizeConst = blob.ReadCompressedUInt(); if (blob.Length != 0) { fm.ArraySubType = (UnmanagedType)blob.ReadCompressedUInt(); } } else if (fm.UnmanagedType == UnmanagedType.ByValTStr) { fm.SizeConst = blob.ReadCompressedUInt(); } else if (fm.UnmanagedType == UnmanagedType.Interface || fm.UnmanagedType == UnmanagedType.IDispatch || fm.UnmanagedType == UnmanagedType.IUnknown) { if (blob.Length != 0) { fm.IidParameterIndex = blob.ReadCompressedUInt(); } } else if (fm.UnmanagedType == UnmanagedType.CustomMarshaler) { blob.ReadCompressedUInt(); blob.ReadCompressedUInt(); fm.MarshalType = ReadString(blob); fm.MarshalCookie = ReadString(blob); TypeNameParser parser = TypeNameParser.Parse(fm.MarshalType, false); if (!parser.Error) { fm.MarshalTypeRef = parser.GetType(module.universe, module, false, fm.MarshalType, false, false); } } return(true); } return(false); }
/// <summary> /// Load the specified asset and activate the localization. /// </summary> void Load(TextAsset asset) { mLanguage = asset.name; PlayerPrefs.SetString("Language", mLanguage); ByteReader reader = new ByteReader(asset); mDictionary = reader.ReadDictionary(); UIRoot.Broadcast("OnLocalize", this); }
public static bool ContainsFileRecordSegment(byte[] recordBytes, int offset) { string fileSignature = ByteReader.ReadAnsiString(recordBytes, offset, 4); return(fileSignature == ValidSignature); }
/// <summary> /// Load the specified CSV file. /// </summary> static public bool LoadCSV (TextAsset asset) { #if SHOW_REPORT mUsed.Clear(); #endif ByteReader reader = new ByteReader(asset); // The first line should contain "KEY", followed by languages. BetterList<string> temp = reader.ReadCSV(); // There must be at least two columns in a valid CSV file if (temp.size < 2) return false; // The first entry must be 'KEY', capitalized temp[0] = "KEY"; #if !UNITY_3_5 // Ensure that the first value is what we expect if (!string.Equals(temp[0], "KEY")) { Debug.LogError("Invalid localization CSV file. The first value is expected to be 'KEY', followed by language columns.\n" + "Instead found '" + temp[0] + "'", asset); return false; } else #endif { knownLanguages = new string[temp.size - 1]; for (int i = 0; i < knownLanguages.Length; ++i) knownLanguages[i] = temp[i + 1]; } mDictionary.Clear(); // Read the entire CSV file into memory while (temp != null) { AddCSV(temp); temp = reader.ReadCSV(); } return true; }
public override void Load(ByteReader br) { }