Post

RE Course - 6.09 - Implementing the Player Class

This part is optional but it gives our efforts purpose. And it’s fun.

Now that we’ve reversed the Player class, let’s write our own program that makes a Player class and uses the functions related to the class.

The player’s name doesn’t have to be a std::string, it can probably be a const* char as well.

Copy/Paste Code

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
#include <iostream>
#include <Windows.h>

class Player {
public:
	int score;
	float health;
	std::string name;
};

//void __cdecl InitializePlayer(class Player * __ptr64)
typedef void(WINAPI* IInitializePlayer)(Player*); // ?InitializePlayer@@YAXPEAVPlayer@@@Z
//void PrintPlayerStats(Player);
typedef void(WINAPI* IPrintPlayerStats)(Player); // PrintPlayerStats

int main()
{
	Player player;
	HMODULE dll = LoadLibraryA("DLL.DLL"); //Load our DLL.
	if (dll != NULL)
	{
		//Initialize Player
		IInitializePlayer InitializePlayer = (IInitializePlayer)GetProcAddress(dll, "?InitializePlayer@@YAXPEAVPlayer@@@Z");
		if (InitializePlayer != NULL) {
			InitializePlayer(&player);
		}
		else { printf("Can't load the function."); }

		//PrintPlayerStats
		IPrintPlayerStats PrintPlayerStats = (IPrintPlayerStats)GetProcAddress(dll, "PrintPlayerStats");
		if (InitializePlayer != NULL) {
			PrintPlayerStats(player);
		}
		else { printf("Can't load the function."); }
		
	}
}

-> Next Lesson
<- Previous Lesson

Chapter Home

This post is licensed under CC BY 4.0 by the author.