Facepunch / sbox-issues

175 stars 12 forks source link

Tools in a Game project #2616

Closed gio3k closed 9 months ago

gio3k commented 1 year ago

For?

S&Box

What can't you do?

Have tool code in a gamemode without separating them

I'd like to make Hammer tools / editors just for the specific gamemodes they would be used for

How would you like it to work?

Allow tool code in gamemodes

What have you tried?

Putting tool code in a gamemode (did not work)

Additional context

No response

LeQuackers commented 1 year ago

Wouldn't #2228 solve this? Why don't you want to separate them?

Adesii commented 1 year ago

This sounds like a bad idea.. since tool addons dont have a whitelist you are able to do anything in c#. So combining both would defeat the purpose of the gamemode whitelist. Referencing games from tools would be great tho.

gio3k commented 1 year ago

2228 does sound like the way to go, but I'm not sure about having a whole tool addon for a small gamemode specific tool (what if I just want a feature or two in Hammer?)

since tool addons dont have a whitelist you are able to do anything in c#.

That's interesting to know. Maybe bundling the tools with the gamemode without compiling them as one would be a better option?

I'll close this for now but I'm still not sure

gio3k commented 1 year ago

Reopening - this is a big pain point for me right now

I feel like you all misunderstood what I mean here (maybe I explained badly) - I don't mean compile the game & tool into one assembly... I just want the tool to compile with and reference the game and run in the same load context.

Wouldn't https://github.com/sboxgame/issues/issues/2228 solve this? Why don't you want to separate them?

No, it wouldn't solve it, not fully at least - while yes, you would be able to use types from your tool, you wouldn't be able to do anything with them and vice versa - they're in different load contexts and you can't do anything with them without reflection hell, so what's really the point? You could just share the files between them (which is horrendous for other reasons)

This sounds like a bad idea.. since tool addons dont have a whitelist you are able to do anything in c#.

This isn't a problem. Yes tool addons don't have a whitelist, but the game and tool wouldn't be compiled into 1 assembly anyways - access control could just look through the compiled game assembly.

And even if that was a bigger issue... you're using the tools API - where you can access every part of the game internally anyways. You could restart the computer if you wanted! You're opening yourself up to that already if you're using tools.

DoctorGurke commented 1 year ago

I don't think in the grand scheme of things it's too much to ask to be able to make dedicated custom tools for game projects and properly use and access all relevant references. On a similar note, tools cannot access the organization FileSystem, which further blocks such systems.

handsomematt commented 9 months ago

You can make an Editor folder in your game project now