Skip to content

Commit 11eb7f2

Browse files
Make root directory lookup lazy
1 parent b557099 commit 11eb7f2

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

api/AltV.Net/Elements/Args/MValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public static MValue Create(ICheckpoint checkpoint)
268268
public static MValue Create(Function function)
269269
{
270270
var mValue = Nil;
271-
AltNative.MValueCreate.MValue_CreateFunction(AltNative.MValueCreate.Invoker_Create(Alt.Module.ModuleResource.NativePointer, function), ref mValue);
271+
AltNative.MValueCreate.MValue_CreateFunction(AltNative.MValueCreate.Invoker_Create(Alt.Server.Resource.CSharpResourceImpl.NativePointer, function), ref mValue);
272272
return mValue;
273273
}
274274

api/AltV.Net/INativeResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace AltV.Net
55
{
66
public interface INativeResource
77
{
8-
IntPtr ResourceImpl { get; }
8+
IntPtr ResourceImplPtr { get; }
99

1010
CSharpResourceImpl CSharpResourceImpl { get; }
1111

api/AltV.Net/NativeResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class NativeResource : INativeResource
99
{
1010
internal readonly IntPtr NativePointer;
1111

12-
public IntPtr ResourceImpl => AltNative.Resource.Resource_GetImpl(NativePointer);
12+
public IntPtr ResourceImplPtr => AltNative.Resource.Resource_GetImpl(NativePointer);
1313

1414
private CSharpResourceImpl cSharpResourceImpl;
1515

api/AltV.Net/Server.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,25 @@ public class Server : IServer
3131

3232
public int NetTime => AltNative.Server.Server_GetNetTime(NativePointer);
3333

34-
public string RootDirectory { get; }
34+
private string rootDirectory;
35+
36+
public string RootDirectory
37+
{
38+
get
39+
{
40+
if (rootDirectory != null) return rootDirectory;
41+
var ptr = IntPtr.Zero;
42+
AltNative.Server.Server_GetRootDirectory(NativePointer, ref ptr);
43+
rootDirectory = Marshal.PtrToStringUTF8(ptr);
44+
45+
return rootDirectory;
46+
}
47+
}
3548

3649
public NativeResource Resource { get; }
3750

38-
public Server(IntPtr nativePointer, NativeResource resource, IBaseBaseObjectPool baseBaseObjectPool, IBaseEntityPool baseEntityPool,
51+
public Server(IntPtr nativePointer, NativeResource resource, IBaseBaseObjectPool baseBaseObjectPool,
52+
IBaseEntityPool baseEntityPool,
3953
IEntityPool<IPlayer> playerPool,
4054
IEntityPool<IVehicle> vehiclePool,
4155
IBaseObjectPool<IBlip> blipPool,
@@ -52,9 +66,6 @@ public Server(IntPtr nativePointer, NativeResource resource, IBaseBaseObjectPool
5266
this.checkpointPool = checkpointPool;
5367
this.voiceChannelPool = voiceChannelPool;
5468
this.colShapePool = colShapePool;
55-
var ptr = IntPtr.Zero;
56-
AltNative.Server.Server_GetRootDirectory(nativePointer, ref ptr);
57-
RootDirectory = Marshal.PtrToStringUTF8(ptr);
5869
Resource = resource;
5970
}
6071

0 commit comments

Comments
 (0)