harbingerofme / DebugToolkit

Debugging commands for Risk of Rain 2. Previously known as RoR2Cheats.
https://thunderstore.io/package/IHarbHD/DebugToolkit/
BSD 3-Clause "New" or "Revised" License
14 stars 8 forks source link

Add New Command: interact_range #145

Open Foretack opened 1 year ago

Foretack commented 1 year ago

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 commented 1 year ago

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);
        }
    };
}