Hooks in "UpdatePlacement" (when Rust checks if a player can build)Suggestion

Heyho!

Is it possible to override the test/check methods inside the Component.UpdatePlacement(...) method (used for placement e.g.: foundations)? [maybe wrong section, sorry if thats the case]

What I want to achieve:
When a player has a certain permission (or some other conditions are allowing him to), he sould be able to "ignore" placement errors like "Placing through rock" or "Too close to another building". Unfortunately, I didn't find anything to allow such behaviour (if I just was completely blind, ignore the stuff below and please tell me how to do this ^^).

Looking through Rust using dnSpy, I found the method mentioned above. Could you add hooks to override the default behaviour? Something like this probably (I'm not exactly sure how the "hooks" should look like or if it is "easy" to implement):

...
if (!this.TestPlacingThroughRock(ref placement, target) && !Hook_PlacingThroughRock(ref placement, target)){
    ...
    //if true, building would be blocked
}
...
if (global::BuildingProximity.Check(target.player, this, placement.position, placement.rotation) && Hook_BuildingProximityCheck(target.player, this, placement.position, placement.rotation)){
    ...
    //if true, building would be blocked
}
...

If thats not possible (like if you "just insert IL code" when nescessary or at the beginning of a method), maybe this could be an alternative:

Construction.cs:

private bool TestPlacingThroughRock(ref global::Construction.Placement placement, global::Construction.Target target) {
    bool? hookResult = Hook_TestPlacingThroughRock(ref placement, target); //null - no hook, true/false - hook result
    if(hookResult != null)
        return (bool)hookResult;
   ...
}

BuildingProximity.cs:

public static bool Check(global::BasePlayer player, global::Construction construction, Vector3 position, Quaternion rotation) {
    //same scheme as above
    ...
}

(for the other (not mentioned) methods called inside the "UpdatePlacement" method something like this would be also great)

Also I dont know how the client would behave if this logic was changed. But.. lets try?

Sorry for the delay in providing a reply. Some of those checks may be handled client-side as well, so I'm unsure if those particular ones would work how you'd like. I can try adding something to test with, but no guarantees.

Were you wanting just those two particular areas?
No problem, in these times we have all the time :)

All would be great, but I think not all are nescessary. I'll provide you a prioritized list down below (from high to low):

bool BuildingProximity.Check
bool DeployVolume.Check
bool Construction.TestPlacingCloseToRoad
bool BasePlayer.IsBuildingBlocked
- there are multiple methods but the one used by construction is (Vector3, Quaternion, Bounds)
bool Construction.TestPlacingThroughRock
bool Construction.TestPlacingThroughWall
Would a single check suffice?

Technically yes, but then I wouldn't know which "error" would normally occur ... unless I "copy/paste" the code from dnSpy.
It is definitely an option tho.

Merged post

Hey Wulf, how can I get my hands on this - could you release a Test-Build?
5e8210c5f386b.jpg Rurido
Hey Wulf, how can I get my hands on this - could you release a Test-Build?

It was in a build, but it was causing an issue that we haven't been able to fix yet.

That's unlucky. Any way to assist you? [No pressure ;)]
Probably not. The hook location should have worked, but for some reason is causing an error. This hasa been an issue with the patcher before, so it may be something that needs to get fixed in the patcher, else possible settle for a different hook location.
Does the patching fail or is there an error when running the game/mod?
There's an error when running the server due to the IL.

What would I need to patch, build and test oxide locally?

I found your injection code (removed) in commit 74aa59a7b821994be5cf3ff9588bf8ee1d5a2e8a. If I edit the Rust.obj, how would I patch the dlls? Also you mentioned that there may be an issue with the patcher - which script does the patching/how would I get it running?

If its too much to explain then nvm, but I think/hope I could help.

Any updates?

If the hook you created doesnt work on this position, could you try to add it before "!target.valid" or after "common.FindMaleSockets(target, list);"?
If this still doesnt work, could you add the hook at the locations mentioned earlier?

5e8210c5f386b.jpg Rurido
No problem, in these times we have all the time :)

All would be great, but I think not all are nescessary. I'll provide you a prioritized list down below (from high to low):

bool BuildingProximity.Check
bool DeployVolume.Check
bool Construction.TestPlacingCloseToRoad
bool BasePlayer.IsBuildingBlocked
- there are multiple methods but the one used by construction is (Vector3, Quaternion, Bounds)
bool Construction.TestPlacingThroughRock
bool Construction.TestPlacingThroughWall
Sorry, no changes yet and unsure when there will be.