Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unwanted offsets from CrashCatcher.cpp #385

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 4.0.17
- 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
29 changes: 20 additions & 9 deletions plugins/crash_catcher/CrashCatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,23 @@ namespace Plugins::CrashCatcher
/** @ingroup CrashCatcher
* @brief Install hooks
*/
void Init()
void LoadSettings()
{
try
{
if (!global->bPatchInstalled)
{
global->bPatchInstalled = true;
// Load the settings
auto config = Serializer::JsonToObject<Config>();

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

FARPROC fpHook = (FARPROC)Cb_GetRoot;
ReadProcMem((char*)global->hModServerAC + 0x84018, &fpOldGetRootProc, 4);
Expand Down Expand Up @@ -520,9 +522,16 @@ namespace Plugins::CrashCatcher

// Patch the NPC persist distance in MP to 6.5km and patch the
// max spawn distance to 6.5km
float fDistance = 6500;
WriteProcMem((char*)global->hModContentAC + 0xD3D6E, &fDistance, 4);
WriteProcMem((char*)global->hModContentAC + 0x58F46, &fDistance, 4);

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

if (config.npcSpawnDistance > 0.f)
{
WriteProcMem((char*)global->hModContentAC + 0x58F46, &config.npcSpawnDistance, 4);
}
}
}
}
Expand Down Expand Up @@ -604,11 +613,13 @@ 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)
{
if (fdwReason == DLL_PROCESS_ATTACH && CoreGlobals::c()->flhookReady)
Init();
LoadSettings();

if (fdwReason == DLL_PROCESS_DETACH)
Shutdown();
Expand All @@ -626,7 +637,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
22 changes: 18 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 @@ -20,10 +34,10 @@ namespace Plugins::CrashCatcher
std::map<uint, mstime> mapSaveTimes;
};

#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
Loading