Skip to content

Commit

Permalink
Fixed Pre(Un)Morph being called out of order.
Browse files Browse the repository at this point in the history
- This had broken several mods that relied on the inventory being in place before the switch, which was the intended way to begin with.
  • Loading branch information
MajorCooke authored and madame-rachelle committed Jun 24, 2024
1 parent 5fc3d44 commit 3e91d38
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
36 changes: 36 additions & 0 deletions src/playsim/p_mobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5345,6 +5345,42 @@ int MorphPointerSubstitution(AActor* from, AActor* to)
return false;
}

// [MC] Had to move this here since ObtainInventory was also moved as well. Should be called
// before any transference of items since that's what was intended when introduced.
if (!from->alternative) // Morphing into
{
{
IFVIRTUALPTR(from, AActor, PreMorph)
{
VMValue params[] = { from, to, false };
VMCall(func, params, 3, nullptr, 0);
}
}
{
IFVIRTUALPTR(to, AActor, PreMorph)
{
VMValue params[] = { to, from, true };
VMCall(func, params, 3, nullptr, 0);
}
}
}
else // Unmorphing back
{
{
IFVIRTUALPTR(from, AActor, PreUnmorph)
{
VMValue params[] = { from, to, false };
VMCall(func, params, 3, nullptr, 0);
}
}
{
IFVIRTUALPTR(to, AActor, PreUnmorph)
{
VMValue params[] = { to, from, true };
VMCall(func, params, 3, nullptr, 0);
}
}
}
// Since the check is good, move the inventory items over. This should always be done when
// morphing to emulate Heretic/Hexen's behavior since those stored the inventory in their
// player structs.
Expand Down
1 change: 1 addition & 0 deletions wadsrc/static/zscript/actors/morph.zs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extend class Actor
}

// [MC] Called when an actor morphs, on both the previous form (!current) and present form (current).
// Due to recent changes, these are now called internally instead of within the virtuals.
virtual void PreMorph(Actor mo, bool current) {}
virtual void PostMorph(Actor mo, bool current) {}
virtual void PreUnmorph(Actor mo, bool current) {}
Expand Down
6 changes: 0 additions & 6 deletions wadsrc/static/zscript/actors/player/player_morph.zs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ extend class PlayerPawn
return false;
}

PreMorph(morphed, false);
morphed.PreMorph(self, true);

morphed.EndAllPowerupEffects();

if ((style & MRF_TRANSFERTRANSLATION) && !morphed.bDontTranslate)
Expand Down Expand Up @@ -259,9 +256,6 @@ extend class PlayerPawn
if (!MorphInto(alt))
return false;

PreUnmorph(alt, false); // This body's about to be left.
alt.PreUnmorph(self, true); // This one's about to become current.

alt.EndAllPowerupEffects();

// Remove the morph power if the morph is being undone prematurely.
Expand Down

0 comments on commit 3e91d38

Please sign in to comment.