mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-15 15:09:30 +00:00
1.5.8 (#17)
* remove d3dx9.dll dependency (still requires dx legacy sdk for development, but not for end users) * fix * Fix to allow gMod to be loaded as "d3d9.dll" Don't check for d3d9 functions when checking dll's, its not that deep. Fix to allow gMod to load "d3d9.dll" using the default method rather than defaulting to system directory * use d3dx sdk for wic texture loading until we figure out how to load volume/cube textures without it * fix jons commit * 1.5.7 * create warning message * pass correct pointer type, shouldn't matter but lets see * use Warning instead of Message for failed actions * need to use d3dpool_managed... * use specialised methods * actually do something in the Direct3DCreate9Ex method? * spaces * test loading WIC textures with modified WICTextureLoader9.cpp * include * Hook into GetProcAddress instead of d3d9 dll * extern "C" the Direct3DCreate9/Ex functions * turn on debug messages * add back in creating of our replacement textures, woopsies * add messages back in, not loading yet, debug later * remove SingleTexture stuff * dont rely on d3dx anymore :) * Tidied up assertion error box Added logic to use gmod as d3d9.dll or gmod.dll Added check to avoid recursive calls to create d3d9 * Remove unused func
This commit is contained in:
@@ -7,9 +7,19 @@ using HashType = DWORD32;
|
||||
#include <iostream>
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#if 1
|
||||
#define Message(...) { printf(__VA_ARGS__); }
|
||||
#else
|
||||
#define Message(...)
|
||||
#endif
|
||||
#define Warning(...) { fprintf(stderr, __VA_ARGS__); }
|
||||
|
||||
#else
|
||||
|
||||
#define Message(...)
|
||||
#define Warning(...)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include "Utils.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
+47
-47
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "FileLoader.h"
|
||||
#include "uMod_IDirect3DTexture9.h"
|
||||
#include <DDSTextureLoader/DDSTextureLoader9.h>
|
||||
@@ -61,12 +59,9 @@ private:
|
||||
bool isDirectXExDevice = false;
|
||||
|
||||
// DX9 proxy functions
|
||||
uMod_IDirect3DTexture9* GetSingleTexture();
|
||||
uMod_IDirect3DVolumeTexture9* GetSingleVolumeTexture();
|
||||
uMod_IDirect3DCubeTexture9* GetSingleCubeTexture();
|
||||
int SetLastCreatedTexture(uMod_IDirect3DTexture9*);
|
||||
int SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9*);
|
||||
int SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9*);
|
||||
void SetLastCreatedTexture(uMod_IDirect3DTexture9*);
|
||||
void SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9*);
|
||||
void SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9*);
|
||||
|
||||
bool should_update = false;
|
||||
|
||||
@@ -176,59 +171,64 @@ int TextureClient::LookUpToMod(uModTexturePtr auto pTexture)
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern HINSTANCE gl_hThisInstance;
|
||||
int TextureClient::LoadTexture(TextureFileStruct* file_in_memory, uModTexturePtrPtr auto ppTexture)
|
||||
{
|
||||
Message("LoadTexture( %p, %p, %#lX): %p\n", file_in_memory, ppTexture, file_in_memory->crc_hash, this);
|
||||
if (file_in_memory->is_wic_texture) {
|
||||
if constexpr (std::same_as<decltype(ppTexture), uMod_IDirect3DTexture9**>) {
|
||||
if (D3D_OK != D3DXCreateTextureFromFileInMemoryEx(
|
||||
D3D9Device, file_in_memory->data.data(),
|
||||
file_in_memory->data.size(), D3DX_DEFAULT, D3DX_DEFAULT,
|
||||
D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
|
||||
D3DX_DEFAULT, D3DX_DEFAULT, 0, nullptr, nullptr,
|
||||
reinterpret_cast<IDirect3DTexture9**>(ppTexture))) {
|
||||
*ppTexture = nullptr;
|
||||
Message("LoadWICTexture( %p, %#lX): FAILED\n", *ppTexture, file_in_memory->crc_hash);
|
||||
return RETURN_TEXTURE_NOT_LOADED;
|
||||
}
|
||||
Warning("(%#lX)\n", file_in_memory->crc_hash);
|
||||
#if 0
|
||||
if (D3D_OK != D3DXCreateTextureFromFileInMemoryEx(
|
||||
D3D9Device, file_in_memory->data.data(),
|
||||
file_in_memory->data.size(), D3DX_DEFAULT, D3DX_DEFAULT,
|
||||
D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
|
||||
D3DX_DEFAULT, D3DX_DEFAULT, 0, nullptr, nullptr,
|
||||
reinterpret_cast<IDirect3DTexture9**>(ppTexture))) {
|
||||
*ppTexture = nullptr;
|
||||
Warning("LoadWICTexture(%p, %#lX): FAILED\n", *ppTexture, file_in_memory->crc_hash);
|
||||
return RETURN_TEXTURE_NOT_LOADED;
|
||||
}
|
||||
D3DXIMAGE_INFO info;
|
||||
D3DXGetImageInfoFromFileInMemory(file_in_memory->data.data(), file_in_memory->data.size(), &info);
|
||||
char dllpath[MAX_PATH]{};
|
||||
GetModuleFileName(gl_hThisInstance, dllpath, MAX_PATH); //ask for name and path of this dll
|
||||
const auto dds_export_path = std::filesystem::path(dllpath).parent_path() / "d3dxout" / std::format("GW.EXE_{:X}.dds", file_in_memory->crc_hash);
|
||||
if (!std::filesystem::exists(dds_export_path)) {
|
||||
D3DXSaveTextureToFile(dds_export_path.string().c_str(), D3DXIFF_DDS, *ppTexture, nullptr);
|
||||
}
|
||||
else if constexpr (std::same_as<decltype(ppTexture), uMod_IDirect3DVolumeTexture9**>) {
|
||||
if (D3D_OK != D3DXCreateVolumeTextureFromFileInMemoryEx(
|
||||
D3D9Device, file_in_memory->data.data(),
|
||||
file_in_memory->data.size(), D3DX_DEFAULT, D3DX_DEFAULT,
|
||||
D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
|
||||
D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0,
|
||||
nullptr,
|
||||
nullptr,
|
||||
reinterpret_cast<IDirect3DVolumeTexture9**>(ppTexture))) {
|
||||
*ppTexture = nullptr;
|
||||
Message("LoadWICTexture( %p, %#lX): FAILED\n", *ppTexture, file_in_memory->crc_hash);
|
||||
return RETURN_TEXTURE_NOT_LOADED;
|
||||
}
|
||||
SetLastCreatedVolumeTexture(nullptr);
|
||||
}
|
||||
else if constexpr (std::same_as<decltype(ppTexture), uMod_IDirect3DCubeTexture9**>) {
|
||||
if (D3D_OK != D3DXCreateCubeTextureFromFileInMemoryEx(
|
||||
D3D9Device, file_in_memory->data.data(), file_in_memory->data.size(), D3DX_DEFAULT, D3DX_DEFAULT, 0,
|
||||
D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
|
||||
D3DX_DEFAULT, D3DX_DEFAULT, 0, nullptr, nullptr,
|
||||
reinterpret_cast<IDirect3DCubeTexture9**>(ppTexture))) {
|
||||
*ppTexture = nullptr;
|
||||
Message("LoadWICTexture( %p, %#lX): FAILED\n", *ppTexture, file_in_memory->crc_hash);
|
||||
return RETURN_TEXTURE_NOT_LOADED;
|
||||
}
|
||||
#else
|
||||
if (D3D_OK != DirectX::CreateWICTextureFromMemoryEx(
|
||||
D3D9Device,
|
||||
file_in_memory->data.data(),
|
||||
file_in_memory->data.size(),
|
||||
0, 0, D3DPOOL_MANAGED, DirectX::WIC_LOADER_MIP_AUTOGEN,
|
||||
reinterpret_cast<IDirect3DTexture9**>(ppTexture))) {
|
||||
*ppTexture = nullptr;
|
||||
Warning("LoadWICTexture(%p, %#lX): FAILED\n", *ppTexture, file_in_memory->crc_hash);
|
||||
return RETURN_TEXTURE_NOT_LOADED;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (D3D_OK != DirectX::CreateDDSTextureFromMemoryEx(
|
||||
D3D9Device,
|
||||
file_in_memory->data.data(),
|
||||
file_in_memory->data.size(),
|
||||
0, D3DPOOL_MANAGED, false, reinterpret_cast<LPDIRECT3DTEXTURE9*>(ppTexture))) {
|
||||
0, D3DPOOL_MANAGED, false,
|
||||
reinterpret_cast<LPDIRECT3DTEXTURE9*>(ppTexture))) {
|
||||
*ppTexture = nullptr;
|
||||
Message("LoadDDSTexture( %p, 0x%#lX): FAILED\n", *ppTexture, file_in_memory->crc_hash);
|
||||
Warning("LoadDDSTexture Normal(%p, %#lX): FAILED\n", *ppTexture, file_in_memory->crc_hash);
|
||||
return RETURN_TEXTURE_NOT_LOADED;
|
||||
}
|
||||
SetLastCreatedTexture(nullptr);
|
||||
if constexpr (std::same_as<decltype(ppTexture), uMod_IDirect3DTexture9**>) {
|
||||
|
||||
SetLastCreatedTexture(nullptr);
|
||||
}
|
||||
else if constexpr (std::same_as<decltype(ppTexture), uMod_IDirect3DVolumeTexture9**>) {
|
||||
SetLastCreatedVolumeTexture(nullptr);
|
||||
}
|
||||
else if constexpr (std::same_as<decltype(ppTexture), uMod_IDirect3DCubeTexture9**>) {
|
||||
SetLastCreatedCubeTexture(nullptr);
|
||||
}
|
||||
(*ppTexture)->FAKE = true;
|
||||
|
||||
Message("LoadTexture( %p, %#lX): DONE\n", *ppTexture, file_in_memory->crc_hash);
|
||||
|
||||
@@ -139,48 +139,31 @@ public:
|
||||
|
||||
uMod_IDirect3DTexture9* GetLastCreatedTexture() { return LastCreatedTexture; }
|
||||
|
||||
int SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture)
|
||||
void SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture)
|
||||
{
|
||||
LastCreatedTexture = pTexture;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uMod_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture() { return LastCreatedVolumeTexture; }
|
||||
|
||||
int SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture)
|
||||
void SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture)
|
||||
{
|
||||
LastCreatedVolumeTexture = pTexture;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uMod_IDirect3DCubeTexture9* GetLastCreatedCubeTexture() { return LastCreatedCubeTexture; }
|
||||
|
||||
int SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture)
|
||||
void SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture)
|
||||
{
|
||||
LastCreatedCubeTexture = pTexture;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
uMod_IDirect3DTexture9* GetSingleTexture() { return SingleTexture; }
|
||||
uMod_IDirect3DVolumeTexture9* GetSingleVolumeTexture() { return SingleVolumeTexture; }
|
||||
uMod_IDirect3DCubeTexture9* GetSingleCubeTexture() { return SingleCubeTexture; }
|
||||
|
||||
private:
|
||||
int CreateSingleTexture();
|
||||
IDirect3DDevice9* m_pIDirect3DDevice9 = nullptr;
|
||||
|
||||
int CounterSaveSingleTexture;
|
||||
uMod_IDirect3DTexture9* SingleTexture = nullptr;
|
||||
uMod_IDirect3DVolumeTexture9* SingleVolumeTexture = nullptr;
|
||||
uMod_IDirect3DCubeTexture9* SingleCubeTexture = nullptr;
|
||||
char SingleTextureMod;
|
||||
|
||||
D3DCOLOR TextureColour;
|
||||
int BackBufferCount;
|
||||
bool NormalRendering;
|
||||
|
||||
int uMod_Reference;
|
||||
bool NormalRendering = true;
|
||||
int uMod_Reference = 1;
|
||||
|
||||
uMod_IDirect3DTexture9* LastCreatedTexture = nullptr;
|
||||
uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture = nullptr;
|
||||
|
||||
@@ -161,52 +161,36 @@ public:
|
||||
|
||||
uMod_IDirect3DTexture9* GetLastCreatedTexture() { return LastCreatedTexture; }
|
||||
|
||||
int SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture)
|
||||
void SetLastCreatedTexture(uMod_IDirect3DTexture9* pTexture)
|
||||
{
|
||||
LastCreatedTexture = pTexture;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uMod_IDirect3DVolumeTexture9* GetLastCreatedVolumeTexture() { return LastCreatedVolumeTexture; }
|
||||
|
||||
int SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture)
|
||||
void SetLastCreatedVolumeTexture(uMod_IDirect3DVolumeTexture9* pTexture)
|
||||
{
|
||||
LastCreatedVolumeTexture = pTexture;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uMod_IDirect3DCubeTexture9* GetLastCreatedCubeTexture() { return LastCreatedCubeTexture; }
|
||||
|
||||
int SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture)
|
||||
void SetLastCreatedCubeTexture(uMod_IDirect3DCubeTexture9* pTexture)
|
||||
{
|
||||
LastCreatedCubeTexture = pTexture;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
uMod_IDirect3DTexture9* GetSingleTexture() { return SingleTexture; }
|
||||
uMod_IDirect3DVolumeTexture9* GetSingleVolumeTexture() { return SingleVolumeTexture; }
|
||||
uMod_IDirect3DCubeTexture9* GetSingleCubeTexture() { return SingleCubeTexture; }
|
||||
|
||||
private:
|
||||
int CreateSingleTexture();
|
||||
IDirect3DDevice9Ex* m_pIDirect3DDevice9Ex;
|
||||
|
||||
int CounterSaveSingleTexture;
|
||||
uMod_IDirect3DTexture9* SingleTexture;
|
||||
uMod_IDirect3DVolumeTexture9* SingleVolumeTexture;
|
||||
uMod_IDirect3DCubeTexture9* SingleCubeTexture;
|
||||
char SingleTextureMod;
|
||||
|
||||
D3DCOLOR TextureColour;
|
||||
int BackBufferCount;
|
||||
bool NormalRendering;
|
||||
bool NormalRendering = true;
|
||||
|
||||
int uMod_Reference;
|
||||
int uMod_Reference = 1;
|
||||
|
||||
uMod_IDirect3DTexture9* LastCreatedTexture;
|
||||
uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture;
|
||||
uMod_IDirect3DCubeTexture9* LastCreatedCubeTexture;
|
||||
uMod_IDirect3DTexture9* LastCreatedTexture = nullptr;
|
||||
uMod_IDirect3DVolumeTexture9* LastCreatedVolumeTexture = nullptr;
|
||||
uMod_IDirect3DCubeTexture9* LastCreatedCubeTexture = nullptr;
|
||||
|
||||
TextureClient* uMod_Client;
|
||||
TextureClient* uMod_Client = nullptr;
|
||||
};
|
||||
|
||||
@@ -7,11 +7,14 @@ interface uMod_IDirect3DTexture9 : public IDirect3DTexture9 {
|
||||
{
|
||||
m_D3Dtex = *ppTex; //Texture which will be displayed and will be passed to the game
|
||||
m_D3Ddev = pIDirect3DDevice9; //device pointer
|
||||
CrossRef_D3Dtex = nullptr; //cross reference
|
||||
// fake texture: store the pointer to the original uMod_IDirect3DTexture9 object, needed if a fake texture is unselected
|
||||
// original texture: stores the pointer to the fake texture object, is needed if original texture is deleted,
|
||||
// thus the fake texture can also be deleted
|
||||
}
|
||||
virtual ~uMod_IDirect3DTexture9()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// callback interface
|
||||
IDirect3DTexture9* m_D3Dtex = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user