Skip to content

Commit 6e07701

Browse files
author
Maki
committed
fixed DDS loading from hash
1 parent a22e4e6 commit 6e07701

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

ff8_demaster/opengl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ void* __stdcall HookGlViewport(const GLint x, const GLint y, const GLsizei width
123123
{
124124
MH_CreateHookApi(L"OPENGL32", "glBindTexture", HookGlBindTexture, &ogl_bind_texture);
125125
MH_CreateHookApi(L"OPENGL32", "glTexParameteri", HookGlTextParameteri, &ogl_tex_parametri);
126+
//creating api hook is probably mandatory. Other way is to hook the entry of the api, but idk
126127
MH_CreateHookApi(L"OPENGL32", "glTexImage2D", HookGlTexImage2D, &ogl_tex_image2d);
128+
127129
//create mh hook for swapbuffers
128130
MH_CreateHook(&SwapBuffers, &HookSwapBuffers, &SwapBuffersTrampoline);
129131
MH_EnableHook(MH_ALL_HOOKS);

ff8_demaster/texture.cpp

+25-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct loadedTextureInformation
4141

4242
std::map<uint64_t, loadedTextureInformation> loadedTextures;
4343

44+
45+
//below could use splitting into multiple functions
4446
void* __stdcall HookGlTexImage2D(GLenum target,
4547
GLint level,
4648
GLint internalformat,
@@ -62,7 +64,7 @@ void* __stdcall HookGlTexImage2D(GLenum target,
6264
else if (internalformat == GL_RGB || internalformat == GL_BGR
6365
|| internalformat == GL_RGB8)
6466
lengthModifier = 3;
65-
if(HASH_ENABLED)
67+
if(HASH_ENABLED) //=======HASHING====//
6668
{
6769
if (data != nullptr && width != 0 && height != 0 && lengthModifier != 0
6870
&& width < 1024 && height < 1024)
@@ -89,7 +91,7 @@ if(HASH_ENABLED)
8991
boundId, high64, low64);
9092
knownTextures.insert(std::pair(high64, TexImageInformation{
9193
low64,static_cast<GLuint>(boundId), internalformat, width, height }));
92-
if(HASH_OUTPUT)
94+
if(HASH_OUTPUT) //======OUTPUT OF HASHED TEXTURES======//
9395
{
9496
std::string exportPath = std::string(destinationPath.string());
9597
exportPath.append(GetHashExtension(true));
@@ -127,7 +129,7 @@ if(HASH_OUTPUT)
127129
OutputDebug("Hashing of %dx%d*%d took %lfms\n", width, height,
128130
lengthModifier,
129131
static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start).count()) / 1e6);
130-
if(HASH_LOAD_HD)
132+
if(HASH_LOAD_HD) //=====HASH LOAD CODE=====//
131133
{
132134
std::string importPath = std::string(destinationPath.string());
133135
importPath.append(HASH_HD_SUFFIX);
@@ -155,9 +157,16 @@ if(HASH_OUTPUT)
155157
{
156158
OutputDebug("Loading custom HD texture: %s!", destinationPath.string().c_str());
157159

158-
//BUGGED BELOW, DO NOT USE DDS YET!
160+
159161
if(bimg::isCompressed(imageContainer->m_format))
162+
{
160163
RenderTexture(imageContainer); //redundant on checking two times for compression, but whatev
164+
//return cast to glTexImage2D but with error
165+
return static_cast<void * (__stdcall*) (GLenum, GLint, GLint, GLsizei, GLsizei,
166+
GLint, GLenum, GLenum, const void*)>(ogl_tex_image2d)
167+
(target, -1, internalformat, static_cast<GLsizei>(width)
168+
, static_cast<GLsizei>(height), border, format, type, data);
169+
}
161170
else
162171
{
163172
loadedTextureInformation lti{};
@@ -187,6 +196,18 @@ if(HASH_OUTPUT)
187196
}
188197

189198

199+
200+
//this is null sub- basically hooking api requires static cast to function pointer. However if there's need to
201+
//actually call compressed texture function, this is the way to do it. I call the compressed texture method and
202+
//then return the main texture2D method into this null function. The compressed texture and glTexImage2D are voids
203+
//that don't return anything as they work under bindings, so compressed texture will utilize the bound texture
204+
//while this null reroute will do nothing and not overwrite the texture
205+
void NullHookGlTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
206+
GLenum format, GLenum type, const void* data)
207+
{
208+
}
209+
210+
190211
BYTE* cltBackAdd1;
191212
BYTE* cltBackAdd2;
192213
DWORD* _thisFF8 = nullptr; //__thiscall, so this is ECX

ff8_demaster/texture.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ struct TexImageInformation
5858
GLint internalformat;
5959
GLsizei width, height;
6060
};
61-
6261
inline std::map<uint64_t, TexImageInformation> knownTextures;
6362
void* __stdcall HookGlTexImage2D(GLenum target,
6463
GLint level,
@@ -68,4 +67,16 @@ void* __stdcall HookGlTexImage2D(GLenum target,
6867
GLint border,
6968
GLenum format,
7069
GLenum type,
71-
const void* data);
70+
const void* data);
71+
72+
void NullHookGlTexImage2D(GLenum target,
73+
GLint level,
74+
GLint internalformat,
75+
GLsizei width,
76+
GLsizei height,
77+
GLint border,
78+
GLenum format,
79+
GLenum type,
80+
const void* data);
81+
82+
inline LPVOID nullHookGlTexImage2DPtr = NullHookGlTexImage2D;

0 commit comments

Comments
 (0)