Float Arrays + Hexadecimal

I was looking to move a camera around in a game by just changing the X,Y,Z coordinates in physical memory of the game. I have the addresses and I can successfully change my camera position by manually going in and modifying them. However, I'm trying to create a program to make the arrows on the keyboard do this for me.

I have the concept down, but I'm at a stand still! Coordinates are floats or doubles. In this case, X-4 bytes(float), Y-4 bytes(float), Z-4 bytes(float). So we have a total of 12 consecutive bytes. 3 float numbers. Now, I am using ReadProcessMemory to get the current float values. Then using GetAsyncVirtualKey(VK_LEFT) I would DECREASE my X float value, VK_RIGHT would INCREASE my X float value, etc. Then use WriteProcessMemory to write those new values to the same camera addresses.

I know this works because I've WriteProcessMemory set values and it moves the camera on my hotkey.

I guess my problem is, converting the 4 byte hex to a float number in decimal then increasing or decreasing by lets say 0.001 each time we press a hotkey. Then converting it back to hex and writing it. Maybe this is too complicated?

Any advice? Here's portion of my code:
1
2
3
4
5
6
		BYTE xRock0[4];
		BYTE xRock1[4];
		BYTE yRock0[4];
		BYTE yRock1[4];
	//???	float zRock[4];
		BYTE subRock=0.001f;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
I have function on 100ms timer.

void timer() {

	if(GetAsyncKeyState(VK_LEFT)&1) {

 // THERE ARE 2 ADDYS FOR CAM, NOT SURE WHICH CHANGES SO I DO BOTH
	

		ReadProcessMemory(hand, (void*)0x4BB2E1AC, &xRock0,4,&bytes);
		ReadProcessMemory(hand, (void*)0x4BF3F75C, &xRock1,4,&bytes);

		xRock0[4]=xRock0[4]-subRock;
		xRock1[4]=xRock1[4]-subRock;

		WriteProcessMemory(hand,(void*)0x4BB2E1AC,&xRock0,4,&bytes);
		WriteProcessMemory(hand, (void*)0x4BF3F75C, &xRock1,4,&bytes);


	}
		if(GetAsyncKeyState(VK_RIGHT)&1) {

 
	

		ReadProcessMemory(hand, (void*)0x4BB2E1AC, &xRock0,4,&bytes);
		ReadProcessMemory(hand, (void*)0x4BF3F75C, &xRock1,4,&bytes);

		xRock0[4]=xRock0[4]+subRock;
		xRock1[4]=xRock1[4]+subRock;

		WriteProcessMemory(hand,(void*)0x4BB2E1AC,&xRock0,4,&bytes);
		WriteProcessMemory(hand, (void*)0x4BF3F75C, &xRock1,4,&bytes);


	}	if(GetAsyncKeyState(VK_UP)&1) {

 
	

		ReadProcessMemory(hand, (void*)0x4BB2E1B0, &yRock0,4,&bytes);
		ReadProcessMemory(hand, (void*)0x4BF3F760, &yRock1,4,&bytes);

		yRock0[4]=yRock0[4]+subRock;
		yRock1[4]=yRock1[4]+subRock;

		WriteProcessMemory(hand,(void*)0x4BB2E1B0,&yRock0,4,&bytes);
		WriteProcessMemory(hand, (void*)0x4BF3F760, &yRock1,4,&bytes);


	}	if(GetAsyncKeyState(VK_DOWN)&1) {

 
	

		ReadProcessMemory(hand, (void*)0x4BB2E1B0, &yRock0,4,&bytes);
		ReadProcessMemory(hand, (void*)0x4BF3F760, &yRock1,4,&bytes);

		yRock0[4]=yRock0[4]-subRock;
		yRock1[4]=yRock1[4]-subRock;

		WriteProcessMemory(hand,(void*)0x4BB2E1B0,&yRock0,4,&bytes);
		WriteProcessMemory(hand, (void*)0x4BF3F760, &yRock1,4,&bytes);


	}
	


}
Okay, so I fixed my problem. No need for converting hex to float, it is all done for you when you readprocessmemory...meaning I read it as a float instead of just 4 bytes. I also declared everything at the top instead of in my timer function. I also figured out which address was the real one so i only have to wpm and rpm once. Check it out!!!!

Declares
1
2
3
4
float xRock0=0.0f;
float yRock0=0.0f;
float zRock0=0.0f;
float subtract=0.5f;


Enable/Disable buttons
1
2
3
4
5
6
7
				case IDC_ENABLE:
					enable=TRUE;
					return TRUE;

				case IDC_DISABLE:
				 enable=FALSE;
					return TRUE;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
void timer() {

	if(enable){

		if(GetAsyncKeyState(VK_LEFT)&1) {


		ReadProcessMemory(hand, (void*)0x4BB2E1AC, &xRock0,4,&bytes);

		xRock0=xRock0-subtract;

		WriteProcessMemory(hand,(void*)0x4BB2E1AC,&xRock0,4,&bytes);


	}
		if(GetAsyncKeyState(VK_RIGHT)&1) {

 
	

		ReadProcessMemory(hand, (void*)0x4BB2E1AC, &xRock0,4,&bytes);

		xRock0=xRock0+subtract;

		WriteProcessMemory(hand,(void*)0x4BB2E1AC,&xRock0,4,&bytes);


	}	if(GetAsyncKeyState(VK_UP)&1) {

 
	

		ReadProcessMemory(hand, (void*)0x4BB2E1B0, &yRock0,4,&bytes);

		yRock0=yRock0+subtract;

		WriteProcessMemory(hand,(void*)0x4BB2E1B0,&yRock0,4,&bytes);


	}	if(GetAsyncKeyState(VK_DOWN)&1) {

 
	

		ReadProcessMemory(hand, (void*)0x4BB2E1B0, &yRock0,4,&bytes);

		yRock0=yRock0-subtract;

		WriteProcessMemory(hand,(void*)0x4BB2E1B0,&yRock0,4,&bytes);

	}
	

if(GetAsyncKeyState(VK_PRIOR)&1) {

 
	

		ReadProcessMemory(hand, (void*)0x4BB2E1B4, &zRock0,4,&bytes);

		zRock0=zRock0+subtract;

		WriteProcessMemory(hand,(void*)0x4BB2E1B4,&zRock0,4,&bytes);


	}	if(GetAsyncKeyState(VK_NEXT)&1) {

 
	

		ReadProcessMemory(hand, (void*)0x4BB2E1B4, &zRock0,4,&bytes);

		zRock0=zRock0-subtract;

		WriteProcessMemory(hand,(void*)0x4BB2E1B4,&zRock0,4,&bytes);

	}

	}

}
Topic archived. No new replies allowed.