Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual Override Methods not working correctly? #109

Open
Deaadman opened this issue Oct 12, 2023 · 4 comments
Open

Virtual Override Methods not working correctly? #109

Deaadman opened this issue Oct 12, 2023 · 4 comments
Labels
enhancement New feature or request generation Related to assembly generation
Milestone

Comments

@Deaadman
Copy link

I was developing a mod for The Long Dark, trying to create a derived class from within the game. The code snippet goes like this:

public class Panel_ModMenu : Panel_AutoReferenced 
{
    private BasicMenu m_BasicMenu;
    public GameObject m_BasicMenuRoot;

    public Panel_ModMenu(IntPtr ptr) : base(ptr) { }

    public override void Initialize()
    {
        base.Initialize();
        m_BasicMenu = BasicMenu.InstantiateMenu(InterfaceManager.s_BasicMenuPrefab, m_BasicMenuRoot, gameObject, this);
    }

    public override void Enable(bool enable)
    {
        base.Enable(enable);
        if (enable)
        {
            m_BasicMenu.Enable(true);
            GameManager.GetCameraEffects().DepthOfFieldTurnOn();
            return;
        }
        m_BasicMenu.Enable(false);
        GameManager.GetCameraEffects().DepthOfFieldTurnOff(false);
    }
}

The issue I'm facing is with the override void methods. The Panel_Base class which the Panel_AutoReferenced class also inherits isn't abstract. The Initialized override method could be getting called from the virtual void method within the Panel_Base class to initialize this new panel. But it isn't, and whenever I try to call my Initialize method manually - a recursion occurs.

Unless I've missed something, or it's not working because I don't know how to code - this might be an error with this project.

@ds5678
Copy link
Collaborator

ds5678 commented Jul 14, 2024

Were you able to figure it out?

I suspect this scenario just isn't currently supported. Everything surrounding inheritance and virtual methods is complicated.

@Deaadman
Copy link
Author

Were you able to figure it out?

I suspect this scenario just isn't currently supported. Everything surrounding inheritance and virtual methods is complicated.

Unfortunately not, like you said I don't think this specific scenario is supported. You can see what I did as a workaround here - but it doesn't actually register this panel as a proper one, so using methods such as InterfaceManager.GetPanel<>() can't find this new panel I've created.

@ds5678
Copy link
Collaborator

ds5678 commented Jul 14, 2024

I'm planning on doing a 1.4.6 release soon. It'll include #124, any improvements implemented since 1.4.5, and possibly some additional unstripping improvements. I expect this will be part of the next MelonLoader hotfix.

After that's released, I want to focus on reworking the type system, which would include resolving this issue. I plan for the rewrite to be released slightly before the next big MelonLoader update, which I suspect will happen around November.

@Deaadman
Copy link
Author

Sounds good! Being able to inherit off Hinterlands classes would be a major help when it comes to UI work, and potentially other stuff that I haven't gotten into. Maybe weather types too?

Who knows, but I appreciate it regardless!

@ds5678 ds5678 added enhancement New feature or request generation Related to assembly generation labels Jul 15, 2024
@ds5678 ds5678 added this to the 2.0.0 milestone Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request generation Related to assembly generation
Projects
None yet
Development

No branches or pull requests

2 participants