1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2024-11-27 16:00:52 +01:00

iidxhook-util: Major refactoring of d3d9 module

Uses the hook/d3d9 module with IRP handlers now. All previously
available features are implemented.

Furthermore, a new overhauled up-/downscaling method is implemented
which supports all IIDX versions now.
This commit is contained in:
icex2 2019-10-06 21:19:06 +02:00
parent d169ee84b3
commit c5d39d82d5
2 changed files with 1021 additions and 907 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,123 +1,180 @@
#ifndef IIDXHOOK_D3D9_H
#define IIDXHOOK_D3D9_H
/**
* This module hooks into various D3D9 calls implementing a large set of features for IIDX games such as:
* window mode, frame buffer up-/downscaling, software rate limiting, software monitor check,...
*
* @author icex2
*/
#include <stdbool.h>
#include <stdint.h>
#include "hook/d3d9.h"
/**
* Filter types for scaling back buffer, e.g. upscaling for higher resolution monitors.
*/
enum d3d9_back_buffer_scale_filter {
D3D9_BACK_BUFFER_SCALE_FILTER_NONE = 0,
D3D9_BACK_BUFFER_SCALE_FILTER_LINEAR = 1,
D3D9_BACK_BUFFER_SCALE_FILTER_POINT = 2,
enum iidxhook_util_d3d9_back_buffer_scale_filter {
IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE = 0,
IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_LINEAR = 1,
IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_POINT = 2,
};
/**
* Callback function to receive resulting refresh rate of monitor check.
*/
typedef void (*d3d9_monitor_check_result_callback_t)(double refresh_rate);
typedef void (*iidxhook_util_d3d9_monitor_check_result_callback_t)(double refresh_rate);
/**
* Hook some d3d9 functions to patch gfx related stuff
* like enabling window mode.
*
* Games using d3d9:
* - IIDX: Gold to Copula
* Config structure for this module. Enable/disable supported features.
*/
void d3d9_hook_init(void);
struct iidxhook_util_d3d9_config {
/**
* Enable/disable window mode. Consider combining with framed.
*/
bool windowed;
/**
* Enable a window frame and make the window movable, resizable, minizable.
*/
bool framed;
/**
* Override the default window height which is determined by the frame buffer size.
* Set this to 0 to disable the override.
*/
uint16_t override_window_width;
/**
* Override the default window width which is determined by the frame buffer size.
* Set this to 0 to disable the override.
*/
uint16_t override_window_height;
/**
* Set a software driven framerate limit for the rendering loop and lock to the specified refresh rate, e.g. 59.94.
* Use this if the game won't sync up properly with vsync enabled.
*/
float framerate_limit;
/**
* Override the GPU vendor ID identifier on display device enumeration.
* Use this to disable locking to specific GPU cards.
* Combine with the pci_pid parameter.
*
* Vendor ATI: 1002
*/
uint16_t pci_vid;
/**
* Override the GPU product ID identifier on display device enumeration.
* Use this to disable locking to specific GPU cards.
* Combine with the pci_pid parameter.
*
* PIDs:
* 7146: RV515 [Radeon X1300]
* 95C5: RV620 LE [Radeon HD 3450]
*/
uint16_t pci_pid;
/**
* Enable a software "monitor check" which determines the (avg.) refresh rate
* of the game. Ensure that your GPU is outputting a stable refresh rate to
* your monitor. Otherwise, the resulting values fluctuate a lot.
*
* Callback to a function that receives the result of the monitor check once it completed.
*/
iidxhook_util_d3d9_monitor_check_result_callback_t iidx09_to_19_monitor_check_cb;
/**
* Ported from d3d8 module to enable this when using d3d8to9.
*
* Fixes UV coordinates for background videos on IIDX Red to DD and a quad seam issue for 14 to 17.
* Use this if you experience the game stretching the background videos or seeing a quad seam
* (see implementation for further details).
*/
bool iidx11_to_17_fix_uvs_bg_videos;
/**
* Ported from d3d8 module to enable this when using d3d8to9.
*
* Fixes the 3D background displayed during song select by disabling fog.
* On some machines/GPUs the background is rendered completely white which
* is caused by buggy fog rendering. Fog is used to hide the rings appearing
* but that's quite 'far away' so disabling fog doesn't look bad.
*/
bool iidx12_fix_song_select_bg;
/**
* Ported from d3d8 module to enable this when using d3d8to9.
*
* Fixes the 3D background displayed during song select by disabling lighting.
* On some machines/GPUs the background is rendered completely black which
* is caused by buggy lighting. Disabling (dynamic) lighting sets the whole
* scene to ambient lighting which displays everything properly.
*/
bool iidx13_fix_song_select_bg;
/**
* Fixes a parameter on CreateTexture calls causing the game to crash with
* NVIDIA cards (on GOLD and possible newer)
*/
bool iidx14_to_19_nvidia_fix;
/**
* Scale the back buffer after a frame got rendered. This allows you to up-/downscale the final frame to display
* arbitrary resolutions, e.g. 640x480 -> 1920x1080 to allow displaying the game in the monitor's native resolution.
* This avoids over-/underscan (yes, that's still a thing with todays TVs) or leaving the upscaling to monitors/TVs
* that are doing a terrible job regarding picture quality or latency wise.
*
* @param width Target width to scale the frame to. 0 disables scaling entirely.
* @param height Target height to scale the frame to. 0 disables scaling entirely.
* @param filter Filtering method to use for scaling. Depending on how you scale, this can have an impact on the
* final image quality.
*/
uint16_t scale_back_buffer_width;
/**
* Back buffer scale height, see parameter scale_back_buffer_width for full doc.
*/
uint16_t scale_back_buffer_height;
/**
* Back buffer scale filter to apply, see parameter scale_back_buffer_width for full doc.
*/
enum iidxhook_util_d3d9_back_buffer_scale_filter scale_back_buffer_filter;
};
/**
* Set the game to window mode.
*
* @param framed True to add a window frame and make the window
* movable, resizable, minizable. False for no frame.
* @param width Width of the window. -1 to keep original width.
* @param height Height of the window. -1 to keep original height.
*/
void d3d9_set_windowed(bool framed, int32_t width, int32_t height);
/**
* Patch the GPU device ID detection to allow running the game with
* other GPUs than the ones it is locked to.
*
* @param vid Vendor ID to patch.
* @param pid Product ID to patch.
*/
void d3d9_set_pci_id(uint16_t vid, uint16_t pid);
/**
* Set a framerate limit for the rendering loop.
*
* Use this if the game won't sync up properly with vsync enabled.
*
* @limit Number of frames to limit the rendering loop to
*/
void d3d9_set_frame_rate_limit(float limit);
/**
* Enable a software a "monitor check" which determines the (avg.) refresh rate
* of the game. Ensure that your GPU is outputting a stable refresh rate to
* your monitor. Otherwise, the resulting values fluctuate a lot
* Initialize this hook module. Must be called before any other function of this module.
*
* @param cb Callback to a function that receives the result of the monitor
* check once it completed.
* Games using d3d9: IIDX 14 (Gold) to IIDX 27 (Rootage)
* For d3d8 based games (IIDX 9 to 13): use d3d8to9 wrapper to allow usage of this module.
*/
void d3d9_enable_monitor_check(d3d9_monitor_check_result_callback_t cb);
void iidxhook_util_d3d9_hook_init(void);
/**
* Ported from d3d8 module to enable this when using d3d8to9.
* Initialize the provided config struct with default values.
*
* Fixes UV coordinates for background videos on
* IIDX Red to DD. Use this if you experience the game
* stretching the background videos
* (see implementation for further details)
* @param config Pointer to an initialized struct to write default values to.
*/
void d3d9_iidx_fix_stretched_bg_videos(void);
void iidxhook_util_d3d9_init_config(struct iidxhook_util_d3d9_config* config);
/**
* Ported from d3d8 module to enable this when using d3d8to9.
* Configure this module by applying the provided config.
*
* Fixes the 3D background displayed during song select by disabling fog.
* On some machines/GPUs the background is rendered completely white which
* is caused by buggy fog rendering. Fog is used to hide the rings appearing
* but that's quite 'far away' so disabling fog doesn't look bad.
* @param config Config to apply.
*/
void d3d9_iidx_fix_12_song_select_bg(void);
void iidxhook_util_d3d9_configure(const struct iidxhook_util_d3d9_config* config);
/**
* Ported from d3d8 module to enable this when using d3d8to9.
* Main IRP handler call for this module. Must be set up with the hook/d3d9 module to receive calls from d3d9.
*
* Fixes the 3D background displayed during song select by disabling lighting.
* On some machines/GPUs the background is rendered completely black which
* is caused by buggy lighting. Disabling (dynamic) lighting sets the whole
* scene to ambient lighting which displays everything properly.
* @param irp Pointer to a valid IRP.
* @return S_OK on success, error otherwise (depending on the irp op).
*/
void d3d9_iidx_fix_13_song_select_bg(void);
/**
* Fixes a parameter on CreateTexture calls causing the game to crash with
* NVIDIA cards (on GOLD and possible newer)
*/
void d3d9_enable_nvidia_fix(void);
/**
* Fixes UV coordinates for background videos on
* (similar to the d3d8 games). But, this fixes the quad seam issue on 14 to
* 17, only.
*/
void d3d9_bg_video_seams_fix(void);
/**
* Scale the back buffer after a frame got rendered. This allows you to up-/downscale the final frame to display
* arbitrary resolutions, e.g. 640x480 -> 1920x1080 to allow displaying the game in the monitor's native resolution.
* This avoids over-/underscan (yes, that's still a thing with todays TVs) or leaving the upscaling to monitors/TVs
* that are doing a terrible job regarding picture quality or latency wise.
*
* @param width Target width to scale the frame to. 0 disables scaling entirely.
* @param height Target height to scale the frame to. 0 disables scaling entirely.
* @param filter Filtering method to use for scaling. Depending on how you scale, this can have an impact on the final
* image quality.
*/
void d3d9_scale_back_buffer(uint16_t width, uint16_t height, enum d3d9_back_buffer_scale_filter filter);
HRESULT iidxhook_util_d3d9_irp_handler(struct hook_d3d9_irp* irp);
#endif