├── .gitattributes ├── .gitignore ├── README.md ├── externalCheat ├── ExternalCheat.cpp ├── ExternalCheat.h ├── PatternScan.cpp ├── PatternScan.h ├── externalCheat.vcxproj ├── externalCheat.vcxproj.filters ├── getpid.cpp ├── getpid.h └── main.cpp ├── game.sln ├── game ├── bow.cpp ├── bow.h ├── enemy.cpp ├── enemy.h ├── game.cpp ├── game.h ├── game.vcxproj ├── game.vcxproj.filters ├── gameexceptions.h ├── gameobject.cpp ├── gameobject.h ├── healingpotion.cpp ├── healingpotion.h ├── item.cpp ├── item.h ├── main.cpp ├── player.cpp ├── player.h ├── potion.cpp ├── potion.h ├── sword.cpp ├── sword.h ├── unit.cpp ├── unit.h ├── weapon.cpp └── weapon.h ├── gameUnitTests ├── gameUnitTests.vcxproj ├── gameUnitTests.vcxproj.filters ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── testGameLogic.cpp └── testPlayerClass.cpp ├── injector ├── getpid.cpp ├── getpid.h ├── includes.h ├── injector.iobj ├── injector.ipdb ├── injector.vcxproj ├── injector.vcxproj.filters └── main.cpp └── internalCheat ├── InternalCheat.cpp ├── InternalCheat.h ├── PatternScan.cpp ├── PatternScan.h ├── ch_includes.h ├── getpid.cpp ├── getpid.h ├── includes.h ├── internalCheat.vcxproj ├── internalCheat.vcxproj.filters └── main.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | out/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | [Ll]og/ 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | #wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | project.fragment.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | 74 | # Chutzpah Test files 75 | _Chutzpah* 76 | 77 | # Visual C++ cache files 78 | ipch/ 79 | *.aps 80 | *.ncb 81 | *.opendb 82 | *.opensdf 83 | *.sdf 84 | *.cachefile 85 | *.VC.db 86 | *.VC.VC.opendb 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | *.sap 93 | 94 | # TFS 2012 Local Workspace 95 | $tf/ 96 | 97 | # Guidance Automation Toolkit 98 | *.gpState 99 | 100 | # ReSharper is a .NET coding add-in 101 | _ReSharper*/ 102 | *.[Rr]e[Ss]harper 103 | *.DotSettings.user 104 | 105 | # JustCode is a .NET coding add-in 106 | .JustCode 107 | 108 | # TeamCity is a build add-in 109 | _TeamCity* 110 | 111 | # DotCover is a Code Coverage Tool 112 | *.dotCover 113 | 114 | # NCrunch 115 | _NCrunch_* 116 | .*crunch*.local.xml 117 | nCrunchTemp_* 118 | 119 | # MightyMoose 120 | *.mm.* 121 | AutoTest.Net/ 122 | 123 | # Web workbench (sass) 124 | .sass-cache/ 125 | 126 | # Installshield output folder 127 | [Ee]xpress/ 128 | 129 | # DocProject is a documentation generator add-in 130 | DocProject/buildhelp/ 131 | DocProject/Help/*.HxT 132 | DocProject/Help/*.HxC 133 | DocProject/Help/*.hhc 134 | DocProject/Help/*.hhk 135 | DocProject/Help/*.hhp 136 | DocProject/Help/Html2 137 | DocProject/Help/html 138 | 139 | # Click-Once directory 140 | publish/ 141 | 142 | # Publish Web Output 143 | *.[Pp]ublish.xml 144 | *.azurePubxml 145 | # TODO: Comment the next line if you want to checkin your web deploy settings 146 | # but database connection strings (with potential passwords) will be unencrypted 147 | #*.pubxml 148 | *.publishproj 149 | 150 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 151 | # checkin your Azure Web App publish settings, but sensitive information contained 152 | # in these scripts will be unencrypted 153 | PublishScripts/ 154 | 155 | # NuGet Packages 156 | *.nupkg 157 | # The packages folder can be ignored because of Package Restore 158 | **/packages/* 159 | # except build/, which is used as an MSBuild target. 160 | !**/packages/build/ 161 | # Uncomment if necessary however generally it will be regenerated when needed 162 | #!**/packages/repositories.config 163 | # NuGet v3's project.json files produces more ignoreable files 164 | *.nuget.props 165 | *.nuget.targets 166 | 167 | # Microsoft Azure Build Output 168 | csx/ 169 | *.build.csdef 170 | 171 | # Microsoft Azure Emulator 172 | ecf/ 173 | rcf/ 174 | 175 | # Windows Store app package directories and files 176 | AppPackages/ 177 | BundleArtifacts/ 178 | Package.StoreAssociation.xml 179 | _pkginfo.txt 180 | 181 | # Visual Studio cache files 182 | # files ending in .cache can be ignored 183 | *.[Cc]ache 184 | # but keep track of directories ending in .cache 185 | !*.[Cc]ache/ 186 | 187 | # Others 188 | ClientBin/ 189 | ~$* 190 | *~ 191 | *.dbmdl 192 | *.dbproj.schemaview 193 | *.jfm 194 | *.pfx 195 | *.publishsettings 196 | node_modules/ 197 | orleans.codegen.cs 198 | 199 | # Since there are multiple workflows, uncomment next line to ignore bower_components 200 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 201 | #bower_components/ 202 | 203 | # RIA/Silverlight projects 204 | Generated_Code/ 205 | 206 | # Backup & report files from converting an old project file 207 | # to a newer Visual Studio version. Backup files are not needed, 208 | # because we have git ;-) 209 | _UpgradeReport_Files/ 210 | Backup*/ 211 | UpgradeLog*.XML 212 | UpgradeLog*.htm 213 | 214 | # SQL Server files 215 | *.mdf 216 | *.ldf 217 | 218 | # Business Intelligence projects 219 | *.rdl.data 220 | *.bim.layout 221 | *.bim_*.settings 222 | 223 | # Microsoft Fakes 224 | FakesAssemblies/ 225 | 226 | # GhostDoc plugin setting file 227 | *.GhostDoc.xml 228 | 229 | # Node.js Tools for Visual Studio 230 | .ntvs_analysis.dat 231 | 232 | # Visual Studio 6 build log 233 | *.plg 234 | 235 | # Visual Studio 6 workspace options file 236 | *.opt 237 | 238 | # Visual Studio LightSwitch build output 239 | **/*.HTMLClient/GeneratedArtifacts 240 | **/*.DesktopClient/GeneratedArtifacts 241 | **/*.DesktopClient/ModelManifest.xml 242 | **/*.Server/GeneratedArtifacts 243 | **/*.Server/ModelManifest.xml 244 | _Pvt_Extensions 245 | 246 | # Paket dependency manager 247 | .paket/paket.exe 248 | paket-files/ 249 | 250 | # FAKE - F# Make 251 | .fake/ 252 | 253 | # JetBrains Rider 254 | .idea/ 255 | *.sln.iml 256 | 257 | # CodeRush 258 | .cr/ 259 | 260 | # Python Tools for Visual Studio (PTVS) 261 | __pycache__/ 262 | *.pyc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cheat examples 2 | 3 | ## Project modules 4 | 5 | | Project | Description | 6 | | ------ | -------------| 7 | | injector | Dll injector (uses ```CreateRemoteThread``` with ```LoadLibraryA```) | 8 | | internalCheat | DLL-library to inject into the target process using ```injector``` | 9 | | externalCheat | External cheat, which uses ```ReadProcessMemory``` and ```WriteProcessMemory``` | 10 | | game | RPG-like game with basic inventory and fight systems. | 11 | | gameUnitTests | Unit tests for the game. | 12 | 13 | ## Injector 14 | 15 | The injector is a simple console application, which injects a DLL into a target process. It uses ```CreateRemoteThread``` with ```LoadLibraryA``` to inject the DLL. 16 | 17 | ![Imgur](https://i.imgur.com/XlLDUwZ.png) 18 | 19 | ## Internal Cheat 20 | 21 | Internal cheat is a DLL-library, which is injected into the target process using ```injector```. It uses pattern scanning to find the addresses of the game's variables. 22 | 23 | ### How it works 24 | 25 | 1. The DLL is injected into the target process using ```injector```. 26 | 27 | ```c++ 28 | // Write DLL path to newly allocated memory 29 | WriteProcessMemory(psHandle, psMemoryLibPath, fullLibPath, MAX_PATH, &fullLibPathSize); 30 | 31 | // Get address of LoadLibraryA 32 | FARPROC loadLibraryA = GetProcAddress(GetModuleHandle("kernel32"), "LoadLibraryA"); 33 | 34 | // Call LoadLibraryA in remote process to load DLL 35 | CreateRemoteThread(psHandle, NULL, NULL, (LPTHREAD_START_ROUTINE)loadLibraryA, psMemoryLibPath, NULL, NULL); 36 | ``` 37 | 38 | 2. After the dll is injected it will begin it's execution in the memory space of the target process. The first thing it does is to find the address of the `hp` variable. 39 | 40 | ```c++ 41 | // InternalCheat.cpp 42 | mem_region = reinterpret_cast(PatternScan::find_pattern_internal("50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FD FD FD FD")); 43 | ``` 44 | 45 | 3. The final step is to start the cheat loop. Every 5 seconds the cheat will set `hp` variable to INT_MAX. 46 | 47 | ```c++ 48 | // InternalCheat.cpp 49 | const auto player_health = reinterpret_cast(reinterpret_cast(mem_region) + hpOffset); 50 | while (true) 51 | { 52 | *player_health = INT_MAX; // update player's health 53 | std::this_thread::sleep_for(std::chrono::milliseconds(5000)); // sleep for 5 seconds 54 | } 55 | ``` 56 | 57 | Final results: 58 | 59 | ![Imgur](https://i.imgur.com/EuwAd19.png) 60 | 61 | ## External Cheat 62 | 63 | Simplified version of injector-like cheat. 64 | This version uses ```ReadProcessMemory``` and ```WriteProcessMemory``` to manipulate values inside process memory space. 65 | 66 | ### How it works 67 | 68 | 1. The cheat tries to acquire a handle to the target process. 69 | 70 | ```c++ 71 | // Get a handle to the process 72 | activePsHandle = OpenProcess(PROCESS_ALL_ACCESS, false, pid); 73 | ``` 74 | 75 | 2. If previous step was successful, the cheat will try to find the address of the `hp` variable. 76 | 77 | ```c++ 78 | // ExternalCheat.cpp 79 | mem_region = reinterpret_cast(PatternScan::find_pattern_external(activePsHandle, "50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FD FD FD FD")); 80 | ``` 81 | 82 | 3. If pattern scanning was successful, the cheat will start the cheat loop. Every 5 seconds the cheat will set `hp` variable to INT_MAX. 83 | 84 | ```c++ 85 | while (true) 86 | { 87 | int newHp = INT_MAX; 88 | if (!WriteMem(activePsHandle, reinterpret_cast(mem_region) + hpOffset, &newHp)) 89 | { 90 | std::wcout << "[-] Cannot write process memory!\n"; 91 | } 92 | 93 | std::this_thread::sleep_for(std::chrono::milliseconds(5000)); 94 | } 95 | ``` 96 | 97 | Final results: 98 | 99 | ![Imgur](https://i.imgur.com/2LeTFqy.png) 100 | 101 | ## The Game 102 | 103 | To test developed cheats I've created a simple game with basic inventory and fight systems. The game is written in C++. 104 | 105 | Main menu: 106 | 107 | - ```[c]reate``` - Creates a new player with default stats (63hp, 4dmg). 108 | - ```[f]ight``` - fight with a random enemy (only active, if you have an active player) 109 | - ```[s]tats``` - view your player stats 110 | - ```[i]inventory``` - displays your inventory or allows you to select a new active item. (if you have an active player) 111 | - ```[e]xit``` - closes the game 112 | 113 | Fight menu: 114 | 115 | - ```[a]ttack``` - attack an enemy 116 | - ```[h]eal``` - heal yourself 117 | - ```[r]un``` - run away from the enemy 118 | 119 | Inventory menu: 120 | 121 | - ```[d]isplay``` - displays your inventory 122 | - ```[e]quip``` - allows you to select a new active item 123 | 124 | ![Imgur](https://i.imgur.com/0kmwRTx.png) 125 | 126 | ## Game Unit Tests 127 | 128 | How to run 129 | 130 | 1. Test -> Windows -> Test Explorer 131 | 2. Test Explorer -> Run All 132 | -------------------------------------------------------------------------------- /externalCheat/ExternalCheat.cpp: -------------------------------------------------------------------------------- 1 | #include "ExternalCheat.h" 2 | 3 | constexpr long long int hpOffset = -0x4; 4 | 5 | ExternalCheat* ExternalCheat::cHinstance = nullptr; 6 | 7 | ExternalCheat::ExternalCheat() 8 | { 9 | is_initialized = false; 10 | } 11 | 12 | ExternalCheat* ExternalCheat::get_instance() 13 | { 14 | if (cHinstance == nullptr) 15 | { 16 | cHinstance = new ExternalCheat(); 17 | } 18 | return cHinstance; 19 | } 20 | 21 | int ExternalCheat::init(DWORD pid) 22 | { 23 | if (is_initialized) 24 | return NULL; 25 | 26 | // Open handle to process with full access 27 | activePsHandle = OpenProcess(PROCESS_ALL_ACCESS, false, pid); 28 | 29 | if (activePsHandle != nullptr) 30 | { 31 | mem_region = reinterpret_cast(PatternScan::find_pattern_external(activePsHandle, "50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FD FD FD FD")); 32 | if (mem_region != NULL) 33 | { 34 | printf("[+] Found player signature! ptr: 0x%p\n", mem_region); 35 | } 36 | else { 37 | printf("[-] Cannot find player signature! Aborting.\n"); 38 | return NULL; 39 | } 40 | 41 | is_initialized = true; 42 | return 1; 43 | } 44 | else { 45 | std::wcout << "[-] Cannot open process.\n"; 46 | std::wcout << "[-] Check your privilegies.\n"; 47 | getchar(); 48 | return NULL; 49 | } 50 | } 51 | 52 | int ExternalCheat::exec() 53 | { 54 | std::wcout << "[+][CH] Cheat is now running\n"; 55 | while (true) 56 | { 57 | int newHp = INT_MAX; 58 | if (!WriteMem(activePsHandle, reinterpret_cast(mem_region) + hpOffset, &newHp)) 59 | { 60 | std::wcout << "[-] Cannot write process memory!\n"; 61 | } 62 | 63 | // Sleep For 5 seconds 64 | std::this_thread::sleep_for(std::chrono::milliseconds(5000)); 65 | } 66 | } -------------------------------------------------------------------------------- /externalCheat/ExternalCheat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "PatternScan.h" 9 | 10 | class ExternalCheat 11 | { 12 | public: 13 | static ExternalCheat* get_instance(); 14 | int init(DWORD pid); 15 | int exec(); 16 | 17 | // RPM/WPM wrappers 18 | // Read a value from memory and put it in Value 19 | // Returns true on success, false on failure 20 | /*template 21 | static bool ReadMem(HANDLE psHandle, DWORDLONG dwAddress, T& Value) 22 | { 23 | return ReadProcessMemory(psHandle, reinterpret_cast(dwAddress), Value, sizeof(T), NULL) == TRUE; 24 | }*/ 25 | 26 | // Write a Value in memory 27 | // Returns true on success, false on failure 28 | template 29 | inline bool WriteMem(HANDLE psHandle, DWORDLONG dwAddress, const T& Value) 30 | { 31 | return WriteProcessMemory(psHandle, reinterpret_cast(dwAddress), reinterpret_cast(Value), sizeof(T), NULL) == TRUE; 32 | } 33 | 34 | private: 35 | HANDLE activePsHandle = NULL; 36 | static ExternalCheat* cHinstance; 37 | bool is_initialized = false; 38 | void* mem_region = nullptr; 39 | 40 | ExternalCheat(); 41 | }; -------------------------------------------------------------------------------- /externalCheat/PatternScan.cpp: -------------------------------------------------------------------------------- 1 | #include "PatternScan.h" 2 | 3 | std::vector<_MEMORY_BASIC_INFORMATION*> PatternScan::query_memory_regions(HANDLE psHandle) 4 | { 5 | std::vector<_MEMORY_BASIC_INFORMATION *> regions; 6 | DWORDLONG curr_addr = 0; 7 | 8 | for (;;) 9 | { 10 | _MEMORY_BASIC_INFORMATION *mbi = new _MEMORY_BASIC_INFORMATION; 11 | 12 | if (VirtualQueryEx(psHandle, reinterpret_cast(curr_addr), mbi, sizeof _MEMORY_BASIC_INFORMATION) == 0) 13 | { 14 | break; 15 | } 16 | 17 | if ((mbi->State == MEM_COMMIT || mbi->State == MEM_RESERVE) && 18 | (mbi->Protect == PAGE_READONLY || 19 | mbi->Protect == PAGE_READWRITE || 20 | mbi->Protect == PAGE_EXECUTE_READ || 21 | mbi->Protect == PAGE_EXECUTE_READWRITE)) 22 | { 23 | regions.push_back(mbi); 24 | } 25 | 26 | curr_addr += mbi->RegionSize; 27 | } 28 | 29 | return regions; 30 | } 31 | 32 | DWORDLONG PatternScan::find_pattern_external(HANDLE psHandle, std::string pattern) 33 | { 34 | DWORDLONG curr_addr = 0; 35 | std::vector<_MEMORY_BASIC_INFORMATION*> regions = query_memory_regions(psHandle); 36 | 37 | for (_MEMORY_BASIC_INFORMATION *cur_region : regions) 38 | { 39 | auto result = PatternScan::find_pattern_external_in_range(psHandle, cur_region, pattern); 40 | 41 | if (result != NULL) 42 | { 43 | return result; 44 | } 45 | } 46 | 47 | return NULL; 48 | } 49 | 50 | DWORDLONG PatternScan::find_pattern_external_in_range(HANDLE psHandle, _MEMORY_BASIC_INFORMATION* cur_mbi, std::string pattern) 51 | { 52 | 53 | // Allocate buffer for saved process memory 54 | byte* memory = new byte[cur_mbi->RegionSize]; 55 | 56 | if (memory == nullptr) 57 | { 58 | delete[] memory; 59 | return NULL; 60 | } 61 | 62 | if (!ReadProcessMemory(psHandle, cur_mbi->BaseAddress, memory, cur_mbi->RegionSize, NULL)) 63 | { 64 | delete[] memory; 65 | return NULL; 66 | } 67 | 68 | auto strstream = std::istringstream(pattern); 69 | 70 | std::vector values; 71 | std::string s; 72 | 73 | while (getline(strstream, s, ' ')) 74 | { 75 | if (s.find("??") != std::string::npos) 76 | { 77 | values.push_back(-1); 78 | continue; 79 | } 80 | 81 | auto parsed = std::stoi(s, 0, 16); 82 | values.push_back(parsed); 83 | } 84 | 85 | for (size_t p_cur = 0; p_cur < cur_mbi->RegionSize - values.size(); p_cur++) 86 | { 87 | auto localAddr = p_cur; 88 | auto found = true; 89 | 90 | for (auto value : values) 91 | { 92 | if (value == -1) 93 | { 94 | localAddr += 1; 95 | continue; 96 | } 97 | 98 | char neededValue = static_cast(value); 99 | char currentValue = memory[localAddr]; 100 | 101 | if (neededValue != currentValue) 102 | { 103 | found = false; 104 | break; 105 | } 106 | 107 | localAddr += 1; 108 | } 109 | 110 | if (found) 111 | { 112 | delete[] memory; 113 | return p_cur + reinterpret_cast(cur_mbi->BaseAddress); 114 | } 115 | } 116 | 117 | delete[] memory; 118 | return NULL; 119 | } -------------------------------------------------------------------------------- /externalCheat/PatternScan.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Shlwapi.h" 6 | // #include 7 | #include 8 | // #include 9 | 10 | class PatternScan 11 | { 12 | private: 13 | 14 | public: 15 | // Get all memory regions of target process 16 | static std::vector<_MEMORY_BASIC_INFORMATION *> query_memory_regions(HANDLE psHandle); 17 | 18 | // Find pattern in process memory 19 | // player_base_ = reinterpret_cast(find_pattern("ED 03 ?? ?? 01 00 00 00")); 20 | // ?? - unknown bytes 21 | static DWORDLONG find_pattern_external(HANDLE psHandle, std::string pattern); 22 | 23 | // Find pattern in specific memory range 24 | static DWORDLONG find_pattern_external_in_range(HANDLE psHandle, _MEMORY_BASIC_INFORMATION* cur_mbi, std::string pattern); 25 | }; -------------------------------------------------------------------------------- /externalCheat/externalCheat.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC} 24 | externalCheat 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | out\ 74 | 75 | 76 | out\ 77 | 78 | 79 | 80 | Level3 81 | Disabled 82 | true 83 | true 84 | 85 | 86 | out\$(TargetName)$(TargetExt) 87 | 88 | 89 | 90 | 91 | Level3 92 | Disabled 93 | true 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | MaxSpeed 101 | true 102 | true 103 | true 104 | true 105 | 106 | 107 | true 108 | true 109 | 110 | 111 | 112 | 113 | Level3 114 | MaxSpeed 115 | true 116 | true 117 | true 118 | true 119 | 120 | 121 | true 122 | true 123 | out\$(TargetName)$(TargetExt) 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /externalCheat/externalCheat.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | -------------------------------------------------------------------------------- /externalCheat/getpid.cpp: -------------------------------------------------------------------------------- 1 | #include "getpid.h" 2 | 3 | std::vector get_pid_by_name(std::wstring targetName) 4 | { 5 | std::vector pids; 6 | 7 | DWORD targetPid; 8 | HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // all processes 9 | 10 | PROCESSENTRY32W entry; 11 | entry.dwSize = sizeof entry; 12 | 13 | if (!Process32FirstW(snap, &entry)) //start with the first in snapshot 14 | { 15 | return std::vector(); 16 | } 17 | 18 | do { 19 | if (std::wstring(entry.szExeFile) == targetName) //name matches; add to list 20 | { 21 | pids.push_back(entry.th32ProcessID); 22 | // HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); 23 | // CloseHandle(hProcess); 24 | } 25 | } while (Process32NextW(snap, &entry)); //keep going until end of snapshot 26 | 27 | return pids; 28 | } -------------------------------------------------------------------------------- /externalCheat/getpid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | std::vector get_pid_by_name(std::wstring targetName); -------------------------------------------------------------------------------- /externalCheat/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "getpid.h" 5 | #include "ExternalCheat.h" 6 | 7 | int main() 8 | { 9 | std::wstring psName; 10 | std::vector pids; 11 | 12 | for (;;) 13 | { 14 | std::wcout << "[+] Enter process name: "; 15 | std::wcin >> psName; 16 | std::wcout << "[+] Searching pids of process with name: " << psName << std::endl; 17 | 18 | // Get Process PID by its name 19 | pids = get_pid_by_name(psName); 20 | 21 | if (pids.size() == 0) { 22 | std::wcout << "[-] Cannot find any process!\n"; 23 | } 24 | else { 25 | std::wcout << "[+] 1. PID: " << pids[0] << std::endl; 26 | break; 27 | } 28 | } 29 | 30 | ExternalCheat* cheat = ExternalCheat::get_instance(); 31 | if (cheat->init(pids[0])) 32 | { 33 | std::wcout << "[+][CH] Cheat loaded successfully!\n"; 34 | cheat->exec(); 35 | } 36 | else { 37 | std::wcout << "[-] Player Signature Cannot be found!" << "\n> "; 38 | } 39 | } -------------------------------------------------------------------------------- /game.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.572 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "game\game.vcxproj", "{D0357620-C8B7-42B6-A99E-9F3D8B462490}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "externalCheat", "externalCheat\externalCheat.vcxproj", "{A78276CE-0377-4A2F-861E-FCD02FBEE6CC}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "internalCheat", "internalCheat\internalCheat.vcxproj", "{095A401C-88F4-4918-B1B7-D95FFDC4404D}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "injector", "injector\injector.vcxproj", "{A42982F7-8F96-4674-AF04-F80A6497A0C5}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gameUnitTests", "gameUnitTests\gameUnitTests.vcxproj", "{68D600E6-E1A8-4A92-8D0E-58EC68CB7608}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|x64 = Debug|x64 19 | Debug|x86 = Debug|x86 20 | Release|x64 = Release|x64 21 | Release|x86 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {D0357620-C8B7-42B6-A99E-9F3D8B462490}.Debug|x64.ActiveCfg = Debug|x64 25 | {D0357620-C8B7-42B6-A99E-9F3D8B462490}.Debug|x64.Build.0 = Debug|x64 26 | {D0357620-C8B7-42B6-A99E-9F3D8B462490}.Debug|x86.ActiveCfg = Debug|Win32 27 | {D0357620-C8B7-42B6-A99E-9F3D8B462490}.Debug|x86.Build.0 = Debug|Win32 28 | {D0357620-C8B7-42B6-A99E-9F3D8B462490}.Release|x64.ActiveCfg = Release|x64 29 | {D0357620-C8B7-42B6-A99E-9F3D8B462490}.Release|x64.Build.0 = Release|x64 30 | {D0357620-C8B7-42B6-A99E-9F3D8B462490}.Release|x86.ActiveCfg = Release|Win32 31 | {D0357620-C8B7-42B6-A99E-9F3D8B462490}.Release|x86.Build.0 = Release|Win32 32 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC}.Debug|x64.ActiveCfg = Debug|x64 33 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC}.Debug|x64.Build.0 = Debug|x64 34 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC}.Debug|x86.ActiveCfg = Debug|Win32 35 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC}.Debug|x86.Build.0 = Debug|Win32 36 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC}.Release|x64.ActiveCfg = Release|x64 37 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC}.Release|x64.Build.0 = Release|x64 38 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC}.Release|x86.ActiveCfg = Release|Win32 39 | {A78276CE-0377-4A2F-861E-FCD02FBEE6CC}.Release|x86.Build.0 = Release|Win32 40 | {095A401C-88F4-4918-B1B7-D95FFDC4404D}.Debug|x64.ActiveCfg = Debug|x64 41 | {095A401C-88F4-4918-B1B7-D95FFDC4404D}.Debug|x64.Build.0 = Debug|x64 42 | {095A401C-88F4-4918-B1B7-D95FFDC4404D}.Debug|x86.ActiveCfg = Debug|Win32 43 | {095A401C-88F4-4918-B1B7-D95FFDC4404D}.Debug|x86.Build.0 = Debug|Win32 44 | {095A401C-88F4-4918-B1B7-D95FFDC4404D}.Release|x64.ActiveCfg = Release|x64 45 | {095A401C-88F4-4918-B1B7-D95FFDC4404D}.Release|x64.Build.0 = Release|x64 46 | {095A401C-88F4-4918-B1B7-D95FFDC4404D}.Release|x86.ActiveCfg = Release|Win32 47 | {095A401C-88F4-4918-B1B7-D95FFDC4404D}.Release|x86.Build.0 = Release|Win32 48 | {A42982F7-8F96-4674-AF04-F80A6497A0C5}.Debug|x64.ActiveCfg = Debug|x64 49 | {A42982F7-8F96-4674-AF04-F80A6497A0C5}.Debug|x64.Build.0 = Debug|x64 50 | {A42982F7-8F96-4674-AF04-F80A6497A0C5}.Debug|x86.ActiveCfg = Debug|Win32 51 | {A42982F7-8F96-4674-AF04-F80A6497A0C5}.Debug|x86.Build.0 = Debug|Win32 52 | {A42982F7-8F96-4674-AF04-F80A6497A0C5}.Release|x64.ActiveCfg = Release|x64 53 | {A42982F7-8F96-4674-AF04-F80A6497A0C5}.Release|x64.Build.0 = Release|x64 54 | {A42982F7-8F96-4674-AF04-F80A6497A0C5}.Release|x86.ActiveCfg = Release|Win32 55 | {A42982F7-8F96-4674-AF04-F80A6497A0C5}.Release|x86.Build.0 = Release|Win32 56 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608}.Debug|x64.ActiveCfg = Debug|x64 57 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608}.Debug|x64.Build.0 = Debug|x64 58 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608}.Debug|x86.ActiveCfg = Debug|Win32 59 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608}.Debug|x86.Build.0 = Debug|Win32 60 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608}.Release|x64.ActiveCfg = Release|x64 61 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608}.Release|x64.Build.0 = Release|x64 62 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608}.Release|x86.ActiveCfg = Release|Win32 63 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608}.Release|x86.Build.0 = Release|Win32 64 | EndGlobalSection 65 | GlobalSection(SolutionProperties) = preSolution 66 | HideSolutionNode = FALSE 67 | EndGlobalSection 68 | GlobalSection(ExtensibilityGlobals) = postSolution 69 | SolutionGuid = {C344FCF1-83B4-4D62-B9A1-919A754A094B} 70 | EndGlobalSection 71 | EndGlobal 72 | -------------------------------------------------------------------------------- /game/bow.cpp: -------------------------------------------------------------------------------- 1 | #include "bow.h" 2 | 3 | Bow::Bow() 4 | { 5 | desc = "Simple Bow"; 6 | 7 | weaponType = WeaponType::bow; 8 | 9 | int minDamage = 1; 10 | int maxDamage = 10; 11 | damage = rand() % maxDamage + minDamage; 12 | 13 | if (damage >= 1 && damage <= 3) 14 | rarity = Rarity::common; 15 | else if (damage >= 4 && damage <= 6) 16 | rarity = Rarity::rare; 17 | else if (damage >= 4 && damage <= 6) 18 | rarity = Rarity::rare; 19 | else if (damage >= 7 && damage <= 9) 20 | rarity = Rarity::epic; 21 | else if (damage == 10) 22 | rarity = Rarity::legendary; 23 | } 24 | 25 | Bow::~Bow() 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /game/bow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "weapon.h" 4 | 5 | class Bow : public Weapon 6 | { 7 | public: 8 | Bow(); 9 | ~Bow(); 10 | }; -------------------------------------------------------------------------------- /game/enemy.cpp: -------------------------------------------------------------------------------- 1 | #include "enemy.h" 2 | 3 | Enemy::Enemy() // generate random enemy with random item 4 | { 5 | init(); 6 | 7 | if (rand() % 2 == 0) // generate heal potion 8 | { 9 | activeItem = new HealPotion(); 10 | } 11 | else { // generate weapon 12 | switch (Weapon::random_weapon()) 13 | { 14 | case Weapon::WeaponType::bow: 15 | activeItem = new Bow(); 16 | break; 17 | case Weapon::WeaponType::sword: 18 | activeItem = new Sword(); 19 | break; 20 | } 21 | } 22 | 23 | 24 | int minHealthRandom = 8; 25 | int maxHealthRandom = 30; 26 | 27 | isAlive = true; 28 | handle = enemies[rand() % 5]; 29 | 30 | healStats->maxHealth = 40; 31 | healStats->minHealth = 0; 32 | healStats->health = rand() % maxHealthRandom + minHealthRandom; 33 | 34 | healStats->heal = 3; 35 | healStats->maxHeal = 5; 36 | 37 | int minDamageRandom = 1; 38 | int maxDamageRandom = 5; 39 | damageStats->maxDamage = 6; 40 | damageStats->minDamage = 1; 41 | damageStats->damage = rand() % maxDamageRandom + minDamageRandom; 42 | } 43 | 44 | Enemy::Enemy(std::string name, int health, int damage) 45 | { 46 | init(); 47 | 48 | activeItem = nullptr; 49 | 50 | isAlive = true; 51 | handle = name; 52 | 53 | healStats->health = health; 54 | healStats->maxHealth = 40; 55 | healStats->minHealth = 0; 56 | healStats->heal = 1; 57 | healStats->maxHeal = 2; 58 | 59 | damageStats->damage = damage; 60 | damageStats->maxDamage = 5; 61 | damageStats->minDamage = 1; 62 | } 63 | 64 | Enemy::Enemy(std::string name, int health, int maxHealth, int minHealth, int heal, int maxHeal, int maxDamage, int minDamage, int damage) 65 | { 66 | init(); 67 | 68 | activeItem = nullptr; 69 | 70 | isAlive = true; 71 | handle = name; 72 | 73 | healStats->health = health; 74 | healStats->maxHealth = maxHealth; 75 | healStats->minHealth = minHealth; 76 | healStats->heal = heal; 77 | healStats->maxHeal = maxHeal; 78 | 79 | damageStats->damage = damage; 80 | damageStats->maxDamage = maxDamage; 81 | damageStats->minDamage = minDamage; 82 | } 83 | 84 | void Enemy::init() { 85 | reward = new Reward; 86 | 87 | reward->minGoldReward = 10; 88 | reward->maxGoldReward = 100; 89 | reward->minExpReward = 1; 90 | reward->maxExpReward = 5; 91 | reward->gold = rand() % reward->maxGoldReward + reward->minGoldReward; 92 | reward->exp = rand() % reward->maxExpReward + reward->minExpReward; 93 | } 94 | 95 | Enemy::~Enemy() 96 | { 97 | if (activeItem != nullptr) 98 | delete activeItem; 99 | delete reward; 100 | } 101 | 102 | int Enemy::decrease_health(int dmg) 103 | { 104 | if (healStats != nullptr) { 105 | try 106 | { 107 | if (dmg < 0) 108 | throw NegativeDamageException(); 109 | } 110 | catch (NegativeDamageException &e) { 111 | std::cout << e.what(); 112 | return NULL; 113 | } 114 | 115 | healStats->health -= dmg; 116 | if (healStats->health <= healStats->minHealth) 117 | { 118 | healStats->health = 0; 119 | die(); 120 | return healStats->health; 121 | } 122 | return healStats->health; 123 | } 124 | return NULL; 125 | } 126 | 127 | 128 | int Enemy::increase_health(int heal) 129 | { 130 | if (healStats != nullptr) 131 | { 132 | try 133 | { 134 | if (heal < 0) 135 | throw NegativeHealException(); 136 | } 137 | catch (NegativeHealException &e) { 138 | std::cout << e.what(); 139 | return NULL; 140 | } 141 | 142 | healStats->health += heal; 143 | if (healStats->health > healStats->maxHealth) 144 | healStats->health = healStats->maxHealth; 145 | return healStats->health; 146 | } 147 | return NULL; 148 | } 149 | 150 | int Enemy::attack(Unit *unit) 151 | { 152 | if (unit != nullptr) 153 | { 154 | if (activeItem != nullptr) 155 | { 156 | if (Weapon* weapon = dynamic_cast(activeItem)) // If object is typeof weapon 157 | unit->decrease_health(damageStats->damage + weapon->get_damage()); 158 | else 159 | unit->decrease_health(damageStats->damage); 160 | } 161 | else { 162 | unit->decrease_health(damageStats->damage); 163 | } 164 | return unit->get_health(); 165 | } 166 | return NULL; 167 | } 168 | 169 | int Enemy::attack(Unit *unit, int dmg) 170 | { 171 | if (unit != nullptr) 172 | { 173 | if (activeItem != nullptr) 174 | if (Weapon* weapon = dynamic_cast(activeItem)) // If object is typeof weapon 175 | { 176 | unit->decrease_health(dmg + weapon->get_damage()); 177 | } 178 | else { 179 | unit->decrease_health(dmg); 180 | } 181 | else 182 | unit->decrease_health(dmg); 183 | 184 | return unit->get_health(); 185 | } 186 | return NULL; 187 | } 188 | 189 | int Enemy::heal(Unit *unit) 190 | { 191 | if (unit != nullptr) 192 | { 193 | unit->increase_health(healStats->heal); 194 | return unit->get_health(); 195 | } 196 | return NULL; 197 | } 198 | 199 | int Enemy::heal(Unit *unit, int healAmount) 200 | { 201 | if (unit != nullptr) 202 | { 203 | unit->increase_health(healAmount); 204 | return unit->get_health(); 205 | } 206 | return NULL; 207 | } 208 | 209 | void Enemy::die() 210 | { 211 | isAlive = false; 212 | } 213 | 214 | int Enemy::get_gold() 215 | { 216 | if (reward != nullptr) { 217 | return reward->gold; 218 | } 219 | return NULL; 220 | } 221 | 222 | int Enemy::get_exp() 223 | { 224 | if (reward != nullptr) { 225 | return reward->exp; 226 | } 227 | return NULL; 228 | } -------------------------------------------------------------------------------- /game/enemy.h: -------------------------------------------------------------------------------- 1 | #include "unit.h" 2 | #include "bow.h" 3 | #include "sword.h" 4 | #include "healingpotion.h" 5 | 6 | class Enemy : public Unit 7 | { 8 | protected: 9 | struct Reward 10 | { 11 | int minGoldReward; 12 | int maxGoldReward; 13 | int minExpReward; 14 | int maxExpReward; 15 | int gold; 16 | int exp; 17 | }; 18 | 19 | Reward *reward; 20 | 21 | std::vector enemies = { "skelet", "goblin", "gul'", "zombie", "ogr" }; 22 | 23 | void init(); 24 | 25 | public: 26 | Enemy(); // Default constructor 27 | Enemy(std::string name, int healt, int damage); 28 | Enemy(std::string name, int healt, int maxHealth, int minHealth, int heal, int maxHeal, int maxDamage, int minDamage, int damage); 29 | ~Enemy(); 30 | 31 | int decrease_health(int dmg); 32 | int increase_health(int heal); 33 | 34 | int attack(Unit *unit); 35 | int attack(Unit *unit, int dmg); 36 | 37 | int heal(Unit *unit); 38 | int heal(Unit *unit, int healAmount); 39 | 40 | void die(); 41 | 42 | int get_gold(); 43 | int get_exp(); 44 | }; -------------------------------------------------------------------------------- /game/game.cpp: -------------------------------------------------------------------------------- 1 | #include "game.h" 2 | 3 | void show_banner() { 4 | std::string introBanner = R"EOF( _ 5 | (_) 6 | |=| 7 | |=| 8 | /|__|_|__|\ 9 | ( ( ) ) Welcome to Emberstorm RPG! 10 | \|\/\"/\/|/ >>>>>--------------------------> 11 | | Y | 12 | | | | 13 | | | | 14 | _| | | 15 | __/ | | |\ 16 | / \ | | | \ 17 | __| | | | 18 | /\/ | | | |\ 19 | < +\ | |\ /> \ 20 | > + \ | LJ | 21 | + \|+ \ < \ 22 | (O) + | ) 23 | | \ /\ 24 | ( | ) (o) \/ ) 25 | _\\|//__( | )______)_/ 26 | \\|// 27 | 28 | )EOF"; 29 | std::cout << introBanner; 30 | } 31 | 32 | void update() { 33 | srand(time(NULL)); 34 | } 35 | -------------------------------------------------------------------------------- /game/game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "gameexceptions.h" 15 | 16 | void update(); 17 | void show_banner(); 18 | -------------------------------------------------------------------------------- /game/game.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {D0357620-C8B7-42B6-A99E-9F3D8B462490} 24 | game 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | out\ 74 | $(ProjectName) 75 | 76 | 77 | out\ 78 | $(ProjectName) 79 | 80 | 81 | 82 | Level3 83 | Disabled 84 | true 85 | true 86 | 87 | 88 | 89 | 90 | Level3 91 | Disabled 92 | true 93 | true 94 | 95 | 96 | out\$(TargetName)$(TargetExt) 97 | 98 | 99 | 100 | 101 | Level3 102 | MaxSpeed 103 | true 104 | true 105 | true 106 | true 107 | 108 | 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | MaxSpeed 117 | true 118 | true 119 | true 120 | true 121 | 122 | 123 | true 124 | true 125 | out\$(TargetName)$(TargetExt) 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 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /game/game.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {c6f08517-63ff-4dec-b7d7-73d8f2a1a1fb} 18 | 19 | 20 | {e9b98643-386a-477f-81f9-c60c8cd69eba} 21 | 22 | 23 | {51857676-6afc-41fe-b633-434e74effeec} 24 | 25 | 26 | {2cb27665-e8d2-43b0-9d3e-02be3bda0c75} 27 | 28 | 29 | {6e0b436e-1e4f-4b1c-93fa-80f3726e2708} 30 | 31 | 32 | {e340e166-9318-4e91-8676-bef7780cf876} 33 | 34 | 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files\items 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files\items\potions 59 | 60 | 61 | Source Files\items\weapons 62 | 63 | 64 | Source Files\items\potions 65 | 66 | 67 | Source Files\items\weapons 68 | 69 | 70 | Source Files\items\weapons 71 | 72 | 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files\items 94 | 95 | 96 | Header Files\items\weapons 97 | 98 | 99 | Header Files\items\potions 100 | 101 | 102 | Header Files\items\potions 103 | 104 | 105 | Header Files\items\weapons 106 | 107 | 108 | Header Files\items\weapons 109 | 110 | 111 | -------------------------------------------------------------------------------- /game/gameexceptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct NegativeHealException : public std::exception 4 | { 5 | const char *what() const throw () 6 | { 7 | return "Negative heal exception\n"; 8 | } 9 | }; 10 | 11 | struct NegativeDamageException : public std::exception 12 | { 13 | const char *what() const throw () 14 | { 15 | return "Negative damage exception\n"; 16 | } 17 | }; 18 | 19 | struct NegativeGoldException : public std::exception 20 | { 21 | const char *what() const throw () 22 | { 23 | return "Negative gold exception\n"; 24 | } 25 | }; 26 | 27 | struct NegativeExpException : public std::exception 28 | { 29 | const char *what() const throw () 30 | { 31 | return "Negative experience exception\n"; 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /game/gameobject.cpp: -------------------------------------------------------------------------------- 1 | #include "gameobject.h" -------------------------------------------------------------------------------- /game/gameobject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "game.h" 4 | 5 | // Main class 6 | // Any game object must be inherited from this class 7 | class GameObject 8 | { 9 | 10 | }; -------------------------------------------------------------------------------- /game/healingpotion.cpp: -------------------------------------------------------------------------------- 1 | #include "healingpotion.h" 2 | 3 | HealPotion::HealPotion() 4 | { 5 | desc = "Simple Heal Potion"; 6 | 7 | int minHealVal = 1; 8 | int maxHealVal = 9; 9 | healval = rand() % maxHealVal + minHealVal; 10 | 11 | if (healval >= 1 && healval <= 2) 12 | rarity = Rarity::common; 13 | else if (healval >= 3 && healval <= 4) 14 | rarity = Rarity::rare; 15 | else if (healval >= 5 && healval <= 6) 16 | rarity = Rarity::rare; 17 | else if (healval >= 7 && healval <= 8) 18 | rarity = Rarity::epic; 19 | else if (healval == 9) 20 | rarity = Rarity::legendary; 21 | else 22 | rarity = Rarity::none; 23 | } 24 | 25 | HealPotion::~HealPotion() 26 | { 27 | } 28 | 29 | int HealPotion::use(Unit *unit) 30 | { 31 | return unit->heal(unit, healval); 32 | } 33 | 34 | int HealPotion::get_heal_val() 35 | { 36 | return healval; 37 | } -------------------------------------------------------------------------------- /game/healingpotion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "potion.h" 4 | 5 | class HealPotion : public Potion 6 | { 7 | protected: 8 | int healval; 9 | public: 10 | HealPotion(); 11 | ~HealPotion(); 12 | int use(Unit *unit); 13 | int get_heal_val(); 14 | }; -------------------------------------------------------------------------------- /game/item.cpp: -------------------------------------------------------------------------------- 1 | #include "item.h" 2 | 3 | Item::~Item() {} 4 | 5 | std::string Item::get_desc() 6 | { 7 | return desc; 8 | } 9 | 10 | Item::Rarity Item::get_rarity() 11 | { 12 | return rarity; 13 | } 14 | 15 | std::string Item::get_rarity_str() 16 | { 17 | switch (rarity) 18 | { 19 | case Item::Rarity::common: 20 | return "common"; 21 | case Item::Rarity::rare: 22 | return "rare"; 23 | case Item::Rarity::epic: 24 | return "epic"; 25 | case Item::Rarity::legendary: 26 | return "legendary"; 27 | } 28 | return "none"; 29 | } -------------------------------------------------------------------------------- /game/item.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gameobject.h" 4 | 5 | class Item : public GameObject 6 | { 7 | protected: 8 | std::string desc; 9 | public: 10 | enum Rarity 11 | { 12 | none, 13 | common, 14 | rare, 15 | epic, 16 | legendary, 17 | last 18 | }; 19 | Item::Rarity rarity = Item::Rarity::none; 20 | 21 | std::string get_desc(); 22 | Item::Rarity get_rarity(); 23 | std::string get_rarity_str(); 24 | 25 | virtual ~Item(); 26 | }; -------------------------------------------------------------------------------- /game/main.cpp: -------------------------------------------------------------------------------- 1 | #include "game.h" 2 | #include "player.h" 3 | #include "enemy.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | std::string choice = ""; 8 | 9 | Enemy *enemy = nullptr; 10 | Player *player = nullptr; 11 | 12 | show_banner(); 13 | 14 | for (;;) { 15 | update(); 16 | 17 | std::cout << "* [c]reate - crete new Player with random stats\n"; 18 | std::cout << "* [f]ight - with random enemy\n"; 19 | std::cout << "* [s]tats - view your stats\n"; 20 | std::cout << "* [i]nventory - view your inventory\n"; 21 | std::cout << "* [e]xit - leave game\n"; 22 | std::cout << "> "; 23 | std::cin >> choice; 24 | std::cout << '\n'; 25 | 26 | if (choice == "create" || choice == "c") { 27 | std::string name; 28 | std::cout << "[*] Enter player name: "; 29 | std::cin >> name; 30 | std::cout << '\n'; 31 | 32 | player = new Player(name); 33 | if (player != nullptr) { 34 | std::cout << "[*] Player created!\n"; 35 | std::cout << "[*] Your stats\n"; 36 | std::cout << "[*] Handle: " + player->get_handle() + "\n"; 37 | std::cout << "[*] Health: " + std::to_string(player->get_health()) + "\n"; 38 | 39 | //printf("[+] player health address: 0x%p\n", player->get_health_ptr()); 40 | 41 | std::cout << "[*] Heal: " + std::to_string(player->get_heal()) + "\n"; 42 | std::cout << "[*] Damage: " + std::to_string(player->get_damage()) + "\n"; 43 | std::cout << "[*] Gold: " + std::to_string(player->get_gold()) + "\n"; 44 | std::cout << "[*] Exp: " + std::to_string(player->get_exp()) + "\n"; 45 | std::cout << "[*] Total Killed: " + std::to_string(player->get_total_killed()) + "\n\n"; 46 | } 47 | else { 48 | std::cout << "[-] Something went horribly wrong...\n"; 49 | } 50 | } 51 | else if (choice == "fight" || choice == "f") { 52 | if (player != nullptr) { 53 | enemy = new Enemy(); 54 | if (enemy != nullptr) { 55 | std::cout << "[*] Enemy stats\n"; 56 | std::cout << "[*] Handle: " + enemy->get_handle() + "\n"; 57 | std::cout << "[*] Health: " + std::to_string(enemy->get_health()) + "\n"; 58 | std::cout << "[*] Heal: " + std::to_string(enemy->get_heal()) + "\n"; 59 | if (enemy->get_active_item() != nullptr) 60 | { 61 | if (Weapon* weapon = dynamic_cast(enemy->get_active_item())) // If object is typeof weapon 62 | { 63 | std::cout << "[*] Damage: " + std::to_string(enemy->get_damage() - weapon->get_damage()) + " (+" + std::to_string(weapon->get_damage()) + ")" + "\n"; 64 | } 65 | else { 66 | std::cout << "[*] Damage: " + std::to_string(enemy->get_damage()) + "\n"; 67 | } 68 | } 69 | else { 70 | std::cout << "[*] Damage: " + std::to_string(enemy->get_damage()) + "\n"; 71 | } 72 | std::cout << "[*] Gold: " + std::to_string(enemy->get_gold()) + "\n"; 73 | std::cout << "[*] Exp: " + std::to_string(enemy->get_exp()) + "\n"; 74 | 75 | if (enemy->get_active_item() != nullptr) 76 | { 77 | if (Weapon* weapon = dynamic_cast(enemy->get_active_item())) // If object is typeof weapon 78 | { 79 | std::cout << "[*] Enemy item: " + weapon->get_type_str() + "\n"; 80 | std::cout << "[*] Damage: " + std::to_string(weapon->get_damage()) + "\n"; 81 | } 82 | else if (HealPotion* healPotion = dynamic_cast(enemy->get_active_item())) { 83 | std::cout << "[*] Enemy item: healing Potion\n"; 84 | std::cout << "[*] Heal: " + std::to_string(healPotion->get_heal_val()) + "\n"; 85 | } 86 | std::cout << "[*] Rarity: " + enemy->get_active_item()->get_rarity_str() + "\n"; 87 | } 88 | 89 | // While hp of enemy and player isnt null 90 | while (player->get_isAlive() && enemy->get_isAlive()) 91 | { 92 | update(); 93 | std::cout << "* Write [a]ttack to attack enemy\n"; 94 | std::cout << "* Write [h]eal to heal yourself\n"; 95 | std::cout << "* Write [r]un away to run away (you will lose exp and gold)\n> "; 96 | std::cin >> choice; 97 | std::cout << '\n'; 98 | 99 | if (choice == "a" || choice == "attack") { 100 | player->attack(enemy); 101 | std::cout << "[+] You have dealt " + std::to_string(player->get_damage()) + " damage\n"; 102 | std::cout << "[+] Enemy health: " + std::to_string(enemy->get_health()) + "\n"; 103 | 104 | if (enemy->get_isAlive()) 105 | { 106 | std::cout << "[*] Enemy attacking you\n"; 107 | enemy->attack(player); 108 | std::cout << "[+] You were dealt " + std::to_string(enemy->get_damage()) + " points of damage\n"; 109 | std::cout << "[+] Your health: " + std::to_string(player->get_health()) + "\n\n"; 110 | } 111 | } 112 | else if (choice == "h" || choice == "heal") 113 | { 114 | std::cout << "[+] Available healing potions:\n"; 115 | int counter = 1; 116 | for (Item *item : *player->get_inventory()) 117 | { 118 | if (HealPotion* healPotion = dynamic_cast(item)) 119 | { 120 | std::cout << "---------- " + std::to_string(counter) + " ----------\n"; 121 | std::cout << "[+] Heal: " + std::to_string(healPotion->get_heal_val()) << "\n"; 122 | std::cout << "[+] Desc: " + healPotion->get_desc() << "\n"; 123 | std::cout << "[+] Rarity: " + healPotion->get_rarity_str() << "\n"; 124 | } 125 | counter++; 126 | } 127 | 128 | std::cout << "[+] Which one you want to use?\n> "; 129 | std::cin >> choice; 130 | 131 | if (std::stoi(choice) > 0 && std::stoi(choice) <= player->get_inventory()->size()) 132 | { 133 | if ((*player->get_inventory())[std::stoull(choice) - 1] != nullptr) 134 | { 135 | if (HealPotion* healPotion = dynamic_cast((*player->get_inventory())[std::stoull(choice) - 1])) 136 | { 137 | healPotion->use(player); 138 | std::cout << "[+] You cured yourself for " + std::to_string(healPotion->get_heal_val()) + " hitpoints\n"; 139 | std::cout << "[+] Your hp: " + std::to_string(player->get_health()) + "\n"; 140 | 141 | delete (*player->get_inventory())[std::stoull(choice) - 1]; 142 | player->get_inventory()->erase(player->get_inventory()->begin() + std::stoi(choice) - 1); 143 | } 144 | else { 145 | std::cout << "[-] Not a potion\n"; 146 | } 147 | } 148 | } 149 | else { 150 | std::cout << "[-] Cannot use this potion\n"; 151 | } 152 | 153 | std::cout << "[*] Enemy attacking you\n"; 154 | enemy->attack(player); 155 | std::cout << "[+] You were dealt " + std::to_string(enemy->get_damage()) + " points of damage\n"; 156 | std::cout << "[+] Your health: " + std::to_string(player->get_health()) + "\n\n"; 157 | } 158 | else if (choice == "r" || choice == "run") 159 | { 160 | player->decrease_gold(enemy->get_gold()); 161 | player->decrease_exp(enemy->get_exp()); 162 | 163 | std::cout << "[-] You are running away!\n"; 164 | std::cout << "[+] You lost " + std::to_string(enemy->get_gold()) + " gold\n"; 165 | std::cout << "[+] You lost " + std::to_string(enemy->get_exp()) + " exp\n\n"; 166 | break; 167 | } 168 | } 169 | if (!player->get_isAlive()) { 170 | std::cout << "[-] You died\n"; 171 | player = nullptr; 172 | } 173 | else if (!enemy->get_isAlive()) { 174 | player->increase_total_killed(); 175 | player->increase_gold(enemy->get_gold()); 176 | player->increase_exp(enemy->get_exp()); 177 | std::cout << "[+] You got\n"; 178 | std::cout << "[+] Gold: " + std::to_string(enemy->get_gold()) + "\n"; 179 | std::cout << "[+] Exp: " + std::to_string(enemy->get_exp()) + "\n"; 180 | 181 | if (enemy->get_active_item() != nullptr) 182 | { 183 | if (Weapon* weapon = dynamic_cast(enemy->get_active_item())) // If object is typeof weapon 184 | { 185 | std::cout << "[*] New item: " + weapon->get_type_str() + "\n"; 186 | std::cout << "[*] Damage: " + std::to_string(weapon->get_damage()) + "\n"; 187 | } 188 | player->lift_item(enemy->get_active_item()); 189 | } 190 | std::cout << "[+] You win\n\n"; 191 | } 192 | delete enemy; 193 | enemy = nullptr; 194 | } 195 | else { 196 | std::cout << "[-] Cannot create enemy\n"; 197 | } 198 | } 199 | else { 200 | std::cout << "Player is NULL\n\n"; 201 | } 202 | } 203 | else if (choice == "stats" || choice == "s") 204 | { 205 | if (player != nullptr) 206 | { 207 | std::cout << "[*] Your stats\n"; 208 | std::cout << "[*] Handle: " + player->get_handle() + "\n"; 209 | std::cout << "[*] Health: " + std::to_string(player->get_health()) + "\n"; 210 | std::cout << "[*] Heal: " + std::to_string(player->get_heal()) + "\n"; 211 | if (player->get_active_item() != nullptr) 212 | { 213 | if (Weapon* weapon = dynamic_cast(player->get_active_item())) // If object is typeof weapon 214 | { 215 | std::cout << "[*] Damage: " + std::to_string(player->get_damage() - weapon->get_damage()) + " (+" + std::to_string(weapon->get_damage()) + ")" + "\n"; 216 | } 217 | else { 218 | std::cout << "[*] Damage: " + std::to_string(player->get_damage()) + "\n"; 219 | } 220 | } 221 | else { 222 | std::cout << "[*] Damage: " + std::to_string(player->get_damage()) + "\n"; 223 | } 224 | std::cout << "[*] Gold: " + std::to_string(player->get_gold()) + "\n"; 225 | std::cout << "[*] Exp: " + std::to_string(player->get_exp()) + "\n"; 226 | std::cout << "[*] Total Killed: " + std::to_string(player->get_total_killed()) + "\n\n"; 227 | } 228 | else { 229 | std::cout << "[-] Player is NULL\n"; 230 | } 231 | } 232 | else if (choice == "inventory" || choice == "i") // FIXME: I DONT KNOW HOW TO MAKE INVENTORY WORK! 233 | { 234 | if (player != nullptr) 235 | { 236 | std::cout << "[d]isplay - display inventory\n"; 237 | std::cout << "[e]quip - equip new item\n> "; 238 | std::cin >> choice; 239 | std::cout << "\n"; 240 | 241 | if (choice == "d" || choice == "display") 242 | { 243 | if (player->get_active_item() != nullptr) 244 | { 245 | std::cout << "[+] Currently selected item\n"; 246 | if (Weapon* weapon = dynamic_cast(player->get_active_item())) 247 | { 248 | std::cout << " * Type: " + weapon->get_type_str() << "\n"; 249 | std::cout << " * Desc: " + weapon->get_desc() + "\n"; 250 | std::cout << " * Damage: " + std::to_string(weapon->get_damage()) + "\n"; 251 | std::cout << " * Rarity: " + weapon->get_rarity_str() + "\n"; 252 | } 253 | } 254 | else { 255 | std::cout << "[-] No item selected\n"; 256 | } 257 | 258 | std::cout << "[*] Your inventory:\n"; 259 | int counter = 1; 260 | if (player->get_inventory()->size() == 0) 261 | { 262 | std::cout << " Inventory is empty\n"; 263 | } 264 | 265 | for (Item *item : *(player->get_inventory())) 266 | { 267 | if (item != nullptr) 268 | { 269 | std::cout << "---------- " + std::to_string(counter) + " ----------\n"; 270 | if (Weapon* weapon = dynamic_cast(item)) 271 | { 272 | std::cout << " * Item: " + weapon->get_type_str() + "\n"; 273 | std::cout << " * Desc: " + weapon->get_desc() + "\n"; 274 | std::cout << " * Damage: " + std::to_string(weapon->get_damage()) + "\n"; 275 | std::cout << " * Rarity: " + weapon->get_rarity_str() + "\n"; 276 | } 277 | else if (HealPotion* healPotion = dynamic_cast(item)) 278 | { 279 | std::cout << " * Item: healing potion\n"; 280 | std::cout << " * Desc: " + healPotion->get_desc() + "\n"; 281 | std::cout << " * Heal: " + std::to_string(healPotion->get_heal_val()) + "\n"; 282 | std::cout << " * Rarity: " + healPotion->get_rarity_str() + "\n"; 283 | } 284 | } 285 | counter++; 286 | } 287 | std::cout << "\n"; 288 | } 289 | else if (choice == "e" || choice == "equip") 290 | { 291 | if (player->get_inventory()->size() != 0) 292 | { 293 | std::cout << "[+] Select item you want to pick up [1-" + std::to_string(player->get_inventory()->size()) + "]\n> "; 294 | std::cin >> choice; 295 | std::cout << "\n"; 296 | if (std::stoi(choice) > 0 297 | && std::stoi(choice) <= player->get_inventory()->size() 298 | && (*player->get_inventory())[std::stoull(choice) - 1] != nullptr) 299 | { 300 | if (HealPotion* healPotion = dynamic_cast((*player->get_inventory())[std::stoull(choice) - 1])) 301 | { 302 | std::cout << "[-] Cannot select heal potion as active item\n[-] Potions can be used only in battle\n\n"; 303 | } 304 | else { 305 | if (player->get_active_item() != nullptr) 306 | { 307 | Item *temp; 308 | temp = player->get_active_item(); 309 | player->equip((*player->get_inventory())[std::stoull(choice) - 1]); 310 | (*player->get_inventory())[std::stoull(choice) - 1] = temp; 311 | } 312 | else { 313 | player->equip((*player->get_inventory())[std::stoull(choice) - 1]); 314 | (*player->get_inventory()).pop_back(); 315 | } 316 | std::cout << "[+] Successfully selected!\n\n"; 317 | } 318 | } 319 | else { 320 | std::cout << "[-] Wrong inventory index\n\n"; 321 | } 322 | } 323 | else { 324 | std::cout << "[-] Inventory is empty\n\n"; 325 | } 326 | } 327 | } 328 | else { 329 | std::cout << "[-] Player is NULL!\n\n"; 330 | } 331 | } 332 | else if (choice == "exit" || choice == "e") { 333 | std::cout << "Goodbye!\n"; 334 | return 0; 335 | } 336 | } 337 | 338 | return 0; 339 | } -------------------------------------------------------------------------------- /game/player.cpp: -------------------------------------------------------------------------------- 1 | #include "player.h" 2 | 3 | Player::Player() 4 | { 5 | init(); 6 | 7 | isAlive = true; 8 | handle = "player"; 9 | 10 | healStats->health = 63; 11 | healStats->maxHealth = 80; 12 | healStats->minHealth = 0; 13 | 14 | healStats->heal = 0; 15 | healStats->maxHeal = 0; 16 | 17 | damageStats->damage = 2; 18 | damageStats->maxDamage = 5; 19 | damageStats->minDamage = 1; 20 | } 21 | 22 | Player::Player(std::string name) 23 | { 24 | init(); 25 | 26 | isAlive = true; 27 | handle = name; 28 | 29 | healStats->health = 63; 30 | healStats->maxHealth = 80; 31 | healStats->minHealth = 0; 32 | healStats->heal = 0; 33 | healStats->maxHeal = 0; 34 | 35 | damageStats->damage = 4; 36 | damageStats->maxDamage = 7; 37 | damageStats->minDamage = 1; 38 | } 39 | 40 | Player::Player(std::string name, int health, int damage) 41 | { 42 | isAlive = true; 43 | handle = name; 44 | 45 | healStats->health = health; 46 | healStats->maxHealth = 40; 47 | healStats->minHealth = 0; 48 | healStats->heal = 0; 49 | healStats->maxHeal = 0; 50 | 51 | damageStats->damage = damage; 52 | damageStats->maxDamage = 5; 53 | damageStats->minDamage = 1; 54 | } 55 | 56 | Player::Player(std::string name, int health, int maxHealth, int minHealth, int heal, int maxHeal, int maxDamage, int minDamage, int damage) 57 | { 58 | init(); 59 | 60 | isAlive = true; 61 | handle = name; 62 | 63 | healStats->health = health; 64 | healStats->maxHealth = maxHealth; 65 | healStats->minHealth = minHealth; 66 | healStats->heal = heal; 67 | healStats->maxHeal = maxHeal; 68 | 69 | damageStats->damage = damage; 70 | damageStats->maxDamage = maxDamage; 71 | damageStats->minDamage = minDamage; 72 | } 73 | 74 | Player::~Player() 75 | { 76 | } 77 | 78 | void Player::init() 79 | { 80 | if (properties == nullptr) 81 | { 82 | properties = new Properties; 83 | properties->exp = 0; 84 | properties->gold = 0; 85 | } 86 | } 87 | 88 | int Player::increase_gold(int gold) 89 | { 90 | if (properties != nullptr) 91 | { 92 | try 93 | { 94 | if (gold < 0) 95 | throw NegativeGoldException(); 96 | } 97 | catch (NegativeGoldException &e) { 98 | std::cout << e.what(); 99 | return NULL; 100 | } 101 | properties->gold += gold; 102 | return properties->gold; 103 | } 104 | return NULL; 105 | } 106 | 107 | int Player::increase_exp(int exp) 108 | { 109 | if (properties != nullptr) 110 | { 111 | try 112 | { 113 | if (exp < 0) 114 | throw NegativeExpException(); 115 | } 116 | catch (NegativeExpException &e) { 117 | std::cout << e.what(); 118 | return NULL; 119 | } 120 | properties->exp += exp; 121 | return properties->exp; 122 | } 123 | return NULL; 124 | } 125 | 126 | int Player::decrease_gold(int gold) 127 | { 128 | if (properties != nullptr) 129 | { 130 | try 131 | { 132 | if (gold < 0) 133 | throw NegativeGoldException(); 134 | } 135 | catch (NegativeGoldException &e) { 136 | std::cout << e.what(); 137 | return NULL; 138 | } 139 | properties->gold -= gold; 140 | if (properties->gold < 0) 141 | properties->gold = 0; 142 | return properties->gold; 143 | } 144 | return NULL; 145 | } 146 | 147 | int Player::decrease_exp(int exp) 148 | { 149 | if (properties != nullptr) 150 | { 151 | try 152 | { 153 | if (exp < 0) 154 | throw NegativeExpException(); 155 | } 156 | catch (NegativeExpException &e) { 157 | std::cout << e.what(); 158 | return NULL; 159 | } 160 | properties->exp -= exp; 161 | if (properties->exp < 0) 162 | properties->exp = 0; 163 | return properties->exp; 164 | } 165 | return NULL; 166 | } 167 | 168 | int Player::increase_total_killed() 169 | { 170 | if (properties != nullptr) 171 | { 172 | properties->toltalKilled++; 173 | return properties->toltalKilled; 174 | } 175 | return NULL; 176 | } 177 | 178 | int Player::decrease_health(int dmg) 179 | { 180 | if (healStats != nullptr) { 181 | try 182 | { 183 | if (dmg < 0) 184 | throw NegativeDamageException(); 185 | } 186 | catch (NegativeDamageException &e) { 187 | std::cout << e.what(); 188 | return NULL; 189 | } 190 | 191 | healStats->health -= dmg; 192 | if (healStats->health <= healStats->minHealth) 193 | { 194 | healStats->health = 0; 195 | die(); 196 | return healStats->health; 197 | } 198 | return healStats->health; 199 | } 200 | return NULL; 201 | } 202 | 203 | 204 | int Player::increase_health(int heal) 205 | { 206 | if (healStats != nullptr) 207 | { 208 | try 209 | { 210 | if (heal < 0) 211 | throw NegativeHealException(); 212 | } 213 | catch (NegativeHealException &e) { 214 | std::cout << e.what(); 215 | return NULL; 216 | } 217 | 218 | healStats->health += heal; 219 | if (healStats->health > healStats->maxHealth) 220 | healStats->health = healStats->maxHealth; 221 | return healStats->health; 222 | } 223 | return NULL; 224 | } 225 | 226 | int Player::attack(Unit *unit) 227 | { 228 | if (unit != nullptr) 229 | { 230 | if (activeItem != nullptr) 231 | { 232 | if (Bow* bow = dynamic_cast(activeItem)) { 233 | unit->decrease_health(damageStats->damage + bow->get_damage()); 234 | } 235 | else if (Sword* sword = dynamic_cast(activeItem)) 236 | { 237 | unit->decrease_health(damageStats->damage + sword->get_damage()); 238 | } 239 | else { 240 | unit->decrease_health(damageStats->damage); 241 | } 242 | } 243 | else 244 | unit->decrease_health(damageStats->damage); 245 | 246 | return unit->get_health(); 247 | } 248 | return NULL; 249 | } 250 | 251 | int Player::attack(Unit *unit, int dmg) 252 | { 253 | if (unit != nullptr) 254 | { 255 | if (activeItem != nullptr) 256 | { 257 | if (Bow* bow = dynamic_cast(activeItem)) { 258 | unit->decrease_health(dmg + bow->get_damage()); 259 | } 260 | else if (Sword* sword = dynamic_cast(activeItem)) 261 | { 262 | unit->decrease_health(dmg + sword->get_damage()); 263 | } 264 | else { 265 | unit->decrease_health(dmg); 266 | } 267 | } 268 | else 269 | unit->decrease_health(dmg); 270 | 271 | return unit->get_health(); 272 | } 273 | return NULL; 274 | } 275 | 276 | int Player::heal(Unit *unit) 277 | { 278 | if (unit != nullptr) 279 | { 280 | unit->increase_health(healStats->heal); 281 | return unit->get_health(); 282 | } 283 | return NULL; 284 | } 285 | 286 | int Player::heal(Unit *unit, int healAmount) 287 | { 288 | if (unit != nullptr) 289 | { 290 | unit->increase_health(healAmount); 291 | return unit->get_health(); 292 | } 293 | return NULL; 294 | } 295 | 296 | size_t Player::lift_item(Item *item) 297 | { 298 | if (Bow* bow = dynamic_cast(item)) { 299 | items.push_back(new Bow(*bow)); 300 | } 301 | else if (Sword* sword = dynamic_cast(item)) 302 | { 303 | items.push_back(new Sword(*sword)); 304 | } 305 | else if (HealPotion* healPotion = dynamic_cast(item)) 306 | { 307 | items.push_back(new HealPotion(*healPotion)); 308 | } 309 | return items.size(); 310 | } 311 | 312 | void Player::equip(Item *item) 313 | { 314 | if (Bow* bow = dynamic_cast(item)) 315 | { 316 | activeItem = bow; // Should i create here new Bow? Or I can reuse old one? 317 | } 318 | else if (Sword* sword = dynamic_cast(item)) 319 | { 320 | activeItem = sword; 321 | } 322 | } 323 | 324 | void Player::die() 325 | { 326 | isAlive = false; 327 | } 328 | 329 | int Player::get_gold() 330 | { 331 | if (properties != nullptr) 332 | { 333 | return properties->gold; 334 | } 335 | return NULL; 336 | } 337 | 338 | int Player::get_exp() 339 | { 340 | if (properties != nullptr) 341 | { 342 | return properties->exp; 343 | } 344 | return NULL; 345 | } 346 | 347 | int Player::get_total_killed() 348 | { 349 | if (properties != nullptr) 350 | { 351 | return properties->toltalKilled; 352 | } 353 | return NULL; 354 | } 355 | -------------------------------------------------------------------------------- /game/player.h: -------------------------------------------------------------------------------- 1 | #include "unit.h" 2 | #include "bow.h" 3 | #include "sword.h" 4 | #include "healingpotion.h" 5 | 6 | class Player : public Unit 7 | { 8 | protected: 9 | struct Properties 10 | { 11 | int gold = 0; 12 | int exp = 0; 13 | int toltalKilled = 0; 14 | }; 15 | Properties *properties = nullptr; 16 | 17 | public: 18 | Player(); // Default constructor 19 | Player(std::string name); 20 | Player(std::string name, int healt, int damage); 21 | Player(std::string name, int healt, int maxHealth, int minHealth, int heal, int maxHeal, int maxDamage, int minDamage, int damage); 22 | ~Player(); 23 | 24 | int increase_gold(int gold); 25 | int increase_exp(int exp); 26 | int decrease_gold(int gold); 27 | int decrease_exp(int exp); 28 | int increase_total_killed(); 29 | 30 | int decrease_health(int dmg); 31 | int increase_health(int heal); 32 | 33 | int attack(Unit *unit); 34 | int attack(Unit *unit, int dmg); 35 | 36 | int heal(Unit *unit); 37 | int heal(Unit *unit, int healAmount); 38 | 39 | size_t lift_item(Item *item); // add item to inventory 40 | void equip(Item *item); // equip weapon 41 | 42 | void die(); 43 | void init(); 44 | 45 | int get_gold(); 46 | int get_exp(); 47 | int get_total_killed(); 48 | }; -------------------------------------------------------------------------------- /game/potion.cpp: -------------------------------------------------------------------------------- 1 | #include "potion.h" 2 | 3 | Potion::Potion() 4 | { 5 | 6 | } 7 | 8 | Potion::~Potion() 9 | { 10 | 11 | } 12 | 13 | int Potion::use(Unit *unit) 14 | { 15 | return 0; 16 | } -------------------------------------------------------------------------------- /game/potion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "item.h" 4 | #include "unit.h" 5 | 6 | class Potion : public Item 7 | { 8 | public: 9 | enum PotionType 10 | { 11 | none, 12 | heal, 13 | last 14 | }; 15 | Potion::PotionType potionType = Potion::PotionType::none; 16 | 17 | Potion(); 18 | ~Potion(); 19 | virtual int use(Unit *unit); 20 | 21 | Potion::PotionType get_type() {}; 22 | }; -------------------------------------------------------------------------------- /game/sword.cpp: -------------------------------------------------------------------------------- 1 | #include "sword.h" 2 | 3 | Sword::Sword() 4 | { 5 | desc = "Simple Sword"; 6 | 7 | weaponType = WeaponType::sword; 8 | 9 | int minDamage = 1; 10 | int maxDamage = 10; 11 | damage = rand() % maxDamage + minDamage; 12 | 13 | if (damage >= 1 && damage <= 3) 14 | rarity = Rarity::common; 15 | else if (damage >= 4 && damage <= 6) 16 | rarity = Rarity::rare; 17 | else if (damage >= 4 && damage <= 6) 18 | rarity = Rarity::rare; 19 | else if (damage >= 7 && damage <= 9) 20 | rarity = Rarity::epic; 21 | else if (damage == 10) 22 | rarity = Rarity::legendary; 23 | } 24 | 25 | Sword::~Sword() 26 | { 27 | } -------------------------------------------------------------------------------- /game/sword.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "weapon.h" 4 | 5 | class Sword : public Weapon 6 | { 7 | public: 8 | Sword(); 9 | ~Sword(); 10 | }; -------------------------------------------------------------------------------- /game/unit.cpp: -------------------------------------------------------------------------------- 1 | #include "unit.h" 2 | #include "bow.h" 3 | #include "sword.h" 4 | #include "healingpotion.h" 5 | 6 | Unit::Unit() { // Constructor 7 | healStats = new HealStats; 8 | damageStats = new DamageStats; 9 | } 10 | 11 | Unit::~Unit() { // Destructor 12 | delete healStats; 13 | delete damageStats; 14 | 15 | for (int i = 0; i < items.size(); ++i) 16 | { 17 | if (items[i] != nullptr) 18 | delete items[i]; 19 | } 20 | } 21 | 22 | std::string Unit::get_handle() 23 | { 24 | return handle; 25 | } 26 | 27 | int Unit::get_health() 28 | { 29 | if (healStats != nullptr) 30 | return healStats->health; 31 | return NULL; 32 | } 33 | 34 | //void* Unit::get_health_ptr() 35 | //{ 36 | // if (healStats != nullptr) 37 | // return &(healStats->health); 38 | // return NULL; 39 | //} 40 | 41 | int Unit::get_heal() 42 | { 43 | if (healStats != nullptr) 44 | return healStats->heal; 45 | return NULL; 46 | } 47 | 48 | int Unit::get_damage() 49 | { 50 | if (damageStats != nullptr) { 51 | if (activeItem != nullptr) 52 | { 53 | if (Bow* bow = dynamic_cast(activeItem)) { 54 | return damageStats->damage + bow->get_damage(); 55 | } 56 | else if (Sword* sword = dynamic_cast(activeItem)) 57 | { 58 | return damageStats->damage + sword->get_damage(); 59 | } 60 | } 61 | return damageStats->damage; 62 | } 63 | return NULL; 64 | } 65 | 66 | bool Unit::get_isAlive() 67 | { 68 | return isAlive; 69 | } 70 | 71 | std::vector * Unit::get_inventory() 72 | { 73 | return &items; 74 | } 75 | 76 | Item* Unit::get_active_item() 77 | { 78 | if (activeItem != nullptr) 79 | return activeItem; 80 | return NULL; 81 | } -------------------------------------------------------------------------------- /game/unit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gameobject.h" 4 | #include "weapon.h" 5 | #include "item.h" 6 | 7 | class Unit : public GameObject 8 | { 9 | protected: 10 | struct HealStats 11 | { 12 | int health; 13 | int maxHealth; 14 | int minHealth; 15 | int heal; 16 | int maxHeal; 17 | }; 18 | 19 | struct DamageStats 20 | { 21 | int damage; 22 | int maxDamage; 23 | int minDamage; 24 | }; 25 | 26 | HealStats *healStats = nullptr; 27 | DamageStats *damageStats = nullptr; 28 | std::string handle; 29 | bool isAlive = false; 30 | 31 | std::vector items; // all items 32 | Item *activeItem = nullptr; // currently acvtive item 33 | 34 | public: 35 | Unit(); 36 | ~Unit(); 37 | 38 | virtual int decrease_health(int dmg) = 0; // damage yourself 39 | virtual int increase_health(int heal) = 0; 40 | virtual int attack(Unit *unit) = 0; // use unit default damage value 41 | virtual int attack(Unit *unit, int dmg) = 0; 42 | virtual int heal(Unit *unit) = 0; // use unit default heal value 43 | virtual int heal(Unit *unit, int healAmount) = 0; 44 | virtual void die(void) = 0; 45 | 46 | std::string get_handle(); 47 | int get_health(); 48 | 49 | //void* get_health_ptr(); 50 | 51 | int get_heal(); 52 | int get_damage(); 53 | bool get_isAlive(); 54 | 55 | std::vector * get_inventory(); 56 | Item* get_active_item(); 57 | }; -------------------------------------------------------------------------------- /game/weapon.cpp: -------------------------------------------------------------------------------- 1 | #include "weapon.h" 2 | 3 | Weapon::WeaponType Weapon::random_weapon() 4 | { 5 | return static_cast(rand() % Weapon::WeaponType::last); 6 | } 7 | 8 | int Weapon::get_damage() 9 | { 10 | return damage; 11 | } 12 | 13 | Weapon::WeaponType Weapon::get_type() 14 | { 15 | return weaponType; 16 | } 17 | 18 | std::string Weapon::get_type_str() 19 | { 20 | switch (weaponType) 21 | { 22 | case Weapon::WeaponType::bow: 23 | return "bow"; 24 | case Weapon::WeaponType::sword: 25 | return "sword"; 26 | default: 27 | return "none"; 28 | } 29 | } -------------------------------------------------------------------------------- /game/weapon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "item.h" 4 | 5 | class Weapon : public Item 6 | { 7 | protected: 8 | int damage = 0; 9 | public: 10 | enum WeaponType 11 | { 12 | none, 13 | sword, 14 | bow, 15 | last 16 | }; 17 | Weapon::WeaponType weaponType = Weapon::WeaponType::none; 18 | 19 | Weapon::WeaponType get_type(); 20 | std::string get_type_str(); 21 | int get_damage(); 22 | static Weapon::WeaponType random_weapon(); 23 | }; -------------------------------------------------------------------------------- /gameUnitTests/gameUnitTests.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {68D600E6-E1A8-4A92-8D0E-58EC68CB7608} 24 | Win32Proj 25 | gameUnitTests 26 | 10.0 27 | NativeUnitTestProject 28 | 29 | 30 | 31 | DynamicLibrary 32 | true 33 | v142 34 | Unicode 35 | false 36 | 37 | 38 | DynamicLibrary 39 | false 40 | v142 41 | true 42 | Unicode 43 | false 44 | 45 | 46 | DynamicLibrary 47 | true 48 | v142 49 | Unicode 50 | false 51 | 52 | 53 | DynamicLibrary 54 | false 55 | v142 56 | true 57 | Unicode 58 | false 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | true 80 | C:\Users\madrat\Desktop\simple_cheats\game;$(IncludePath) 81 | 82 | 83 | true 84 | 85 | 86 | true 87 | 88 | 89 | true 90 | C:\Users\madrat\Desktop\simple_cheats\game\source\repos\game\game;$(IncludePath) 91 | 92 | 93 | 94 | Use 95 | Level3 96 | Disabled 97 | $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) 98 | _DEBUG;%(PreprocessorDefinitions) 99 | true 100 | 101 | 102 | Windows 103 | $(VCInstallDir)UnitTest\lib;C:\Users\madrat\Desktop\simple_cheats\game\x64\Debug;%(AdditionalLibraryDirectories) 104 | bow.obj;enemy.obj;game.obj;gameobject.obj;healingpotion.obj;item.obj;main.obj;player.obj;potion.obj;sword.obj;unit.obj;weapon.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 105 | 106 | 107 | 108 | 109 | Use 110 | Level3 111 | Disabled 112 | $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) 113 | WIN32;_DEBUG;%(PreprocessorDefinitions) 114 | true 115 | 116 | 117 | Windows 118 | $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) 119 | 120 | 121 | 122 | 123 | Level3 124 | Use 125 | MaxSpeed 126 | true 127 | true 128 | $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) 129 | WIN32;NDEBUG;%(PreprocessorDefinitions) 130 | true 131 | 132 | 133 | Windows 134 | true 135 | true 136 | $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) 137 | 138 | 139 | 140 | 141 | Level3 142 | Use 143 | MaxSpeed 144 | true 145 | true 146 | $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) 147 | NDEBUG;%(PreprocessorDefinitions) 148 | true 149 | 150 | 151 | Windows 152 | true 153 | true 154 | $(VCInstallDir)UnitTest\lib;C:\Users\madrat\Desktop\simple_cheats\game\source\repos\game\game\x64\Debug;%(AdditionalLibraryDirectories) 155 | bow.obj;enemy.obj;game.obj;gameobject.obj;healingpotion.obj;item.obj;main.obj;player.obj;potion.obj;sword.obj;unit.obj;weapon.obj;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | Create 165 | Create 166 | Create 167 | Create 168 | 169 | 170 | 171 | 172 | 173 | 174 | {d0357620-c8b7-42b6-a99e-9f3d8b462490} 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /gameUnitTests/gameUnitTests.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /gameUnitTests/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // gameUnitTests.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /gameUnitTests/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | // Headers for CppUnitTest 11 | #include "CppUnitTest.h" 12 | 13 | // TODO: reference additional headers your program requires here 14 | -------------------------------------------------------------------------------- /gameUnitTests/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /gameUnitTests/testGameLogic.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CppUnitTest.h" 3 | 4 | #include "game.h" 5 | #include "player.h" 6 | #include "enemy.h" 7 | 8 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 9 | 10 | namespace unittests 11 | { 12 | TEST_CLASS(TestGameLogic) 13 | { 14 | public: 15 | 16 | TEST_METHOD(TestAttack) 17 | { 18 | std::string pName = "AAAAAAAA"; 19 | int pHealth = 20; 20 | int pDmg = 2; 21 | Player *player = new Player(pName, pHealth, pDmg); 22 | 23 | std::string eName = "BBBBBBBB"; 24 | int eHealth = 10; 25 | int eDmg = 1; 26 | Enemy *enemy = new Enemy(eName, eHealth, eDmg); 27 | 28 | Assert::AreEqual(eHealth - pDmg, player->attack(enemy)); 29 | } 30 | 31 | TEST_METHOD(TestAttackUnderZero) 32 | { 33 | std::string pName = "madrat"; 34 | int pHealth = 2023; 35 | int pDmg = 18; 36 | Player *player = new Player(pName, pHealth, pDmg); 37 | 38 | std::string eName = "goblin"; 39 | int eHealth = 9; 40 | int eDmg = 5; 41 | Enemy *enemy = new Enemy(eName, eHealth, eDmg); 42 | 43 | Assert::AreEqual(0, player->attack(enemy)); 44 | } 45 | 46 | TEST_METHOD(TestPlayerEquip) 47 | { 48 | std::string pName = "madrat"; 49 | int pHealth = 240; 50 | int pDmg = 64; 51 | Player *player = new Player(pName, pHealth, pDmg); 52 | 53 | Bow *bow = new Bow(); 54 | 55 | player->equip(bow); 56 | 57 | Item *equipedItem = player->get_active_item(); 58 | 59 | Assert::IsNotNull(equipedItem); 60 | } 61 | 62 | TEST_METHOD(TestHealUsingPotion) 63 | { 64 | std::string pName = "madrat"; 65 | int pHealth = 240; 66 | int pDmg = 64; 67 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 0, 0, pDmg * 2, 1, pDmg); 68 | 69 | HealPotion* healPotion = new HealPotion(); 70 | 71 | healPotion->use(player); 72 | 73 | Assert::AreEqual(pHealth + healPotion->get_heal_val(), player->get_health()); 74 | } 75 | }; 76 | } -------------------------------------------------------------------------------- /gameUnitTests/testPlayerClass.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CppUnitTest.h" 3 | 4 | #include "game.h" 5 | #include "player.h" 6 | #include "enemy.h" 7 | 8 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 9 | 10 | namespace unittests 11 | { 12 | TEST_CLASS(TestPlayerClass) 13 | { 14 | public: 15 | 16 | TEST_METHOD(TestIncreaseGold) 17 | { 18 | std::string pName = "madrat"; 19 | Player *player = new Player(pName); 20 | 21 | int gold = 20; 22 | player->increase_gold(gold); 23 | 24 | Assert::AreEqual(player->get_gold(), gold); 25 | } 26 | 27 | TEST_METHOD(TestDecreaseGold) 28 | { 29 | std::string pName = "madrat"; 30 | Player *player = new Player(pName); 31 | 32 | int inc_gold = 40; 33 | player->increase_gold(inc_gold); 34 | 35 | int dec_gold = 30; 36 | player->decrease_gold(dec_gold); 37 | 38 | Assert::AreEqual(player->get_gold(), inc_gold - dec_gold); 39 | } 40 | 41 | TEST_METHOD(TestIncreaseExp) 42 | { 43 | std::string pName = "madrat"; 44 | Player *player = new Player(pName); 45 | 46 | int exp = 20; 47 | player->increase_exp(exp); 48 | 49 | Assert::AreEqual(player->get_exp(), exp); 50 | } 51 | 52 | TEST_METHOD(TestDecreaseExp) 53 | { 54 | std::string pName = "madrat"; 55 | Player *player = new Player(pName); 56 | 57 | int inc_exp = 40; 58 | player->increase_exp(inc_exp); 59 | 60 | int dec_exp = 30; 61 | player->decrease_exp(dec_exp); 62 | 63 | Assert::AreEqual(player->get_exp(), inc_exp - dec_exp); 64 | } 65 | 66 | TEST_METHOD(TestIncreaseTotalKilled) 67 | { 68 | std::string pName = "madrat"; 69 | Player *player = new Player(pName); 70 | 71 | player->increase_total_killed(); 72 | player->increase_total_killed(); 73 | player->increase_total_killed(); 74 | 75 | Assert::AreEqual(player->get_total_killed(), 3); 76 | } 77 | 78 | TEST_METHOD(TestDecreaseHealth) 79 | { 80 | std::string pName = "madrat"; 81 | int pHealth = 240; 82 | int pDmg = 64; 83 | Player *player = new Player(pName, pHealth, pDmg); 84 | 85 | int damage = 20; 86 | player->decrease_health(damage); 87 | 88 | Assert::AreEqual(player->get_health(), pHealth - damage); 89 | } 90 | 91 | TEST_METHOD(TestIncreaseHealth) 92 | { 93 | std::string pName = "madrat"; 94 | int pHealth = 240; 95 | int pDmg = 64; 96 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 0, 0, pDmg * 2, 1, pDmg); 97 | 98 | int inc_hp = 20; 99 | player->increase_health(inc_hp); 100 | 101 | Assert::AreEqual(player->get_health(), pHealth + inc_hp); 102 | } 103 | 104 | TEST_METHOD(TestAttackEnemy) 105 | { 106 | std::string pName = "madrat"; 107 | int pHealth = 240; 108 | int pDmg = 64; 109 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 0, 0, pDmg * 2, 1, pDmg); 110 | 111 | std::string eName = "goblin"; 112 | int eHealth = 135; 113 | int eDmg = 51; 114 | Enemy *enemy = new Enemy(eName, eHealth, eDmg); 115 | 116 | player->attack(enemy); 117 | 118 | Assert::AreEqual(enemy->get_health(), eHealth - pDmg); 119 | } 120 | 121 | TEST_METHOD(TestAttackEnemySpecDamageVal) 122 | { 123 | std::string pName = "madrat"; 124 | int pHealth = 240; 125 | int pDmg = 64; 126 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 0, 0, pDmg * 2, 1, pDmg); 127 | 128 | std::string eName = "goblin"; 129 | int eHealth = 135; 130 | int eDmg = 51; 131 | Enemy *enemy = new Enemy(eName, eHealth, eDmg); 132 | 133 | int playerAttackPower = 21; 134 | player->attack(enemy, playerAttackPower); 135 | 136 | Assert::AreEqual(enemy->get_health(), eHealth - playerAttackPower); 137 | } 138 | 139 | TEST_METHOD(TestHealYourself) 140 | { 141 | std::string pName = "madrat"; 142 | int pHealth = 240; 143 | int pDmg = 64; 144 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 12, 20, pDmg * 2, 1, pDmg); 145 | 146 | player->heal(player); 147 | 148 | Assert::AreEqual(player->get_health(), pHealth + player->get_heal()); 149 | } 150 | 151 | TEST_METHOD(TestHealYourselfSpecVal) 152 | { 153 | std::string pName = "madrat"; 154 | int pHealth = 240; 155 | int pDmg = 64; 156 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 0, 0, pDmg * 2, 1, pDmg); 157 | 158 | int healAmount = 19; 159 | player->heal(player, healAmount); 160 | 161 | Assert::AreEqual(player->get_health(), healAmount + pHealth); 162 | } 163 | 164 | TEST_METHOD(TestLiftItem) 165 | { 166 | std::string pName = "madrat"; 167 | int pHealth = 240; 168 | int pDmg = 64; 169 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 0, 0, pDmg * 2, 1, pDmg); 170 | 171 | Sword *sword = new Sword(); 172 | player->lift_item(sword); 173 | 174 | Assert::AreEqual(player->get_inventory()->size(), size_t(1)); 175 | } 176 | 177 | TEST_METHOD(TestEquipItem) 178 | { 179 | std::string pName = "madrat"; 180 | int pHealth = 240; 181 | int pDmg = 64; 182 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 0, 0, pDmg * 2, 1, pDmg); 183 | 184 | Sword *sword = new Sword(); 185 | player->equip(sword); 186 | 187 | Assert::IsNotNull(player->get_active_item()); 188 | } 189 | 190 | TEST_METHOD(TestDie) 191 | { 192 | std::string pName = "madrat"; 193 | int pHealth = 240; 194 | int pDmg = 64; 195 | Player *player = new Player(pName, pHealth, pHealth * 2, 0, 0, 0, pDmg * 2, 1, pDmg); 196 | 197 | player->die(); 198 | 199 | Assert::AreEqual(player->get_isAlive(), false); 200 | } 201 | }; 202 | } -------------------------------------------------------------------------------- /injector/getpid.cpp: -------------------------------------------------------------------------------- 1 | #include "getpid.h" 2 | 3 | std::vector get_pid_by_name(std::wstring targetName) 4 | { 5 | std::vector pids; 6 | 7 | DWORD targetPid; 8 | HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // all processes 9 | 10 | PROCESSENTRY32W entry; 11 | entry.dwSize = sizeof entry; 12 | 13 | if (!Process32FirstW(snap, &entry)) //start with the first in snapshot 14 | { 15 | return std::vector(); 16 | } 17 | 18 | do { 19 | if (std::wstring(entry.szExeFile) == targetName) //name matches; add to list 20 | { 21 | pids.push_back(entry.th32ProcessID); 22 | // HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); 23 | // CloseHandle(hProcess); 24 | } 25 | } while (Process32NextW(snap, &entry)); //keep going until end of snapshot 26 | 27 | return pids; 28 | } -------------------------------------------------------------------------------- /injector/getpid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "includes.h" 3 | 4 | std::vector get_pid_by_name(std::wstring targetName); -------------------------------------------------------------------------------- /injector/includes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "Shlwapi.h" 9 | -------------------------------------------------------------------------------- /injector/injector.iobj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4drat/cheat_examples/90577d9c53ce67bedfc3ae6689700514637eacb9/injector/injector.iobj -------------------------------------------------------------------------------- /injector/injector.ipdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4drat/cheat_examples/90577d9c53ce67bedfc3ae6689700514637eacb9/injector/injector.ipdb -------------------------------------------------------------------------------- /injector/injector.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {A42982F7-8F96-4674-AF04-F80A6497A0C5} 24 | injector 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | out\ 74 | 75 | 76 | /out 77 | 78 | 79 | /out 80 | 81 | 82 | /out 83 | 84 | 85 | 86 | Level3 87 | Disabled 88 | true 89 | true 90 | %(AdditionalIncludeDirectories) 91 | 92 | 93 | shlwapi.lib;%(AdditionalDependencies) 94 | 95 | 96 | out\$(TargetName)$(TargetExt) 97 | 98 | 99 | 100 | 101 | Level3 102 | Disabled 103 | true 104 | true 105 | 106 | 107 | out\$(TargetName)$(TargetExt) 108 | 109 | 110 | 111 | 112 | Level3 113 | MaxSpeed 114 | true 115 | true 116 | true 117 | true 118 | 119 | 120 | true 121 | true 122 | out\$(TargetName)$(TargetExt) 123 | 124 | 125 | 126 | 127 | Level3 128 | MaxSpeed 129 | true 130 | true 131 | true 132 | true 133 | %(AdditionalIncludeDirectories) 134 | 135 | 136 | true 137 | true 138 | shlwapi.lib;%(AdditionalDependencies) 139 | 140 | 141 | out\$(TargetName)$(TargetExt) 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /injector/injector.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | Header Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /injector/main.cpp: -------------------------------------------------------------------------------- 1 | #include "getpid.h" 2 | 3 | int main() 4 | { 5 | std::wstring psName; 6 | std::string libraryPath; 7 | TCHAR fullLibPath[MAX_PATH]; 8 | size_t fullLibPathSize = 0; 9 | std::vector pids; 10 | 11 | for (;;) 12 | { 13 | std::wcout << "[+] Enter path to DLL you want to inject: "; 14 | std::cin >> libraryPath; 15 | 16 | // Check if DLL library exists 17 | if (PathFileExistsA(libraryPath.c_str())) 18 | { 19 | // Get Full path 20 | fullLibPathSize = GetFullPathNameA(libraryPath.c_str(), MAX_PATH, fullLibPath, NULL); 21 | break; 22 | } 23 | else { 24 | std::wcout << "[-] Check library path!\n"; 25 | } 26 | } 27 | 28 | for (;;) 29 | { 30 | std::wcout << "[+] Enter process name: "; 31 | std::wcin >> psName; 32 | std::wcout << "[+] Searching pids of process with name: " << psName << std::endl; 33 | 34 | // Get Process PID by its name 35 | pids = get_pid_by_name(psName); 36 | 37 | if (pids.size() == 0) { 38 | std::wcout << "[-] Cannot find any process!\n"; 39 | } 40 | else { 41 | std::wcout << "[+] 1. PID: " << pids[0] << std::endl; 42 | break; 43 | } 44 | } 45 | 46 | // Open handle to process with full access 47 | HANDLE psHandle = OpenProcess(PROCESS_ALL_ACCESS, false, pids[0]); 48 | 49 | if (psHandle != nullptr) 50 | { 51 | // Allocate memory for dll path in remote process 52 | LPVOID psMemoryLibPath = VirtualAllocEx(psHandle, NULL, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 53 | 54 | if (psMemoryLibPath != nullptr) 55 | { 56 | // Write DLL path to newly allocated memory 57 | WriteProcessMemory(psHandle, psMemoryLibPath, fullLibPath, MAX_PATH, &fullLibPathSize); 58 | 59 | // Get address of LoadLibraryA 60 | FARPROC loadLibraryA = GetProcAddress(GetModuleHandle("kernel32"), "LoadLibraryA"); 61 | 62 | // Call LoadLibraryA in remote process to load DLL 63 | CreateRemoteThread(psHandle, NULL, NULL, (LPTHREAD_START_ROUTINE)loadLibraryA, psMemoryLibPath, NULL, NULL); 64 | 65 | printf("[+] Remote thread in process with pid: %d created!\n", pids[0]); 66 | } 67 | else { 68 | std::wcout << "[-] Something went wrong.\n"; 69 | return 2; 70 | } 71 | 72 | } 73 | else { 74 | std::wcout << "[-] Cannot open process.\n"; 75 | std::wcout << "[-] Check your privilegies.\n"; 76 | getchar(); 77 | return 2; 78 | } 79 | } -------------------------------------------------------------------------------- /internalCheat/InternalCheat.cpp: -------------------------------------------------------------------------------- 1 | #include "InternalCheat.h" 2 | 3 | constexpr long long int hpOffset = -0x4; 4 | 5 | InternalCheat* InternalCheat::cHinstance = nullptr; 6 | 7 | InternalCheat::InternalCheat() 8 | { 9 | is_initialized = false; 10 | } 11 | 12 | InternalCheat* InternalCheat::get_instance() 13 | { 14 | if (cHinstance == nullptr) 15 | { 16 | cHinstance = new InternalCheat(); 17 | } 18 | return cHinstance; 19 | } 20 | 21 | int InternalCheat::init() 22 | { 23 | if (is_initialized) 24 | return NULL; 25 | 26 | mem_region = reinterpret_cast(PatternScan::find_pattern_internal("50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FD FD FD FD")); 27 | if (mem_region != NULL) 28 | printf("[+][CH] Found player signature! ptr: 0x%p\n", mem_region); 29 | else 30 | { 31 | printf("[-][CH] Cannot find player signature! Aborting.\n> "); 32 | return NULL; 33 | } 34 | 35 | is_initialized = true; 36 | 37 | return 1; 38 | } 39 | 40 | int InternalCheat::exec() 41 | { 42 | std::wcout << "[+][CH] Cheat is now running\n> "; 43 | const auto player_health = reinterpret_cast(reinterpret_cast(mem_region) + hpOffset); 44 | while (true) 45 | { 46 | *player_health = INT_MAX; 47 | 48 | // Sleep For 5 seconds 49 | std::this_thread::sleep_for(std::chrono::milliseconds(5000)); 50 | } 51 | } -------------------------------------------------------------------------------- /internalCheat/InternalCheat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "PatternScan.h" 9 | 10 | class InternalCheat 11 | { 12 | public: 13 | static InternalCheat* get_instance(); 14 | int init(); 15 | int exec(); 16 | 17 | // RPM/WPM wrappers 18 | // Read a value from memory and put it in Value 19 | // Returns true on success, false on failure 20 | template 21 | static bool ReadMem(DWORDLONG dwAddress, T& Value) 22 | { 23 | return ReadMemory(reinterpret_cast(dwAddress), Value, sizeof(T), NULL) == TRUE; 24 | } 25 | 26 | // Write a Value in memory 27 | // Returns true on success, false on failure 28 | template 29 | inline bool WriteMem(DWORDLONG dwAddress, const T& Value) 30 | { 31 | return WriteProcessMemory(GetCurrentProcess(), reinterpret_cast(dwAddress), reinterpret_cast(Value), sizeof(T), NULL) == TRUE; 32 | } 33 | 34 | private: 35 | static InternalCheat* cHinstance; 36 | bool is_initialized = false; 37 | void* mem_region = nullptr; 38 | 39 | InternalCheat(); 40 | }; -------------------------------------------------------------------------------- /internalCheat/PatternScan.cpp: -------------------------------------------------------------------------------- 1 | #include "PatternScan.h" 2 | 3 | void PatternScan::get_module_info(std::string moduleName, MODULEINFO& modInfo) 4 | { 5 | HMODULE hModule = nullptr; 6 | 7 | GetModuleHandleEx(0, moduleName.c_str(), &hModule); 8 | GetModuleInformation(GetCurrentProcess(), hModule, &modInfo, sizeof(MODULEINFO)); 9 | } 10 | 11 | DWORDLONG PatternScan::find_pattern_static(MODULEINFO module, const char* pattern, const char* mask) 12 | { 13 | DWORDLONG base = (DWORDLONG)module.lpBaseOfDll; 14 | DWORDLONG size = module.SizeOfImage; 15 | DWORD patternLength = DWORD(strlen(mask)); 16 | 17 | for (DWORDLONG i = 0; i < size - patternLength; i++) 18 | { 19 | bool found = true; 20 | for (DWORDLONG j = 0; j < patternLength; j++) 21 | { 22 | found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j); 23 | } 24 | if (found) 25 | { 26 | return base + i; 27 | } 28 | } 29 | return NULL; 30 | } 31 | 32 | DWORDLONG PatternScan::find_pattern_internal(std::string pattern) 33 | { 34 | auto mbi = MEMORY_BASIC_INFORMATION(); 35 | DWORDLONG curr_addr = 0; 36 | 37 | while (true) 38 | { 39 | if (VirtualQuery(reinterpret_cast(curr_addr), &mbi, sizeof mbi) == 0) 40 | { 41 | break; 42 | } 43 | 44 | if ((mbi.State == MEM_COMMIT || mbi.State == MEM_RESERVE) && 45 | (mbi.Protect == PAGE_READONLY || 46 | mbi.Protect == PAGE_READWRITE || 47 | mbi.Protect == PAGE_EXECUTE_READ || 48 | mbi.Protect == PAGE_EXECUTE_READWRITE)) 49 | { 50 | auto result = PatternScan::find_pattern_internal_in_range(pattern, reinterpret_cast(mbi.BaseAddress), reinterpret_cast(mbi.BaseAddress) + mbi.RegionSize); 51 | 52 | if (result != NULL) 53 | { 54 | return result; 55 | } 56 | } 57 | 58 | curr_addr += mbi.RegionSize; 59 | } 60 | 61 | return NULL; 62 | } 63 | 64 | DWORDLONG PatternScan::find_pattern_internal_in_range(std::string pattern, const DWORDLONG range_start, const DWORDLONG range_end) 65 | { 66 | auto strstream = std::istringstream(pattern); 67 | 68 | std::vector values; 69 | std::string s; 70 | 71 | while (getline(strstream, s, ' ')) 72 | { 73 | if (s.find("??") != std::string::npos) 74 | { 75 | values.push_back(-1); 76 | continue; 77 | } 78 | 79 | auto parsed = std::stoi(s, 0, 16); 80 | values.push_back(parsed); 81 | } 82 | 83 | for (auto p_cur = range_start; p_cur < range_end; p_cur++) 84 | { 85 | auto localAddr = p_cur; 86 | auto found = true; 87 | 88 | for (auto value : values) 89 | { 90 | if (value == -1) 91 | { 92 | localAddr += 1; 93 | continue; 94 | } 95 | 96 | auto neededValue = static_cast(value); 97 | auto pCurrentValue = reinterpret_cast(localAddr); 98 | auto currentValue = *pCurrentValue; 99 | 100 | if (neededValue != currentValue) 101 | { 102 | found = false; 103 | break; 104 | } 105 | 106 | localAddr += 1; 107 | } 108 | 109 | if (found) 110 | { 111 | return p_cur; 112 | } 113 | } 114 | return NULL; 115 | } -------------------------------------------------------------------------------- /internalCheat/PatternScan.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Shlwapi.h" 6 | #include 7 | #include 8 | #include 9 | 10 | class PatternScan 11 | { 12 | private: 13 | 14 | public: 15 | // Searh in static memory (not stack or heap) 16 | // moduleName - name of module (game.exe), modInfo - structure which will be filled up 17 | static void get_module_info(std::string moduleName, MODULEINFO& modInfo); 18 | 19 | // Searh in static memory (not stack or heap) 20 | // Find pattern in specific module 21 | // void* ammoDecAddress = FindPattern(L"bf4.exe", L"\x89\x93\x00\x00\x00\x00\x00\x9d", L"xx????xx"); 22 | static DWORDLONG find_pattern_static(MODULEINFO module, const char* pattern, const char* mask); 23 | 24 | // Find pattern in process memory 25 | // player_base_ = reinterpret_cast(find_pattern("ED 03 ?? ?? 01 00 00 00")); 26 | // ?? - unknown bytes 27 | static DWORDLONG find_pattern_internal(std::string pattern); 28 | 29 | // Find pattern in specific memory range 30 | static DWORDLONG find_pattern_internal_in_range(std::string pattern, const DWORDLONG range_start, const DWORDLONG range_end); 31 | }; -------------------------------------------------------------------------------- /internalCheat/ch_includes.h: -------------------------------------------------------------------------------- 1 | #pragma once -------------------------------------------------------------------------------- /internalCheat/getpid.cpp: -------------------------------------------------------------------------------- 1 | #include "getpid.h" 2 | 3 | std::vector get_pid_by_name(std::wstring targetName) 4 | { 5 | std::vector pids; 6 | 7 | DWORD targetPid; 8 | HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // all processes 9 | 10 | PROCESSENTRY32W entry; 11 | entry.dwSize = sizeof entry; 12 | 13 | if (!Process32FirstW(snap, &entry)) //start with the first in snapshot 14 | { 15 | return std::vector(); 16 | } 17 | 18 | do { 19 | if (std::wstring(entry.szExeFile) == targetName) //name matches; add to list 20 | { 21 | pids.push_back(entry.th32ProcessID); 22 | // HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); 23 | // CloseHandle(hProcess); 24 | } 25 | } while (Process32NextW(snap, &entry)); //keep going until end of snapshot 26 | 27 | return pids; 28 | } -------------------------------------------------------------------------------- /internalCheat/getpid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "includes.h" 3 | 4 | std::vector get_pid_by_name(std::wstring targetName); -------------------------------------------------------------------------------- /internalCheat/includes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "Shlwapi.h" -------------------------------------------------------------------------------- /internalCheat/internalCheat.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {095A401C-88F4-4918-B1B7-D95FFDC4404D} 24 | internalCheat 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | MultiByte 40 | 41 | 42 | DynamicLibrary 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | DynamicLibrary 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | .dll 74 | out\ 75 | 76 | 77 | .dll 78 | out\ 79 | 80 | 81 | 82 | Level3 83 | Disabled 84 | true 85 | true 86 | C:\Users\User\Desktop\simple_cheats\game\source\repos\game\externalCheat 87 | 88 | 89 | out\$(TargetName)$(TargetExt) 90 | 91 | 92 | 93 | 94 | Level3 95 | Disabled 96 | true 97 | true 98 | 99 | 100 | 101 | 102 | Level3 103 | MaxSpeed 104 | true 105 | true 106 | true 107 | true 108 | 109 | 110 | true 111 | true 112 | 113 | 114 | 115 | 116 | Level3 117 | MaxSpeed 118 | true 119 | true 120 | true 121 | true 122 | 123 | 124 | 125 | 126 | true 127 | true 128 | out\$(TargetName)$(TargetExt) 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /internalCheat/internalCheat.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /internalCheat/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "InternalCheat.h" 5 | 6 | BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved) 7 | { 8 | if (fdwReason == DLL_PROCESS_ATTACH) 9 | { 10 | std::wcout << "\n[+][CH] Cheat loaded successfully!\n"; 11 | InternalCheat *cheat = InternalCheat::get_instance(); 12 | if (cheat->init()) 13 | { 14 | std::wcout << "[+][CH] Cheat initialized successfully!\n"; 15 | // MessageBox(NULL, "Cheat Successfully Initialized!", "Cheat", MB_OK); 16 | cheat->exec(); 17 | } 18 | else { 19 | std::wcout << "[-] Player Signature Cannot be found!" << "\n> "; 20 | // MessageBox(NULL, "Player Signature Cannot be found!", "Cheat", MB_OK); 21 | } 22 | } 23 | return 0; 24 | } --------------------------------------------------------------------------------