Skip to content

Commit

Permalink
remove d3dx dependency, severely improve memory usage if necessary (#19)
Browse files Browse the repository at this point in the history
* basic tga/hdr image loading

* bgr tga tex

* convert to dds during loading
doesn't work yet, fails to create textures from dds memory

* remove ext member from TextureFileStruct

* do not convert images, leads to weird loading problems...

* use regex matching for tpf loading

* convert non-RGBA images to RGBA

* remove d3dx (mostly)

* fix moving wrong image

* move TextureFunction to module

* move FileLoader to ModfileLoader module

* move TextureClient to module

* spaces

* ifdef debug

* 1.6.0

* compress images to dxt5 (bc3_unorm) to use less memory

* remove unnecessary directxtex source code patch

* don't move unnecessarily

* only compress if mods in filesystem use up more than 400mb

* use std::future to prepare to multithread image loading
fails when using std::launch::async though, maybe something in the directxtex library is not thread safe

* remove d3dx sdk from workflows

* remove extern "C"

* catch exception when saving texture

* make loading async (call CoInitializeEx)

* support DXGI_FORMAT_BC1_UNORM (DXT1) compressed textures without warning

* don't warn for BC2 BC4 or BC5 either

* update README.md
  • Loading branch information
DubbleClick authored Dec 4, 2023
1 parent b49428b commit 9e593e8
Show file tree
Hide file tree
Showing 24 changed files with 882 additions and 896 deletions.
52 changes: 0 additions & 52 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,66 +26,14 @@ jobs:
with:
fetch-depth: 0

- name: Config
run: echo "DXSDK_DIR=DXSDK" >> $GITHUB_ENV
shell: bash

- name: Cache
id: cache
uses: actions/cache@v1
with:
path: DXSDK
key: DXSDK

- name: Cache create
if: steps.cache.outputs.cache-hit != 'true'
run: |
curl -L https://download.microsoft.com/download/a/e/7/ae743f1f-632b-4809-87a9-aa1bb3458e31/DXSDK_Jun10.exe -o _DX2010_.exe
7z x _DX2010_.exe DXSDK/Include
7z x _DX2010_.exe DXSDK/Lib/x86
shell: bash

- name: Echo cache
run: echo ${{ env.DXSDK_DIR }}

- name: List dxsdk files
run: |
cd DXSDK
ls
cd Include
ls
cd ../Lib/x86
ls
- name: Copy DirectX headers to project include directory
run: Copy-Item -Path "${{ env.DXSDK_DIR }}/Include/*" -Destination header/ -Recurse -Force
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
shell: pwsh

- name: Ensure Lib directory exists and copy DirectX libraries
run: |
$libDir = "Lib/"
if (-Not (Test-Path -Path $libDir)) {
New-Item -ItemType Directory -Path $libDir
}
Copy-Item -Path "${{ env.DXSDK_DIR }}/Lib/x86/*" -Destination $libDir -Recurse -Force
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
shell: pwsh

- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.3.1

- name: Build CMake Files
run: cmake -S . -B build -A Win32
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}

- name: Build binaries
run: cmake --build build --config Release
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}

- name: Retrieve version
id: set_version
Expand Down
53 changes: 0 additions & 53 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,64 +29,11 @@ jobs:
with:
fetch-depth: 0

#https://stackoverflow.com/questions/61037714/how-to-install-an-old-version-of-the-direct-x-api-in-github-actions
- name: Config
run: echo "DXSDK_DIR=DXSDK" >> $GITHUB_ENV
shell: bash

- name: Cache
id: cache
uses: actions/cache@v1
with:
path: DXSDK
key: DXSDK

- name: Cache create
if: steps.cache.outputs.cache-hit != 'true'
run: |
curl -L https://download.microsoft.com/download/a/e/7/ae743f1f-632b-4809-87a9-aa1bb3458e31/DXSDK_Jun10.exe -o _DX2010_.exe
7z x _DX2010_.exe DXSDK/Include
7z x _DX2010_.exe DXSDK/Lib/x86
shell: bash

- name: Echo cache
run: echo ${{ env.DXSDK_DIR }}

- name: List dxsdk files
run: |
cd DXSDK
ls
cd Include
ls
cd ../Lib/x86
ls
- name: Copy DirectX headers to project include directory
run: Copy-Item -Path "${{ env.DXSDK_DIR }}/Include/*" -Destination header/ -Recurse -Force
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
shell: pwsh

- name: Ensure Lib directory exists and copy DirectX libraries
run: |
$libDir = "Lib/"
if (-Not (Test-Path -Path $libDir)) {
New-Item -ItemType Directory -Path $libDir
}
Copy-Item -Path "${{ env.DXSDK_DIR }}/Lib/x86/*" -Destination $libDir -Recurse -Force
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
shell: pwsh

- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.3.1

- name: Build CMake Files
run: cmake -S . -B build -A Win32
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}

- name: Build binaries
run: cmake --build build --config Release
env:
DXSDK_DIR: ${{ env.DXSDK_DIR }}
32 changes: 7 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ if(${CLEAN} MATCHES "ON")
endif()

set(VERSION_MAJOR 1)
set(VERSION_MINOR 5)
set(VERSION_PATCH 8)
set(VERSION_MINOR 6)
set(VERSION_PATCH 0)
set(VERSION_TWEAK 0)

set(VERSION_RC "${CMAKE_CURRENT_BINARY_DIR}/version.rc")
Expand All @@ -31,22 +31,6 @@ set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/bin/install)

add_compile_options(/MP /permissive-)

find_library(D3D9_LIB NAMES d3d9 PATHS $ENV{DXSDK_DIR}/lib/x86 NO_DEFAULT_PATH)
find_library(D3DX9_LIB NAMES d3dx9 PATHS $ENV{DXSDK_DIR}/lib/x86 NO_DEFAULT_PATH)
find_library(DXGUID_LIB NAMES dxguid PATHS $ENV{DXSDK_DIR}/lib/x86 NO_DEFAULT_PATH)

if(NOT D3D9_LIB)
find_library(D3D9_LIB NAMES d3d9 PATHS ${CMAKE_SOURCE_DIR}/Lib)
endif()

if(NOT D3DX9_LIB)
find_library(D3DX9_LIB NAMES d3dx9 PATHS ${CMAKE_SOURCE_DIR}/Lib)
endif()

if(NOT DXGUID_LIB)
find_library(DXGUID_LIB NAMES dxguid PATHS ${CMAKE_SOURCE_DIR}/Lib)
endif()

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(libzippp)
include(minhook)
Expand All @@ -57,25 +41,23 @@ add_library(gMod SHARED)
file(GLOB SOURCES
"header/*.h"
"source/*.cpp"
"modules/*.ixx"
${VERSION_RC}
)

target_include_directories(gMod PRIVATE
"header"
${CMAKE_INSTALL_PREFIX}/include
$ENV{DXSDK_DIR}/Include
)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${SOURCES})
target_sources(gMod PRIVATE ${SOURCES})

target_link_libraries(gMod PRIVATE
${D3D9_LIB}
${D3DX9_LIB}
${DXGUID_LIB}
dxguid
libzippp
psapi
minhook
directxtex
psapi
minhook
directxtex
)
target_link_options(gMod PRIVATE
"$<$<CONFIG:DEBUG>:/NODEFAULTLIB:LIBCMT>"
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Requirements:
- DirectX SDK (June 2010)
- Visual Studio 2022
- CMake 3.16+, integrated into the Developer Powershell for VS 2022

Compile:
- cmake -B build
- cmake --open build
- compile

*Usage is primarily intended with GW Launcher or Daybreak, but it can be used without.*

**Usage with manual gMod.dll injection:**
- Create a file called modlist.txt in either the Guild Wars (Gw.exe) folder, or the gMod.dll folder.
- Inject gMod.dll before d3d9.dll is loaded.

**Usage without dll injection:**
- Create a file called modlist.txt in the Guild Wars (Gw.exe) folder.
- Place gMod.dll in the Guild Wars folder
- Rename gMod.dll to d3d9.dll
- Launch Guild Wars

**Format of the modlist.txt file:**


Each line in the modlist.txt is the full path to a mod you want to load (eg. `D:\uMod\Borderless Cartography Made Easy 2015 1.3.tpf`)
gMod will load all these files on startup
14 changes: 0 additions & 14 deletions README.txt

This file was deleted.

7 changes: 0 additions & 7 deletions cmake/dxtk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ endif()

FetchContent_Populate(directxtex)

file(READ "${directxtex_SOURCE_DIR}/WICTextureLoader/WICTextureLoader9.cpp" FILE_CONTENT)
string(REPLACE
"hr = frame->GetPixelFormat(&pixelFormat);\n"
"hr = frame->GetPixelFormat(&pixelFormat); if (pixelFormat == GUID_WICPixelFormat32bppBGR) pixelFormat = GUID_WICPixelFormat32bppBGRA;\n"
FILE_CONTENT "${FILE_CONTENT}" )
file(WRITE "${directxtex_SOURCE_DIR}/WICTextureLoader/WICTextureLoader9.cpp" "${FILE_CONTENT}")

add_library(directxtex)
file(GLOB SOURCES
"${directxtex_SOURCE_DIR}/DDSTextureLoader/DDSTextureLoader9.h"
Expand Down
45 changes: 27 additions & 18 deletions header/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,36 @@
//#define HashType DWORD64
using HashType = DWORD32;

#ifdef LOG_MESSAGE
#include <iostream>

struct TexEntry {
std::vector<BYTE> data{};
HashType crc_hash = 0; // hash value
std::string ext{};
};

struct TextureFileStruct {
std::vector<BYTE> data{};
HashType crc_hash = 0; // hash value
};

inline void Message(const char* format, ...)
{
#ifdef _DEBUG

#if 1
#define Message(...) { printf(__VA_ARGS__); }
#else
#define Message(...)
#if 0
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
#endif
#define Warning(...) { fprintf(stderr, __VA_ARGS__); }

#else

#define Message(...)
#define Warning(...)

#endif
}

inline void Warning(const char* format, ...)
{
#ifdef _DEBUG
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
#endif
}

#ifndef _countof
#define _countof(arr) sizeof(arr) / sizeof(*arr)
#endif
30 changes: 0 additions & 30 deletions header/FileLoader.h

This file was deleted.

7 changes: 3 additions & 4 deletions header/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
#include <cstdlib>
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <future>
#include <map>
#include <ranges>
#include "Utils.h"

#include <d3d9.h>

#include "Defines.h"
#include "Error.h"
#include "Defines.h"
#include "dll_main.h"
#include "TextureFunction.h"

#include "uMod_IDirect3D9.h"
#include "uMod_IDirect3D9Ex.h"
Expand All @@ -26,8 +27,6 @@
#include "uMod_IDirect3DTexture9.h"
#include "uMod_IDirect3DVolumeTexture9.h"

#include "TextureClient.h"

#pragma warning(disable : 4477)

extern unsigned int gl_ErrorState;
Expand Down
Loading

0 comments on commit 9e593e8

Please sign in to comment.