Skip to content

Commit

Permalink
Implement 'nowaterphysics' NPC config
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluenaxela committed Apr 26, 2017
1 parent 940fc68 commit 29e1adc
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
1 change: 1 addition & 0 deletions LuaScriptsLib/core/npcconfig_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ local propertyTables = {
-- Extended properties
vulnerableharmtypes = {name="vulnerableharmtypes", t=FIELD_DWORD, encoder=encodeHarmMask, decoder=decodeHarmMask},
spinjumpsafe = {name="spinjumpsafe", t=FIELD_BOOL},
nowaterphysics = {name="nowaterphysics", t=FIELD_BOOL},
}

-- Deprecated aliases
Expand Down
1 change: 1 addition & 0 deletions LunaDll/Misc/RuntimeHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ void __stdcall runtimeHookSmbxCheckWindowedRaw(void);
void __stdcall runtimeHookBlockBumpableRaw(void);
void __stdcall runtimeHookNPCVulnerabilityRaw(void);
void __stdcall runtimeHookNPCSpinjumpSafeRaw(void);
void __stdcall runtimeHookNPCNoWaterPhysicsRaw(void);
void __stdcall runtimeHookCheckInputRaw(void);
void __stdcall runtimeHookSetHDCRaw(void);

Expand Down
1 change: 1 addition & 0 deletions LunaDll/Misc/RuntimeHookComponents/RuntimeHookGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ void TrySkipPatch()
PATCH(0xA28FE3).JMP(runtimeHookNPCVulnerabilityRaw).Apply();

PATCH(0x9A9D33).JMP(runtimeHookNPCSpinjumpSafeRaw).NOP_PAD_TO_SIZE<10>().Apply();
PATCH(0xA0A991).JMP(runtimeHookNPCNoWaterPhysicsRaw).NOP_PAD_TO_SIZE<6>().Apply();

PATCH(0xA75079).JMP(runtimeHookCheckInputRaw).NOP_PAD_TO_SIZE<7>().Apply();

Expand Down
41 changes: 41 additions & 0 deletions LunaDll/Misc/RuntimeHookComponents/RuntimeHookHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,47 @@ __declspec(naked) void __stdcall runtimeHookNPCSpinjumpSafeRaw(void)
}
}

static int __stdcall runtimeHookNPCNoWaterPhysics(NPCMOB* npc)
{
if (NPC::GetNoWaterPhysics(npc->id))
{
return -1;
}

return 0;
}

__declspec(naked) void __stdcall runtimeHookNPCNoWaterPhysicsRaw(void)
{
// 00A0A991 | 0F 8E 89 01 00 00 | jle foo3.A0AB20 |
// 00A0A997
__asm {
jle early_exit
pushf
push eax
push ecx
push edx
push esi // Args #1
call runtimeHookNPCNoWaterPhysics
cmp eax, 0
jne alternate_exit
pop edx
pop ecx
pop eax
popf
push 0xA0A997
ret
alternate_exit :
pop edx
pop ecx
pop eax
popf
early_exit :
push 0xA0AB20
ret
}
}

static void __stdcall runtimeHookCheckInput(int playerIdx, KeyMap* keymap)
{
if (playerIdx >= 0 && playerIdx <= 1)
Expand Down
19 changes: 15 additions & 4 deletions LunaDll/SMBXInternal/NPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,17 @@ void NPC::AllFace(int identity, int section, double x) {
}

// Declerations of inbuilt NPC property arrays
static uint32_t npcprop_vulnerableharmtypes[NPC::MAX_ID + 1] = { 0 };
static int16_t npcprop_spinjumpsafe[NPC::MAX_ID+1] = { 0 };
static uint32_t npcprop_vulnerableharmtypes[NPC::MAX_ID+1] = { 0 };
static int16_t npcprop_nowaterphysics[NPC::MAX_ID + 1] = { 0 };

// Initialization of inbuilt NPC property arrays
void NPC::InitProperties() {
for (int i = 1; i <= NPC::MAX_ID; i++)
{
npcprop_vulnerableharmtypes[i] = 0;
npcprop_spinjumpsafe[i] = 0;
npcprop_nowaterphysics[i] = 0;
}

// Set built-in spinjump safe IDs
Expand Down Expand Up @@ -178,16 +180,25 @@ bool NPC::GetSpinjumpSafe(int id) {
return (npcprop_spinjumpsafe[id] != 0);
}

bool NPC::GetNoWaterPhysics(int id) {
if ((id < 1) || (id > NPC::MAX_ID)) return false;
return (npcprop_nowaterphysics[id] != 0);
}

// Getter for address of NPC property arrays
uintptr_t NPC::GetPropertyTableAddress(const std::string& s)
{
if (s == "spinjumpsafe")
if (s == "vulnerableharmtypes")
{
return reinterpret_cast<uintptr_t>(npcprop_vulnerableharmtypes);
}
else if (s == "spinjumpsafe")
{
return reinterpret_cast<uintptr_t>(npcprop_spinjumpsafe);
}
else if (s == "vulnerableharmtypes")
else if (s == "nowaterphysics")
{
return reinterpret_cast<uintptr_t>(npcprop_vulnerableharmtypes);
return reinterpret_cast<uintptr_t>(npcprop_nowaterphysics);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions LunaDll/SMBXInternal/NPCs.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ namespace NPC {
void InitProperties();
uint32_t GetVulnerableHarmTypes(int id);
bool GetSpinjumpSafe(int id);
bool GetNoWaterPhysics(int id);

uintptr_t GetPropertyTableAddress(const std::string& s);

Expand Down

0 comments on commit 29e1adc

Please sign in to comment.