Repository: godot
Issue: Godot C# Registers Derived Script Types Incorrectly as Supertype, and Other Cross Language Problems
Labels: bug,topic:gdscript,topic:dotnet

### Tested versions

v4.2.2.stable.mono.official

### System information

Godot v4.2.2.stable.mono.official - Desktop

### Issue description

When you create a custom C# class that extends a Godot type and mark it as a [GlobalClass], Godot incorrectly registers this custom class as its base type (like Resource or Node) instead of the custom type when it is returned from a method or property. This causes problems when you try to use the custom type in GDScript code, due to typing/autocomplete issues, and other larger problems.

If you look at ScriptMethods.generated.cs, className is "Resource" when it should be "Duration"
```csharp
    internal new static global::System.Collections.Generic.List<global::Godot.Bridge.MethodInfo> GetGodotMethodList()
    {
        var methods = new global::System.Collections.Generic.List<global::Godot.Bridge.MethodInfo>(1);
        methods.Add(new(name: MethodName.ShouldReturnDurationType, returnVal: new(type: (global::Godot.Variant.Type)24, name: "", hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)6, exported: false, className: new global::Godot.StringName("Resource")), flags: (global::Godot.MethodFlags)33, arguments: null, defaultArguments: null));
        return methods;
    }
```

Also, the behaviour is different depending on the derived type of Duration, if it's a resource derived type, instead of a node you will get compile errors and parse errors (see in steps to reproduce). 

### Steps to reproduce

Have a C# GlobalClass

```csharp
using Godot;

[GlobalClass]
public partial class Duration : Resource {
	// having to export to access the property from gdscript is another issue https://github.com/godotengine/godot/issues/92183
	[Export] public Duration ShouldBeDurationType { get; set; }
	public static Duration ShouldReturnDurationType() {
		return new Duration();
	}
}


```

In gdscript, create an instance via static method, and try to get an instance from its property.
The method return is a Resource instead of the Duration type, and the properties cause parser errors.
```gdscript
func _init() -> void:
    # Warning(unsafe_call_argument): The argument 1 of the function "method_that_accepts_duration()" requires the subtype "res://Duration.cs" but the supertype "Resource" was provided.
    method_that_accepts_duration(Duration.ShouldReturnDurationType())
    
    var instance := Duration.new()
    # Error: Invalid argument for "method_that_accepts_duration()" function: argument 1 should be "res://Duration.cs" but is "Duration".
    method_that_accepts_duration(instance.ShouldBeDurationType)
    # Error: Invalid cast. Cannot convert from "Duration" to "res://Duration.cs".
    method_that_accepts_duration(instance.ShouldBeDurationType as Duration)

func method_that_accepts_duration(duration: Duration) -> void:
    print(str(duration))
 
```


```gdscript
# This only happens when duration is registered as a [GlobalClass] and is resource derived
# if you remove the [GlobalClass] attribute, and import it with "const Duration = preload("res://Duration.cs")"
# you will not get any errors, however, it is inferred as a "Resource" rather than "Duration"
	

func _init() -> void:
	var instance := Duration.new()
	
	# You get a get a compiler error on saving by the statement below existing.
	# " modules/gdscript/gdscript_compiler.cpp:121 - GDScript bug: Native class "Duration" not found."
	var untyped = instance.ShouldBeDurationType
	#           ^ if its := (inferred), you will get 3 compiler errors instead of one


```

### Minimal reproduction project (MRP)

[mrp.zip](https://github.com/user-attachments/files/16243630/mrp.zip)