Skip to content

Conversation

@clansty
Copy link
Member

@clansty clansty commented Jan 7, 2026

No description provided.

@cursor
Copy link

cursor bot commented Jan 7, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on February 11.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@gemini-code-assist
Copy link

Summary of Changes

Hello @clansty, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the input system by introducing hot-plugging support for ADX HID devices. This allows the application to dynamically detect and manage device connections and disconnections, improving resilience and user convenience. The changes involve a refactoring of the device handling logic, making it more robust against device state changes.

Highlights

  • Hot-plugging functionality: Introduced the ability for ADX HID input devices to be connected and disconnected dynamically while the application is running, enhancing user experience and flexibility.
  • Enhanced Device Management: Implemented new utility methods (TryConnectDevice, IsDeviceAvailable, DisconnectDevice, NeedsButtonInput) to centralize and improve the robustness of HID device handling.
  • Robust Input Thread: The HidInputThread has been refactored to continuously monitor device availability, attempt reconnection, and gracefully handle disconnections, preventing input failures.
  • Improved Thread Lifecycle: Ensured that only one input thread runs per player and configured these threads as background threads for better application stability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces hot-plug support for ADX HID controllers, which is a great feature. The implementation is mostly solid, with background threads handling device connection, disconnection, and input reading. I've identified a few areas for improvement regarding code clarity, robustness, and efficiency. My suggestions include replacing magic numbers with constants, improving exception handling to avoid swallowing errors silently, removing a redundant check, and reducing CPU usage in a polling loop.

Comment on lines +38 to +40
var device = p == 0
? HidDevices.Enumerate(0x2E3C, [0x5750, 0x5767]).FirstOrDefault(it => !it.DevicePath.EndsWith("kbd"))
: HidDevices.Enumerate(0x2E4C, 0x5750).Concat(HidDevices.Enumerate(0x2E3C, 0x5768)).FirstOrDefault(it => !it.DevicePath.EndsWith("kbd"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Vendor IDs (e.g., 0x2E3C) and Product IDs (e.g., 0x5750) are hardcoded as magic numbers. Using named constants for these values would significantly improve code readability and maintainability. I recommend defining constants for these IDs at the class level and using them here and in the NeedsButtonInput method.

Comment on lines +56 to +63
try
{
return device.IsConnected;
}
catch
{
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching a generic Exception and silently returning false can hide unexpected errors and make debugging difficult. It's better to catch a more specific exception if the HidLibrary provides one. If not, at least log the exception to aid in troubleshooting.

        try
        {
            return device.IsConnected;
        }
        catch (Exception e)
        {
            MelonLogger.Warning($"[HidInput] Error checking device {p + 1}P connection: {e.Message}");
            return false;
        }

Comment on lines +71 to +78
try
{
device.CloseDevice();
}
catch
{
// ignore
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to other try-catch blocks in this file, catching a generic Exception is not ideal. Even if the intention is to ignore the error (as the device is likely disconnected), logging the exception can be valuable for debugging unexpected behavior.

        try
        {
            device.CloseDevice();
        }
        catch (Exception e)
        {
            // It's likely the device was already disconnected, but we log it just in case.
            MelonLogger.Warning($"[HidInput] Error closing device {p + 1}P: {e.Message}");
        }

Comment on lines +95 to +102
try
{
return device.Attributes.ProductId is not (0x5767 or 0x5768);
}
catch
{
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This try-catch block catches a generic Exception and silently returns false, which can mask underlying problems. It's better to log the exception for debugging purposes, similar to the suggestions for IsDeviceAvailable and DisconnectDevice.

        try
        {
            return device.Attributes.ProductId is not (0x5767 or 0x5768);
        }
        catch (Exception e)
        {
            MelonLogger.Warning($"[HidInput] Error reading attributes for device {p + 1}P: {e.Message}");
            return false;
        }

if (device == null) return false;
try
{
return device.Attributes.ProductId is not (0x5767 or 0x5768);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These hardcoded product IDs (0x5767, 0x5768) should be replaced with named constants for better readability and maintainability, as mentioned in the comment for the TryConnectDevice method.

Comment on lines +115 to +119
if (!NeedsButtonInput(p))
{
var newState = report1P.Data[i];
if (newState == 1 && inputBuf[p, i] == 0)
Thread.Sleep(500);
continue;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When a connected device does not require button input, the thread enters a polling loop, sleeping for 500ms and then re-checking the device status. This is inefficient and consumes CPU resources unnecessarily. Consider increasing the sleep duration to reduce the polling frequency and lower the performance impact.

            if (!NeedsButtonInput(p))
            {
                Thread.Sleep(2000); // Increase sleep time to reduce CPU usage
                continue;
            }

@clansty clansty merged commit ae5f092 into main Jan 7, 2026
2 checks passed
@clansty clansty deleted the adxHotPlug branch January 7, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants