ReadByte() public method

public ReadByte ( ) : byte
return byte
コード例 #1
0
ファイル: Pet_Info.cs プロジェクト: stephenZh/l2net
        public void Load_Pet(ByteBuffer buff)
        {
            SummonType = buff.ReadUInt32(); //1 = summon, 2 = pet
            ID = buff.ReadUInt32();
            NPCID = buff.ReadUInt32();
            isAttackAble = buff.ReadUInt32();//attackable = 0

            X = buff.ReadUInt32();
            Y = buff.ReadUInt32();
            Z = buff.ReadUInt32();
            Heading = buff.ReadInt32();
            buff.ReadUInt32();//0x00

            MatkSpeed = buff.ReadUInt32();
            PatkSpeed = buff.ReadUInt32();
            RunSpeed = buff.ReadUInt32();
            WalkSpeed = buff.ReadUInt32();
            SwimRunSpeed = buff.ReadUInt32();
            SwimWalkSpeed = buff.ReadUInt32();
            flRunSpeed = buff.ReadUInt32();
            flWalkSpeed = buff.ReadUInt32();
            if (Globals.gamedata.Chron >= Chronicle.CT1)
            {
                FlyRunSpeed = buff.ReadUInt32();
                FlyWalkSpeed = buff.ReadUInt32();
            }

            MoveSpeedMult = System.Convert.ToSingle(buff.ReadDouble());
            AttackSpeedMult = System.Convert.ToSingle(buff.ReadDouble());
            CollisionRadius = System.Convert.ToSingle(buff.ReadDouble());
            CollisionHeight = System.Convert.ToSingle(buff.ReadDouble());

            LWeapon = buff.ReadUInt32();
            Armor = buff.ReadUInt32();
            RWeapon = buff.ReadUInt32();

            HasOwner = buff.ReadByte(); //owneronline
            isRunning = buff.ReadByte();
            isInCombat = buff.ReadByte();
            isAlikeDead = buff.ReadByte();
            isSummoned = buff.ReadByte(); //isSummoned 0=teleported  1=default   2=summoned

            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                buff.ReadUInt32(); //FF FF FF FF
            }
            Name = buff.ReadString();
            if (string.IsNullOrWhiteSpace(Name))
            {
                Name = Util.GetNPCName(NPCID);//"Unnamed Pet";
            }
            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                buff.ReadUInt32(); //FF FF FF FF
            }
            Title = buff.ReadString(); //OwnerName
            buff.ReadUInt32();//1

            PvPFlag = buff.ReadUInt32();
            Karma = buff.ReadInt32();

            Cur_Fed = buff.ReadUInt32();
            Max_Fed = buff.ReadUInt32();

            Cur_HP = buff.ReadUInt32();
            Max_HP = buff.ReadUInt32();

            Cur_MP = buff.ReadUInt32();
            Max_MP = buff.ReadUInt32();

            SP = buff.ReadUInt32();
            Level = buff.ReadUInt32();
            XP = buff.ReadUInt64();

            XP_ThisLevel = buff.ReadUInt64();
            XP_NextLevel = buff.ReadUInt64();

            Cur_Load = buff.ReadUInt32();
            Max_Load = buff.ReadUInt32();

            Patk = buff.ReadUInt32();
            PDef = buff.ReadUInt32();
            Accuracy = buff.ReadUInt32();// p
            Evasion = buff.ReadUInt32();//p
            Focus = buff.ReadUInt32();//p
            Matk = buff.ReadUInt32();
            MDef = buff.ReadUInt32();

            buff.ReadUInt32();//m acu
            buff.ReadUInt32();//m eva
            buff.ReadUInt32();//m crit

            buff.ReadUInt32();// speed
            buff.ReadUInt32();//patak sped
            buff.ReadUInt32();// cast

            /*if (Globals.gamedata.Chron < Chronicle.CT3_0)
            {
                AbnormalEffects = buff.ReadUInt32(); //AbnormalEffect bleed=1; poison=2; poison & bleed=3; flame=4;
            }
            else
            {
                buff.ReadUInt32(); //??
            }*/
            Mountable = buff.ReadUInt16();

            buff.ReadByte();
            buff.ReadUInt16();

            if (Globals.gamedata.Chron >= Chronicle.CT1)
            {
                TeamCircle = buff.ReadByte();
                /*if (Globals.gamedata.Chron >= Chronicle.CT3_0)
                {
                    //buff.ReadUInt32(); //00 00 00 00
                    buff.ReadUInt16();
                    AbnormalEffects = buff.ReadUInt32();
                    buff.ReadUInt32(); //00 00 00 00
                    buff.ReadUInt16(); //00 00 00 00
                }*/
                SSUsage = buff.ReadUInt32();
                SPSUSage = buff.ReadUInt32();
                Form = buff.ReadUInt32();
                buff.ReadUInt32();//0x00
                if (Globals.gamedata.Chron >= Chronicle.CT3_0)
                {
                    //buff.ReadUInt16(); //00 00
                    try
                    {
                        buff.ReadUInt32(); //00 00
                        buff.ReadUInt32(); //02 00 00 00 current pet points
                        buff.ReadUInt32(); //06 00 00 00 max pet points

                        uint abn_count = buff.ReadUInt32();
                        if (abn_count < 30) // well ... its oddi wayso :P
                        {
                            _AbnEffects.Add(buff.ReadUInt32());
                        }


                    }
                    catch
                    {

                    }
                }
            }
            else
            {
                HasOwner = buff.ReadByte();
                SSUsage = buff.ReadUInt32();
                Form = buff.ReadUInt32();
                buff.ReadUInt32();//0x00
            }
        }
コード例 #2
0
ファイル: Pet_Info.cs プロジェクト: stephenZh/l2net
        public void Update(ByteBuffer buff)
        {
            uint data = buff.ReadByte();

            switch (data)
            {
                case 0x01://level
                    Level = buff.ReadUInt32();
                    break;
                case 0x02://exp
                    XP = buff.ReadUInt64();
                    break;
                case 0x03://str
                    buff.ReadUInt32();
                    break;
                case 0x04://dex
                    buff.ReadUInt32();
                    break;
                case 0x05://con
                    buff.ReadUInt32();
                    break;
                case 0x06://int
                    buff.ReadUInt32();
                    break;
                case 0x07://wit
                    buff.ReadUInt32();
                    break;
                case 0x08://men
                    buff.ReadUInt32();
                    break;
                case 0x09://cur hp
                    Cur_HP = buff.ReadUInt32();
                    break;
                case 0x0A://max hp
                    Max_HP = buff.ReadUInt32();
                    break;
                case 0x0B://cur mp
                    Cur_MP = buff.ReadUInt32();
                    break;
                case 0x0C://max mp
                    Max_MP = buff.ReadUInt32();
                    break;
                case 0x0D://sp
                    SP = buff.ReadUInt32();
                    break;
                case 0x0E://cur load
                    Cur_Load = buff.ReadUInt32();
                    break;
                case 0x0F://max load
                    Max_Load = buff.ReadUInt32();
                    break;
                case 0x10://..
                    buff.ReadUInt32();
                    break;
                case 0x11://patk
                    Patk = buff.ReadUInt32();
                    break;
                case 0x12://atk spd
                    PatkSpeed = buff.ReadUInt32();
                    break;
                case 0x13://pdef
                    PDef = buff.ReadUInt32();
                    break;
                case 0x14://evasion
                    Evasion = buff.ReadUInt32();
                    break;
                case 0x15://acc
                    Accuracy = buff.ReadUInt32();
                    break;
                case 0x16://crit
                    Focus = buff.ReadUInt32();
                    break;
                case 0x17://m atk
                    Matk = buff.ReadUInt32();
                    break;
                case 0x18://cast spd
                    MatkSpeed = buff.ReadUInt32();
                    break;
                case 0x19://mdef
                    MDef = buff.ReadUInt32();
                    break;
                case 0x1A://pvp flag
                    PvPFlag = buff.ReadUInt32();
                    break;
                case 0x1B://karma
                    Karma = buff.ReadInt32();
                    break;
                case 0x1C://..
                    buff.ReadUInt32();
                    break;
                case 0x1D://..
                    buff.ReadUInt32();
                    break;
                case 0x1E://..
                    buff.ReadUInt32();
                    break;
                case 0x1F://..
                    buff.ReadUInt32();
                    break;
                case 0x20://..
                    buff.ReadUInt32();
                    break;
                case 0x21://cur cp
                    Cur_CP = buff.ReadUInt32();
                    break;
                case 0x22://max cp
                    Max_CP = buff.ReadUInt32();
                    break;
                default:
                    buff.ReadUInt32();
                    break;
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Besyaka/swtor-emu
        static void Main(string[] args)
        {
            Console.Title = "Nexus Shard Server";

            Console.WriteLine("Nexus Shard Server\n");
            Utility.WriteLegal();
            Console.WriteLine("");

            AsyncServer server = new AsyncServer(IPAddress.Parse("0.0.0.0"), 20063);
            server.Start();

            server.ConnectionAccepted += new AsyncServer.ConnectionAcceptedHandler(connection =>
            {
                TORLog.Network("CnxAccept => " + connection.GetHashCode());
                connection.DataReceived += new AsyncConnection.ConnectionDataReceivedHandler(data =>
                {
                    if (connection.State == 1)
                    {
                        // rsa packet
                        connection.SetState(2);
                        connection.SendPacket(new SMsg_ClientSignatureRequest("OmegaServerProxyObjectName", 0x0174F5));
                        return;
                    }

                    ByteBuffer buffer = new ByteBuffer(ByteOrder.LittleEndian, data);
                    byte opcode = (byte)buffer.ReadByte();

                    byte[] len_data = buffer.ReadBytes(4);
                    byte chk = (byte)buffer.ReadByte();
                    uint packetid = buffer.ReadUInt();

                    if (chk != (byte)(opcode ^ len_data[0] ^ len_data[1] ^ len_data[2] ^ len_data[3]))
                    {
                        TORLog.Warn("Received packet with invalid checksum!");
                    }

                    if (opcode == 1) // Client Ping Packet
                    {
                        TORLog.Network("Ping from " + connection.GetHashCode() + " Seq = " + packetid);
                        ByteBuffer response = new ByteBuffer(ByteOrder.LittleEndian);
                        response.WriteByte(2); // Pong OPC = 2
                        response.WriteInt(0); // Pong Len
                        response.WriteByte(0); // Pong Chk
                        response.WriteUInt(packetid); // Pong
                        response.WriteInt(0);
                        response.WriteInt(1);
                        response.WriteByte(0);
                        connection.SendTORPacket(response);
                        return;
                    }

                    string packetname = OpcodeManager.Instance.GetPacketName(opcode, packetid);

                    if (packetname == "")
                    {
                        TORLog.Warn("Received unknown packet from SWTOR client\nOpcode = 0x" + opcode.ToString("X2") + " -- PacketID = 0x" + packetid.ToString("X8"));
                        TORLog.Warn("--- dump ---");
                        TORLog.Warn(Utility.HexDump(data));
                    }
                    else
                    {
                        try
                        {
                            IClientPacket pkt = Activator.CreateInstance(Type.GetType("ShardServer.Packets.Client." + packetname)) as IClientPacket;
                            TORLog.Network("PktRecv @ " + connection.GetHashCode() + " << " + packetname);
                            pkt.ExecutePacket(connection, buffer);
                        }
                        catch (Exception ex)
                        {
                            TORLog.Error("Exception occured while processing " + packetname, ex);
                        }
                    }
                });
                // Send HELLO packet
                connection.SendClear(new byte[] { 0x03, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
                // State is 1
                connection.SetState(1);
                connection.EngageReading();
            });

            TORLog.Info("SHARD Server running, press Enter to exit ...");
            Console.ReadLine();
        }
コード例 #4
0
ファイル: CharacterPackets.cs プロジェクト: Besyaka/swtor-emu
        void IClientPacket.ExecutePacket(AsyncConnection connection, ByteBuffer packet)
        {
            uint id = packet.ReadObjectIDRev();
            int namelen = packet.ReadInt();
            string name = "";
            for (int i = 0; i < namelen; i++)
            {
                name += (char)packet.ReadByte();
            }
            packet.ReadInt(); packet.ReadInt();
            packet.ReadInt();

            uint CHARSPEC1 = packet.ReadUInt();
            byte CHARSPEC2 = (byte)packet.ReadByte();

            packet.ReadBytes(36);

            uint CHARSPECAPP1 = packet.ReadUInt();
            uint CHARSPECAPP2 = packet.ReadUInt();
            uint CHARSPECAPP3 = packet.ReadUInt();
            ushort CHARSPECAPP4 = packet.ReadUShort();

            packet.ReadByte(); // separator

            byte[] classBytes = packet.ReadBytes(8);
            Array.Reverse(classBytes);
            ulong classNodeRefId = BitConverter.ToUInt64(classBytes, 0);

            Console.WriteLine("----- Creating Character -----");
            Console.WriteLine("Name = " + name);
            Console.WriteLine("Class ID = " + classNodeRefId);
            Console.WriteLine("App1 = " + CHARSPECAPP1);
            Console.WriteLine("App2 = " + CHARSPECAPP2);
            Console.WriteLine("App3 = " + CHARSPECAPP3);
            Console.WriteLine("App4 = " + CHARSPECAPP4);

            /*byte[] known_offs = new byte[] { 84, 88, 91, 92, 95, 96, 100, 104, 107, 108, 112 };
            long originalPositon = packet.Position;
            byte[] thispkt = packet.ReadBytes((int)(packet.Length - packet.Position));
            packet.Position = originalPositon;

            if (lastpacket != null)
            {

                for (byte i = 0; i < thispkt.Length; i++)
                {
                    if (lastpacket[i] != thispkt[i] && !known_offs.Contains<byte>(i))
                        Console.WriteLine("Data differs at " + i + " : " + lastpacket[i] + " => " + thispkt[i]);
                }
            }

            lastpacket = thispkt;*/

            Character c = new Character()
            {
                //APP1 = CHARSPECAPP1,
                //APP2 = CHARSPECAPP2,
                //APP3 = CHARSPECAPP3,
                //APP4 = CHARSPECAPP4,
                AreaSpec = TORBusiness.Data.MapAreas.PCShip_XSFreighter,
                Class = (CharacterClass)classNodeRefId,
                Level = 44,
                Name = name,
                spec2 = CHARSPEC1,
                spec3 = CHARSPEC2,
            };

            packet.ReadBytes(78);
            packet.ReadByte();
            byte appDataCount = (byte)packet.ReadByte();
            c.Appearance = new Tuple<byte, byte>[appDataCount];
            packet.ReadByte();
            Console.WriteLine("appearance entries: " + appDataCount);
            for (int i = 0; i < appDataCount; i++)
            {
                byte[] data = packet.ReadBytes(4);
                c.Appearance[i] = new Tuple<byte, byte>(data[0], data[3]);
                Console.WriteLine("Appearance = " + data[3]);
            }

            Program.LastCreatedChar = c;

            connection.SendPacket(new SMsg_CharacterCreateResponse(id, name, 0x07));
        }
コード例 #5
0
ファイル: CharacterPackets.cs プロジェクト: Besyaka/swtor-emu
 void IClientPacket.ExecutePacket(AsyncConnection connection, ByteBuffer packet)
 {
     uint objid = packet.ReadObjectIDRev();
     packet.ReadByte();
     uint charid = packet.ReadUInt();
     TORLog.Info("CharacterSelectRequest@" + objid + " - " + charid);
     connection.SendPacket(new SMsg_CharacterSelectResponse(objid));
     connection.SendPacket(new SMsg_CharacterCurrentMap(objid, "ord_main", "4611686019802843831"));
     connection.SendPacket(new SMsg_CharacterAreaEnter(objid));
     connection.SendPacket(new SMsg_CharacterAreaServerSpec(objid, "ord_main", "4611686019802843831"));
 }
コード例 #6
0
        bool LoadPackage(ByteBuffer buffer, string packageSource, string assetNamePrefix)
        {
            if (buffer.ReadUint() != 0x46475549)
            {
                if (Application.isPlaying)
                {
                    throw new Exception("FairyGUI: old package format found in '" + packageSource + "'");
                }
                else
                {
                    Debug.LogWarning("FairyGUI: old package format found in '" + packageSource + "'");
                    return(false);
                }
            }

            buffer.version = buffer.ReadInt();
            buffer.ReadBool(); //compressed
            id   = buffer.ReadString();
            name = buffer.ReadString();
            if (_packageInstById.ContainsKey(id) && name != _packageInstById[id].name)
            {
                Debug.LogWarning("FairyGUI: Package id conflicts, '" + name + "' and '" + _packageInstById[id].name + "'");
                return(false);
            }
            buffer.Skip(20);
            int indexTablePos = buffer.position;
            int cnt;

            buffer.Seek(indexTablePos, 4);

            cnt = buffer.ReadInt();
            string[] stringTable = new string[cnt];
            for (int i = 0; i < cnt; i++)
            {
                stringTable[i] = buffer.ReadString();
            }
            buffer.stringTable = stringTable;

            buffer.Seek(indexTablePos, 1);

            PackageItem pi;

            if (assetNamePrefix == null)
            {
                assetNamePrefix = string.Empty;
            }
            else if (assetNamePrefix.Length > 0)
            {
                assetNamePrefix = assetNamePrefix + "_";
            }

            cnt = buffer.ReadShort();
            for (int i = 0; i < cnt; i++)
            {
                int nextPos = buffer.ReadInt();
                nextPos += buffer.position;

                pi       = new PackageItem();
                pi.owner = this;
                pi.type  = (PackageItemType)buffer.ReadByte();
                pi.id    = buffer.ReadS();
                pi.name  = buffer.ReadS();
                buffer.ReadS(); //path
                pi.file     = buffer.ReadS();
                pi.exported = buffer.ReadBool();
                pi.width    = buffer.ReadInt();
                pi.height   = buffer.ReadInt();

                switch (pi.type)
                {
                case PackageItemType.Image:
                {
                    pi.objectType = ObjectType.Image;
                    int scaleOption = buffer.ReadByte();
                    if (scaleOption == 1)
                    {
                        Rect rect = new Rect();
                        rect.x        = buffer.ReadInt();
                        rect.y        = buffer.ReadInt();
                        rect.width    = buffer.ReadInt();
                        rect.height   = buffer.ReadInt();
                        pi.scale9Grid = rect;

                        pi.tileGridIndice = buffer.ReadInt();
                    }
                    else if (scaleOption == 2)
                    {
                        pi.scaleByTile = true;
                    }

                    buffer.ReadBool();         //smoothing
                    break;
                }

                case PackageItemType.MovieClip:
                {
                    buffer.ReadBool();         //smoothing
                    pi.objectType = ObjectType.MovieClip;
                    pi.rawData    = buffer.ReadBuffer();
                    break;
                }

                case PackageItemType.Font:
                {
                    pi.rawData = buffer.ReadBuffer();
                    break;
                }

                case PackageItemType.Component:
                {
                    int extension = buffer.ReadByte();
                    if (extension > 0)
                    {
                        pi.objectType = (ObjectType)extension;
                    }
                    else
                    {
                        pi.objectType = ObjectType.Component;
                    }
                    pi.rawData = buffer.ReadBuffer();

                    UIObjectFactory.ResolvePackageItemExtension(pi);
                    break;
                }

                case PackageItemType.Atlas:
                case PackageItemType.Sound:
                case PackageItemType.Misc:
                {
                    pi.file = assetNamePrefix + pi.file;
                    break;
                }
                }
                _items.Add(pi);
                _itemsById[pi.id] = pi;
                if (pi.name != null)
                {
                    _itemsByName[pi.name] = pi;
                }

                buffer.position = nextPos;
            }

            buffer.Seek(indexTablePos, 2);

            cnt = buffer.ReadShort();
            for (int i = 0; i < cnt; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                string itemId = buffer.ReadS();
                pi = _itemsById[buffer.ReadS()];

                AtlasSprite sprite = new AtlasSprite();
                sprite.atlas       = pi;
                sprite.rect.x      = buffer.ReadInt();
                sprite.rect.y      = buffer.ReadInt();
                sprite.rect.width  = buffer.ReadInt();
                sprite.rect.height = buffer.ReadInt();
                sprite.rotated     = buffer.ReadBool();
                _sprites[itemId]   = sprite;

                buffer.position = nextPos;
            }

            if (buffer.Seek(indexTablePos, 3))
            {
                cnt = buffer.ReadShort();
                for (int i = 0; i < cnt; i++)
                {
                    int nextPos = buffer.ReadInt();
                    nextPos += buffer.position;

                    if (_itemsById.TryGetValue(buffer.ReadS(), out pi))
                    {
                        if (pi.type == PackageItemType.Image)
                        {
                            pi.pixelHitTestData = new PixelHitTestData();
                            pi.pixelHitTestData.Load(buffer);
                        }
                    }

                    buffer.position = nextPos;
                }
            }

            if (!Application.isPlaying)
            {
                _items.Sort(ComparePackageItem);
            }

            return(true);
        }
コード例 #7
0
        void LoadFont(PackageItem item)
        {
            BitmapFont font = new BitmapFont(item);

            item.bitmapFont = font;
            ByteBuffer buffer = item.rawData;

            buffer.Seek(0, 0);

            bool ttf = buffer.ReadBool();

            font.canTint    = buffer.ReadBool();
            font.resizable  = buffer.ReadBool();
            font.hasChannel = buffer.ReadBool();
            int fontSize   = buffer.ReadInt();
            int xadvance   = buffer.ReadInt();
            int lineHeight = buffer.ReadInt();

            float       texScaleX   = 1;
            float       texScaleY   = 1;
            NTexture    mainTexture = null;
            AtlasSprite mainSprite  = null;

            if (ttf && _sprites.TryGetValue(item.id, out mainSprite))
            {
                mainTexture = (NTexture)GetItemAsset(mainSprite.atlas);
                texScaleX   = mainTexture.root.uvRect.width / mainTexture.width;
                texScaleY   = mainTexture.root.uvRect.height / mainTexture.height;
            }

            buffer.Seek(0, 1);

            BitmapFont.BMGlyph bg;
            int cnt = buffer.ReadInt();

            for (int i = 0; i < cnt; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                bg = new BitmapFont.BMGlyph();
                char ch = buffer.ReadChar();
                font.AddChar(ch, bg);

                string img = buffer.ReadS();
                int    bx  = buffer.ReadInt();
                int    by  = buffer.ReadInt();
                bg.offsetX = buffer.ReadInt();
                bg.offsetY = buffer.ReadInt();
                bg.width   = buffer.ReadInt();
                bg.height  = buffer.ReadInt();
                bg.advance = buffer.ReadInt();
                bg.channel = buffer.ReadByte();
                if (bg.channel == 1)
                {
                    bg.channel = 3;
                }
                else if (bg.channel == 2)
                {
                    bg.channel = 2;
                }
                else if (bg.channel == 3)
                {
                    bg.channel = 1;
                }

                if (ttf)
                {
                    if (mainSprite.rotated)
                    {
                        bg.uv[0] = new Vector2((float)(by + bg.height + mainSprite.rect.x) * texScaleX,
                                               1 - (float)(mainSprite.rect.yMax - bx) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].x - (float)bg.height * texScaleX, bg.uv[0].y);
                        bg.uv[2] = new Vector2(bg.uv[1].x, bg.uv[0].y + (float)bg.width * texScaleY);
                        bg.uv[3] = new Vector2(bg.uv[0].x, bg.uv[2].y);
                    }
                    else
                    {
                        bg.uv[0] = new Vector2((float)(bx + mainSprite.rect.x) * texScaleX,
                                               1 - (float)(by + bg.height + mainSprite.rect.y) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].x, bg.uv[0].y + (float)bg.height * texScaleY);
                        bg.uv[2] = new Vector2(bg.uv[0].x + (float)bg.width * texScaleX, bg.uv[1].y);
                        bg.uv[3] = new Vector2(bg.uv[2].x, bg.uv[0].y);
                    }

                    bg.lineHeight = lineHeight;
                }
                else
                {
                    PackageItem charImg;
                    if (_itemsById.TryGetValue(img, out charImg))
                    {
                        GetItemAsset(charImg);
                        Rect uvRect = charImg.texture.uvRect;
                        bg.uv[0] = uvRect.position;
                        bg.uv[1] = new Vector2(uvRect.xMin, uvRect.yMax);
                        bg.uv[2] = new Vector2(uvRect.xMax, uvRect.yMax);
                        bg.uv[3] = new Vector2(uvRect.xMax, uvRect.yMin);
                        if (charImg.texture.rotated)
                        {
                            NGraphics.RotateUV(bg.uv, ref uvRect);
                        }
                        bg.width  = charImg.texture.width;
                        bg.height = charImg.texture.height;

                        if (mainTexture == null)
                        {
                            mainTexture = charImg.texture.root;
                        }
                    }

                    if (fontSize == 0)
                    {
                        fontSize = bg.height;
                    }

                    if (bg.advance == 0)
                    {
                        if (xadvance == 0)
                        {
                            bg.advance = bg.offsetX + bg.width;
                        }
                        else
                        {
                            bg.advance = xadvance;
                        }
                    }

                    bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
                    if (bg.lineHeight < font.size)
                    {
                        bg.lineHeight = font.size;
                    }
                }

                buffer.position = nextPos;
            }

            font.size        = fontSize;
            font.mainTexture = mainTexture;
            if (!font.hasChannel)
            {
                font.shader = ShaderConfig.imageShader;
            }
        }