-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteam_API_Base.cpp
More file actions
195 lines (155 loc) · 5.6 KB
/
Steam_API_Base.cpp
File metadata and controls
195 lines (155 loc) · 5.6 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <Windows.h>
#include <Shlwapi.h>
#include <conio.h>
#include <new.h>
#define STEAM_API_EXPORTS
#include "Steam\steam_api.h"
#include "Steam\steamclientpublic.h"
#include "Steam\steam_gameserver.h"
#include "RegistryFunctions.h"
#include "Win32MiniDump.h"
#include "CallbackManager.h"
#include "Steam_API_Base.h"
#include "Functions\Client.h"
#include "Functions\InterfacePointers.h"
#include "Functions\InterfacePointersNew.h"
#include "Functions\GameServer.h"
#include "Functions\Minidump.h"
#include "Functions\Callbacks.h"
#include "Functions\Shutdown.h"
#include "Functions\CreateInterface.h"
#include "Functions\Flat.h"
void MyInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved)
{
MessageBoxW(nullptr, L"steam_api(64).dll Crashed (Invalid Parameter Handler)!", L"Invalid Parameter Handler", MB_ICONERROR);
ExitProcess(0);
}
int FailedMemoryAllocationHandler(size_t Size)
{
MessageBoxW(nullptr, L"steam_api(64).dll Crashed (Memory Allocation Handler)!", L"Failed To Allocate Memory", MB_ICONERROR);
ExitProcess(0);
}
void WriteColoredText(WORD Color, WORD OriginalColor, const char* Text)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), Color);
_cprintf_s("%s", Text);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), OriginalColor);
return;
}
void* InternalAPI_Init(HMODULE *hSteamclient, bool bInitLocal, const char *Interface)
{
SteamUtilsForCallbacks = nullptr;
SteamControllerForCallbacks = nullptr;
SteamInputForCallbacks = nullptr;
if (hSteamclient == nullptr)
return nullptr;
if (Interface == nullptr)
return nullptr;
*hSteamclient = nullptr;
char szSteamClientDll[MAX_PATH] = { 0 };
const char* InstallPath = SteamAPI_GetSteamInstallPath();
if (_stricmp(InstallPath, "SteamAPIBaseInvalidPath") == 0)
{
if (bInitLocal == false)
return nullptr;
}
else
{
#if defined(_M_IX86)
_snprintf_s(szSteamClientDll, MAX_PATH, _TRUNCATE, "%s\\steamclient.dll", InstallPath);
#endif
#if defined(_M_AMD64)
_snprintf_s(szSteamClientDll, MAX_PATH, _TRUNCATE, "%s\\steamclient64.dll", InstallPath);
#endif
}
if (SteamAPI_IsSteamRunning() == true)
{
*hSteamclient = LoadLibraryExA(szSteamClientDll, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
if (*hSteamclient == nullptr)
WriteColoredText(FOREGROUND_RED | FOREGROUND_INTENSITY, 7, "[Steam_API_Base] InternalAPI_Init --> Failed to load steamclient(64).dll!\r\n");
}
else
{
WriteColoredText(FOREGROUND_RED | FOREGROUND_INTENSITY, 7, "[Steam_API_Base] InternalAPI_Init --> SteamAPI_IsSteamRunning() Failed!\r\n");
}
if (*hSteamclient == nullptr)
{
if (bInitLocal == false)
{
WriteColoredText(FOREGROUND_RED | FOREGROUND_INTENSITY, 7, "[Steam_API_Base] InternalAPI_Init --> Unable to locate a running instance of Steam and bInitLocal is false!\r\n");
return nullptr;
}
#if defined(_M_IX86)
*hSteamclient = LoadLibraryW(L"steamclient.dll");
#endif
#if defined(_M_AMD64)
*hSteamclient = LoadLibraryW(L"steamclient64.dll");
#endif
if (*hSteamclient == nullptr)
{
WriteColoredText(FOREGROUND_RED | FOREGROUND_INTENSITY, 7, "[Steam_API_Base] InternalAPI_Init --> Unable to locate a running instance of Steam, or a local steamclient(64).dll!\r\n");
return nullptr;
}
}
oCreateInterface = (_CreateInterface)GetProcAddress(*hSteamclient, "CreateInterface");
if (oCreateInterface != nullptr)
{
SteamClientSafe = (ISteamClient *)oCreateInterface("SteamClient017", nullptr);
oReleaseThreadLocalMemory = (_ReleaseThreadLocalMemory)GetProcAddress(*hSteamclient, "Steam_ReleaseThreadLocalMemory");
ContextCounter++;
return oCreateInterface(Interface, nullptr);
}
else
{
WriteColoredText(FOREGROUND_RED | FOREGROUND_INTENSITY, 7, "[Steam_API_Base] InternalAPI_Init --> Unable to locate interface factory in steamclient(64).dll!\r\n");
FreeLibrary(*hSteamclient);
*hSteamclient = nullptr;
}
return nullptr;
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_invalid_parameter_handler OldHandler, NewHandler;
NewHandler = MyInvalidParameterHandler;
OldHandler = _set_invalid_parameter_handler(NewHandler);
_set_new_handler(FailedMemoryAllocationHandler);
AllocConsole();
char szFullDllPath[MAX_PATH] = { 0 };
const DWORD ModuleFileName = GetModuleFileNameA(hModule, szFullDllPath, sizeof(szFullDllPath));
if (ModuleFileName == 0)
{
MessageBoxW(nullptr, L"Unable to get dll name (1)!", L"Steam API Base", MB_ICONERROR);
ExitProcess(0);
}
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
MessageBoxW(nullptr, L"Unable to get dll name (2)!", L"Steam API Base", MB_ICONERROR);
ExitProcess(0);
}
_cprintf_s("[Steam_API_Base] Dll Path --> %s\r\n", szFullDllPath);
#if defined(_M_IX86)
if (StrStrIA(szFullDllPath, "steam_api.dll") == nullptr)
{
MessageBoxW(nullptr, L"Dll name must be steam_api.dll!", L"Steam API Base", MB_ICONERROR);
ExitProcess(0);
}
#endif
#if defined(_M_AMD64)
if (StrStrIA(szFullDllPath, "steam_api64.dll") == nullptr)
{
MessageBoxW(nullptr, L"Dll name must be steam_api64.dll!", L"Steam API Base", MB_ICONERROR);
ExitProcess(0);
}
#endif
_cprintf_s("[Steam_API_Base] PID --> %lu\r\n", GetCurrentProcessId());
_cprintf_s("[Steam_API_Base] ThreadID --> %lu\r\n", GetCurrentThreadId());
GetInterfacePointers.Clear();
GetGameServerInterfacePointers.Clear();
InitializeSRWLock(&ContextLock);
InitializeSRWLock(&CallbackLock);
Win32MiniDump = new CWin32MiniDump();
}
return 1;
}