Muchaszewski / VoidCrew_RemoveAllComponents

Other
3 stars 0 forks source link

Remove All Components does Bad Things if a client has it and the host doesn't. #1

Open ShadowDragon8685 opened 10 months ago

ShadowDragon8685 commented 10 months ago

Remove All Components can be used as a griefing tool, in the worst-case scenario, if the clients have this mod and the host does not.

If the client has Remove All Components installed and the host doesn't, then the disassembly levers are shown to the client on a ship's default installations. If the client then attempts to pull out one of these installations, the lever will attempt to pull out, then it will show the client an "Error: Unable to build here" message.

Thereafter, that installation will be bugged: it will not be able to be turned on by anyone, whether the client with the mod, or any other player, but it will not be able to be removed by anyone, essentially becoming a dead slot.

The ideal fix, presuming that it's totally impossible and/or undesirable, to get a modded client game to convince an unmodded host game to allow the deconstruction, would be to check to see if the player is the client; and if so, not show them the removal lever unless the host also have the mod installed. Failing that, not showing the levers if the modded player is only a client would be satisfactory.

Muchaszewski commented 10 months ago

Thanks for detailed report, unfortunately this might be completely out of scope of this mod. Generally modded clients will always be a tool to grief other players.

The ideal solution is having a proper mod loader/api, which might be created if the community will grow. Then generally it's the mod loader/mod API to detect if all clients have mods and prevent connecting with other players.

Doing such work in this mod will make it overly complex. I generally recommend you go to thunderstore discord and vote there for a category on their page. This would incentive the community to create such tool.

Other avenue would be for the game developers to do proper API and make them add if the client is modded or not. Eg: by detecting Bepeinex and checking mods that are installed.

For now I assign this as won't fix but might look into simple solutions to this problem.

18107 commented 9 months ago

You could add && PhotonNetwork.IsMasterClient to the end of line 19. This removes the ability from clients to remove components when the host has the mod, but prevents accidental griefing if the host doesn't have the mod.

Alternatively, the below code could be used.


[HarmonyPatch]
    internal class AbstractModuleMediatorPatch
    {
        static MethodBase TargetMethod()
        {
            return typeof(AbstractModuleMediator<CellModule>).GetMethod("InitializeDeconstructButton", BindingFlags.NonPublic | BindingFlags.Instance);
        }

        static void Prefix(AbstractModuleMediator<CellModule> __instance)
        {
            if (__instance.Module?.BuildingConstraints?.allowDeconstruction == false && PhotonNetwork.IsMasterClient)
            {
                __instance.Module.BuildingConstraints.allowDeconstruction = true;
            }
        }
    }```