Advertisement
kubpica

launcher code

Mar 6th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <tlhelp32.h>
  7. #include <fstream>
  8. //#include <sstream>
  9. using namespace std;
  10.  
  11. /*DWORD getPid(string procName){
  12.        HANDLE hsnap;
  13.        PROCESSENTRY32 pt;
  14.        PROCESSENTRY32 pt_;
  15.        bool bzyt = false;
  16.        hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  17.        pt.dwSize = sizeof(PROCESSENTRY32);
  18.        int counter = 0;
  19.        do{
  20.            //std::wstring ws(pt.szExeFile);
  21.            //std::string s((const char*)&ws[0], sizeof(wchar_t)/sizeof(char)*ws.size());
  22.            //if(s.compare(procName)){  //if(pt.szExeFile == procName){
  23.             if(pt.szExeFile == procName){
  24.                 DWORD pid = pt.th32ProcessID;
  25.                 CloseHandle(hsnap);
  26.                 return pid;
  27.             }
  28.             if(bzyt && pt.th32ProcessID == pt_.th32ProcessID){
  29.                 if(counter<3){
  30.                     hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  31.                     pt.dwSize = sizeof(PROCESSENTRY32);
  32.                     cout << "!" << endl;
  33.                 }else if (counter>100){
  34.                     return 0;
  35.                 }
  36.                 counter++;
  37.             }
  38.             pt_ = pt;
  39.             bzyt = true;
  40.             //if(pt.th32ProcessID == pt_.th32ProcessID) cout << "Tak" << endl;
  41.         } while(Process32Next(hsnap, &pt));
  42.         CloseHandle(hsnap);
  43.         return 0;   //if nothing is found return 0;
  44.  
  45.         }*/
  46.  
  47. DWORD getPid(string name)
  48. {
  49.     DWORD pid = 0;
  50.  
  51.     // Create toolhelp snapshot.
  52.     HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  53.     PROCESSENTRY32 process;
  54.     ZeroMemory(&process, sizeof(process));
  55.     process.dwSize = sizeof(process);
  56.  
  57.     // Walkthrough all processes.
  58.     if (Process32First(snapshot, &process))
  59.     {
  60.         do
  61.         {
  62.             // Compare process.szExeFile based on format of name, i.e., trim file path
  63.             // trim .exe if necessary, etc.
  64.             if (string(process.szExeFile) == string(name))
  65.             {
  66.                pid = process.th32ProcessID;
  67.                break;
  68.             }
  69.         } while (Process32Next(snapshot, &process));
  70.     }
  71.  
  72.     CloseHandle(snapshot);
  73.  
  74.     return pid;
  75. }
  76.  
  77. BOOL InjectLibrary(HANDLE hProcess, char *fnDll) {
  78.  
  79.     BOOL success = FALSE;
  80.     HANDLE hThread = NULL;
  81.     char *fnRemote = NULL;
  82.     FARPROC procLoadLibraryA = NULL;
  83.  
  84.     size_t lenFilename = strlen(fnDll) + 1;
  85.  
  86.     /* Allocate space in the remote process */
  87.     fnRemote = (char *)VirtualAllocEx(hProcess, NULL, lenFilename, MEM_COMMIT, PAGE_READWRITE);
  88.  
  89.     if (fnRemote) {
  90.  
  91.         /* Write the filename to the remote process. */
  92.         if (WriteProcessMemory(hProcess, fnRemote, fnDll, lenFilename, NULL)) {
  93.  
  94.             /* Get the address of the LoadLibraryA function */
  95.             procLoadLibraryA = GetProcAddress(GetModuleHandle("Kernel32"), "LoadLibraryA");
  96.             hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)procLoadLibraryA, fnRemote, 0, NULL);
  97.  
  98.             if (hThread) {
  99.                 WaitForSingleObject(hThread, INFINITE);
  100.                 success = TRUE;
  101.             }
  102.         }
  103.  
  104.         VirtualFreeEx(hProcess, fnRemote, 0, MEM_RELEASE);
  105.     }
  106.  
  107.     return success;
  108. }
  109.  
  110. HANDLE proc;
  111.  
  112. int main()
  113. {
  114.     string ip;
  115.     string exe;
  116.     string dll = "kubs_mod_client.dll";
  117.     exe = "Turok2MP.exe";
  118.     ip = "-maxframerate 64 -quickmouse -exclusivemouse";
  119.     float camerafov1 = 70;
  120.     float weaponfov1 = 50;
  121.     float maxpan = 3000;
  122.     bool showGUI = true;
  123.     ifstream config;
  124.     config.open("launcherConfig.txt", std::fstream::in);
  125.     if( !config.good() ){
  126.         cout << "Config not found. Creating new one." << endl;
  127.         config.close();
  128.         ofstream newconfig;
  129.         newconfig.open("launcherConfig.txt", std::fstream::trunc | std::fstream::out);
  130.         newconfig << "ExeName=Turok2MP.exe" << endl;
  131.         newconfig << "StartupParameters=-maxframerate 64 -quickmouse -exclusivemouse" << endl;
  132.         newconfig << "CameraFOV=70" << endl;
  133.         newconfig << "WeaponFOV=50" << endl;
  134.         //newconfig << "ShowGUI=1" << endl;
  135.         newconfig << "//MaxPan is about \"3D sound\" (600 is default, 10000 is best for competitive gameplay but may be annoying) - you can test it in game with 'set maxpan' command." << endl;
  136.         newconfig << "MaxPan=3000" << endl;
  137.         newconfig.close();
  138.     }else{
  139.         string slowo;
  140.         string wiersz;
  141.         //std::stringstream ss;
  142.         while(getline( config, wiersz )){
  143.             //ss.str( std::string() ); ss.clear();
  144.             //ss << wiersz;
  145.             //ss >> slowo; //while(ss >> slowo){
  146.             slowo = wiersz.substr(0,wiersz.find("=")+1);
  147.             //cout << slowo << endl;
  148.                 if(slowo == "StartupParameters="){
  149.                     ip = wiersz.substr(wiersz.find("=")+1);
  150.                 }else if(slowo == "ExeName="){
  151.                     exe = wiersz.substr(wiersz.find("=")+1);
  152.                 }else if(slowo == "DllName="){
  153.                     dll = wiersz.substr(wiersz.find("=")+1);
  154.                     //cout << "dll: " << dll << endl;
  155.                 }
  156.                 slowo.clear();
  157.                 wiersz.clear();
  158.         }
  159.     }
  160.     config.close();
  161.  
  162.     cout << "T2 Multiplayer mod launcher by kubpica 1.1" << endl;
  163.     cout << "kubpicapf@gmail.com" << endl;
  164.     cout << "It works correctly only with 1.03 exe (Basber's mod exe v1.27)" << endl;
  165.  
  166.     DWORD pid = getPid(exe.c_str());
  167.     if (pid!=0){
  168.         cout << "Game is already running." << endl;
  169.         cin.get();
  170.         return 1;
  171.     }
  172.  
  173.     int h = (int) ShellExecute( NULL, NULL, exe.c_str(), ip.c_str(), NULL, SW_SHOW );
  174.     if ( !(h>32) ){
  175.         cout << "Could not open game." << endl;
  176.         cout << "Make sure you have " << exe << " and this launcher in your turok2 main folder" << endl;
  177.         cin.get();
  178.         return 1;
  179.     }
  180.  
  181.     Sleep(1000);
  182.  
  183.     pid = getPid(exe.c_str());
  184.     if (pid==0){
  185.         cout << "Game not found in processes. Make sure you have " << exe << " and this launcher in your turok2 main folder" << endl;
  186.         cin.get();
  187.         return 1;
  188.     }
  189.  
  190.     proc = OpenProcess(PROCESS_ALL_ACCESS,false,pid);
  191.     if (proc==NULL){
  192.         cout << "Could not open game process." << endl;
  193.         cin.get();
  194.         return 1;
  195.     }
  196.  
  197.     cout << "Game found." << endl;
  198.     char * writable = new char[dll.size() + 1];
  199.     strcpy(writable, dll.c_str());
  200.     if(InjectLibrary(proc, writable)){
  201.         //cout << "Mod (dll) injected successfully" << endl;
  202.         cout << "Injecting " << dll << endl;
  203.         //system("pause");
  204.     }
  205.     else{
  206.         cout << "Failed to inject dll (mod)." << endl;
  207.         cin.get();
  208.     }
  209.     delete[] writable;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement