Addon Interoperability

I’ve been wondering, in Garry’s Mod we’ve always been able to make addons work with/depend on each other, simply because they’re all in the same space. Addon X can access the global tables on Addon Y, maybe even depend on them.

Now, will that be possible on S&box? Would I be able for instance to make a framework for other developers to use and create addons that depend on it? Would multiple addons be able to use said framework at the same time?

Edit: I’ll give an example of this. Let’s say I have my addon which adds a super cool attribute called FrameworkAttribute. Other addons want to use it to add it to their methods. Can these addons reference my framework’s assembly in order to be able to do this:

using MyFrameworkAddon;

[Framework]
public class SomeOtherAddon
{
    public void DoStuff()
    {
        Console.WriteLine("Hey, this addon uses FrameworkAttribute from MyFrameworkAddon!");
    }
}
6 Likes

Good question.
I wonder how that worked in GMod. Wire Mod for example was able to control pretty much everything in the game.

2 Likes

C# packages have what is called public API defined by developer that can be accessed from other parts of code. S&box addons will be the same. Private code of addons should not be accessed, although there can be some detour ways.

3 Likes

That’s not the question, I’m aware of accessors, the question is addons depending on others or a framework via assembly references.

2 Likes

Well, I forgot that addons can also include media content files. There are problems with the way Garry’s Mod handles file dependency:

  1. If some addon requires files from other addon, this file can also be redefined by third addon, because the way to access these files is made through the global filesystem. I think there should be a way to access addon files directly to allow private/public behaviour.
  2. What file will have higher priority if two addons have two different files with the same path/name?
2 Likes

Again, not media content files, other assemblies (i.e. third party libraries, or other S&box addons, accessing the same DLL for a library).

My goal is to make an addon that acts as a framework for other addons to use, I need to know if that’s feasible. The framework wouldn’t depend on any other addons, but other addons might depend on it for example.

2 Likes

I was wondering how this will work too. Will s&box generate some reference assemblies that we add?

2 Likes

I suppose so, at least to interact with S&box, I doubt that’s gonna be hard. The hardest imo would be to interop with other addons. I don’t know how that’ll work, and I hope they figured something solid out for it because working with other devs/addons sounds pretty fun.

2 Likes

I think the idea is we extend our classes off of addon classes and call base stuff when we want the parent class’s stuff to run. Other addons we might not even care about extending—just let them do their thing

dm98 code uses partial classes so maybe we can add our own stuff to other addons within our own addons, but that might be a bad idea

2 Likes

Yeah that doesn’t sound very clean to me

1 Like

partial classes dont work that way and the question is more like how addons can reference other addon code in a strong typed language like C#

3 Likes

I also don’t like the use of partial classes that way, I’ve never actually found a good reason to use them in the past.

In any case, I hope a dev on S&box’s team has an answer, I’d love to start writing game agnostic frameworks and port them to S&box in the future as long as we have at least a good idea of what’s going to be allowed or not code wise, and how referencing other addons is going to be.

3 Likes

Alright I’m going to answer this myself after some digging on the Discord, I’m just overthinking it. Addons can depend on others as seen in Garry’s DM98 gamemode repo.

I’m going to assume S&box is going to handle all the dependencies when it compiles the source code of addons.

2 Likes

Possibly, but it’d be nice to have a way to reference assembly metadata so we get intellisense and stuff

4 Likes

As long as we can directly reference built addon DLLs in our code Intellisense should work. Question is, will S&box allow that/be able to handle that.

2 Likes

Is there any reference that addons will be compiled to DLLs? Because I highly doubt that, I think addons will be stored as pure scripts and compiled at runtime similarly to plugins in Rust.

2 Likes

They will be compiled to DLLs and sent to the clients when they join from what I’ve seen. For Intellisense an assembly reference to another addon is probably the easiest solution.

2 Likes

Maybe we’ll have to add a VS plugin to be able to just “add references” to sbox addons

2 Likes

What if you just pull addons from github and add them as projects so you can use them as references