1

so I have this problem of me not understanding how to convert this one function into useable code in C#. Problem being that I am currently hooking into a game via C# and I want to rebuild a function that is very much required on the C# side of my modification, the game is of course written in C++

void __fastcall CachedReader::OutOfBoundsError(CachedReader *this, unsigned __int64 a2, __int64 a3)
{
    ulong totalSize = a2 + a3;
    if ( totalSize > (*(__int64 (__fastcall **)(_QWORD))(**((_QWORD **)this + 3) + 48i64))(*((_QWORD *)this + 3)) )
    {
        //TODO: Error logging here
    }
}

Any help converting this is greatly appreciated :)

1 Answer 1

1

This is a quick follow-up for anyone running into the same problem. I managed to figure it out with a bit of brain power

delegate long GetFileLengthDelegate(ulong v2);
        internal long GetFileLength()
        {
            IntPtr functionPointer = new IntPtr((long)*((ulong*)(**((ulong**)readerPtr + 3) + 48)));
            GetFileLengthDelegate getFileLength = Marshal.GetDelegateForFunctionPointer<GetFileLengthDelegate>(functionPointer);

            return getFileLength((*((ulong*)readerPtr + 3)));
        }

Apparently those types of statements are function pointers and the the second set of parantheses act as the parameters for it. Hope it can help anyone out there!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.