Skip to content

Commit

Permalink
fix: Extended Grass loading new worldspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
SaneEngineer committed Apr 22, 2024
1 parent 57dbd4a commit fe6f084
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 66 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.21)
set(NAME "NGIO-NG" CACHE STRING "")
set(VERSION 1.0.9 CACHE STRING "")
set(VERSION 1.0.11 CACHE STRING "")
set(VR_VERSION 2)
set(AE_VERSION 1)

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## No Grass in Objects NG

This is a port of No Grass in Objects rewritten using Commonlib, The main features of Caching, Raycasting (No grass in objects part), and extended grass distance are working in AE. The config is roughly the same with a change to ini that should be created while the mod is first loaded, minor renaming of settings and an option for debug logs. To my knowledge all features except for grass scale should be working in SE, the same goes for AE. Right now `Extend-grass-distance` is broken and should be set false in order to avoid crashes.
This is a port of No Grass in Objects rewritten using Commonlib, The main features of Caching and Raycasting (No grass in objects part). Extended grass distance, is working but is incomplete and may result in crashes. The config is roughly the same with a change to ini that should be created while the mod is first loaded, minor renaming of settings and an option for debug logs. To my knowledge all features except for grass scale should be working in SE, the same goes for AE.

---

Expand Down Expand Up @@ -32,7 +32,9 @@ This can be found by opening Steam and locating Skyrim SE in your game library,
* Crashing while Caching
- Check `NGIO-NG/log`, `PrecacheGrass.txt`, and `Data\Grass\` to see if any progress is being done. If no progress is being made check any crash logs as the crash is likely caused by an issue with a mod affecting the area. This can be a texture, mesh, patch, or mod editing the area. It should be mentioned by the crash log.
- I recommend using [Crash Logger SSE AE VR](https://www.nexusmods.com/skyrimspecialedition/mods/59818?tab=description) over [Trainwreck](https://www.nexusmods.com/skyrimspecialedition/mods/106440). As it provides much more helpful and readable crash logs.

* Raycasting not working
- Raycasting when used without a grass cache does not apply without loading a save twice. Raycasting will always take effect when a cache is generated with it enabled.

---

## Requirements to Build
Expand Down
6 changes: 3 additions & 3 deletions include/GrassControl/DistantGrass.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ namespace GrassControl
static std::string MakeKey(const std::string& ws, int x, int y);

public:
void UpdatePositionWithRemove(RE::TESWorldSpace* ws, int addType, int nowX, int nowY, int grassRadius) const;
void UpdatePositionWithRemove(RE::TESWorldSpace* ws, int addType, int nowX, int nowY, int grassRadius);

void QueueLoad(RE::TESWorldSpace* ws, int x, int y);

private:
void _DoUnload(std::shared_ptr<_cell_data> d) const;
void _DoUnload(const std::shared_ptr<_cell_data>& d);

public:
void Unload(const RE::TESWorldSpace* ws, int x, int y) const;
void Unload(const RE::TESWorldSpace* ws, int x, int y);

void _DoLoad(const RE::TESWorldSpace* ws, int x, int y) const;
};
Expand Down
24 changes: 13 additions & 11 deletions src/DistantGrass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace GrassControl
return rtn;
}

void DistantGrass::LoadOnlyCellInfoContainer2::UpdatePositionWithRemove(RE::TESWorldSpace* ws, int addType, int nowX, int nowY, int grassRadius) const
void DistantGrass::LoadOnlyCellInfoContainer2::UpdatePositionWithRemove(RE::TESWorldSpace* ws, int addType, int nowX, int nowY, int grassRadius)
{
unsigned int wsId = ws != nullptr ? ws->formID : 0;

Expand Down Expand Up @@ -191,7 +191,7 @@ namespace GrassControl
}
}

void DistantGrass::LoadOnlyCellInfoContainer2::_DoUnload(std::shared_ptr<_cell_data> d) const
void DistantGrass::LoadOnlyCellInfoContainer2::_DoUnload(const std::shared_ptr<_cell_data>& d)
{
if (d == nullptr)
return;
Expand All @@ -216,10 +216,17 @@ namespace GrassControl

d->DummyCell_Ptr = nullptr;
d->State = _cell_data::_cell_states::None;

for (auto it = map.begin(); it != map.end(); ++it) {
if (it->second == d) {
map.erase(it);
break;
}
}
}
}

void DistantGrass::LoadOnlyCellInfoContainer2::Unload(const RE::TESWorldSpace* ws, const int x, const int y) const
void DistantGrass::LoadOnlyCellInfoContainer2::Unload(const RE::TESWorldSpace* ws, const int x, const int y)
{
if (ws == nullptr)
return;
Expand Down Expand Up @@ -248,7 +255,7 @@ namespace GrassControl
std::string key = MakeKey(ws->editorID.c_str(), x, y);
std::shared_ptr<_cell_data> d;
{
std::scoped_lock lock(locker());
std::scoped_lock lock(NRlocker());
auto it = this->map.find(key);
d = it == this->map.end() ? nullptr : it->second;
}
Expand All @@ -257,7 +264,7 @@ namespace GrassControl
return;

{
std::scoped_lock lock(locker());
std::scoped_lock lock(NRlocker());
if (d->State == _cell_data::_cell_states::Loaded) {
// This shouldn't happen
} else if (d->State == _cell_data::_cell_states::Loading) {
Expand Down Expand Up @@ -1619,12 +1626,7 @@ namespace GrassControl
int bigSide = std::max(grassRadius, uHalf);
bool canLoadGrass = Memory::Internal::read<uint8_t>(addr_AllowLoadFile + 8) != 0;

std::string wsName;
try {
//auto wsObj = (RE::TESWorldSpace*)ws;
wsName = wsObj->editorID.c_str();
} catch (...) {
}
std::string wsName = wsObj->editorID.c_str();

int nowX = prevX + movedX;
int nowY = prevY + movedY;
Expand Down
51 changes: 2 additions & 49 deletions src/GidFileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,46 +177,7 @@ namespace GrassControl
// Set the ini stuff.
auto setting = RE::INISettingCollection::GetSingleton()->GetSetting("bAllowLoadGrass:Grass");
setting->data.b = true;
/* BROKEN TODO
if (auto addr = (RELOCATION_ID(15204, 15372).address() + OFFSET(0xAC - 0x10, 0xBD)); REL::make_pattern<"44 38 3D">().match(RELOCATION_ID(15204, 15372).address() + OFFSET(0xAC - 0x10, 0xBD))) {
Utility::Memory::SafeWrite(addr, Utility::Assembly::NoOperation9);
}
*/
/*
auto addr = RELOCATION_ID(15202, 15370).address() + OFFSET(0xBE7 - 0x890, 0x351);
//Memory::WriteHook(new HookParameters() { Address = addr, IncludeLength = 0, ReplaceLength = 7, Before = [&] (std::any ctx)
struct Patch : Xbyak::CodeGenerator
{
Patch(bool only_load, const std::uintptr_t a_target)
{
Xbyak::Label retnLabel;
Xbyak::Label j_else;
mov(al, only_load);
movzx(eax, al);
test(eax, eax);
jne(j_else);
mov(rax, 1);
jmp(ptr[rip + retnLabel]);
L(j_else);
mov(rax, 0);
jmp(ptr[rip + retnLabel]);
L(retnLabel);
dq(a_target + 0x7);
}
};
Patch patch(only_load, addr);
patch.ready();
auto& trampoline = SKSE::GetTrampoline();
Utility::Memory::SafeWrite(addr + 5, Utility::Assembly::NoOperation2);
trampoline.write_branch<5>(addr, trampoline.allocate(patch));
*/

if (!only_load) {
auto setting = RE::INISettingCollection::GetSingleton()->GetSetting("bAllowCreateGrass:Grass");
setting->data.b = true;
Expand Down Expand Up @@ -249,8 +210,8 @@ namespace GrassControl
patch.ready();

auto& trampoline = SKSE::GetTrampoline();
Utility::Memory::SafeWrite(addr, Utility::Assembly::NoOperation7);
trampoline.write_branch<5>(addr, trampoline.allocate(patch));
Utility::Memory::SafeWrite(addr + 5, Utility::Assembly::NoOperation2);
} else {
stl::report_and_fail("Failed to Disable Grass Console");
}
Expand Down Expand Up @@ -330,14 +291,6 @@ namespace GrassControl
Xbyak::Label retnLabel;
Xbyak::Label exchange;

/*
push(rax);
xor_(eax, eax);
mov(rcx, mode);
lock();
xchg(ptr[rcx], rax);
*/

mov(rdi, ptr[rsp + 0x50]);

sub(rsp, 0x20);
Expand Down

0 comments on commit fe6f084

Please sign in to comment.