C# Packets Bizarres!

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#1
Bonsoir à tous,
Je remarque qu'il y a des packets "bizarre" que je n'arrive pas à implementer.

Je m'explique, normalement dans les sources du jeu il est dis quel type nous devons instancier, hors je m'apercois que ça peut varier.
En effet, dans le MapComplementaryInformationsDataMessage nous devons sois disant avoir une liste de InteractiveElement hors je vois en faisant ça :

C#:
for (interactiveElementsIndex = 0; (interactiveElementsIndex < interactiveElementsCount); interactiveElementsIndex = (interactiveElementsIndex + 1))
            {
                short protocol = (short)reader.ReadUShort();
                Console.WriteLine("*************************** " + protocol + " ***************************");
                if ((TypeEnum)protocol == TypeEnum.InteractiveElement)
                {
                    InteractiveElement objectToAdd = ProtocolTypeManager.GetInstance<InteractiveElement>(protocol);
                    objectToAdd.Deserialize(reader);
                    m_interactiveElements.Add(objectToAdd);
                }
                else if ((TypeEnum)protocol == TypeEnum.InteractiveElementWithAgeBonus)
                {
                    InteractiveElementWithAgeBonus tmp = ProtocolTypeManager.GetInstance<InteractiveElementWithAgeBonus>(protocol);
                    tmp.Deserialize(reader);
                    m_interactiveElements.Add(new InteractiveElement(tmp.EnabledSkills, tmp.DisabledSkills, tmp.ElementId, tmp.ElementTypeId, tmp.OnCurrentMap));
                }
            }
Que parfois il me recupere le TypeID du InteractiveElement, mais parfois du InteractiveElementWithAgeBonus.... j'ai essayer cette implementation, mais ça ne veut pas marcher quand je recois le MapComplementaryInformationsDataInHouseMessage par exemple... je ne sais pas pourquoi....

Merci
 
Inscrit
6 Octobre 2015
Messages
38
Reactions
0
#2
Salut, c'est pareil pour les acteurs qui peuvent contenir des GameRolePlayCharacterInformations ou des GameRolePlayMerchantInformations par exemple, qui hérite tout deux de GameRolePlayActorInformations
les serialize/derialize doivent être donc fait en tant que GameRolePlayCharacterInformations ou GameRolePlayMerchantInformations et non GameRolePlayActorInformations
 

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#3
Bizzare.... tu pourrais me montrer ton MapComplementaryInformationsDataMessage et ton FriendsList et FriendUpdate alors s'il te plait? merci
 
Inscrit
15 Aout 2016
Messages
20
Reactions
0
#4
C'est de l'héritage.
Prenons l'exemple concernant les élements interactifs :
Code:
         var _loc6_:uint = param1.readUnsignedShort();
         var _loc7_:uint = 0;
         while(_loc7_ < _loc6_)
         {
            _loc18_ = param1.readUnsignedShort();
            _loc19_ = ProtocolTypeManager.getInstance(InteractiveElement,_loc18_);
            _loc19_.deserialize(param1);
            this.interactiveElements.push(_loc19_);
            _loc7_++;
         }
Dans la boucle while, on lit un ushort, qui correspond au type de l'élement. Il nous permet de récupérer le bon type en questionnant le ProtocolTypeManager. Le type récupéré doit donc être un enfant du type de base (ici InteractiveElement)

Ensuite, on appelle la méthode Deserialize (car si tu appeles DeserializeAs_InteractiveElement, l'héritage ne fonctionnera pas).
 

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#5
Ahhhh je vois du coup le problème c'est mon ProtocolTypeManager.... je pourrais voir comment tu as fait le tient please? dicord si tu veux au pire : yovano_c#4592
 
Inscrit
15 Aout 2016
Messages
20
Reactions
0
#6
Grâce à la réflection, je récupère tout les types qui contiennent l'interface INetworkType, puis je les met dans un Dictionary<int, Type> (int pour l'id du type).

Tu peux optimiser un peu plus en faisant un Dictionary<int, Func<object>>, où la Func retournera le type instancié. Il ne te restera plus qu'a le cast selon le type désiré
 

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#7
Mais c'est ce que je fais lol :o avec le Func et tout pourtant :o ajoute moi discord please qu'on s'appelle...
 

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#8
Du coup tu le cast comment ? deja est-ce que mes If sont bons ???
C#:
short protocol = (short)reader.ReadUShort();
                Console.WriteLine("************* FriendsList ************** " + protocol + " ***************************");
                if ((TypeEnum)protocol == TypeEnum.FriendInformations)
                {
                    FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendInformations>((short)reader.ReadUShort());
                    objectToAdd.Deserialize(reader);
                    m_friendsList.Add(objectToAdd);
                }
                else if ((TypeEnum)protocol == TypeEnum.FriendOnlineInformations)
                {
                    FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendOnlineInformations>((short)reader.ReadUShort());
                    objectToAdd.Deserialize(reader);
                    m_friendsList.Add(objectToAdd);
                }
                else
                {
                    FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendInformations>((short)reader.ReadUShort());
                    objectToAdd.Deserialize(reader);
                    m_friendsList.Add(objectToAdd);
                }

Ensuite comme tu vois, je cast comme ça, mais est-ce que c'est bon??? :

C#:
FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendOnlineInformations>((short)reader.ReadUShort());
 
Inscrit
15 Aout 2016
Messages
20
Reactions
0
#9
Montre le code de ton ProtocolTypeManager
 

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#10
C#:
using DofusBot.Utilities.Reflection;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;

namespace DofusBot.Protocol
{
    public static class ProtocolTypeManager
    {

        private static readonly Dictionary<short, Type> types = new Dictionary<short, Type>(200);
        private static readonly Dictionary<short, Func<object>> typesConstructors = new Dictionary<short, Func<object>>(200);
        public static void Initialize()
        {
            Assembly asm = Assembly.GetAssembly(typeof(ProtocolTypeManager));

            foreach (Type type in asm.GetTypes())
            {
                if (type.Namespace == null || !type.Namespace.Contains("Protocol.Network.Types"))
                    continue;

                FieldInfo field = type.GetField("ProtocolId");

                if (field != null)
                {
                    short id = (short)(int)(field.GetValue(type));

                    types.Add(id, type);

                    ConstructorInfo ctor = type.GetConstructor(Type.EmptyTypes);

                    if (ctor == null)
                        throw new System.Exception(string.Format("'{0}' doesn't implemented a parameterless constructor", type));

                    typesConstructors.Add(id, ctor.CreateDelegate<Func<object>>());
                }
            }

            Console.WriteLine(string.Format("<{0}> type(s) loaded.", types.Count));
        }

        public static T GetInstance<T>(short id) where T : class
        {
            if (!types.ContainsKey(id))
            {
                Console.WriteLine(string.Format("Type <id:{0}> doesn't exist", id));
            }

            return typesConstructors[id]() as T;
        }

        [Serializable]
        public class ProtocolTypeNotFoundException : System.Exception
        {
            public ProtocolTypeNotFoundException()
            {
            }

            public ProtocolTypeNotFoundException(string message)
                : base(message)
            {
            }

            public ProtocolTypeNotFoundException(string message, System.Exception inner)
                : base(message, inner)
            {
            }

            protected ProtocolTypeNotFoundException(
                SerializationInfo info,
                StreamingContext context)
                : base(info, context)
            {
            }
        }

    }
}
 
Inscrit
15 Aout 2016
Messages
20
Reactions
0
#11
Du coup tu le cast comment ? deja est-ce que mes If sont bons ???
C#:
short protocol = (short)reader.ReadUShort();
                Console.WriteLine("************* FriendsList ************** " + protocol + " ***************************");
                if ((TypeEnum)protocol == TypeEnum.FriendInformations)
                {
                    FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendInformations>((short)reader.ReadUShort());
                    objectToAdd.Deserialize(reader);
                    m_friendsList.Add(objectToAdd);
                }
                else if ((TypeEnum)protocol == TypeEnum.FriendOnlineInformations)
                {
                    FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendOnlineInformations>((short)reader.ReadUShort());
                    objectToAdd.Deserialize(reader);
                    m_friendsList.Add(objectToAdd);
                }
                else
                {
                    FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendInformations>((short)reader.ReadUShort());
                    objectToAdd.Deserialize(reader);
                    m_friendsList.Add(objectToAdd);
                }

Ensuite comme tu vois, je cast comme ça, mais est-ce que c'est bon??? :

C#:
FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendOnlineInformations>((short)reader.ReadUShort());
Tu ne dois pas gérer le cas par type. Ton code doit plutôt ressembler à ça :
Code:
FriendInformations objectToAdd = ProtocolTypeManager.GetInstance<FriendInformations>((short)reader.ReadUShort());
objectToAdd.Deserialize(reader);
this.m_friendsList.Add(objectToAdd);
 

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#12
Ok bon bah mon probleme viens pas de là alors... tu peux dl mon projet et look please ?....
J'ai ces 4 packets qui ne fonctionne pas juste (pour l'instant en tout cas.. j'en ai ps vu d'autre) et je ne sais pas d'ou ça peut venir alors..pour moi les packets sont bon.. ça dois etre les types qui sont implementer dans ces messages....:

- FriendsListMessage
- FriendUpdateMessage
- MapComplementaryInformationsDataMessage
- GameRolePlayShowActorMessage

https://mega.nz/#!JTAVSarQ!AkuYI2rti4zuhMihMICPlAOJokIjYU17doeluppVgf8
 

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#13
AH oui change le DofusPath dans le Main_Load pour ton chemin dofus aussi :3
 
Inscrit
5 Mai 2017
Messages
3
Reactions
0
#14
Yovano,

Certaines classes de votre projet sont la lecture des types de données dans les mauvaises positions. Probablement votre protocolbuilder l'a fait sans le vouloir. La mise en œuvre de la deserialize de classe doit être simple et passer ProtocolId pour GetInstance le ProtocolTypeManager et il résoudra le constructeur à appeler, ainsi que le type. Le problème est à la lecture des paquets de InteractiveElement enfants.

Câlins.
 

DevChris

Membre Actif
Inscrit
12 Avril 2017
Messages
138
Reactions
24
#15
Speak english please Gustavo your french is bad. So, I know that some things are misplaced. But I don't see them.... you can tell me where they are?
 
Haut Bas