Exemplo n.º 1
0
 /// <summary>
 /// Loads data (waypoints, loot, targets, settings) from a binary file loaded into a Objects.Packet object.
 /// </summary>
 /// <param name="version">The version of LibreBot which created the file.</param>
 /// <param name="p">The Objects.Packet object.</param>
 /// <returns></returns>
 private bool Load(ushort version, Objects.Packet p)
 {
     while (p.GetPosition < p.Length)
     {
         Enums.CavebotDatType type = (Enums.CavebotDatType)p.GetByte();
         ushort count = 0;
         switch (type)
         {
             case Enums.CavebotDatType.Settings:
                 switch (version)
                 {
                     case 212:
                     case 213:
                         this.CurrentSettings.EatFood = p.GetBool();
                         this.CurrentSettings.Exhaust = p.GetUInt16();
                         this.CurrentSettings.MinimumHealthToShoot = p.GetUInt16();
                         this.CurrentSettings.NodeRadius = p.GetByte();
                         this.CurrentSettings.NodeSkipRange = p.GetByte();
                         this.CurrentSettings.OpenContainers = p.GetBool();
                         this.CurrentSettings.PrioritizeDanger = p.GetBool();
                         this.CurrentSettings.StickToCreature = p.GetBool();
                         this.CurrentSettings.StopAttackingWhenOutOfRange = p.GetBool();
                         this.CurrentSettings.UseGoldStacks = p.GetBool();
                         this.CurrentSettings.CanUseMagicRope = p.GetBool();
                         this.CurrentSettings.UseAlternateNodeFinder = p.GetBool();
                         this.CurrentSettings.KillBeforeLooting = p.GetBool();
                         break;
                     default:
                         this.CurrentSettings.EatFood = p.GetBool();
                         this.CurrentSettings.Exhaust = p.GetUInt16();
                         this.CurrentSettings.MinimumHealthToShoot = p.GetUInt16();
                         this.CurrentSettings.NodeRadius = p.GetByte();
                         this.CurrentSettings.NodeSkipRange = p.GetByte();
                         this.CurrentSettings.OpenContainers = p.GetBool();
                         this.CurrentSettings.PrioritizeDanger = p.GetBool();
                         this.CurrentSettings.StickToCreature = p.GetBool();
                         this.CurrentSettings.StopAttackingWhenOutOfRange = p.GetBool();
                         this.CurrentSettings.UseGoldStacks = p.GetBool();
                         this.CurrentSettings.CanUseMagicRope = p.GetBool();
                         break;
                 }
                 break;
             case Enums.CavebotDatType.Loot:
                 count = p.GetUInt16();
                 for (int i = 0; i < count; i++)
                 {
                     switch (version)
                     {
                         default:
                             Loot l = new Loot();
                             l.ID = p.GetUInt16();
                             l.Name = p.GetString();
                             l.Cap = p.GetUInt16();
                             string destination = p.GetString();
                             switch (destination.ToLower())
                             {
                                 case "ground":
                                     l.Destination = Loot.Destinations.Ground;
                                     break;
                                 default:
                                     l.Destination = Loot.Destinations.EmptyContainer;
                                     l.Index = byte.Parse(destination[1].ToString());
                                     break;
                             }
                             this.AddLoot(l);
                             break;
                         case 213:
                             this.AddLoot(new Loot(p.GetUInt16(),
                                 p.GetString(),
                                 p.GetUInt16(),
                                 (Loot.Destinations)p.GetByte(),
                                 p.GetByte()));
                             break;
                     }
                 }
                 break;
             case Enums.CavebotDatType.Targetting:
                 count = p.GetUInt16();
                 for (int i = 0; i < count; i++)
                 {
                     Target t = new Target(this);
                     t.Name = p.GetString();
                     if (version < 212) // load old settings (single setting environment)
                     {
                         Target.Setting setting = new Target.Setting(t);
                         setting.Count = p.GetByte();
                         setting.Range = p.GetByte();
                         setting.DistanceRange = 3;
                         setting.FightMode = (Enums.FightMode)p.GetByte();
                         setting.FightStance = (Enums.FightStance)p.GetByte();
                         p.GetString(); // ring
                         p.GetString(); // rune
                         setting.Spell = p.GetString();
                         setting.DangerLevel = p.GetByte();
                         p.GetBool(); // friendly mode
                         setting.MustBeReachable = p.GetBool();
                         setting.MustBeShootable = p.GetBool();
                         t.DoLoot = p.GetBool();
                         setting.UseThisSetting = true;
                         p.GetBool(); // alarm, deprecated
                         t.SetSettings(new List<Target.Setting>() { setting });
                     }
                     else // load new settings (multiple setting environment)
                     {
                         ushort settingsCount = p.GetUInt16();
                         List<Target.Setting> settings = new List<Target.Setting>();
                         for (int j = 0; j < settingsCount; j++)
                         {
                             Target.Setting setting = new Target.Setting(t);
                             setting.Count = p.GetByte();
                             setting.Range = p.GetByte();
                             setting.DistanceRange = 3;
                             setting.FightMode = (Enums.FightMode)p.GetByte();
                             setting.FightStance = (Enums.FightStance)p.GetByte();
                             p.GetString(); // ring
                             p.GetString(); // rune
                             setting.Spell = p.GetString();
                             setting.DangerLevel = p.GetByte();
                             p.GetBool(); // friendly mode
                             setting.MustBeReachable = p.GetBool();
                             setting.MustBeShootable = p.GetBool();
                             t.DoLoot = p.GetBool();
                             setting.UseThisSetting = true;
                             settings.Add(setting);
                         }
                         t.SetSettings(settings);
                     }
                     this.AddTarget(t);
                 }
                 break;
             case Enums.CavebotDatType.Waypoints:
                 count = p.GetUInt16();
                 for (int i = 0; i < count; i++)
                 {
                     Modules.Cavebot.Waypoint.Types wpType = (Modules.Cavebot.Waypoint.Types)p.GetByte();
                     Objects.Location wpLocation = new Objects.Location(p.GetUInt16(), p.GetUInt16(), p.GetByte());
                     string wpLabel = p.GetString();
                     List<Objects.Location> wpNodes = new List<Objects.Location>();
                     string wpScript = string.Empty;
                     switch (wpType)
                     {
                         case Modules.Cavebot.Waypoint.Types.Node:
                             switch (version)
                             {
                                 case 200:
                                     this.AddWaypoint(new Waypoint(this, wpLocation, wpType));
                                     break;
                                 case 201:
                                 default:
                                     ushort nodeCount = p.GetUInt16();
                                     for (int j = 0; j < nodeCount; j++) wpNodes.Add(new Objects.Location(p.GetUInt16(), p.GetUInt16(), p.GetByte()));
                                     this.AddWaypoint(new Waypoint(this, wpLocation, wpNodes));
                                     break;
                             }
                             break;
                         case Modules.Cavebot.Waypoint.Types.Script:
                             if (version == 211)
                             {
                                 ushort scriptCount = p.GetUInt16();
                                 List<Objects.Script> scripts = new List<Objects.Script>();
                                 string filePath = p.GetString();
                                 string contents = System.IO.File.Exists(filePath) ?
                                     System.IO.File.ReadAllText(filePath) :
                                     string.Empty;
                                 /*for (int j = 0; j < scriptCount; j++)
                                 {
                                     string fileName = p.GetString();
                                     if (!System.IO.File.Exists(fileName)) continue;
                                     Objects.Script script = new Objects.Script(this.Client, fileName, wpLocation);
                                     scripts.Add(script);
                                 }*/
                                 this.AddWaypoint(new Waypoint(this, wpLocation, contents));
                             }
                             else
                             {
                                 wpScript = p.GetString();
                                 this.AddWaypoint(new Waypoint(this, wpLocation, wpScript));
                             }
                             break;
                         default:
                             this.AddWaypoint(new Waypoint(this, wpLocation, wpType));
                             break;
                     }
                 }
                 break;
             default:
                 return false;
         }
     }
     return true;
 }