forked from codeurzebs/fivem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuaNativesLoader.cpp
More file actions
134 lines (108 loc) · 2.61 KB
/
Copy pathLuaNativesLoader.cpp
File metadata and controls
134 lines (108 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "StdInc.h"
#include <VFSManager.h>
#include <VFSZipFile.h>
#include <ResourceManager.h>
namespace fx
{
bool mountedAnyNatives = false;
}
static bool MountNatives(const std::string& name)
{
static std::map<std::string, std::vector<uint8_t>> storedFiles;
const void* thisData = nullptr;
size_t thisDataSize = 0;
{
auto stream = vfs::OpenRead(fmt::sprintf("citizen:/scripting/lua/%s.zip", name));
if (stream.GetRef())
{
storedFiles[name] = stream->ReadToEnd();
thisData = storedFiles[name].data();
thisDataSize = storedFiles[name].size();
}
}
if (thisData)
{
fwRefContainer<vfs::ZipFile> device = new vfs::ZipFile();
if (device->OpenArchive(fmt::sprintf("memory:$%016llx,%d,0:%s", (uintptr_t)thisData, thisDataSize, name)))
{
vfs::Mount(device, fmt::sprintf("nativesLua:/%s/", name));
return true;
}
}
return false;
}
class MarkerDevice : public vfs::Device
{
// Inherited via Device
virtual THandle Open(const std::string& fileName, bool readOnly, bool append = false) override
{
if (fileName == "n:m:a:r:k:e:r" && readOnly)
{
return 1;
}
return vfs::Device::InvalidHandle;
}
virtual size_t Read(THandle handle, void* outBuffer, size_t size) override
{
return -1;
}
virtual size_t Seek(THandle handle, intptr_t offset, int seekType) override
{
return -1;
}
virtual bool Close(THandle handle) override
{
return true;
}
virtual THandle FindFirst(const std::string& folder, vfs::FindData* findData) override
{
return vfs::Device::InvalidHandle;
}
virtual bool FindNext(THandle handle, vfs::FindData* findData) override
{
return false;
}
virtual void FindClose(THandle handle) override
{
}
virtual std::string GetAbsolutePath() const override
{
return "";
}
bool Flush(THandle handle) override
{
return true;
}
};
static InitFunction initFunction([]()
{
fx::ResourceManager::OnInitializeInstance.Connect([](fx::ResourceManager*)
{
bool mountedFiles = false;
if (auto device = vfs::GetDevice("nativesLua:/marker/"); device.GetRef())
{
mountedFiles = device->Open("n:m:a:r:k:e:r", true) != vfs::Device::InvalidHandle;
}
if (!mountedFiles)
{
mountedFiles =
#if defined(IS_RDR3)
MountNatives("rdr3_universal") &&
#elif defined(GTA_NY)
MountNatives("ny_universal") &&
#elif defined(GTA_FIVE)
MountNatives("natives_universal") &&
MountNatives("natives_21e43a33") &&
MountNatives("natives_0193d0af") &&
#elif defined(IS_FXSERVER)
MountNatives("natives_server") &&
#endif
true;
if (mountedFiles)
{
vfs::Mount(new MarkerDevice(), "nativesLua:/marker/");
}
}
fx::mountedAnyNatives = mountedFiles;
});
});