forked from Andoryuuta/cwsdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdllmain.cpp
153 lines (125 loc) · 4.05 KB
/
dllmain.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <windows.h>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdint>
#include <sstream>
#include <vector>
#include <bitset>
#include <map>
#include "cwsdk.h"
// Open new console for c(in/out/err)
void OpenConsole()
{
AllocConsole();
FILE* cinStream;
FILE* coutStream;
FILE* cerrStream;
freopen_s(&cinStream, "CONIN$", "r", stdin);
freopen_s(&coutStream, "CONOUT$", "w", stdout);
freopen_s(&cerrStream, "CONOUT$", "w", stderr);
}
// Prints the world map of `cube::Creature`s.
void print_entities() {
auto gc = cube::GetGameController();
auto stdMap = gc->world.EntitesMap->CopyToSTDMap();
for (auto const& x : stdMap)
{
auto key = x.first;
auto val = x.second;
std::cout << "cube::Creature addr: " << std::hex << val << std::endl;
std::wcout << L"\tName: " << val->GetName() << std::endl;
std::cout << "\tGUID: " << std::dec << val->GUID << std::endl;
std::cout << "\tShown on map / Objective boss:" << (val->entity_data.appearance.movement_flags & 0x2000) << std::endl;
std::cout << "\thostility_flags: " << std::hex << std::bitset<32>(val->entity_data.hostility_flags) << std::endl;
std::cout << "\tmovement_flags: " << std::hex << std::bitset<32>(val->entity_data.appearance.movement_flags) << std::endl;
if (key != gc->local_player->GUID) {
//val->parent_owner = gc->local_player->GUID;
std::cout << "\tdistance in blocks:" << std::dec << gc->local_player->DistanceFrom(val) / 65536 << std::endl;
//val->hostility_flags = 0x0;
}
}
}
void add_petfood() {
auto gc = cube::GetGameController();
// Get our current zone.
int zone_x = (gc->local_player->entity_data.position.X / 65536) / 256;
int zone_y = (gc->local_player->entity_data.position.Y / 65536) / 256;
cube::Zone* cur_zone = gc->world.GetZone(zone_x, zone_y);
gc->world.Lock();
for (int i = 0; i <= 155; i++) {
// make the pickupable_object and use the game's default constructor for init values.
zone_pickupable_object obj;
// Make the petfood item(s)
obj.item.category_id = 20;
obj.item.item_id = i;
obj.position = gc->local_player->entity_data.position;
obj.position.X += (i - 5) * 65536; // offset by 5 blocks every iteration
// append the object to the zones objects vector.
cur_zone->pickupable_objects.push_back(obj);
}
gc->world.Unlock();
}
DWORD WINAPI MyFunc(LPVOID lpvParam) {
OpenConsole();
cube::InitGlobals();
auto gc = cube::GetGameController();
print_entities();
try
{
while (true) {
//std::cout << GetAsyncKeyState((int)'H') << std::endl;
if (GetAsyncKeyState((int)'H')) {// & 0x8000) {
cube::Creature* creature = cube::util::SpawnMonster(gc->local_player->entity_data.position, cube::Creature::Race::Cow, 1, gc->local_player->entity_data.level);
gc->ChatWidget->Print(L"Spawned ", Color::White());
gc->ChatWidget->Print(creature->GetName(), Color::Green());
gc->ChatWidget->Print(L"\n", Color::White());
Sleep(250);
}
if (GetAsyncKeyState((int)'N')) {
add_petfood();
gc->ChatWidget->Print(L"Spawned petfood objects.\n", Color::White());
Sleep(1000);
}
if (GetAsyncKeyState((int)'J') && 0x8000) {
gc->ChatWidget->Print(L"Ending cwsdk test.\n", Color::Blue());
std::cout << "Exit!" << std::endl;
break;
}
// Clear chat
if (GetAsyncKeyState((int)'W') && 0x8000) {
gc->ChatWidget->Print(L"\n", Color::White());
gc->ChatWidget->Print(L"\n", Color::White());
gc->ChatWidget->Print(L"\n", Color::White());
gc->ChatWidget->Print(L"\n", Color::White());
gc->ChatWidget->Print(L"\n", Color::White());
gc->ChatWidget->Print(L"\n", Color::White());
gc->ChatWidget->Print(L"\n", Color::White());
}
}
Sleep(20);
}
catch (const std::exception&)
{
std::cout << "got exception" << std::endl;
}
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(NULL, 0, MyFunc, 0, 0, NULL);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}