From 301c336d45dd3815de715049d2b0f4ca2ec4da58 Mon Sep 17 00:00:00 2001 From: Peter Thoman Date: Mon, 31 Dec 2012 15:54:37 +0100 Subject: [PATCH] Version 2.0.1 --- DATA/DSfix.ini | 89 ++++++++++------ DATA/DSfixKeys.ini | 2 +- DATA/README.txt | 1 + DATA/VERSIONS.txt | 24 ++++- DSfix.v11.suo | Bin 94720 -> 108544 bytes FPS.cpp | 230 ++++++++++------------------------------- RenderstateManager.cpp | 43 +------- Settings.cpp | 3 + Settings.def | 4 +- d3d9dev.cpp | 44 ++++++-- main.h | 2 +- 11 files changed, 174 insertions(+), 268 deletions(-) diff --git a/DATA/DSfix.ini b/DATA/DSfix.ini index 584b3e5..b83b11f 100644 --- a/DATA/DSfix.ini +++ b/DATA/DSfix.ini @@ -7,6 +7,14 @@ renderWidth 1920 renderHeight 1080 +# The display width/height +# 0 means use the same resolution as renderWidth/Height +# (use for downscaling - if in doubt, leave at 0) +presentWidth 0 +presentHeight 0 + +############# Anti Aliasing + # AA toggle and quality setting # 0 = off (best performance, worst IQ) # 1 = low @@ -19,6 +27,8 @@ aaQuality 0 # either "SMAA" or "FXAA" aaType SMAA +############# Ambient Occlusion + # Enable and set the strength of the SSAO effect (all 3 settings have the same performance impact!) # 0 = off # 1 = low @@ -26,25 +36,19 @@ aaType SMAA # 3 = high ssaoStrength 0 -# Enable variable framerate (up to 60) -# NOTE: -# - this requires in-memory modification of game code, and may get you banned from GFWL -# - there may be unintended side-effects in terms of gameplay -# - you need a very powerful system (especially CPU) in order to maintain 60 FPS -# - in some instances, collision detection may fail. Avoid sliding down ladders -# Use this at your own risk! -# 0 = no changes to game code -# 1 = unlock the frame rate -unlockFPS 0 - -# FPS limit, only used with unlocked framerate -# do not set this much higher than 60, this will lead to various issues with the engine -FPSlimit 60 +# Set SSAO scale +# 1 = high quality (default) +# 2 = lower quality, lower impact on performance +# 3 = lowest quality, lowest impact on performance +ssaoScale 1 -# FPS threshold -# DSfix will dynamically disable SMAA if your framerate drops below this value -# and re-enable it once it has normalized (with a bit of hysteresis thresholding) -FPSthreshold 45 +# Determine the type of AO used +# "VSSAO" = Volumetric SSAO (default, suggested) +# "HBAO" = Horizon-Based Ambient Occlusion +# "SCAO" = VSSAO + HBAO +# VSSAO and HBAO types have a different effect and similar performance +# SCAO combines both, with a higher performance impact +ssaoType VSSAO ############# Depth of field @@ -56,7 +60,7 @@ FPSthreshold 45 # 2160 = DoF pyramid starts at 3840x2160 # higher values will decrease performance # do NOT set this to the same value as your vertical rendering resolution! -dofOverrideResolution 0 +dofOverrideResolution 540 # Depth of Field scaling override (NOT RECOMMENDED) # 0 = DoF scaling enabled (default, recommended) @@ -70,7 +74,38 @@ disableDofScaling 0 # 0 or 1 at 540 DoF resolution # 1 or 2 above that # 3 or 4 at 2160 DoF resolution (if you're running a 680+) -dofBlurAmount 0 +dofBlurAmount 1 + +############# Framerate + +# Enable variable framerate (up to 60) +# NOTE: +# - this requires in-memory modification of game code, and may get you banned from GFWL +# - there may be unintended side-effects in terms of gameplay +# - you need a very powerful system (especially CPU) in order to maintain 60 FPS +# - in some instances, collision detection may fail. Avoid sliding down ladders +# Use this at your own risk! +# 0 = no changes to game code +# 1 = unlock the frame rate +unlockFPS 0 + +# FPS limit, only used with unlocked framerate +# do not set this much higher than 60, this will lead to various issues with the engine +FPSlimit 60 + +# FPS threshold +# DSfix will dynamically disable AA if your framerate drops below this value +# and re-enable it once it has normalized (with a bit of hysteresis thresholding) +FPSthreshold 28 + +############# Filtering + +# texture filtering override +# 0 = no change +# 1 = enable some bilinear filtering (use only if you need it!) +# 2 = full AF override (may degrade performance) +# if in doubt, leave this at 0 +filteringOverride 0 ############################################################################### # HUD options @@ -98,7 +133,7 @@ hudTopLeftOpacity 0.8f # Bottom left: item indicators & counts hudBottomLeftOpacity 0.75f # Bottom right: soul count -hudBottomRightOpacity 0.0f +hudBottomRightOpacity 0.5f ############################################################################### # Window & Mouse Cursor Options @@ -195,23 +230,11 @@ logLevel 0 # The settings below are not yet ready to use!! ############################################################################### -# texture filtering override (NOT RECOMMENDED) -# 0 = no change -# 1 = enable supersampling by downscaling (use only if you need it!) -# 2 = full AF override (may degrade performance, currently implemented badly, do not enable) -# if in doubt, leave this at 0 -# you do not need this this if you override filtering in the driver, which is a better option -filteringOverride 0 - # You can only set either forceFullscreen or forceWindowed (or neither) # 0 = off, 1 = on forceWindowed 0 forceFullscreen 0 -# The following settings are only functional if either forceFullscreen or forceWindowed is enabled -# The display width/height -presentWidth 1280 -presentHeight 720 # turn on/off Vsync enableVsync 0 # adjust display refresh rate in fullscreen mode - this is NOT linked to FPS! diff --git a/DATA/DSfixKeys.ini b/DATA/DSfixKeys.ini index 2d793a5..c45d285 100644 --- a/DATA/DSfixKeys.ini +++ b/DATA/DSfixKeys.ini @@ -10,7 +10,7 @@ toggleBorderlessFullscreen VK_F8 toggleHUD VK_RCONTROL toggleHUDChanges VK_RSHIFT -#toggleSMAA VK_NUMPAD1 +#toggleAA VK_NUMPAD1 #toggleVSSAO VK_NUMPAD2 #toggleDofGauss VK_NUMPAD3 diff --git a/DATA/README.txt b/DATA/README.txt index 60e1595..a34bbf6 100644 --- a/DATA/README.txt +++ b/DATA/README.txt @@ -56,6 +56,7 @@ First, make sure that the .ini files are present in the correct location. Additionally, the "dsfix" folder should be in that same location. Turn off tools such as MSI Afterburner or other overlays that manipulate D3D. Then try restoring the default settings in the .ini file +If you are using the framerate unlock feature, disable Windows "Data Execution Prevention". If none of these help then check if the problem still occurs when you remove/rename DINPUT8.dll Finally, try rebooting If the issue still persists, then report the problem, otherwise it has nothing to do with DSfix. diff --git a/DATA/VERSIONS.txt b/DATA/VERSIONS.txt index a6a8576..eb214cf 100644 --- a/DATA/VERSIONS.txt +++ b/DATA/VERSIONS.txt @@ -1,21 +1,35 @@ -25-10-1012 -- version 1.9 beta +22-12-2012 -- version 2.0.1 +========================= +- Fixed HUD modification bug introduced in 2.0 + + +21-12-2012 -- version 2.0 +========================= +- Updated the framerate unlock feature to work with the patched version of the game (Nwks) +- Updated post-processing AA to work with the patched version of the game +- Added "PresentWidth" and "PresentHeight" for full control over (windowed) downsampling +- Fixed an issue where hudless screenshots would sometimes not correctly capture some effects + + +25-10-2012 -- version 1.9 beta ============================== - Added 2 new ambient occlusion algorithms: HBAO and SCAO - Added scale option for ambient occlusion on lower-end systems - Disabled hotkeys when Dark Souls is not active - Reinstated the texture filtering option with slightly better implementation +- Small bug fixes in frame rate limits calculation - Rework WindowManager::resize to center the window along with resizing, and call on startup (wT) - Fix prevExStyle in WindowManager::toggleBorderlessFullscreen (wT) -21-10-1012 -- version 1.8 beta +21-10-2012 -- version 1.8 beta ============================== - Added FXAA option for AA - Added 30 FPS limit toggle - Greatly improved SSAO depth usage, removed thickness model hack -29-09-1012 -- version 1.7 beta +29-09-2012 -- version 1.7 beta ============================== - Re-implemented the FPS limiter. It's quite exact now and also performed at a better point in time (before presenting the frame) @@ -23,14 +37,14 @@ - Added FPS thresholding for SMAA -29-09-1012 -- version 1.6.1 beta +29-09-2012 -- version 1.6.1 beta ================================ - Fixed sporadic graphics issues introduced in 1.6 - Fixed modified HUD issues with very long spell names - Fixed modified HUD issues with "POISONED"/"BLOOD LOSS" text -29-09-1012 -- version 1.6 beta +29-09-2012 -- version 1.6 beta ============================== - Unlocked framerate. Thanks to the hard work of Clément Barnier, the framerate can now be unlocked entirely. (look into the .ini for details) diff --git a/DSfix.v11.suo b/DSfix.v11.suo index b5da038a05e46bbc6c8e369255cc4ec3859b4f40..d81c59c81798ce05fe96b2baf7cc238018466819 100644 GIT binary patch delta 8357 zcmd5>33QWnw*T(eBuz`&rdud&Xwwu*%hH8bL})S4qEJg0I+V(ybYZgv3WP-#n-*k| zWoWMQXIua~@Matsl?LqSI8InZ1Pay1V@41}K%e3QVp+<0!n^lNQi31{eV+6D&iUoP zZ};B+{oU`2?X23?qFIw7Qi{PZLN7^=OOm7_T)%PS1|<>@hHWd1k^{#rf8NyjbTgE3 zbs5f+=fP6EB2e|VAl=da0 z6CRYL8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Tfk<|^Tu%iLA_Pz78#V>ZBsd?pEan4JwfL+&;wn$IW=Dk)_J)B#%K(GT1Aa&e0 zB2(<5@h$e?x#5uDXoX$)T<$p~E)V7Jx56R!nr3JcxXpLeV|(B}5c*aW`ol@47^)Ndh*82j0H};D6w=EoA@z diff --git a/FPS.cpp b/FPS.cpp index 863d152..ea72756 100644 --- a/FPS.cpp +++ b/FPS.cpp @@ -22,13 +22,21 @@ static DWORD originalBase = NULL; static DWORD imageBase = NULL; // Hook Globals -static DWORD HighGraphics; -static DWORD TaskFuncPtr; +float lastRenderTime; static LARGE_INTEGER timerFreq; static LARGE_INTEGER counterAtStart; +// Hook Addresses +//------------------------------------ +// Time-step value address +#define ADDR_TS 0x012498E0 // 1.0.0 was 0x012497F0, 1.0.1 is 0x012498E0 +// Presentation interval address +#define ADDR_PRESINT 0x0102788E // 1.0.0 was 0x010275AE, 1.0.1 is 0x0102788E +// getDrawThreadMsgCommand address in HGCommandDispatcher loop +#define ADDR_GETCMD 0x00BD60ED // 1.0.0 was 0x00BD601D, 1.0.1 is 0x00BD60ED + //---------------------------------------------------------------------------------------- -//Functions +// Support Functions //---------------------------------------------------------------------------------------- // Misc @@ -63,7 +71,7 @@ void updateAnimationStepTime(float stepTime, float minFPS, float maxFPS) { float cappedStep = 1/(float)FPS; DWORD data = *(DWORD*)&cappedStep; - writeToAddress(&data, convertAddress(0x012497F0), sizeof(data)); + writeToAddress(&data, convertAddress(ADDR_TS), sizeof(data)); } // Timer @@ -75,19 +83,21 @@ float getElapsedTime(void) { // Detour //------------------------------------ -//Make sure to adjust length according to instructions below detoured address! -//Partially overwritten instructions will mess-up disassembly and capacity to debug -void *DetourApply(BYTE *orig, BYTE *hook, int len, int type) { +// Make sure to adjust length according to instructions below detoured address! +// Partially overwritten instructions will mess-up disassembly and capacity to debug +void *DetourApply(BYTE *orig, BYTE *hook, int len, BYTE type) +{ BYTE OP, SZ; - if (type == 0) { + if (type == JMPOP) { OP = JMPOP; SZ = JMP32_SZ; } - else if(type == 1) { + else if (type == CALLOP) { OP = CALLOP; SZ = CALL32_SZ; } + else return 0; DWORD dwProt = 0; BYTE *jmp = (BYTE*)malloc(len+SZ); @@ -107,7 +117,6 @@ void *DetourApply(BYTE *orig, BYTE *hook, int len, int type) { return (jmp-len); } - void DetourRemove(BYTE *src, BYTE *jmp, int len) { DWORD dwProt = 0; VirtualProtect(src, len, PAGE_READWRITE, &dwProt); @@ -116,175 +125,39 @@ void DetourRemove(BYTE *src, BYTE *jmp, int len) { } //---------------------------------------------------------------------------------------- -//Game hooks -//---------------------------------------------------------------------------------------- - -// Render Loop +// Hook functions //---------------------------------------------------------------------------------------- -void renderLoop(void) { - bool run = true; - DWORD threadID = GetCurrentThreadId(); - int taskFunc; - DWORD task; - - //Pointers conversion - DWORD pGetTaskF = convertAddress(0x00577330); - DWORD pCleanTaskF = convertAddress(0x00577450); - - QueryPerformanceFrequency(&timerFreq); - QueryPerformanceCounter(&counterAtStart); - float lastTime = 0.0f; - - // Render loop - do { - // Get Job & state - _asm { - PUSH 1 - MOV ECX, HighGraphics - CALL pGetTaskF //Get task pointer - MOV task, EAX //Store task pointer (EAX) - MOV ECX, [EAX+0x0C] //Get task function - MOV taskFunc, ECX //Store function - } - if (task == (HighGraphics+0x08)) //No task - break; - - switch (taskFunc) { - // Exit loop - case 0: - _asm { - MOV EDI, TaskFuncPtr - MOV EAX, [EDI] - MOV EDX, [EAX+0x0C] - MOV ECX, EDI - CALL EDX - } - run = false; - break; - // Start Watch-dog Thread - case 1: - _asm { - MOV ESI, task - MOV EDI, TaskFuncPtr - MOV ECX, [ESI+0x2C] - MOV EDX, [ESI+0x28] - MOV EAX, [EDI] - PUSH ECX - MOV ECX, [ESI+0x24] - PUSH EDX - MOV EDX, [EAX+0x08] - PUSH ECX - MOV ECX, EDI - CALL EDX - } - break; - // Update and/or Render - case 2: - _asm { - MOV ESI, task - MOV EDI, TaskFuncPtr - MOV ECX, [ESI+0x24] - MOV EAX, [EDI] - MOV EDX, [EAX+0x10] - PUSH ECX - MOV ECX, EDI - CALL EDX - } - break; - // Do nothing (was debug log) - case 3: - _asm { - MOV EDI, TaskFuncPtr - MOV EAX, [EDI] - MOV EDX, [EAX+0x14] - MOV ECX, TaskFuncPtr - CALL EDX - } - break; - // Do nothing (was debug log) - case 4: - _asm { - MOV EDI, TaskFuncPtr - MOV EAX, [EDI] - MOV EDX, [EAX+0x18] - MOV ECX, TaskFuncPtr - CALL EDX - } - break; - // Force Render (caused by watchdog timeout) - case 5: - _asm { - MOV EDI, TaskFuncPtr - MOV EAX, [EDI] - MOV EDX, [EAX+0x1C] - MOV ECX, TaskFuncPtr - CALL EDX - } - break; - default: - break; - } - - // If rendering was performed, update animation step-time - if((taskFunc == 2) || (taskFunc == 5)) { - // FPS regulation - float maxFPS = (float)Settings::get().getCurrentFPSLimit(); - float minFPS = 10.0f; - float currentTime = getElapsedTime(); - float deltaTime = currentTime - lastTime; - - // Update step-time - updateAnimationStepTime((float)deltaTime, minFPS, maxFPS); - - lastTime = currentTime; - } - - // Task cleanup - _asm { - MOV ESI, task - PUSH ESI - MOV ECX, HighGraphics - CALL pCleanTaskF - } - - } while (run); -} - -// Render Entry -//---------------------------------------------------------------------------------------- -__declspec(naked) void renderLoopEntry(void) { -#define LOCALOFFSET __LOCAL_SIZE - // Prologue - _asm { - // Create Stack frame - PUSH EBX - PUSH EBP - MOV EBP, ESP - SUB ESP, LOCALOFFSET - // Retrieve stack parameters - MOV EBX, [EBP+0x0C] - PUSH ESI - PUSH EDI - // Store parameters to globals - MOV HighGraphics, EBX //HighGraphics: EBP - MOV TaskFuncPtr, ECX //Pointer to functions structure: EDI +void _stdcall updateFramerate(unsigned int cmd) { + // If rendering was performed, update animation step-time + if((cmd == 2) || (cmd == 5)) { + // FPS regulation based on previous render + float maxFPS = (float)Settings::get().getCurrentFPSLimit(); + float minFPS = 10.0f; + float currentTime = getElapsedTime(); + float deltaTime = currentTime - lastRenderTime; + lastRenderTime = currentTime; + + // Update step-time + updateAnimationStepTime((float)deltaTime, minFPS, maxFPS); } +} - // Start Recorder Process - renderLoop(); - - // Epilogue +// Hook +__declspec(naked) void getDrawThreadMsgCommand(void) { __asm { - POP EDI - POP ESI - MOV ESP, EBP - POP EBP - POP EBX - RETN 4 + MOV EAX, [ECX+0Ch] // Put msgCmd in EAX (Return value) + PUSHAD + PUSH EAX + CALL updateFramerate // Call updateFramerate(msgCmd) + POPAD + RETN } } +//---------------------------------------------------------------------------------------- +// Game Patches +//---------------------------------------------------------------------------------------- void applyFPSPatch() { enableGFWLCompatibility(); @@ -296,19 +169,24 @@ void applyFPSPatch() { if(exeHandle != NULL) imageBase = (DWORD)exeHandle; - // Patches + // Init counter for frame-rate calculations + lastRenderTime = 0.0f; + QueryPerformanceFrequency(&timerFreq); + QueryPerformanceCounter(&counterAtStart); + + // Binary patches //-------------------------------------------------------------- DWORD address; DWORD data; // Override D3D Presentation Interval - address = convertAddress(0x010275AE); + address = convertAddress(ADDR_PRESINT); data = 5; //Set to immediate writeToAddress(&data, address, sizeof(data)); - // Detour Render loop entry - address = convertAddress(0x00BD6000); - DetourApply((BYTE*)address, (BYTE*)renderLoopEntry, 6, 0); + // Detour call to getDrawThreadMsgCommand + address = convertAddress(ADDR_GETCMD); + DetourApply((BYTE*)address, (BYTE*)getDrawThreadMsgCommand, 5, CALLOP); SDLOG(0, "FPS rate unlocked\n"); } diff --git a/RenderstateManager.cpp b/RenderstateManager.cpp index f2ded4e..29bb9d8 100644 --- a/RenderstateManager.cpp +++ b/RenderstateManager.cpp @@ -311,7 +311,8 @@ HRESULT RSManager::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSur D3DSURFACE_DESC desc; oldRenderTarget->GetDesc(&desc); if(desc.Width == Settings::get().getRenderWidth() && desc.Height == Settings::get().getRenderHeight()) { - if(takeScreenshot) { + // screenshots + if(takeScreenshot && rddp >= 6) { takeScreenshot = false; SDLOG(0, "Capturing screenshot\n"); char timebuf[128], buffer[512]; @@ -323,46 +324,6 @@ HRESULT RSManager::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSur sprintf(buffer, "%s\\%s", Settings::get().getScreenshotDir().c_str(), timebuf); SDLOG(0, " - to %s\n", buffer); D3DXSaveSurfaceToFile(buffer, D3DXIFF_BMP, oldRenderTarget, NULL, NULL); - - // dump identified zsurf - //strftime(timebuf, 128, "zsurf_%Y-%m-%d_%H-%M-%S.tga", timeinfo); - //D3DXSaveSurfaceToFile(timebuf, D3DXIFF_TGA, zSurf, NULL, NULL); - - // calculate metrics on z surf - //D3DSURFACE_DESC desc; - //zSurf->GetDesc(&desc); - //SDLOG(0, "ZSURF format: %s", D3DUtil_D3DFormatToString(desc.Format)); - //IDirect3DSurface9* offSurf; - //d3ddev->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &offSurf, NULL); - //d3ddev->GetRenderTargetData(zSurf, offSurf); - //D3DLOCKED_RECT lockedRect; - //offSurf->LockRect(&lockedRect, NULL, D3DLOCK_READONLY); - //UINT16 mindepth = UINT16_MAX, maxdepth = 0; - //for(size_t y=0; y < desc.Height; ++y) { - // UCHAR *row = (UCHAR*)(lockedRect.pBits) + lockedRect.Pitch*y; - // for(size_t x=0; x < desc.Width; ++x) { - // // ARGB, R has high bits, G has low - // UINT16 depth = *(UINT16*)(row + x*4+1); - // if(depthmaxdepth) maxdepth = depth; - // SDLOG(0, "%6u, ", depth); - // } - // SDLOG(0,"\n"); - //} - //SDLOG(0, "ZSURF depth: %u - %u", mindepth, maxdepth); - //offSurf->UnlockRect(); - //offSurf->Release(); - - // dump textures used in final rendering step - //strftime(timebuf, 128, "%Y-%m-%d_%H-%M-%S", timeinfo); - //for(size_t i=0; i<4; ++i) { - // char namebuf[128]; - // IDirect3DBaseTexture9* tex; - // d3ddev->GetTexture(i, &tex); - // sprintf(namebuf, "tex%u_%s.tga", i, timebuf); - // D3DXSaveTextureToFile(namebuf, D3DXIFF_TGA, tex, NULL); - // tex->Release(); - //} } // HUD stuff if(hud && doHud && rddp == 9) { diff --git a/Settings.cpp b/Settings.cpp index 71b332d..7c6772a 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -30,6 +30,9 @@ void Settings::load() { if(getBackupInterval() < 600) { BackupInterval = 600; } + + if(getPresentWidth() == 0) PresentWidth = getRenderWidth(); + if(getPresentHeight() == 0) PresentHeight = getRenderHeight(); if(getOverrideLanguage().length() >= 2 && getOverrideLanguage().find("none") != 0) { performLanguageOverride(); diff --git a/Settings.def b/Settings.def index 47d522f..fd00578 100644 --- a/Settings.def +++ b/Settings.def @@ -63,8 +63,8 @@ SETTING(float, HudBottomRightOpacity, "hudBottomRightOpacity", 1.0f) SETTING(bool, BorderlessFullscreen, "borderlessFullscreen", false); SETTING(bool, ForceFullscreen, "forceFullscreen", false); SETTING(bool, ForceWindowed, "forceWindowed", false); -SETTING(unsigned, PresentWidth, "presentWidth", 1280); -SETTING(unsigned, PresentHeight, "presentHeight", 720); +SETTING(unsigned, PresentWidth, "presentWidth", 0); +SETTING(unsigned, PresentHeight, "presentHeight", 0); SETTING(bool, EnableVsync, "enableVsync", true); SETTING(unsigned, FullscreenHz, "fullscreenHz", 60); SETTING(int, D3DAdapterOverride, "d3dAdapterOverride", -1); diff --git a/d3d9dev.cpp b/d3d9dev.cpp index dc68308..406a6e0 100644 --- a/d3d9dev.cpp +++ b/d3d9dev.cpp @@ -32,13 +32,39 @@ HRESULT APIENTRY hkIDirect3DDevice9::Present(CONST RECT *pSourceRect, CONST RECT } HRESULT APIENTRY hkIDirect3DDevice9::SetVertexShaderConstantF(UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount) { - SDLOG(7, "SetVertexShaderConstantF: start: %u, count: %u\n", StartRegister, Vector4fCount); - if(Settings::get().getLogLevel() > 13) { - for(size_t i=0; iSetVertexShaderConstantF(StartRegister,pConstantData,Vector4fCount); + //static float replacement[128*8]; + //SDLOG(0, "SetVertexShaderConstantF: start: %u, count: %u\n", StartRegister, Vector4fCount); + //if(Settings::get().getLogLevel() > 13 || Vector4fCount == 8 || Vector4fCount == 4) { + // for(size_t i=0; iSetVertexShaderConstantF(StartRegister, replacement, Vector4fCount); + // } + //} /*else if(StartRegister == 8 && Vector4fCount == 4) { + // SDLOG(0, "!!4ball\n"); + // return m_pD3Ddev->SetVertexShaderConstantF(StartRegister, replacement, Vector4fCount); + //}*/ + return m_pD3Ddev->SetVertexShaderConstantF(StartRegister, pConstantData, Vector4fCount); } HRESULT APIENTRY hkIDirect3DDevice9::SetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) { @@ -217,8 +243,8 @@ HRESULT APIENTRY hkIDirect3DDevice9::CreateTexture(UINT Width, UINT Height, UINT // return m_pD3Ddev->CreateTexture(Width*2, Height*2, Levels, Usage, Format, Pool, ppTexture, pSharedHandle); //} if(Width == 1280 && Height == 720) { - SDLOG(1, " - OVERRIDE to %4u/%4u!\n", Settings::get().getRenderWidth(), Settings::get().getRenderHeight()); - return m_pD3Ddev->CreateTexture(Settings::get().getRenderWidth(), Settings::get().getRenderHeight(), Levels, Usage, Format, Pool, ppTexture, pSharedHandle); + SDLOG(1, " - OVERRIDE to %4u/%4u!\n", Settings::get().getPresentWidth(), Settings::get().getPresentHeight()); + return m_pD3Ddev->CreateTexture(Settings::get().getPresentWidth(), Settings::get().getPresentHeight(), Levels, Usage, Format, Pool, ppTexture, pSharedHandle); } HRESULT res = m_pD3Ddev->CreateTexture(Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle); //RSManager::get().registerTexture(*ppTexture); diff --git a/main.h b/main.h index 732e8c4..d3b9ea1 100644 --- a/main.h +++ b/main.h @@ -18,7 +18,7 @@ #pragma once -#define VERSION "1.9" +#define VERSION "2.0.1" #define RELEASE_VER