Skip to content

Commit

Permalink
Implements StopSound for VoxelAnimTypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Oct 24, 2021
1 parent 97a2682 commit 95a07c3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/extensions/ext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#include "terrainext_hooks.h"
#include "superext_hooks.h"
#include "particlesysext_hooks.h"
#include "voxelanimext_hooks.h"

#include "combatext_hooks.h"

Expand Down Expand Up @@ -184,6 +185,7 @@ void Extension_Hooks()
TerrainClassExtension_Hooks();
SuperClassExtension_Hooks();
ParticleSystemClassExtension_Hooks();
VoxelAnimClassExtension_Hooks();

CombatExtension_Hooks();

Expand Down
90 changes: 90 additions & 0 deletions src/extensions/voxelanim/voxelanimext_hooks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*******************************************************************************
/* O P E N S O U R C E -- V I N I F E R A **
/*******************************************************************************
*
* @project Vinifera
*
* @file VOXELANIMEXT_HOOKS.CPP
*
* @author CCHyper
*
* @brief Contains the hooks for the extended VoxelAnimClass.
*
* @license Vinifera is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* Vinifera is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#include "voxelanimext_hooks.h"
#include "voxelanim.h"
#include "voxelanimtype.h"
#include "voxelanimtypeext.h"
#include "voc.h"
#include "fatal.h"
#include "debughandler.h"
#include "asserthandler.h"

#include "hooker.h"
#include "hooker_macros.h"


/**
* A fake class for implementing new member functions which allow
* access to the "this" pointer of the intended class.
*
* @note: This must not contain a constructor or deconstructor!
* @note: All functions must be prefixed with "_" to prevent accidental virtualization.
*/
class VoxelAnimClassFake final : public VoxelAnimClass
{
public:
void _entry_E4();
};


/**
* Implementation of entry_E4() for VoxelAnimClass.
*/
void VoxelAnimClassFake::_entry_E4()
{
VoxelAnimTypeClassExtension *voxelanimtypeext = nullptr;

/**
* #issue-474
*
* Implements StopSound for VoxelAnimTypes.
*
* @author: CCHyper
*/
voxelanimtypeext = VoxelAnimTypeClassExtensions.find(Class);
if (voxelanimtypeext) {

/**
* Play the StopSound if one has been defined.
*/
if (voxelanimtypeext->StopSound != VOC_NONE) {
Sound_Effect(voxelanimtypeext->StopSound, Center_Coord());
}
}

ObjectClass::entry_E4();
}


/**
* Main function for patching the hooks.
*/
void VoxelAnimClassExtension_Hooks()
{
Change_Virtual_Address(0x006D9134, Get_Func_Address(&VoxelAnimClassFake::_entry_E4));
}
31 changes: 31 additions & 0 deletions src/extensions/voxelanim/voxelanimext_hooks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
/* O P E N S O U R C E -- V I N I F E R A **
/*******************************************************************************
*
* @project Vinifera
*
* @file VOXELANIMEXT_HOOKS.H
*
* @author CCHyper
*
* @brief Contains the hooks for the extended VoxelAnimClass.
*
* @license Vinifera is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* Vinifera is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#pragma once


void VoxelAnimClassExtension_Hooks();
29 changes: 17 additions & 12 deletions src/extensions/voxelanimtype/voxelanimtypeext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ ExtensionMap<VoxelAnimTypeClass, VoxelAnimTypeClassExtension> VoxelAnimTypeClass
* @author: CCHyper
*/
VoxelAnimTypeClassExtension::VoxelAnimTypeClassExtension(VoxelAnimTypeClass *this_ptr) :
Extension(this_ptr)
Extension(this_ptr),
StopSound(VOC_NONE)
{
ASSERT(ThisPtr != nullptr);
//EXT_DEBUG_TRACE("VoxelAnimTypeClassExtension constructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//EXT_DEBUG_WARNING("VoxelAnimTypeClassExtension constructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_TRACE("VoxelAnimTypeClassExtension constructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_WARNING("VoxelAnimTypeClassExtension constructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));

IsInitialized = true;
}
Expand All @@ -73,8 +74,8 @@ VoxelAnimTypeClassExtension::VoxelAnimTypeClassExtension(const NoInitClass &noin
*/
VoxelAnimTypeClassExtension::~VoxelAnimTypeClassExtension()
{
//EXT_DEBUG_TRACE("VoxelAnimTypeClassExtension deconstructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//EXT_DEBUG_WARNING("VoxelAnimTypeClassExtension deconstructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_TRACE("VoxelAnimTypeClassExtension deconstructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_WARNING("VoxelAnimTypeClassExtension deconstructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));

IsInitialized = false;
}
Expand All @@ -88,7 +89,7 @@ VoxelAnimTypeClassExtension::~VoxelAnimTypeClassExtension()
HRESULT VoxelAnimTypeClassExtension::Load(IStream *pStm)
{
ASSERT(ThisPtr != nullptr);
//EXT_DEBUG_TRACE("VoxelAnimTypeClassExtension::Size_Of - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_TRACE("VoxelAnimTypeClassExtension::Size_Of - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));

HRESULT hr = Extension::Load(pStm);
if (FAILED(hr)) {
Expand All @@ -109,7 +110,7 @@ HRESULT VoxelAnimTypeClassExtension::Load(IStream *pStm)
HRESULT VoxelAnimTypeClassExtension::Save(IStream *pStm, BOOL fClearDirty)
{
ASSERT(ThisPtr != nullptr);
//EXT_DEBUG_TRACE("VoxelAnimTypeClassExtension::Size_Of - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_TRACE("VoxelAnimTypeClassExtension::Size_Of - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));

HRESULT hr = Extension::Save(pStm, fClearDirty);
if (FAILED(hr)) {
Expand All @@ -128,7 +129,7 @@ HRESULT VoxelAnimTypeClassExtension::Save(IStream *pStm, BOOL fClearDirty)
int VoxelAnimTypeClassExtension::Size_Of() const
{
ASSERT(ThisPtr != nullptr);
//EXT_DEBUG_TRACE("VoxelAnimTypeClassExtension::Size_Of - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_TRACE("VoxelAnimTypeClassExtension::Size_Of - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));

return sizeof(*this);
}
Expand All @@ -142,7 +143,7 @@ int VoxelAnimTypeClassExtension::Size_Of() const
void VoxelAnimTypeClassExtension::Detach(TARGET target, bool all)
{
ASSERT(ThisPtr != nullptr);
//EXT_DEBUG_TRACE("VoxelAnimTypeClassExtension::Detach - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_TRACE("VoxelAnimTypeClassExtension::Detach - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
}


Expand All @@ -154,7 +155,9 @@ void VoxelAnimTypeClassExtension::Detach(TARGET target, bool all)
void VoxelAnimTypeClassExtension::Compute_CRC(WWCRCEngine &crc) const
{
ASSERT(ThisPtr != nullptr);
//EXT_DEBUG_TRACE("VoxelAnimTypeClassExtension::Compute_CRC - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_TRACE("VoxelAnimTypeClassExtension::Compute_CRC - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));

crc(StopSound);
}


Expand All @@ -166,14 +169,16 @@ void VoxelAnimTypeClassExtension::Compute_CRC(WWCRCEngine &crc) const
bool VoxelAnimTypeClassExtension::Read_INI(CCINIClass &ini)
{
ASSERT(ThisPtr != nullptr);
//EXT_DEBUG_TRACE("VoxelAnimTypeClassExtension::Read_INI - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
EXT_DEBUG_WARNING("VoxelAnimTypeClassExtension::Read_INI - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
//DEV_DEBUG_TRACE("VoxelAnimTypeClassExtension::Read_INI - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
DEV_DEBUG_WARNING("VoxelAnimTypeClassExtension::Read_INI - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));

const char *ini_name = ThisPtr->Name();

if (!ini.Is_Present(ini_name)) {
return false;
}

StopSound = ini.Get_VocType(ini_name, "StopSound", StopSound);

return true;
}
5 changes: 4 additions & 1 deletion src/extensions/voxelanimtype/voxelanimtypeext.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class VoxelAnimTypeClassExtension final : public Extension<VoxelAnimTypeClass>
bool Read_INI(CCINIClass &ini);

public:

/**
* The sound effect to play when this voxel anim has finished.
*/
VocType StopSound;
};


Expand Down

0 comments on commit 95a07c3

Please sign in to comment.