diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..0e168fee --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +0.1.0 (in development) +------------------------------------------------------------------------ +- Feature: Towns can now always be renamed (As seen in OpenTTD). +- Feature: Playable in a resizable window. diff --git a/src/openloco/interop/hooks.cpp b/src/openloco/interop/hooks.cpp index ecc4f3c1..f114ae6c 100644 --- a/src/openloco/interop/hooks.cpp +++ b/src/openloco/interop/hooks.cpp @@ -48,6 +48,13 @@ void register_hooks() return 0; }); + register_hook(0x00498E9B, + [](registers ®s) -> uint8_t + { + openloco::ui::windows::sub_498E9B((openloco::ui::window *)regs.esi); + return 0; + }); + // Remove the set window pos function, we do not want it as it // keeps moving the process window to 0, 0 // Can be removed when windowmgr:update() is hooked diff --git a/src/openloco/openloco.cpp b/src/openloco/openloco.cpp index 69c17c79..f7982c35 100644 --- a/src/openloco/openloco.cpp +++ b/src/openloco/openloco.cpp @@ -63,6 +63,11 @@ namespace openloco return glpCmdLine; } + bool is_editor_mode() + { + return (_screen_flags & screen_flags::editor) != 0; + } + bool is_paused() { return paused_state; diff --git a/src/openloco/openloco.h b/src/openloco/openloco.h index 5752a25c..dc0a9b1c 100644 --- a/src/openloco/openloco.h +++ b/src/openloco/openloco.h @@ -16,6 +16,8 @@ namespace openloco void * hInstance(); const char * lpCmdLine(); + bool is_editor_mode(); + bool is_paused(); void prompt_tick_loop(std::function tickAction); void sub_48A18C(); diff --git a/src/openloco/openloco.vcxproj b/src/openloco/openloco.vcxproj index 7a856458..75bbf41d 100644 --- a/src/openloco/openloco.vcxproj +++ b/src/openloco/openloco.vcxproj @@ -33,6 +33,7 @@ + diff --git a/src/openloco/windowmgr.h b/src/openloco/windowmgr.h index fc3bbbed..1ad55793 100644 --- a/src/openloco/windowmgr.h +++ b/src/openloco/windowmgr.h @@ -42,8 +42,12 @@ namespace openloco::ui::windows save = 2 }; + window * open_town_window(uint16_t townId); + void sub_498E9B(window * w); + bool prompt_browse(browse_type type, char * path, const char * filter, const char * title); bool prompt_ok_cancel(string_id okButtonStringId); + } namespace openloco::ui::textinput diff --git a/src/openloco/windows/townwnd.cpp b/src/openloco/windows/townwnd.cpp new file mode 100644 index 00000000..421f5440 --- /dev/null +++ b/src/openloco/windows/townwnd.cpp @@ -0,0 +1,29 @@ +#include "../interop/interop.hpp" +#include "../openloco.h" +#include "../windowmgr.h" + +namespace openloco::ui::windows +{ + // 0x00498E9B + void sub_498E9B(window * w) + { + w->enabled_widgets |= 2; +#ifdef _DISABLE_TOWN_RENAME_ + if (is_editor_mode()) + { + w->enabled_widgets &= ~2; + } +#endif + } + + // 0x00446F6B + // dx: townId + // esi: {return} + window * open_town_window(uint16_t townId) + { + registers regs; + regs.dx = townId; + LOCO_CALLPROC_X(0x00446F6B, regs); + return (window *)regs.esi; + } +}