Skip to content

Commit 9f2dc7e

Browse files
Add load, unload
1 parent 3c5ff5c commit 9f2dc7e

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

api/AltV.Net/CSharpNativeResource.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ namespace AltV.Net
88
/// A wrapper around none standard alt:V cpp apis
99
/// </summary>
1010
//TODO: move SetDelegates to this thing
11-
public class CSharpNativeResource : NativeResource
11+
public class CSharpNativeResource
1212
{
13-
internal CSharpNativeResource(IntPtr nativePointer) : base(nativePointer)
13+
internal readonly IntPtr NativePointer;
14+
15+
internal CSharpNativeResource(IntPtr nativePointer)
1416
{
17+
NativePointer = nativePointer;
1518
}
1619

1720
public void SetExport(string key, MValue value)
@@ -24,5 +27,15 @@ public void Reload()
2427
{
2528
AltNative.Resource.CSharpResource_Reload(NativePointer);
2629
}
30+
31+
public void Load()
32+
{
33+
AltNative.Resource.CSharpResource_Load(NativePointer);
34+
}
35+
36+
public void Unload()
37+
{
38+
AltNative.Resource.CSharpResource_Unload(NativePointer);
39+
}
2740
}
2841
}

api/AltV.Net/Native/AltV.Resource.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ internal static extern ushort
1515

1616
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
1717
internal static extern void CSharpResource_Reload(IntPtr resourcePointer);
18+
19+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
20+
internal static extern void CSharpResource_Load(IntPtr resourcePointer);
21+
22+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
23+
internal static extern void CSharpResource_Unload(IntPtr resourcePointer);
1824

1925
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
2026
internal static extern ushort Resource_GetExports(IntPtr resourcePointer, ref StringViewArray keys,

runtime/include/CSharpResource.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ EXPORT void CSharpResource_Reload(CSharpResource* resource);
192192

193193
EXPORT void CSharpResource_SetExport(CSharpResource* resource, const char* key, const alt::MValue &val);
194194

195+
EXPORT void CSharpResource_Load(CSharpResource* resource);
196+
197+
EXPORT void CSharpResource_Unload(CSharpResource* resource);
198+
195199
EXPORT void CSharpResource_SetMain(CSharpResource* resource,
196200
MainDelegate_t mainDelegate,
197201
StopDelegate_t stopDelegate,

runtime/src/CSharpResource.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,18 @@ void CSharpResource_Reload(CSharpResource* resource) {
469469
resource->MainDelegate(resource->server, resource, resource->GetName().CStr(), resource->GetMain().CStr());
470470
}
471471

472+
void CSharpResource_Load(CSharpResource* resource) {
473+
resource->coreClr->ExecuteManagedResource(resource->server, resource->GetPath().CStr(), resource->GetName().CStr(),
474+
resource->GetMain().CStr(), resource);
475+
resource->MainDelegate(resource->server, resource, resource->GetName().CStr(), resource->GetMain().CStr());
476+
}
477+
478+
void CSharpResource_Unload(CSharpResource* resource) {
479+
resource->OnStopDelegate();
480+
resource->coreClr->ExecuteManagedResourceUnload(resource->server, resource->GetPath().CStr(),
481+
resource->GetMain().CStr());
482+
}
483+
472484
void Server_GetCSharpResource(alt::IServer* server, const char* resourceName, CSharpResource*&resource) {
473485
resource = (CSharpResource*) server->GetResource(resourceName);
474486
}

0 commit comments

Comments
 (0)