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

Add New Command: interact_range #145

Open
Foretack opened this issue Aug 18, 2023 · 1 comment
Open

Add New Command: interact_range #145

Foretack opened this issue Aug 18, 2023 · 1 comment

Comments

@Foretack
Copy link

Describe your new command

The command should allow the user to modify the range of which they can interact with chests, shrines, printers etc...

Use cases

A lot of bodies used with spawn_as practically do not have an interaction range. For example, if you spawn_as Mithrix, the only thing you can interact with is tri-shops, and you have to be standing inside them too. Mithrix' body is too large for the player to be able to interact with anything. Many other bodies suffer from this, like Clay Dunestrider, Stone Titan, Xi Construct, drones and pretty much any body that is not the size of a playable character. This command would solve the issue for all these bodies, for any user that wishes to play as them.

@Foretack
Copy link
Author

Foretack commented Aug 18, 2023

I tried to implement this myself, but this is as far as I got:

[ConCommand(commandName = "interact_range", flags = ConVarFlags.ExecuteOnServer)]
public static void CCInteractRange(ConCommandArgs args)
{
    IL.RoR2.InteractionDriver.FindBestInteractableObject += (ilc) =>
    {
        var cursor = new ILCursor(ilc);

        bool found = cursor.TryGotoNext(
            x => x.MatchLdarg(0),
            x => x.MatchCallOrCallvirt<InteractionDriver>("get_interactor"),
            x => x.MatchLdfld<Interactor>("maxInteractionDistance"),
            x => x.MatchStloc(3)
        );

        if (found)
        {
            cursor.Emit(OpCodes.Ldarg, 0);
            cursor.Emit(OpCodes.Ldloc, 3);
            // EmitDelegate ?
            cursor.Emit(OpCodes.Stloc, 3);
        }
    };
}

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

No branches or pull requests

1 participant