haekb / nolf2-modernizer

NOLF 2 Modernizer aims to unlock resolution support, restore multi-player support, and fix a few bugs here and there.
https://haekb.itch.io/nolf2-modernizer
30 stars 4 forks source link

Double Cross AI bug #62

Closed haekb closed 4 years ago

haekb commented 4 years ago

On scene 3 planting a bug, a guard who's suppose to be "friendly" is hostile, making the mission impossible to complete!

It's the smoking guard seen here: https://youtu.be/PjLCAAjFKuM?t=39

haekb commented 4 years ago

This was not caused by the frametime consolidation changes I've done.

haekb commented 4 years ago

Turns out to be some weird polymorphic stuff. It tries to dynamic_cast a different type (with the same base class).

haekb commented 4 years ago

Here's an example of the problem

class Base  {
public:
    Base() {};
    virtual ~Base() {};
};

class T1 : Base {
public:
    T1() {};
    virtual ~T1() {};
};

class T2 : Base {
public:
    T2() {};
    virtual ~T2() {};
};

class THolder
{
public:
    // TypeHolder will store our type as Type1!
    // This is the major incompatibility with Visual C++ 6.0 vs everything else C++ 
    THolder(void* pT)
    {
        m_pT = (T1*)pT;
    }

    T1* m_pT;

};

int main(int argc, char* argv[])
{
    //class T1 : Base
    //class T2 : Base

    // Create our Type 2 class
    T2* pT2 = new T2();

    // Put T2 into our TypeHolder class
    THolder* pHolder = new THolder((void*)pT);

    // This fails on everything except for Visual C++ 6.0,
    // however a C-style cast will work.
    T2* pNewT = dynamic_cast<T2*>(pHolder->m_pT); 

    if (pNewT)
    {
        printf("Dynamic Cast worked!\n");
    }
    else
    {
        printf("Dynamic Cast failed: pNewT is null\n");
    }

    return 0;
}

The result is always Dynamic Cast failed: pNewT is null.

haekb commented 4 years ago

Updated the example with a working visual c++ 6.0 vs failing everything else c++ hah.

haekb commented 4 years ago

To fix this I simply changed storing m_pInformationVolume as an AIVolume type to the AIInformationVolume type. As it's not used in any other context. I'm not sure why it was being stored as an AIVolume type...