diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a30d25 --- /dev/null +++ b/.gitignore @@ -0,0 +1,398 @@ +## 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/main/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/ + +# 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 +*.tlog +*.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 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# 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/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# 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 + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0082d0a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/injector"] + path = deps/injector + url = https://github.com/thelink2012/injector diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..58e0354 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 akifle47 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/VolumetricLights.sln b/VolumetricLights.sln new file mode 100644 index 0000000..6d0ec41 --- /dev/null +++ b/VolumetricLights.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32630.192 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VolumetricLights", "VolumetricLights.vcxproj", "{CEC3FA6A-F689-4F8C-B24A-A4E44587D63D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CEC3FA6A-F689-4F8C-B24A-A4E44587D63D}.Debug|x86.ActiveCfg = Debug|Win32 + {CEC3FA6A-F689-4F8C-B24A-A4E44587D63D}.Debug|x86.Build.0 = Debug|Win32 + {CEC3FA6A-F689-4F8C-B24A-A4E44587D63D}.Release|x86.ActiveCfg = Release|Win32 + {CEC3FA6A-F689-4F8C-B24A-A4E44587D63D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5410D7A8-15A6-4FD6-BAF3-8FE486AD1210} + EndGlobalSection +EndGlobal diff --git a/VolumetricLights.vcxproj b/VolumetricLights.vcxproj new file mode 100644 index 0000000..92aae87 --- /dev/null +++ b/VolumetricLights.vcxproj @@ -0,0 +1,161 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + 16.0 + Win32Proj + {cec3fa6a-f689-4f8c-b24a-a4e44587d63d} + VolumetricLights + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + .asi + true + $(SolutionDir)build\$(Configuration)\bin\ + $(SolutionDir)\deps\injector\include;$(IncludePath) + $(LibraryPath) + $(SolutionDir)build\$(Configuration)\ + + + .asi + true + $(SolutionDir)build\$(Configuration)\bin\ + $(SolutionDir)\deps\injector\include;$(IncludePath) + $(LibraryPath) + $(SolutionDir)build\$(Configuration)\ + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + true + %(AdditionalDependencies) + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + true + true + true + %(AdditionalDependencies) + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + \ No newline at end of file diff --git a/VolumetricLights.vcxproj.filters b/VolumetricLights.vcxproj.filters new file mode 100644 index 0000000..1b409c1 --- /dev/null +++ b/VolumetricLights.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/assets/VolumetricLights.cfg b/assets/VolumetricLights.cfg new file mode 100644 index 0000000..3a341ce --- /dev/null +++ b/assets/VolumetricLights.cfg @@ -0,0 +1 @@ +VolumetricIntensityMultiplier = 1.0 \ No newline at end of file diff --git a/deps/injector b/deps/injector new file mode 160000 index 0000000..07e6a54 --- /dev/null +++ b/deps/injector @@ -0,0 +1 @@ +Subproject commit 07e6a5430885146575b075c689c26ce2bac1951a diff --git a/src/Utils.h b/src/Utils.h new file mode 100644 index 0000000..98d2749 --- /dev/null +++ b/src/Utils.h @@ -0,0 +1,53 @@ +#pragma once +#include +#include + +namespace Utils +{ + template + inline void WriteMemory(uint32_t address, T value) + { + static uint32_t baseAddress = 0; + if(!baseAddress) + { + baseAddress = (uint32_t)GetModuleHandle(L"GTAIV.exe"); + } + + injector::WriteMemory(baseAddress + address, value); + } + + template + inline void WriteMemory(uint32_t address, T value, uint32_t size) + { + static uint32_t baseAddress = 0; + if(!baseAddress) + { + baseAddress = (uint32_t)GetModuleHandle(L"GTAIV.exe"); + } + + injector::WriteMemoryRaw(baseAddress + address, value, size, true); + } + + template + inline void WriteCall(uint32_t address, T function) + { + static uint32_t baseAddress = 0; + if(!baseAddress) + { + baseAddress = (uint32_t)GetModuleHandle(L"GTAIV.exe"); + } + + injector::MakeCALL(baseAddress + address, function); + } + + inline void *ReadMemory(uint32_t address) + { + static uint32_t baseAddress = 0; + if(!baseAddress) + { + baseAddress = (uint32_t)GetModuleHandle(L"GTAIV.exe"); + } + + return (void *)(baseAddress + address); + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..1aa85f7 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,173 @@ +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include +#include + +#include "Utils.h" +#include "rage/LightSource.h" +#include "rage/Weather.h" + +float gVolumeIntensity = 1.0f; +float gCfgVolumetricIntensityMultiplier = 1.0f; + +void (__cdecl *CRenderPhaseDeferredLighting_LightsToScreen__BuildRenderListO)() = nullptr; +void (__cdecl *CopyLightO)() = nullptr; + +void Init(); +void Update(); +void OnAfterCopyLight(rage::CLightSource*); + +bool HasSnow(CWeather::eWeatherType type); + +void __declspec(naked) CRenderPhaseDeferredLighting_LightsToScreen__BuildRenderListH() +{ + _asm + { + push ecx + call Update + + pop ecx + call CRenderPhaseDeferredLighting_LightsToScreen__BuildRenderListO + + ret + } +} + +void __declspec(naked) CopyLightH() +{ + _asm + { + push [esp+0x4] + call CopyLightO + + push eax + call OnAfterCopyLight + pop eax + + ret 0x4 + } +} + +BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) +{ + if(fdwReason == DLL_PROCESS_ATTACH) + { + if(*(uint32_t *)Utils::ReadMemory(0x208C34) != 0x404B100F) + { + MessageBox(0, L"Only version 1.0.8.0 is supported", L"Snow.asi", MB_ICONERROR | MB_OK); + return false; + } + + CRenderPhaseDeferredLighting_LightsToScreen__BuildRenderListO = *(void(__cdecl **)())Utils::ReadMemory(0x9E4874); + Utils::WriteMemory(0x9E4874, CRenderPhaseDeferredLighting_LightsToScreen__BuildRenderListH); + + CopyLightO = (void(__cdecl *)())Utils::ReadMemory(0x62A7F0); + Utils::WriteCall(0x62DAB7, CopyLightH); + Utils::WriteCall(0x62DA71, CopyLightH); + } + + return true; +} + +void Init() +{ + static bool initialized = false; + if(initialized) + return; + + std::ifstream cfgFile("VolumetricLights.cfg"); + if(cfgFile.is_open()) + { + std::string currLine; + while(std::getline(cfgFile, currLine)) + { + size_t index; + index = currLine.rfind("VolumetricIntensityMultiplier"); + if(index != std::string::npos) + { + index += sizeof("VolumetricIntensityMultiplier"); + + while(index < currLine.size()) + { + if(currLine[index] != ' ' && currLine[index] != '=') + { + break; + } + + index++; + } + + gCfgVolumetricIntensityMultiplier = std::stof(currLine.substr(index)); + } + } + } + + //movss xmm0, dword ptr [esi + eax * 1 + 0x4C] or xmm0 = Lights::mRenderLights[i].mTxdId + uint8_t buffer[] = {0x44, 0x06, 0x4C, 0x90, 0x90}; + Utils::WriteMemory(0x630B00, buffer, 5); +} + +void Update() +{ + Init(); + + gVolumeIntensity = 0.0f; + + static CWeather::eWeatherType currWeather; + + CWeather::eWeatherType prevWeather = currWeather; + currWeather = CWeather::GetCurrentWeather(); + CWeather::eWeatherType nextWeather = CWeather::GetNextWeather(); + + if(HasSnow(prevWeather) || HasSnow(currWeather) || HasSnow(nextWeather)) + { + float threshold; + if(!HasSnow(currWeather) && HasSnow(nextWeather)) + threshold = CWeather::GetNextWeatherPercentage(); + else if(HasSnow(currWeather) && !HasSnow(nextWeather)) + threshold = 0.9999f - CWeather::GetNextWeatherPercentage(); + else if(!HasSnow(currWeather) && !HasSnow(nextWeather)) + threshold = 0.0f; + else + threshold = 0.9999f; + + gVolumeIntensity = threshold * 4.0f * gCfgVolumetricIntensityMultiplier; + } +} + +void OnAfterCopyLight(rage::CLightSource *light) +{ + //CLightSource doesnt have a member to control the volume intensity so + //i abuse type casting to use mTxdId for it as im p sure its only used for headlights anyway + + if(light->mFlags & 8 /*volumetric*/) + { + *(float*)&light->mTxdId = 1.0f; + } + else if(light->mType == rage::LT_SPOT && !(light->mFlags & 0x300)/*vehicles and traffic lights*/) + { + if(gVolumeIntensity > 0.0f && light->mRadius < 50.0f) + { + light->mVolumeSize = 1.0f; + light->mVolumeScale = 0.5f; + light->mFlags |= 8; + *(float*)&light->mTxdId = gVolumeIntensity; + } + } +} + +bool HasSnow(CWeather::eWeatherType type) +{ + switch(type) + { + case CWeather::RAIN: + case CWeather::DRIZZLE: + case CWeather::LIGHTNING: + case CWeather::FOGGY: + return true; + default: + return false; + } +} \ No newline at end of file diff --git a/src/rage/LightSource.h b/src/rage/LightSource.h new file mode 100644 index 0000000..ea144f4 --- /dev/null +++ b/src/rage/LightSource.h @@ -0,0 +1,44 @@ +#pragma once +#include "Vector.h" +#include + +namespace rage +{ + enum eLightType + { + LT_POINT = 0x0, + LT_DIR = 0x1, + LT_SPOT = 0x2, + LT_AO = 0x3, + LT_CLAMPED = 0x4, + }; + + class CLightSource + { + public: + Vector3 mDirection; + int32_t field_C; + Vector3 mTangent; + int32_t field_1C; + Vector3 mPosition; + int32_t field_2C; + Vector4 mColor; + float mIntensity; + eLightType mType; + int32_t mFlags; + int32_t mTxdId; + int32_t field_50; + float mRadius; + float mInnerConeAngle; + float mOuterConeAngle; + int32_t field_60; + int32_t field_64; + int32_t field_68; + int32_t field_6C; + float mVolumeSize; + float mVolumeScale; + uint8_t gap78[8]; + }; + + static_assert(sizeof(CLightSource) == 0x80); +} \ No newline at end of file diff --git a/src/rage/Vector.h b/src/rage/Vector.h new file mode 100644 index 0000000..4fc58a4 --- /dev/null +++ b/src/rage/Vector.h @@ -0,0 +1,16 @@ +#pragma once + +namespace rage +{ + struct Vector3 + { + public: + float x, y, z; + }; + + struct Vector4 + { + public: + float x, y, z, w; + }; +} \ No newline at end of file diff --git a/src/rage/Weather.h b/src/rage/Weather.h new file mode 100644 index 0000000..74c4f7c --- /dev/null +++ b/src/rage/Weather.h @@ -0,0 +1,35 @@ +#pragma once +#include "../Utils.h" + +namespace CWeather +{ + enum eWeatherType : uint32_t + { + EXTRASUNNY, + SUNNY, + SUNNY_WINDY, + CLOUDY, + RAIN, + DRIZZLE, + FOGGY, + LIGHTNING + }; + + static eWeatherType GetCurrentWeather() + { + static eWeatherType *currentWeather = *(eWeatherType**)Utils::ReadMemory(0x74E6A7); + return *currentWeather; + } + + static eWeatherType GetNextWeather() + { + static eWeatherType *nextWeather = *(eWeatherType**)Utils::ReadMemory(0x74E6B3); + return *nextWeather; + } + + static float GetNextWeatherPercentage() + { + static float *nextWeatherPctg = *(float**)Utils::ReadMemory(0x74E69B); + return *nextWeatherPctg; + } +} \ No newline at end of file