Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions EEex-v2.6.6.0/headers/EEex-v2.6.6.0/EEex.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace EEex {
void Opcode_Hook_OnCopy(CGameEffect* pSrcEffect, CGameEffect* pDstEffect);
void Opcode_Hook_OnDestruct(CGameEffect* pEffect);
void Opcode_Hook_AfterListsResolved(CGameSprite* pSprite);
void Opcode_Hook_FlushDeferredAfterListsResolved(CGameSprite* pSprite);

////////////
// Sprite //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4885,6 +4885,7 @@ namespace EEex
extern byte CGameSprite_Hit_Roll;
extern bool AIBase_LuaHook_OnEventTriggerSet_Enabled;
extern bool Opcode_LuaHook_AfterListsResolved_Enabled;
extern bool Opcode_LuaHook_DeferredAfterListsResolved_Enabled;
extern bool Projectile_LuaHook_GlobalMutators_Enabled;
extern bool StutterDetector_Enabled;
extern int UncapFPS_BusyWaitThreshold;
Expand Down
1 change: 1 addition & 0 deletions EEex-v2.6.6.0/scripts/generate_bindings/in/bindings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace EEex
// Globals
bool AIBase_LuaHook_OnEventTriggerSet_Enabled;
bool Opcode_LuaHook_AfterListsResolved_Enabled;
bool Opcode_LuaHook_DeferredAfterListsResolved_Enabled;
bool Projectile_LuaHook_GlobalMutators_Enabled;
bool StutterDetector_Enabled;
int UncapFPS_BusyWaitThreshold;
Expand Down
40 changes: 40 additions & 0 deletions EEex-v2.6.6.0/source/EEex-v2.6.6.0/EEex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ struct ExSpriteData {

EngineVal<CVidBitmap> combatRoundsOverride[5]{};
Array<int, 3> oldDisabledSpellTypes;
bool deferredAfterListsResolvedPending = false;
int oldDisableSpells = 0;
uint64_t uuid = 0;

Expand Down Expand Up @@ -3837,6 +3838,13 @@ void EEex::Opcode_Hook_AfterListsResolved(CGameSprite* pSprite) {
CDerivedStats& stats = *pSprite->GetActiveStats();
lua_State *const L = luaState();

if (EEex::Opcode_LuaHook_DeferredAfterListsResolved_Enabled) {
// The engine can resolve the same sprite's effect lists many times in a
// tick. Defer opt-in Lua listeners to the sprite's real AI pass, where
// this bit is consumed and collapsed to one Lua call.
exData.deferredAfterListsResolvedPending = true;
}

if
(
stats.m_disableSpells != exData.oldDisableSpells
Expand Down Expand Up @@ -3869,6 +3877,37 @@ void EEex::Opcode_Hook_AfterListsResolved(CGameSprite* pSprite) {
STUTTER_LOG_END
}

void EEex::Opcode_Hook_FlushDeferredAfterListsResolved(CGameSprite* pSprite) {

STUTTER_LOG_START(void, "EEex::Opcode_Hook_FlushDeferredAfterListsResolved")

if (!EEex::Opcode_LuaHook_DeferredAfterListsResolved_Enabled) {
return;
}

auto itr = exSpriteDataMap.find(pSprite);
if (itr == exSpriteDataMap.end()) {
return;
}

ExSpriteData& exData = itr->second;
if (!exData.deferredAfterListsResolvedPending) {
return;
}

// Clear before entering Lua. If the callback causes another list
// resolution, the new pending bit survives for the next ProcessAI() pass.
exData.deferredAfterListsResolvedPending = false;

lua_State *const L = luaState();
luaCallProtected(L, 1, 0, [&](int _) {
lua_getglobal(L, "EEex_Opcode_LuaHook_DeferredAfterListsResolved"); // 1 [ ..., EEex_Opcode_LuaHook_DeferredAfterListsResolved ]
tolua_pushusertype(L, pSprite, "CGameSprite"); // 2 [ ..., EEex_Opcode_LuaHook_DeferredAfterListsResolved, pSpriteUD ]
});

STUTTER_LOG_END
}

////////////
// Sprite //
////////////
Expand Down Expand Up @@ -5361,6 +5400,7 @@ void EEex::InitEEex() {
initUncapFPS();

EEex::Opcode_LuaHook_AfterListsResolved_Enabled = false;
EEex::Opcode_LuaHook_DeferredAfterListsResolved_Enabled = false;
EEex::Projectile_LuaHook_GlobalMutators_Enabled = false;
initProjectileMutator();
EEex::StutterDetector_Enabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bool EEex::bStripUUID;
byte EEex::CGameSprite_Hit_Roll;
bool EEex::AIBase_LuaHook_OnEventTriggerSet_Enabled;
bool EEex::Opcode_LuaHook_AfterListsResolved_Enabled;
bool EEex::Opcode_LuaHook_DeferredAfterListsResolved_Enabled;
bool EEex::Projectile_LuaHook_GlobalMutators_Enabled;
bool EEex::StutterDetector_Enabled;
int EEex::UncapFPS_BusyWaitThreshold;
Expand Down
21 changes: 21 additions & 0 deletions EEex-v2.6.6.0/source/EEex-v2.6.6.0/Generated/EEexLua_generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ static int tolua_get_EEex_reference_Opcode_LuaHook_AfterListsResolved_Enabled(lu
return 1;
}

static int tolua_get_EEex_Opcode_LuaHook_DeferredAfterListsResolved_Enabled(lua_State* L)
{
tolua_pushboolean(L, (bool)EEex::Opcode_LuaHook_DeferredAfterListsResolved_Enabled);
return 1;
}

static int tolua_set_EEex_Opcode_LuaHook_DeferredAfterListsResolved_Enabled(lua_State* L)
{
EEex::Opcode_LuaHook_DeferredAfterListsResolved_Enabled = tolua_setter_toboolean(L, "Opcode_LuaHook_DeferredAfterListsResolved_Enabled");
return 0;
}

static int tolua_get_EEex_reference_Opcode_LuaHook_DeferredAfterListsResolved_Enabled(lua_State* L)
{
tolua_pushusertype(L, (void*)&EEex::Opcode_LuaHook_DeferredAfterListsResolved_Enabled, "Primitive<bool>");
return 1;
}

static int tolua_get_EEex_Projectile_LuaHook_GlobalMutators_Enabled(lua_State* L)
{
tolua_pushboolean(L, (bool)EEex::Projectile_LuaHook_GlobalMutators_Enabled);
Expand Down Expand Up @@ -917,6 +935,8 @@ int OpenBindingsInternal(lua_State* L)
tolua_variable(L, "reference_AIBase_LuaHook_OnEventTriggerSet_Enabled", tolua_get_EEex_reference_AIBase_LuaHook_OnEventTriggerSet_Enabled, NULL);
tolua_variable(L, "Opcode_LuaHook_AfterListsResolved_Enabled", tolua_get_EEex_Opcode_LuaHook_AfterListsResolved_Enabled, tolua_set_EEex_Opcode_LuaHook_AfterListsResolved_Enabled);
tolua_variable(L, "reference_Opcode_LuaHook_AfterListsResolved_Enabled", tolua_get_EEex_reference_Opcode_LuaHook_AfterListsResolved_Enabled, NULL);
tolua_variable(L, "Opcode_LuaHook_DeferredAfterListsResolved_Enabled", tolua_get_EEex_Opcode_LuaHook_DeferredAfterListsResolved_Enabled, tolua_set_EEex_Opcode_LuaHook_DeferredAfterListsResolved_Enabled);
tolua_variable(L, "reference_Opcode_LuaHook_DeferredAfterListsResolved_Enabled", tolua_get_EEex_reference_Opcode_LuaHook_DeferredAfterListsResolved_Enabled, NULL);
tolua_variable(L, "Projectile_LuaHook_GlobalMutators_Enabled", tolua_get_EEex_Projectile_LuaHook_GlobalMutators_Enabled, tolua_set_EEex_Projectile_LuaHook_GlobalMutators_Enabled);
tolua_variable(L, "reference_Projectile_LuaHook_GlobalMutators_Enabled", tolua_get_EEex_reference_Projectile_LuaHook_GlobalMutators_Enabled, NULL);
tolua_variable(L, "StutterDetector_Enabled", tolua_get_EEex_StutterDetector_Enabled, tolua_set_EEex_StutterDetector_Enabled);
Expand Down Expand Up @@ -961,6 +981,7 @@ int OpenBindingsInternal(lua_State* L)
tolua_function(L, "UpdateLastScrollTime", &tolua_function_EEex_UpdateLastScrollTime);
tolua_constantstring(L, "usertype_AIBase_LuaHook_OnEventTriggerSet_Enabled", "Primitive<bool>");
tolua_constantstring(L, "usertype_Opcode_LuaHook_AfterListsResolved_Enabled", "Primitive<bool>");
tolua_constantstring(L, "usertype_Opcode_LuaHook_DeferredAfterListsResolved_Enabled", "Primitive<bool>");
tolua_constantstring(L, "usertype_Projectile_LuaHook_GlobalMutators_Enabled", "Primitive<bool>");
tolua_constantstring(L, "usertype_StutterDetector_Enabled", "Primitive<bool>");
tolua_constantstring(L, "usertype_UncapFPS_BusyWaitThreshold", "Primitive<int>");
Expand Down
1 change: 1 addition & 0 deletions EEex-v2.6.6.0/source/EEex-v2.6.6.0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static void exportPatterns() {
exportPattern(TEXT("EEex::Opcode_Hook_ApplySpell_ShouldFlipSplprotSourceAndTarget"), EEex::Opcode_Hook_ApplySpell_ShouldFlipSplprotSourceAndTarget);
exportPattern(TEXT("EEex::Opcode_Hook_OnCheckAdd"), EEex::Opcode_Hook_OnCheckAdd);
exportPattern(TEXT("EEex::Opcode_Hook_AfterListsResolved"), EEex::Opcode_Hook_AfterListsResolved);
exportPattern(TEXT("EEex::Opcode_Hook_FlushDeferredAfterListsResolved"), EEex::Opcode_Hook_FlushDeferredAfterListsResolved);

////////////
// Sprite //
Expand Down