From 6e07701981f3f70c787d30518de210aa88be6a4b Mon Sep 17 00:00:00 2001 From: Maki Date: Thu, 29 Dec 2022 17:39:38 +0100 Subject: [PATCH] fixed DDS loading from hash --- ff8_demaster/opengl.cpp | 2 ++ ff8_demaster/texture.cpp | 29 +++++++++++++++++++++++++---- ff8_demaster/texture.h | 15 +++++++++++++-- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/ff8_demaster/opengl.cpp b/ff8_demaster/opengl.cpp index 04cf2fb..90cb3c6 100644 --- a/ff8_demaster/opengl.cpp +++ b/ff8_demaster/opengl.cpp @@ -123,7 +123,9 @@ void* __stdcall HookGlViewport(const GLint x, const GLint y, const GLsizei width { MH_CreateHookApi(L"OPENGL32", "glBindTexture", HookGlBindTexture, &ogl_bind_texture); MH_CreateHookApi(L"OPENGL32", "glTexParameteri", HookGlTextParameteri, &ogl_tex_parametri); + //creating api hook is probably mandatory. Other way is to hook the entry of the api, but idk MH_CreateHookApi(L"OPENGL32", "glTexImage2D", HookGlTexImage2D, &ogl_tex_image2d); + //create mh hook for swapbuffers MH_CreateHook(&SwapBuffers, &HookSwapBuffers, &SwapBuffersTrampoline); MH_EnableHook(MH_ALL_HOOKS); diff --git a/ff8_demaster/texture.cpp b/ff8_demaster/texture.cpp index b173b99..3268019 100644 --- a/ff8_demaster/texture.cpp +++ b/ff8_demaster/texture.cpp @@ -41,6 +41,8 @@ struct loadedTextureInformation std::map loadedTextures; + +//below could use splitting into multiple functions void* __stdcall HookGlTexImage2D(GLenum target, GLint level, GLint internalformat, @@ -62,7 +64,7 @@ void* __stdcall HookGlTexImage2D(GLenum target, else if (internalformat == GL_RGB || internalformat == GL_BGR || internalformat == GL_RGB8) lengthModifier = 3; -if(HASH_ENABLED) +if(HASH_ENABLED) //=======HASHING====// { if (data != nullptr && width != 0 && height != 0 && lengthModifier != 0 && width < 1024 && height < 1024) @@ -89,7 +91,7 @@ if(HASH_ENABLED) boundId, high64, low64); knownTextures.insert(std::pair(high64, TexImageInformation{ low64,static_cast(boundId), internalformat, width, height })); -if(HASH_OUTPUT) +if(HASH_OUTPUT) //======OUTPUT OF HASHED TEXTURES======// { std::string exportPath = std::string(destinationPath.string()); exportPath.append(GetHashExtension(true)); @@ -127,7 +129,7 @@ if(HASH_OUTPUT) OutputDebug("Hashing of %dx%d*%d took %lfms\n", width, height, lengthModifier, static_cast(std::chrono::duration_cast(stop - start).count()) / 1e6); - if(HASH_LOAD_HD) + if(HASH_LOAD_HD) //=====HASH LOAD CODE=====// { std::string importPath = std::string(destinationPath.string()); importPath.append(HASH_HD_SUFFIX); @@ -155,9 +157,16 @@ if(HASH_OUTPUT) { OutputDebug("Loading custom HD texture: %s!", destinationPath.string().c_str()); - //BUGGED BELOW, DO NOT USE DDS YET! + if(bimg::isCompressed(imageContainer->m_format)) + { RenderTexture(imageContainer); //redundant on checking two times for compression, but whatev + //return cast to glTexImage2D but with error + return static_cast(ogl_tex_image2d) + (target, -1, internalformat, static_cast(width) + , static_cast(height), border, format, type, data); + } else { loadedTextureInformation lti{}; @@ -187,6 +196,18 @@ if(HASH_OUTPUT) } + +//this is null sub- basically hooking api requires static cast to function pointer. However if there's need to +//actually call compressed texture function, this is the way to do it. I call the compressed texture method and +//then return the main texture2D method into this null function. The compressed texture and glTexImage2D are voids +//that don't return anything as they work under bindings, so compressed texture will utilize the bound texture +//while this null reroute will do nothing and not overwrite the texture +void NullHookGlTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, + GLenum format, GLenum type, const void* data) +{ +} + + BYTE* cltBackAdd1; BYTE* cltBackAdd2; DWORD* _thisFF8 = nullptr; //__thiscall, so this is ECX diff --git a/ff8_demaster/texture.h b/ff8_demaster/texture.h index 0a13a59..f768b21 100644 --- a/ff8_demaster/texture.h +++ b/ff8_demaster/texture.h @@ -58,7 +58,6 @@ struct TexImageInformation GLint internalformat; GLsizei width, height; }; - inline std::map knownTextures; void* __stdcall HookGlTexImage2D(GLenum target, GLint level, @@ -68,4 +67,16 @@ void* __stdcall HookGlTexImage2D(GLenum target, GLint border, GLenum format, GLenum type, - const void* data); \ No newline at end of file + const void* data); + +void NullHookGlTexImage2D(GLenum target, + GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const void* data); + +inline LPVOID nullHookGlTexImage2DPtr = NullHookGlTexImage2D; \ No newline at end of file