Implement support for DrawTexture hook

This commit is contained in:
Maschell 2019-03-01 19:18:03 +01:00
parent fb71817c33
commit 492571207d
4 changed files with 28 additions and 1 deletions

View File

@ -41,6 +41,29 @@ void gdImageToUnormR8G8B8A8(gdImagePtr gdImg, u32 *imgBuffer, u32 width, u32 hei
} }
} }
void TextureUtils::drawTexture(GX2Texture * texture, GX2Sampler* sampler, float x, float y, int32_t width, int32_t height, float alpha = 1.0f) {
float widthScaleFactor = 1.0f / (float)1280;
float heightScaleFactor = 1.0f / (float)720;
glm::vec3 positionOffsets = glm::vec3(0.0f);
positionOffsets[0] = (x-((1280)/2)+(width/2)) * widthScaleFactor * 2.0f;
positionOffsets[1] = -(y-((720)/2)+(height/2)) * heightScaleFactor * 2.0f;
glm::vec3 scale(width*widthScaleFactor,height*heightScaleFactor,1.0f);
Texture2DShader::instance()->setShaders();
Texture2DShader::instance()->setAttributeBuffer();
Texture2DShader::instance()->setAngle(0.0f);
Texture2DShader::instance()->setOffset(positionOffsets);
Texture2DShader::instance()->setScale(scale);
Texture2DShader::instance()->setColorIntensity(glm::vec4(alpha));
Texture2DShader::instance()->setBlurring(glm::vec3(0.0f));
Texture2DShader::instance()->setTextureAndSampler(texture, sampler);
Texture2DShader::instance()->draw();
}
bool TextureUtils::convertImageToTexture(const uint8_t *img, int32_t imgSize, void * _texture){ bool TextureUtils::convertImageToTexture(const uint8_t *img, int32_t imgSize, void * _texture){
if(!img || (imgSize < 8) || _texture == NULL){ if(!img || (imgSize < 8) || _texture == NULL){
return false; return false;

View File

@ -18,11 +18,12 @@
#define __TEXTURE_UTILS_UTILS_H_ #define __TEXTURE_UTILS_UTILS_H_
#include <stdint.h> #include <stdint.h>
#include <dynamic_libs/gx2_functions.h> #include <dynamic_libs/gx2_functions.h>
#include <video/shaders/Texture2DShader.h>
class TextureUtils { class TextureUtils {
public: public:
static bool convertImageToTexture(const uint8_t *img, int32_t imgSize, void * texture); static bool convertImageToTexture(const uint8_t *img, int32_t imgSize, void * texture);
static void drawTexture(GX2Texture * texture, GX2Sampler* sampler, float x, float y, int32_t width, int32_t height, float alpha);
private: private:
TextureUtils() {} TextureUtils() {}
~TextureUtils() {} ~TextureUtils() {}

View File

@ -8,6 +8,7 @@
#include "main.h" #include "main.h"
#include "utils.h" #include "utils.h"
#include "mymemory/memory_mapping.h" #include "mymemory/memory_mapping.h"
#include <video/shaders/Texture2DShader.h>
DECL(uint32_t, ProcUIProcessMessages, uint32_t u) { DECL(uint32_t, ProcUIProcessMessages, uint32_t u) {
uint32_t res = real_ProcUIProcessMessages(u); uint32_t res = real_ProcUIProcessMessages(u);
@ -20,6 +21,7 @@ DECL(uint32_t, ProcUIProcessMessages, uint32_t u) {
CallHook(WUPS_LOADER_HOOK_ENDING_APPLICATION); CallHook(WUPS_LOADER_HOOK_ENDING_APPLICATION);
ConfigUtils::saveConfigToSD(); ConfigUtils::saveConfigToSD();
DeInit(); DeInit();
Texture2DShader::destroyInstance();
} }
} }

View File

@ -69,6 +69,7 @@ void CallHookEx(wups_loader_hook_type_t hook_type, int32_t plugin_index_needed)
wups_loader_init_overlay_args_t args; wups_loader_init_overlay_args_t args;
args.overlayfunction_ptr = &overlay_helper; args.overlayfunction_ptr = &overlay_helper;
args.textureconvertfunction_ptr = &TextureUtils::convertImageToTexture; args.textureconvertfunction_ptr = &TextureUtils::convertImageToTexture;
args.drawtexturefunction_ptr = (void (*)(void*,void*,float,float,int32_t,int32_t,float)) &TextureUtils::drawTexture;
((void (*)(wups_loader_init_overlay_args_t))((uint32_t*)func_ptr) )(args); ((void (*)(wups_loader_init_overlay_args_t))((uint32_t*)func_ptr) )(args);
} else if(hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) { } else if(hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) {
((void (*)(void))((uint32_t*)func_ptr) )(); ((void (*)(void))((uint32_t*)func_ptr) )();