Skip to content

Commit

Permalink
Merge pull request #47 from YoYoGames/daniel.dev
Browse files Browse the repository at this point in the history
Fix buffer overflow, add some logging
  • Loading branch information
DiasFranciscoA authored Feb 4, 2022
2 parents 2035777 + b8287d2 commit 259eaf3
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion DLL/GDKExtension/GDKX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ YYRunnerInterface gs_runnerInterface;
YYRunnerInterface* g_pYYRunnerInterface;

char* g_XboxSCID = NULL;
bool g_gdk_initialised = false;

void InitIAPFunctionsM();
void UpdateIAPFunctionsM();
Expand All @@ -34,7 +35,7 @@ void YYExtensionInitialise(const struct YYRunnerInterface* _pFunctions, size_t _
} // end if

// copy out all the functions
memcpy(&gs_runnerInterface, _pFunctions, _functions_size);
memcpy(&gs_runnerInterface, _pFunctions, sizeof(YYRunnerInterface));
g_pYYRunnerInterface = &gs_runnerInterface;
}

Expand Down Expand Up @@ -123,6 +124,14 @@ void gdk_init(RValue& Result, CInstance* selfinst, CInstance* otherinst, int arg
return;
}

if (g_gdk_initialised)
{
DebugConsoleOutput("ERROR: gdk_init() called but GDK is already initialised!\n");
return;
}

DebugConsoleOutput("gdk_init() called - initialising the GDK extension\n");

std::vector<std::string> event_manifest_names = _find_packaged_files("Events-*.man");

if (event_manifest_names.size() == 0)
Expand Down Expand Up @@ -154,11 +163,19 @@ void gdk_init(RValue& Result, CInstance* selfinst, CInstance* otherinst, int arg

XUM::Init();
InitIAPFunctionsM();

g_gdk_initialised = true;
}

YYEXPORT
void gdk_update(RValue& Result, CInstance* selfinst, CInstance* otherinst, int argc, RValue* arg)
{
if (!g_gdk_initialised)
{
DebugConsoleOutput("ERROR: gdk_update() called but GDK isn't initialised! (call gdk_init() first)\n");
return;
}

XUM::Update();
UpdateIAPFunctionsM();

Expand All @@ -169,6 +186,14 @@ void gdk_update(RValue& Result, CInstance* selfinst, CInstance* otherinst, int a
YYEXPORT
void gdk_quit(RValue& Result, CInstance* selfinst, CInstance* otherinst, int argc, RValue* arg)
{
if (!g_gdk_initialised)
{
DebugConsoleOutput("ERROR: gdk_quit() called but GDK isn't initialised!\n");
return;
}

DebugConsoleOutput("gdk_quit() called - shutting down the GDK extension\n");

QuitIAPFunctionsM();
XUM::Quit();

Expand All @@ -190,6 +215,8 @@ void gdk_quit(RValue& Result, CInstance* selfinst, CInstance* otherinst, int arg

YYFree(g_XboxSCID);
g_XboxSCID = NULL;

g_gdk_initialised = false;
}

YYEXPORT
Expand Down

0 comments on commit 259eaf3

Please sign in to comment.