-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
104 lines (84 loc) · 3.21 KB
/
main.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
#include <Windows.h>
#include <thread>
#include <iostream>
#include "meta_jni.hpp"
#include "mappings.hpp"
static void mainThread(HMODULE dll)
{
AllocConsole();
FILE* buff1 = nullptr;
freopen_s(&buff1, "CONOUT$", "w", stdout);
JavaVM* jvm = nullptr;
JNI_GetCreatedJavaVMs(&jvm, 1, nullptr);
JNIEnv* env = nullptr;
jvm->AttachCurrentThread((void**)&env, nullptr);
jni::init();
jni::set_thread_env(env); //this is needed for every new thread that uses the lib
env->PushLocalFrame(100); //every local ref created after this will be deleted on PopLocalFrame
maps::Minecraft Minecraft{};
maps::EntityPlayerSP EntityPlayerSP{};
maps::String String{};
std::cout << "injected\n";
std::cout << Minecraft.get_name() << '\n';
std::cout << Minecraft.get_signature() << '\n';
maps::Minecraft theMinecraft = Minecraft.theMinecraft.get();
maps::Minecraft g_theMinecraft = maps::Minecraft(theMinecraft, true);
std::cout << "display width test: " << theMinecraft.displayWidth.get() << '\n';
theMinecraft.displayWidth = 100;
std::cout << "display width test after change: " << theMinecraft.displayWidth.get() << '\n';
theMinecraft.clickMouse();
std::cout << Minecraft.clickMouse.get_signature() << '\n';
theMinecraft.resize(800, 600);
maps::EntityPlayerSP thePlayer = theMinecraft.thePlayer.get();
thePlayer.sendChatMessage(String.create("test"));
maps::String clientBrand = thePlayer.getClientBrand.call();
std::cout << clientBrand.to_string() << '\n';
jni::array<maps::EntityPlayerSP> testArray = jni::array<maps::EntityPlayerSP>::create({});
std::cout << "test array: " << jobject(testArray) << '\n';
maps::WorldClient theWorld = theMinecraft.theWorld.get();
std::vector<maps::EntityPlayer> playerEntities = jni::array<maps::EntityPlayer>(theWorld.playerEntities.get().toArray()).to_vector();
for (maps::EntityPlayer& p : playerEntities)
{
std::cout << p.getName().to_string() << ' ' << p.getHealth() << '\n';
}
env->PopLocalFrame(nullptr);
while (!GetAsyncKeyState(VK_END))
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
jni::shutdown();
jvm->DetachCurrentThread();
fclose(buff1);
FreeConsole();
FreeLibraryAndExitThread(dll, 0);
return;
}
BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved) // reserved
{
// Perform actions based on the reason for calling.
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Return FALSE to fail DLL load.
CloseHandle(CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)mainThread, hinstDLL, 0, 0));
break;
case DLL_THREAD_ATTACH:
// Do thread-specific initialization.
break;
case DLL_THREAD_DETACH:
// Do thread-specific cleanup.
break;
case DLL_PROCESS_DETACH:
if (lpvReserved != nullptr)
{
break; // do not do cleanup if process termination scenario
}
// Perform any necessary cleanup.
break;
}
return TRUE; // Successful DLL_PROCESS_ATTACH.
}