#include "SDL_internal.h"
extern "C" {
#include "../../core/gdk/SDL_gdk.h"
#include "../../core/windows/SDL_windows.h"
#include "../../events/SDL_events_c.h"
#include "../SDL_main_callbacks.h"
}
#include <XGameRuntime.h>
#include <xsapi-c/services_c.h>
#include <shellapi.h>
#include <appnotify.h>
extern "C"
int SDL_RunApp(int argc, char **argv, SDL_main_func mainFunction, void *reserved)
{
(void)reserved;
void *heap_allocated = NULL;
const char *args_error = WIN_CheckDefaultArgcArgv(&argc, &argv, &heap_allocated);
if (args_error) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal Error", args_error, NULL);
return -1;
}
int result = -1;
XTaskQueueHandle taskQueue;
HRESULT hr = XGameRuntimeInitialize();
if (SUCCEEDED(hr) && SDL_GetGDKTaskQueue(&taskQueue)) {
Uint32 titleid = 0;
char scidBuffer[64];
XblInitArgs xblArgs;
XTaskQueueSetCurrentProcessTaskQueue(taskQueue);
hr = XGameGetXboxTitleId(&titleid);
if (SUCCEEDED(hr)) {
SDL_zero(xblArgs);
xblArgs.queue = taskQueue;
SDL_snprintf(scidBuffer, 64, "00000000-0000-0000-0000-0000%08X", titleid);
xblArgs.scid = scidBuffer;
hr = XblInitialize(&xblArgs);
} else {
SDL_SetError("[GDK] Unable to get titleid. Will not call XblInitialize. Check MicrosoftGame.config!");
}
if (!GDK_RegisterChangeNotifications()) {
return -1;
}
result = SDL_CallMainFunction(argc, argv, mainFunction);
GDK_UnregisterChangeNotifications();
XTaskQueueTerminate(taskQueue, false, nullptr, nullptr);
while (XTaskQueueDispatch(taskQueue, XTaskQueuePort::Completion, 0))
;
XTaskQueueCloseHandle(taskQueue);
XGameRuntimeUninitialize();
} else {
#ifdef SDL_PLATFORM_WINGDK
if (hr == E_GAMERUNTIME_DLL_NOT_FOUND) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal Error", "[GDK] Gaming Runtime library not found (xgameruntime.dll)", NULL);
} else {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal Error", "[GDK] Could not initialize - aborting", NULL);
}
#else
SDL_assert_always(0 && "[GDK] Could not initialize - aborting");
#endif
}
if (heap_allocated) {
HeapFree(GetProcessHeap(), 0, heap_allocated);
}
return result;
}