Skip to content

Commit

Permalink
Merge pull request #12 from Archie-osu/beta
Browse files Browse the repository at this point in the history
Merge 0.0.6 from Beta to Stable
  • Loading branch information
Archie-osu authored Sep 23, 2021
2 parents b9922e8 + 46edd2a commit 8e16ebe
Show file tree
Hide file tree
Showing 18 changed files with 505 additions and 69 deletions.
2 changes: 1 addition & 1 deletion ExamplePlugin/Src/Hello World/SDK/FwdDecls/FwdDecls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ typedef bool (*FNCodeExecute)(YYObjectBase* Self, YYObjectBase* Other, CCode* co
// Macros

#define WIN32_LEAN_AND_MEAN 1
#define YYSDK_VERSION "0.0.5c" // YYToolkit version - don't change this!
#define YYSDK_VERSION "0.0.6" // YYToolkit version - don't change this!
#define YYTK_MAGIC 'TFSI'

// Macros, but complicated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct APIVars_t
YYObjectBase* g_pGlobal = nullptr; // A pointer to the global game instance
FNCodeExecute Code_Execute = nullptr; // A pointer to the Code_Execute function
FNCodeFunctionGetTheFunction Code_Function_GET_the_function = nullptr; // A pointer to a function with a long-ass name
CDynamicArray<CScript*>* ppScripts = nullptr; // A pointer to all game script objects (array from 1 to size - 1)
void* Window_Handle = nullptr; // A pointer to the window handle (HWND)
void* Window_Device = nullptr; // A pointer to either a D3D11Device*, or an DIRECT3DDEVICE9
std::map<unsigned long, YYTKPlugin> Plugins; // A map of all plugins loaded (Key = Base address, Value = YYTKPlugin object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct CScript
int (**_vptr$CScript)(void);
CStream* s_text;
CCode* s_code;
void* s_pFunc;
YYGMLFuncs* s_pFunc;
CInstance* s_pStaticObject;

union
Expand All @@ -25,4 +25,6 @@ struct CScript

const char* s_name;
int s_offset;

// const char* GetScriptName();
};
126 changes: 110 additions & 16 deletions ExamplePlugin/Src/Hello World/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,84 @@
#include "SDK/SDK.hpp" // Include the SDK.
#include <Windows.h> // Include Windows's mess.

static constexpr unsigned char g_PatchBytes[]
static constexpr unsigned char g_scrDebugPatch[]
{
0x04, 0x00, 0x00, 0xB6,
0x01, 0x00, 0x0F, 0x84,
0x06, 0x00, 0x00, 0xB6,
0x01, 0x00, 0x00, 0xB6,
0x01, 0x00, 0x0F, 0x84,
0x00, 0x00, 0x52, 0x07,
0x00, 0x00, 0x05, 0x9C,
0x00, 0x00, 0x02, 0x9D,
0x00, 0x00, 0x02, 0xC0,
0xB7, 0x8A, 0x01, 0x00,
0x00, 0x00, 0x52, 0x07,
0xFF, 0xFF, 0x0F, 0x84,
0x00, 0x00, 0x52, 0x07,
0x00, 0x00, 0x05, 0x9C,
0x00, 0x00, 0x02, 0xC0,
0xB7, 0x8A, 0x01, 0x00,
0x02, 0x00, 0x02, 0xD9,
0xA0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x86,
0xFF, 0xFF, 0x0F, 0x84,
0x00, 0x00, 0x55, 0x45,
0xFE, 0xB0, 0x01, 0x80,
0x00, 0x00, 0x05, 0x9E
};

static constexpr unsigned char g_scrDogcheckPatch[]
{
0x1D, 0x00, 0x00, 0xB6,
0xFB, 0xFF, 0x05, 0xC2,
0xE8, 0xAB, 0x01, 0xA0,
0x03, 0x00, 0x0F, 0x84,
0x00, 0x03, 0x52, 0x15,
0x04, 0x00, 0x00, 0xB8,
0x00, 0x00, 0x0F, 0x84,
0x00, 0x00, 0x52, 0x07,
0x00, 0x00, 0x05, 0x9C,
0xFB, 0xFF, 0x05, 0xC2,
0xE8, 0xAB, 0x01, 0xA0,
0xE8, 0x00, 0x0F, 0x84,
0x00, 0x05, 0x52, 0x15,
0x06, 0x00, 0x00, 0xB7,
0xFB, 0xFF, 0x05, 0xC2,
0xE8, 0xAB, 0x01, 0xA0,
0x0A, 0x00, 0x0F, 0x84,
0x00, 0x02, 0x52, 0x15,
0x02, 0x00, 0x00, 0xB6,
0x00, 0x00, 0x0F, 0xC0,
0x05, 0x00, 0x00, 0xB8,
0x00, 0x00, 0x0F, 0x84,
0x00, 0x00, 0x52, 0x07,
0x00, 0x00, 0x05, 0x9C,
0x04, 0x00, 0x00, 0xB6,
0x00, 0x00, 0x0F, 0x84,
0x00, 0x00, 0x52, 0x07,
0x00, 0x00, 0x05, 0x9C,
0x00, 0x00, 0x02, 0x9D,
0x00, 0x00, 0x02, 0xC0,
0xB9, 0x8A, 0x01, 0x00,
0x00, 0x00, 0x52, 0x07,
0xFF, 0xFF, 0x0F, 0x84,
0x00, 0x00, 0x52, 0x07,
0x02, 0x00, 0x02, 0xD9,
0xA0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x52, 0x07,
0x02, 0x00, 0x02, 0xD9,
0xA0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x86,
0xFF, 0xFF, 0x0F, 0x84,
0x00, 0x00, 0x55, 0x45,
0xFE, 0xB0, 0x01, 0x80,
0x00, 0x00, 0x55, 0x45,
0xFF, 0xB0, 0x01, 0x80,
0x00, 0x00, 0x05, 0x9E
};

static YYTKStatus(*GetScriptByName)(const char* Name, CScript*& outScript);

static VMBuffer oscr_Debug = { 0 };
static VMBuffer oscr_Dogcheck = { 0 };

// Handles all events that happen inside the game.
// Previously, callbacks served this purpose, however in 0.0.3, an object-oriented design was implemented.
// If you want to modify a code entry, you're gonna need this function.
YYTKStatus PluginEventHandler(YYTKPlugin* pPlugin, YYTKEventBase* pEvent)
{
// Check if the event currently raised is a code event
// Check if the event currently raised is a rendering event (EndScene for DX9, Present for DX11)
if (pEvent->GetEventType() == EventType::EVT_DOCALLSCRIPT)
{
// Convert the base event to the actual event object based on it's type.
Expand All @@ -48,12 +100,52 @@ YYTKStatus PluginEventHandler(YYTKPlugin* pPlugin, YYTKEventBase* pEvent)
// Check if the code entry name is called scr_debug
if (strcmp(pScript->s_code->i_pName, "gml_Script_scr_debug") == 0)
{
// Modify the buffer
pScript->s_code->i_pVM->m_pBuffer = (char*)(g_PatchBytes);
pScript->s_code->i_pVM->m_size = 64;
// Save the original buffer
oscr_Debug = *pScript->s_code->i_pVM;

// Modify the game buffer
pScript->s_code->i_pVM->m_pBuffer = (char*)(g_scrDebugPatch);
pScript->s_code->i_pVM->m_size = 72;

// Call the function
pCodeEvent->Call(pScript, argc, pStackPointer, pVM, pLocals, pArguments);

// Restore the original buffer
pScript->s_code->i_pVM->m_pBuffer = oscr_Debug.m_pBuffer;
pScript->s_code->i_pVM->m_size = oscr_Debug.m_size;
}

else if (strcmp(pScript->s_code->i_pName, "gml_Script_scr_dogcheck") == 0)
{
// Save the original buffer
oscr_Dogcheck = *pScript->s_code->i_pVM;

// Modify the game buffer
pScript->s_code->i_pVM->m_pBuffer = (char*)(g_scrDogcheckPatch);
pScript->s_code->i_pVM->m_size = 164;

// Call the function
pCodeEvent->Call(pScript, argc, pStackPointer, pVM, pLocals, pArguments);

// Restore the original buffer
pScript->s_code->i_pVM->m_pBuffer = oscr_Dogcheck.m_pBuffer;
pScript->s_code->i_pVM->m_size = oscr_Dogcheck.m_size;
}
}
}

// Go To Room port
if (GetAsyncKeyState(VK_F3) & 1)
{
auto CallBuiltin = pPlugin->GetCoreExport<YYTKStatus(*)(const char* Name, int argc, YYRValue& _result, YYRValue* Args)>("Global_CallBuiltin");

YYRValue Result, Result2;
YYRValue Arguments[2] = { "Go to room (ported by Archie from UMT to YYToolkit)\nEnter the room ID you wish to teleport to.", 11.0 };

CallBuiltin("get_integer", 2, Result, Arguments);

CallBuiltin("room_goto", 1, Result2, &Result);
}
}
return YYTK_OK;
}
Expand All @@ -66,7 +158,9 @@ DllExport YYTKStatus PluginEntry(YYTKPlugin* pPlugin)
// This is not required if you don't need to modify code entries / draw with D3D / anything else that requires precise timing.
pPlugin->PluginHandler = PluginEventHandler;

printf("[DR Chapter 2 Debug Enabler] I'm about to do what's called a pro-gamer move.\n");
printf("[Chapter2++] Loaded!\n");
printf("[Chapter2++] - Press F3 to teleport to rooms (UndertaleModTool GoToRoom.csx script)\n");
printf("[Chapter2++] - Dogcheck disabled, debug mode enabled.\n");

// Tell the core everything went fine.
return YYTK_OK;
Expand Down
44 changes: 22 additions & 22 deletions Launcher/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8e16ebe

Please sign in to comment.