public void ReadFields(IPacket packet, IFieldReader reader) { IDynamicPacket dynamicPacket = packet as IDynamicPacket; if (dynamicPacket != null) { dynamicPacket.DynamicTypeName = m_DynamicTypeName; } ReadFields(packet.GetType(), packet, reader); }
private bool LoadCSV() { string fullPath = ResourceManager.GetFullPath(m_DataFile.ToLower(), false); bool result; if (!File.Exists(fullPath)) { result = false; } else { FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read); BinaryReader binaryReader = new BinaryReader(fileStream); //读取是不是csv的文件,如果是的话,就加载。防止被别人修改数据 if (binaryReader.ReadString() != "chenfuling") { binaryReader.Close(); fileStream.Close(); result = false; } else { //先读取所有数据的总大小,然后读取byte[]数据 IDynamicPacket dynamicPacket = DynamicPacket.Create(binaryReader.ReadBytes(binaryReader.ReadInt32())); //在byte[]数据里面,先读取多少份不同类型的数据 int num = dynamicPacket.ReadInt32(); int i = 0; while (i < num) { //读取这份类型数据的总大小 int size = dynamicPacket.ReadInt32(); //根据大小读取这份数据byte[] IDynamicPacket subPacket = DynamicPacket.Create(dynamicPacket.ReadBytes(size)); //读取出这份类型的数据类型字符串 string type = subPacket.ReadString(); //根据类型,解析出数据 switch (type) { case "table\\map\\maplist.csv": //根据ushort的数量大小,再解析出List<T>数据 //DataMaplistManager.Instance.Deserialize(subPacket); break; } i++; } binaryReader.Close(); fileStream.Close(); result = true; } } return(result); }
public void Deserialize(IDynamicPacket packet) { this.ID = packet.ReadInt32(); this.Name = packet.ReadString(); this.MapType = packet.ReadInt32(); this.MapFile = packet.ReadString(); this.MapFilePath = packet.ReadString(); this.DeathMatch_OMG = packet.ReadInt32(); this.PicFile = packet.ReadString(); this.ShopFile = packet.ReadString(); this.PCBgSoundFile = packet.ReadString(); this.PCWarnSoundFile = packet.ReadString(); this.PCToughSoundFile = packet.ReadString(); this.PCNormalSoundFile = packet.ReadString(); this.UnPCBgSoundFile = packet.ReadString(); this.UnPCWarnSoundFile = packet.ReadString(); this.UnPCToughSoundFile = packet.ReadString(); this.UnPCNormalSoundFile = packet.ReadString(); this.LCameraPos = packet.ReadString(); this.LCameraAngle = packet.ReadString(); this.ECameraPos = packet.ReadString(); this.ECameraAngle = packet.ReadString(); this.MapCenterX = packet.ReadFloat(); this.MapCenterY = packet.ReadFloat(); this.MaxX = packet.ReadFloat(); this.MaxY = packet.ReadFloat(); this.MinCameraScale = packet.ReadFloat(); this.MaxCameraScale = packet.ReadFloat(); this.MouseWheelSensitivity = packet.ReadFloat(); this.LeagueBaseDeadEft = packet.ReadInt32(); this.EmpireBaseDeadEft = packet.ReadInt32(); this.MineBaseDeadEft = packet.ReadInt32(); this.TheirBaseDeadEft = packet.ReadInt32(); this.LeagueAttackedEffect = packet.ReadInt32(); this.EmpireAttackedEffect = packet.ReadInt32(); this.LeagueEffectWhenHeroDead = packet.ReadInt32(); this.EmpireEffectWhenHeroDead = packet.ReadInt32(); this.LeagueHighHpEffect = packet.ReadInt32(); this.EmpireHighHpEffect = packet.ReadInt32(); this.LeagueLowHpEffect = packet.ReadInt32(); this.EmpireLowHpEffect = packet.ReadInt32(); this.EmpireBasePos = packet.ReadString(); this.LeagueBasePos = packet.ReadString(); this.ComPos = packet.ReadString(); this.ComSmallPos = packet.ReadString(); }
public void Serialize(IDynamicPacket packet) { packet.Write(this.ID); packet.Write(this.Name); packet.Write(this.MapType); packet.Write(this.MapFile); packet.Write(this.MapFilePath); packet.Write(this.DeathMatch_OMG); packet.Write(this.PicFile); packet.Write(this.ShopFile); packet.Write(this.PCBgSoundFile); packet.Write(this.PCWarnSoundFile); packet.Write(this.PCToughSoundFile); packet.Write(this.PCNormalSoundFile); packet.Write(this.UnPCBgSoundFile); packet.Write(this.UnPCWarnSoundFile); packet.Write(this.UnPCToughSoundFile); packet.Write(this.UnPCNormalSoundFile); packet.Write(this.LCameraPos); packet.Write(this.LCameraAngle); packet.Write(this.ECameraPos); packet.Write(this.ECameraAngle); packet.Write(this.MapCenterX); packet.Write(this.MapCenterY); packet.Write(this.MaxX); packet.Write(this.MaxY); packet.Write(this.MinCameraScale); packet.Write(this.MaxCameraScale); packet.Write(this.MouseWheelSensitivity); packet.Write(this.LeagueBaseDeadEft); packet.Write(this.EmpireBaseDeadEft); packet.Write(this.MineBaseDeadEft); packet.Write(this.TheirBaseDeadEft); packet.Write(this.LeagueAttackedEffect); packet.Write(this.EmpireAttackedEffect); packet.Write(this.LeagueEffectWhenHeroDead); packet.Write(this.EmpireEffectWhenHeroDead); packet.Write(this.LeagueHighHpEffect); packet.Write(this.EmpireHighHpEffect); packet.Write(this.LeagueLowHpEffect); packet.Write(this.EmpireLowHpEffect); packet.Write(this.EmpireBasePos); packet.Write(this.LeagueBasePos); packet.Write(this.ComPos); packet.Write(this.ComSmallPos); }
void Start() { StringFileReader sfr = new StringFileReader(); FileStream fs = new FileStream("F://chenfuling/龙翼编年史/龙翼编年史/bin/" + path, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); Debug.Log(br.ReadString()); Debug.Log(br.ReadUInt32()); int a = br.ReadInt32(); Debug.Log(a); byte[] a1 = br.ReadBytes(a); IDynamicPacket packet = DynamicPacket.Create(a1); int num = packet.ReadInt32(); Debug.Log(num); int i = 0; while (i < num) { int count = packet.ReadInt32(); Debug.Log("count:" + count); IDynamicPacket packet2 = DynamicPacket.Create(packet.ReadBytes(count)); string text = packet2.ReadString(); switch (text) { case "table\\herolist.csv": //DataBeastlistManager.Instance.Deserialize(packet2); //DataHerolistManager.Instance.CorrectString(reader); // Debug.Log(DataBeastlistManager.Instance.DataList[0].StrategyDesc); break; case "table\\map\\maplist.csv": DataMaplistManager.Instance.Deserialize(packet2); break; } i++; } }
public void Deserialize(IDynamicPacket packet) { this.dataList = packet.ReadList <DataMaplist1>(); }
public void Serialize(IDynamicPacket packet) { packet.Write <DataMaplist1>(this.dataList); }
public void Deserialize(IDynamicPacket packet) { }
public void Serialize(IDynamicPacket packet) { packet.Write <TaskMain>(this.mainList); }
/// <summary> /// Create a PacketDefinition describing the fields and serialization version information for the /// IPacket object passed by the caller. /// </summary> /// <param name="packet">IPacket object to generate a PacketDefinition for</param> /// <returns>PacketDefinition describing fields to be serialized, including nested types</returns> public static PacketDefinition CreatePacketDefinition(IPacket packet) { // These flags are used in the GetMethod call below. The key flag is DeclaredOnly // which is needed because we want to support object hierarchies that implement // IPacket at multiple levels. We accomplish this by called GetPacketDefinition // at each level in the hierarchy that implements IPacket. const BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic; // We iterate from the type we are passed down object hierarchy looking for // IPacket implementations. Then, on the way back up, we link together // the m_BasePacket fields to that the PacketDefinition we return includes // a description of all the nested types. Stack <PacketDefinition> stack = new Stack <PacketDefinition>(); Type type = packet.GetType(); // walk down the hierarchy till we get to a base object that no longer implements IPacket while (typeof(IPacket).IsAssignableFrom(type)) { // We push one PacketDefinition on the stack for each level in the hierarchy PacketDefinition definition; // Even though the current type implements IPacket, it may not have a GetPacketDefinition at this level MethodInfo method = GetIPacketMethod(type, "GetPacketDefinition", flags, Type.EmptyTypes); if (method != null) { definition = (PacketDefinition)method.Invoke(packet, new object[0]); definition.m_WriteMethod = GetIPacketMethod(type, "WriteFields", flags, new Type[] { typeof(PacketDefinition), typeof(SerializedPacket) }); if (definition.m_WriteMethod == null) { throw new GibraltarSerializationException("The current packet implements part but not all of the IPacket interface. No Write Method could be found. Did you implement IPacket explicitly?"); } if (definition.CanHaveRequiredPackets) { definition.m_GetRequiredPacketsMethod = GetIPacketMethod(type, "GetRequiredPackets", flags, Type.EmptyTypes); if (definition.m_GetRequiredPacketsMethod == null) { throw new GibraltarSerializationException("The current packet implements part but not all of the IPacket interface. No GetRequiredPackets Method could be found. Did you implement IPacket explicitly?"); } } } else { // If GetPacketDefinition isn't defined at this level, // push an empty PacketDefinition on the stack as a placeholder definition = new PacketDefinition(type.Name, -1, false); } // Push the PacketDefinition for this level on the stack // then iterate down to the next deeper level in the object hierarchy stack.Push(definition); type = type.GetTypeInfo().BaseType; } // At this point the top of the stack contains the mostly deeply nested base type. // While there are 2 or more elements on the stack, the deeper of the two // should reference the top element as a base type while (stack.Count >= 2) { // Pop off the deepest base type still in the stack PacketDefinition basePacket = stack.Pop(); // The next element is now visible, so let's peek at it PacketDefinition derivedPacket = stack.Peek(); // link the base type with its derived class derivedPacket.m_BasePacket = basePacket; } // At this point there should be exactly one element in the stack // which contains the return value for this method. PacketDefinition packetDefinition = stack.Pop(); // Check if this is a DynamicPacket. If so, it should have a unique dynamic type. // If the DynamicType field has not been assigned, assign a unique string. IDynamicPacket dynamicPacket = packet as IDynamicPacket; if (dynamicPacket != null) { if (dynamicPacket.DynamicTypeName == null) { dynamicPacket.DynamicTypeName = Guid.NewGuid().ToString(); } packetDefinition.m_DynamicTypeName = dynamicPacket.DynamicTypeName; } // Record whether or not this is a cachable packet. packetDefinition.m_IsCachable = packet is ICachedPacket; return(packetDefinition); }
public void Serialize(IDynamicPacket packet) { packet.Write(this.ID); }