Skip to content

Commit

Permalink
fixed DDS loading from hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Maki committed Dec 29, 2022
1 parent a22e4e6 commit 6e07701
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ff8_demaster/opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 25 additions & 4 deletions ff8_demaster/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct loadedTextureInformation

std::map<uint64_t, loadedTextureInformation> loadedTextures;


//below could use splitting into multiple functions
void* __stdcall HookGlTexImage2D(GLenum target,
GLint level,
GLint internalformat,
Expand All @@ -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)
Expand All @@ -89,7 +91,7 @@ if(HASH_ENABLED)
boundId, high64, low64);
knownTextures.insert(std::pair(high64, TexImageInformation{
low64,static_cast<GLuint>(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));
Expand Down Expand Up @@ -127,7 +129,7 @@ if(HASH_OUTPUT)
OutputDebug("Hashing of %dx%d*%d took %lfms\n", width, height,
lengthModifier,
static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(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);
Expand Down Expand Up @@ -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<void * (__stdcall*) (GLenum, GLint, GLint, GLsizei, GLsizei,
GLint, GLenum, GLenum, const void*)>(ogl_tex_image2d)
(target, -1, internalformat, static_cast<GLsizei>(width)
, static_cast<GLsizei>(height), border, format, type, data);
}
else
{
loadedTextureInformation lti{};
Expand Down Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions ff8_demaster/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ struct TexImageInformation
GLint internalformat;
GLsizei width, height;
};

inline std::map<uint64_t, TexImageInformation> knownTextures;
void* __stdcall HookGlTexImage2D(GLenum target,
GLint level,
Expand All @@ -68,4 +67,16 @@ void* __stdcall HookGlTexImage2D(GLenum target,
GLint border,
GLenum format,
GLenum type,
const void* data);
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;

0 comments on commit 6e07701

Please sign in to comment.