Example #1
0
    ReturnType operator()(Args ... args)
    {
        if (mPassThrough && IsMgsi())
        {
            return mRealFuncPtr(args...);
        }

#if ENABLE_LOGGING
        if (kLogArgs)
        {
            if (!IsMgsi() && !mRealFuncPtr)
            {
                std::cout << "WARNING: Unimpl call: " << mFnName << std::endl;
            }
            std::cout << mFnName << " (";
            doPrint(std::cout, args...);
            std::cout << ")" << std::endl;
        }
#endif

#pragma warning(push)
#pragma warning(disable:4127) // conditional expression is constant
        if (kNewAddr)
        {
            // Call "newAddr" since we've replaced the function completely
            return reinterpret_cast<TFuncType>(kNewAddr)(args...);
        }
        else
        {
            if (!IsMgsi())
            {
                // Cast handles "return void;" this case is a stub for when
                // calling a real game function outside of the game exe
                return (ReturnType)0;
            }
            // Call "mRealFuncPtr" here so that we are calling the "real" function

            // If not running within the game then we can't call real so just return
            // a default R and log params
            return mRealFuncPtr(args...);
        }
#pragma warning(pop)


    }
Example #2
0
File: File.cpp Project: rcxrdx/msgi
void *__cdecl mgs_calloc(size_t NumOfElements, size_t SizeOfElements)
{
    if (IsMgsi())
    {
        // TODO: Track
        LOG_WARNING("calloc() not tracked");
        return mgs_calloc_.Ptr()(NumOfElements, SizeOfElements);
    }
    else
    {
        return calloc(NumOfElements, SizeOfElements);
    }
}
Example #3
0
File: File.cpp Project: rcxrdx/msgi
void *__cdecl mgs_realloc(void *Memory, size_t NewSize)
{
    if (IsMgsi())
    {
        // TODO: Track
        LOG_WARNING("realloc() not tracked");
        return mgs_realloc_.Ptr()(Memory, NewSize);
    }
    else
    {
        return realloc(Memory, NewSize);
    }
}
Example #4
0
File: File.cpp Project: rcxrdx/msgi
void *__cdecl mgs_malloc(size_t Size)
{
    if (IsMgsi())
    {
        void* ptr = mgs_malloc_.Ptr()(Size);
        if (ptr)
        {
            MgsVar::TrackAlloc(ptr, Size);
        }
        return ptr;
    }
    return malloc(Size);
}
Example #5
0
File: File.cpp Project: rcxrdx/msgi
void __cdecl mgs_free(void *Memory)
{
    if (IsMgsi())
    {
        if (Memory)
        {
            MgsVar::TrackFree(Memory);
        }
        mgs_free_.Ptr()(Memory);
    }
    else
    {
        free(Memory);
    }
}
Example #6
0
    Signature* Ptr() const
    {
#pragma warning(push)
#pragma warning(disable:4127) // conditional expression is constant
        if (!IsMgsi())
        {
            if (convention == eCDecl)
            {
                return Cdecl_Static_Hook_Impl;
            }
            else if (convention == eStdCall)
            {
                return reinterpret_cast<Signature*>(StdCall_Static_Hook_Impl);
            }
            else
            {
                abort();
            }
        }
#pragma warning(pop)
        return mRealFuncPtr;
    }