Alexander-Lancellott / MHGU-MHXX-HP-Overlay-For-Switch-Emulator

A simple open-source HP overlay that I've developed for MHGU and MHXX Switch Version in Python.
https://ko-fi.com/alexander_lancellott
GNU General Public License v3.0
6 stars 0 forks source link

MHGU-MHXX-HP-Overlay-For-Switch-Emulator

[![StaticBadge](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/) [![App](https://img.shields.io/badge/App-1.0.0-green)](https://github.com/Alexander-Lancellott/MHGU-MHXX-HP-Overlay-For-Switch-Emulator)

Description

A simple open-source HP overlay that I've developed for MHGU and MHXX Switch Version in Python. This project is a port of another one I previously created called MH-HP-Overlay-For-3DS-Emulator, but this time it's designed to work with Switch emulators, such as Ryujinx and Y***, Suda*** or S***, on their PC (Windows) versions.

This overlay uses an AOB (Array of Bytes) scan to locate the memory addresses where each monster's HP values are stored. In my previous project, I was able to use pointers, which is much more efficient and less prone to errors. However, for this project, I had to resort to using AOB scanning because Ryujinx and Y*** do not provide tools to access the game's emulated memory in an orderly and easy manner, as Citra does with a Python script developed by the Citra team that allows external access to the emulated memory with minimal complications. As mentioned earlier, AOB scanning is inefficient because it scans every byte of the entire emulator's memory to find a match for the given pattern. To mitigate this, I reduced the load of this scan by first identifying the memory region where the monsters' HP values are stored and limiting the scan size to that specific chunk of memory instead of scanning the entire emulator memory. Additionally, to minimize the impact on CPU and RAM performance, I created a Python module written in C, which not only reduced the performance impact but also increased execution speed.

I am not sure if the specific memory region used to limit the scan might change in future versions of the emulators. Therefore, in the compatibility list, besides listing the versions of the games I have tested, I will also include a list of the latest version of each emulator that I have confirmed to work with the overlay.

Although I've conducted numerous tests, the overlay may still contain some bugs that I haven't detected. If you encounter any issues, I would appreciate it if you could report them by opening an issue and providing any evidence that allows for replication.

You can support me by donating! I’d really appreciate it. But either way, thank you for using this mod!

Buy Me a Coffee at ko-fi.com

Compatibility

I think I've managed to make the overlay compatible with the base version and the latest update of MHGU and MHXX. Below is a list of the versions where I tested and confirmed that the overlay works correctly:

Below, I also include a list of the version of each emulator in which I have confirmed the overlay works correctly.

High DPI Scaling (optional, only if you notice it)

If your monitor has a resolution higher than 1080p, it's likely you're using a DPI scale above 100%. In this case, the initial position of the overlay may not be the same as when using 100% scaling. To mitigate this, you have three options:

How to use

To use the overlay, simply open the MHGU-MHXX-HP-Overlay.exe file.

If one of the games from the compatibility list isn't running in the emulator, you will see a red message in the overlay console saying No game running and a countdown starting from 20 minutes. When the countdown reaches zero, the overlay will automatically close to save resources.

No game running

Otherwise, if one of the games from the compatibility list is running in the emulator, you will see a green message in the overlay console indicating which of the compatible games is currently running.

Game running

If everything works correctly, upon starting a hunting mission, you should see labels arranged one below the other, displaying the monster's name along with its HP in the top right corner of the game window.

![Labels](https://res.cloudinary.com/dms5y8rug/image/upload/c_thumb,g_face,q_auto:best/MH-HP-Overlay/labels.png)

If you don't like the color of the overlay or its position in the top right corner of the window, go directly to the Customize Overlay section to edit it to your liking. However, I recommend that you continue reading this section first.

Borderless screen system & Native full-screen mode

The full-screen mode in the latest versions of the Ryujinx and Y*** emulators allows the overlay to be visible. However, in Ryujinx LDN 3.1.3, you'll notice that the overlay is not visible in this mode. To address this, I developed a borderless screen system that closely resembles the native full-screen mode of the emulator. This system can be toggled on or off using a keyboard shortcut, which is set to Ctrl + Alt + F by default. To exit this mode, simply press the same shortcut again.

It’s important not to confuse this shortcut with the emulator's native shortcut for switching to full-screen mode, which is usually F11 by default. If you want to change the default keyboard shortcut for the overlay, you can do so by referring to the Hotkey subsection.

Transition

Please note that, by default, if you use the overlay’s borderless screen system, the toolbar and the bottom bar of the emulator will still be visible. This differs from the native full-screen mode of the emulator. To achieve a full-screen experience identical to the native one in Ryujinx LDN 3.1.3, you need to go to the Actions menu in the toolbar, click on Hide UI to hide both bars, and then modify the config.ini file to set the emu_hide_ui option from false to true. Remember to close and restart the overlay, and you can then use Ctrl + Alt + F to achieve a native full-screen appearance.

For the latest versions of Ryujinx and Y***, you shouldn't have any issues using either the emulator's native full-screen mode or the overlay's borderless screen system. However, if you want to use the borderless screen system in Y*** and hide the bars, go to the View menu in the toolbar and disable the Single Window mode option, which will display another window without the bars.

Native full-screen mode
Full-screen
Borderless screen system
Borderless

Customize Overlay

Inside the root folder, there is a file called config.ini, which stores the values for options that can be edited using a text editor like Notepad++ to customize the overlay.

It's important to close and reopen the overlay each time you edit this file for the changes to take effect.

Below, you will find sub-sections dedicated to documenting each of the available options in the config.ini.

Hotkey

The config.ini file includes the hotkey option, which defines the keyboard shortcut used to toggle the borderless screen system on/off. By default, this shortcut is Ctrl + Alt + F. You can replace it with another shortcut if the default one is inconvenient for you.

It's important to note that special keys such as Ctrl, Shift, or Alt are represented by specific symbols. It's recommended to refer to the following documentation to ensure you're using the correct symbols when editing the shortcut. The symbols *, ~, $ aren't allowed.

Remember to close and reopen the overlay after making changes to the config.ini file for these adjustments to take effect.

Option Default value Type Observation
hotkey ^!f string Must be valid hotkey, check this: https://www.autohotkey.com/docs/v1/Hotkeys.htm#Symbols

Debugger

If the debugger option in the config.ini file is set to true, a .log file will be generated where all application logs will be stored. This option is intended solely for testing and troubleshooting, so its default value is false.

Option Default value Type Observation
debugger false boolean This is case-insensitive and recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'

Font

Within the config.ini file, you can customize the type, weight, and size of the font used in the overlay by editing the following options:

Make sure to use Web Safe Fonts and to close and reopen the overlay after making changes in the config.ini file for these adjustments to take effect.

Option Default value Type Observation
font_family Consolas, monaco, monospace string This is a CSS property and must be a Web Safe Font
font_weight bold string This is a CSS property
font_size 18 integer This is a CSS property, its value is in pixels and must be greater than or equal to 1

Max Workers

The max_workers option in the config.ini file allows you to adjust the maximum number of threads that will parallelize the load and execution of the AOB scan for faster and more efficient CPU performance. The default value is 2, which should be sufficient in most cases. If your CPU doesn't have very powerful cores, you might consider increasing this value, but even then, performance improvements cannot be guaranteed. The minimum value is 1, and the maximum is 16.

Option Default value Type Observation
max_workers 2 integer Must be greater than or equal to 1 and less than or equal to 16

HP update time

The hp_update_time option in the config.ini file allows you to adjust the HP value update interval in seconds. The default value is 0.8, which is equivalent to 800 milliseconds, and the minimum value is 0.1.

You can modify this value to increase or decrease the time interval for updating the HP value. Higher values will increase the update interval and may improve performance since this overlay uses an AOB scan. If you notice high CPU usage when using it, consider increasing this value. On the other hand, if you have a powerful CPU, you might consider lowering the value to reduce the HP update interval if the default seems too slow.

Remember to close and reopen the overlay after making changes to the config.ini file for these adjustments to take effect.

Option Default value Type Observation
hp_update_time 0.8 float Must be greater than or equal to 0.1

Show Initial HP

The show_initial_hp option in the config.ini file allows you to show or hide each monster's maximum HP. Its default value is set to true.

Remember to close and reopen the overlay after making changes to the config.ini file for these adjustments to take effect.

Option Default value Type Observation
show_initial_hp true boolean This is case-insensitive and recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'

Show HP Percentage

The show_hp_percentage option in the config.ini file allows you to show or hide HP as a percentage for each monster. Its default value is set to true.

Remember to close and reopen the overlay after making changes to the config.ini file for these adjustments to take effect.

Option Default value Type Observation
show_hp_percentage true boolean This is case-insensitive and recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'

Show Small Monsters

The show_small_monsters option in the config.ini file determines whether the overlay will display all monsters, including small ones. By default, this option is set to true.

To display only large monsters, change the value of show_small_monsters to false.

Remember to close and reopen the overlay after making changes to the config.ini file for these adjustments to take effect.

Option Default value Type Observation
show_small_monsters true boolean This is case-insensitive and recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'

Show Size Multiplier & Crown

The show_size_multiplier and show_crown options in the config.ini file allow you to show or hide the size multiplier and crown of each monster.

![Size Multiplier & Crown](https://res.cloudinary.com/dms5y8rug/image/upload/c_thumb,g_face,q_auto:best/MH-HP-Overlay/size_multiplier_and_crown.png)
Option Default value Type Observation
show_size_multiplier true boolean This is case-insensitive and recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'
show_crown true boolean This is case-insensitive and recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'

Position (X & Y)

The x and y options within the config.ini file allow you to adjust the position of the overlay using Cartesian coordinates. These values are relative and percentage-based to the size of the target window, with a minimum range of 0 and maximum of 100 for each coordinate.

Adjust these values to move the overlay to the desired position on the screen.

Remember to close and reopen the overlay after making changes in the config.ini file for these adjustments to take effect.

Option Default value Type Observation
x 100 integer Must be greater than or equal to 0 and less than or equal to 100
y 0 integer Must be greater than or equal to 0 and less than or equal to 100
x = 100
y = 0
x-100
x = 0
y = 0
x-0
x = 0
y = 100
y-100

Fix X & Fix Y

The fix_x and fix_y options in the config.ini file allow you to adjust the position of the overlay in situations where modifying the x and y coordinates may not be sufficient. For example, if you want the overlay to extend outside the window to view it on a secondary monitor without obstructing the game's UI, or if changing the opacity or color isn't a solution for you, or when adjusting the x and y coordinates doesn't adequately address the overlay's placement.

Remember to close and reopen the overlay after making changes in the config.ini file for these adjustments to take effect.

Option Default value Type Observation
fix_x 0 integer It must be any integer, whether positive or negative, its value is in pixels
fix_y 0 integer It must be any integer, whether positive or negative, its value is in pixels
fix_x = 0 fix_x = 500
fix-y-0 fix-y-10

Align

Within the config.ini file, the align option controls the alignment of labels in the overlay. When set to true, all labels will adjust their width to match the width of the largest label.

This ensures a consistent and orderly presentation of labels in the overlay interface.

Remember to close and reopen the overlay after making changes to the config.ini file for these adjustments to take effect.

Option Default value Type Observation
align true boolean This is case-insensitive and recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'
align = true align = false
labels align

Orientation

The orientation option within the config.ini file allows you to define the position of content within the labels. You can configure this option with one of the following values:

Remember to close and reopen the overlay after making changes in the config.ini file for these adjustments to take effect.

Option Default value Type Observation
orientation center string Must be center, left or right
align = true align = false
orientation = center orientation = left orientation = right
labels left right

Emulator Hide UI

The emu_hide_ui option in the config.ini file, when set to true, allows you to remove the top and bottom margins of the overlay. This is useful if these margins are bothersome when the toolbar and bottom bar of the emulator are no longer visible and you want a native fullscreen experience. Its default value is set to false.

Remember to close and reopen the overlay after making changes in the config.ini file for these adjustments to take effect.

Option Default value Type Observation
emu_hide_ui false boolean This is case-insensitive and recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'

Color

Within the config.ini file, you can customize the color of text and background in the overlay labels, as well as their opacity. The available options are as follows:

Adjust these values according to your preferences to customize the visual appearance of the overlay.

Remember to close and reopen the overlay after making changes in the config.ini file for these adjustments to take effect.

Option Default value Type Observation
text_color aquamarine string Must be a CSS SVG Color
background_color darkslategray string Must be a CSS SVG Color
text_opacity 100 integer Must be greater than or equal to 1 and less than or equal to 100
background_opacity 60 integer Must be greater than or equal to 1 and less than or equal to 100

Building - (For Developers)

$ git clone
$ python -m venv .venv
$ .venv\Scripts\activate
$ pip install .
$ build

You will find the build in the build/dist folder

Python modules used