Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ContainersStructure.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <Windows.h>
- #include <iostream>
- #include <TlHelp32.h>
- #include <list>
- #pragma region Structures
- struct ContainersEntry
- {
- int unk[2]; // offset 0, 0x4
- int address; // offset 0x8
- int count; // offset 0xC
- // size = 0x10
- };
- struct ContainerNode
- {
- int left; // offset 0
- int parent; // offset 0x4
- int right; // offset 0x8
- int containerIndex; // offset 0xC
- int containerAddress; // offset 0x10
- // size = 0x14
- };
- struct TibiaColor
- {
- int r; // offset 0
- int g; // offset 0x4
- int b; // offset 0x8
- // size = 0xC
- };
- struct Item
- {
- int unk; // offset 0
- int count; // offset 0x4
- int id; // offset 0x8
- TibiaColor color; // offset 0xC
- int isVisible; // offset 0x18
- // size = 0x1C
- };
- struct StdString
- {
- union
- {
- char buffer[0x10];
- int pointer;
- } field; // offset 0x0, length = 0x10
- int length; // offset 0x10
- int maxLength; // offset 0x14
- int unk; // offset 0x18
- // size = 0x1C
- };
- struct Container
- {
- int index; // offset 0;
- Item asItem; // offset 0x4
- StdString name; // offset 0x20
- int unk; // offset 0x3C
- int slotsCount; // offset 0x40
- int itemsCount; // offset 0x44
- int firstObjectIndex; // offset 0x48
- int itemsAddress; // offset 0x4C
- // size = 0x50
- };
- #pragma endregion
- #pragma region Variables
- #define CONTAINERS_BASE_POINTER 0x5E72C0 // Tibia 10.10
- HANDLE process;
- int baseAddress;
- #pragma endregion
- #pragma region Reading / Converting Memory
- int ReadInt(int address)
- {
- int value;
- ReadProcessMemory(process, (LPCVOID)address, &value, sizeof(int), NULL);
- return value;
- }
- void ReadString(int address, char* buffer, int length)
- {
- ReadProcessMemory(process, (LPCVOID)address, buffer, length, NULL);
- }
- void ConvertToString(StdString stdString, char* buffer, int* length)
- {
- *length = stdString.length;
- if (stdString.maxLength <= 0xF)
- {
- strcpy(buffer, stdString.field.buffer);
- }
- else
- {
- ReadString(stdString.field.pointer, buffer, stdString.length + 1);
- }
- }
- int ReadContainersPointer()
- {
- return ReadInt(CONTAINERS_BASE_POINTER + baseAddress);
- }
- ContainersEntry ReadContainersEntry(int address)
- {
- ContainersEntry value;
- ReadProcessMemory(process, (LPCVOID)(address), &value, sizeof(ContainersEntry), NULL);
- return value;
- }
- ContainerNode ReadContainerNode(int address)
- {
- ContainerNode value;
- ReadProcessMemory(process, (LPCVOID)address, &value, sizeof(ContainerNode), NULL);
- return value;
- }
- Container ReadContainer(int address)
- {
- Container value;
- ReadProcessMemory(process, (LPCVOID)address, &value, sizeof(Container), NULL);
- return value;
- }
- void GetItems(int address, Item* items, int itemsCount)
- {
- ReadProcessMemory(process, (LPCVOID)address, items, itemsCount * sizeof(Item), NULL);
- }
- #pragma endregion
- #pragma region Window / Process Utils
- MODULEENTRY32 GetMainModule(DWORD processId)
- {
- MODULEENTRY32 moduleEntry = {0};
- HANDLE snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId);
- if(!snapShot)
- return moduleEntry;
- moduleEntry.dwSize = sizeof(moduleEntry);
- Module32First(snapShot, &moduleEntry);
- CloseHandle(snapShot);
- return moduleEntry;
- }
- BYTE* GetTibiaBaseAddress(DWORD processId)
- {
- return GetMainModule(processId).modBaseAddr;
- }
- HWND FindTibiaWindow()
- {
- return FindWindow(L"TibiaClient", NULL);
- }
- void OpenTibiaProcess(HWND windowHandle)
- {
- DWORD processId;
- GetWindowThreadProcessId(windowHandle, &processId);
- baseAddress = (int)GetTibiaBaseAddress(processId);
- process = OpenProcess(PROCESS_ALL_ACCESS, false, processId);
- }
- #pragma endregion
- #pragma region Container Utils
- void RecursiveMethod(ContainerNode *node, int entryAddress, std::list<Container> *containers)
- {
- if (node->left != entryAddress)
- {
- ContainerNode leftNode = ReadContainerNode(node->left);
- RecursiveMethod(&leftNode, entryAddress, containers);
- }
- containers->push_back(ReadContainer(node->containerAddress));
- if (node->right != entryAddress)
- {
- ContainerNode rightNode = ReadContainerNode(node->right);
- RecursiveMethod(&rightNode, entryAddress, containers);
- }
- }
- std::list<Container> GetContainers()
- {
- std::list<Container> containers;
- ContainersEntry containersInfo = ReadContainersEntry(ReadContainersPointer());
- if (containersInfo.count > 0)
- {
- ContainerNode entryNode = ReadContainerNode(containersInfo.address);
- entryNode = ReadContainerNode(entryNode.parent);
- RecursiveMethod(&entryNode, containersInfo.address, &containers);
- }
- return containers;
- }
- #pragma endregion
- #pragma region Application Entrypoint
- int _tmain(int argc, _TCHAR* argv[])
- {
- HWND tibiaWindow = FindTibiaWindow();
- if (tibiaWindow)
- {
- OpenTibiaProcess(tibiaWindow);
- char input;
- do
- {
- std::list<Container> containers = GetContainers();
- std::cout << "Containers Count: " << containers.size() << std::endl;
- for (std::list<Container>::const_iterator container = containers.begin(); container != containers.end(); container++)
- {
- Item* items = new Item[container->itemsCount];
- GetItems(container->itemsAddress, items, container->itemsCount);
- char name[32];
- int length;
- ConvertToString(container->name, name, &length);
- printf("\r\nContainer [%d] %s\r\n\r\n", container->asItem.id, name);
- for (int i = 0; i < container->itemsCount; i++)
- printf(" Count: %3d, Id: %5d\r\n", items[i].count, items[i].id);
- delete [] items;
- }
- std::cout << "\r\nPress Y to continue..." << std::endl;
- std::cin >> input;
- std::cout << "\r\n";
- }
- while (input == 'Y' || input == 'y');
- CloseHandle(process);
- }
- else
- {
- std::cout << "Tibia not found.\r\n\r\n";
- }
- system("pause");
- return 0;
- }
- #pragma endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement