CounterStrikeSharp
CounterStrikeSharp copied to clipboard
Fix schemafields that are supposed to return fix sized arrays
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
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?
When this will be worked on, lets not forget about #613