CounterStrikeSharp icon indicating copy to clipboard operation
CounterStrikeSharp copied to clipboard

Fix schemafields that are supposed to return fix sized arrays

Open KillStr3aK opened this issue 2 years ago • 2 comments

The current workaround is this:

public unsafe T[] GetFixedArray<T>(nint pointer, string @class, string member, int length) where T: NativeObject
{
    nint ptr = pointer + Schema.GetSchemaOffset(@class, member);
    Span<nint> references = MemoryMarshal.CreateSpan<nint>(ref ptr, length);
    T[] values = new T[length];

    for (int i = 0; i < length; i++)
    {
        values[i] = (T)Activator.CreateInstance(typeof(T), references[i])!;
    }

    return values;
}

this works in general and can access the whole schemaclass but when I messed with viewmodels I've experienced a segfault when tried to access the animation? string and it was corrupted memory but haven't investigated further yet but this needs attention for sure.

I might take on this just to dont forget about the issue in general I've opened this

KillStr3aK avatar Nov 25 '23 17:11 KillStr3aK

Bumping this, the current implementation with Span<T> limits the usage of the API as it does not support any T that has a pointer or reference inside

Is there anything wrong with the mentioned workaround tho?

KillStr3aK avatar Oct 08 '24 11:10 KillStr3aK

When this will be worked on, lets not forget about #613

KillStr3aK avatar Oct 08 '24 11:10 KillStr3aK