Skip to content

Commit 4be58c6

Browse files
committed
Clean this up
Change all the std::cout to wcout because I finally figured out how to attach the VS debugger to BL3 and it wants wcout
1 parent 48b6e47 commit 4be58c6

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

BL3DX11Injection/BL3DX11Injection.vcxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@
107107
<ConformanceMode>true</ConformanceMode>
108108
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
109109
<CallingConvention>Cdecl</CallingConvention>
110+
<Optimization>Disabled</Optimization>
111+
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
112+
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
113+
<StringPooling>true</StringPooling>
110114
</ClCompile>
111115
<Link>
112116
<SubSystem>Windows</SubSystem>
@@ -170,9 +174,6 @@
170174
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
171175
</ClCompile>
172176
</ItemGroup>
173-
<ItemGroup>
174-
<None Include="d3d11.def" />
175-
</ItemGroup>
176177
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
177178
<ImportGroup Label="ExtensionTargets" />
178179
</Project>

BL3DX11Injection/BL3DX11Injection.vcxproj.filters

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,4 @@
3333
<Filter>Source Files</Filter>
3434
</ClCompile>
3535
</ItemGroup>
36-
<ItemGroup>
37-
<None Include="d3d11.def">
38-
<Filter>Source Files</Filter>
39-
</None>
40-
</ItemGroup>
4136
</Project>

BL3DX11Injection/dllmain.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ void LoadPlugins() {
5858

5959
INIReader reader(iniPath.c_str());
6060
if (reader.ParseError() != 0) {
61-
std::cout << "Unable to load 'pluginLoader.ini'" << std::endl;
61+
std::wcout << "Unable to load 'pluginLoader.ini'" << std::endl;
6262
}
6363

6464
WIN32_FIND_DATA fd; // This'll store our data about the plugin we're currently loading in.
6565
const HANDLE dllFile = FindFirstFile((pluginsPath + L"*.dll").c_str(), &fd); // Get the first DLL file in our plugins dir
6666
int dllCount = 0;
6767

6868
if (dllFile == INVALID_HANDLE_VALUE) {
69-
std::cout << "No Plugins Found..." << std::endl;
69+
std::wcout << "No Plugins Found..." << std::endl;
7070
return; // Just return now, no need to bother to execute the rest of the code
7171
}
7272

@@ -77,7 +77,7 @@ void LoadPlugins() {
7777

7878
if (reader.Sections().count(s)) {
7979
float delayTime = reader.GetFloat(s, "delaySeconds", 0);
80-
std::cout << "Waiting " << delayTime << " seconds to load " << s << std::endl;
80+
std::wcout << "Waiting " << delayTime << " seconds to load " << WidenString(s) << std::endl;
8181
Sleep(delayTime * 1000);
8282
}
8383

@@ -98,6 +98,7 @@ void LoadPlugins() {
9898
}
9999

100100
int executionThread() {
101+
101102
AllocConsole(); // Allocate our console
102103

103104
std::string cmdArgs = GetCommandLineA(); // Get the command line args for our running process
@@ -121,8 +122,8 @@ int executionThread() {
121122
SetStdHandle(STD_ERROR_HANDLE, hStdout); // stderr is going back to STDOUT
122123
SetStdHandle(STD_INPUT_HANDLE, hStdin);
123124

124-
std::cout << "Console allocated...\n";
125-
std::cout << "==== Debug ====\n";
125+
std::wcout << "Console allocated...\n";
126+
std::wcout << "==== Debug ====\n";
126127
WCHAR pluginsFilePath[513] = { 0 };
127128
GetModuleFileNameW(gameModule, pluginsFilePath, 512);
128129

@@ -132,7 +133,7 @@ int executionThread() {
132133

133134
// This'll hapen if we are magically unable to create the plugins dir.
134135
if (!CreateDirectory(pPath.c_str(), nullptr) && GetLastError() != ERROR_ALREADY_EXISTS) {
135-
std::cout << "Unable to create plugins folder..." << std::endl;
136+
std::wcout << "Unable to create plugins folder..." << std::endl;
136137
return FALSE;
137138
}
138139
pluginsPath = pPath;
@@ -143,25 +144,6 @@ int executionThread() {
143144
return TRUE;
144145
}
145146

146-
std::wstring GetLastErrorAsString()
147-
{
148-
//Get the error message, if any.
149-
DWORD errorMessageID = ::GetLastError();
150-
if (errorMessageID == 0)
151-
return std::wstring(); //No error message has been recorded
152-
153-
LPWSTR messageBuffer = nullptr;
154-
size_t size = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
155-
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
156-
157-
std::wstring message(messageBuffer, size);
158-
159-
//Free the buffer.
160-
LocalFree(messageBuffer);
161-
162-
return message;
163-
}
164-
165147
#pragma region Linker Exports
166148

167149
#pragma comment(linker, "/export:D3D11CoreRegisterLayers=d3d11_org.D3D11CoreRegisterLayers")

BL3DX11Injection/pch.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,29 @@
33
#include "pch.h"
44

55
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
6+
7+
std::wstring GetLastErrorAsString()
8+
{
9+
//Get the error message, if any.
10+
DWORD errorMessageID = ::GetLastError();
11+
if (errorMessageID == 0)
12+
return std::wstring(); //No error message has been recorded
13+
14+
LPWSTR messageBuffer = nullptr;
15+
size_t size = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
16+
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
17+
18+
std::wstring message(messageBuffer, size);
19+
20+
//Free the buffer.
21+
LocalFree(messageBuffer);
22+
23+
return message;
24+
}
25+
26+
std::wstring WidenString(const std::string& s) {
27+
return std::wstring(s.begin(), s.end());
28+
}
29+
30+
31+

BL3DX11Injection/pch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515
#include <iostream>
1616
#include <stdio.h>
1717

18+
std::wstring GetLastErrorAsString();
19+
std::wstring WidenString(const std::string& s);
20+
1821
#endif //PCH_H

0 commit comments

Comments
 (0)