Skip to content

Commit

Permalink
Add file.existsInGame and game.modelExists (#1953)
Browse files Browse the repository at this point in the history
* Add file.existsInGame

* Add game.modelExists
  • Loading branch information
thegrb93 authored Dec 31, 2024
1 parent d0142d9 commit 7ecd2b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lua/starfall/libs_cl/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ registerprivilege("file.read", "Read files", "Allows the user to read files from
registerprivilege("file.write", "Write files", "Allows the user to write files to data/sf_filedata directory", { client = { default = 1 } })
registerprivilege("file.writeTemp", "Write temporary files", "Allows the user to write temp files to data/sf_filedatatemp directory", { client = {} })
registerprivilege("file.exists", "File existence check", "Allows the user to determine whether a file in data/sf_filedata exists", { client = { default = 1 } })
registerprivilege("file.existsInGame", "File existence check", "Allows the user to determine whether a file in game dir exists", { client = { default = 1 } })
registerprivilege("file.isDir", "Directory check", "Allows the user to determine whether a file in data/sf_filedata is a directory", { client = { default = 1 } })
registerprivilege("file.find", "File find", "Allows the user to see what files are in data/sf_filedata", { client = { default = 1 } })
registerprivilege("file.findInGame", "File find in garrysmod", "Allows the user to see what files are in garrysmod", { client = { default = 1 } })
Expand Down Expand Up @@ -319,6 +320,15 @@ function file_library.exists(path)
return file.Exists("sf_filedata/" .. SF.NormalizePath(path), "DATA")
end

--- Checks if a file exists in path relative to gmod
-- @param string path Filepath in game folder
-- @return boolean? True if exists, false if not, nil if error
function file_library.existsInGame(path)
checkpermission (instance, path, "file.existsInGame")
checkluatype (path, TYPE_STRING)
return file.Exists(SF.NormalizePath(path), "GAME")
end

--- Checks if a given file is a directory or not
-- @param string path Filepath relative to data/sf_filedata/.
-- @return boolean True if given path is a directory, false if it's a file
Expand Down
10 changes: 10 additions & 0 deletions lua/starfall/libs_sh/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ game_library.getRealTickInterval = engine.AbsoluteFrameTime
-- @return number Ticks
game_library.getTickCount = engine.TickCount

--- Checks if a model exists in the game files
-- @param string path Filepath in game folder
-- @return boolean? True if exists, false if not, nil if error
function game_library.modelExists(path)
checkluatype (path, TYPE_STRING)
path = SF.NormalizePath(path)
if string.find(path, "models/", 1, true)~=1 then return false end
return file.Exists(path, "GAME")
end

--- Returns AmmoData for given id
-- @param number id See https://wiki.facepunch.com/gmod/Default_Ammo_Types
-- @return table AmmoData, see https://wiki.facepunch.com/gmod/Structures/AmmoData
Expand Down

0 comments on commit 7ecd2b4

Please sign in to comment.