├── .gitignore ├── LICENSE ├── README.md ├── UDP.sln └── UDP ├── UDP.cpp ├── UDP.h ├── dllmain.cpp ├── mapping ├── AbstractClass.cpp ├── AbstractClass.h ├── CM.h ├── Mapping.cpp ├── Mapping.h ├── Mem.h └── impl │ ├── Entity.cpp │ ├── Entity.h │ ├── EntityPlayerSP.cpp │ ├── EntityPlayerSP.h │ ├── JavaList.cpp │ ├── JavaList.h │ ├── JavaSet.cpp │ ├── JavaSet.h │ ├── Minecraft.cpp │ ├── Minecraft.h │ ├── WorldClient.cpp │ └── WorldClient.h ├── stdafx.cpp ├── stdafx.h ├── targetver.h └── util └── MathHelper.h /.gitignore: -------------------------------------------------------------------------------- 1 | /UDP/ipch/ 2 | /UDP/x64/ 3 | /ipch/ 4 | /x64/ 5 | 6 | *.dll 7 | *.lib 8 | *.vcxproj 9 | *.filters 10 | *.user 11 | *.db 12 | *.opendb 13 | *.suo 14 | *.sln -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 DoubleParallax 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unknown Detection Party 2 | ### A Minecraft Cheat in C++ 3 | 4 | ![](https://i.imgur.com/LhpA6Kl.png) 5 | 6 | Nothing big, just a small intro for (s)kids wanting to make C++ injection clients (and no, this doesn't involve any Java code) 7 | 8 | The code is a mess, I already know, so don't bother ripping into me. I don't like C++, I don't aspire to be good in C++, I just do what works, and I never intend to make anything commercial either, so it really doesn't matter to me 9 | 10 | Happy skidding! 11 | 12 | ### Getting Started With a Fresh Project 13 | 14 | You can either follow the text instructions below or [follow them via video](https://www.youtube.com/watch?v=rr_QV16jktw). 15 | 16 | - If you haven't already, install Visual Studio (If you already have a x64 C++ compile setup, just use that, but the next few steps will be for VS) 17 | - Start VS, and create a new project. Make sure to select `Visual C++ >> Windows Desktop >> Dynamic-Link Library (DLL)` as the project type. Give it a name and location, and create it 18 | - You can probably just delete the file it creates named `.cpp` as you'll either create another later, or do everything in the `dllmain.cpp` file 19 | - Now that you have a base location for your project, locate your JDK installation (Somewhere around `C:\Program Files\Java\jdk1.8.0_xxx\`) 20 | - Locate the `jvm.lib` library inside the JDK installation (`.\lib\jvm.lib`) 21 | - Locate the `jvm.dll` dll inside the JDK installation (`.\jre\bin\jvm.dll`) 22 | - Copy the two located files into your project's code directory (`.\Project Name\Project Name\`, it should be the place where all the `.cpp` and `.h` files are) 23 | - Head back to VS, click `Build >> Properties` in the toolbar at the top 24 | - Switch the `"Platform"` to (if it's not already) `x64` since Minecraft runs in 64bit, and your DLL just won't work otherwise 25 | - In the left panel, open `VC++ Directories`. It should be the third one down (unless I'm just special) 26 | - Click in the first entry field: `Executable Directories`, and click the dropdown on the right, then `` 27 | - Click the first icon in the top left to create a new entry (do this twice, once after the first) 28 | - For the first one, put the following: `\include`, and for the second: `\include\win32` 29 | - Now, in the panel on the left, open the `Linker` node, and open `Input`. 30 | - Just like the dependencies, click the `Additional Dependencies` entry field, click the dropdown, edit, and then enter `jvm.lib` and click ok 31 | - Next, in the `dllmain.cpp` file, put the following: 32 | ```cpp 33 | //Required libraries 34 | #include 35 | #include 36 | 37 | /* 38 | Handle the base injection in the newly created thread (if injection was successful) 39 | Allocates a new console window to the application and routes stdin, stdout, and 40 | stderr to the console. This prevents any debugging being mixed in with Minecraft's 41 | output window 42 | */ 43 | void inject() { 44 | AllocConsole(); 45 | FILE* fIn; 46 | FILE* fOut; 47 | freopen_s(&fIn, "conin$", "r", stdin); 48 | freopen_s(&fOut, "conout$", "w", stdout); 49 | freopen_s(&fOut, "conout$", "w", stderr); 50 | 51 | std::cout << "Injection Successful!" << std::endl; 52 | } 53 | 54 | /* 55 | Entry point function for the DLL 56 | If it has just been attached, create a new process thread and run the "inject" function 57 | */ 58 | BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { 59 | if (fdwReason == DLL_PROCESS_ATTACH) 60 | CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)inject, nullptr, 0, nullptr); 61 | return TRUE; 62 | } 63 | ``` 64 | - Change the compile mode at the top of Visual Studio to x64, and build the DLL (`Ctrl + Shift + B`) 65 | 66 | You should now have a built DLL to inject straight into Minecraft, and watch the magic unfold! 67 | 68 | ### Disclaimer 69 | 70 | The code is shit, there's countless things I could do to improve the functionality (including toggle for the aimbot), but I really couldn't care less, so don't bother saying it's shit cause I'll just screenshot this disclaimer and link you to Chum Drum Bedrum 71 | -------------------------------------------------------------------------------- /UDP.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UDP", "UDP\UDP.vcxproj", "{D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}.Debug|x64.ActiveCfg = Debug|x64 17 | {D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}.Debug|x64.Build.0 = Debug|x64 18 | {D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}.Debug|x86.ActiveCfg = Debug|Win32 19 | {D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}.Debug|x86.Build.0 = Debug|Win32 20 | {D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}.Release|x64.ActiveCfg = Release|x64 21 | {D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}.Release|x64.Build.0 = Release|x64 22 | {D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}.Release|x86.ActiveCfg = Release|Win32 23 | {D00485CB-DCF3-4DEB-BB17-F4D0E61D9ABA}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {49EC6E8D-ADCB-4706-A108-56540A0C2BA9} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /UDP/UDP.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UDP.h" 3 | #include "util/MathHelper.h" 4 | #include "mapping/impl/JavaList.h" 5 | #include "mapping/impl/Minecraft.h" 6 | #include "mapping/impl/EntityPlayerSP.h" 7 | #include "mapping/impl/WorldClient.h" 8 | #include "mapping/impl/Entity.h" 9 | 10 | UDP::UDP() 11 | { 12 | //Get the JVM and JNI environment 13 | jsize count; 14 | if (JNI_GetCreatedJavaVMs(&jvm, 1, &count) != JNI_OK || count == 0) { 15 | std::cout << "Failed to get the JVM" << std::endl; 16 | return; 17 | } 18 | jint res = jvm->GetEnv((void **)&env, JNI_VERSION_1_6); 19 | if (res == JNI_EDETACHED) 20 | res = jvm->AttachCurrentThread((void **)&env, nullptr); 21 | if (res != JNI_OK) { 22 | std::cout << "Failed to attach to thread" << std::endl; 23 | return; 24 | } 25 | std::cout << "Attached to JVM" << std::endl; 26 | 27 | //Get the Minecraft instance 28 | Minecraft * mc = new Minecraft(this); 29 | 30 | // Infininte loop, very error-prone but good enough for the purpose of showiing that it works. 31 | // 32 | // In this case there is no null checking, so this will crash if the world is null, 33 | // so inject while in-game. This will crash if you leave. 34 | // 35 | while (true) { 36 | // This is in the loop so that the instances are current. IE, joining a new world not trying to reference the old one. 37 | EntityPlayerSP * player = mc->getPlayerContainer(); 38 | WorldClient * world = mc->getWorldContainer(); 39 | // Ensure the player an world are not null (IE, check if in-game) 40 | if (player == nullptr || world == nullptr) { 41 | Sleep(1000); 42 | } 43 | //Get all the entities, calculate the closest one 44 | JavaSet * entities = world->getEntities(); 45 | double dist = 6; 46 | Entity * closest = nullptr; 47 | for (int i = 0; i < entities->size(); i++) { 48 | Entity * entity = new Entity(this, mc, entities->get(i)); 49 | if (entity->getId() != player->getId()) { 50 | double newDist = MathHelper::distance(entity->getPosX(), entity->getPosY(), entity->getPosZ(), player->getPosX(), player->getPosY(), player->getPosZ()); 51 | if (newDist < dist) { 52 | dist = newDist; 53 | closest = entity; 54 | } 55 | } 56 | } 57 | 58 | //If there is an entity in range, look at it 59 | if (closest != nullptr) { 60 | double * rotation = MathHelper::direction(player->getPosX(), player->getPosY(), player->getPosZ(), closest->getPosX(), closest->getPosY(), closest->getPosZ()); 61 | player->setRotationYaw(rotation[0]); 62 | player->setRotationPitch(rotation[1]); 63 | } 64 | 65 | //Sleep cause I'm tired 66 | Sleep(1000 / 60); 67 | } 68 | } 69 | 70 | JavaVM * UDP::getJvm() { 71 | return jvm; 72 | } 73 | 74 | JNIEnv * UDP::getEnv() { 75 | return env; 76 | } -------------------------------------------------------------------------------- /UDP/UDP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | class UDP 6 | { 7 | public: 8 | UDP(); 9 | JavaVM * getJvm(); 10 | JNIEnv * getEnv(); 11 | private: 12 | JavaVM * jvm; 13 | JNIEnv * env; 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /UDP/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnknownDetectionParty/UDP-CPP/018233f85f81ac0c2f7ccd780844be8a8102d39a/UDP/dllmain.cpp -------------------------------------------------------------------------------- /UDP/mapping/AbstractClass.cpp: -------------------------------------------------------------------------------- 1 | #include "AbstractClass.h" 2 | 3 | AbstractClass::AbstractClass(UDP * udp, const char * clsName) 4 | { 5 | this->udp = udp; 6 | this->clsKey = clsName; 7 | 8 | //Find each class that inherits AbstractClass by the class name provided 9 | cls = udp->getEnv()->FindClass(Mapping::getClassName(clsName)); 10 | 11 | //Check for exceptions. I got lazy, and this is the only time I actually check for errors 12 | //Basically, checks if there's an error, prints the stack trace to the console, then clears the error 13 | if (udp->getEnv()->ExceptionCheck()) { 14 | udp->getEnv()->ExceptionDescribe(); 15 | udp->getEnv()->ExceptionClear(); 16 | } 17 | } -------------------------------------------------------------------------------- /UDP/mapping/AbstractClass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../stdafx.h" 5 | #include "../UDP.h" 6 | #include "Mapping.h" 7 | #include "CM.h" 8 | #include "Mem.h" 9 | 10 | class AbstractClass 11 | { 12 | public: 13 | AbstractClass(UDP * udp, const char * clsName); 14 | 15 | //This stuff is just to make using JNI easier (it's already easy, just likes to be easier) 16 | //It doesn't cover everything, but covers most basic shit 17 | 18 | //Boolean 19 | template jboolean getBoolean(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallBooleanMethod(parent, method, values); } 20 | template jboolean getBoolean(jmethodID method, T values...) { return udp->getEnv()->CallStaticBooleanMethod(cls, method, values); } 21 | jboolean getBoolean(jobject parent, jmethodID method) { return udp->getEnv()->CallBooleanMethod(parent, method); } 22 | jboolean getBoolean(jmethodID method) { return udp->getEnv()->CallStaticBooleanMethod(cls, method); } 23 | jboolean getBoolean(jobject parent, jfieldID field) { return udp->getEnv()->GetBooleanField(parent, field); } 24 | jboolean getBoolean(jfieldID field) { return udp->getEnv()->GetStaticBooleanField(cls, field); } 25 | 26 | //Byte 27 | template jbyte getByte(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallByteMethod(parent, method, values); } 28 | template jbyte getByte(jmethodID method, T values...) { return udp->getEnv()->CallStaticByteMethod(cls, method, values); } 29 | jbyte getByte(jobject parent, jmethodID method) { return udp->getEnv()->CallByteMethod(parent, method); } 30 | jbyte getByte(jmethodID method) { return udp->getEnv()->CallStaticByteMethod(cls, method); } 31 | jbyte getByte(jobject parent, jfieldID field) { return udp->getEnv()->GetByteField(parent, field); } 32 | jbyte getByte(jfieldID field) { return udp->getEnv()->GetStaticByteField(cls, field); } 33 | 34 | //Char 35 | template jchar getChar(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallCharMethod(parent, method, values); } 36 | template jchar getChar(jmethodID method, T values...) { return udp->getEnv()->CallStaticCharMethod(cls, method, values); } 37 | jchar getChar(jobject parent, jmethodID method) { return udp->getEnv()->CallCharMethod(parent, method); } 38 | jchar getChar(jmethodID method) { return udp->getEnv()->CallStaticCharMethod(cls, method); } 39 | jchar getChar(jobject parent, jfieldID field) { return udp->getEnv()->GetCharField(parent, field); } 40 | jchar getChar(jfieldID field) { return udp->getEnv()->GetStaticCharField(cls, field); } 41 | 42 | //Short 43 | template jshort getShort(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallShortMethod(parent, method, values); } 44 | template jshort getShort(jmethodID method, T values...) { return udp->getEnv()->CallStaticShortMethod(cls, method, values); } 45 | jshort getShort(jobject parent, jmethodID method) { return udp->getEnv()->CallShortMethod(parent, method); } 46 | jshort getShort(jmethodID method) { return udp->getEnv()->CallStaticShortMethod(cls, method); } 47 | jshort getShort(jobject parent, jfieldID field) { return udp->getEnv()->GetShortField(parent, field); } 48 | jshort getShort(jfieldID field) { return udp->getEnv()->GetStaticShortField(cls, field); } 49 | 50 | //Int 51 | template jint getInt(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallIntMethod(parent, method, values); } 52 | template jint getInt(jmethodID method, T values...) { return udp->getEnv()->CallStaticIntMethod(cls, method, values); } 53 | jint getInt(jobject parent, jmethodID method) { return udp->getEnv()->CallIntMethod(parent, method); } 54 | jint getInt(jmethodID method) { return udp->getEnv()->CallStaticIntMethod(cls, method); } 55 | jint getInt(jobject parent, jfieldID field) { return udp->getEnv()->GetIntField(parent, field); } 56 | jint getInt(jfieldID field) { return udp->getEnv()->GetStaticIntField(cls, field); } 57 | 58 | //Long 59 | template jlong getLong(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallLongMethod(parent, method, values); } 60 | template jlong getLong(jmethodID method, T values...) { return udp->getEnv()->CallStaticLongMethod(cls, method, values); } 61 | jlong getLong(jobject parent, jmethodID method) { return udp->getEnv()->CallLongMethod(parent, method); } 62 | jlong getLong(jmethodID method) { return udp->getEnv()->CallStaticLongMethod(cls, method); } 63 | jlong getLong(jobject parent, jfieldID field) { return udp->getEnv()->GetLongField(parent, field); } 64 | jlong getLong(jfieldID field) { return udp->getEnv()->GetStaticLongField(cls, field); } 65 | 66 | //Float 67 | template jfloat getFloat(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallFloatMethod(parent, method, values); } 68 | template jfloat getFloat(jmethodID method, T values...) { return udp->getEnv()->CallStaticFloatMethod(cls, method, values); } 69 | jfloat getFloat(jobject parent, jmethodID method) { return udp->getEnv()->CallFloatMethod(parent, method); } 70 | jfloat getFloat(jmethodID method) { return udp->getEnv()->CallStaticFloatMethod(cls, method); } 71 | jfloat getFloat(jobject parent, jfieldID field) { return udp->getEnv()->GetFloatField(parent, field); } 72 | jfloat getFloat(jfieldID field) { return udp->getEnv()->GetStaticFloatField(cls, field); } 73 | 74 | //Double 75 | template jdouble getDouble(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallDoubleMethod(parent, method, values); } 76 | template jdouble getDouble(jmethodID method, T values...) { return udp->getEnv()->CallStaticDoubleMethod(cls, method, values); } 77 | jdouble getDouble(jobject parent, jmethodID method) { return udp->getEnv()->CallDoubleMethod(parent, method); } 78 | jdouble getDouble(jmethodID method) { return udp->getEnv()->CallStaticDoubleMethod(cls, method); } 79 | jdouble getDouble(jobject parent, jfieldID field) { return udp->getEnv()->GetDoubleField(parent, field); } 80 | jdouble getDouble(jfieldID field) { return udp->getEnv()->GetStaticDoubleField(cls, field); } 81 | 82 | //Object 83 | template jobject getObject(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallObjectMethod(parent, method, values); } 84 | template jobject getObject(jmethodID method, T values...) { return udp->getEnv()->CallStaticObjectMethod(cls, method, values); } 85 | jobject getObject(jobject parent, jmethodID method) { return udp->getEnv()->CallObjectMethod(parent, method); } 86 | jobject getObject(jmethodID method) { return udp->getEnv()->CallStaticObjectMethod(cls, method); } 87 | jobject getObject(jobject parent, jfieldID field) { return udp->getEnv()->GetObjectField(parent, field); } 88 | jobject getObject(jfieldID field) { return udp->getEnv()->GetStaticObjectField(cls, field); } 89 | 90 | //Array 91 | int getArrayLength(jobjectArray arr) { return udp->getEnv()->GetArrayLength(arr); } 92 | jobject getArrayElement(jobjectArray arr, jsize index) { return udp->getEnv()->GetObjectArrayElement(arr, index); } 93 | 94 | //Void 95 | template void callMethod(jobject parent, jmethodID method, T values...) { return udp->getEnv()->CallVoidMethod(parent, method, values); } 96 | template void callMethod(jmethodID method, T values...) { return udp->getEnv()->CallStaticVoidMethod(cls, method, values); } 97 | void callMethod(jobject parent, jmethodID method) { return udp->getEnv()->CallVoidMethod(parent, method); } 98 | void callMethod(jmethodID method) { return udp->getEnv()->CallStaticVoidMethod(cls, method); } 99 | 100 | void setBoolean(jobject parent, jfieldID field, jboolean value) { udp->getEnv()->SetBooleanField(parent, field, value); } 101 | void setBoolean(jfieldID field, jboolean value) { udp->getEnv()->SetStaticBooleanField(cls, field, value); } 102 | 103 | void setByte(jobject parent, jfieldID field, jbyte value) { udp->getEnv()->SetByteField(parent, field, value); } 104 | void setByte(jfieldID field, jbyte value) { udp->getEnv()->SetStaticByteField(cls, field, value); } 105 | 106 | void setChar(jobject parent, jfieldID field, jchar value) { udp->getEnv()->SetCharField(parent, field, value); } 107 | void setChar(jfieldID field, jchar value) { udp->getEnv()->SetStaticCharField(cls, field, value); } 108 | 109 | void setShort(jobject parent, jfieldID field, jshort value) { udp->getEnv()->SetShortField(parent, field, value); } 110 | void setShort(jfieldID field, jshort value) { udp->getEnv()->SetStaticShortField(cls, field, value); } 111 | 112 | void setInt(jobject parent, jfieldID field, jint value) { udp->getEnv()->SetIntField(parent, field, value); } 113 | void setInt(jfieldID field, jint value) { udp->getEnv()->SetStaticIntField(cls, field, value); } 114 | 115 | void setLong(jobject parent, jfieldID field, jlong value) { udp->getEnv()->SetLongField(parent, field, value); } 116 | void setLong(jfieldID field, jlong value) { udp->getEnv()->SetStaticLongField(cls, field, value); } 117 | 118 | void setFloat(jobject parent, jfieldID field, jfloat value) { udp->getEnv()->SetFloatField(parent, field, value); } 119 | void setFloat(jfieldID field, jfloat value) { udp->getEnv()->SetStaticFloatField(cls, field, value); } 120 | 121 | void setDouble(jobject parent, jfieldID field, jdouble value) { udp->getEnv()->SetDoubleField(parent, field, value); } 122 | void setDouble(jfieldID field, jdouble value) { udp->getEnv()->SetStaticDoubleField(cls, field, value); } 123 | 124 | protected: 125 | const char* clsKey; 126 | UDP * udp; 127 | jclass cls; 128 | // Field getter that uses the mapping class so only a clear-text name needs to be defined. 129 | // "name" : Clear-text name used by 'Mapping.h' to define the field. 130 | // Return: JNI field wrapper 131 | jfieldID getFieldID(const char * name) { 132 | CM* cm = Mapping::getClass(clsKey); 133 | Mem field = cm->fields.at(std::string(name)); 134 | return getFieldID(field.name, field.desc, field.isStatic); 135 | } 136 | // Method getter that uses the mapping class so only a clear-text name needs to be defined. 137 | // "name" : Clear-text name used by 'Mapping.h' to define the method. 138 | // Return: JNI method wrapper 139 | jmethodID getMethodID(const char * name) { 140 | CM* cm = Mapping::getClass(clsKey); 141 | Mem method = cm->methods.at(std::string(name)); 142 | return getMethodID(method.name, method.desc, method.isStatic); 143 | } 144 | private: 145 | // Return: JNI field wrapper 146 | jfieldID getFieldID(const char * name, 147 | const char * sig, bool _static) { 148 | return _static ? udp->getEnv()->GetStaticFieldID(cls, name, sig) : udp->getEnv()->GetFieldID(cls, name, sig); 149 | } 150 | // Return: JNI method wrapper 151 | jmethodID getMethodID(const char * name, 152 | const char * sig, bool _static) { 153 | return _static ? udp->getEnv()->GetStaticMethodID(cls, name, sig) : udp->getEnv()->GetMethodID(cls, name, sig); 154 | } 155 | }; 156 | 157 | -------------------------------------------------------------------------------- /UDP/mapping/CM.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Mem.h" 5 | 6 | struct CM { 7 | char* name; 8 | std::map fields; 9 | std::map methods; 10 | CM(char* clsName) : name(clsName) {} 11 | }; -------------------------------------------------------------------------------- /UDP/mapping/Mapping.cpp: -------------------------------------------------------------------------------- 1 | #include "Mapping.h" 2 | std::map lookup; -------------------------------------------------------------------------------- /UDP/mapping/Mapping.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "CM.h" 5 | #include "Mem.h" 6 | #include 7 | 8 | // Map of class names to mapping structures 9 | extern std::map lookup; 10 | 11 | // Basic centralization of mappings. 12 | // Current implementation is not ideal, but better than per-file mappings. 13 | class Mapping 14 | { 15 | public: 16 | Mapping() { 17 | // Populate the map 18 | setup(); 19 | } 20 | 21 | static CM* getClass(const char* key) { 22 | CM* cm = lookup.at(std::string(key)); 23 | return cm; 24 | } 25 | 26 | static const char* getClassName(const char* key) { 27 | return getClass(key)->name; 28 | } 29 | private: 30 | static void setup() { 31 | // How to define mappings: 32 | // --- Unobfuscated classes: 33 | // 34 | // Creating mappings for a class: 35 | // 36 | // SimpleID, InternalName 37 | // m = make("Set", "java/util/Set"); 38 | // 39 | // Adding a member to the class: 40 | // MappingInst, MethodName, InternalDescriptor, IsStatic 41 | // method(m, "get", "(I)Ljava/lang/Object;", false); 42 | // 43 | // ------------------------- 44 | // 45 | // base - normal jvm classes 46 | struct CM* m = make("List", "java/util/List"); 47 | method(m, "get", "(I)Ljava/lang/Object;", false); 48 | method(m, "toArray", "()[Ljava/lang/Object;", false); 49 | method(m, "size", "()I", false); 50 | m = make("Set", "java/util/Set"); 51 | method(m, "toArray", "()[Ljava/lang/Object;", false); 52 | method(m, "size", "()I", false); 53 | // How to define mappings: 54 | // --- Obfuscated classes: 55 | // 56 | // Creating mappings for a class: 57 | // 58 | // SimpleID, ObfuscatedName 59 | // m = make("Entity", "v"); 60 | // 61 | // Adding a member to the class: 62 | // MappingInst, SimpleID, ObfuscatedName, ObfuscatedDescriptor, IsStatic 63 | // method(m, "getID", "S", "()I", false); 64 | // 65 | // ----------------------------------- 66 | // 67 | // obfuscated minecraft classes - 1.12 68 | m = make("Entity", "ve"); 69 | field(m, "x", "p", "D", false); 70 | field(m, "y", "q", "D", false); 71 | field(m, "z", "r", "D", false); 72 | method(m, "getID", "S", "()I", false); 73 | method(m, "getName", "h_", "()Ljava/lang/String;", false); 74 | m = make("WorldClient", "brz"); 75 | field(m, "entities", "K", "Ljava/util/Set;", false); 76 | method(m, "setTime", "b", "(J)V", false); 77 | m = make("PlayerSP", "bub"); 78 | field(m, "x", "p", "D", false); 79 | field(m, "y", "q", "D", false); 80 | field(m, "z", "r", "D", false); 81 | field(m, "yaw", "v", "F", false); 82 | field(m, "pitch", "w", "F", false); 83 | method(m, "getID", "S", "()I", false); 84 | method(m, "getName", "h_", "()Ljava/lang/String;", false); 85 | method(m, "setSprint", "f", "(Z)V", false); 86 | m = make("Minecraft", "bhz"); 87 | field(m, "player", "h", "Lbub;", false); 88 | field(m, "world", "f", "Lbrz;", false); 89 | method(m, "getMinecraft", "z", "()Lbhz;", true); 90 | } 91 | 92 | static void field(CM *cm, char* name, char* desc, bool isStatic) { 93 | field(cm, name, name, desc, isStatic); 94 | } 95 | 96 | static void method(CM *cm, char* name, char* desc, bool isStatic) { 97 | method(cm, name, name, desc, isStatic); 98 | } 99 | 100 | static void field(CM *cm, char* keyName, char* obName, char* desc, bool isStatic) { 101 | std::cout << " Mapping " << obName << " to " << keyName << std::endl; 102 | Mem *m = new Mem(obName, desc, isStatic); 103 | cm->fields.insert(std::make_pair(std::string(keyName), *m)); 104 | } 105 | 106 | static void method(CM *cm, char* keyName, char* obName, char* desc, bool isStatic) { 107 | std::cout << " Mapping " << obName << desc << " to " << keyName << std::endl; 108 | Mem *m = new Mem(obName, desc, isStatic); 109 | cm->methods.insert(std::make_pair(std::string(keyName), *m)); 110 | } 111 | 112 | static CM* make(char* key, char* name) { 113 | //struct CM cm(name); 114 | struct CM *cm = new CM(name); 115 | std::cout << "Mapping " << name << " to " << key << std::endl; 116 | lookup.insert(std::make_pair(std::string(key), cm)); 117 | return cm; 118 | } 119 | }; -------------------------------------------------------------------------------- /UDP/mapping/Mem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | struct Mem { 3 | char* name; 4 | char* desc; 5 | bool isStatic; 6 | Mem(char* memName, char* memDesc, bool stat) : name(memName), desc(memDesc), isStatic(stat) {} 7 | }; -------------------------------------------------------------------------------- /UDP/mapping/impl/Entity.cpp: -------------------------------------------------------------------------------- 1 | #include "Minecraft.h" 2 | #include "Entity.h" 3 | 4 | Entity::Entity(UDP * udp, Minecraft * mc, jobject entity) : AbstractClass::AbstractClass(udp, "Entity") 5 | { 6 | this->mc = mc; 7 | this->entity = entity; 8 | 9 | //Get all the field and method IDs for Entity that we want (mappings are for 1.12) 10 | fdPosX = getFieldID("x"); 11 | fdPosY = getFieldID("y"); 12 | fdPosZ = getFieldID("z"); 13 | mdGetId = getMethodID("getID"); 14 | mdGetName = getMethodID("getName"); 15 | } 16 | 17 | jdouble Entity::getPosX() { 18 | return getDouble(entity, fdPosX); 19 | } 20 | 21 | jdouble Entity::getPosY() { 22 | return getDouble(entity, fdPosY); 23 | } 24 | 25 | jdouble Entity::getPosZ() { 26 | return getDouble(entity, fdPosZ); 27 | } 28 | 29 | jint Entity::getId() { 30 | return getInt(entity, mdGetId); 31 | } 32 | 33 | const char * Entity::getName() { 34 | //Needs to get the name as a jstring, then convert that to something usable 35 | jstring str = (jstring)getObject(entity, mdGetName); 36 | return udp->getEnv()->GetStringUTFChars(str, false); 37 | } 38 | -------------------------------------------------------------------------------- /UDP/mapping/impl/Entity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../stdafx.h" 4 | #include "JavaSet.h" 5 | #include "../AbstractClass.h" 6 | 7 | class Minecraft; 8 | class Entity : public AbstractClass 9 | { 10 | public: 11 | Entity(UDP * udp, Minecraft * mc, jobject entity); 12 | 13 | jdouble getPosX(); 14 | jdouble getPosY(); 15 | jdouble getPosZ(); 16 | jint getId(); 17 | const char * getName(); 18 | private: 19 | jfieldID fdPosX; 20 | jfieldID fdPosY; 21 | jfieldID fdPosZ; 22 | jmethodID mdGetId; 23 | jmethodID mdGetName; 24 | 25 | Minecraft * mc; 26 | jobject entity; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /UDP/mapping/impl/EntityPlayerSP.cpp: -------------------------------------------------------------------------------- 1 | #include "Minecraft.h" 2 | #include "EntityPlayerSP.h" 3 | 4 | EntityPlayerSP::EntityPlayerSP(UDP * udp, Minecraft * mc) : AbstractClass::AbstractClass(udp, "PlayerSP") 5 | { 6 | this->mc = mc; 7 | 8 | //Get all the field and method IDs for EntityPlayerSP that we want (mappings are for 1.12) 9 | fdPosX = getFieldID("x"); 10 | fdPosY = getFieldID("y"); 11 | fdPosZ = getFieldID("z"); 12 | fdRotationYaw = getFieldID("yaw"); 13 | fdRotationPitch = getFieldID("pitch"); 14 | mdGetId = getMethodID("getID"); 15 | mdGetName = getMethodID("getName"); 16 | mdSetSprinting = getMethodID("setSprint"); 17 | } 18 | 19 | jdouble EntityPlayerSP::getPosX() { 20 | return getDouble(mc->getPlayer(), fdPosX); 21 | } 22 | 23 | jdouble EntityPlayerSP::getPosY() { 24 | return getDouble(mc->getPlayer(), fdPosY); 25 | } 26 | 27 | jdouble EntityPlayerSP::getPosZ() { 28 | return getDouble(mc->getPlayer(), fdPosZ); 29 | } 30 | 31 | jint EntityPlayerSP::getId() { 32 | return getInt(mc->getPlayer(), mdGetId); 33 | } 34 | 35 | const char * EntityPlayerSP::getName() { 36 | //Needs to get the name as a jstring, then convert that to something usable 37 | jstring str = (jstring)getObject(mc->getPlayer(), mdGetName); 38 | return udp->getEnv()->GetStringUTFChars(str, false); 39 | } 40 | 41 | void EntityPlayerSP::setRotationYaw(jfloat yaw) { 42 | setFloat(mc->getPlayer(), fdRotationYaw, yaw); 43 | } 44 | 45 | void EntityPlayerSP::setRotationPitch(jfloat pitch) { 46 | setFloat(mc->getPlayer(), fdRotationPitch, pitch); 47 | } 48 | 49 | void EntityPlayerSP::setSprinting(jboolean sprinting) { 50 | callMethod(mc->getPlayer(), mdSetSprinting, sprinting); 51 | } 52 | -------------------------------------------------------------------------------- /UDP/mapping/impl/EntityPlayerSP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../AbstractClass.h" 4 | 5 | 6 | class UDP; 7 | class Minecraft; 8 | class EntityPlayerSP : public AbstractClass 9 | { 10 | public: 11 | EntityPlayerSP(UDP * udp, Minecraft * mc); 12 | 13 | jdouble getPosX(); 14 | jdouble getPosY(); 15 | jdouble getPosZ(); 16 | jint getId(); 17 | const char * getName(); 18 | 19 | void setRotationYaw(jfloat yaw); 20 | void setRotationPitch(jfloat pitch); 21 | void setSprinting(jboolean sprinting); 22 | private: 23 | jfieldID fdPosX; 24 | jfieldID fdPosY; 25 | jfieldID fdPosZ; 26 | jfieldID fdRotationYaw; 27 | jfieldID fdRotationPitch; 28 | jmethodID mdGetId; 29 | jmethodID mdGetName; 30 | jmethodID mdSetSprinting; 31 | 32 | Minecraft * mc; 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /UDP/mapping/impl/JavaList.cpp: -------------------------------------------------------------------------------- 1 | #include "JavaList.h" 2 | 3 | JavaList::JavaList(UDP * udp, jobject list) : AbstractClass::AbstractClass(udp, "List") 4 | { 5 | mdGet = getMethodID("get"); 6 | mdSize = getMethodID("size"); 7 | mdToArray = getMethodID("toArray"); 8 | 9 | this->list = list; 10 | } 11 | 12 | jobject JavaList::get(jint index) { 13 | return getObject(list, mdGet, index); 14 | } 15 | 16 | int JavaList::size() { 17 | return getInt(list, mdSize); 18 | } 19 | 20 | jobjectArray JavaList::toArray() { 21 | return (jobjectArray) getObject(list, mdToArray); 22 | } -------------------------------------------------------------------------------- /UDP/mapping/impl/JavaList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../AbstractClass.h" 4 | 5 | class JavaList : public AbstractClass 6 | { 7 | public: 8 | JavaList(UDP * udp, jobject list); 9 | 10 | jobject get(jint index); 11 | int size(); 12 | jobjectArray toArray(); 13 | private: 14 | jmethodID mdGet; 15 | jmethodID mdSize; 16 | jmethodID mdToArray; 17 | 18 | jobject list; 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /UDP/mapping/impl/JavaSet.cpp: -------------------------------------------------------------------------------- 1 | #include "JavaSet.h" 2 | #include "../AbstractClass.h" 3 | 4 | 5 | JavaSet::JavaSet(UDP * udp, jobject set) : AbstractClass::AbstractClass(udp, "Set") 6 | { 7 | mdSize = getMethodID("size"); 8 | mdToArray = getMethodID("toArray"); 9 | 10 | this->set = set; 11 | } 12 | 13 | int JavaSet::size() { 14 | return getInt(set, mdSize); 15 | } 16 | 17 | jobjectArray JavaSet::toArray() { 18 | return (jobjectArray)getObject(set, mdToArray); 19 | } 20 | 21 | jobject JavaSet::get(int index) { 22 | return getArrayElement(toArray(), index); 23 | } -------------------------------------------------------------------------------- /UDP/mapping/impl/JavaSet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../AbstractClass.h" 4 | 5 | class JavaSet : public AbstractClass 6 | { 7 | public: 8 | JavaSet(UDP * udp, jobject set); 9 | 10 | int size(); 11 | jobjectArray toArray(); 12 | 13 | jobject get(int index); 14 | private: 15 | jmethodID mdSize; 16 | jmethodID mdToArray; 17 | 18 | jobject set; 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /UDP/mapping/impl/Minecraft.cpp: -------------------------------------------------------------------------------- 1 | #include "Minecraft.h" 2 | #include "EntityPlayerSP.h" 3 | #include "WorldClient.h" 4 | 5 | Minecraft::Minecraft(UDP * udp) : AbstractClass::AbstractClass(udp, "Minecraft") 6 | { 7 | smdGetMinecraft = getMethodID("getMinecraft"); 8 | fdPlayer = getFieldID("player"); 9 | fdWorld = getFieldID("world"); 10 | } 11 | 12 | jobject Minecraft::getMinecraft() { 13 | return getObject(smdGetMinecraft); 14 | } 15 | 16 | jobject Minecraft::getPlayer() { 17 | return getObject(getMinecraft(), fdPlayer); 18 | } 19 | 20 | jobject Minecraft::getWorld() { 21 | return getObject(getMinecraft(), fdWorld); 22 | } 23 | 24 | EntityPlayerSP * Minecraft::getPlayerContainer() { 25 | //If the player container doesn't exist, make it, why am I even commenting this? 26 | if (!playerContainer) 27 | playerContainer = new EntityPlayerSP(udp, this); 28 | return playerContainer; 29 | } 30 | 31 | WorldClient * Minecraft::getWorldContainer() { 32 | if (!worldContainer) 33 | worldContainer = new WorldClient(udp, this); 34 | return worldContainer; 35 | } -------------------------------------------------------------------------------- /UDP/mapping/impl/Minecraft.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../AbstractClass.h" 4 | 5 | 6 | class UDP; 7 | class EntityPlayerSP; 8 | class WorldClient; 9 | class Minecraft : public AbstractClass 10 | { 11 | public: 12 | Minecraft(UDP * udp); 13 | 14 | jobject getMinecraft(); 15 | jobject getPlayer(); 16 | jobject getWorld(); 17 | 18 | EntityPlayerSP * getPlayerContainer(); 19 | WorldClient * getWorldContainer(); 20 | private: 21 | jfieldID fdPlayer; 22 | jfieldID fdWorld; 23 | jmethodID smdGetMinecraft; 24 | 25 | EntityPlayerSP * playerContainer; 26 | WorldClient * worldContainer; 27 | }; -------------------------------------------------------------------------------- /UDP/mapping/impl/WorldClient.cpp: -------------------------------------------------------------------------------- 1 | #include "Minecraft.h" 2 | #include "WorldClient.h" 3 | 4 | WorldClient::WorldClient(UDP * udp, Minecraft * mc) : AbstractClass::AbstractClass(udp, "WorldClient") 5 | { 6 | this->mc = mc; 7 | fdEntityList = getFieldID("entities"); 8 | mdSetWorldTime = getMethodID("setTime"); 9 | } 10 | 11 | jobject WorldClient::getEntityList() { 12 | return getObject(mc->getWorld(), fdEntityList); 13 | } 14 | 15 | void WorldClient::setWorldTime(jlong time) { 16 | callMethod(mc->getWorld(), mdSetWorldTime, time); 17 | } 18 | 19 | JavaSet * WorldClient::getEntities() { 20 | JavaSet * set = new JavaSet(udp, getEntityList()); 21 | return set; 22 | } 23 | -------------------------------------------------------------------------------- /UDP/mapping/impl/WorldClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "JavaSet.h" 4 | #include "../AbstractClass.h" 5 | 6 | class Minecraft; 7 | class WorldClient : public AbstractClass 8 | { 9 | public: 10 | WorldClient(UDP * udp, Minecraft * mc); 11 | 12 | jobject getEntityList(); 13 | void setWorldTime(jlong time); 14 | 15 | JavaSet * getEntities(); 16 | private: 17 | jfieldID fdEntityList; 18 | jmethodID mdSetWorldTime; 19 | 20 | Minecraft * mc; 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /UDP/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnknownDetectionParty/UDP-CPP/018233f85f81ac0c2f7ccd780844be8a8102d39a/UDP/stdafx.cpp -------------------------------------------------------------------------------- /UDP/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnknownDetectionParty/UDP-CPP/018233f85f81ac0c2f7ccd780844be8a8102d39a/UDP/stdafx.h -------------------------------------------------------------------------------- /UDP/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnknownDetectionParty/UDP-CPP/018233f85f81ac0c2f7ccd780844be8a8102d39a/UDP/targetver.h -------------------------------------------------------------------------------- /UDP/util/MathHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | class MathHelper 6 | { 7 | public: 8 | static double radtodeg(double x) { 9 | return x * 180.0 / M_PI; 10 | } 11 | 12 | static double degtorad(double x) { 13 | return x * M_PI / 180.0; 14 | } 15 | 16 | static double distance(double x, double y) { 17 | return sqrt(pow(x, 2) + pow(y, 2)); 18 | } 19 | 20 | static double distance(double x1, double y1, double z1, double x2, double y2, double z2) { 21 | return distance(y1 - y2, distance(x1 - x2, z1 - z2)); 22 | } 23 | 24 | static double direction(double x1, double y1, double x2, double y2) { 25 | return radtodeg(atan2(y2 - y1, x2 - x1)); 26 | } 27 | 28 | static double * direction(double x1, double y1, double z1, double x2, double y2, double z2) { 29 | double dx = x2 - x1; 30 | double dy = y2 - y1; 31 | double dz = z2 - z1; 32 | double yaw = radtodeg(atan2(dz, dx)) - 90; 33 | double pitch = -radtodeg(atan2(dy, distance(dx, dz))); 34 | return new double[2] { yaw, pitch }; 35 | } 36 | }; --------------------------------------------------------------------------------