Skip to content

Commit

Permalink
Feature/ragdolforce (#10)
Browse files Browse the repository at this point in the history
* wip

* Fix
  • Loading branch information
brandonsturgeon authored Jul 4, 2024
1 parent 3e9c2ae commit 84e6630
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
31 changes: 24 additions & 7 deletions moon/wiremod_limits/lib/e2.moon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import rawget, rawset, CurTime, IsValid from _G
import CurTime, IsValid from _G

CFCWiremodLimits.Lib.E2 = {
alertDelay: 3
Expand All @@ -17,8 +17,8 @@ e2.throttleGroup = (signatures, throttleStruct) ->
makeThrottler = (sig) ->
id = groupName

failure = alertFailure and =>
ply = rawget self, "player"
failure = =>
ply @player
return unless IsValid ply

throttleAlerts = ply.E2ThrottleAlerts
Expand All @@ -28,14 +28,14 @@ e2.throttleGroup = (signatures, throttleStruct) ->
ply.E2ThrottleAlerts = {}

now = CurTime!
lastAlert = rawget(throttleAlerts, id) or 0
return if lastAlert > now - rawget(e2, "alertDelay")
lastAlert = throttleAlerts[id] or 0
return if lastAlert > now - e2.alertDelay

ply\ChatPrint "'#{sig}' was rate-limited! You must wait #{delay} seconds between executions (or wait for your budget to refill)"
ply\ChatPrint "(Budget: #{budget} | Refill Rate: #{refillRate}/second)"
rawset throttleAlerts, id, now
throttleAlerts[id] = now

throttleStruct.failure = failure if failure
throttleStruct.failure = failure if alertFailure

Throttler\create originals[sig], throttleStruct

Expand All @@ -51,5 +51,22 @@ e2.throttleFuncs = (signatures, delay, message) ->
for signature in *signatures
e2.throttleFunc signature, delay, message

-- Wraps a set of functions with the same wrapper.
-- The wrapper receives the original function as the first argument
-- followed by the arguments passed to the original function
e2.wrapGroup = (signatures, wrapper) ->
funcs = wire_expression2_funcs
originals = {}

for signature in *signatures
original = funcs[signature][3]
originals[signature] = original

funcs[signature][3] = (...) ->
wrapper original, ...

e2.wrapFunc = (signature, wrapper) ->
e2.wrapGroup {signature}, wrapper

hook.Add "PlayerInitialSpawn", "WiremodLimits_E2ThrottleSetup", (ply) ->
ply.E2ThrottleAlerts = {}
29 changes: 29 additions & 0 deletions moon/wiremod_limits/modules/e2.moon
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,32 @@ do
.shouldSkip = => return true if @player\IsAdmin!

E2.throttleGroup use, throttle

do
toEntity = {
"applyAngForce(e:a)"
"applyForce(e:v)"
"applyOffsetForce(e:vv)"
}

subjectIsRagdoll = (args) ->
ent = args[1]
return ent\IsRagdoll!

subjectWrapper = (original, runtime, args, ...) ->
runtime\forceThrow "[CFC] applyForce functions are disabled on ragdolls" if subjectIsRagdoll args
original runtime, args, ...

E2.wrapGroup toEntity, subjectWrapper

do
toBone = {
"applyAngForce(b:a)"
"applyForce(b:v)"
"applyOffsetForce(b:vv)"
}

disabler = (original, runtime, args, ...) ->
runtime\forceThrow "[CFC] applyForce functions are disabled on bones"

E2.wrapGroup toBone, disabler

0 comments on commit 84e6630

Please sign in to comment.