-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
110 lines (78 loc) · 2.64 KB
/
main.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "StdAfx.h"
/*
Steam API Interface
Developer: sk0r / Czybik
Version: v0.1 (Steam-API v015) 13th August, 2014
Contact: [email protected]
See readme.txt for more details
File: main.cpp: Main functions
*/
//======================================================================
VOID OnShutdown(VOID);
//======================================================================
//======================================================================
BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType)
{
//Console control handler
if (dwCtrlType == CTRL_CLOSE_EVENT) { //Close console event
OnShutdown();
return TRUE;
}
return FALSE;
}
//======================================================================
//======================================================================
VOID OnShutdown(VOID)
{
//Do stuff on shutdown
ConsolePrint("Shutting down...");
g_oNameChanger.SetStatus(FALSE);
g_oSteamAPI.Shutdown();
SetConsoleCtrlHandler(&ConsoleControlHandler, FALSE);
}
//======================================================================
//======================================================================
int main(int argc, char* argv[])
{
//Entry point implementation
//Set Pseudo-random seed
srand(time(NULL));
//Set console title
SetConsoleTitleA(PROGRAM_NAME);
//Print about message
ConsolePrint(PROGRAM_INFO "\n");
//Format application path
if (!SetAppPath(g_szAppPath)) {
ConsolePrint("[Formatting App Path] Failed: %d", GetLastError());
return EXIT_FAILURE;
}
//Register console control handler
if (!SetConsoleCtrlHandler(&ConsoleControlHandler, TRUE)) {
ConsolePrint("[Console Control Handler] Failed to register: %d", GetLastError());
return EXIT_FAILURE;
}
//Initialize Steam API
InitResult irResult = g_oSteamAPI.Initialize(g_szAppPath);
ConsolePrint("[SteamAPI] Initialized: %d (%s) -> %d\n", irResult, g_oSteamAPI.InitResultToString(irResult), GetLastError());
if (irResult != IR_SUCCESS)
return EXIT_FAILURE;
//Initialize name changer
ISteamFriends* pSteamFriends = g_oSteamAPI.SteamFriendsInterface();
if (!pSteamFriends)
ConsolePrint("[SteamAPI] SteamFriendsInterface failed to initialize!");
g_oNameChanger.SetInterface(pSteamFriends);
g_oNameChanger.SetStatus(TRUE);
//Main loop
ConsolePrint("Waiting for games, press [ESC] to exit.");
g_oNameChanger.ReadNames();
while(g_oSteamAPI.IsSteamRunning()) {
if ((GetForegroundWindow() == FindWindowA(NULL, PROGRAM_NAME)) && (GetAsyncKeyState(VK_ESCAPE))) {
break;
}
g_oNameChanger.Think();
}
//When done
OnShutdown();
return EXIT_SUCCESS;
}
//======================================================================