Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRE_X_STATUS_APPLY & POST_X_STATUS_APPLY #571

Merged
merged 23 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c35152f
PRE/POST_X_STATUS_APPLY, 3/16
BabyblueSheep Oct 12, 2024
dbb3dc1
PRE/POST_X_STATUS_APPLY, 6/16 + fixes
BabyblueSheep Oct 12, 2024
14486d3
PRE/POST_X_STATUS_APPLY, 10/16
BabyblueSheep Oct 13, 2024
8deafe0
Merge branch 'TeamREPENTOGON:main' into status
BabyblueSheep Oct 13, 2024
af8efce
PRE/POST_X_STATUS_APPLY, 12/16, but heavy testing needed
BabyblueSheep Oct 14, 2024
8490e17
test callbacks
BabyblueSheep Oct 15, 2024
c85aaa2
Merge branch 'TeamREPENTOGON:main' into status
BabyblueSheep Oct 15, 2024
85b94b5
Merge branch 'TeamREPENTOGON:main' into status
BabyblueSheep Oct 16, 2024
5aecf95
PRE/POST_X_STATUS_APPLY, 14/16
BabyblueSheep Oct 16, 2024
332d900
Merge branch 'status' of https://github.com/BabyblueSheep/REPENTOGON …
BabyblueSheep Oct 16, 2024
d1439fd
PRE/POST_X_STATUS_APPLY, 16/16! testing needed
BabyblueSheep Oct 16, 2024
74f3fd9
tested, everything works. yay :)
BabyblueSheep Oct 16, 2024
0bb3a57
Update CustomCallbacks.cpp
BabyblueSheep Oct 16, 2024
cc91d67
i think im done
BabyblueSheep Oct 16, 2024
41a56e2
X_CONFUSION_STATUS_APPLY has ignoreBosses
BabyblueSheep Oct 16, 2024
c0cd182
fixes
BabyblueSheep Nov 9, 2024
af94f2b
Update changelog.txt
BabyblueSheep Nov 9, 2024
bf50d0e
remove documentation
BabyblueSheep Nov 9, 2024
f476dea
add documentation that i accidentally removed oops
BabyblueSheep Nov 9, 2024
8daccc5
more fixes
BabyblueSheep Nov 10, 2024
1113a77
try to fix merge conflict
BabyblueSheep Nov 10, 2024
ed68570
Update main_ex.lua
BabyblueSheep Nov 10, 2024
5c43b9b
Update main_ex.lua
BabyblueSheep Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Additions:
* EntityFamiliar:
- IsLilDelirium
- SetLilDelirium
* Enums:
- StatusEffect
* ModCallbacks:
- MC_PRE_PLAYER_POCKET_ITEM_SWAP(Player)
Triggers when the player swaps their pocket items using the action drop button (even if they are empty).
Expand All @@ -28,6 +30,16 @@ Additions:
- POST_ENTITY_SET_COLOR(Entity entity, int duration, int priority, bool fadeOut, bool share)
Fires after an entity's color is changed via Entity:SetColor
This only fires for `Entity:SetColor` and does not fire when changing the entity's color directly.
- MC_PRE_STATUS_EFFECT_APPLY(StatusEffect, Entity Entity, EntityRef Source, int Duration, nil or float or boolean or Vector ExtraParam1, nil or boolean or Color ExtraParam2)
Fires before a status efffect is applied to an entity.
Return an int to change duration.
Return false to cancel application. Prevents MC_POST_STATUS_EFFECT_APPLY from firing.
Return a table to change duration and extra parameters.
Extra parameters will be different depending on status effect.
This only fires for `Entity:AddX` methods.
- MC_POST_STATUS_EFFECT_APPLY(StatusEffect, Entity Entity, EntityRef Source, int Duration, nil or float or boolean or Vector ExtraParam1, nil or boolean or Color ExtraParam2)
Fires after a status efffect is applied to an entity.
This only fires for `Entity:AddX` methods.
* Added the following customtag for items.xml:
* "noexpansionpack" - Prevents the active item (with 1 or 2 max charges) from being picked by Expansion Pack trinket.
* Sprite:
Expand Down
330 changes: 330 additions & 0 deletions repentogon/LuaInterfaces/CustomCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4659,3 +4659,333 @@ HOOK_METHOD(Entity, GetStatusEffectTarget, () -> Entity*) {
}
return super();
}

// PRE/POST_STATUS_EFFECT_APPLY (1465/1466)
struct TimedOnlyStatusEffectApplyInputs {
Entity* entity;
EntityRef source;
int duration;
};

void HandleTimedOnlyStatusApplyCallback(int statusId, TimedOnlyStatusEffectApplyInputs& inputs, std::function<void(const EntityRef&, int)> super)
{
const int preCallbackId = 1465;

if (CallbackState.test(preCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults results = lua::LuaCaller(L).push(preCallbackId)
.push(statusId)
.push(statusId)
.push(inputs.entity, lua::Metatables::ENTITY)
.push(&(inputs.source), lua::Metatables::ENTITY_REF)
.push(inputs.duration)
.call(1);

if (!results) {
if (lua_isinteger(L, -1)) {
inputs.duration = (int)lua_tointeger(L, -1);
}
else if (lua_isboolean(L, -1))
{
if (!lua_toboolean(L, -1)) {
return;
}
}
}
}

super(inputs.source, inputs.duration);

const int postCallbackId = 1466;

if (CallbackState.test(postCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults result = lua::LuaCaller(L).push(postCallbackId)
.push(statusId)
.push(statusId)
.push(inputs.entity, lua::Metatables::ENTITY)
.push(&(inputs.source), lua::Metatables::ENTITY_REF)
.push(inputs.duration)
.call(1);
}
}

#define _APPLY_TIMED_ONLY_STATUS_EFFECT_LAMBDA() [this](const EntityRef& ref, int duration) { return super(ref, duration); }
#define HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(_method, statusId) \
HOOK_METHOD(Entity, _method, (const EntityRef& ref, int duration) -> void) { \
TimedOnlyStatusEffectApplyInputs inputs = {this, ref, duration}; \
HandleTimedOnlyStatusApplyCallback(statusId, inputs, _APPLY_TIMED_ONLY_STATUS_EFFECT_LAMBDA()); \
}

struct DamageStatusEffectApplyInputs {
Entity* entity;
EntityRef source;
int duration;
float damage;
};

void HandleDamageStatusApplyCallback(int statusId, DamageStatusEffectApplyInputs& inputs, std::function<void(const EntityRef&, int, float)> super)
{
const int preCallbackId = 1465;

if (CallbackState.test(preCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults results = lua::LuaCaller(L).push(preCallbackId)
.push(statusId)
.push(statusId)
.push(inputs.entity, lua::Metatables::ENTITY)
.push(&(inputs.source), lua::Metatables::ENTITY_REF)
.push(inputs.duration)
.push(inputs.damage)
.call(1);

if (!results) {
if (lua_istable(L, -1)) {
inputs.duration = lua::callbacks::ToInteger(L, 1);
inputs.damage = (float)lua::callbacks::ToNumber(L, 2);
}
else if (lua_isinteger(L, -1)) {
inputs.duration = (int)lua_tointeger(L, -1);
}
else if (lua_isboolean(L, -1))
{
if (!lua_toboolean(L, -1)) {
return;
}
}
}
}

super(inputs.source, inputs.duration, inputs.damage);

const int postCallbackId = 1466;

if (CallbackState.test(postCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults result = lua::LuaCaller(L).push(postCallbackId)
.push(statusId)
.push(statusId)
.push(inputs.entity, lua::Metatables::ENTITY)
.push(&(inputs.source), lua::Metatables::ENTITY_REF)
.push(inputs.duration)
.push(inputs.damage)
.call(1);
}
}

#define _APPLY_DAMAGE_STATUS_EFFECT_LAMBDA() [this](const EntityRef& ref, int duration, float damage) { return super(ref, duration, damage); }
#define HOOK_DAMAGE_STATUS_APPLY_CALLBACKS(_method, statusId) \
HOOK_METHOD(Entity, _method, (const EntityRef& ref, int duration, float damage) -> void) { \
DamageStatusEffectApplyInputs inputs = {this, ref, duration, damage}; \
HandleDamageStatusApplyCallback(statusId, inputs, _APPLY_DAMAGE_STATUS_EFFECT_LAMBDA()); \
}

HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddBaited, 0);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddBleeding, 1);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddBrimstoneMark, 2);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddCharmed, 4);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddFear, 6);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddFreeze, 7);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddIce, 8);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddMagnetized, 10);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddMidasFreeze, 11);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddShrink, 13);
HOOK_TIMED_ONLY_STATUS_APPLY_CALLBACKS(AddWeakness, 15);

HOOK_DAMAGE_STATUS_APPLY_CALLBACKS(AddBurn, 3);
HOOK_DAMAGE_STATUS_APPLY_CALLBACKS(AddPoison, 12);

HOOK_METHOD(Entity, AddConfusion, (const EntityRef& ref, int duration, bool ignoreBosses) -> void) {
const int preCallbackId = 1465;
const int statusId = 5;

if (CallbackState.test(preCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults results = lua::LuaCaller(L).push(preCallbackId)
.push(statusId)
.push(statusId)
.push(this, lua::Metatables::ENTITY)
.push((EntityRef*)(&ref), lua::Metatables::ENTITY_REF)
.push(duration)
.push(ignoreBosses)
.call(1);

if (!results) {
if (lua_istable(L, -1)) {
duration = lua::callbacks::ToInteger(L, 1);
ignoreBosses = lua::callbacks::ToBoolean(L, 2);
}
else if (lua_isinteger(L, -1)) {
duration = (int)lua_tointeger(L, -1);
}
else if (lua_isboolean(L, -1))
{
if (!lua_toboolean(L, -1)) {
return;
}
}
}
}

super(ref, duration, ignoreBosses);

const int postCallbackId = 1466;

if (CallbackState.test(postCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults result = lua::LuaCaller(L).push(postCallbackId)
.push(statusId)
.push(statusId)
.push(this, lua::Metatables::ENTITY)
.push((EntityRef*)(&ref), lua::Metatables::ENTITY_REF)
.push(duration)
.push(ignoreBosses)
.call(1);
}
}

HOOK_METHOD(Entity, AddKnockback, (const EntityRef& ref, const Vector& pushDirection, int duration, bool takeImpactDamage) -> void) {
Vector pushVector(pushDirection);

const int preCallbackId = 1465;
const int statusId = 9;

if (CallbackState.test(preCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults results = lua::LuaCaller(L).push(preCallbackId)
.push(statusId)
.push(statusId)
.push(this, lua::Metatables::ENTITY)
.push((EntityRef*)(&ref), lua::Metatables::ENTITY_REF)
.push(duration)
.push(&pushVector, lua::Metatables::VECTOR)
.push(takeImpactDamage)
.call(1);

if (!results) {
if (lua_istable(L, -1)) {
duration = lua::callbacks::ToInteger(L, 1);

lua_pushinteger(L, 2);
lua_gettable(L, -2);
pushVector = *lua::GetUserdata<Vector*>(L, -1, lua::Metatables::VECTOR, "Vector");
lua_pop(L, 1);

takeImpactDamage = lua::callbacks::ToBoolean(L, 3);
}
else if (lua_isinteger(L, -1)) {
duration = (int)lua_tointeger(L, -1);
}
else if (lua_isboolean(L, -1))
{
if (!lua_toboolean(L, -1)) {
return;
}
}
}
}

super(ref, pushVector, duration, takeImpactDamage);

const int postCallbackId = 1466;

if (CallbackState.test(postCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults result = lua::LuaCaller(L).push(postCallbackId)
.push(statusId)
.push(statusId)
.push(this, lua::Metatables::ENTITY)
.push((EntityRef*)(&ref), lua::Metatables::ENTITY_REF)
.push(duration)
.push(&pushVector, lua::Metatables::VECTOR)
.push(takeImpactDamage)
.call(1);
}
}

HOOK_METHOD(Entity, AddSlowing, (const EntityRef& ref, int duration, float amount, ColorMod color) -> void) {
const int preCallbackId = 1465;
const int statusId = 14;

if (CallbackState.test(preCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults results = lua::LuaCaller(L).push(preCallbackId)
.push(statusId)
.push(statusId)
.push(this, lua::Metatables::ENTITY)
.push((EntityRef*)(&ref), lua::Metatables::ENTITY_REF)
.push(duration)
.push(amount)
.push(&color, lua::Metatables::COLOR)
.call(1);

if (!results) {
if (lua_istable(L, -1)) {
duration = lua::callbacks::ToInteger(L, 1);
amount = (float)lua::callbacks::ToNumber(L, 1);

lua_pushinteger(L, 3);
lua_gettable(L, -2);
color = *lua::GetUserdata<ColorMod*>(L, -1, lua::Metatables::COLOR, "Color");
lua_pop(L, 1);

}
else if (lua_isinteger(L, -1)) {
duration = (int)lua_tointeger(L, -1);
}
else if (lua_isboolean(L, -1))
{
if (!lua_toboolean(L, -1)) {
return;
}
}
}
}

super(ref, duration, amount, color);

const int postCallbackId = 1466;

if (CallbackState.test(postCallbackId - 1000)) {
lua_State* L = g_LuaEngine->_state;
lua::LuaStackProtector protector(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key);

lua::LuaResults results = lua::LuaCaller(L).push(postCallbackId)
.push(statusId)
.push(statusId)
.push(this, lua::Metatables::ENTITY)
.push((EntityRef*)(&ref), lua::Metatables::ENTITY_REF)
.push(duration)
.push(amount)
.push(&color, lua::Metatables::COLOR)
.call(1);
}
}
21 changes: 21 additions & 0 deletions repentogon/resources/scripts/enums_ex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ ModCallbacks.MC_POST_GRID_ENTITY_PRESSUREPLATE_RENDER = 1461
ModCallbacks.MC_PRE_GRID_ENTITY_WALL_RENDER = 1462
ModCallbacks.MC_POST_GRID_ENTITY_WALL_RENDER = 1463
ModCallbacks.MC_MENU_INPUT_ACTION = 1464
ModCallbacks.MC_PRE_STATUS_EFFECT_APPLY = 1465
ModCallbacks.MC_POST_STATUS_EFFECT_APPLY = 1466

ModCallbacks.MC_POST_SAVESLOT_LOAD = 1470
ModCallbacks.MC_PRE_CHALLENGE_DONE = 1471
Expand Down Expand Up @@ -2776,6 +2778,25 @@ CharacterMenuStatus = {
CHARACTER_PAPER_SWAP = 4,
}

StatusEffect = {
BAITED = 0,
BLEEDING = 1,
BRIMSTONE_MARK = 2,
BURN = 3,
CHARMED = 4,
CONFUSION = 5,
FEAR = 6,
FREEZE = 7,
ICE = 8,
KNOCKBACK = 9,
MAGNETIZED = 10,
MIDAS_FREEZE = 11,
POISON = 12,
SHRINK = 13,
SLOWING = 14,
WEAKNESS = 15,
}

--deprecated enums

Achievement.REVERSED_THE_HEIROPHANT = 529
Expand Down
Loading