Skip to content

Commit

Permalink
Implements initial WaveClass extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Sep 4, 2021
1 parent bf366b0 commit 5614754
Show file tree
Hide file tree
Showing 8 changed files with 640 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/extensions/ext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
#include "combatext_hooks.h"

#include "empulseext_hooks.h"
#include "waveext_hooks.h"

#include "dropshipext_hooks.h"

Expand Down Expand Up @@ -173,6 +174,7 @@ void Extension_Hooks()
CombatExtension_Hooks();

EMPulseClassExtension_Hooks();
WaveClassExtension_Hooks();

DropshipExtension_Hooks();

Expand Down
19 changes: 19 additions & 0 deletions src/extensions/saveload/saveload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
#include "buildingext.h"
#include "terrainext.h"

#include "waveext.h"


/**
* Constant of the current build version number. This number should be
Expand Down Expand Up @@ -115,6 +117,7 @@ unsigned ViniferaSaveGameVersion =
+ sizeof(TechnoClassExtension)
+ sizeof(BuildingClassExtension)
+ sizeof(TerrainClassExtension)
+ sizeof(WaveClassExtension)
;


Expand Down Expand Up @@ -314,6 +317,8 @@ DEFINE_EXTENSION_SAVE(TechnoClassExtension, TechnoClassExtensions);
DEFINE_EXTENSION_SAVE(BuildingClassExtension, BuildingClassExtensions);
DEFINE_EXTENSION_SAVE(TerrainClassExtension, TerrainClassExtensions);

DEFINE_EXTENSION_SAVE(WaveClassExtension, WaveClassExtensions);

DEFINE_EXTENSION_LOAD(ObjectTypeClassExtension, ObjectTypeClassExtensions);
DEFINE_EXTENSION_LOAD(TechnoTypeClassExtension, TechnoTypeClassExtensions);
DEFINE_EXTENSION_LOAD(BuildingTypeClassExtension, BuildingTypeClassExtensions);
Expand Down Expand Up @@ -346,6 +351,8 @@ DEFINE_EXTENSION_LOAD(TechnoClassExtension, TechnoClassExtensions);
DEFINE_EXTENSION_LOAD(BuildingClassExtension, BuildingClassExtensions);
DEFINE_EXTENSION_LOAD(TerrainClassExtension, TerrainClassExtensions);

DEFINE_EXTENSION_LOAD(WaveClassExtension, WaveClassExtensions);


/**
* Save all Vinifera data to the file stream.
Expand Down Expand Up @@ -564,6 +571,12 @@ bool Vinifera_Put_All(IStream *pStm)
return false;
}

DEBUG_INFO("Saving WaveClassExtension\n");
if (!Vinifera_Save_WaveClassExtension(pStm)) {
DEBUG_INFO("\t***** FAILED!\n");
return false;
}

/**
* Save global data and values here.
*/
Expand Down Expand Up @@ -812,6 +825,12 @@ bool Vinifera_Load_All(IStream *pStm)
return false;
}

DEBUG_INFO("Loading WaveClassExtension\n");
if (!Vinifera_Load_WaveClassExtension(pStm)) {
DEBUG_INFO("\t***** FAILED!\n");
return false;
}

/**
* Load global data and values here.
*/
Expand Down
158 changes: 158 additions & 0 deletions src/extensions/wave/waveext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*******************************************************************************
/* O P E N S O U R C E -- V I N I F E R A **
/*******************************************************************************
*
* @project Vinifera
*
* @file WAVEEXT.CPP
*
* @author CCHyper
*
* @brief Extended WaveClass class.
*
* @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 "waveext.h"
#include "wave.h"
#include "wwcrc.h"
#include "asserthandler.h"
#include "debughandler.h"


/**
* Provides the map for all WaveClass extension instances.
*/
ExtensionMap<WaveClass, WaveClassExtension> WaveClassExtensions;


/**
* Class constructor.
*
* @author: CCHyper
*/
WaveClassExtension::WaveClassExtension(WaveClass *this_ptr) :
Extension(this_ptr)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("WaveClassExtension constructor - 0x%08X\n", (uintptr_t)(ThisPtr));
//DEV_DEBUG_WARNING("WaveClassExtension constructor - 0x%08X\n", (uintptr_t)(ThisPtr));

IsInitialized = true;
}


/**
* Class no-init constructor.
*
* @author: CCHyper
*/
WaveClassExtension::WaveClassExtension(const NoInitClass &noinit) :
Extension(noinit)
{
IsInitialized = false;
}


/**
* Class deconstructor.
*
* @author: CCHyper
*/
WaveClassExtension::~WaveClassExtension()
{
//DEV_DEBUG_TRACE("WaveClassExtension deconstructor - 0x%08X\n", (uintptr_t)(ThisPtr));
//DEV_DEBUG_WARNING("WaveClassExtension deconstructor - 0x%08X\n", (uintptr_t)(ThisPtr));

IsInitialized = false;
}


/**
* Initializes an object from the stream where it was saved previously.
*
* @author: CCHyper
*/
HRESULT WaveClassExtension::Load(IStream *pStm)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("WaveClassExtension::Load - 0x%08X\n", (uintptr_t)(ThisPtr));

HRESULT hr = Extension::Load(pStm);
if (FAILED(hr)) {
return E_FAIL;
}

new (this) WaveClassExtension(NoInitClass());

return hr;
}


/**
* Saves an object to the specified stream.
*
* @author: CCHyper
*/
HRESULT WaveClassExtension::Save(IStream *pStm, BOOL fClearDirty)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("WaveClassExtension::Save - 0x%08X\n", (uintptr_t)(ThisPtr));

HRESULT hr = Extension::Save(pStm, fClearDirty);
if (FAILED(hr)) {
return hr;
}

return hr;
}


/**
* Return the raw size of class data for save/load purposes.
*
* @author: CCHyper
*/
int WaveClassExtension::Size_Of() const
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("WaveClassExtension::Size_Of - 0x%08X\n", (uintptr_t)(ThisPtr));

return sizeof(*this);
}


/**
* Removes the specified target from any targeting and reference trackers.
*
* @author: CCHyper
*/
void WaveClassExtension::Detach(TARGET target, bool all)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("WaveClassExtension::Detach - 0x%08X\n", (uintptr_t)(ThisPtr));
}


/**
* Compute a unique crc value for this instance.
*
* @author: CCHyper
*/
void WaveClassExtension::Compute_CRC(WWCRCEngine &crc) const
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("WaveClassExtension::Compute_CRC - 0x%08X\n", (uintptr_t)(ThisPtr));
}
53 changes: 53 additions & 0 deletions src/extensions/wave/waveext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
/* O P E N S O U R C E -- V I N I F E R A **
/*******************************************************************************
*
* @project Vinifera
*
* @file WAVEEXT.H
*
* @author CCHyper
*
* @brief Extended WaveClass class.
*
* @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

#include "extension.h"
#include "container.h"
#include "wave.h"


class WaveClassExtension final : public Extension<WaveClass>
{
public:
WaveClassExtension(WaveClass *this_ptr);
WaveClassExtension(const NoInitClass &noinit);
~WaveClassExtension();

virtual HRESULT Load(IStream *pStm) override;
virtual HRESULT Save(IStream *pStm, BOOL fClearDirty) override;
virtual int Size_Of() const override;

virtual void Detach(TARGET target, bool all = true) override;
virtual void Compute_CRC(WWCRCEngine &crc) const override;

public:
};


extern ExtensionMap<WaveClass, WaveClassExtension> WaveClassExtensions;
48 changes: 48 additions & 0 deletions src/extensions/wave/waveext_hooks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
/* O P E N S O U R C E -- V I N I F E R A **
/*******************************************************************************
*
* @project Vinifera
*
* @file WAVEEXT_HOOKS.CPP
*
* @author CCHyper
*
* @brief Contains the hooks for the extended WaveClass.
*
* @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 "waveext_hooks.h"
#include "waveext_init.h"
#include "wave.h"
#include "fatal.h"
#include "asserthandler.h"
#include "debughandler.h"

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


/**
* Main function for patching the hooks.
*/
void WaveClassExtension_Hooks()
{
/**
* Initialises the extended class.
*/
WaveClassExtension_Init();
}
31 changes: 31 additions & 0 deletions src/extensions/wave/waveext_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 WAVEEXT_HOOKS.H
*
* @author CCHyper
*
* @brief Contains the hooks for the extended WaveClass.
*
* @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 WaveClassExtension_Hooks();
Loading

0 comments on commit 5614754

Please sign in to comment.