MarrKoo

Reduce_Read_Time.lua

Jan 27th, 2021 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. -- Reduce Read Time
  2. -- require "TimedActions/ISReadABook"
  3.  
  4. --SIMPLE INJECTION
  5.  
  6. local old_fn = ISReadABook.new; -- We put the link to the old function in a variable "old_fn".
  7.  
  8. -- Replacing the old function with new one.
  9. -- The old function continues to exist and we have the link in the variable old_fn.
  10. function ISReadABook:new(...) -- "..." means any parameters. ":" means unlisted "self" parameter.
  11.     local o = old_fn(self, ...); -- We call old function and give all parameters to it.
  12.     -- The result o is saved in a local variable o.
  13.     -- AFTER old function is finished, we apply our patch.
  14.     -- Sadly, injection in the middle of the function (if possible) should be more complicated.
  15.     -- So we keep it simple:
  16.     -- We only have to take into account that at the end of the old function, time can be overwritten by 1.
  17.     if o.maxTime ~= 1 then
  18.         o.maxTime = o.maxTime * 0.5;
  19.     end
  20.     return o; --We return o as old function did.
  21. end
  22. -- Now nobody (except us) has access to the old function.
Advertisement
Add Comment
Please, Sign In to add comment