Skip to content

Commit

Permalink
my pocket friends
Browse files Browse the repository at this point in the history
Additions:
* EntityPlayer:
	- [Get/Set]ActionHoldDrop - how long player holds action drop button.
	- [Get/Set]ForgottenSwapFormCooldown
* ModCallbacks:
	- MC_PRE_PLAYER_POCKET_ITEM_SWAP(Player)
		Return true to cancel pocket item swap.

Modified:
* EntityPlayer:
	- SwapForgottenForm returns boolean, depending if Forgotten/Soul form was switched or not.
  • Loading branch information
epfly6 committed Oct 2, 2024
1 parent 9a6d532 commit 555bce0
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 5 deletions.
14 changes: 14 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
v1.0.x -
Additions:
* EntityPlayer:
- [Get/Set]ActionHoldDrop - how long player holds action drop button.
- [Get/Set]ForgottenSwapFormCooldown
* ModCallbacks:
- MC_PRE_PLAYER_POCKET_ITEM_SWAP(Player)
Return true to cancel pocket item swap.
/newline/
Modified:
* EntityPlayer:
- SwapForgottenForm returns boolean, depending if Forgotten/Soul form was switched or not.
/newline/
/versionseparator/
v1.0.12.a -
* The changelogs menu has been revamped. Use the left and right arrow keys to look between versions.
Additions:
Expand Down
1 change: 1 addition & 0 deletions libzhl/functions/DailyChallenge.zhl
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ struct DailyChallenge depends (ChallengeParam) {
unsigned int _id : 0x0; // 0x0
unsigned int _seed : 0x4; // 0x4
bool _isPractice : 0x8; // 0x8
unsigned int _specialDailyId : 0xc;
ChallengeParam _params : 0x10;
} : 0xb4;
4 changes: 3 additions & 1 deletion libzhl/functions/EntityPlayer.zhl
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ __thiscall void Entity_Player::AddNullCostume(int costumeid);
__thiscall void Entity_Player::ClearDeadEyeCharge();

"558bec83e4c081ecb4000000a1????????33c4898424????????5356578bf9897c24":
__thiscall void Entity_Player::SwapForgottenForm(bool unk1, bool unk2);
__thiscall bool Entity_Player::SwapForgottenForm(bool unk1, bool unk2);

"558bec83e4f081ec480100008b55":
__thiscall TearParams* Entity_Player::GetTearHitParams(TearParams * res, int WeaponType, float DamageScale, int TearDisplacement, Entity* Source);
Expand Down Expand Up @@ -685,12 +685,14 @@ struct Entity_Player depends (ANM2, ColorMod, KColor, PlayerCostumeMap, Temporar
int8_t _tearDisplacement : 0x14bc;
ActiveItemDesc _activeDesc[4] : 0x14c4;
int _bombPlaceDelay : 0x1544;
int _forgottenSwapFormCooldown : 0x1548;
int _controllerIndex : 0x154c;
int _playerIndex : 0x1550;
int _moveDirection : 0x1558;
int _headDirection: 0x155c;
uint32_t _trinketsID[2] : 0x15e8;
vector_SmeltedTrinketDesc _smeltedTrinkets : 0x1670;
uint32_t _actionHoldDrop : 0x16e8;
int _playerForms[15] : 0x1700;
KColor _footprintColor1 : 0x1768;
KColor _footprintColor2 : 0x1794;
Expand Down
36 changes: 34 additions & 2 deletions repentogon/LuaInterfaces/Entities/LuaEntityPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,8 +1352,8 @@ LUA_FUNCTION(Lua_SwapForgottenForm) {
Entity_Player* player = lua::GetUserdata<Entity_Player*>(L, 1, lua::Metatables::ENTITY_PLAYER, "EntityPlayer");
bool IgnoreHealth = lua::luaL_optboolean(L, 2, false);
bool NoEffects = lua::luaL_optboolean(L, 3, false);
player->SwapForgottenForm(IgnoreHealth, NoEffects);
return 0;
lua_pushboolean(L, player->SwapForgottenForm(IgnoreHealth, NoEffects));
return 1;
}

LUA_FUNCTION(Lua_SpawnAquariusCreep) {
Expand Down Expand Up @@ -2547,6 +2547,34 @@ LUA_FUNCTION(Lua_PlayerGetTearDisplacement) {
return 1;
}

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

return 1;
}

LUA_FUNCTION(Lua_PlayerSetActionHoldDrop) {
Entity_Player* player = lua::GetUserdata<Entity_Player*>(L, 1, lua::Metatables::ENTITY_PLAYER, "EntityPlayer");
player->_actionHoldDrop = (unsigned int)luaL_checkinteger(L, 2);

return 0;
}

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

return 1;
}

LUA_FUNCTION(Lua_PlayerSetForgottenSwapFormCooldown) {
Entity_Player* player = lua::GetUserdata<Entity_Player*>(L, 1, lua::Metatables::ENTITY_PLAYER, "EntityPlayer");
player->_forgottenSwapFormCooldown = (int)luaL_checkinteger(L, 2);

return 0;
}

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

Expand Down Expand Up @@ -2777,6 +2805,10 @@ HOOK_METHOD(LuaEngine, RegisterClasses, () -> void) {
{ "GetMaxKeys", Lua_PlayerGetMaxKeys },
{ "GetMaxBombs", Lua_PlayerGetMaxBombs },
{ "GetTearDisplacement", Lua_PlayerGetTearDisplacement },
{ "GetActionHoldDrop", Lua_PlayerGetActionHoldDrop },
{ "SetActionHoldDrop", Lua_PlayerSetActionHoldDrop },
{ "GetForgottenSwapFormCooldown", Lua_PlayerGetForgottenSwapFormCooldown },
{ "SetForgottenSwapFormCooldown", Lua_PlayerSetForgottenSwapFormCooldown },
{ NULL, NULL }
};
lua::RegisterFunctions(_state, lua::Metatables::ENTITY_PLAYER, functions);
Expand Down
1 change: 1 addition & 0 deletions repentogon/Patches/ASMPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void PerformASMPatches() {
ASMPatchProjectileDeath();
ASMPatchTearDeath();
ASMPatchPrePlayerGiveBirth();
ASMPatchPrePlayerPocketItemSwap();

// Delirium
delirium::AddTransformationCallback();
Expand Down
45 changes: 45 additions & 0 deletions repentogon/Patches/ASMPatches/ASMCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,3 +1087,48 @@ void ASMPatchPrePlayerGiveBirth() {
printf("[REPENTOGON] Patching Entity_Player::TriggerHeartPickedUp at %p for MC_PRE_PLAYER_GIVE_BIRTH_IMMACULATE\n", immaculateAddr);
PreBirthPatch(immaculateAddr, false); // Immaculate
}

//MC_PRE_PLAYER_POCKET_ITEM_SWAP(1287)
bool __stdcall RunPrePlayerPocketItemSwapCallback(Entity_Player* player) {
const int callbackid = 1287;

if (CallbackState.test(callbackid - 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(callbackid)
.pushnil()
.push(player, lua::Metatables::ENTITY_PLAYER)
.call(1);


if (!result) {
if (lua_isboolean(L, -1)) {
return (bool)lua_toboolean(L, -1);
}
}
}

return false;
}

void ASMPatchPrePlayerPocketItemSwap() {
ASMPatch::SavedRegisters savedRegisters(ASMPatch::SavedRegisters::Registers::GP_REGISTERS, true);
ASMPatch patch;

SigScan scanner_transition("8dbb????????833f00");
scanner_transition.Scan();
void* addr = scanner_transition.GetAddress();
printf("[REPENTOGON] Patching Entity_Player::control_drop_pocket_items at %p\n", addr);

patch.PreserveRegisters(savedRegisters)
.Push(ASMPatch::Registers::EBX) // Player
.AddInternalCall(RunPrePlayerPocketItemSwapCallback)
.AddBytes("\x84\xC0") // test al, al
.RestoreRegisters(savedRegisters)
.AddConditionalRelativeJump(ASMPatcher::CondJumps::JNE, (char*)addr + 0xB3) // Skipping pocket item swap
.AddBytes(ByteBuffer().AddAny((char*)addr, 6)) // Restore the commands we overwrote
.AddRelativeJump((char*)addr + 6);
sASMPatcher.PatchAt(addr, &patch);
}
1 change: 1 addition & 0 deletions repentogon/Patches/ASMPatches/ASMCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ void ASMPatchPickupUpdatePickupGhosts();
void ASMPatchProjectileDeath();
void ASMPatchTearDeath();
void ASMPatchPrePlayerGiveBirth();
void ASMPatchPrePlayerPocketItemSwap();
4 changes: 2 additions & 2 deletions repentogon/Patches/VanillaTweaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ HOOK_METHOD(OptionsConfig, Save, () -> void) {
}
*/

HOOK_METHOD(Console, SubmitInput, (bool unk) -> void) {
HOOK_METHOD(Console, RunCommand, (std_string& in, std_string* out, Entity_Player* player) -> void) {
Game* game = g_Game;
if (game->GetDailyChallenge()._id != 0 && !game->GetDailyChallenge()._isPractice) {
return;
}
super(unk);
super(in, out, player);
}

// Instruct the stat HUD to recalculate planetarium chance after every new level. Avoids running planetarium chance calculation and associated callbacks every frame
Expand Down
2 changes: 2 additions & 0 deletions repentogon/resources/scripts/enums_ex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ ModCallbacks.MC_PRE_PLAYER_REMOVE_COSTUME = 1282
ModCallbacks.MC_POST_PLAYER_ADD_COSTUME = 1283
ModCallbacks.MC_POST_PLAYER_REMOVE_COSTUME = 1284

ModCallbacks.MC_PRE_PLAYER_POCKET_ITEMS_SWAP = 1287

ModCallbacks.MC_PRE_GET_RANDOM_ROOM_INDEX = 1290

ModCallbacks.MC_POST_GLOWING_HOURGLASS_SAVE = 1300
Expand Down

0 comments on commit 555bce0

Please sign in to comment.