Skip to content

Commit f51463a

Browse files
v6.0.2: add "loadRawData" setting - passes file content to engineLoad* functions instead of file path
1 parent f9a4e98 commit f51463a

File tree

8 files changed

+41
-22
lines changed

8 files changed

+41
-22
lines changed

[examples]/sampobj_red/meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<info author="Fernando" name="SAMP Objects Red"
77
description="uses newmodels functions to add all SA-MP objects"
8-
version="6.0.1"
8+
version="6.0.2"
99
type="script" />
1010

1111
<!-- IMPORTANT TO HAVE THIS VERSION OR HIGHER SO THAT IT WORKS AS EXPECTED

[examples]/test_vehicles/meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<meta>
2-
<include resource="newmodels_red" minversion="6.0.1"/>
2+
<include resource="newmodels_red" minversion="6.0.2"/>
33
<script src="s_vehicles.lua" type="server"/>
44
<script src="s_vehicles_alt.lua" type="server"/>
55
<script src="s_test_cmd.lua" type="server"/>

newmodels_red/meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<meta>
2-
<info author="FernandoMTA" version="6.0.1" type="script" name="newmodels_red"
2+
<info author="FernandoMTA" version="6.0.2" type="script" name="newmodels_red"
33
description="Codename Newmodels Red - Adds new vehicle/ped/object models, automatically synced with all players."/>
44

55
<!-- IMPORTANT TO HAVE THIS VERSION OR HIGHER SO THAT IT WORKS AS EXPECTED

newmodels_red/models/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The available options are (any line that doesn't contain a valid setting string
2121
- `disableAutoFree`
2222
- `disableTXDTextureFiltering`
2323
- `enableDFFAlphaTransparency`
24+
- `loadRawData`
2425
- `txd=PATH_TO_TXD_FILE_INSIDE_models_FOLDER` (used for shared textures)
2526
- `dff=PATH_TO_DFF_FILE_INSIDE_models_FOLDER` (used for shared models)
2627
- `col=PATH_TO_COL_FILE_INSIDE_models_FOLDER` (used for shared collisions)

newmodels_red/models_alt/s_mod_list.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
--
3636
-- > New parameters added in newmodels v6:
3737
--
38-
-- None.
38+
-- 'loadRawData' : if true, the mod files will be loaded using the file content data,
39+
-- and not passing the file path to engineLoad* MTA functions.
3940
--
4041
-- ..........................
4142
-- AVAILABLE TYPES .....

newmodels_red/scripts/core/client_logic.lua

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ local LOADING_QUEUE_PHASES = {
2121
local currFreeIdDelay = 9500 -- ms
2222
local FREE_ID_DELAY_STEP = 500 -- ms
2323

24+
local function getCustomModelSetting(settings, key)
25+
if settings and settings[key] ~= nil then
26+
return settings[key]
27+
end
28+
return DEFAULT_AUTO_MODEL_SETTINGS[key]
29+
end
30+
2431
local function applyElementCustomModel(element)
2532
local customModel = elementModels[element]
2633
if not customModel then return end
@@ -87,7 +94,7 @@ local function finishLoadCustomModel(customModel)
8794
return
8895
end
8996

90-
local enableDFFAlphaTransparency = customInfo.settings.enableDFFAlphaTransparency
97+
local enableDFFAlphaTransparency = getCustomModelSetting(customInfo.settings, "enableDFFAlphaTransparency")
9198

9299
if (col and not engineReplaceCOL(col.element, allocatedModel))
93100
or (txd and not engineImportTXD(txd.element, allocatedModel))
@@ -114,14 +121,14 @@ local function finishLoadCustomModel(customModel)
114121
reusableModelElements[dff.path] = dff.element
115122
end
116123

117-
local disableAutoFree = customInfo.settings.disableAutoFree
118-
local lodDistance = customInfo.settings.lodDistance
119-
if lodDistance then
124+
local disableAutoFree = getCustomModelSetting(customInfo.settings, "disableAutoFree")
125+
local lodDistance = getCustomModelSetting(customInfo.settings, "lodDistance")
126+
if type(lodDistance) == "number" then
120127
engineSetModelLODDistance(allocatedModel, lodDistance)
121128
end
122129

123-
local physicalPropsGroup = customInfo.settings.physicalPropsGroup
124-
if physicalPropsGroup then
130+
local physicalPropsGroup = getCustomModelSetting(customInfo.settings, "physicalPropsGroup")
131+
if type(physicalPropsGroup) == "number" then
125132
engineSetModelPhysicalPropertiesGroup(allocatedModel, physicalPropsGroup)
126133
end
127134

@@ -196,7 +203,8 @@ local function beginLoadCustomModelElements(customModel)
196203
end
197204

198205
local colPath, txdPath, dffPath = customInfo.col, customInfo.txd, customInfo.dff
199-
local disableTXDTextureFiltering = customInfo.settings.disableTXDTextureFiltering
206+
local disableTXDTextureFiltering = getCustomModelSetting(customInfo.settings, "disableTXDTextureFiltering")
207+
local loadRawData = getCustomModelSetting(customInfo.settings, "loadRawData")
200208

201209
local decryptFunc = getNandoDecrypterFunction()
202210

@@ -234,10 +242,9 @@ local function beginLoadCustomModelElements(customModel)
234242
end
235243
if not modElement then
236244
onFailedToLoadModFile(customModel, modPath, modType)
237-
return false
245+
return
238246
end
239247
onLoadedModFile(customModel, modType, modPath, modElement)
240-
return true
241248
end
242249

243250
local function loadOneMod(modType, modPath)
@@ -249,12 +256,19 @@ local function beginLoadCustomModelElements(customModel)
249256
loadModElement(modType, modPath, data)
250257
end) then
251258
onFailedToLoadModFile(customModel, modPath, modType)
252-
return
253259
end
254-
else
255-
if not loadModElement(modType, modPath) then
260+
elseif loadRawData then
261+
local file = fileOpen(modPath)
262+
if not file then
263+
onFailedToLoadModFile(customModel, modPath, modType)
256264
return
257265
end
266+
local data = fileRead(file, fileGetSize(file))
267+
fileClose(file)
268+
-- print("Loaded raw data for", modType, "of custom model", customModel)
269+
loadModElement(modType, modPath, data)
270+
else
271+
loadModElement(modType, modPath)
258272
end
259273
end
260274

@@ -357,7 +371,7 @@ local function beginDownloadModelFiles(customModel)
357371
return
358372
end
359373

360-
if (not customInfo.settings["downloadFilesOnDemand"]) then
374+
if (not getCustomModelSetting(customInfo.settings, "downloadFilesOnDemand")) then
361375
-- No downloading needed, proceed to load model elements
362376
beginLoadCustomModelElements(customModel)
363377
return

newmodels_red/scripts/core/server_logic.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ end
2121
-- .................................................................
2222

2323
-- Model settings (from .txt files overriding defaults):
24-
local DECLARATIVE_SETTINGS = { "disableAutoFree", "disableTXDTextureFiltering", "enableDFFAlphaTransparency" }
24+
local DECLARATIVE_SETTINGS = { "disableAutoFree", "disableTXDTextureFiltering", "enableDFFAlphaTransparency",
25+
"loadRawData" }
2526
-- - txd=path
2627
-- - dff=path
2728
-- - col=path
@@ -123,10 +124,6 @@ local function isAnyFileDownloadOnDemand(filePaths)
123124
end
124125

125126
local function parseModelSettings(customModel, customModelInfo, thisFullPath, isFromSettingsOption)
126-
local customModelSettings = {}
127-
for key, value in pairs(DEFAULT_AUTO_MODEL_SETTINGS) do
128-
customModelSettings[key] = value
129-
end
130127
local file = fileOpen(thisFullPath, true)
131128
if not file then
132129
return false, "failed to open file: " .. thisFullPath
@@ -136,6 +133,7 @@ local function parseModelSettings(customModel, customModelInfo, thisFullPath, is
136133
if not info then
137134
return false, "failed to read file: " .. thisFullPath
138135
end
136+
local customModelSettings = {}
139137
local lines = split(info, "\n")
140138
for _, settingStr in pairs(lines) do
141139
settingStr = settingStr:gsub("\r", "")
@@ -396,6 +394,10 @@ local function parseModListEntry(modelType, modInfo)
396394
if modInfo.metaDownloadFalse then
397395
settings["downloadFilesOnDemand"] = true
398396
end
397+
-- New setting from v6
398+
if modInfo.loadRawData then
399+
settings["loadRawData"] = true
400+
end
399401

400402
local ncExt = NANDOCRYPT_EXT
401403

newmodels_red/scripts/core/shared_config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ DEFAULT_AUTO_MODEL_SETTINGS = {
55
["disableAutoFree"] = false,
66
["disableTXDTextureFiltering"] = false,
77
["enableDFFAlphaTransparency"] = false,
8+
["loadRawData"] = true,
89
}
910

1011
-- For downloadFile behavior

0 commit comments

Comments
 (0)