Skip to content

Commit

Permalink
Hide normals and odd black transparency
Browse files Browse the repository at this point in the history
Add ability to block certain render passes
Make fixed function lighting code toggleable
Clean up culling patch
Move includes for hooks to Hooks.cpp
  • Loading branch information
BlueAmulet committed May 26, 2023
1 parent da642fb commit 56a607c
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 33 deletions.
1 change: 1 addition & 0 deletions NewVegasReloaded/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C" {
TheSettingManager->SaveSettings();

// Log settings
Logger::Log("Translate lights: %s", SettingManager::PassLights ? "true" : "false");
Logger::Log("Light mode: %u", SettingManager::LightRangeMode);
Logger::Log("Disable culling: %s", SettingManager::DisableCulling ? "true" : "false");
Logger::Log("Enable sun light: %s", SettingManager::SunLight ? "true" : "false");
Expand Down
2 changes: 2 additions & 0 deletions NewVegasReloaded/NewVegasReloaded.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<ClInclude Include="..\TESReloaded\Core\Hooks\NewVegas\Hooks.h" />
<ClCompile Include="..\TESReloaded\Core\Hooks\NewVegas\Lights.cpp" />
<ClInclude Include="..\TESReloaded\Core\Hooks\NewVegas\Lights.h" />
<ClInclude Include="..\TESReloaded\Core\Hooks\NewVegas\Render.h" />
<ClInclude Include="..\TESReloaded\Core\SettingManager.h" />
<ClInclude Include="..\TESReloaded\Framework\Common\Base\Logger.h" />
<ClInclude Include="..\TESReloaded\Framework\Common\Base\PluginVersion.h" />
Expand All @@ -137,6 +138,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\TESReloaded\Core\CommandManager.cpp" />
<ClCompile Include="..\TESReloaded\Core\Hooks\NewVegas\Render.cpp" />
<ClCompile Include="..\TESReloaded\Core\SettingManager.cpp" />
<ClCompile Include="..\TESReloaded\Framework\Common\Base\Logger.cpp" />
<ClCompile Include="..\TESReloaded\Framework\Common\Base\PluginVersion.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions NewVegasReloaded/NewVegasReloaded.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<ClInclude Include="..\TESReloaded\Core\Hooks\NewVegas\Culling.h">
<Filter>Core\Hooks\NewVegas</Filter>
</ClInclude>
<ClInclude Include="..\TESReloaded\Core\Hooks\NewVegas\Render.h">
<Filter>Core\Hooks\NewVegas</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
Expand Down Expand Up @@ -130,6 +133,9 @@
<ClCompile Include="..\TESReloaded\Core\Hooks\NewVegas\Culling.cpp">
<Filter>Core\Hooks\NewVegas</Filter>
</ClCompile>
<ClCompile Include="..\TESReloaded\Core\Hooks\NewVegas\Render.cpp">
<Filter>Core\Hooks\NewVegas</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Exports.def">
Expand Down
25 changes: 8 additions & 17 deletions TESReloaded/Core/Hooks/NewVegas/Culling.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Anti culling patch, thanks Wall_SoGB
// Disable culling patch, thanks Wall_SoGB
#include "Hooks.h"

class BSOcclusionPlane;

Expand All @@ -11,7 +12,7 @@ void __fastcall BSCullingProcess_PushCullModeEx(BSCullingProcess* apThis, void*,
apThis->kCullMode = 1;
}

typedef void* (__fastcall* MTRenderManager__AddTask)(void*, void*, NiCamera*, BSCompoundFrustum*, NiNode*, void*, void*, BSShaderAccumulator*, UInt32, UInt32, UInt32);
typedef void (__fastcall* MTRenderManager__AddTask)(void*, void*, NiCamera*, BSCompoundFrustum*, NiNode*, void*, void*, BSShaderAccumulator*, UInt32, UInt32, UInt32);
static MTRenderManager__AddTask MTRenderManager__AddTaskFnk = (MTRenderManager__AddTask)0xBA3390;

void __fastcall MTRenderManager__AddTaskEx(void* ecx, void* edx, NiCamera* apCamera, BSCompoundFrustum* apFrustum, NiNode* apNode, void* apGeometryList1, void* apGeometryList2, BSShaderAccumulator* apShaderAccum, UInt32 aeCullMode, UInt32, UInt32) {
Expand Down Expand Up @@ -56,25 +57,15 @@ __declspec(naked) void BSCullingProcess_ProcessEx() {
}

void AttachCullingHooks() {
// Not all calls of this are patched
for (int callAddr : {0x8014F7, 0x80182E, 0x874260, 0x8742F0, 0x874316, 0x8743A6, 0x876233, 0x8767FD, }) {
SafeWriteCall(callAddr, (UInt32)BSCullingProcess_SetCullModeEx);
}

for (int callAddr : {0x54EB4E, 0x54EB91, 0x7134DF, 0x73354D, 0x740F7D, 0x77F188, 0x78E820, 0x794939, 0x7BBD3D, 0x7C1A0D, 0x7C9D09, 0x7E480E, 0x7FBD02, 0x7FE3D1, 0x8753CA, 0x875C45, }) {
SafeWriteCall(callAddr, (UInt32)BSCullingProcess_PushCullModeEx);
}

for (int callAddr : {0x4EA815, 0x4EAF18, 0x4EB1D7, 0x4EC769, 0x713F97, 0x874037, 0x87509C, 0xB9E6CB, }) {
SafeWriteCall(callAddr, (UInt32)MTRenderManager__AddTaskEx);
}

for (int callAddr : {0x549CCF, 0xB5AD64, 0xC347B7, 0xC4965C, }) {
SafeWriteCall(callAddr, (UInt32)BSOcclusionPlane__WithinFrustumEx);
}

for (int callAddr : {0xB5F25E, 0xB5F33A, 0xC49596, }) {
SafeWriteCall(callAddr, (UInt32)WithinFrustumDistFirst);
}
SafeWriteJump(0xC4F270, (UInt32)BSCullingProcess_PushCullModeEx);
MH_CreateHookSimple((LPVOID*)&MTRenderManager__AddTaskFnk, MTRenderManager__AddTaskEx);
SafeWriteJump(0xC33CF0, (UInt32)BSOcclusionPlane__WithinFrustumEx);
SafeWriteJump(0xC344C0, (UInt32)WithinFrustumDistFirst);

SafeWriteCall(0xC49690, (UInt32)CompletelyWithinFrustum);
SafeWrite32(0x101EA44, (UInt32)CompletelyWithinFrustum);
Expand Down
47 changes: 35 additions & 12 deletions TESReloaded/Core/Hooks/NewVegas/Hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
#include "Hooks.h"
#include "../lib/minhook/include/MinHook.h"
#include "Hooks.h"
#include "../GameCommon.h"
#include "Culling.h"
#include "Game.h"
#include "Lights.h"
#include "Render.h"

bool MH_CreateHookSimple(LPVOID *ppOriginal, LPVOID pDetour) {
if (ppOriginal == nullptr) {
Logger::Log("Attempted to create null hook for %p", pDetour);
}
void* pTarget = *ppOriginal;
if (MH_CreateHook(pTarget, pDetour, ppOriginal) != MH_OK) {
Logger::Log("Failed to create hook for %p", pTarget);
}
else if (MH_EnableHook(pTarget)) {
Logger::Log("Failed to enable hook for %p", pTarget);
}
else {
Logger::Debug("Created hook for %p to %p", pTarget, pDetour);
return true;
}
return false;
}

void AttachHooks() {
if (MH_Initialize() == MH_OK) {
MH_CreateHook((void*)InitializeRenderer, &InitializeRendererHook, reinterpret_cast<LPVOID*>(&InitializeRenderer));
MH_CreateHook((void*)NewTES, &NewTESHook, reinterpret_cast<LPVOID*>(&NewTES));
MH_CreateHook((void*)NewMenuInterfaceManager, &NewMenuInterfaceManagerHook, reinterpret_cast<LPVOID*>(&NewMenuInterfaceManager));
if (MH_EnableHook(MH_ALL_HOOKS) != MH_OK) {
Logger::Log("Failed to apply hooks");
}
} else {
if (MH_Initialize() != MH_OK) {
Logger::Log("Failed to initialize MinHook");
return;
}
MH_CreateHookSimple((LPVOID*)&InitializeRenderer, InitializeRendererHook);
MH_CreateHookSimple((LPVOID*)&NewTES, NewTESHook);
MH_CreateHookSimple((LPVOID*)&NewMenuInterfaceManager, NewMenuInterfaceManagerHook);

AttachLightHooks();
AttachRenderHooks();

if (SettingManager::PassLights) {
AttachLightHooks();
}

if (SettingManager::DisableCulling)
{
if (SettingManager::DisableCulling) {
AttachCullingHooks();
}
}
1 change: 1 addition & 0 deletions TESReloaded/Core/Hooks/NewVegas/Hooks.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once

bool MH_CreateHookSimple(LPVOID*, LPVOID);
void AttachHooks();
18 changes: 18 additions & 0 deletions TESReloaded/Core/Hooks/NewVegas/Render.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "Hooks.h"

typedef void(__fastcall* RenderListAdd)(void*, void*, void*, WORD, BYTE, BYTE, void*, void*, void*, void*);
static RenderListAdd RenderListOrig = (RenderListAdd)0xBA9EE0;

void __fastcall RenderListHook(void* ecx, void* edx, void* triStrips, WORD renderPassNum, BYTE enable, BYTE numLights, void* light0, void* light1, void* light2, void* light3) {
// Block normals and weird transparent black
if (renderPassNum == 306 || renderPassNum == 334) {
return;
}
// Hide lights from game
RenderListOrig(ecx, edx, triStrips, renderPassNum, enable, min(numLights, 1), light0, nullptr, nullptr, nullptr);
}

void AttachRenderHooks()
{
MH_CreateHookSimple((LPVOID*)&RenderListOrig, RenderListHook);
}
2 changes: 2 additions & 0 deletions TESReloaded/Core/Hooks/NewVegas/Render.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
void AttachRenderHooks();
3 changes: 3 additions & 0 deletions TESReloaded/Core/SettingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void SettingManager::LoadSettings() {
}

Logger::Log("Reading settings from %ls", iniPath);
GetSettingBool(PassLights);
GetSettingInt(LightRangeMode);
GetSettingBool(DisableCulling);
GetSettingBool(SunLight);
Expand All @@ -70,12 +71,14 @@ void SettingManager::SaveSettings() {
}

Logger::Log("Saving settings to %ls", iniPath);
WriteSettingBool(PassLights);
WriteSettingInt(LightRangeMode);
WriteSettingBool(DisableCulling);
WriteSettingBool(SunLight);
WriteSettingBool(VisualSun);
}

bool SettingManager::PassLights = true;
int SettingManager::LightRangeMode = 0;
bool SettingManager::DisableCulling = true;
bool SettingManager::SunLight = true;
Expand Down
1 change: 1 addition & 0 deletions TESReloaded/Core/SettingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SettingManager : public SettingManagerBase {
wchar_t iniPath[MAX_PATH];

// Settings
static bool PassLights;
static int LightRangeMode;
static bool DisableCulling;
static bool SunLight;
Expand Down
4 changes: 0 additions & 4 deletions TESReloaded/Framework/NewVegas/Framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@
#include "Defines.h"
#include "Base.h"
#include "Managers.h"
#include "../Core/Hooks/GameCommon.h"
#include "../Core/Hooks/NewVegas/Culling.h"
#include "../Core/Hooks/NewVegas/Game.h"
#include "../Core/Hooks/NewVegas/Lights.h"

0 comments on commit 56a607c

Please sign in to comment.