-
-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathAPIs.cpp
More file actions
140 lines (116 loc) · 3.41 KB
/
APIs.cpp
File metadata and controls
140 lines (116 loc) · 3.41 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
135
136
137
138
139
140
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* The original code is copyright (c) 2024, open.mp team and contributors.
*/
#include "../ComponentManager.hpp"
OMP_CAPI(CustomModel_AddCharModel, bool(int baseid, int newid, StringCharPtr dff, StringCharPtr textureLibrary))
{
auto models = ComponentManager::Get()->models;
if (!models)
{
return false;
}
bool ret = models->addCustomModel(ModelType::Skin, newid, baseid, dff, textureLibrary);
return ret;
}
OMP_CAPI(CustomModel_AddSimpleModel, bool(int virtualWorld, int baseid, int newid, StringCharPtr dff, StringCharPtr textureLibrary))
{
auto models = ComponentManager::Get()->models;
if (!models)
{
return false;
}
bool ret = models->addCustomModel(ModelType::Object, newid, baseid, dff, textureLibrary, virtualWorld);
return ret;
}
OMP_CAPI(CustomModel_AddSimpleModelTimed, bool(int virtualWorld, int baseid, int newid, StringCharPtr dff, StringCharPtr textureLibrary, int timeOn, int timeOff))
{
auto models = ComponentManager::Get()->models;
if (!models)
{
return false;
}
bool ret = models->addCustomModel(ModelType::Object, newid, baseid, dff, textureLibrary, virtualWorld, uint8_t(timeOn), uint8_t(timeOff));
return ret;
}
OMP_CAPI(Player_GetCustomSkin, int(objectPtr player))
{
POOL_ENTITY_RET(players, IPlayer, player, player_, 0);
IPlayerCustomModelsData* data = queryExtension<IPlayerCustomModelsData>(player_);
if (!data)
{
return 0;
}
auto skin = data->getCustomSkin();
return skin;
}
OMP_CAPI(CustomModel_RedirectDownload, bool(objectPtr player, StringCharPtr url))
{
POOL_ENTITY_RET(players, IPlayer, player, player_, false);
IPlayerCustomModelsData* data = queryExtension<IPlayerCustomModelsData>(player_);
if (!data)
{
return false;
}
if (!data->sendDownloadUrl(url))
{
ComponentManager::Get()->core->logLn(LogLevel::Warning, "This native can be used only within OnPlayerRequestDownload callback.");
return false;
}
return true;
}
OMP_CAPI(CustomModel_FindModelFileNameFromCRC, int(int crc, OutputStringViewPtr output))
{
auto models = ComponentManager::Get()->models;
if (!models)
{
return false;
}
auto result = models->getModelNameFromChecksum(crc);
SET_CAPI_STRING_VIEW(output, result);
return true;
}
OMP_CAPI(CustomModel_IsValid, bool(int modelId))
{
auto models = ComponentManager::Get()->models;
if (!models)
{
return false;
}
auto valid = models->isValidCustomModel(modelId);
return valid;
}
OMP_CAPI(CustomModel_GetPath, bool(int modelId, OutputStringViewPtr dffPath, OutputStringViewPtr txdPath))
{
auto models = ComponentManager::Get()->models;
if (!models)
{
return false;
}
StringView dffPathSV {};
StringView txdPathSV {};
auto status = models->getCustomModelPath(modelId, dffPathSV, txdPathSV);
SET_CAPI_STRING_VIEW(dffPath, dffPathSV);
SET_CAPI_STRING_VIEW(txdPath, txdPathSV);
return status;
}
OMP_CAPI(SetModelDownloadAtConnect, bool(bool value))
{
auto models = ComponentManager::Get()->models;
if (!models)
return false;
return models->setModelDownloadAtConnect(value);
}
OMP_CAPI(StartDownloadForPlayer, bool(objectPtr player))
{
POOL_ENTITY_RET(players, IPlayer, player, player_, false);
auto models = ComponentManager::Get()->models;
if (!models)
{
return false;
}
return models->startDownloadForPlayer(*player_);
}