Skip to content

Commit

Permalink
Silence warnings, fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukem9 committed Dec 8, 2021
1 parent c550621 commit 85a0f2a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
68 changes: 45 additions & 23 deletions FFXW32/FFXW32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h>
#include <thread>
#include <atomic>
#include <array>
#include "Loader.h"
#include "CreationKit32.h"
#include "LipSynchAnim.h"
Expand Down Expand Up @@ -51,7 +52,7 @@ void IPCExitNotificationThread()
CloseHandle(parentProcess);
}

bool StartCreationKitIPC(uint32_t ProcessID)
int StartCreationKitIPC(uint32_t ProcessID)
{
// Disable any kind of buffering when using printf or related functions
setvbuf(stdout, NULL, _IONBF, 0);
Expand All @@ -66,7 +67,7 @@ bool StartCreationKitIPC(uint32_t ProcessID)
if (!mapping)
{
printf("Could not create file mapping object (%d).\n", GetLastError());
return false;
return 1;
}

auto tunnel = reinterpret_cast<CreationKit::LipGenTunnel *>(MapViewOfFile(mapping, FILE_MAP_ALL_ACCESS, 0, 0, 0x40000));
Expand All @@ -76,7 +77,7 @@ bool StartCreationKitIPC(uint32_t ProcessID)
printf("Could not map view of file (%d).\n", GetLastError());

CloseHandle(mapping);
return false;
return 1;
}

sprintf_s(temp, "CkNotifyEvent%d", ProcessID);
Expand All @@ -91,7 +92,7 @@ bool StartCreationKitIPC(uint32_t ProcessID)

UnmapViewOfFile(tunnel);
CloseHandle(mapping);
return false;
return 1;
}

// Thread to check for parent process exit
Expand Down Expand Up @@ -157,28 +158,11 @@ bool StartCreationKitIPC(uint32_t ProcessID)
CloseHandle(mapping);

g_CreationKitPID = 0;
return true;
return 0;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
int StartCommandLine()
{
// Create the IPC tunnel if this was launched from CreationKit.exe
if (const char *pid = getenv("Ckpid"); pid && strlen(pid) > 0)
{
if (!StartCreationKitIPC(atoi(pid)))
return 1;

return 0;
}

// Use command line processing instead
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}

auto initVersionFromArgv = []()
{
if (!_stricmp(__argv[1], "Skyrim"))
Expand Down Expand Up @@ -232,4 +216,42 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
}

return 0;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Create the IPC tunnel if this was launched from CreationKit.exe
if (const char *pid = getenv("Ckpid"); pid && strlen(pid) > 0)
{
int result = StartCreationKitIPC(atoi(pid));
return result;
}

// Use command line processing instead
std::array<FILE *, 3> handles {};
bool attached = AttachConsole(ATTACH_PARENT_PROCESS);

if (attached)
{
handles[0] = freopen("CONIN$", "r", stdin);
handles[1] = freopen("CONOUT$", "w", stdout);
handles[2] = freopen("CONOUT$", "w", stderr);
}

int result = StartCommandLine();

if (attached)
{
for (auto handle : handles)
{
if (handle)
fclose(handle);
}

// Prevent the parent console from hanging after main returns
SendMessageA(GetConsoleWindow(), WM_CHAR, VK_RETURN, 0);
FreeConsole();
}

return result;
}
4 changes: 2 additions & 2 deletions FFXW32/FFXW32.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion FFXW32/Loader.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stb.h>
#include "stb.h"
#include "resource.h"
#include "CreationKit32.h"
#include "LipSynchAnim.h"
Expand Down
5 changes: 4 additions & 1 deletion dependencies/stb.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#define STB_DEFINE
#include "stb.h"
#pragma warning(push)
#pragma warning(disable: 4996)
#include "stb.h"
#pragma warning(pop)

0 comments on commit 85a0f2a

Please sign in to comment.