Skip to content

Commit 5a6cb19

Browse files
committed
Fixes bug with the current difficulty not being checked when enabling triggers.
1 parent d258b4f commit 5a6cb19

File tree

4 files changed

+172
-2
lines changed

4 files changed

+172
-2
lines changed

src/extensions/extension_hooks.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
//#include "teamtypeext_hooks.h"
7171
#include "terrainext_hooks.h"
7272
#include "terraintypeext_hooks.h"
73-
//#include "triggerext_hooks.h"
73+
#include "triggerext_hooks.h"
7474
#include "triggertypeext_hooks.h"
7575
#include "unittypeext_hooks.h"
7676
//#include "voxelanimext_hooks.h"
@@ -201,7 +201,7 @@ void Extension_Hooks()
201201
//TeamTypeClassExtension_Hooks(); // Not yet implemented
202202
TerrainClassExtension_Hooks();
203203
TerrainTypeClassExtension_Hooks();
204-
//TriggerTypeExtension_Hooks(); // Not yet implemented
204+
TriggerClassExtension_Hooks();
205205
TriggerTypeClassExtension_Hooks();
206206
UnitTypeClassExtension_Hooks();
207207
//VoxelAnimClassExtension_Hooks(); // Not yet implemented

src/extensions/taction/tactionext_hooks.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
*
2727
******************************************************************************/
2828
#include "tactionext_hooks.h"
29+
#include "tibsun_globals.h"
30+
#include "trigger.h"
31+
#include "triggertype.h"
32+
#include "scenario.h"
2933
#include "fatal.h"
3034
#include "debughandler.h"
3135
#include "asserthandler.h"
@@ -34,6 +38,52 @@
3438
#include "hooker_macros.h"
3539

3640

41+
/**
42+
* #issue-299
43+
*
44+
* Fixes the issue with the current difficulty not being checked
45+
* when enabling triggers.
46+
*
47+
* @see: TriggerClass and TriggerTypeClass for the other parts of this fix.
48+
*
49+
* @author: CCHyper
50+
*/
51+
DECLARE_PATCH(_TActionClass_Operator_Enable_Trigger_For_Difficulty_Patch)
52+
{
53+
GET_REGISTER_STATIC(int, trigger_index, edi);
54+
static TriggerClass *trigger;
55+
56+
/**
57+
* This is direct port of the code from Red Alert 2, which looks to fix this issue.
58+
*/
59+
60+
/**
61+
* We need to re-fetch the trigger from the vector as the
62+
* register is reused by this point.
63+
*/
64+
trigger = Triggers[trigger_index];
65+
if (trigger) {
66+
67+
/**
68+
* Set this trigger to be disabled if it is marked as disabled
69+
* for this current mission difficulty.
70+
*/
71+
if (Scen->Difficulty == DIFF_EASY && !trigger->Class->Easy
72+
|| Scen->Difficulty == DIFF_NORMAL && !trigger->Class->Normal
73+
|| Scen->Difficulty == DIFF_HARD && !trigger->Class->Hard) {
74+
75+
trigger->Disable();
76+
77+
} else {
78+
79+
trigger->Enable();
80+
}
81+
}
82+
83+
JMP(0x0061A611);
84+
}
85+
86+
3787
/**
3888
* Main function for patching the hooks.
3989
*/
@@ -51,4 +101,6 @@ void TActionClassExtension_Hooks()
51101
* @author: CCHyper
52102
*/
53103
Patch_Dword(0x00619552+2, (0x007E4820+4)); // Foot vector to Technos vector.
104+
105+
Patch_Jump(0x0061A60C, &_TActionClass_Operator_Enable_Trigger_For_Difficulty_Patch);
54106
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*******************************************************************************
2+
/* O P E N S O U R C E -- V I N I F E R A **
3+
/*******************************************************************************
4+
*
5+
* @project Vinifera
6+
*
7+
* @file TRIGGEREXT_HOOKS.CPP
8+
*
9+
* @author CCHyper
10+
*
11+
* @brief Contains the hooks for the extended TriggerClass.
12+
*
13+
* @license Vinifera is free software: you can redistribute it and/or
14+
* modify it under the terms of the GNU General Public License
15+
* as published by the Free Software Foundation, either version
16+
* 3 of the License, or (at your option) any later version.
17+
*
18+
* Vinifera is distributed in the hope that it will be
19+
* useful, but WITHOUT ANY WARRANTY; without even the implied
20+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21+
* PURPOSE. See the GNU General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU General Public
24+
* License along with this program.
25+
* If not, see <http://www.gnu.org/licenses/>.
26+
*
27+
******************************************************************************/
28+
#include "sideext_hooks.h"
29+
#include "tibsun_globals.h"
30+
#include "trigger.h"
31+
#include "triggertype.h"
32+
#include "scenario.h"
33+
#include "fatal.h"
34+
#include "debughandler.h"
35+
#include "asserthandler.h"
36+
37+
#include "hooker.h"
38+
#include "hooker_macros.h"
39+
40+
41+
/**
42+
* #issue-299
43+
*
44+
* Fixes the issue with the current difficulty not being checked
45+
* when enabling triggers.
46+
*
47+
* @see: TriggerTypeClass and TActionClass for the other parts of this fix.
48+
*
49+
* @author: CCHyper
50+
*/
51+
DECLARE_PATCH(_TriggerClass_Constructor_Enabled_For_Difficulty_Patch)
52+
{
53+
GET_REGISTER_STATIC(TriggerClass *, this_ptr, esi);
54+
55+
/**
56+
* This is direct port of the code from Red Alert 2, which looks to fix this issue.
57+
*/
58+
59+
if (this_ptr->Class) {
60+
61+
this_ptr->Reset();
62+
63+
/**
64+
* Set this trigger to be disabled if;
65+
* - The class instance is marked as inactive.
66+
* - It is marked as disabled for this current mission difficulty.
67+
*/
68+
if (!this_ptr->Class->Enabled
69+
|| (Scen->Difficulty == DIFF_EASY && !this_ptr->Class->Easy)
70+
|| (Scen->Difficulty == DIFF_NORMAL && !this_ptr->Class->Normal)
71+
|| (Scen->Difficulty == DIFF_HARD && !this_ptr->Class->Hard)) {
72+
73+
this_ptr->IsEnabled = false;
74+
}
75+
}
76+
77+
JMP(0x00649188);
78+
}
79+
80+
81+
/**
82+
* Main function for patching the hooks.
83+
*/
84+
void TriggerClassExtension_Hooks()
85+
{
86+
Patch_Jump(0x00649171, &_TriggerClass_Constructor_Enabled_For_Difficulty_Patch);
87+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*******************************************************************************
2+
/* O P E N S O U R C E -- V I N I F E R A **
3+
/*******************************************************************************
4+
*
5+
* @project Vinifera
6+
*
7+
* @file TRIGGEREXT_HOOKS.H
8+
*
9+
* @author CCHyper
10+
*
11+
* @brief Contains the hooks for the extended TriggerClass.
12+
*
13+
* @license Vinifera is free software: you can redistribute it and/or
14+
* modify it under the terms of the GNU General Public License
15+
* as published by the Free Software Foundation, either version
16+
* 3 of the License, or (at your option) any later version.
17+
*
18+
* Vinifera is distributed in the hope that it will be
19+
* useful, but WITHOUT ANY WARRANTY; without even the implied
20+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21+
* PURPOSE. See the GNU General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU General Public
24+
* License along with this program.
25+
* If not, see <http://www.gnu.org/licenses/>.
26+
*
27+
******************************************************************************/
28+
#pragma once
29+
30+
31+
void TriggerClassExtension_Hooks();

0 commit comments

Comments
 (0)