Skip to content

Commit

Permalink
Prerelease version 4
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterTh committed Jan 17, 2014
1 parent 702e3f2 commit 2b96e95
Show file tree
Hide file tree
Showing 24 changed files with 178 additions and 60 deletions.
2 changes: 2 additions & 0 deletions Actions.def
Expand Up @@ -23,6 +23,8 @@ ACTION(setBicubicScaling, RSManager::get().getScaler()->setScaling(Scaler::BICUB

ACTION(showStatus, RSManager::get().getScaler()->showStatus())

ACTION(dumpFrame, RSManager::get().dumpFrame())

ACTION(reloadAAEffect, RSManager::get().reloadAA())

ACTION(userTrigger, SDLOG(0, "================================================================= USER TRIGGER ===\n"))
5 changes: 1 addition & 4 deletions Console.cpp
Expand Up @@ -111,10 +111,7 @@ void Console::draw() {
else lineHeight = y + 15.0f;
}

void Console::print(float x, float y, const char *text) {
// assume orthographic projection with units = screen pixels, origin at top left
//float wF = 1.0f/Console::get().getW(), hF = 1.0f/Console::get().getH();

void Console::print(float x, float y, const char *text) {
unsigned passes;
effect->SetTexture(textTex2DHandle, fontTex);
effect->Begin(&passes, 0);
Expand Down
30 changes: 26 additions & 4 deletions Detouring.cpp
Expand Up @@ -4,13 +4,14 @@
#include <atlbase.h>
#include <atlconv.h>
#include <mmsystem.h>
#include <Psapi.h>

#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

#include <MinHook.h>

#include <boost/algorithm/string/case_conv.hpp>
#include "string_utils.h"

#include "Settings.h"
#include "RenderstateManager.h"
Expand Down Expand Up @@ -347,10 +348,31 @@ GENERATE_INTERCEPT_HEADER(SetWindowPos, BOOL, WINAPI, _In_ HWND hWnd, _In_opt_ H
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual detouring /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

HMODULE findDll(const string& name) {
if(name.find("*") != name.npos) {
SDLOG(16, "Dll pattern search...\n");
HMODULE modules[1024];
DWORD needed;
if(EnumProcessModules(GetCurrentProcess(), modules, 1024*sizeof(HMODULE), &needed)) {
for(unsigned i=0; i < (needed / sizeof(HMODULE)); i++) {
TCHAR modname[MAX_PATH];
if(GetModuleFileNameEx(GetCurrentProcess(), modules[i], modname, sizeof(modname)/sizeof(TCHAR))) {
SDLOG(16, " - checking against module %s\n", modname);
if(matchWildcard(modname, name)) {
SDLOG(1, "Found dll matching pattern %s in %s\n", name.c_str(), modname);
return modules[i];
}
}
}
}
}
return GetModuleHandle(name.c_str());
}

void hookFunction(const char* name, const char* dllname, void **ppTarget, void* const pDetour, void** ppOriginal, bool& flag) {
if(!flag) {
SDLOG(1, "Trying to hook %s in %s\n", name, dllname);
HMODULE dllhandle = GetModuleHandle(dllname);
SDLOG(6, "Trying to hook %s in %s\n", name, dllname);
HMODULE dllhandle = findDll(dllname);
if(dllhandle) {
*ppTarget = GetProcAddress(dllhandle, name);
MH_STATUS ret = MH_CreateHook(*ppTarget, pDetour, ppOriginal); \
Expand All @@ -362,7 +384,7 @@ void hookFunction(const char* name, const char* dllname, void **ppTarget, void*
flag = true;
} \
else { SDLOG(0, " -> ERROR enabling hook for %s\n", name); } \
} else SDLOG(1, " -> DLL not loaded!\n")
} else SDLOG(6, " -> DLL not found!\n")
}
}

Expand Down
Binary file modified GeDoSaTo.v11.suo
Binary file not shown.
6 changes: 4 additions & 2 deletions GeDoSaTo.vcxproj
Expand Up @@ -84,11 +84,11 @@
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">d3d9</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LibraryPath>C:\dev\minhook\lib;C:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Lib\x86;$(LibraryPath)</LibraryPath>
<LibraryPath>C:\dev\boost\stage\lib;C:\dev\minhook\lib;C:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>C:\dev\minhook\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\dev\minhook\lib;C:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Lib\x86;$(LibraryPath)</LibraryPath>
<LibraryPath>C:\dev\boost\stage\lib;C:\dev\minhook\lib;C:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand Down Expand Up @@ -320,6 +320,7 @@
<ClCompile Include="Settings.cpp" />
<ClCompile Include="SMAA.cpp" />
<ClCompile Include="SSAO.cpp" />
<ClCompile Include="string_utils.cpp" />
<ClCompile Include="Timer.cpp" />
<ClCompile Include="version.cpp" />
<ClCompile Include="WindowManager.cpp" />
Expand All @@ -342,6 +343,7 @@
<ClInclude Include="KeyActions.h" />
<ClInclude Include="SearchTex.h" />
<ClInclude Include="SMAA.h" />
<ClInclude Include="string_utils.h" />
<ClInclude Include="Textures.def" />
<ClInclude Include="RenderstateManager.h" />
<ClInclude Include="main.h" />
Expand Down
3 changes: 3 additions & 0 deletions Hooks.def
Expand Up @@ -7,6 +7,9 @@ HOOK(LoadLibraryExW, "Kernel32.dll")
HOOK(Direct3DCreate9, "D3d9.dll")
HOOK(Direct3DCreate9Ex, "D3d9.dll")

HOOK(D3DXCreateTextureFromFileInMemory, "d3dx9_*.dll")
HOOK(D3DXCreateTextureFromFileInMemoryEx, "d3dx9_*.dll")

HOOK(EnumDisplaySettingsExA, "User32.dll")
HOOK(EnumDisplaySettingsExW, "User32.dll")

Expand Down
46 changes: 26 additions & 20 deletions RenderstateManager.cpp
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <string>

#include <boost/filesystem.hpp>

#include "d3dutil.h"
#include "d3d9dev_ex.h"
#include "Settings.h"
Expand Down Expand Up @@ -258,9 +260,14 @@ void RSManager::registerD3DXCreateTextureFromFileInMemory(LPCVOID pSrcData, UINT
IDirect3DSurface9* surf;
((IDirect3DTexture9*)pTexture)->GetSurfaceLevel(0, &surf);
string directory = getInstalledFileName(format("textures\\%s\\dump\\", getExeFileName().c_str()));
CreateDirectory(directory.c_str(), NULL);
D3DXSaveSurfaceToFile(format("%s%08x.tga", directory.c_str(), hash).c_str(), D3DXIFF_TGA, surf, NULL, NULL);
surf->Release();
SDLOG(0, "%s\n", boost::filesystem::path(directory).string().c_str())
try {
boost::filesystem::create_directories(boost::filesystem::path(directory));
D3DXSaveSurfaceToFile(format("%s%08x.tga", directory.c_str(), hash).c_str(), D3DXIFF_TGA, surf, NULL, NULL);
} catch(boost::filesystem::filesystem_error e) {
SDLOG(0, "ERROR - Filesystem error while trying to create directory:\n%s\n", e.what());
}
SAFERELEASE(surf);
}
registerKnowTexture(pSrcData, SrcDataSize, pTexture);
}
Expand Down Expand Up @@ -344,23 +351,22 @@ const char* RSManager::getTextureName(IDirect3DBaseTexture9* pTexture) {
}

HRESULT RSManager::redirectD3DXCreateTextureFromFileInMemoryEx(LPDIRECT3DDEVICE9 pDevice, LPCVOID pSrcData, UINT SrcDataSize, UINT Width, UINT Height, UINT MipLevels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, DWORD Filter, DWORD MipFilter, D3DCOLOR ColorKey, D3DXIMAGE_INFO* pSrcInfo, PALETTEENTRY* pPalette, LPDIRECT3DTEXTURE9* ppTexture) {
//if(Settings::get().getEnableTextureOverride()) {
// UINT ssize = (SrcDataSize == 2147483647u) ? (Width*Height/2) : SrcDataSize;
// UINT32 hash = SuperFastHash((char*)const_cast<void*>(pSrcData), ssize);
// SDLOG(4, "Trying texture override size: %8u, hash: %8x\n", ssize, hash);
//
// char buffer[128];
// sprintf_s(buffer, "dpfix/tex_override/%08x.dds", hash);
// if(fileExists(buffer)) {
// SDLOG(3, "Texture override (dds)! hash: %8x\n", hash);
// return D3DXCreateTextureFromFileEx(pDevice, buffer, D3DX_DEFAULT, D3DX_DEFAULT, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture);
// }
// sprintf_s(buffer, "dpfix/tex_override/%08x.png", hash);
// if(fileExists(buffer)) {
// SDLOG(3, "Texture override (png)! hash: %8x\n", hash);
// return D3DXCreateTextureFromFileEx(pDevice, buffer, D3DX_DEFAULT, D3DX_DEFAULT, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture);
// }
//}
if(Settings::get().getEnableTextureOverride()) {
UINT ssize = (SrcDataSize == 2147483647u) ? (Width*Height/2) : SrcDataSize;
UINT32 hash = SuperFastHash((char*)const_cast<void*>(pSrcData), ssize);
SDLOG(4, "Trying texture override size: %8u, hash: %8x\n", ssize, hash);

string fn = getInstalledFileName(format("textures\\%s\\override\\%08x.dds", getExeFileName().c_str(), hash));
if(fileExists(fn.c_str())) {
SDLOG(3, "Texture override (dds)! hash: %8x\n", hash);
return D3DXCreateTextureFromFileEx(pDevice, fn.c_str(), D3DX_DEFAULT, D3DX_DEFAULT, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture);
}
fn = getInstalledFileName(format("textures\\%s\\override\\%08x.png", getExeFileName().c_str(), hash));
if(fileExists(fn.c_str())) {
SDLOG(3, "Texture override (png)! hash: %8x\n", hash);
return D3DXCreateTextureFromFileEx(pDevice, fn.c_str(), D3DX_DEFAULT, D3DX_DEFAULT, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture);
}
}
return TrueD3DXCreateTextureFromFileInMemoryEx(pDevice, pSrcData, SrcDataSize, Width, Height, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture);
}

Expand Down
9 changes: 6 additions & 3 deletions Settings.def
Expand Up @@ -15,15 +15,18 @@ SETTING(unsigned, OverrideHeight, "overrideHeight", 720);

SETTING(std::string, ScalingType, "scalingType", "linear");

SETTING(bool, EmulateFlipBehaviour, "emulateFlipBehaviour", true);

// Texture options
SETTING(bool, EnableTextureDumping, "enableTextureDumping", false);
SETTING(bool, EnableTextureOverride, "enableTextureOverride", false);

// Mouse options
SETTING(bool, ModifyGetCursorPos, "modifyGetCursorPos", true);
SETTING(bool, AdjustMessagePt, "adjustMessagePt", true);

// Logging Options
SETTING(int, LogLevel, "logLevel", 0);

// Wrapper chaining options
SETTING(std::string, Dinput8dllWrapper, "dinput8dllWrapper", "");

// Folder options
SETTING(std::string, ScreenshotDir, "screenshotDir", ".");
4 changes: 2 additions & 2 deletions blacklist.cpp
@@ -1,19 +1,19 @@
#include "blacklist.h"

#include "main.h"
#include "string_utils.h"

#include <fstream>
using namespace std;

#include <boost/algorithm/string.hpp>

bool onBlacklist(std::string fn) {
std::ifstream infile(getAssetFileName("blacklist.txt"));
string line;
boost::algorithm::trim(fn);
while(std::getline(infile, line)) {
boost::algorithm::trim(line);
if(boost::iequals(fn, line)) return true;
if(matchWildcard(fn, line)) return true;
}
return false;
}
7 changes: 5 additions & 2 deletions d3d9dev.cpp
Expand Up @@ -124,11 +124,13 @@ HRESULT APIENTRY hkIDirect3DDevice9::BeginStateBlock() {

HRESULT APIENTRY hkIDirect3DDevice9::Clear(DWORD Count, CONST D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
RSManager::setLatest(rsMan);
SDLOG(4, "Clear");
return m_pD3Ddev->Clear(Count, pRects, Flags, Color, Z, Stencil);
}

HRESULT APIENTRY hkIDirect3DDevice9::ColorFill(IDirect3DSurface9* pSurface,CONST RECT* pRect, D3DCOLOR color) {
RSManager::setLatest(rsMan);
SDLOG(6, "ColorFill");
return m_pD3Ddev->ColorFill(pSurface,pRect,color);
}

Expand Down Expand Up @@ -525,6 +527,7 @@ HRESULT APIENTRY hkIDirect3DDevice9::SetFVF(DWORD FVF) {

void APIENTRY hkIDirect3DDevice9::SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp) {
RSManager::setLatest(rsMan);
SDLOG(3, "SetGammaRamp\n");
m_pD3Ddev->SetGammaRamp(iSwapChain,Flags, pRamp);
}

Expand Down Expand Up @@ -616,13 +619,13 @@ HRESULT APIENTRY hkIDirect3DDevice9::SetSoftwareVertexProcessing(BOOL bSoftware)

HRESULT APIENTRY hkIDirect3DDevice9::SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride) {
RSManager::setLatest(rsMan);
SDLOG(4, "SetStreamSource %d: %p (%u, %u)\n", StreamNumber, pStreamData, OffsetInBytes, Stride);
SDLOG(8, "SetStreamSource %d: %p (%u, %u)\n", StreamNumber, pStreamData, OffsetInBytes, Stride);
return m_pD3Ddev->SetStreamSource(StreamNumber, pStreamData,OffsetInBytes, Stride);
}

HRESULT APIENTRY hkIDirect3DDevice9::SetStreamSourceFreq(UINT StreamNumber,UINT Divider) {
RSManager::setLatest(rsMan);
SDLOG(4, "SetStreamSourceFreq %d: %u\n", StreamNumber, Divider);
SDLOG(8, "SetStreamSourceFreq %d: %u\n", StreamNumber, Divider);
return m_pD3Ddev->SetStreamSourceFreq(StreamNumber, Divider);
}

Expand Down
24 changes: 24 additions & 0 deletions d3dutil.cpp
Expand Up @@ -190,6 +190,17 @@ TCHAR* D3DMultisampleTypeToString(D3DMULTISAMPLE_TYPE type) {
return "Unknown D3D multisample type";
}

TCHAR* D3DSwapEffectToString(D3DSWAPEFFECT swap) {
switch(swap) {
case D3DSWAPEFFECT_DISCARD: return "D3DSWAPEFFECT_DISCARD";
case D3DSWAPEFFECT_FLIP: return "D3DSWAPEFFECT_FLIP";
case D3DSWAPEFFECT_COPY: return "D3DSWAPEFFECT_COPY";
case D3DSWAPEFFECT_OVERLAY: return "D3DSWAPEFFECT_OVERLAY";
case D3DSWAPEFFECT_FLIPEX: return "D3DSWAPEFFECT_FLIPEX";
}
return "Unknown swap effect";
}

string D3DMatrixToString(const D3DMATRIX* pMatrix) {
std::stringstream ss;
if(!pMatrix) return string("NULL_MATRIX");
Expand All @@ -202,3 +213,16 @@ string D3DMatrixToString(const D3DMATRIX* pMatrix) {
}
return ss.str();
}

string D3DPresentExFlagsToString(DWORD flags) {
string ret;
if(flags & D3DPRESENT_DONOTFLIP) ret += "D3DPRESENT_DONOTFLIP | ";
if(flags & D3DPRESENT_DONOTWAIT) ret += "D3DPRESENT_DONOTWAIT | ";
if(flags & D3DPRESENT_FORCEIMMEDIATE) ret += "D3DPRESENT_FORCEIMMEDIATE | ";
if(flags & D3DPRESENT_LINEAR_CONTENT) ret += "D3DPRESENT_LINEAR_CONTENT | ";
if(flags & D3DPRESENT_VIDEO_RESTRICT_TO_MONITOR) ret += "D3DPRESENT_VIDEO_RESTRICT_TO_MONITOR | ";
if(flags & D3DPRESENT_UPDATEOVERLAYONLY) ret += "D3DPRESENT_UPDATEOVERLAYONLY | ";
if(flags & D3DPRESENT_HIDEOVERLAY) ret += "D3DPRESENT_HIDEOVERLAY | ";
if(flags & D3DPRESENT_UPDATECOLORKEY) ret += "D3DPRESENT_UPDATECOLORKEY | ";
return ret;
}
2 changes: 2 additions & 0 deletions d3dutil.h
Expand Up @@ -11,5 +11,7 @@ TCHAR* D3DDeclUsageToString(D3DDECLUSAGE type);
TCHAR* D3DDevTypeToString(D3DDEVTYPE type);
TCHAR* D3DResourceTypeToString(D3DRESOURCETYPE type);
TCHAR* D3DMultisampleTypeToString(D3DMULTISAMPLE_TYPE type);
TCHAR* D3DSwapEffectToString(D3DSWAPEFFECT swap);

string D3DMatrixToString(const D3DMATRIX* pMatrix);
string D3DPresentExFlagsToString(DWORD flags);
30 changes: 18 additions & 12 deletions main.cpp
Expand Up @@ -27,7 +27,7 @@ FILE* g_oFile = NULL;
bool g_active = false;

LRESULT CALLBACK GeDoSaToHook(_In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM lParam) {
SDLOG(16, "GeDoSaToHook called\n");
SDLOG(18, "GeDoSaToHook called\n");
return CallNextHookEx(NULL, nCode, wParam, lParam);
}

Expand All @@ -39,24 +39,30 @@ const char* GeDoSaToVersion() {

BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved) {
if(dwReason == DLL_PROCESS_ATTACH) {
OutputDebugString("GeDoSaTo: startup");

// read install location from registry
getInstallDirectory();
OutputDebugString("GeDoSaTo: Got install dir");

// don't attach to processes on the blacklist
if(onBlacklist(getExeFileName())) {
OutputDebugString("GeDoSaTo: Blacklisted");
if(getExeFileName() == "GeDoSaToTool") return true;
return false;
}
g_active = true;

// read install location from registry
getInstallDirectory();
OutputDebugString("GeDoSaTo: Active");

// initialize log
// initialize log
string logFn = format("logs\\%s_%s.log", getExeFileName().c_str(), getTimeString().c_str());
boost::replace_all(logFn, ":", "-");
boost::replace_all(logFn, " ", "_");
std::replace(logFn.begin(), logFn.end(), ':', '-');
std::replace(logFn.begin(), logFn.end(), ' ', '_');
logFn = getInstalledFileName(logFn);
fopen_s(&g_oFile, logFn.c_str(), "w");
if(!g_oFile) OutputDebugString(format("GeDoSaTo: Error opening log fn %s", logFn.c_str()).c_str());
else OutputDebugString(format("GeDoSaTo: Opening log fn %s, handle: %p", logFn.c_str(), g_oFile).c_str());
OutputDebugString("GeDoSaTo: Log file initialized, let that take over");

// startup
sdlogtime(-1);
Expand Down Expand Up @@ -96,9 +102,9 @@ const std::string& getInstallDirectory() {
const string& getExeFileName() {
static string exeFn;
if(exeFn.empty()) {
char fileName[2048];
GetModuleFileNameA(NULL, fileName, 2048);
exeFn = string(fileName);
char fileName[MAX_PATH];
GetModuleFileNameA(NULL, fileName, MAX_PATH);
exeFn = fileName;
size_t pos = exeFn.rfind("\\");
if(pos != string::npos) {
exeFn = exeFn.substr(pos+1);
Expand Down Expand Up @@ -179,10 +185,10 @@ void messageErrorAndExit(string error) {
#include <stdarg.h>

string format(const char* formatString, ...) {
va_list arglist;
va_start(arglist, formatString);
const unsigned BUFFER_SIZE = 2048*8;
char buffer[BUFFER_SIZE];
va_list arglist;
va_start(arglist, formatString);
vsnprintf_s(buffer, BUFFER_SIZE, formatString, arglist);
va_end(arglist);
return string(buffer);
Expand Down

0 comments on commit 2b96e95

Please sign in to comment.