Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string compression functions #3020

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lua/entities/gmod_wire_expression2/core/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,23 @@ e2function number string:unicodeLength(number startPos, number endPos)
end
return -1
end

--[[******************************************************************************]]--
__e2setcost(10)

local compress = util.Compress
local decompress = util.Decompress

e2function string compress(string plaintext)
local len = #plaintext
if len > 32768 then return self:throw("Input string is too long!", "") end
self.prf = self.prf + len * 0.1
return compress(plaintext)
end

e2function string decompress(string compressed)
local len = #compressed
if len > 32768 then return self:throw("Input string is too long!", "") end
self.prf = self.prf + len * 0.5
return decompress(compressed) or self:throw("Invalid input for decompression!", "")
end
2 changes: 2 additions & 0 deletions lua/wire/client/e2descriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ E2Helper.Descriptions["matchFirst(s:s)"] = "runs string.match(S, S2) and returns
E2Helper.Descriptions["matchFirst(s:sn)"] = "runs string.match(S, S2, N) and returns the first match or an empty string if the match failed"
E2Helper.Descriptions["gmatch(s:s)"] = "runs string.gmatch(S, S2) and returns the captures in arrays in a table"
E2Helper.Descriptions["gmatch(s:sn)"] = "runs string.gmatch(S, S2, N) and returns the captures in arrays in a table"
E2Helper.Descriptions["compress(s)"] = "Compresses the input string using LZMA compression. See decompress(string)"
E2Helper.Descriptions["decompress(s)"] = "Decompresses an LZMA-compressed string. See compress(string)"

-- Entity/Player
E2Helper.Descriptions["entity(n)"] = "Gets the entity associated with the id"
Expand Down
Loading