diff --git a/Source/Contents/NavigationManager.h b/Source/Contents/NavigationManager.h index 4eceb3d..3966240 100644 --- a/Source/Contents/NavigationManager.h +++ b/Source/Contents/NavigationManager.h @@ -3,8 +3,15 @@ #include #include +#include -class NavigationObject; +class NavigationObject { +public: + bool HasName(const char* name) const; + + /* 0000 */ unsigned char unknown_0000[8]; + /* 0008 */ std::string name; +}; struct NavigationTarget { /* 0000 */ int type; @@ -20,14 +27,22 @@ public: NavigationTarget GetSavedTarget() const; int GetCurrentTargetType() const; int SaveCurrentTarget(); + NavigationObject* FindObject(const char* name) const; + float FitToSquare(int* offsetX, int* offsetY, int width, int height, float size) const; + void LoadSettings(); - /* 0000 */ unsigned char unknown_0000[0x10FC]; + /* 0000 */ std::vector objects; + /* 000C */ unsigned char unknown_000C[0x10F0]; /* 10FC */ NavigationTarget currentTarget; /* 1124 */ NavigationTarget savedTarget; + /* 114C */ unsigned char unknown_114C[0x1F8]; + /* 1344 */ int viewIcon; }; #if defined(_WIN32) && !defined(_WIN64) +static_assert(offsetof(NavigationObject, name) == 0x8); static_assert(offsetof(NavigationManager, savedTarget) == 0x1124); +static_assert(offsetof(NavigationManager, viewIcon) == 0x1344); #endif #endif diff --git a/Source/Contents/NavigationRoute.cpp b/Source/Contents/NavigationRoute.cpp new file mode 100644 index 0000000..3a01e30 --- /dev/null +++ b/Source/Contents/NavigationRoute.cpp @@ -0,0 +1,57 @@ +#include "Contents/NavigationManager.h" + +#include "Client/Registry.h" +#include "Utility/RegistryKey.h" + +#include + +// OFFSET: 0x00B88800 +// FUNCTION: fn_19376 +NavigationObject* NavigationManager::FindObject(const char* name) const { + for (NavigationObject* object : this->objects) { + if (object->HasName(name)) { + return object; + } + } + return nullptr; +} + +// OFFSET: 0x00B8D270 +// FUNCTION: fn_19434 +bool NavigationObject::HasName(const char* name) const { + return std::strcmp(this->name.c_str(), name) == 0; +} + +// OFFSET: 0x00B996D0 +// FUNCTION: fn_19613 +void NavigationManager::LoadSettings() { + RegistryKey key; + std::string subKey(g_subKey); + subKey += "\Navigation"; + if (key.Open(HKEY_LOCAL_MACHINE, subKey.c_str())) { + DWORD viewIcon = 0; + if (key.Query("ViewIcon", REG_DWORD, reinterpret_cast(&viewIcon), sizeof(viewIcon))) { + this->viewIcon = viewIcon; + } + } +} + +// OFFSET: 0x00B9C020 +// FUNCTION: fn_19618 +float NavigationManager::FitToSquare(int* offsetX, int* offsetY, int width, int height, float size) const { + float scale; + if (width > height) { + scale = size / width; + *offsetY = static_cast((width - height) * 0.5f * scale); + *offsetX = 0; + } else if (width < height) { + scale = size / height; + *offsetX = static_cast((height - width) * 0.5f * scale); + *offsetY = 0; + } else { + *offsetY = 0; + scale = size / width; + *offsetX = 0; + } + return scale; +} diff --git a/Source/Utility/RegistryKey.h b/Source/Utility/RegistryKey.h index 6e5378a..a7f0dd6 100644 --- a/Source/Utility/RegistryKey.h +++ b/Source/Utility/RegistryKey.h @@ -5,6 +5,14 @@ class RegistryKey { public: + RegistryKey() : handle(nullptr) {} + ~RegistryKey() { + if (this->handle != nullptr) { + RegCloseKey(this->handle); + } + this->handle = nullptr; + } + /* 0000 */ HKEY handle; bool Create(HKEY parent, const char* subKey); diff --git a/data/compile.json b/data/compile.json index c678a1c..07ca124 100644 --- a/data/compile.json +++ b/data/compile.json @@ -364,6 +364,7 @@ "Source/Contents/MovementRouteInterpolation.cpp": 4, "Source/Contents/Movies/BinkMovie.cpp": 3, "Source/Contents/Movies/BinkMovies.cpp": 3, + "Source/Contents/NavigationRoute.cpp": 4, "Source/Contents/NavigationSource.cpp": 4, "Source/Contents/Party/AdvenPartyInfo.cpp": 4, "Source/Contents/Party/AdventurerAgencyMgr.cpp": 4,