Problème Deserialize

Inscrit
1 Avril 2016
Messages
20
Reactions
0
#1
Salut,

J'ai un problème le code est commenté avec l'erreur, je tente d'afficher les personnages qui entre la map avec le message GameRolePlayShowActorMessage, et quand j'arrive a la deserialization de EntityLook
C#:
class EntityLook
    {
        public const uint Id = 55;

        public uint bonesId;

        public uint[] skins;

        public int[] indexedColors;

        public int[] scales;

        public SubEntity[] subentities;

        public virtual uint TypeId
        {
            get
            {
                return 55;
            }
        }

        public EntityLook()
        {
        }

        public EntityLook(uint bonesId, uint[] skins, int[] indexedColors, int[] scales, SubEntity[] subentities)
        {
            this.bonesId = bonesId;
            this.skins = skins;
            this.indexedColors = indexedColors;
            this.scales = scales;
            this.subentities = subentities;
        }

        public virtual void Serialize(IDataWriter writer)
        {
            writer.WriteVarShort((short)this.bonesId);
            writer.WriteShort((short)this.skins.Length);
            for (uint i = 0; i < this.skins.Length; i++)
            {
                writer.WriteVarShort((short)this.skins[i]);
            }
            writer.WriteShort((short)this.indexedColors.Length);
            for (uint j = 0; j < this.indexedColors.Length; j++)
            {
                writer.WriteInt(this.indexedColors[j]);
            }
            writer.WriteShort((short)this.scales.Length);
            for (uint k = 0; k < this.scales.Length; k++)
            {
                writer.WriteVarShort((short)this.scales[k]);
            }
            writer.WriteShort((short)this.subentities.Length);
            for (uint l = 0; l < this.subentities.Length; l++)
            {
                SubEntity subEntity = this.subentities[l];
                subEntity.Serialize(writer);
            }
        }

        public virtual void Deserialize(IDataReader reader)
        {
            this.bonesId = reader.ReadVarUhShort();
            uint num = reader.ReadUShort();
            this.skins = new uint[num];
            for (uint i = 0; i < num; i++)
            {
//C'est ici que je reçois l'erreur, sa lit plusieurs fois mais apres sa cause l'erreur et sa me sort soit Too much Data (dans ReadVarShort) ou Impossible de lire au-delà de la fin du flux (dans ReadByte) Regarde en bas j'ai les méthodes concerné
                this.skins[i] = reader.ReadVarUhShort();
            }
            num = reader.ReadUShort();
            this.indexedColors = new int[num];
            for (uint j = 0; j < num; j++)
            {
                this.indexedColors[j] = reader.ReadInt();
            }
            num = reader.ReadUShort();
            this.scales = new int[num];
            for (uint k = 0; k < num; k++)
            {
                this.scales[k] = reader.ReadVarShort();
            }
            num = reader.ReadUShort();
            this.subentities = new SubEntity[num];
            for (uint l = 0; l < num; l++)
            {
                this.subentities[l] = new SubEntity();
                this.subentities[l].Deserialize(reader);
            }
        }
    }




LES METHODES AUQUEL JE RECOIT ERREUR ILS SONT DANS MON BIGENDIANREADER :
public byte ReadByte()
        {//ERREUR: Impossible de lire au-delà de la fin du flux
            return this.m_reader.ReadByte();
        }

public short ReadVarShort()
        {//ERREUR: Too much Data
            int num = 0;
            int i = 0;
            while (i < 16)
            {
                int num2 = (int)this.ReadByte();
                bool flag = (num2 & 128) == 128;
                bool flag2 = i > 0;
                if (flag2)
                {
                    num += (num2 & 127) << i;
                }
                else
                {
                    num += (num2 & 127);
                }
                i += 7;
                bool flag3 = !flag;
                if (flag3)
                {
                    bool flag4 = num > 32767;
                    if (flag4)
                    {
                        num -= 65536;
                    }
                    return (short)num;
                }
            }
            throw new Exception("Too much data");
        }

//Laquelle j'appelle dans EntityLook
public uint ReadVarUhShort()
        {
            return (uint)this.ReadVarShort();
        }
Merci d'avance
 
Dernière édition:

Arth

Contributeur
Inscrit
28 Aout 2016
Messages
80
Reactions
3
#2
Salut,
Je ne suis pas pro du C# (enfaîte je connais pas le C# :p) mais je te donne mon avis quand même:
Ton problème ne semble pas venir des portions de code que tu nous montre.
Parfois les erreurs sont en amont de ou l'on trouve les rapports d'erreur et elles ne pointent le bout de leur nez que lorsque que l'on manipule les données que l'on ne désire pas.

En gros je pense que tu devrait afficher les données qui entre dans ton Deserialize, voir si elles correspondent à ce que tu pourrait désirer (une analyse rapide à la mano). Du debug au printf quoi ^^. Sans ces données c'est difficile de dire l'erreur. Mais on peut faire des suppositions:
  • Ton parser de packet découpe mal les données. (mais c'est peu probable).
  • Ton deserialize de packet est incorrect (on ne l'as pas ici alors on sais jamais).
  • Ta methode ReadByte est tombé sur le byte EOF (End Of File) il a alors décider d’arrêter la lecture alors que ce n'est qu'une donné. (dépend du fonctionnement de ReadByte)
  • Plein d'autre chose...
 
Inscrit
1 Avril 2016
Messages
20
Reactions
0
#3
C'est vrai des fois des erreurs sa viens loin ^^

J'avais déjà afficher les données de EntityLook qui m'on parait bien mais la je vais affiche tout et je te montre les autres classes.

Dabord j'appelle GameRolePlayActorInformations depuis ma classe GameRolePlayShowActorMessage.

C#:
class GameRolePlayActorInformations : GameContextActorInformations
    {
        public new const uint Id = 141;

        public override uint TypeId
        {
            get
            {
                return 141;
            }
        }

        public GameRolePlayActorInformations()
        {
        }

        public GameRolePlayActorInformations(double contextualId, EntityLook look, EntityDispositionInformations disposition)
            : base(contextualId, look, disposition)
        {
        }

        public override void Serialize(IDataWriter writer)
        {
            base.Serialize(writer);
        }

        public override void Deserialize(IDataReader reader)
        {//on vois bien sa appel la base GameContextActorInformations
            base.Deserialize(reader);
        }
    }
C#:
class GameContextActorInformations
    {
        public const uint Id = 150;

        public double contextualId;

        public EntityLook look;

        public EntityDispositionInformations disposition;

        public virtual uint TypeId
        {
            get
            {
                return 150;
            }
        }

        public GameContextActorInformations()
        {
        }

        public GameContextActorInformations(double contextualId, EntityLook look, EntityDispositionInformations disposition)
        {
            this.contextualId = contextualId;
            this.look = look;
            this.disposition = disposition;
        }

        public virtual void Serialize(IDataWriter writer)
        {
            writer.WriteDouble(this.contextualId);
            this.look.Serialize(writer);
            writer.WriteShort((short)this.disposition.TypeId);
            this.disposition.Serialize(writer);
        }

        public virtual void Deserialize(IDataReader reader)
        {
            this.contextualId = reader.ReadDouble();
            Log("contextualId : " + this.contextualId);
            this.look = new EntityLook();
            this.look.Deserialize(reader);//ON APPELLE LE DESERIALIZE DE ENTITYLOOK
            this.disposition = (EntityDispositionInformations)ProtocolTypeManager.GetInstance(EntityDispositionInformations.Id);
            this.disposition.Deserialize(reader);
        }
    }
Voila les logs :
contextualId : 5,63483157703801E-308
bonesId : 32 (qui change biensur depend de qui entre map)
num : 256
et voila Skins :
SKINS : 2
SKINS : 91
SKINS : 2148
SKINS : 0
SKINS : 5
SKINS : 1
SKINS : 1630719
SKINS : 2
SKINS : 14945
SKINS : 16
SKINS : 3
SKINS : 123
SKINS : 121
SKINS : 0
SKINS : 4
SKINS : 14678
SKINS : 7
SKINS : 5
SKINS : 106
SKINS : 65
SKINS : 6
SKINS : 0
SKINS : 1
SKINS : 135
SKINS : 0
SKINS : 2
SKINS : 91
SKINS : 2148
SKINS : 0
SKINS : 5
SKINS : 1
SKINS : 1630719
SKINS : 2
SKINS : 14945
SKINS : 16
SKINS : 3
SKINS : 123
SKINS : 121
SKINS : 0
SKINS : 4
SKINS : 14678
SKINS : 7
SKINS : 5
SKINS : 106
SKINS : 65
SKINS : 6
SKINS : 0
SKINS : 1
SKINS : 135
SKINS : 0
SKINS : 0
SKINS : 0
SKINS : 60
SKINS : 0
SKINS : 19
SKINS : 2
SKINS : 0
SKINS : 8
SKINS : 83
SKINS : 120
SKINS : 45
SKINS : 84
SKINS : 101
SKINS : 108
SKINS : 108
SKINS : 97
SKINS : 0
SKINS : 29
SKINS : 8
SKINS : 0
SKINS : 1
SKINS : 0
SKINS : 0
SKINS : 5
SKINS : 46335
SKINS : 0
SKINS : 0
SKINS : 0
SKINS : 66
SKINS : 97
SKINS : 2530
SKINS : 544
SKINS : 0
SKINS : 0
Une exception de première chance de type 'System.IO.EndOfStreamException' s'est produite dans mscorlib.dll
Une exception non gérée du type 'System.IO.EndOfStreamException' s'est produite dans mscorlib.dll
Informations supplémentaires : Impossible de lire au-delà de la fin du flux.
SKINS : 0
SKINS : 0
SKINS : 60
SKINS : 0
SKINS : 19
SKINS : 2
SKINS : 0
SKINS : 8
SKINS : 83
SKINS : 120
SKINS : 45
SKINS : 84
SKINS : 101
SKINS : 108
SKINS : 108
SKINS : 97
SKINS : 0
SKINS : 29
SKINS : 8
SKINS : 0
SKINS : 1
SKINS : 0
SKINS : 0
SKINS : 5
SKINS : 46335
SKINS : 0
SKINS : 0
SKINS : 0
SKINS : 66
SKINS : 97
SKINS : 2530
SKINS : 544
SKINS : 0
SKINS : 0

Des fois commeça Skins (sa change c normal) :
SKINS : 2
SKINS : 90
SKINS : 2140
SKINS : 0
SKINS : 5
SKINS : 1
SKINS : 1631359
SKINS : 2
SKINS : 14561
SKINS : 14
SKINS : 3
SKINS : 88
SKINS : 100
SKINS : 0
SKINS : 4
SKINS : 89
SKINS : 51
SKINS : 16
SKINS : 5
SKINS : 183034
SKINS : 0
SKINS : 1
SKINS : 140
SKINS : 0
SKINS : 0
SKINS : 0
SKINS : 60
SKINS : 1
SKINS : 126
SKINS : 1
SKINS : 0
SKINS : 10
SKINS : 69
SKINS : 103
SKINS : 97
SKINS : 110
SKINS : 101
SKINS : 45
SKINS : 82
SKINS : 111
SKINS : 120
SKINS : 111
SKINS : 0
SKINS : 29
SKINS : 8
SKINS : 0
SKINS : 0
SKINS : 0
SKINS : 0
SKINS : 5
SKINS : 1335806
SKINS : 0
SKINS : 0
SKINS : 0
SKINS : 66
SKINS : 103
SKINS : 3144
SKINS : 640
SKINS : 0
SKINS : 0
Une exception de première chance de type 'System.IO.EndOfStreamException' s'est produite dans mscorlib.dll
Une exception non gérée du type 'System.IO.EndOfStreamException' s'est produite dans mscorlib.dll
Informations supplémentaires : Impossible de lire au-delà de la fin du flux.
 
Dernière édition:

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
150
#4
Ton code m'a l'air correct, tes IO sont à jour ?
 
Inscrit
1 Avril 2016
Messages
20
Reactions
0
#5
J'utilise tes IO https://github.com/BlueDream4/Dofus-2.27-IO
Mais si le problème venait de là, ça veut dire il devrai pas lire du tout ? car je vois bien il lis this.bonesId = reader.ReadVarUhShort(); et meme this.skins = reader.ReadVarUhShort(); mais il sort l'erreur aléatoirement ici
 
Dernière édition par un modérateur:
Inscrit
18 Février 2015
Messages
228
Reactions
7
#6
C'est sûrement avant tu lis quelques chose en trop dans ton message GameRolePlayShowActorMessage revois la structure du message
 
Inscrit
1 Avril 2016
Messages
20
Reactions
0
#7
le voila GameRolePlayShowActorMessage
C#:
class GameRolePlayShowActorMessage : NetworkMessage
    {
        public const uint Id = 5632;

        public GameRolePlayActorInformations informations;

        public override uint MessageId
        {
            get
            {
                return 5632;
            }
        }

        public GameRolePlayShowActorMessage()
        {
        }

        public GameRolePlayShowActorMessage(GameRolePlayActorInformations informations)
        {
            this.informations = informations;
        }

        public override void Serialize(IDataWriter writer)
        {
            writer.WriteShort((short)this.informations.TypeId);
            this.informations.Serialize(writer);
        }

        public override void Deserialize(IDataReader reader)
        {
            this.informations = (GameRolePlayActorInformations)ProtocolTypeManager.GetInstance(GameRolePlayActorInformations.Id);
            this.informations.Deserialize(reader);
        }
    }
 

Arth

Contributeur
Inscrit
28 Aout 2016
Messages
80
Reactions
3
#8
Bah ... dans ton serialize tu captures une variable short en premier, et dans ton deserialize tu ne le fait pas.
Je te fait remarquer que si tu avais analysé à la main ce packet (car il te pose problème) tu aurais vite vu l'erreur, mais bon ;).

D'ailleur ton code semble être erroné, si on regarde les sources du client, ton GetInstance ne prend pas en paramètre GameRolePlayActorInformations.Id, mais l'id que tu doit capturer avant.

Code:
public function deserializeAs_GameRolePlayShowActorMessage(param1:ICustomDataInput) : void
      {
         var _loc2_:uint = param1.readUnsignedShort();
         this.informations = ProtocolTypeManager.getInstance(GameRolePlayActorInformations,_loc2_);
         this.informations.deserialize(param1);
      }
 
Inscrit
1 Avril 2016
Messages
20
Reactions
0
#9
Merci, j'avais pas fait attention a var _loc2_:uint = param1.readUnsignedShort(); même si j'ai analysé a la main, j'ai traduit plusieurs paquets a la main c'est pour ça j'ai pas fait attention a cause de la fatigue ^^

Oui c'est vrai, fallait j'appel GetInstance de ProtocolTypeManager par l'id que j'ai capturer : _loc2_, car pour Deserializer sa utilise GameRolePlayCharacterInformations.
 
Dernière édition:
Inscrit
1 Avril 2016
Messages
20
Reactions
0
#10
J'utilise pas Tree Expressions dans mon ProtocolTypeManager mais j'utilise un dictionnaire chaque id avec son instance et je crée l'instance par l'id
 
Haut Bas