aboutsummaryrefslogtreecommitdiff
path: root/MinimapText.cpp
blob: 0153d7784c87eb275a591132b376d84da3d73671 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "MinimapText.h"

#include "Engine.h"
#include "Sdk.h"
#include "Renderer.h"
#include "Utility.h"
#include "Offsets.h"

#include "MidfunctionHook.h"
#include "Patcher.h"

#include <map>

#include "Config.h"

#pragma warning( disable : 4244 )

MidfunctionHook minimapHook;
bool* hookEnabled;
bool displayWood = false;
bool displayFood = false;
bool displayGold = true;
bool displayStone = false;
bool displayPopulation = false;


void __fastcall minimapProxy(Registers* registers)
{
	if (!*hookEnabled)
	{
		return;
	}
	if (!displayWood && !displayFood && !displayGold && !displayStone && !displayPopulation)
	{
		return;
	}

	Player* player = Engine::Get()->GetPlayerByName((char*)registers->rdi);
	if (!player)
	{
		return;
	}

	if (!player->pResources)
	{
		return;
	}

	std::string woodString = std::to_string(((int)player->pResources->wood));
	std::string foodString = std::to_string((int)player->pResources->food);
	std::string goldString = std::to_string((int)player->pResources->gold);
	std::string stoneString = std::to_string((int)player->pResources->stone);
	std::string populationString = std::to_string((int)player->pResources->currentPop) + "/" + std::to_string((int)player->pResources->currentPop + (int)player->pResources->popSpaceLeft);

	std::string newName = std::string(player->name) + " -";
	if (displayWood)
	{
		newName += " Wood: " + woodString;
	}
	if (displayFood)
	{
		newName += " Food: " + foodString;
	}
	if (displayGold)
	{
		newName += " Gold: " + goldString;
	}
	if (displayStone)
	{
		newName += " Stone: " + stoneString;
	}
	if (displayPopulation)
	{
		newName += " Pop: " + populationString;
	}
	MidfunctionHook::OverwriteRegister(registers->rsp, Register::RDI, (int64_t)newName.c_str());
}

void MinimapText::LoadConfig()
{
	Config* config = Config::Get();
	*hookEnabled = config->ReadInt("MinimapText", "hookEnabled");
	displayWood = config->ReadInt("MinimapText", "displayWood");
	displayFood = config->ReadInt("MinimapText", "displayFood");
	displayGold = config->ReadInt("MinimapText", "displayGold");
	displayStone = config->ReadInt("MinimapText", "displayStone");
	displayPopulation = config->ReadInt("MinimapText", "displayPopulation");
}

void MinimapText::SaveConfig()
{
	Config* config = Config::Get();
	config->Write<int>("MinimapText", "hookEnabled", *hookEnabled);
	config->Write<int>("MinimapText", "displayWood", displayWood);
	config->Write<int>("MinimapText", "displayFood", displayFood);
	config->Write<int>("MinimapText", "displayGold", displayGold);
	config->Write<int>("MinimapText", "displayStone", displayStone);
	config->Write<int>("MinimapText", "displayPopulation", displayPopulation);
}

void MinimapText::OnInitialise()
{
	hookEnabled = &enabled;

	minimapHook.Hook((BYTE*)(int64_t)GetModuleHandle(NULL) + Offsets::minimapHookOffset, (BYTE*)minimapProxy, 20);
}

void MinimapText::OnShutdown()
{
	minimapHook.Unhook();
}

void MinimapText::OnMenuMainWindow()
{
	ImGui::Separator();
	ImGui::Checkbox("Minimap Ressource Information", &enabled);
	ImGui::Checkbox("Wood##Minimap", &displayWood);
	ImGui::SameLine();
	ImGui::Checkbox("Food##Minimap", &displayFood);
	ImGui::SameLine();
	ImGui::Checkbox("Gold##Minimap", &displayGold);
	ImGui::SameLine();
	ImGui::Checkbox("Stone##Minimap", &displayStone);
	ImGui::SameLine();
	ImGui::Checkbox("Population##Minimap", &displayPopulation);
	ImGui::Separator();
}