SmartlyDressedGames / Legally-Distinct-Missile

Fork of Rocket for Unturned maintained by the game developers.
MIT License
79 stars 29 forks source link

Newest dependency not loading #49

Closed Sl4vP0weR closed 2 years ago

Sl4vP0weR commented 2 years ago

If we try to use dependency SomeLibrary.dll with version 4.0.1.0 for plugin Rocket.Core will throw FileNotFound exception for SomeLibrary.dll with version 4.0.2.0 in the Libraries folder. Fixes in Rocket.Core/Plugins/RocketPluginManager.cs:

private Dictionary<AssemblyName, string> _libraries => libraries.ToDictionary(x => new AssemblyName(x.Key), x => x.Value);
private Assembly LoadLibrary(string fullname)
{
    try
    {
        var name = new AssemblyName(fullname);
        var libs = _libraries.Where(x => x.Key.Name == name.Name);
        var lib = libs.FirstOrDefault(x => x.Key.Version >= name.Version);
        return Assembly.Load(File.ReadAllBytes(lib.Value));
    }
    catch { }
    Logging.Logger.LogError("Could not find dependency: " + fullname);
    return null;
}
//update this method
private void Awake() {
  AppDomain.CurrentDomain.AssemblyResolve += delegate (object sender, ResolveEventArgs args)
  {
      return LoadLibrary(args.Name);
  };
}

Better optimization:

private Dictionary<AssemblyName, string> _libraries = new Dictionary<AssemblyName, string>();
//update this method
private void loadPlugins()
{
    libraries = GetAssembliesFromDirectory(Environment.LibrariesDirectory);
    foreach (var pair in GetAssembliesFromDirectory(Environment.PluginsDirectory))
    {
        if (!libraries.ContainsKey(pair.Key))
            libraries.Add(pair.Key, pair.Value);
    }
    _libraries = libraries.ToDictionary(x => new AssemblyName(x.Key), x => x.Value);
Trojaner commented 2 years ago

OpenMod handles this in a much cleaner way, consider switching to it

Sl4vP0weR commented 2 years ago

OpenMod handles this in a much cleaner way, consider switching to it

Servers with OpenMod is loading twice longer cause of NuGet packages. RocketMod still most used module for Unturned game server. OpenMod not associated with this repository, please do not force OpenMod as a solution of any issue.

Sl4vP0weR commented 2 years ago

@SDGNelson

SDGNelson commented 2 years ago

I am hesitant to muck around in fundamental Rocket features like this. How important is it? i.e., what stops you from using the expected version?

Sl4vP0weR commented 2 years ago

I am hesitant to muck around in fundamental Rocket features like this. How important is it? i.e., what stops you from using the expected version?

Some plugins can use different versions of same library, they will conflict. We can rename libraries to use different versions of them, but if we using library that got deprecated versions ? Example with System.Threading.Tasks.Extensions and Microsoft.EntityFramework(EF) EF need to use some version of System.Threading.Tasks.Extensions, but if we want to use MySql with Pomelo.EntityFramework(it uses deprecated version of System.Threading.Tasks.Extensions)? Plugin will not load correctly, we need to put libraries in the Unturned_Data/Managed folder(I think it's not a correct solution).

Sorry for my bad problem describing, but it is what it is.

Sl4vP0weR commented 2 years ago

This update should not cause problems, but will fix dependencies loading bug.

Sl4vP0weR commented 2 years ago

@SDGNelson

negrifelipe commented 2 years ago

I am hesitant to muck around in fundamental Rocket features like this. How important is it? i.e., what stops you from using the expected version?

Some plugins can use different versions of same library, they will conflict. We can rename libraries to use different versions of them, but if we using library that got deprecated versions ? Example with System.Threading.Tasks.Extensions and Microsoft.EntityFramework(EF) EF need to use some version of System.Threading.Tasks.Extensions, but if we want to use MySql with Pomelo.EntityFramework(it uses deprecated version of System.Threading.Tasks.Extensions)? Plugin will not load correctly, we need to put libraries in the Unturned_Data/Managed folder(I think it's not a correct solution).

Sorry for my bad problem describing, but it is what it is.

You should move to openmod or patch how rm resolves the dependencies

SDGNelson commented 2 years ago

It's on the back of my mind to do. I had been intending for this most recent update to happen next Friday, but the sort by group request was high priority. This will probably happen in one of the next updates.

SDGNelson commented 2 years ago

This has been merged for Friday's update. If you would like to double-check it is pre-compiled in the Extras folder on the preview branch, or in this commit on the dev branch: https://github.com/SmartlyDressedGames/Legally-Distinct-Missile/commit/512a08c75779ec81d5c61238791792f077c5adcd

As far as I can tell it seems to be working fine, but my Rocket setup is very vanilla so it would be much appreciated if you could give it a try as well.

Sl4vP0weR commented 2 years ago

@SDGNelson Looks fine, but we forgot about sorting by version to get most close one.

SDGNelson commented 2 years ago

Glad that it seems to work okay. Thanks for checking. If the libraries are backwards compatible hopefully >= should be fine for now?

Sl4vP0weR commented 2 years ago

If the libraries are backwards compatible hopefully >= should be fine for now?

I don't think so, some versions of assemblies may be deprecated, so better to use closest version to dependency if it's exists.

SDGNelson commented 2 years ago

I made the initial change because it seems important for maintaining compatibility, but all these subsequent requests #51 #52 are outside the scope of this repository. For example I do not want to cause a kerfuffle if any plugins need to be recompiled for a .NET upgrade. The best option is probably to fork this repository to make any changes you want, and maybe there will be some other developers who want an actively updated/upgraded version of Rocket.

educatalan02 commented 2 years ago

This update broke alot of plugins.

SDGNelson commented 2 years ago

@educatalan02 are the plugins depending on a newer version than what is in the libraries folder? Or what seems to be the issue? I suppose perhaps if there is no >= version maybe it should fallback to an older version - but that might introduce its own problems?

negrifelipe commented 2 years ago

@SDGNelson Everything works fine for me, but how rocketmod handles/resolves the dependencies can be done in a much cleaner and better way. I know that its outside of the scope of this repo but i think it would have been better to rewrite how the plugin manager loads the plugins and handles the libraries

SDGNelson commented 2 years ago

@01-Feli agreed that both Rocket and the vanilla built-in loading is far from perfect. I suppose OpenMod is probably the best option in this regard.

negrifelipe commented 2 years ago

I think it is time to stop mataining rocketmod and start forcing people to rm progressively. There are a lot of good devs that might port a lot of rm plugins if people need them

Trojaner commented 2 years ago

This update broke some plugin loaders, but the fix is easy. If you reference the "libraries" field, make sure its a Dictionary<AssemblyName, string> now. Shouldn't take more than 5 minutes to fix.

Sl4vP0weR commented 2 years ago

@SDGNelson orderby version is important.

Sl4vP0weR commented 2 years ago

This update broke some plugin loaders, but the fix is easy. If you reference the "libraries" field, make sure its a Dictionary<AssemblyName, string> now. Shouldn't take more than 5 minutes to fix.

Nelson's fault. My code was better solution to not touch other assemblies.

negrifelipe commented 2 years ago

Yeah your code is the best especially this try catch block image

kulkaGM commented 2 years ago

Depends on the developer, everybody has own ways how to do certain things, so why roast somebody? (Im not gonna talk about the laugh emoji from Nelson and Trojaner, because.... uh.. okay i'll do it...)

This is how somebody shouldn't act to somebody especially when one is the main game developer and second is his best friend who does tell him what to do only because he's controlling OpenMod with support of the game dev... (Do you think Troj writed on Unturned discord in 8 past months?)
Oh also its good to force people to OpenMod when Trojaner based it for advertising himself and imperial (You don't think that? I don't see anything than only use this LOL). What about the OpenMod advertising? People will come somewhere to ask help with server problems [OM & Imperial Discord (its wierd when only Trojaner have the most toxic communities on the Unturned)] tell somebody what's the problem and the only what they will hear... "LMAO Don't use RocketMod its old OpenMod is better in someway!" Bruh nobody gives..... you know what. If RocketMod was that bad... people wouldn't use him.

Trojaner, you are good developer, but sometimes you don't think twice.

Basically this can be taken like my opinions, but a lot of people will se the thing here., that's like Rocket community sees things.

Trojaner commented 2 years ago

@kulkaGM

This is how somebody shouldn't act to somebody especially when one is the main game developer and second is his best friend who does tell him what to do only because he's controlling OpenMod with support of the game dev... (Do you think Troj writed on Unturned discord in 8 past months?)

Have you actually read what Sl4v wrote here? He is just rude at this point.

Nelson supports OpenMod because its the biggest community supported plugin framework for Unturned. Any other mature framework would have gotten the same support.

Oh also its good to force people to OpenMod when Trojaner based it for advertising himself and imperial

From the OpenMod Discord #faq channel:
image

Neither OpenMod nor the OpenMod Discord references ImperialPlugins anywhere. OpenMod does not advertise ImperialPlugins. They are completely separate projects. However ImperialPlugins advertises OpenMod a lot.

Also OpenMod is maintained by a collective, not just me. There are currently 22 contributors to it.

(You don't think that? I don't see anything than only use this LOL).

This can be disproven easily. There are currently more OpenMod plugins than RocketMod plugins (excluding broken ones): https://openmod.github.io/openmod-plugins/ vs. https://ldmcommunity.net/pluginlist/

People will come somewhere to ask help with server prolems [OM & Imperial Discord (its wierd when only Trojaner have the most toxic communities on the Unturned)] tell somebody what's the problem and the only what they will hear... "LMAO Don't use RocketMod its old OpenMod is better in someway!" Bruh nobody gives..... you know what.

I don't know what you experienced, but especially the OpenMod Discord server is one of the friendliest places around there. ImperialPlugins is basically the only place when it comes to getting help for RocketMod plugin development. No one forces you to use OpenMod anywhere.

If RocketMod was that bad... people wouldn't use him.

RocketMod is only popular because there are 10 years old plugins that somehow still work.

@Sl4vP0weR

Nelson's fault. My code was better solution to not touch other assemblies.

No, your code would have broken it in the same way. In fact your code would also cause silent errors due the empty try-catch.

kulkaGM commented 2 years ago

Its not about direct advertising, its about that everything is connected with your name. When people hear that they will imagine two things..

You are also arguing with amount of plugins when ldm community site, listed only couple of the fixed ones or new ones. But theres more than 80 plugins on RocketMod Community Plugins organization for example and also much more on whole github where creators didn't mentioned rocketmod or it hasn't been forked. And also in future there will be more plugins in OM because its maintained.

Sl4vP0weR commented 2 years ago

Yeah your code is the best especially this try catch block image

This code was an example btw. Yeah, you are the best, showing your selfimportance and "cleverness" is the best way to introduce yourself as a good person.

Sl4vP0weR commented 2 years ago

This fix made people go crazy for many reasons, please, be more friendly to each other and remember that all changes for the future of this game. I think I should close this issue cause of discords, peace to all.

educatalan02 commented 2 years ago

This fix made people go crazy for many reasons, please, be more friendly to each other and remember that all changes for the future of this game. I think I should close this issue cause of discords, peace to all.

It's not needed to be friendly against a plugin loader cracker.

negrifelipe commented 2 years ago

😂

SDGNelson commented 2 years ago

Perhaps I should not have reacted with the laugh emoji. I was a bit annoyed with Sl4vP0weR's demeanour. It is easy to provide better support to people who are polite, and vice versa.

Trojaner is correct that any widely-adopted plugin framework will receive support. This thread might be interesting to look back on: https://github.com/SmartlyDressedGames/U3-Docs/issues/32

Paradox304 commented 2 years ago

Depends on the developer, everybody has own ways how to do certain things, so why roast somebody? (Im not gonna talk about the laugh emoji from Nelson and Trojaner, because.... uh.. okay i'll do it...)

This is how somebody shouldn't act to somebody especially when one is the main game developer and second is his best friend who does tell him what to do only because he's controlling OpenMod with support of the game dev... (Do you think Troj writed on Unturned discord in 8 past months?) Oh also its good to force people to OpenMod when Trojaner based it for advertising himself and imperial (You don't think that? I don't see anything than only use this LOL). What about the OpenMod advertising? People will come somewhere to ask help with server problems [OM & Imperial Discord (its wierd when only Trojaner have the most toxic communities on the Unturned)] tell somebody what's the problem and the only what they will hear... "LMAO Don't use RocketMod its old OpenMod is better in someway!" Bruh nobody gives..... you know what. If RocketMod was that bad... people wouldn't use him.

Trojaner, you are good developer, but sometimes you don't think twice.

Basically this can be taken like my opinions, but a lot of people will se the thing here., that's like Rocket community sees things.

Don't know what you're on about, saying that people force you to use OpenMod in the discord, nobody does that. Saying stuff that doesn't make sense 🙄