-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClosureManager.hpp
More file actions
70 lines (54 loc) · 2.71 KB
/
Copy pathClosureManager.hpp
File metadata and controls
70 lines (54 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Created by Dottik on 21/8/2024.
//
#pragma once
#include <algorithm>
#include <lobject.h>
#include <lua.h>
#include <map>
#include "Roblox/TypeDefinitions.hpp"
struct LuauHookInformation {
/// @brief Used to quickly distinguish between a C function and a Lua function.
bool isC;
/// @brief Whether or not the hook was a C->L or L->C hook, which cannot be unhooked due to its nature.
bool isWrappedHook;
/// @brief A clone of the original closure, not returned by hookfunction.
/// must be referenced on the lua registry, else, it may be as well useless, due to it being GCd.
Closure *originalClosureClone;
/// @brief The replaced closure on the environment.
Closure *hookedClosure;
};
struct ClosureWrapInformation {
Closure *closure;
bool requiresYielding;
};
class ClosureManager final {
static std::shared_ptr<ClosureManager> pInstance;
std::map<RBX::DataModelType, std::map<Closure *, LuauHookInformation>>
m_hookMap; // TODO: Make hook map use DataModel Types'
std::map<RBX::DataModelType, std::map<Closure *, ClosureWrapInformation>> m_newcclosureMap;
/// @brief Handles a newcclosure call.
static int newcclosure_handler(lua_State *L);
public:
static std::shared_ptr<ClosureManager> GetSingleton();
void ResetManager(const RBX::DataModelType &resetTarget);
bool IsWrappedCClosure(lua_State *L, Closure *cl);
bool IsWrapped(lua_State *L, const Closure *closure);
/// @brief Hooks two functions present at the top of the lua_State's stack.
/// @remarks This requires two closures, no matter which type, to be present on the lua stack, else this function
/// call will fail.
static int hookfunction(lua_State *L);
/// @brief Unhooks the function present at the top of the lua_State's stack.
/// @remarks This requires a closures, no matter which type, to be present on the lua stack.
static int unhookfunction(lua_State *L);
void FixClosure(lua_State *L, Closure *closure);
/// @brief Wraps the closure at the top of the lua_State's stack into a C closure, no matter which type.
/// @remarks This function will leave the resulting new C closure at the top of the lua stack!
static int newcclosure(lua_State *L);
/// @brief Wraps the closure at the top of the lua_State's stack into an L closure, no matter which type.
/// @remarks This function will leave the resulting new L closure at the top of the lua stack!
static int newlclosure(lua_State *L);
/// @brief Clones the function present at the top of the stack. No matter which type of closure it is.
/// @remarks This function will leave the resulting closure at the top of the lua stack!
static int clonefunction(lua_State *L);
};