public static CoreBot loadBotModule(String configName, String routeName) { CoreBot bot = null; Module.SaveConfigHolder configHolder = new Module.SaveConfigHolder(); List <Waypoint> wplist = BotLoader.loadWaypoints(routeName, "wpr"); byte[] configBytes = BotLoader.loadFile(configName, "cfg"); if (configBytes.Length > 0 && wplist.Count > 0) { configHolder.parseBytes(configBytes, true); } if (configHolder.type != ConfigType.None) { if (configHolder.type == ConfigType.Fishing) { bot = new FishingBot(configHolder.fishingConfig, wplist); } else if (configHolder.type == ConfigType.Gathering) { bot = new GatheringBot(configHolder.gatheringConfig, wplist); } else if (configHolder.type == ConfigType.Combat) { bot = new CombatBot(configHolder.combatConfig, wplist); } } return(bot); }
private void loadConfigFile(String fileName) { bool successSave = false; bool invalidData = false; long fileSize = 0; Module.SaveConfigHolder configHolder = null; if (fileName != null && fileName.Length > 0) { try { string regexSearch = new string(Path.GetInvalidPathChars()); Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch))); String validFileName = r.Replace(fileName, ""); String fullPath = Path.Combine(this.currentDirectory, validFileName); fullPath = Path.ChangeExtension(fullPath, "cfg"); if (File.Exists(fullPath)) { using (FileStream fs = new FileStream(fullPath, FileMode.Open)) { using (BinaryReader binReader = new BinaryReader(fs)) { byte[] bytes = binReader.ReadBytes((int)binReader.BaseStream.Length); configHolder = new Module.SaveConfigHolder(); configHolder.parseBytes(bytes, true); binReader.Close(); successSave = true; } fs.Close(); } } else { successSave = false; } } catch { successSave = false; MessageBox.Show("Unknown Error\n\nabort loading", "Loading Error"); } } if (invalidData) { if (fileSize > 0) { MessageBox.Show("corrupt file detected\n\nabort loading", "Loading Error"); } else { MessageBox.Show("empty detected\n\nabort loading", "Loading Error"); } } if (successSave && !invalidData) { this.Dispose(); configHolder.fileName = fileName; this.loadFormDelegate(configHolder); } else { this.scanDirectoryForConfig(); } }