forked from lStewieAl/Geck-Extender
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreemptivelyUnloadCells.cpp
More file actions
91 lines (80 loc) · 2 KB
/
PreemptivelyUnloadCells.cpp
File metadata and controls
91 lines (80 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "GECKUtility.h"
#include "GameData.h"
#include "Settings.h"
namespace PreemptivelyUnloadCells
{
bool __fastcall OnLoadInterior_HasBufferedInteriorCell(TES* apTES, void* edx, TESObjectCELL* apCell)
{
bool bHasBufferedInteriorCell = ThisCall<bool>(0x4C7DF0, apTES, apCell);
if (bHasBufferedInteriorCell)
{
return true;
}
if (config.bPreemptivelyUnloadCells)
{
if (apTES->pInteriorCell)
{
apTES->DetachGridCells();
}
if (apTES->FreeExteriorBuffer(true, nullptr))
{
apTES->CleanUpUnusedTextures();
}
}
return false;
}
void __fastcall OnSetWorldSpace_DetachCells(TES* apTES, TESWorldSpace* apNewWorldSpace)
{
apTES->DetachGridCells();
if (config.bPreemptivelyUnloadCells)
{
int iFreed = apTES->FreeExteriorBuffer(true, apTES->pWorldSpace);
if (!apTES->pInteriorCell)
{
iFreed += apTES->FreeInteriorBuffer(true);
}
if (iFreed)
{
apTES->CleanUpUnusedTextures();
}
}
apTES->pWorldSpace = apNewWorldSpace;
}
__HOOK OnSetWorldSpace_DetachCellsHook()
{
_asm
{
mov edx, edi
jmp OnSetWorldSpace_DetachCells
}
}
void OnUpdateCurrentGridCell(TES* apTES)
{
if (config.bPreemptivelyUnloadCells)
{
if (apTES->FreeInteriorBuffer(true))
{
apTES->CleanUpUnusedTextures();
}
}
}
__HOOK OnUpdateCurrentGridCellHook()
{
_asm
{
mov ecx, esi
call OnUpdateCurrentGridCell
cmp dword ptr ds : [esi + 0x88], 0
ret
}
}
void Init()
{
SafeWriteBuf(0x4C9F01, "\x90\x90\x90\x90\x90\x90", 6); // set the worldspace in our hook instead so we keep the pointer to the previous one
WriteRelCall(0x4C9F01 + 6, UInt32(OnSetWorldSpace_DetachCellsHook));// TES::SetWorldSpace
// TES::UpdateCurrentGridCell (0x4CCC5C) - we likely don't need to hook here, it's related to BackgroundCellLoads
WriteRelCall(0x4CCD49, UInt32(OnUpdateCurrentGridCellHook)); // TES::UpdateCurrentGridCell
SafeWrite16(0x4CCD49 + 5, 0x9066);
WriteRelCall(0x4CB0E3, UInt32(OnLoadInterior_HasBufferedInteriorCell)); // TES::LoadInterior
}
}