Skip to content

Commit c7a3239

Browse files
authored
hedit: misc. fixes (#678)
* hedit: reduce console spam Removed extra `print` calls, replaced others with `outputDebugScript` where appropriate. * hedit: improve element data security Improves the security of resource data by using the new `clientChangesPolicy` parameter where appropriate. * hedit: update version variables * hedit: change outputDebugString behavior Changes the function override for `outputDebugString` to always output errors and warnings, instead of only in `DEBUGMODE`.
1 parent 3f0f0d0 commit c7a3239

File tree

9 files changed

+33
-48
lines changed

9 files changed

+33
-48
lines changed

[gameplay]/hedit/meta.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<meta>
2-
<info type="script" name="Ingame Handling Editor" author="Remi-X" version="2.1.5" description="The first ingame handling editor for MTA!" />
2+
<info type="script" name="Ingame Handling Editor" author="Remi-X, MTA contributors (github.com/multitheftauto/mtasa-resources)" version="2.1.6" description="The first ingame handling editor for MTA!" />
33
<oop>true</oop>
4-
<min_mta_version server="1.4.0" client="1.4.0" />
4+
<min_mta_version server="1.6.0-9.22815" client="1.6.0-9.22815" />
55

66
<!-- SHARED -->
77
<script src="shared/variables/general.lua" type="shared" />

[gameplay]/hedit/server/cfgloader.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function loadCFGIntoMemory ( cfgstr )
2626
waitForLine = false
2727

2828
if addingEntry then
29-
print ( "[HEDIT] Error while adding line #"..tostring(#lines)..", invalid character found: "..token )
29+
outputDebugString ( "[HEDIT] Error while adding line #"..tostring(#lines)..", invalid character found: "..token, 1)
3030
table.remove ( lines, #lines )
3131
addingEntry = false
3232
end
@@ -63,18 +63,18 @@ function loadCFGIntoMemory ( cfgstr )
6363

6464

6565
if #lines > 0 then
66-
print ( "[HEDIT] Loaded "..tostring(#lines).." handling entries from "..tostring(string.len(cfgstr)).." bytes into the memory." )
67-
print ( "[HEDIT] Type 'exportcfg' to import the handling entries into defaults.xml." )
68-
print ( "[HEDIT] This may take some time." )
66+
outputDebugString ( "[HEDIT] Loaded "..tostring(#lines).." handling entries from "..tostring(string.len(cfgstr)).." bytes into the memory." )
67+
outputDebugString ( "[HEDIT] Type 'exportcfg' to import the handling entries into defaults.xml." )
68+
outputDebugString ( "[HEDIT] This may take some time." )
6969

7070
addCommandHandler ( "exportcfg", function ( player )
7171

7272
if getElementType ( player ) ~= "console" then
7373
return false
7474
end
7575

76-
print ( "[HEDIT] Importing "..line.." handling entries into defaults.xml." )
77-
print ( "[HEDIT] This may take a while. Please wait." )
76+
outputDebugString ( "[HEDIT] Importing "..line.." handling entries into defaults.xml." )
77+
outputDebugString ( "[HEDIT] This may take a while. Please wait." )
7878

7979
setTimer ( function ( )
8080
exportToDefaults ( lines )
@@ -85,8 +85,8 @@ function loadCFGIntoMemory ( cfgstr )
8585
return true
8686
end
8787

88-
print ( "[HEDIT] No handling entries found in "..tostring(string.len(cfgstr)).." bytes!")
89-
print ( "[HEDIT] Make sure handling.cfg is correct and try again." )
88+
outputDebugString ( "[HEDIT] No handling entries found in "..tostring(string.len(cfgstr)).." bytes!", 2)
89+
outputDebugString ( "[HEDIT] Make sure handling.cfg is correct and try again.", 2 )
9090

9191
return true
9292
end
@@ -113,7 +113,7 @@ function exportToDefaults ( linetabs )
113113

114114
if id == 1 then
115115
if not tonumber ( value ) then
116-
print ( "[HEDIT] Handling line #"..tostring(num).." is invalid, can't import!" )
116+
outputDebugString ( "[HEDIT] Handling line #"..tostring(num).." is invalid, can't import!", 1 )
117117
break
118118
end
119119

@@ -156,8 +156,8 @@ addCommandHandler ( "loadcfg", function ( player )
156156

157157
fileClose ( cfgFile )
158158

159-
print ( "[HEDIT] handling.cfg has been read." )
160-
print ( "[HEDIT] Please wait while loading the lines into the memory." )
159+
outputDebugString ( "[HEDIT] handling.cfg has been read." )
160+
outputDebugString ( "[HEDIT] Please wait while loading the lines into the memory." )
161161

162162
setTimer ( function ( )
163163
loadCFGIntoMemory ( str )
@@ -166,6 +166,6 @@ addCommandHandler ( "loadcfg", function ( player )
166166
return true
167167
end
168168

169-
print ( "[HEDIT] No handling.cfg found. Make sure it's in the root of this resource." )
169+
outputDebugString ( "[HEDIT] No handling.cfg found. Make sure it's in the root of this resource.", 2 )
170170
return false
171171
end )

[gameplay]/hedit/server/core.lua

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,21 @@ addEventHandler ( "onResourceStart", resourceRoot, function ( )
77

88
local resName = getResourceName ( resource )
99

10-
setElementData(resourceRoot, "resourceVersion", getResourceInfo(resource, "version"))
11-
1210
if resName ~= "hedit" and not DEBUGMODE then
13-
outputChatBox ( "Handling Editor failed to start, see the logs for more information." )
14-
print ( "===============================================================================" )
15-
print ( "[HEDIT] Please rename resource '"..resName.."' to 'hedit' to use the handling editor." )
16-
print ( "[HEDIT] The handling editor will not work unless you rename the resource to 'hedit'." )
17-
print ( "===============================================================================" )
11+
outputDebugString ( "[HEDIT] Please rename resource '"..resName.."' to 'hedit' to use the handling editor.", 1)
1812
return cancelEvent ( true, "Rename the handling editor resource to 'hedit' in order to use the resource." )
1913
end
2014

21-
22-
print ( "===============================================================================" )
23-
print ( " MTA:SA HANDLING EDITOR [hedit.github.io]" )
24-
print ( "===============================================================================" )
2515
if fileExists ( "handling.cfg" ) then
26-
print ( " Handling.cfg found." )
27-
print ( " Type 'loadcfg' to load handling.cfg into the memory." )
28-
print ( " After this, you can import the handling into defaults.xml." )
29-
print ( "===============================================================================" )
16+
outputDebugString ( "[HEDIT] Handling.cfg found; type 'loadcfg' to load handling.cfg into the memory.")
3017
end
3118

3219
--Parse meta settings
3320
parseMetaSettings()
3421
addEventHandler("onSettingChange", root, parseMetaSettings)
3522

3623
for model=400,611 do
37-
setElementData ( root, "originalHandling."..tostring ( model ), getOriginalHandling ( model, true ) )
24+
setElementData ( resourceRoot, "hedit:originalHandling."..tostring ( model ), getOriginalHandling ( model, true ), true, "deny" )
3825
end
3926

4027
--initiateCFGLoader ( )

[gameplay]/hedit/server/logmanager.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local vehicleLogs = {}
22

33
function loadHandlingLog ( )
4-
local data = getElementData ( root, "hedit:vehicleLogs" )
4+
local data = getElementData ( root, "hedit:vehicleLogs" ) -- retrieve stashed vehicleLogs from root element data (if it exists)
55

66
if data then
77
vehicleLogs = data
@@ -12,7 +12,7 @@ end
1212

1313

1414
function unloadHandlingLog ( )
15-
setElementData ( root, "hedit:vehicleLogs", vehicleLogs, false )
15+
setElementData ( root, "hedit:vehicleLogs", vehicleLogs, false, "deny") -- stash vehicleLogs as root element data so it can be recovered on next start
1616

1717
return true
1818
end
@@ -109,7 +109,7 @@ function uploadFullLog ( vehicle )
109109
return false
110110
end
111111

112-
triggerClientEvent ( client, "receiveFullLog", client, getElementData(root,"hedit:vehicleLogs")[vehicle] )
112+
triggerClientEvent ( client, "receiveFullLog", client, vehicleLogs[vehicle] )
113113
return true
114114
end
115115
addEvent ( "requestFullLog", true )

[gameplay]/hedit/server/utils.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ function parseMetaSettings()
123123
propertySettings[handlingProperty] = tobool(settingExists)
124124
else
125125
propertySettings[handlingProperty] = false
126-
print("Missing setting for "..handlingProperty..", defaulting to false.")
127126
outputDebugString("Missing setting for "..handlingProperty..", defaulting to false.", 2)
128127
end
129128
end
130-
setElementData(resourceRoot, "propertySettings", propertySettings)
129+
setElementData(resourceRoot, "hedit:propertySettings", propertySettings, true, "deny")
131130
end
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
DEBUGMODE = false
22

3-
MTAVER = 1.6
4-
HVER = "2.1.5"
3+
HVER = "2.1.6"

[gameplay]/hedit/shared/utils.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ end
136136
--This function returns true if a setting is enabled in the meta, false otherwise.
137137
function isHandlingPropertyEnabled(property)
138138
if getLocalPlayer then
139-
return (getElementData(resourceRoot, "propertySettings", false)[property]) or true
139+
return (getElementData(resourceRoot, "hedit:propertySettings", false)[property]) or true
140140
else
141141
return tobool(get("*enable_"..property))
142142
end
@@ -330,7 +330,7 @@ function getHandlingPreviousValue ( vehicle, property )
330330
return false
331331
end
332332

333-
return getElementData ( vehicle, "hedit:vehiclepreviousvalue."..property )
333+
return getElementData ( vehicle, "hedit:vehiclepreviousvalue."..property, false )
334334
end
335335

336336

@@ -344,7 +344,7 @@ function setVehicleSaved ( vehicle, saved )
344344
return true
345345
end
346346

347-
setElementData ( vehicle, "hedit:saved", tostring ( saved ) )
347+
setElementData ( vehicle, "hedit:saved", tostring ( saved ), true, "deny" )
348348

349349
local occupants = getVehicleOccupants ( vehicle )
350350
local seats = getVehicleMaxPassengers ( vehicle )
@@ -370,8 +370,8 @@ function isVehicleSaved ( vehicle )
370370
return false
371371
end
372372

373-
if not getElementData ( vehicle, "hedit:saved" ) then
374-
setElementData ( vehicle, "hedit:saved", "true" )
373+
if not getElementData ( vehicle, "hedit:saved", false ) then
374+
setElementData ( vehicle, "hedit:saved", "true", true, "deny" )
375375
end
376376

377377
return tobool ( getElementData ( vehicle, "hedit:saved" ) )

[gameplay]/hedit/shared/wrappers/general.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ end
1111

1212

1313
_outputDebugString = outputDebugString
14-
function outputDebugString(...)
15-
if DEBUGMODE then
16-
return _outputDebugString(...)
17-
end
14+
function outputDebugString(string, level, r, g, b)
15+
if not level then level = 3 end
16+
if (not DEBUGMODE) and level >= 3 then return end
17+
return _outputDebugString(string, level, r, g, b)
1818
end
1919

2020

[gameplay]/hedit/shared/wrappers/handling.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function setVehicleHandling ( vehicle, property, value, withLog )
175175
end
176176

177177

178-
setElementData ( vehicle, "hedit:vehiclepreviousvalue."..property, oldValue )
178+
setElementData ( vehicle, "hedit:vehiclepreviousvalue."..property, oldValue, true, "deny" )
179179

180180
triggerEvent ( "onVehicleHandlingChange", client, vehicle, property, oldValue, value )
181181

@@ -197,7 +197,7 @@ function getOriginalHandling ( model, force )
197197
return nil
198198
end
199199

200-
local data = getElementData ( root, "originalHandling."..tostring(model) )
200+
local data = getElementData ( resourceRoot, "hedit:originalHandling."..tostring(model), false )
201201
if not data or force then
202202
data = conformHandlingTable ( _getOriginalHandling ( model ), model )
203203
end

0 commit comments

Comments
 (0)