GodotModding / godot-mod-loader

A general purpose mod loader for GDScript based Godot Games [3.x/4.x]
https://discord.godotmodding.com
Creative Commons Zero v1.0 Universal
367 stars 30 forks source link

Set global script classes on Godot 4 #335

Open MateuSai opened 1 year ago

MateuSai commented 1 year ago

Hi, in Godot 4, ProjectSettings.get_setting("_global_script_classes") returns nil. Seems like the equivalent is ProjectSettings.get_global_class_list(), however, I can't find a function to set the global class list. So, script extensions don't work on Godot 4 at the moment. If anyone finds a solution, please let me know.

Qubus0 commented 1 year ago

So, the global classes are moved to .godot/global_script_class_cache.cfg in this pr https://github.com/godotengine/godot/pull/70557 This pr here has a way to open them with ConfigFile, and it should be possible to save it with this as well https://github.com/godotengine/godot-docs/issues/6632 I'm not sure if the game still needs to be restarted - would be nice if not, but I doubt it.

All that aside, if the ModLoader is installed by the developer, the global class method is not needed for script extensions, since all global classes are already added by the editor and included on export. This could only be an issue for the self setup.

KANAjetzt commented 1 year ago

This is the function we are talking about, right?

https://github.com/GodotModding/godot-mod-loader/blob/19a7b7fc484a98969d9a82ff8f402a3a30f08246/addons/mod_loader/internal/script_extension.gd#L113-L132

MateuSai commented 1 year ago

No, the problem is the setting the global classes since it seems there is no straightforward equivalent in Godot 4. In the function you mention I replaced the line 121 with var classes: Array = ProjectSettings.get_global_class_list().

But as Qubus0 said this is only a problem with the self setup. I got it working without changing the lines where the global classes are set, since the code is not being executed, I don't get any error

ugackMiner53 commented 2 weeks ago

I was really struggling with this problem because most of the 4.x games that I want to mod require self setup, as the authors have no intention of making it moddable.

While it's a bad solution (and admittedly removes all support for non self-setup), I found that putting every single class into a single autoload, then prefixing every call to a class with that autoload (and also removing most typedefs) causes self setup to work again on Godot 4.

If anyone is curious about this, I can post more details, but it's really not a viable solution for the project as a whole. I just wanted to share after multiple hours of trying to get this project to work self-setup in Godot 4.x.

KANAjetzt commented 2 weeks ago

@ugackMiner53 What games are you modding? Once we have the hook system running, I’d be happy to look into the self-setup. It would be useful to have some games to test.

ugackMiner53 commented 2 weeks ago

@KANAjetzt Personally, I was doing testing on simple projects made by myself and friends (think Squash the Creeps) in order to prepare for modding actual games without builtin support, like Buckshot Roulette or similar. I'll upload a branch to my personal account with the changes I had to make to get self-setup working again with 4.x, but I don't know if it will be of any use.