|
| 1 | +#include "IsaacRepentance.h" |
| 2 | +#include "LuaCore.h" |
| 3 | +#include "HookSystem.h" |
| 4 | + |
| 5 | +LUA_FUNCTION(Lua_TearParams_GetMassMultiplier) { |
| 6 | + TearParams* params = lua::GetLuabridgeUserdata<TearParams*>(L, 1, lua::Metatables::TEAR_PARAMS, "TearParams"); |
| 7 | + lua_pushnumber(L, params->_massMultiplier); |
| 8 | + return 1; |
| 9 | +} |
| 10 | +LUA_FUNCTION(Lua_TearParams_SetMassMultiplier) { |
| 11 | + TearParams* params = lua::GetLuabridgeUserdata<TearParams*>(L, 1, lua::Metatables::TEAR_PARAMS, "TearParams"); |
| 12 | + float value = (float)luaL_checknumber(L, 2); |
| 13 | + if (value <= 0) { |
| 14 | + return luaL_argerror(L, 2, "MassMultiplier must be positive!"); |
| 15 | + } |
| 16 | + params->_massMultiplier = value; |
| 17 | + return 0; |
| 18 | +} |
| 19 | + |
| 20 | +LUA_FUNCTION(Lua_TearParams_GetKnockbackMultiplier) { |
| 21 | + TearParams* params = lua::GetLuabridgeUserdata<TearParams*>(L, 1, lua::Metatables::TEAR_PARAMS, "TearParams"); |
| 22 | + lua_pushnumber(L, params->_knockbackMultiplier); |
| 23 | + return 1; |
| 24 | +} |
| 25 | +LUA_FUNCTION(Lua_TearParams_SetKnockbackMultiplier) { |
| 26 | + TearParams* params = lua::GetLuabridgeUserdata<TearParams*>(L, 1, lua::Metatables::TEAR_PARAMS, "TearParams"); |
| 27 | + float value = (float)luaL_checknumber(L, 2); |
| 28 | + if (value <= 0) { |
| 29 | + return luaL_argerror(L, 2, "KnockbackMultiplier must be positive!"); |
| 30 | + } |
| 31 | + params->_knockbackMultiplier = value; |
| 32 | + return 0; |
| 33 | +} |
| 34 | + |
| 35 | +LUA_FUNCTION(Lua_TearParams_GetSpeedMultiplier) { |
| 36 | + TearParams* params = lua::GetLuabridgeUserdata<TearParams*>(L, 1, lua::Metatables::TEAR_PARAMS, "TearParams"); |
| 37 | + lua_pushnumber(L, params->_speedMultiplier); |
| 38 | + return 1; |
| 39 | +} |
| 40 | +LUA_FUNCTION(Lua_TearParams_SetSpeedMultiplier) { |
| 41 | + TearParams* params = lua::GetLuabridgeUserdata<TearParams*>(L, 1, lua::Metatables::TEAR_PARAMS, "TearParams"); |
| 42 | + params->_speedMultiplier = (float)luaL_checknumber(L, 2); |
| 43 | + return 0; |
| 44 | +} |
| 45 | + |
| 46 | +LUA_FUNCTION(Lua_TearParams_GetTearDisplacement) { |
| 47 | + TearParams* params = lua::GetLuabridgeUserdata<TearParams*>(L, 1, lua::Metatables::TEAR_PARAMS, "TearParams"); |
| 48 | + lua_pushinteger(L, params->_tearDisplacement); |
| 49 | + return 1; |
| 50 | +} |
| 51 | +LUA_FUNCTION(Lua_TearParams_SetTearDisplacement) { |
| 52 | + TearParams* params = lua::GetLuabridgeUserdata<TearParams*>(L, 1, lua::Metatables::TEAR_PARAMS, "TearParams"); |
| 53 | + int value = (int)luaL_checkinteger(L, 2); |
| 54 | + if (value < -1 || value > 1) { |
| 55 | + // 0 is technically "valid" in that the game can sometimes allow it via GetTearHitParams. |
| 56 | + // I dunno what the implication of having it be zero is though, it doesn't seem entirely intentional. |
| 57 | + // Not treating 0 as an error, but also not going to mention it in the error message. |
| 58 | + return luaL_argerror(L, 2, "TearDisplacement may only be set to -1 or 1"); |
| 59 | + } |
| 60 | + params->_tearDisplacement = value; |
| 61 | + return 0; |
| 62 | +} |
| 63 | + |
| 64 | +inline void RegisterTearParamsVariable(lua_State* L, const char* name, lua_CFunction getFunc, lua_CFunction setFunc) { |
| 65 | + lua::RegisterVariable(L, lua::Metatables::TEAR_PARAMS, name, getFunc, setFunc); |
| 66 | + lua::RegisterVariableGetter(L, lua::Metatables::CONST_TEAR_PARAMS, name, getFunc); |
| 67 | +} |
| 68 | +HOOK_METHOD(LuaEngine, RegisterClasses, () -> void) { |
| 69 | + super(); |
| 70 | + |
| 71 | + lua::LuaStackProtector protector(_state); |
| 72 | + |
| 73 | + RegisterTearParamsVariable(_state, "MassMultiplier", Lua_TearParams_GetMassMultiplier, Lua_TearParams_SetMassMultiplier); |
| 74 | + RegisterTearParamsVariable(_state, "KnockbackMultiplier", Lua_TearParams_GetKnockbackMultiplier, Lua_TearParams_SetKnockbackMultiplier); |
| 75 | + RegisterTearParamsVariable(_state, "SpeedMultiplier", Lua_TearParams_GetSpeedMultiplier, Lua_TearParams_SetSpeedMultiplier); |
| 76 | + RegisterTearParamsVariable(_state, "TearDisplacement", Lua_TearParams_GetTearDisplacement, Lua_TearParams_SetTearDisplacement); |
| 77 | +} |
0 commit comments