Ejemplo n.º 1
0
        public static List <TabStructure> FindTabStructures(Process p, Player player)
        {
            bool firstScan = ReadMemoryManager.TabStructureCount() == 0;
            List <TabStructure> structs = new List <TabStructure>();

            foreach (var tpl in ReadMemoryManager.ScanProcess(p))
            {
                int    length      = tpl.Item1.RegionSize;
                int    baseAddress = tpl.Item1.BaseAddress;
                byte[] bytes       = tpl.Item2;
                for (int i = 0; i < length - 20; i += 4)
                {
                    int value = BitConverter.ToInt32(bytes, i);

                    if (value > 0x40000 && value != baseAddress + i)
                    {
                        int messageptr = BitConverter.ToInt32(bytes, i + 4);
                        int maxsize    = BitConverter.ToInt32(bytes, i + 8);
                        int size       = BitConverter.ToInt32(bytes, i + 16);
                        if (messageptr > 0x40000 && IsPowerOfTwo(maxsize) && size < maxsize && maxsize < 10000 && size >= 0 && maxsize > 0)
                        {
                            if ((baseAddress + i) == MemoryReader.ReadInt32(value))
                            {
                                structs.Add(new TabStructure((uint)(baseAddress + i)));
                            }
                        }
                    }
                }
                if (!firstScan)
                {
                    System.Threading.Thread.Sleep(10);
                }
            }
            return(structs);
        }
Ejemplo n.º 2
0
 private static void ScanMissingChunks(object sender, DoWorkEventArgs e)
 {
     while (true)
     {
         ReadMemoryManager.ScanMissingChunks();
     }
 }
Ejemplo n.º 3
0
        private static void ScanMissingChunksTimer()
        {
            ReadMemoryManager.ScanMissingChunks();
            int scanSpeed = SettingsManager.getSettingInt("ScanSpeed") * 15 + 1;

            if (scanSpeed != missingChunkScanTimer.Interval)
            {
                missingChunkScanTimer.Interval = scanSpeed;
            }
        }
Ejemplo n.º 4
0
        private static void ScanMissingChunksTimer()
        {
            if (ProcessManager.TibiaClientType == "Tibia11")
            {
                if (MemoryReader.playerName != null && (player == null || !MemoryReader.playerName.Equals(player.name, StringComparison.InvariantCultureIgnoreCase)))
                {
                    player      = new Player();
                    player.name = MemoryReader.playerName;
                    try {
                        if (!player.GatherInformationOnline(true))
                        {
                            player = null;
                        }
                    } catch {
                        player = null;
                    }
                }
                // scan for where the tab structures are in Tibia 11
                ReadMemoryManager.ScanTabStructures(player);
            }
            else if (ReadMemoryManager.UseInternalScan)
            {
                // If we are scanning the internal tabs structure, we do not need to scan missing chunks)
            }
            else
            {
                ReadMemoryManager.ScanMissingChunks();
            }
            int scanSpeed = SettingsManager.getSettingInt("ScanSpeed") * 15 + 1;

            if (ProcessManager.TibiaClientType == "Tibia11")
            {
                scanSpeed = scanSpeed * 10;
            }
            if (scanSpeed != missingChunkScanTimer.Interval)
            {
                missingChunkScanTimer.Interval = scanSpeed;
            }
        }
Ejemplo n.º 5
0
        public static void StartScanning()
        {
            scanTimer          = new System.Timers.Timer(10000);
            scanTimer.Elapsed += StuckScanning;

            int initialScanSpeed = SettingsManager.getSettingInt("ScanSpeed") * 15 + 1;

            missingChunkScanTimer           = new System.Timers.Timer(initialScanSpeed);
            missingChunkScanTimer.AutoReset = false;
            missingChunkScanTimer.Elapsed  += (o, e) => {
                ReadMemoryManager.ScanMissingChunks();
                int scanSpeed = SettingsManager.getSettingInt("ScanSpeed") * 15 + 1;
                if (scanSpeed != missingChunkScanTimer.Interval)
                {
                    missingChunkScanTimer.Interval = scanSpeed;
                }

                missingChunkScanTimer.Start();
            };
            missingChunkScanTimer.Start();

            initialScanSpeed        = SettingsManager.getSettingInt("ScanSpeed") * 5 + 1;
            mainScanTimer           = new System.Timers.Timer(initialScanSpeed);
            mainScanTimer.AutoReset = false;
            mainScanTimer.Elapsed  += (o, e) => {
                ScanMemory(o, null);
                int scanSpeed = SettingsManager.getSettingInt("ScanSpeed") * 5 + 1;
                if (scanSpeed != mainScanTimer.Interval)
                {
                    mainScanTimer.Interval = scanSpeed;
                }

                mainScanTimer.Start();
            };
            mainScanTimer.Start();

            currentState = ScanningState.NoTibia;
        }
Ejemplo n.º 6
0
        public MainForm()
        {
            startup = true;
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            mainForm = this;
            InitializeComponent();

            SettingsManager.LoadSettings(Constants.SettingsFile);

            LootDatabaseManager.LootChanged     += NotificationManager.UpdateLootDisplay;
            LootDatabaseManager.LootChanged     += UpdateLogDisplay;
            GlobalDataManager.ExperienceChanged += NotificationManager.UpdateExperienceDisplay;
            GlobalDataManager.DamageChanged     += NotificationManager.UpdateDamageDisplay;
            GlobalDataManager.UsedItemsChanged  += NotificationManager.UpdateUsedItemsDisplay;

            if (!File.Exists(Constants.DatabaseFile))
            {
                ExitWithError("Fatal Error", String.Format("Could not find database file {0}.", Constants.DatabaseFile));
            }

            if (!File.Exists(Constants.NodeDatabase))
            {
                ExitWithError("Fatal Error", String.Format("Could not find database file {0}.", Constants.NodeDatabase));
            }

            LootDatabaseManager.Initialize();
            StyleManager.InitializeStyle();
            NotificationForm.Initialize();
            Parser.Initialize();
            PopupManager.Initialize(this.notifyIcon1);

            prevent_settings_update = true;
            try {
                StorageManager.InitializeStorage();
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted database {0}.\nMessage: {1}", Constants.DatabaseFile, e.Message));
            }
            ProcessManager.Initialize();
            this.initializeSettings();
            try {
                Pathfinder.LoadFromDatabase(Constants.NodeDatabase);
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted database {0}.\nMessage: {1}", Constants.NodeDatabase, e.Message));
            }
            prevent_settings_update = false;

            this.InitializeTabs();
            switchTab(0);
            makeDraggable(this.Controls);

            if (SettingsManager.getSettingBool("StartAutohotkeyAutomatically"))
            {
                AutoHotkeyManager.StartAutohotkey();
            }
            ReadMemoryManager.Initialize();
            HuntManager.Initialize();
            UIManager.Initialize();
            MemoryReader.Initialize();
            HUDManager.Initialize();
            GlobalDataManager.Initialize();

            this.Load += MainForm_Load;

            fileWriter = new StreamWriter(Constants.BigLootFile, true);

            tibialyzerLogo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.draggable_MouseDown);
            startup = false;

            ScanningManager.StartScanning();

            scan_tooltip.AutoPopDelay = 60000;
            scan_tooltip.InitialDelay = 500;
            scan_tooltip.ReshowDelay  = 0;
            scan_tooltip.ShowAlways   = true;
            scan_tooltip.UseFading    = true;

            SetScanningImage("scanningbar-red.gif", "No Tibia Client Found...", true);
        }
Ejemplo n.º 7
0
        public static bool ScanMemory()
        {
            ReadMemoryResults  readMemoryResults  = ReadMemoryManager.ReadMemory();
            ParseMemoryResults parseMemoryResults = Parser.ParseLogResults(readMemoryResults);

            if (parseMemoryResults != null)
            {
                lastResults = parseMemoryResults;
                if (parseMemoryResults.newDamage)
                {
                    GlobalDataManager.UpdateDamage();
                }
            }

            if (readMemoryResults != null && readMemoryResults.newAdvances.Count > 0)
            {
                if (SettingsManager.getSettingBool("AutoScreenshotAdvance"))
                {
                    MainForm.mainForm.Invoke((MethodInvoker) delegate {
                        ScreenshotManager.saveScreenshot("Advance", ScreenshotManager.takeScreenshot());
                    });
                }
                if (SettingsManager.getSettingBool("CopyAdvances"))
                {
                    foreach (object obj in readMemoryResults.newAdvances)
                    {
                        MainForm.mainForm.Invoke((MethodInvoker) delegate {
                            Clipboard.SetText(obj.ToString());
                        });
                    }
                }
                readMemoryResults.newAdvances.Clear();
            }

            if (parseMemoryResults != null && parseMemoryResults.death)
            {
                if (SettingsManager.getSettingBool("AutoScreenshotDeath"))
                {
                    MainForm.mainForm.Invoke((MethodInvoker) delegate {
                        ScreenshotManager.saveScreenshot("Death", ScreenshotManager.takeScreenshot());
                    });
                }
                parseMemoryResults.death = false;
            }

            if (parseMemoryResults != null)
            {
                if (parseMemoryResults.newEventMessages.Count > 0)
                {
                    if (SettingsManager.getSettingBool("EnableEventNotifications"))
                    {
                        foreach (Tuple <Event, string> tpl in parseMemoryResults.newEventMessages)
                        {
                            Event    ev = tpl.Item1;
                            Creature cr = StorageManager.getCreature(ev.creatureid);
                            MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                if (!SettingsManager.getSettingBool("UseRichNotificationType"))
                                {
                                    PopupManager.ShowSimpleNotification("Event in " + ev.location, tpl.Item2, cr.image);
                                }
                                else
                                {
                                    PopupManager.ShowSimpleNotification(new SimpleTextNotification(cr.image, "Event in " + ev.location, tpl.Item2));
                                }
                            });
                        }
                    }
                    parseMemoryResults.newEventMessages.Clear();
                }
            }

            if (SettingsManager.getSettingBool("LookMode") && readMemoryResults != null)
            {
                foreach (string msg in parseMemoryResults.newLooks)
                {
                    string itemName = Parser.parseLookItem(msg).ToLower();
                    if (StorageManager.itemExists(itemName))
                    {
                        MainForm.mainForm.Invoke((MethodInvoker) delegate {
                            CommandManager.ExecuteCommand("item@" + itemName);
                        });
                    }
                    else if (StorageManager.creatureExists(itemName) ||
                             (itemName.Contains("dead ") && (itemName = itemName.Replace("dead ", "")) != null && StorageManager.creatureExists(itemName)) ||
                             (itemName.Contains("slain ") && (itemName = itemName.Replace("slain ", "")) != null && StorageManager.creatureExists(itemName)))
                    {
                        MainForm.mainForm.Invoke((MethodInvoker) delegate {
                            CommandManager.ExecuteCommand("creature@" + itemName);
                        });
                    }
                    else
                    {
                        NPC npc = StorageManager.getNPC(itemName);
                        if (npc != null)
                        {
                            MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                CommandManager.ExecuteCommand("npc@" + itemName);
                            });
                        }
                    }
                }
                parseMemoryResults.newLooks.Clear();
            }

            List <string> commands = parseMemoryResults == null ? new List <string>() : parseMemoryResults.newCommands.ToList();

            commands.Reverse();

            foreach (string command in commands)
            {
                MainForm.mainForm.Invoke((MethodInvoker) delegate {
                    if (!CommandManager.ExecuteCommand(command, parseMemoryResults) && SettingsManager.getSettingBool("EnableUnrecognizedNotifications"))
                    {
                        if (!SettingsManager.getSettingBool("UseRichNotificationType"))
                        {
                            PopupManager.ShowSimpleNotification("Unrecognized command", "Unrecognized command: " + command, StyleManager.GetImage("tibia.png"));
                        }
                        else
                        {
                            PopupManager.ShowSimpleNotification(new SimpleTextNotification(null, "Unrecognized command", "Unrecognized command: " + command));
                        }
                    }
                });
            }
            if (parseMemoryResults != null)
            {
                if (parseMemoryResults.newItems.Count > 0)
                {
                    MainForm.mainForm.Invoke((MethodInvoker) delegate {
                        LootDatabaseManager.UpdateLoot();
                    });
                }
                foreach (Tuple <Creature, List <Tuple <Item, int> > > tpl in parseMemoryResults.newItems)
                {
                    Creature cr = tpl.Item1;
                    List <Tuple <Item, int> > items = tpl.Item2;
                    bool showNotification           = PopupManager.ShowDropNotification(tpl);
                    if (showNotification)
                    {
                        if (!SettingsManager.getSettingBool("UseRichNotificationType"))
                        {
                            Console.WriteLine("Rich Notification");
                            PopupManager.ShowSimpleNotification(cr.displayname, cr.displayname + " dropped a valuable item.", cr.image);
                        }
                        else
                        {
                            MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                PopupManager.ShowSimpleNotification(new SimpleLootNotification(cr, items));
                            });
                        }

                        if (SettingsManager.getSettingBool("AutoScreenshotItemDrop"))
                        {
                            // Take a screenshot if Tibialyzer is set to take screenshots of valuable loot
                            Bitmap screenshot = ScreenshotManager.takeScreenshot();
                            if (screenshot == null)
                            {
                                continue;
                            }
                            // Add a notification to the screenshot
                            SimpleLootNotification screenshotNotification = new SimpleLootNotification(cr, items);
                            Bitmap notification = new Bitmap(screenshotNotification.Width, screenshotNotification.Height);
                            screenshotNotification.DrawToBitmap(notification, new Rectangle(0, 0, screenshotNotification.Width, screenshotNotification.Height));
                            foreach (Control c in screenshotNotification.Controls)
                            {
                                c.DrawToBitmap(notification, new Rectangle(c.Location, c.Size));
                            }
                            screenshotNotification.Dispose();
                            int widthOffset  = notification.Width + 10;
                            int heightOffset = notification.Height + 10;
                            if (screenshot.Width > widthOffset && screenshot.Height > heightOffset)
                            {
                                using (Graphics gr = Graphics.FromImage(screenshot)) {
                                    gr.DrawImage(notification, new Point(screenshot.Width - widthOffset, screenshot.Height - heightOffset));
                                }
                            }
                            notification.Dispose();
                            MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                ScreenshotManager.saveScreenshot("Loot", screenshot);
                            });
                        }
                    }
                }
            }
            return(readMemoryResults != null);
        }
Ejemplo n.º 8
0
        public MainForm()
        {
            startup = true;
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            mainForm = this;
            InitializeComponent();

            Constants.InitializeConstants();

            SettingsManager.Initialize();

            if (File.Exists(Constants.SettingsTemporaryBackup))
            {
                // a temporary backup file exists, this might indicate a problem occurred while writing a settings file (e.g. unexpected shutdown)
                try {
                    SettingsManager.LoadSettings(Constants.SettingsTemporaryBackup);
                    if (SettingsManager.settings.Count == 0)
                    {
                        throw new Exception("Failed to read backup settings.");
                    }
                    if (File.Exists(Constants.SettingsFile))
                    {
                        File.Delete(Constants.SettingsFile);
                    }
                    File.Copy(Constants.SettingsTemporaryBackup, Constants.SettingsFile);
                    File.Delete(Constants.SettingsTemporaryBackup);
                } catch (Exception ex) {
                    DisplayWarning(String.Format("Backup settings file found, but could not read: {0}", ex.Message));
                }
            }
            SettingsManager.LoadSettings(Constants.SettingsFile);

            LootDatabaseManager.LootChanged     += NotificationManager.UpdateLootDisplay;
            LootDatabaseManager.LootChanged     += UpdateLogDisplay;
            GlobalDataManager.ExperienceChanged += NotificationManager.UpdateExperienceDisplay;
            GlobalDataManager.DamageChanged     += NotificationManager.UpdateDamageDisplay;
            GlobalDataManager.UsedItemsChanged  += NotificationManager.UpdateUsedItemsDisplay;

            if (!File.Exists(Constants.DatabaseFile))
            {
                ExitWithError("Fatal Error", String.Format("Could not find database file {0}.", Constants.DatabaseFile));
            }

            if (!File.Exists(Constants.NodeDatabase))
            {
                ExitWithError("Fatal Error", String.Format("Could not find database file {0}.", Constants.NodeDatabase));
            }

            LootDatabaseManager.Initialize();
            StyleManager.InitializeStyle();
            NotificationForm.Initialize();
            Parser.Initialize();
            PopupManager.Initialize(this.notifyIcon1);

            prevent_settings_update = true;
            try {
                StorageManager.InitializeStorage();
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted database {0}.\nMessage: {1}", Constants.DatabaseFile, e.Message));
            }
            try {
                OutfiterManager.Initialize();
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted outfiter database {0}.\nMessage: {1}", Constants.OutfiterDatabaseFile, e.Message));
            }
            ProcessManager.Initialize();
            this.initializeSettings();
            try {
                Pathfinder.LoadFromDatabase(Constants.NodeDatabase);
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted database {0}.\nMessage: {1}", Constants.NodeDatabase, e.Message));
            }
            TaskManager.Initialize();
            prevent_settings_update = false;

            ChangeLanguage(SettingsManager.getSettingString("TibialyzerLanguage"));

            this.InitializeTabs();
            switchTab(0);
            makeDraggable(this.Controls);

            if (SettingsManager.getSettingBool("StartAutohotkeyAutomatically"))
            {
                AutoHotkeyManager.StartAutohotkey();
            }

            ReadMemoryManager.Initialize();
            HuntManager.Initialize();
            UIManager.Initialize();
            MemoryReader.Initialize();
            HUDManager.Initialize();
            GlobalDataManager.Initialize();

            if (SettingsManager.getSettingBool("AutomaticallyDownloadAddresses"))
            {
                MainTab.DownloadNewAddresses();
            }

            this.Load += MainForm_Load;

            fileWriter = new StreamWriter(Constants.BigLootFile, true);

            tibialyzerLogo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.draggable_MouseDown);
            startup = false;

            ScanningManager.StartScanning();

            scan_tooltip.AutoPopDelay = 60000;
            scan_tooltip.InitialDelay = 500;
            scan_tooltip.ReshowDelay  = 0;
            scan_tooltip.ShowAlways   = true;
            scan_tooltip.UseFading    = true;

            SetScanningImage("scanningbar-red.gif", "No Tibia Client Found...", true);
        }
Ejemplo n.º 9
0
        public static List <TabStructure> FindTabStructures(Process p, Player player)
        {
            bool firstScan = ReadMemoryManager.TabStructureCount() == 0;
            List <TabStructure> structs = new List <TabStructure>();

            /*int statsValue = -1, expValue = -1;
             * if (MemoryReader.MemorySettings.ContainsKey("tibia11statsvalue")) {
             *  int.TryParse(MemoryReader.MemorySettings["tibia11statsvalue"], out statsValue);
             * }
             * if (MemoryReader.MemorySettings.ContainsKey("tibia11expvalue")) {
             *  int.TryParse(MemoryReader.MemorySettings["tibia11expvalue"], out expValue);
             * }*/
            int  playerMaxLife = -1, playerMaxMana = -1, playerLevel = -1;
            long playerMinExperience = -1, playerMaxExperience = -1;

            if (player != null)
            {
                playerMaxLife       = player.MaxLife();
                playerMaxMana       = player.MaxMana();
                playerMinExperience = ExperienceBar.GetExperience(player.level - 1);
                playerMaxExperience = ExperienceBar.GetExperience(player.level);
                playerLevel         = player.level;
            }
            foreach (var tpl in ReadMemoryManager.ScanProcess(p))
            {
                int    length      = tpl.Item1.RegionSize;
                int    baseAddress = tpl.Item1.BaseAddress;
                byte[] bytes       = tpl.Item2;
                for (int i = 0; i < length - 20; i += 4)
                {
                    int value = BitConverter.ToInt32(bytes, i);

                    if (value > 0x40000 && value != baseAddress + i)
                    {
                        int messageptr = BitConverter.ToInt32(bytes, i + 4);
                        int maxsize    = BitConverter.ToInt32(bytes, i + 8);
                        int size       = BitConverter.ToInt32(bytes, i + 16);
                        if (messageptr > 0x40000 && IsPowerOfTwo(maxsize) && size < maxsize && maxsize < 10000 && size >= 0 && maxsize > 0)
                        {
                            if ((baseAddress + i) == MemoryReader.ReadInt32(value))
                            {
                                structs.Add(new TabStructure((uint)(baseAddress + i)));
                            }
                        }
                    }
                    if (player != null)
                    {
                        int maxhealth = BitConverter.ToInt32(bytes, i + 0x4);
                        int maxmana   = BitConverter.ToInt32(bytes, i + 0xC);
                        if (maxhealth == playerMaxLife && maxmana == playerMaxMana)
                        {
                            int health = BitConverter.ToInt32(bytes, i);
                            int mana   = BitConverter.ToInt32(bytes, i + 0x8);
                            if (health <= maxhealth && health >= 0 && mana <= maxmana && mana >= 0)
                            {
                                MemoryReader.SetStatsAddress((uint)(baseAddress + i - 0x24));
                            }
                        }
                        else
                        {
                            int  bla        = BitConverter.ToInt32(bytes, i);
                            long experience = BitConverter.ToInt64(bytes, i + 0x4);
                            if (bla == 0 && experience > playerMinExperience && experience < playerMaxExperience)
                            {
                                short level = BitConverter.ToInt16(bytes, i + 0xC);
                                if (level == playerLevel)
                                {
                                    double percentage = BitConverter.ToInt32(bytes, i + 0xE) / 100.0;
                                    long   diff       = playerMaxExperience - playerMinExperience;
                                    if (percentage >= 0 && percentage <= 1 && experience > playerMinExperience + diff * (percentage - 1) && experience < playerMinExperience + diff * (percentage + 1))
                                    {
                                        MemoryReader.SetExpAddress((uint)(baseAddress + i - 0x14));
                                    }
                                }
                            }
                        }
                    }
                }
                if (!firstScan)
                {
                    System.Threading.Thread.Sleep(10);
                }
            }
            return(structs);
        }