From 783429a287e23ea14d1e678e8c51c4c01e1b80f7 Mon Sep 17 00:00:00 2001 From: Piotr Halama Date: Wed, 18 Nov 2020 22:21:05 +0100 Subject: [PATCH] Initial commit Added basic version of skScreen --- .gitignore | 363 +++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 9 + CMakeSettings.json | 28 +++ skScreen/CMakeLists.txt | 16 ++ skScreen/GameConfig.hpp | 28 +++ skScreen/binaryFix.cpp | 96 +++++++++++ skScreen/binaryFix.hpp | 28 +++ skScreen/common.cpp | 26 +++ skScreen/common.hpp | 10 ++ skScreen/gameConfig.cpp | 54 ++++++ skScreen/gameVersion.cpp | 147 ++++++++++++++++ skScreen/gameVersion.hpp | 34 ++++ skScreen/init.cpp | 49 ++++++ skScreen/init.hpp | 12 ++ skScreen/skScreen.cpp | 32 ++++ 15 files changed, 932 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 CMakeSettings.json create mode 100644 skScreen/CMakeLists.txt create mode 100644 skScreen/GameConfig.hpp create mode 100644 skScreen/binaryFix.cpp create mode 100644 skScreen/binaryFix.hpp create mode 100644 skScreen/common.cpp create mode 100644 skScreen/common.hpp create mode 100644 skScreen/gameConfig.cpp create mode 100644 skScreen/gameVersion.cpp create mode 100644 skScreen/gameVersion.hpp create mode 100644 skScreen/init.cpp create mode 100644 skScreen/init.hpp create mode 100644 skScreen/skScreen.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f5429ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ +[Oo]ut/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..edc3f66 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +# CMakeList.txt : Top-level CMake project file, do global configuration +# and include sub-projects here. +# +cmake_minimum_required (VERSION 3.8) + +project ("StuntKit_modules") + +# Include sub-projects. +add_subdirectory ("skScreen") diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 0000000..a54a82d --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,28 @@ +{ + "configurations": [ + { + "name": "x86-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x86" ], + "variables": [] + }, + { + "name": "x86-Release", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x86" ], + "variables": [] + } + ] +} \ No newline at end of file diff --git a/skScreen/CMakeLists.txt b/skScreen/CMakeLists.txt new file mode 100644 index 0000000..f38b1e8 --- /dev/null +++ b/skScreen/CMakeLists.txt @@ -0,0 +1,16 @@ +# CMakeList.txt : CMake project for StuntKit_modules, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.8) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Add source to this project's executable. +add_library (skScreen SHARED "skScreen.cpp" +"init.cpp" "init.hpp" +"binaryFix.cpp" "binaryFix.hpp" +"common.cpp" "common.hpp" +"gameConfig.cpp" "GameConfig.hpp" +"gameVersion.hpp" "gameVersion.cpp" +) + +# TODO: Add tests and install targets if needed. diff --git a/skScreen/GameConfig.hpp b/skScreen/GameConfig.hpp new file mode 100644 index 0000000..9337bd3 --- /dev/null +++ b/skScreen/GameConfig.hpp @@ -0,0 +1,28 @@ +#ifndef GAME_CONFIG_HPP +#define GAME_CONFIG_HPP + +#include +#include +#include +#include +#include + +#include + +class GameConfig { +public: + // TODO fallback to config.cfg? Probably not, as config.exe has limited list of resolutions + /** + * Reads config from game.cfg + */ + GameConfig(); + uint_least32_t getWidth(); + uint_least32_t getHeight(); + +private: + std::map configContainer; + //uint_least32_t width = 640; + //uint_least32_t height = 480; +}; + +#endif /* GAME_CONFIG_HPP*/ \ No newline at end of file diff --git a/skScreen/binaryFix.cpp b/skScreen/binaryFix.cpp new file mode 100644 index 0000000..cba7baa --- /dev/null +++ b/skScreen/binaryFix.cpp @@ -0,0 +1,96 @@ +#include "binaryFix.hpp" + +BinaryFix::BinaryFix(GameVersion gameVersion, GameConfig gameConfig) : gameConfig(gameConfig), gameVersion(gameVersion) +{ +} + +void BinaryFix::set3DRatio() +{ + uint32_t address = 0; + + // TODO remowrk to use getAPI and getRelease? But we do memory patching, so hash is the best option here for now + std::string hash = gameVersion.getGameHash(); + + //search for 1.332999945 + if (hash == "E4BAF3E5CACD51AFCE61007F72781167") { + // International DirectX + address = 0x403327; + } + else if (hash == "C5801F89E46C53A67AC8D7C18A94ACD8") { + // International Glide + address = 0x403327; + } + else if (hash == "CE9A034310D45EED6D6E2C1B6014376E") { + // Polish DirectX + address = 0x440b37; + } + else if (hash == "7D7EB6DFB099CF06FEF28F436CAE6E52") { + // Polish Glide + address = 0x43ef07; + } + + std::stringstream ss; + ss << "got hash: " << hash << " with res " << gameConfig.getWidth() << "x" << gameConfig.getHeight(); + OutputDebugString(ss.str().c_str()); + + if (!address) { + throw std::runtime_error("set3DRatio: unknown game version"); + } + float ratio = static_cast(gameConfig.getWidth())/ static_cast(gameConfig.getHeight()); + replaceMemory(address, ratio); + +} + +void BinaryFix::setUIRatio() +{ + uint32_t addressX = 0; + uint32_t addressY = 0; + + // TODO remowrk to use getAPI and getRelease? But we do memory patching, so hash is the best option here for now + std::string hash = gameVersion.getGameHash(); + if (hash == "E4BAF3E5CACD51AFCE61007F72781167") { + // International DirectX + addressX = 0x46E69C; + } + else if (hash == "C5801F89E46C53A67AC8D7C18A94ACD8") { + // International Glide + addressX = 0x46D754; + } + else if (hash == "CE9A034310D45EED6D6E2C1B6014376E") { + // Polish DirectX + addressX = 0x46f634; + } + else if (hash == "7D7EB6DFB099CF06FEF28F436CAE6E52") { + // Polish Glide + addressX = 0x46D6EC; + } + + if (!addressX) { + throw std::runtime_error("set3DRatio: unknown game version"); + } + + addressY = addressX - 4; + float ratio43 = 4.0f / 3.0f; + float ratioWanted = static_cast(gameConfig.getWidth()) / static_cast(gameConfig.getHeight()); + // TODO rework if the screen is higher than wider + if (ratio43 < ratioWanted) + { + float ratio = ratio43 / ratioWanted * 0.0015625f; // 0.0015625 is magic + replaceMemory(addressX, ratio); + } + else + { + float ratio = ratioWanted /ratio43 * 0.0020833334f; // 0.0020833334 is magic + replaceMemory(addressY, ratio); + } +} + +void BinaryFix::removeResolutionLimit() +{ + +} + +void BinaryFix::fixRadeon() +{ + +} diff --git a/skScreen/binaryFix.hpp b/skScreen/binaryFix.hpp new file mode 100644 index 0000000..c781e81 --- /dev/null +++ b/skScreen/binaryFix.hpp @@ -0,0 +1,28 @@ +#ifndef BINARY_FIX_HPP +#define BINARY_FIX_HPP + +#include +#include + +#include "common.hpp" +#include "gameVersion.hpp" +#include "gameConfig.hpp" + +class BinaryFix { +public: + BinaryFix(GameVersion gameVersion, GameConfig gameConfig); + + void set3DRatio(); + void setUIRatio(); + + void removeResolutionLimit(); + void fixRadeon(); + +private: + GameVersion gameVersion; + GameConfig gameConfig; +}; + + + +#endif /*BINARY_FIX_HPP*/ \ No newline at end of file diff --git a/skScreen/common.cpp b/skScreen/common.cpp new file mode 100644 index 0000000..86baf74 --- /dev/null +++ b/skScreen/common.cpp @@ -0,0 +1,26 @@ +#include "common.hpp" + +void replaceMemory(DWORD address, const char data[], uint32_t length) +{ + DWORD flOldProtect; + if (VirtualProtect((PVOID)address, length, PAGE_EXECUTE_READWRITE, &flOldProtect)) + { + memcpy((PVOID)address, &data[0], length); + VirtualProtect((PVOID)address, length, flOldProtect, &flOldProtect); + } +} + + +void replaceMemory(DWORD address, float number) +{ + char data[4]; + memcpy(data, &number, 4); + replaceMemory(address, data, 4); +} + +void replaceMemory(DWORD address, uint32_t number) +{ + char data[4]; + memcpy(data, &number, 4); + replaceMemory(address, data, 4); +} \ No newline at end of file diff --git a/skScreen/common.hpp b/skScreen/common.hpp new file mode 100644 index 0000000..5105783 --- /dev/null +++ b/skScreen/common.hpp @@ -0,0 +1,10 @@ +#include +#include +#include +// #include + + +void replaceMemory(DWORD address, const char data[], uint32_t length); + +void replaceMemory(DWORD address, float number); +void replaceMemory(DWORD address, uint32_t number); \ No newline at end of file diff --git a/skScreen/gameConfig.cpp b/skScreen/gameConfig.cpp new file mode 100644 index 0000000..1046f21 --- /dev/null +++ b/skScreen/gameConfig.cpp @@ -0,0 +1,54 @@ +#include "GameConfig.hpp" + +GameConfig::GameConfig() +{ + std::ifstream gameCfg("game.cfg", std::fstream::in); + std::string line; + while (std::getline(gameCfg, line)) + { + + // TODO this is very naive tokenization, should work OK for Stunt GP config fiels though + // TODO maybe refactor this and use this kind of files for each module config instead of ini? + size_t delimiter = line.find("="); + if (delimiter != std::string::npos) + { + std::stringstream ss(line); + std::string key; + std::string equalSign; + std::string value; + + + + ss >> key >> equalSign >> value; + + std::stringstream ss2; + ss2 << key << equalSign << value; + OutputDebugString(ss.str().c_str()); + + configContainer.insert({ key, value }); + } + + } +} + +uint_least32_t GameConfig::getWidth() +{ + auto it = configContainer.find("DISPLAYRESWIDTH"); + if (it != configContainer.end()) { + // TODO handle malformed config files + return std::stoi(it->second); + } + OutputDebugString("DISPLAYRESWIDTH not found! Using 640 instead"); + return 640; +} + +uint_least32_t GameConfig::getHeight() +{ + auto it = configContainer.find("DISPLAYRESHEIGHT"); + if (it != configContainer.end()) { + // TODO handle malformed config files + return std::stoi(it->second); + } + OutputDebugString("DISPLAYRESHEIGHT not found! Using 480 instead"); + return 480; +} \ No newline at end of file diff --git a/skScreen/gameVersion.cpp b/skScreen/gameVersion.cpp new file mode 100644 index 0000000..8141276 --- /dev/null +++ b/skScreen/gameVersion.cpp @@ -0,0 +1,147 @@ +#include "gameVersion.hpp" + +GameVersion::GameVersion() { + this->hash = calculateGameHash(); + + hash = getGameHash(); + if (hash == "E4BAF3E5CACD51AFCE61007F72781167") { + release = Release::International; + api = API::DirectX; + } + else if (hash == "C5801F89E46C53A67AC8D7C18A94ACD8") { + release = Release::International; + api = API::Glide; + } + else if (hash == "CE9A034310D45EED6D6E2C1B6014376E") { + release = Release::Polish; + api = API::DirectX; + } + else if (hash == "7D7EB6DFB099CF06FEF28F436CAE6E52") { + release = Release::Polish; + api = API::Glide; + } + +} + +const bool GameVersion::isKnownGameVersion() +{ + if (release == Release::Unknown || api == API::Unknown) + { + return false; + } + return true; +} + +const std::string GameVersion::getGameHash() { + return hash; +} + +const API GameVersion::getAPI() +{ + return api; +} + +const Release GameVersion::getRelease() +{ + return release; +} + +std::string GameVersion::calculateGameHash() +{ + std::string hash = ""; + + char SGPpath[MAX_PATH]; + + BOOL bResult = FALSE; + HCRYPTPROV hProv = 0; + HCRYPTHASH hHash = 0; + HANDLE hFile = NULL; + BYTE rgbFile[BUFSIZE]; + DWORD cbRead = 0; + BYTE rgbHash[MD5LEN]; + DWORD cbHash = 0; + CHAR rgbDigits[] = "0123456789ABCDEF"; + + GetModuleFileName(0, SGPpath, MAX_PATH); + hFile = CreateFile(SGPpath, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + + if (INVALID_HANDLE_VALUE == hFile) + { + OutputDebugString("Error opening SGP file"); + return hash; + } + + // Get handle to the crypto provider + if (!CryptAcquireContext(&hProv, + NULL, + NULL, + PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT)) + { + OutputDebugString("CryptAcquireContext failed"); + CloseHandle(hFile); + return hash; + } + + if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) + { + OutputDebugString("CryptAcquireContext failed"); + CloseHandle(hFile); + CryptReleaseContext(hProv, 0); + return hash; + } + + while (bResult = ReadFile(hFile, rgbFile, BUFSIZE, + &cbRead, NULL)) + { + if (0 == cbRead) + { + break; + } + + if (!CryptHashData(hHash, rgbFile, cbRead, 0)) + { + OutputDebugString("CryptHashData failed"); + CryptReleaseContext(hProv, 0); + CryptDestroyHash(hHash); + CloseHandle(hFile); + return hash; + } + } + + if (!bResult) + { + OutputDebugString("ReadFile failed"); + CryptReleaseContext(hProv, 0); + CryptDestroyHash(hHash); + CloseHandle(hFile); + return hash; + } + + cbHash = MD5LEN; + if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) + { + std::stringstream ss; + for (DWORD i = 0; i < cbHash; i++) + { + ss << rgbDigits[rgbHash[i] >> 4] << rgbDigits[rgbHash[i] & 0xf]; + } + hash = ss.str(); + } + else + { + OutputDebugString("CryptGetHashParam failed"); + } + + CryptDestroyHash(hHash); + CryptReleaseContext(hProv, 0); + CloseHandle(hFile); + + return hash; +} \ No newline at end of file diff --git a/skScreen/gameVersion.hpp b/skScreen/gameVersion.hpp new file mode 100644 index 0000000..398bad0 --- /dev/null +++ b/skScreen/gameVersion.hpp @@ -0,0 +1,34 @@ +#ifndef GAME_VERSION_HPP +#define GAME_VERSION_HPP + +#include +#include + +#include +#include + +// TODO maybe stroring these as strings would be better, especially for logging and error handling +enum class API { Unknown, DirectX, Glide }; +enum class Release { Unknown, International, Polish }; + +class GameVersion { +public: + GameVersion(); + const bool isKnownGameVersion(); + + const std::string getGameHash(); + const API getAPI(); + const Release getRelease(); + +private: + std::string calculateGameHash(); + std::string hash = ""; + API api = API::Unknown; + Release release = Release::Unknown; + + // TODO move all constants to another file? + static constexpr int BUFSIZE = 1024; + static constexpr int MD5LEN = 16; + +}; +#endif /*GAME_VERSION_HPP*/ \ No newline at end of file diff --git a/skScreen/init.cpp b/skScreen/init.cpp new file mode 100644 index 0000000..5a535e1 --- /dev/null +++ b/skScreen/init.cpp @@ -0,0 +1,49 @@ +#include "init.hpp" + + +BOOL Initialize() +{ + // getGameVersion(); + // readGameResolution(); + // readModuleConfiguration(); + + // set3Dratio(); + // setUIRatio(); + + // removeResolutionLimit(); + // fixRadeon(); + + // runInWindow(); + GameVersion gameVersion; + GameConfig gameConfig; + BinaryFix binaryFix(gameVersion, gameConfig); + + // TODO refactor with exceptions? + if (!gameVersion.isKnownGameVersion()) { + // unknown version + std::stringstream ss; + ss << "Unknown version, checkum is " << gameVersion.getGameHash(); + OutputDebugString(ss.str().c_str()); + MessageBox(NULL, "Unknown version of the game exe. This module is incompatible with widescreen fix.", "skScreen failed to load", MB_OK | MB_ICONERROR); + return FALSE; + } + + binaryFix.set3DRatio(); + binaryFix.setUIRatio(); + + // binaryFix.removeResolutionLimit(); + + //only D3D version is affected + /*if (gameVersion.getAPI() == API::DirectX) + { + binaryFix.fixRadeon(); + }*/ + + return TRUE; +} + +BOOL Finalize() { + // this module doesn't need any cleanup yet + // it would if it wa hooking up to any API + return TRUE; +} \ No newline at end of file diff --git a/skScreen/init.hpp b/skScreen/init.hpp new file mode 100644 index 0000000..a7cd28a --- /dev/null +++ b/skScreen/init.hpp @@ -0,0 +1,12 @@ +#ifndef INIT_HPP +#define INIT_HPP +#include +#include + +#include "gameVersion.hpp" +#include "gameConfig.hpp" +#include "binaryFix.hpp" + +BOOL Initialize(); +BOOL Finalize(); +#endif /*INIT_HPP*/ \ No newline at end of file diff --git a/skScreen/skScreen.cpp b/skScreen/skScreen.cpp new file mode 100644 index 0000000..6b2b784 --- /dev/null +++ b/skScreen/skScreen.cpp @@ -0,0 +1,32 @@ +#include "init.hpp" + +BOOL APIENTRY DllMain(HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved +) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: return Initialize(); + case DLL_PROCESS_DETACH: return Finalize(); + } + return TRUE; +} + + +/* +void FixRatio() +{ + // 40b37, Polish D3D + DWORD address = 0x440b37; + + // 0x40'15'55'55 = 2,3333, 21:9 + float ratio = 2.33333333f; + DWORD flOldProtect; + if (VirtualProtect((PVOID)address, 4, PAGE_EXECUTE_READWRITE, &flOldProtect)) // 0x40 = PAGE_EXECUTE_READWRITE + { + memcpy((PVOID)address, &ratio, 4); + VirtualProtect((PVOID)address, 4, flOldProtect, &flOldProtect); + } +} +*/ \ No newline at end of file