HelpHELP - C++ Cpu Usage %100 Problem.

Posts 14 of 4 · Page 1 of 1
HELP - C++ Cpu Usage %100 Problem.
I use win32 & DLL.

I use CreteThread.

Some example.


Example Full Code:
Code:
#include <windows.h>  
#include <tlhelp32.h>  
#include <shlwapi.h>  
#include <tchar.h>
#include <conio.h>  
#include <stdio.h>
#include <Windows.h> 

#include <stdio.h> 
#include <cstdlib> 
#include <iostream> 
#include <time.h>
#include <tlhelp32.h> 
#include <string> 
#include <string.h> 
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <cstdlib>
#include <string>
#include <Shellapi.h>
#include <windows.h>
#include <string.h>
#include <string>
#include <time.h>
#include <iostream>
#include <iostream>
using namespace std;
#include <fstream>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <windows.h>
#include <tlhelp32.h>
#include <sys/stat.h>
#pragma comment (lib, "user32.lib")

int val = 0;
void mythread(){
while(1){
val += 1;
If(val = 10000){
	exit(0);
}
Sleep(1000);
}
}
void mythread2(){
while(1){
int val;
ReadProcessMemory(GetCurrentProcess(),(LPVOID)0x513612,&val,sizeof(val),NULL);
If(val > 500){
	exit(0);
}
Sleep(50);
}
}
  


BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
			CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)mythread2, NULL, NULL, NULL);
			CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)mythread, NULL, NULL, NULL);
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}
But my cpu usage is %100

Who is help me?
First you need to create handles to obtain the return value from CreateThread and make sure you close those handles on DLL_PROCESS_DETACH.

Next you need to make sure you enclose your brackets for DLL_PROCESS_ATTACH:

Code:
case DLL_PROCESS_ATTACH:
{
..
}
Also, why are you using ReadProcessMemory? Since your already in the games memory space you can simply read/write as if it was your own memory. Like this for example:

Code:
*(int*) 0x513612 = val;
Hmmm
From the look of thing you must have copy this from another site with out understanding what the code those.
You really don't need all those header file to create a simple Dll mod for a game.
Code:
#include <windows.h>
#include <iostream>
using namespace std;
Now what are you trying to do change the value of a game.
Code:
*(DWORD_PTR*)(0x513612) = //What every value you want it to be
I fail to see how this code even work or you must have lie. You got the same variable declare.
Code:
int val = 0;
int val;
Below, I upload a great C++ book that should you should start reading. This going to give you a great understanding of C++.
C++ For DUMMIES_mpgh.net.rar2.5 MB · 3 downloads Scanning…
It could also be you're using ReadProcessMemory() 21x / second.

I think that uses more CPU than simply memory reading (As stated above, *(int*)Offset)
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?