Skip to content

Commit

Permalink
MC_EVALUATE_FAMILIAR_MULTIPLIER + WIP CustomCache system
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorForan committed Jul 14, 2024
1 parent ff75d0f commit a8d7d6d
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 41 deletions.
3 changes: 3 additions & 0 deletions libzhl/functions/EntityFamiliar.zhl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ __thiscall void Entity_Familiar::RemoveFromPlayer(bool UnusedRemoveFamiliar);
"8b41??3d84030000":
__thiscall bool Entity_Familiar::CanCharm();

"538bdc83ec0883e4f883c404558b6b??896c24??8bec6aff68????????64a1????????505381ece800000056":
__thiscall void Entity_Familiar::WispInit();


struct Entity_Familiar depends (ColorMod, ItemConfig_Item) : public Entity {
{{
Expand Down
3 changes: 2 additions & 1 deletion libzhl/functions/TemporaryEffects.zhl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ __thiscall void TemporaryEffects::AddEffect(TemporaryEffect* Effect, bool addcos
struct TemporaryEffects
{
vector_TemporaryEffect _effects : 0x4;
bool _disabled: 0x11;
bool _shouldEvaluateCache : 0x10;
bool _disabled : 0x11;
Entity_Player* _player : 0x14;
} : 0x18;
11 changes: 11 additions & 0 deletions repentogon/LuaInterfaces/Entities/LuaEntityFamiliar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "LuaCore.h"
#include "HookSystem.h"
#include "../../Patches/FamiliarTags.h"
#include "../../Patches/EntityPlus.h"

LUA_FUNCTION(Lua_FamiliarGetFollowerPriority)
{
Expand Down Expand Up @@ -153,6 +154,15 @@ LUA_FUNCTION(Lua_FamiliarGetItemConfig) {
return 1;
}

LUA_FUNCTION(Lua_FamiliarEvaluateMultiplier) {
auto* fam = lua::GetUserdata<Entity_Familiar*>(L, 1, lua::Metatables::ENTITY_FAMILIAR, "EntityFamiliar");
EntityFamiliarPlus* famPlus = GetEntityFamiliarPlus(fam);
if (famPlus) {
famPlus->cachedMultiplier = std::nullopt;
}
return 0;
}

HOOK_METHOD(LuaEngine, RegisterClasses, () -> void) {
super();

Expand All @@ -175,6 +185,7 @@ HOOK_METHOD(LuaEngine, RegisterClasses, () -> void) {
{ "GetMoveDelayNum", Lua_FamiliarGetMoveDelayNum },
{ "SetMoveDelayNum", Lua_FamiliarSetMoveDelayNum },
{ "GetItemConfig", Lua_FamiliarGetItemConfig },
{ "EvaluateMultiplier", Lua_FamiliarEvaluateMultiplier },
{ NULL, NULL }
};

Expand Down
52 changes: 52 additions & 0 deletions repentogon/LuaInterfaces/Entities/LuaEntityPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "../LuaWeapon.h"
#include "../../Patches/ASMPatches/ASMPlayer.h"
#include "../../Patches/ExtraLives.h"
#include "../../Patches/EntityPlus.h"
#include "../../Patches/XmlData.h"


/*
Expand Down Expand Up @@ -2366,6 +2368,54 @@ LUA_FUNCTION(Lua_PlayerGetBombVariant) {
return 1;
}

LUA_FUNCTION(Lua_PlayerAddCustomCacheTag) {
Entity_Player* player = lua::GetUserdata<Entity_Player*>(L, 1, lua::Metatables::ENTITY_PLAYER, "EntityPlayer");

EntityPlayerPlus* playerPlus = GetEntityPlayerPlus(player);

const int type = lua_type(L, 2);

if (type == LUA_TTABLE) {
std::set<std::string> customcaches;

auto tableLength = lua_rawlen(L, 2);
for (auto i = 1; i <= tableLength; ++i) {
lua_pushinteger(L, i);
lua_gettable(L, 2);
if (lua_type(L, -1) == LUA_TNIL)
break;
playerPlus->customCacheTags.insert(stringlower(luaL_checkstring(L, -1)));
lua_pop(L, 1);
}
}
else {
playerPlus->customCacheTags.insert(stringlower(luaL_checkstring(L, 2)));
}

const bool evalItems = lua::luaL_optboolean(L, 3, false);

if (evalItems) {
player->EvaluateItems();
}

return 0;
}

LUA_FUNCTION(Lua_PlayerGetCustomCacheValue) {
Entity_Player* player = lua::GetUserdata<Entity_Player*>(L, 1, lua::Metatables::ENTITY_PLAYER, "EntityPlayer");

const std::string layerName = luaL_checkstring(L, 2);

EntityPlayerPlus* playerPlus = GetEntityPlayerPlus(player);

if (playerPlus && playerPlus->customCacheResults.find(layerName) != playerPlus->customCacheResults.end()) {
lua_pushnumber(L, playerPlus->customCacheResults[layerName]);
}
lua_pushnumber(L, 0);

return 1;
}

HOOK_METHOD(LuaEngine, RegisterClasses, () -> void) {
super();

Expand Down Expand Up @@ -2579,6 +2629,8 @@ HOOK_METHOD(LuaEngine, RegisterClasses, () -> void) {
{ "SetBlackHeart", Lua_PlayerSetBlackHeart },
{ "AddNullCostume", Lua_PlayerAddNullCostumeOverride },
{ "GetBombVariant", Lua_PlayerGetBombVariant },
{ "AddCustomCacheTag", Lua_PlayerAddCustomCacheTag },
{ "GetCustomCacheValue", Lua_PlayerGetCustomCacheValue },
{ NULL, NULL }
};
lua::RegisterFunctions(_state, lua::Metatables::ENTITY_PLAYER, functions);
Expand Down
2 changes: 2 additions & 0 deletions repentogon/Patches/ASMPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "../LuaInterfaces/LuaRender.h"
#include "NullItemsAndCostumes.h"
#include "CustomCache.h"
#include "FamiliarTags.h"
#include "GetCoinValue.h"
#include "PocketItems.h"
Expand Down Expand Up @@ -149,6 +150,7 @@ void PerformASMPatches() {
ASMPatchesForGetCoinValue();
ASMPatchesForAddRemovePocketItemCallbacks();
ASMPatchesForEntityPlus();
ASMPatchesForCustomCache();
HookImGui();

// Sprite
Expand Down
Loading

0 comments on commit a8d7d6d

Please sign in to comment.