#include "pch.h"
#include <jni.h>
#include <iostream>
#include "MinecraftMappings.h"
using namespace std;
JavaVM* g_jvm = nullptr;
JNIEnv* g_env = nullptr;
void InitConsole() {
AllocConsole();
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
freopen_s(&fDummy, "CONOUT$", "w", stderr);
freopen_s(&fDummy, "CONIN$", "r", stdin);
std::cout.clear();
std::clog.clear();
std::cerr.clear();
std::cin.clear();
SetConsoleTitleA("Minecraft JNI Cheat - Debug Console");
std::cout << "[+] Console initialized!" << std::endl;
}
bool InitJNI() {
std::cout << "[*] Initializing JNI..." << std::endl;
JavaVM* jvmBuf[1];
jsize nVMs;
jint result = JNI_GetCreatedJavaVMs(jvmBuf, 1, &nVMs);
if (result != JNI_OK || nVMs == 0) {
std::cerr << "Failed to find JavaVM! Error: " << result << std::endl;
return false;
}
g_jvm = jvmBuf[0];
std::cout << "JavaVM found: 0x" << std::hex << (uintptr_t)g_jvm << std::dec << std::endl;
// Attach current thread to JVM
result = g_jvm->AttachCurrentThread((void**)&g_env, nullptr);
if (result != JNI_OK) {
std::cerr << "Failed to attach thread!Error: " << result << std::endl;
return false;
}
std::cout << "Thread attached to JVM" << std::endl;
std::cout << "JNIEnv ready: 0x" << std::hex << (uintptr_t)g_env << std::dec << std::endl;
return true;
}
// Main cheat thread
DWORD WINAPI MainThread(LPVOID lpParam) {
InitConsole();
std::cout << "========================================" << std::endl;
std::cout << " Minecraft JNI Client" << std::endl;
std::cout << "========================================" << std::endl;
Sleep(500);
if (!InitJNI()) {
std::cerr << "!JNI" << std::endl;
Sleep(3000);
FreeConsole();
FreeLibraryAndExitThread((HMODULE)lpParam, 0);
return 1;
}
std::cout << "\n[+] JNI initialized successfully!" << std::endl;
std::cout << "\n[*] Press END to unload cheat..." << std::endl;
std::cout << "========================================\n" << std::endl;
// ============================================
// ============================================
//instance
jclass mcClass = g_env->FindClass("net/minecraft/client/Minecraft");
if (!mcClass) {
cout << "!mineClass" << endl;
}
else {
cout << "mcClass getted" << endl;
jmethodID IDgetInstance = g_env->GetStaticMethodID(mcClass, MC::Methods::GET_INSTANCE, MC::Signatures::GET_INSTANCE_RET);
if (!IDgetInstance) {
cout << "!IDgetInstance" << endl;
}
else {
cout << "IDgetInstance getted" << endl;
jobject getInstance = g_env->CallStaticObjectMethod(mcClass, IDgetInstance);
if (!getInstance) {
cout << "!getInstance" << endl;
}
else {
cout << "Succesful getted Instance!" << endl;
}
}
}
while (true) {
if (GetAsyncKeyState(VK_END) & 1) {
std::cout << "[*] Unloading..." << std::endl;
break;
}
Sleep(100);
}
// ============================================
// ============================================
if (g_jvm && g_env) {
g_jvm->DetachCurrentThread();
std::cout << "[+] Detached from JVM" << std::endl;
}
std::cout << "[+] Cheat unloaded" << std::endl;
Sleep(1000);
FreeConsole();
FreeLibraryAndExitThread((HMODULE)lpParam, 0);
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
CreateThread(nullptr, 0, MainThread, hModule, 0, nullptr);
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}