Skip to content

Commit 99a28ab

Browse files
committed
Clean up TActionClass/TEventClass
1 parent afd93c9 commit 99a28ab

2 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/extensions/taction/tactionext_hooks.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
DECLARE_EXTENDING_CLASS_AND_PAIR(TActionClass)
5656
{
5757
public:
58-
bool _Play_Sound_At_Random_Waypoint(HouseClass *house, ObjectClass *object, TriggerClass *trigger, Cell &cell);
58+
bool _Do_PLAY_SOUND_RANDOM(HouseClass *house, ObjectClass *object, TriggerClass *trigger, const Cell &cell);
5959
};
6060

6161

@@ -66,42 +66,37 @@ DECLARE_EXTENDING_CLASS_AND_PAIR(TActionClass)
6666
*
6767
* @author: CCHyper
6868
*/
69-
bool TActionClassExt::_Play_Sound_At_Random_Waypoint(HouseClass *house, ObjectClass *object, TriggerClass *trigger, Cell &cell)
69+
bool TActionClassExt::_Do_PLAY_SOUND_RANDOM(HouseClass *house, ObjectClass *object, TriggerClass *trigger, const Cell &cell)
7070
{
71-
Cell cell_list[NEW_WAYPOINT_COUNT];
72-
int cell_list_count = 0;
71+
Cell list[NEW_WAYPOINT_COUNT];
72+
int count = 0;
7373

7474
/**
7575
* Make a list of all the valid waypoints in this scenario.
7676
*/
77-
for (WaypointType wp = WAYPOINT_FIRST; wp < NEW_WAYPOINT_COUNT; ++wp) {
78-
if (ScenExtension->Is_Valid_Waypoint(wp)) {
79-
cell_list[cell_list_count++] = ScenExtension->Get_Waypoint_Cell(wp);
80-
if (cell_list_count >= std::size(cell_list)) {
81-
break;
82-
}
77+
for (WaypointType index = WAYPOINT_FIRST; index < NEW_WAYPOINT_COUNT; ++index) {
78+
if (ScenExtension->Is_Valid_Waypoint(index)) {
79+
list[count++] = ScenExtension->Get_Waypoint_Cell(index);
80+
if (count >= std::size(list)) break;
8381
}
8482
}
8583

8684
/**
8785
* Pick a random cell from the valid waypoint list and play the desired sound.
8886
*/
89-
Cell rnd_cell = cell_list[Random_Pick<unsigned int>(0, std::size(cell_list) - 1)];
90-
91-
Static_Sound(Data.Sound, Cell_Coord(rnd_cell, true));
92-
87+
Static_Sound(Data.Sound, list[Random_Pick(0u, std::size(list) - 1)].As_Coord());
9388
return true;
9489
}
9590

9691

9792
/**
9893
* #issue-71
9994
*
100-
* Replace inlined instance of Play_Sound_At_Random_Waypoint.
95+
* Replace inlined instance of Do_PLAY_SOUND_RANDOM.
10196
*
10297
* @author: CCHyper
10398
*/
104-
DECLARE_PATCH(_TActionClass_Operator_Play_Sound_At_Random_Waypoint_Remove_Inline_Patch)
99+
DECLARE_PATCH(_TActionClass_Operator_Do_PLAY_SOUND_RANDOM_Remove_Inline_Patch)
105100
{
106101
GET_REGISTER_STATIC(TActionClass *, this_ptr, esi);
107102
GET_REGISTER_STATIC(ObjectClass *, object, ecx);
@@ -111,7 +106,7 @@ DECLARE_PATCH(_TActionClass_Operator_Play_Sound_At_Random_Waypoint_Remove_Inline
111106
GET_STACK_STATIC(HouseClass *, house, esp, 0x1C4);
112107
static bool retval;
113108

114-
retval = this_ptr->TAction_Play_Sound_At_Random_Waypoint(house, object, trigger, *cell);
109+
retval = this_ptr->Do_PLAY_SOUND_RANDOM(house, object, trigger, *cell);
115110

116111
/**
117112
* Function return.
@@ -321,8 +316,8 @@ void TActionClassExtension_Hooks()
321316
*
322317
* @author: CCHyper
323318
*/
324-
Patch_Jump(0x0061BF50, &TActionClassExt::_Play_Sound_At_Random_Waypoint);
325-
Patch_Jump(0x00619E42, &_TActionClass_Operator_Play_Sound_At_Random_Waypoint_Remove_Inline_Patch);
319+
Patch_Jump(0x0061BF50, &TActionClassExt::_Do_PLAY_SOUND_RANDOM);
320+
Patch_Jump(0x00619E42, &_TActionClass_Operator_Do_PLAY_SOUND_RANDOM_Remove_Inline_Patch);
326321

327322
Patch_Jump(0x00619FDB, &_TAction_Win_FlagLosersAsDefeatedInMultiplayer);
328323
Patch_Jump(0x0061A005, &_TAction_Lose_FlagLoserAsLostInMultiplayer);

0 commit comments

Comments
 (0)