Skip to content

Commit

Permalink
Add the offsets back and into a config for CrashCatcher.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
IrateRedKite committed Jan 22, 2024
1 parent e56e02b commit 99983ae
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## 4.0.17
- Remove modifications of 0x86AEC, 0x84018, 0xD3D6E and 0x58F46 in server.dll from crash catcher. These offsets were hardcoding several values that are often changed by mods manually relating to NPC spawn and scanner range.
- Provided configs for 0x86AEC, 0x84018, 0xD3D6E and 0x58F46 in server.dll in crash catcher. These offsets were hardcoding several values that are often changed by mods manually relating to NPC spawn and scanner range. 0 values disables each respective hook.

## 4.0.16
- Removed a PrintUserCmd from Autobuy that was printing on every repair.
Expand Down
37 changes: 36 additions & 1 deletion plugins/crash_catcher/CrashCatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ namespace Plugins::CrashCatcher
{
const std::unique_ptr<Global> global = std::make_unique<Global>();

void LoadSettings()
{
auto config = Serializer::JsonToObject<Config>();
global->config = std::make_unique<Config>(config);
}

/** @ingroup CrashCatcher
* @brief Need to use our own logging functions since the nature of this plugin isn't compatible with FLHook's standard logging functionality.
*/
Expand Down Expand Up @@ -406,8 +412,20 @@ namespace Plugins::CrashCatcher
if (!global->bPatchInstalled)
{
global->bPatchInstalled = true;
LoadSettings();

global->hModServerAC = GetModuleHandle("server.dll");
if (global->hModServerAC && global->config->npcVisibilityDistance > 0.f)
{
// Patch the NPC visibility distance in MP to 6.5km (default
// is 2.5km)
float visDistance = global->config->npcVisibilityDistance * global->config->npcVisibilityDistance;
WriteProcMem((char*)global->hModServerAC + 0x86AEC, &visDistance, 4);

FARPROC fpHook = (FARPROC)Cb_GetRoot;
ReadProcMem((char*)global->hModServerAC + 0x84018, &fpOldGetRootProc, 4);
WriteProcMem((char*)global->hModServerAC + 0x84018, &fpHook, 4);
}

// Patch the time functions to work around bugs on multiprocessor
// and virtual machines.
Expand Down Expand Up @@ -506,6 +524,21 @@ namespace Plugins::CrashCatcher
PatchCallAddr((char*)global->hModContentAC, 0xC702A, (char*)Cb_CrashProc6F671A0);
PatchCallAddr((char*)global->hModContentAC, 0xC713B, (char*)Cb_CrashProc6F671A0);
PatchCallAddr((char*)global->hModContentAC, 0xC7180, (char*)Cb_CrashProc6F671A0);

// Patch the NPC persist distance in MP to 6.5km and patch the
// max spawn distance to 6.5km
auto persistDistance = global->config->npcPersistDistance;
auto spawnDistance = global->config->npcSpawnDistance;

if (global->config->npcPersistDistance > 0.f)
{
WriteProcMem((char*)global->hModContentAC + 0xD3D6E, &persistDistance, 4);
}

if (global->config->npcSpawnDistance > 0.f)
{
WriteProcMem((char*)global->hModContentAC + 0x58F46, &spawnDistance, 4);
}
}
}
}
Expand Down Expand Up @@ -587,6 +620,8 @@ namespace Plugins::CrashCatcher

using namespace Plugins::CrashCatcher;

REFL_AUTO(type(Config), field(npcVisibilityDistance), field(npcPersistDistance), field(npcSpawnDistance))

// Do things when the dll is loaded
BOOL WINAPI DllMain([[maybe_unused]] HINSTANCE hinstDLL, DWORD fdwReason, [[maybe_unused]] LPVOID lpvReserved)
{
Expand All @@ -609,7 +644,7 @@ extern "C" EXPORT void ExportPluginInfo(PluginInfo* pi)
pi->returnCode(&global->returncode);
pi->versionMajor(PluginMajorVersion::VERSION_04);
pi->versionMinor(PluginMinorVersion::VERSION_00);
pi->emplaceHook(HookedCall::FLHook__LoadSettings, &Init, HookStep::After);
pi->emplaceHook(HookedCall::FLHook__LoadSettings, &LoadSettings, HookStep::After);
pi->emplaceHook(HookedCall::IServerImpl__RequestBestPath, &RequestBestPath);
pi->emplaceHook(HookedCall::IServerImpl__TractorObjects, &TractorObjects);
pi->emplaceHook(HookedCall::IServerImpl__JettisonCargo, &JettisonCargo);
Expand Down
24 changes: 20 additions & 4 deletions plugins/crash_catcher/CrashCatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@

namespace Plugins::CrashCatcher
{

//! Config data for this plugin
struct Config final : Reflectable
{
std::string File() override { return "config/crashcatcher.json"; }

//! Sets the maximum distance at which NPCs become visible as per scanner settings, a value of 0 will disable this override.
float npcVisibilityDistance = 6500.f;
//! Sets the distnace at which NPCs will despawn, a value of 0 will disable this override.
float npcPersistDistance = 6500.f;
//! Sets the distance at which NPCs will spawn, a value of 0 will disable this override.
float npcSpawnDistance = 6500.f;
};

//! Global data for this plugin
struct Global final
{
Expand All @@ -18,12 +32,14 @@ namespace Plugins::CrashCatcher
HMODULE hModContentAC;

std::map<uint, mstime> mapSaveTimes;
//! Contains config data defined above
std::unique_ptr<Config> config = nullptr;
};

#define LOG_EXCEPTION_INTERNAL() \
{ \
AddLogInternal("ERROR Exception in %s", __FUNCTION__); \
AddExceptionInfoLog(); \
#define LOG_EXCEPTION_INTERNAL() \
{ \
AddLogInternal("ERROR Exception in %s", __FUNCTION__); \
AddExceptionInfoLog(); \
};
} // namespace Plugins::CrashCatcher

Expand Down

0 comments on commit 99983ae

Please sign in to comment.