Skip to content

Commit

Permalink
Add compression functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Denneisk committed Mar 25, 2024
1 parent 1c5f5a0 commit 2b54403
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 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,19 @@ 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)
self.prf = self.prf + #plaintext * 0.1
return compress(plaintext)
end

e2function string decompress(string compressed)
self.prf = self.prf + #compressed * 0.5
return decompress(compressed) or ""
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

0 comments on commit 2b54403

Please sign in to comment.