Exemplo n.º 1
0
        public  void ReadAndSendMap()
        {
            ActorDB.Init();
            //LoadMapChunkDatabase();

            string filePath = D3Sharp.Net.Game.Config.Instance.Map;
            string line, line2;

            //avarage = double.Parse("0.0", NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);

            bool versiondetermined = false;
            int version = 0;

            if (File.Exists(filePath))
            {
                StreamReader file = null;
                try
                {

                    System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(@"\s+");

                    file = new StreamReader(filePath);
                    while ((line = file.ReadLine()) != null)
                    {
                        line = rx.Replace(line, @" ");
                        string[] data = line.Split(' ');

                        if (!versiondetermined)
                            if (data.Length > 0)
                                if (data[0].Equals("v"))
                                {
                                    version = int.Parse(data[1]);
                                    Logger.Info("Map file version: " + version);
                                }
                                else
                                {
                                    //reveal world here if fallback - updated map files have world reveal data
                                    #region Interstitial,RevealWorld,WorldStatus,EnterWorld
                                    Game.SendMessage(new RevealWorldMessage()
                                    {
                                        Id = 0x0037,
                                        Field0 = WorldID,
                                        Field1 = 0x000115EE,
                                    });

                                    Game.SendMessage(new EnterWorldMessage()
                                    {
                                        Id = 0x0033,
                                        Field0 = new Vector3D() { Field0 = 3143.75f, Field1 = 2828.75f, Field2 = 59.07559f },
                                        Field1 = WorldID,
                                        Field2 = 0x000115EE,
                                    });
                                    #endregion
                                }
                        versiondetermined = true;

                        if (version == 0)
                        {
                            //fallback to the original version of the text files because people WILL mix them with the new :(

                            if ((line2 = file.ReadLine()) != null)
                            {
                                string[] data2 = line2.Split(' ');

                                RevealSceneMessage r = new RevealSceneMessage(data, WorldID);
                                MapRevealSceneMessage r2 = new MapRevealSceneMessage(data2, WorldID);

                                posx = (r.SceneSpec.tCachedValues.Field3.Field0.Field0 + r.SceneSpec.tCachedValues.Field3.Field1.Field0) / 2.0f + r.Position.Field1.Field0;
                                posy = (r.SceneSpec.tCachedValues.Field3.Field0.Field1 + r.SceneSpec.tCachedValues.Field3.Field1.Field1) / 2.0f + r.Position.Field1.Field1;
                                posz = (r.SceneSpec.tCachedValues.Field3.Field0.Field2 + r.SceneSpec.tCachedValues.Field3.Field1.Field2) / 2.0f + r.Position.Field1.Field2;

                                Game.SendMessage(r);
                                Game.SendMessage(r2);
                            }
                        }
                        else
                            if (data.Length >= 1) //check only lines with data in them
                            {
                                //packet data
                                if (data[0].Equals("p") && data.Length >= 2)
                                {
                                    int packettype = int.Parse(data[1]);
                                    switch (packettype)
                                    {
                                        case 0x34: //revealscenemessage
                                            if (int.Parse(data[56]) == -1)
                                                Game.SendMessage(new RevealSceneMessage(data.Skip(2).ToArray(), WorldID));
                                            break;
                                        case 0x33: //enterworldmessage
                                            WorldID = int.Parse(data[5]);
                                            Game.SendMessage(new EnterWorldMessage()
                                            {
                                                Id = 0x0033,
                                                Field0 = new Vector3D()
                                                {
                                                    Field0 = float.Parse(data[2], System.Globalization.CultureInfo.InvariantCulture),
                                                    Field1 = float.Parse(data[3], System.Globalization.CultureInfo.InvariantCulture),
                                                    Field2 = float.Parse(data[4], System.Globalization.CultureInfo.InvariantCulture)
                                                },
                                                Field1 = WorldID,
                                                Field2 = int.Parse(data[6]),
                                            });
                                            break;
                                        case 0x37: //revealworldmessage
                                            Game.SendMessage(new RevealWorldMessage()
                                            {
                                                Id = 0x0037,
                                                Field0 = int.Parse(data[2]),
                                                Field1 = int.Parse(data[3]),
                                            });
                                            break;
                                        case 0x3b: //acdenterknownmessage
                                            {
                                                ACDEnterKnownMessage wm = new ACDEnterKnownMessage(data.Skip(2).ToArray(), WorldID);
                                                if (!ActorDB.isBlackListed(wm.Field1))
                                                {
                                                    Game.SendMessage(wm);
                                                    Logger.Info(String.Format("{0,7}", wm.Field1) + ": " + ActorDB.GetActorName(wm.Field1));
                                                    if (ActorDB.isNPC(wm.Field1))
                                                    {
                                                        //SEND NPC DATA HERE
                                                        CreateNPC(wm.Field0);
                                                    }
                                                    Game.FlushOutgoingBuffer();
                                                }
                                            }
                                            break;
                                        case 0x44: //maprevealscenemessage
                                            Game.SendMessage(new MapRevealSceneMessage(data.Skip(2).ToArray(), WorldID));
                                            break;
                                        default:
                                            Logger.Error("Unimplemented packet type encountered in map file: " + packettype);
                                            break;
                                    }
                                }

                                //spawn point
                                if (data[0].Equals("s") && data.Length >= 4)
                                {
                                    posx = float.Parse(data[1], System.Globalization.CultureInfo.InvariantCulture);
                                    posy = float.Parse(data[2], System.Globalization.CultureInfo.InvariantCulture);
                                    posz = float.Parse(data[3], System.Globalization.CultureInfo.InvariantCulture);
                                }

                            }

                    }
                }
                catch (Exception e)
                {
                    Logger.DebugException(e, "ReadAndSendMap");
                }
                finally
                {
                    if (file != null)
                        file.Close();
                }
            }
            else
            {
                Logger.Error("Map file {0} not found!", filePath);
            }
        }
Exemplo n.º 2
0
 public void OnMessage(RevealSceneMessage msg)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 3
0
        public void ReadAndSendMap()
        {
            string filePath = Config.Instance.Map;
            string line, line2;

            //avarage = double.Parse("0.0", NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);

            if (File.Exists(filePath))
            {
                StreamReader file = null;
                try
                {
                    file = new StreamReader(filePath);
                    while ((line = file.ReadLine()) != null)
                    {
                        if ((line2 = file.ReadLine()) != null)
                        {

                            //Console.WriteLine(line);
                            string[] data = line.Split(' ');
                            string[] data2 = line2.Split(' ');

                            RevealSceneMessage r = new RevealSceneMessage()
                            {
                                Id = 0x0034,
                                Field0 = 0x772E0000, //int.Parse(data[0]),
                                Field1 = new SceneSpecification()
                                {
                                    Field0 = int.Parse(data[1]),
                                    Field1 = new IVector2D()
                                    {
                                        Field0 = int.Parse(data[2]),
                                        Field1 = int.Parse(data[3]),
                                    },
                                    arSnoLevelAreas = new int[4]
            {
                int.Parse(data[4]), int.Parse(data[5]), int.Parse(data[6]), int.Parse(data[7]), 
            },
                                    snoPrevWorld = int.Parse(data[8]),
                                    Field4 = int.Parse(data[9]),
                                    snoPrevLevelArea = int.Parse(data[10]),
                                    snoNextWorld = int.Parse(data[11]),
                                    Field7 = int.Parse(data[12]),
                                    snoNextLevelArea = int.Parse(data[13]),
                                    snoMusic = int.Parse(data[14]),
                                    snoCombatMusic = int.Parse(data[15]),
                                    snoAmbient = int.Parse(data[16]),
                                    snoReverb = int.Parse(data[17]),
                                    snoWeather = int.Parse(data[18]),
                                    snoPresetWorld = int.Parse(data[19]),
                                    Field15 = int.Parse(data[20]),
                                    Field16 = int.Parse(data[21]),
                                    Field17 = int.Parse(data[22]),
                                    Field18 = int.Parse(data[23]),
                                    tCachedValues = new SceneCachedValues()
                                    {
                                        Field0 = int.Parse(data[24]),
                                        Field1 = int.Parse(data[25]),
                                        Field2 = int.Parse(data[26]),
                                        Field3 = new AABB()
                                        {
                                            Field0 = new Vector3D()
                                            {
                                                Field0 = float.Parse(data[27], System.Globalization.CultureInfo.InvariantCulture),
                                                Field1 = float.Parse(data[28], System.Globalization.CultureInfo.InvariantCulture),
                                                Field2 = float.Parse(data[29], System.Globalization.CultureInfo.InvariantCulture),
                                            },
                                            Field1 = new Vector3D()
                                            {
                                                Field0 = float.Parse(data[30], System.Globalization.CultureInfo.InvariantCulture),
                                                Field1 = float.Parse(data[31], System.Globalization.CultureInfo.InvariantCulture),
                                                Field2 = float.Parse(data[32], System.Globalization.CultureInfo.InvariantCulture),
                                            },
                                        },
                                        Field4 = new AABB()
                                        {
                                            Field0 = new Vector3D()
                                            {
                                                Field0 = float.Parse(data[33], System.Globalization.CultureInfo.InvariantCulture),
                                                Field1 = float.Parse(data[34], System.Globalization.CultureInfo.InvariantCulture),
                                                Field2 = float.Parse(data[35], System.Globalization.CultureInfo.InvariantCulture),
                                            },
                                            Field1 = new Vector3D()
                                            {
                                                Field0 = float.Parse(data[36], System.Globalization.CultureInfo.InvariantCulture),
                                                Field1 = float.Parse(data[37], System.Globalization.CultureInfo.InvariantCulture),
                                                Field2 = float.Parse(data[38], System.Globalization.CultureInfo.InvariantCulture),
                                            },
                                        },
                                        Field5 = new int[4]
                {
                    int.Parse(data[39]), int.Parse(data[40]), int.Parse(data[41]), int.Parse(data[42]), 
                },
                                        Field6 = int.Parse(data[43]),
                                    },
                                },
                                Field2 = int.Parse(data[44]),
                                snoScene = int.Parse(data[45]),
                                Field4 = new PRTransform()
                                {
                                    Field0 = new Quaternion()
                                    {
                                        Field0 = 1f,//float.Parse(data[49],System.Globalization.CultureInfo),
                                        Field1 = new Vector3D()
                                        {
                                            Field0 = 0f,//float.Parse(data[46],System.Globalization.CultureInfo),
                                            Field1 = 0f,//float.Parse(data[47],System.Globalization.CultureInfo),
                                            Field2 = 0f,//float.Parse(data[48],System.Globalization.CultureInfo),
                                        },
                                    },
                                    Field1 = new Vector3D()
                                    {
                                        Field0 = float.Parse(data[50], System.Globalization.CultureInfo.InvariantCulture),
                                        Field1 = float.Parse(data[51], System.Globalization.CultureInfo.InvariantCulture),
                                        Field2 = float.Parse(data[52], System.Globalization.CultureInfo.InvariantCulture),
                                    },
                                },
                                Field5 = int.Parse(data[53]),
                                snoSceneGroup = int.Parse(data[54]),
                                arAppliedLabels = new int[0]
        {
        },
                            };


                            MapRevealSceneMessage r2 = new MapRevealSceneMessage()
                            {
                                Id = 0x0044,
                                Field0 = int.Parse(data2[0]),
                                snoScene = int.Parse(data2[1]),
                                Field2 = new PRTransform()
                                {
                                    Field0 = new Quaternion()
                                    {
                                        Field0 = 1f,//float.Parse(data2[5],System.Globalization.CultureInfo),
                                        Field1 = new Vector3D()
                                        {
                                            Field0 = 0f,//float.Parse(data2[2],System.Globalization.CultureInfo),
                                            Field1 = 0f,//float.Parse(data2[3],System.Globalization.CultureInfo),
                                            Field2 = 0f,//float.Parse(data2[4],System.Globalization.CultureInfo),
                                        },
                                    },
                                    Field1 = new Vector3D()
                                    {
                                        Field0 = float.Parse(data2[6], System.Globalization.CultureInfo.InvariantCulture),
                                        Field1 = float.Parse(data2[7], System.Globalization.CultureInfo.InvariantCulture),
                                        Field2 = float.Parse(data2[8], System.Globalization.CultureInfo.InvariantCulture),
                                    },
                                },
                                Field3 = 0x772E0000,//int.Parse(data2[9]),
                                Field4 = int.Parse(data2[10]),
                            };

                            posx = (r.Field1.tCachedValues.Field3.Field0.Field0 + r.Field1.tCachedValues.Field3.Field1.Field0) / 2.0f + r.Field4.Field1.Field0;
                            posy = (r.Field1.tCachedValues.Field3.Field0.Field1 + r.Field1.tCachedValues.Field3.Field1.Field1) / 2.0f + r.Field4.Field1.Field1;
                            posz = (r.Field1.tCachedValues.Field3.Field0.Field2 + r.Field1.tCachedValues.Field3.Field1.Field2) / 2.0f + r.Field4.Field1.Field2;

                            //Console.WriteLine(r.AsText());
                            //Console.WriteLine(r2.AsText());

                            SendMessage(r);
                            SendMessage(r2);

                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.DebugException(e, "ReadAndSendMap");
                }
                finally
                {
                    if (file != null)
                        file.Close();
                }
            }
            else
            {
                Logger.Error("Map file {0} not found!", filePath);
            }
        }