-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
4,380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.