Skip to content

Commit

Permalink
Try to unfuck YYTK Borderless
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-k0 committed Feb 24, 2024
1 parent fab1687 commit 8a1e7d0
Show file tree
Hide file tree
Showing 39 changed files with 4,380 additions and 0 deletions.
10 changes: 10 additions & 0 deletions LoopHero_ModExample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Native_LoopHeroBorderlessWi
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Cursorlock", "Cursorlock\Cursorlock.vcxproj", "{94296525-402C-4658-B230-F21D9330C99C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "YYTK_LoopHeroBorderlessWindow", "YYTK_LoopHeroBorderlessWindow\YYTK_LoopHeroBorderlessWindow.vcxproj", "{EE7B7D83-9196-40A5-AE42-E85F7934C910}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -41,6 +43,14 @@ Global
{94296525-402C-4658-B230-F21D9330C99C}.Release|x64.Build.0 = Release|x64
{94296525-402C-4658-B230-F21D9330C99C}.Release|x86.ActiveCfg = Release|Win32
{94296525-402C-4658-B230-F21D9330C99C}.Release|x86.Build.0 = Release|Win32
{EE7B7D83-9196-40A5-AE42-E85F7934C910}.Debug|x64.ActiveCfg = Debug|x64
{EE7B7D83-9196-40A5-AE42-E85F7934C910}.Debug|x64.Build.0 = Debug|x64
{EE7B7D83-9196-40A5-AE42-E85F7934C910}.Debug|x86.ActiveCfg = Debug|Win32
{EE7B7D83-9196-40A5-AE42-E85F7934C910}.Debug|x86.Build.0 = Debug|Win32
{EE7B7D83-9196-40A5-AE42-E85F7934C910}.Release|x64.ActiveCfg = Release|x64
{EE7B7D83-9196-40A5-AE42-E85F7934C910}.Release|x64.Build.0 = Release|x64
{EE7B7D83-9196-40A5-AE42-E85F7934C910}.Release|x86.ActiveCfg = Release|Win32
{EE7B7D83-9196-40A5-AE42-E85F7934C910}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
119 changes: 119 additions & 0 deletions YYTK_LoopHeroBorderlessWindow/Assets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#pragma once
#include "Filesystem.h"
#include <SDK.hpp>
#include <string>
// Asset Loading
namespace Assets {
// sprite_add(filepath, imgnum, removebg, smooth, xorig, yorig)
// Filepath is relative to the EXE directory
double AddSprite(std::string filepath, int imgnum, bool removebg, bool smooth, int xorig, int yorig)
{
// Get the current directory
std::string currentDir = Filesys::GetCurrentDir();
// Add the filepath to the current directory
std::string fullpath = currentDir + "\\" + filepath;

//PrintMessage(Color::CLR_AQUA, fullpath.c_str());

// Check if the file exists
if (!Filesys::FileExists(fullpath))
{
PrintMessage(Color::CLR_RED, (("Asset could not be resolved: ") + fullpath).c_str());
return -1.0;
}

// Load the sprite
YYRValue spriteref;
CallBuiltin(spriteref, "sprite_add", nullptr, nullptr, { fullpath.c_str(), (double)imgnum, removebg, smooth, (double)xorig, (double)yorig });
double res = static_cast<double>(spriteref);
if (res != -1.0)
{
PrintMessage(Color::CLR_GREEN, (("Loaded asset: ") + fullpath).c_str());
}
return res; // return the sprite id
}

// Gets the number of subimages
double GetSpriteImgnum(double spriteID)
{
YYRValue spritenum;
CallBuiltin(spritenum, "sprite_get_number", nullptr, nullptr, { spriteID });
return static_cast<double>(spritenum);
}

double GetSpriteWidth(double spriteID)
{
YYRValue yyrval;
CallBuiltin(yyrval, "sprite_get_width", nullptr, nullptr, { spriteID });
return static_cast<double>(yyrval);
}

double GetSpriteHeight(double spriteID)
{
YYRValue yyrval;
CallBuiltin(yyrval, "sprite_get_height", nullptr, nullptr, { spriteID });
return static_cast<double>(yyrval);
}

// Gets w and h and writes it back to width and height params
void GetSpriteDimensions(double spriteID, double& width, double& height)
{
width = GetSpriteWidth(spriteID);
height = GetSpriteHeight(spriteID);
}

double GetSpriteOffsetX(double spriteID)
{
YYRValue yyrval;
CallBuiltin(yyrval, "sprite_get_xoffset", nullptr, nullptr, { spriteID });
return static_cast<double>(yyrval);
}

double GetSpriteOffsetY(double spriteID)
{
YYRValue yyrval;
CallBuiltin(yyrval, "sprite_get_yoffset", nullptr, nullptr, { spriteID });
return static_cast<double>(yyrval);
}

void GetSpriteOffsets(double spriteID, double& xoff, double& yoff)
{
xoff = GetSpriteOffsetX(spriteID);
yoff = GetSpriteOffsetY(spriteID);
}

void SetSpriteOffset(double spriteID, double xoff, double yoff)
{
YYRValue yyrval;
CallBuiltin(yyrval, "sprite_set_offset", nullptr, nullptr, { spriteID, xoff, yoff });
}

//Replaces the spriteID with a sprite from fpath permanently
void SpriteReplace(double spriteID, std::string fpath, double imgnum, bool removebg, bool smooth, double xorig, double yorig)
{
// Get the current directory
std::string currentDir = Filesys::GetCurrentDir();
// Add the filepath to the current directory
std::string fullpath = currentDir + "\\" + fpath;

//PrintMessage(Color::CLR_AQUA, fullpath.c_str());

// Check if the file exists
if (!Filesys::FileExists(fullpath))
{
PrintMessage(Color::CLR_RED, (("Asset could not be resolved: ") + fullpath).c_str());
return;
}

YYRValue yyrval;
CallBuiltin(yyrval, "sprite_replace", nullptr, nullptr, {spriteID, fpath, imgnum, removebg, smooth, xorig, yorig});
PrintMessage(Color::CLR_GREEN, (("Replaced asset: ") + fullpath).c_str());
}

// only works on runtime-loaded assets
void SpriteDelete(double spriteID)
{
YYRValue yyrval;
CallBuiltin(yyrval, "sprite_delete", nullptr, nullptr, { spriteID });
}
}
32 changes: 32 additions & 0 deletions YYTK_LoopHeroBorderlessWindow/Filesystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <string>
#include <direct.h>
// File functions
namespace Filesys {


std::string GetCurrentDir() // Returns EXE directory
{
char cCurrentPath[FILENAME_MAX]; // get working directory into buffer
if (!_getcwd(cCurrentPath, sizeof(cCurrentPath)))
exit(-1);
cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; // not really required

char* s = cCurrentPath; // save path from buffer into currentpath chararr
std::string str(s);
//free(s);
return str;
}

inline bool FileExists(const std::string& name) {
if (FILE* file = fopen(name.c_str(), "r")) {
fclose(file);
return true;
}
else {
return false;
}
}

}
79 changes: 79 additions & 0 deletions YYTK_LoopHeroBorderlessWindow/LHCore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once
#include <Windows.h>
#include "MyPlugin.h"

namespace LHCore {

// Ready-check function
typedef bool (*CoreReady)();
CoreReady pCoreReady = nullptr;
bool isCoreReady = false;

// Saying hello to the core function
typedef bool (*RegisterModule)(std::string, YYTKPlugin*);
RegisterModule pRegisterModule = nullptr;

// unregistering from the core function
typedef bool (*UnregisterModule)(std::string);
UnregisterModule pUnregisterModule = nullptr;

typedef bool (*CoreFoundCallback_t)();

typedef struct ResolveCoreParams_t {
YYTKPlugin* plugin;
CoreFoundCallback_t callback;
} ResolveCoreParams_t;

DWORD WINAPI ResolveCore(LPVOID lpParam)
{
ResolveCoreParams_t* params = static_cast<ResolveCoreParams_t*>(lpParam);
YYTKPlugin* plugin = params->plugin;
CoreFoundCallback_t callback = params->callback;
#ifdef DEBUG
Misc::Print("Importing Core function");
#endif
void* rawCoreReady;
void* rawRegisterModule;
void* rawUnregisterModule;
while (true)
{
Sleep(10);
// Loading ready function
if (PmGetExported("CoreReady", rawCoreReady) == YYTK_OK)
{
pCoreReady = reinterpret_cast<CoreReady>(rawCoreReady);
if (pCoreReady() == true)
{
#ifdef DEBUG
Misc::Print("Core is present", CLR_GREEN);
#endif
isCoreReady = true;

// Loading register function
if (PmGetExported("RegisterModule", rawRegisterModule) == YYTK_OK)
{
pRegisterModule = reinterpret_cast<RegisterModule>(rawRegisterModule);
pRegisterModule(gPluginName, gThisPlugin);
#ifdef DEBUG
Misc::Print("Registered to Core", CLR_GREEN);
#endif
if (callback != NULL)
{
callback();
}
}

// Loading unregister function
if (PmGetExported("UnregisterModule", rawUnregisterModule) == YYTK_OK)
{
pUnregisterModule = reinterpret_cast<UnregisterModule>(rawUnregisterModule);
}

return TRUE;
}
}
Misc::Print("Waiting for Core. Did you install LoopHeroCallbackCore.dll?", CLR_RED);
}
}

}
Loading

0 comments on commit 8a1e7d0

Please sign in to comment.