Skip to content

Commit

Permalink
Fixes bug with the current difficulty not being checked when enabling…
Browse files Browse the repository at this point in the history
… triggers.
  • Loading branch information
CCHyper committed Feb 24, 2023
1 parent 2005b31 commit d649039
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/extensions/extension_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
//#include "teamtypeext_hooks.h"
#include "terrainext_hooks.h"
#include "terraintypeext_hooks.h"
//#include "triggerext_hooks.h"
#include "triggerext_hooks.h"
#include "triggertypeext_hooks.h"
#include "unittypeext_hooks.h"
//#include "voxelanimext_hooks.h"
Expand Down Expand Up @@ -201,7 +201,7 @@ void Extension_Hooks()
//TeamTypeClassExtension_Hooks(); // Not yet implemented
TerrainClassExtension_Hooks();
TerrainTypeClassExtension_Hooks();
//TriggerTypeExtension_Hooks(); // Not yet implemented
TriggerClassExtension_Hooks();
TriggerTypeClassExtension_Hooks(); // Not yet implemented
UnitTypeClassExtension_Hooks();
//VoxelAnimClassExtension_Hooks(); // Not yet implemented
Expand Down
52 changes: 52 additions & 0 deletions src/extensions/taction/tactionext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
*
******************************************************************************/
#include "tactionext_hooks.h"
#include "tibsun_globals.h"
#include "trigger.h"
#include "triggertype.h"
#include "scenario.h"
#include "fatal.h"
#include "debughandler.h"
#include "asserthandler.h"
Expand All @@ -34,6 +38,52 @@
#include "hooker_macros.h"


/**
* #issue-299
*
* Fixes the issue with the current difficulty not being checked
* when enabling triggers.
*
* @see: TriggerClass and TriggerTypeClass for the other parts of this fix.
*
* @author: CCHyper
*/
DECLARE_PATCH(_TActionClass_Operator_Enable_Trigger_For_Difficulty_Patch)
{
GET_REGISTER_STATIC(int, trigger_index, edi);
static TriggerClass *trigger;

/**
* This is direct port of the code from Red Alert 2, which looks to fix this issue.
*/

/**
* We need to re-fetch the trigger from the vector as the
* register is reused by this point.
*/
trigger = Triggers[trigger_index];
if (trigger) {

/**
* Set this trigger to be disabled if it is marked as disabled
* for this current mission difficulty.
*/
if (Scen->Difficulty == DIFF_EASY && !trigger->Class->Easy
|| Scen->Difficulty == DIFF_NORMAL && !trigger->Class->Normal
|| Scen->Difficulty == DIFF_HARD && !trigger->Class->Hard) {

trigger->Disable();

} else {

trigger->Enable();
}
}

JMP(0x0061A611);
}


/**
* Main function for patching the hooks.
*/
Expand All @@ -51,4 +101,6 @@ void TActionClassExtension_Hooks()
* @author: CCHyper
*/
Patch_Dword(0x00619552+2, (0x007E4820+4)); // Foot vector to Technos vector.

Patch_Jump(0x0061A60C, &_TActionClass_Operator_Enable_Trigger_For_Difficulty_Patch);
}
87 changes: 87 additions & 0 deletions src/extensions/trigger/triggerext_hooks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*******************************************************************************
/* O P E N S O U R C E -- V I N I F E R A **
/*******************************************************************************
*
* @project Vinifera
*
* @file TRIGGEREXT_HOOKS.CPP
*
* @author CCHyper
*
* @brief Contains the hooks for the extended TriggerClass.
*
* @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 "sideext_hooks.h"
#include "tibsun_globals.h"
#include "trigger.h"
#include "triggertype.h"
#include "scenario.h"
#include "fatal.h"
#include "debughandler.h"
#include "asserthandler.h"

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


/**
* #issue-299
*
* Fixes the issue with the current difficulty not being checked
* when enabling triggers.
*
* @see: TriggerTypeClass and TActionClass for the other parts of this fix.
*
* @author: CCHyper
*/
DECLARE_PATCH(_TriggerClass_Constructor_Enabled_For_Difficulty_Patch)
{
GET_REGISTER_STATIC(TriggerClass *, this_ptr, esi);

/**
* This is direct port of the code from Red Alert 2, which looks to fix this issue.
*/

if (this_ptr->Class) {

this_ptr->Reset();

/**
* Set this trigger to be disabled if;
* - The class instance is marked as inactive.
* - It is marked as disabled for this current mission difficulty.
*/
if (!this_ptr->Class->Enabled
|| (Scen->Difficulty == DIFF_EASY && !this_ptr->Class->Easy)
|| (Scen->Difficulty == DIFF_NORMAL && !this_ptr->Class->Normal)
|| (Scen->Difficulty == DIFF_HARD && !this_ptr->Class->Hard)) {

this_ptr->IsEnabled = false;
}
}

JMP(0x00649188);
}


/**
* Main function for patching the hooks.
*/
void TriggerClassExtension_Hooks()
{
Patch_Jump(0x00649171, &_TriggerClass_Constructor_Enabled_For_Difficulty_Patch);
}
31 changes: 31 additions & 0 deletions src/extensions/trigger/triggerext_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 TRIGGEREXT_HOOKS.H
*
* @author CCHyper
*
* @brief Contains the hooks for the extended TriggerClass.
*
* @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 TriggerClassExtension_Hooks();

0 comments on commit d649039

Please sign in to comment.