Reklama
Pokazuje wyniki od 1 do 4 z 4

Temat: [Delphi][Poszukiwany/Poszukiwana] C++ -> Delphi , struktura containerów w tibii

  1. #1
    Avatar BBsrv
    Data rejestracji
    2013
    Położenie
    50cm od monitora
    Wiek
    31
    Posty
    4,489
    Siła reputacji
    13

    Domyślny [Delphi][Poszukiwany/Poszukiwana] C++ -> Delphi , struktura containerów w tibii

    Dzień dobry, cześć i czołem, pytacie skąd się wziąłem...
    Jestem weso...

    ops nie to.

    Do rzeczy, potrzebuję kogoś, kto byłby tak miły i przepisał/napisał/whatever dla mnie strukturę backpacków tibiałkowych.

    Posiadam kod w c++ (od @szulak ;, na dole tematu)

    Z c++ mam tyle wspólnego, co politycy z mówieniem prawdy, tak więc liczę na was torgowi programerzy

    czy ktoś byłby skłonny mi pomóc ?

    Jak potrzeba to postawię jakiegoś browara czy dwa.

    Aktualna funkcja jaką posiadam działa - owszem - ale mogę odczytywać tylko pierwsze trzy otwarte containery, każdy kolejny otwarty "staje się" trzecim, a "poprzedni trzeci" przestaje być widoczny.
    Kod:
    backpack_ptr=$9f7498;
    bp_offset1=$8        ;
    bp_offset2=$0         ;
    bp_offset3=$10          ;
    bp_offset4=$28 ;
    Kod:
    
    function TMemory.getbpa(id:integer):integer;
    var x:integer;
    begin
    x:=memory.memreadinteger(backpack_ptr);
    x:=memory.memreadinteger(x+bp_offset1);
    x:=memory.memreadinteger(x+bp_offset2+(id*4)+mem.baza);
    x:=memory.memreadinteger(x+bp_offset3+mem.baza);
    Result:=x+bp_offset4+mem.baza;
    
    end;
    Kod:
    function tmemory.getbpindex(name:string):integer;
    var id,x:integer;
    begin
    for id:=0 to 3 do begin
    x:=memory.memreadinteger(backpack_ptr);
    x:=memory.memreadinteger(x+bp_offset1+mem.baza);
    x:=memory.memreadinteger(x+bp_offset2+(id*4)+mem.baza);
    x:=memory.memreadinteger(x+bp_offset3+mem.baza);
    if name= memory.memreadstring(x+bp_offset4+mem.baza) then begin result:=id; break end;
    end;
    end;
    Głównie zależy mi na TMemory.getbpa()

    @arkes ;
    @szulak ;
    @CoreBot ;
    @Ktokolwiek


    Rodacy... Pomożecie ?

    http://pastebin.com/2eRQhY8U
    http://pastebin.com/2qRRVNZf
    http://pastebin.com/KZDwUgsA
    Kontakt ze mną:
    pw

  2. #2
    Avatar arkes
    Data rejestracji
    2012
    Posty
    433
    Siła reputacji
    13

    Domyślny


    Kod:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using System.Runtime.InteropServices;
    
    namespace Astrabot.Objects
    {
        public class Containers
        {
            #region Declarations
            public static List<Container> containers = new List<Container>();
            List<Item> items = new List<Item>();
            public class Container
            {
                public string name;
                public int bp_id, maxcount, itemcount, gui_id;
                public List<Item> items = new List<Item>();
                public List<Item> item { get { return items; } }
            }
    
            public class Item
            {
                public string container_name;
                public int position, bpid, itemid, itemcount;
            }
            #endregion
            #region Functions
    
            public static string reverse_id(int id)
            {
                for (int i = 0; i < Items.ItemDatabase.Count; i++)
                {
                    if (Items.ItemDatabase.ElementAt(i).itemid == id) { return Items.ItemDatabase.ElementAt(i).name; }
                }
                return null;
            }
    
            public static int item_count(int itemid)
            {
                List<Containers.Container> bps = new List<Containers.Container>();
                List<int> counter = new List<int>();
                bps = Containers.GetContainers().ToList();
                int count = 0;
                int countered = 0;
                foreach (Containers.Container bp in bps)
                {
                    foreach (Containers.Item item in bp.items)
                    {
                        if (item.itemid == itemid)
                        {
                            if (item.itemcount == 0) { countered++; } else { countered = item.itemcount; }
                            counter.Add(countered);
                            countered = 0;
                        }
                    }
                }
                for (int i = 0; i < counter.Count; i++)
                {
                    count = counter.ElementAt(i) + count;
                }
                return count;
            }
    
            public static List<Container> GetContainers()
            {
                try
                {
                    List<Container> lista_bp = new List<Container>();
                    if (Objects.Cont.Get_Count() > 0)
                    {
                        for (int i = 0; i < Objects.Cont.Get_Count(); i++)
                        {
                            Container bp = new Container();
                            bp.bp_id = Objects.Cont.GetContai().ElementAt(i).AsItem.Id;
                            bp.name = Objects.Cont.GetContai().ElementAt(i).Name();
                            bp.maxcount = Objects.Cont.GetContai().ElementAt(i).slotsCount;
                            bp.itemcount = Objects.Cont.GetContai().ElementAt(i).itemsCount;
                            bp.gui_id = Objects.Cont.GetContai().ElementAt(i).index;
                            if (bp.name != null) { lista_bp.Add(bp); }
                                for (int t = 0; t < Objects.Cont.GetContai().ElementAt(i).Items().Count(); t++)
                                {
                                    Item item = new Item();
                                    item.container_name = Objects.Cont.GetContai().ElementAt(i).Name();
                                    item.position = t;
                                    item.itemid = Objects.Cont.GetContai().ElementAt(i).Items().ElementAt(t).id;
                                    item.itemcount = Objects.Cont.GetContai().ElementAt(i).Items().ElementAt(t).count;
                                    item.bpid = bp.bp_id;
                                    bp.items.Add(item);
                                }
                        }
                    }
                    return lista_bp;
                }
                catch (Exception x) { Astrabot.Console.Console.Update(x.ToString()); }
                return null;
            }
    
            public static bool IsItemInBp(Containers.Container bp, int Item_id)
            {
                foreach (Item item in bp.items) { if (item.itemid == Item_id) { return true; } }
                return false;
            }
            #endregion
        }
    }


    Kod:
    using System;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Collections.Generic;
    
    namespace Astrabot.Objects
    {
       public class Cont
       {
           #region Help Data
           /// <summary>
           /// Index - Kolejność Backpacków
           /// ItemsCount - Ilość itemów w backpacku
           /// SlotsCount - Max ilość itemów w backpacku
           /// .AsItem.Id - Id Otwartych backpacków
           #endregion
           #region Import
           [DllImport("kernel32.dll")]
           static extern int ReadProcessMemory(
               IntPtr processHandle,
               int address,
               IntPtr buffer,
               int size,
               out int numberOfBytesRead
           );
           #endregion
           #region Structures
           public struct STD_STRING
            {
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x10)]
                public byte[] buffer; // offset 0x0, length = 0x10
                public int length; // offset 0x10
                public int maxLength; // offset 0x14
                public int unk; // offset 0x18
                public string Text()
                {
                    if (this.maxLength > 0xF)
                        return ReadString(BitConverter.ToInt32(buffer, 0), this.length, false);
                    char[] value = new char[this.length];
                    for (int i = 0; i < this.length; i++)
                        if (this.buffer[i] == 0)
                            return new string(value, 0, i);
                        else
                            value[i] = (char)buffer[i];
                    return new string(value);
                }
            }
    
           public struct CONTAINER_NODE : IComparable<CONTAINER_NODE>, IComparer<CONTAINER_NODE>
            {
                public int left; // offset 0x0
                public int center; // offset 0x4
                public int right; // offset 0x8
                public int containerIndex; // offset 0xC
                public int containerAddress; // offset 0x10
     
                public int Left { get { return this.left; } }
                public int Center { get { return this.center; } }
                public int Right { get { return this.right; } }
                public int ContainerIndex { get { return this.containerIndex; } }
                public int ContainerAddress { get { return this.containerAddress; } }
     
                public bool HasLeft { get { return this.left != 0; } }
                public bool HasCenter { get { return this.center != 0; } }
                public bool HasRight { get { return this.right != 0; } }
                public bool HasContainer { get { return this.containerAddress != 0; } }
     
                public Container Container() { return ReadContainer(this.containerAddress); }
                public int CompareTo(CONTAINER_NODE other) { return this.containerIndex.CompareTo(other.containerIndex); }
                public int Compare(CONTAINER_NODE x, CONTAINER_NODE y) { return x.containerIndex.CompareTo(y.containerIndex); }
            }
    
           public struct CONTAINERS_ENTRY
            {
                public int unk0; // offset 0x0
                public int unk1; // offset 0x4
                public int containersAddress; // offset 0x8
                public int containersCount; // offset 0xC
     
                public int ContainersAddress { get { return this.containersAddress; } }
                public int ContainersCount { get { return this.containersCount; } }
            }
    
           public struct Item
            {
               public int slot; // offset 0x0
               public int count; // offset 0x4
               public int id; // offset 0x8
               public int r; // offset 0xC
               public int g; // offset 0x10          
               public int b; // offset 0x14              
               public int isVisible; // offset 0x18  
               public int unk;//0xc
               public int un0;//0x10
                public int Count { get { return this.count; } }
                public int Id { get { return this.id; } }
                public int R { get { return this.r; } }
                public int G { get { return this.g; } }
                public int B { get { return this.b; } }
                public bool IsVisible { get { return this.isVisible != 0; } }
            }
           public struct Container
            {
                public int index; // offset 0
                public Item asItem; // offset 0x4
                public STD_STRING name; // offset 0x20
                public int unk0; // offset 0x3C
                public int slotsCount; // offset 0x40
                public int itemsCount; // offset 0x44
                public int unk1; // offset 0x48
                public int itemsAddress; // offset 0x4C
                public int Index { get { return this.index; } }
                public Item AsItem { get { return this.asItem; } }
                public int SlotsCount { get { return this.slotsCount; } }
                public int ItemsCount { get { return this.itemsCount; } }
                public string Name() { return this.name.Text(); }
                public Item[] Items() { return ReadItems(this.itemsAddress, this.itemsCount); }
            }
           #endregion
           #region Reading Memory
           static int ReadInt32(int address)
           {
               int numberOfBytesRead;
               int size = sizeof(int);
    
               IntPtr memoryBlock = Marshal.AllocHGlobal(size);
               ReadProcessMemory(processHandle, address, memoryBlock, size, out numberOfBytesRead);
    
               int value = (int)Marshal.PtrToStructure(memoryBlock, typeof(int));
               Marshal.FreeHGlobal(memoryBlock);
    
               return value;
           }
           static string ReadString(int address, int length, bool checkNullChar = true)
           {
               int numberOfBytesRead;
               int size = length;
    
               IntPtr memoryBlock = Marshal.AllocHGlobal(size);
               ReadProcessMemory(processHandle, address, memoryBlock, size, out numberOfBytesRead);
    
               string value = Marshal.PtrToStringAnsi(memoryBlock, length);
               Marshal.FreeHGlobal(memoryBlock);
    
               if (checkNullChar)
               {
                   int index = value.IndexOf('\0');
                   return index == -1 ? value : value.Substring(0, index);
               }
               return value;
           }
           static string ReadStdString(int address)
           {
               int numberOfBytesRead;
               System.Type type = typeof(STD_STRING);
               int size = Marshal.SizeOf(type);
    
               IntPtr memoryBlock = Marshal.AllocHGlobal(size);
               ReadProcessMemory(processHandle, address, memoryBlock, size, out numberOfBytesRead);
    
               STD_STRING value = (STD_STRING)Marshal.PtrToStructure(memoryBlock, type);
               Marshal.FreeHGlobal(memoryBlock);
    
               return value.Text();
           }
           static int ReadContainersPointer()
           {
               return ReadInt32((int)Addresses.containersPointer + baseAddress);
           }
           static CONTAINERS_ENTRY ReadContainersEntry(int address)
           {
               int numberOfBytesRead;
               System.Type type = typeof(CONTAINERS_ENTRY);
               int size = Marshal.SizeOf(type);
    
               IntPtr memoryBlock = Marshal.AllocHGlobal(size);
               ReadProcessMemory(processHandle, address, memoryBlock, size, out numberOfBytesRead);
    
               CONTAINERS_ENTRY value = (CONTAINERS_ENTRY)Marshal.PtrToStructure(memoryBlock, type);
               Marshal.FreeHGlobal(memoryBlock);
    
               return value;
           }
           static CONTAINER_NODE ReadContainerNode(int address)
           {
               int numberOfBytesRead;
               System.Type type = typeof(CONTAINER_NODE);
               int size = Marshal.SizeOf(type);
    
               IntPtr memoryBlock = Marshal.AllocHGlobal(size);
               ReadProcessMemory(processHandle, address, memoryBlock, size, out numberOfBytesRead);
    
               CONTAINER_NODE value = (CONTAINER_NODE)Marshal.PtrToStructure(memoryBlock, type);
               Marshal.FreeHGlobal(memoryBlock);
    
               return value;
           }
           static Item[] ReadItems(int address, int itemsCount)
           {
               int numberOfBytesRead;
               System.Type itemType = typeof(Item);
               int itemSize = Marshal.SizeOf(itemType);
               int size = itemsCount * itemSize;
    
    
               IntPtr memoryBlock = Marshal.AllocHGlobal(size);
               ReadProcessMemory(processHandle, address, memoryBlock, size, out numberOfBytesRead);
    
               Item[] value = new Item[itemsCount];
               for (int i = 0; i < itemsCount; i++)
               {
                   value[i] = (Item)Marshal.PtrToStructure(IntPtr.Add(memoryBlock, i * itemSize), itemType);
               }
    
               Marshal.FreeHGlobal(memoryBlock);
    
               return value;
           }
           static Container ReadContainer(int address)
           {
               int numberOfBytesRead;
               System.Type type = typeof(Container);
               int size = Marshal.SizeOf(type);
    
               IntPtr memoryBlock = Marshal.AllocHGlobal(size);
               ReadProcessMemory(processHandle, address, memoryBlock, size, out numberOfBytesRead);
    
               Container value = (Container)Marshal.PtrToStructure(memoryBlock, type);
               Marshal.FreeHGlobal(memoryBlock);
    
               return value;
           }
           #endregion
           #region Variables
           static IntPtr processHandle;
           static int baseAddress;
           
           
           #endregion
           #region Containers Handler
            class ContainersHandler
            {
                #region Variables
                SortedSet<CONTAINER_NODE> nodes;
                HashSet<int> addresses;
                CONTAINERS_ENTRY entry;
                #endregion
     
                #region Properties
                public int Count { get { return this.entry.ContainersCount; } }
                #endregion
     
                #region Methods
                public void Reset()
                {
                    this.nodes.Clear();
                    this.addresses.Clear();
                    this.entry = ReadContainersEntry(ReadContainersPointer());
                }
                public IEnumerable<Container> Containers()
                {
                    if (this.Count == 0)
                        return new List<Container>();
     
                    int firstNodeAddress = ReadInt32(this.entry.ContainersAddress);
                    CONTAINER_NODE firstNode = ReadContainerNode(firstNodeAddress);
                    RecursiveMethod(firstNode, firstNodeAddress);
     
                    return from node in this.nodes select node.Container();
                }
                #endregion
     
                #region Private Methods
                void RecursiveMethod(CONTAINER_NODE node, int address)
                {
                    this.addresses.Add(address);
     
                    if (this.nodes.Contains(node))
                        return;
     
                    if (node.ContainerAddress != 0)
                        this.nodes.Add(node);
     
                    if (CanSearchOnCenter(node))
                        RecursiveMethod(ReadContainerNode(node.Center), node.Center);
     
                    if (CanSearchOnLeft(node))
                        RecursiveMethod(ReadContainerNode(node.Left), node.Left);
     
                    if (CanSearchOnRight(node))
                        RecursiveMethod(ReadContainerNode(node.Right), node.Right);
                }
                bool CanSearchOnCenter(CONTAINER_NODE node)
                {
                    return node.HasCenter && this.nodes.Count < this.Count && !this.addresses.Contains(node.Center);
                }
                bool CanSearchOnLeft(CONTAINER_NODE node)
                {
                    return node.HasLeft && this.nodes.Count < this.Count && !this.addresses.Contains(node.Left);
                }
                bool CanSearchOnRight(CONTAINER_NODE node)
                {
                    return node.HasRight && this.nodes.Count < this.Count && !this.addresses.Contains(node.Right);
                }
                #endregion
     
                #region Constructors
                public ContainersHandler()
                {
                    this.addresses = new HashSet<int>();
                    this.nodes = new SortedSet<CONTAINER_NODE>();
                    this.entry = ReadContainersEntry(ReadContainersPointer());
                }
                #endregion
            }
            #endregion
           #region Functions
           public static int Get_Count()
           {
               int count = 0;
               processHandle = Client.Tibia.Handle;
               baseAddress = (int)Client.Tibia.MainModule.BaseAddress.ToInt32();
               ContainersHandler containersHandler = new ContainersHandler();
               count = containersHandler.Count;
               return count;
           }
    
           public static IEnumerable<Container> GetContai()
           {
               processHandle = Client.Tibia.Handle;
               baseAddress = (int)Client.Tibia.MainModule.BaseAddress.ToInt32();
               List<Container> lista_bp = new List<Container>();
               ContainersHandler containersHandler = new ContainersHandler();
               foreach (Container container in containersHandler.Containers())
               {
                   Item[] items = container.Items();
               }
               return containersHandler.Containers();
           }
           #endregion
       }
    }


    Podaj tylko odwołania do adresów u mnie były to Addresses.cs

  3. Reklama
  4. #3
    Avatar Lord
    Data rejestracji
    2012
    Położenie
    CPK xDDD
    Wiek
    29
    Posty
    10,488
    Siła reputacji
    18

    Domyślny

    @arkes ;

    Mam prośbę, wyjaśnij mi m. in. jak wygląda ta struktura, bo nie mam teraz czasu motać się w C#.
    Jest gdzies pointer do nextbp?

  5. #4
    Avatar arkes
    Data rejestracji
    2012
    Posty
    433
    Siła reputacji
    13

    Domyślny

    To jest bodajże inna struktura ja ją tylko przepisywałem z tej tp forumowskiej + dorobiłem funkcje wyciągającą dodatkowe zmienne, pointera tam nie ma wystarczy sam backpack start czy jak to sie tam nazywało...
    Da się to zrobić zapewne inaczej jeszcze ale chyba ta opcja jest najlepsza...

Reklama

Informacje o temacie

Użytkownicy przeglądający temat

Aktualnie 1 użytkowników przegląda ten temat. (0 użytkowników i 1 gości)

Podobne tematy

  1. Poszukiwany grafik - itemy do tibii.
    Przez Carian w dziale Artyści
    Odpowiedzi: 0
    Ostatni post: 17-02-2016, 23:41
  2. Struktura z danej kwoty
    Przez Worst Nightmare w dziale Szkoła i nauka
    Odpowiedzi: 0
    Ostatni post: 09-01-2016, 22:42
  3. Poszukiwany, poszukiwana
    Przez moth w dziale Artyści
    Odpowiedzi: 0
    Ostatni post: 06-10-2013, 22:57
  4. problem z strukturą w c++
    Przez haxigi w dziale Programowanie
    Odpowiedzi: 2
    Ostatni post: 06-06-2013, 17:56
  5. Poszukiwana ekipa do gry! :OO Guardia
    Przez thin w dziale Tibia
    Odpowiedzi: 11
    Ostatni post: 24-05-2012, 10:34

Zakładki

Zakładki

Zasady postowania

  • Nie możesz pisać nowych tematów
  • Nie możesz pisać postów
  • Nie możesz używać załączników
  • Nie możesz edytować swoich postów
  •