Skip to content

Commit 8eae9dc

Browse files
authored
feat(schema): allow retrieval of schema data on non-main thread (#1156)
1 parent 5895683 commit 8eae9dc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

managed/CounterStrikeSharp.Tests.Native/SchemaTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq;
2+
using System.Threading;
23
using System.Threading.Tasks;
34
using CounterStrikeSharp.API;
45
using CounterStrikeSharp.API.Core;
@@ -14,7 +15,19 @@ public void GetSchemaOffset_ReturnsValidOffset()
1415
{
1516
var offset = NativeAPI.GetSchemaOffset("CBaseEntity", "m_iHealth");
1617

17-
Assert.True(offset > 0, $"Schema offset for m_iHealth should be positive, got {offset}");
18+
Assert.Equal(1464, offset); // Hardcode for now, this may change but I want to know if it changes
19+
}
20+
21+
[Fact]
22+
public async Task GetSchemaOffset_CanRunOnAnotherThread()
23+
{
24+
await Task.Run(async () =>
25+
{
26+
await Task.Yield();
27+
Assert.NotEqual(Thread.CurrentThread.ManagedThreadId, NativeTestsPlugin.gameThreadId);
28+
var offset = NativeAPI.GetSchemaOffset("CBaseEntity", "m_iHealth");
29+
Assert.True(offset > 0);
30+
});
1831
}
1932

2033
[Fact]

src/mm_plugin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ DLL_EXPORT void InvokeNative(counterstrikesharp::fxNativeContext& context)
5555
if (context.nativeIdentifier == 0) return;
5656

5757
if (context.nativeIdentifier != counterstrikesharp::hash_string_const("QUEUE_TASK_FOR_FRAME") &&
58+
context.nativeIdentifier != counterstrikesharp::hash_string_const("GET_SCHEMA_OFFSET") &&
5859
counterstrikesharp::globals::gameThreadId != std::this_thread::get_id())
5960
{
6061
counterstrikesharp::ScriptContextRaw scriptContext(context);

0 commit comments

Comments
 (0)