Skip to content

Commit 2da5cb9

Browse files
committed
修正在条件中错误的问题
1 parent 5903455 commit 2da5cb9

File tree

5 files changed

+106
-26
lines changed

5 files changed

+106
-26
lines changed

Development/Editor/Plugin/WE/YDTrigger/Common.h

+4
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,8 @@ inline void cc_search_var(uint32_t ptr, std::function<void(uint32_t)> func)
9494
}
9595
}
9696

97+
void CC_PutSearchCondition (DWORD This, DWORD OutClass, char* name);
98+
void CC_PutSearchCondition2(DWORD This, DWORD OutClass, char* name);
99+
void CC_PutSearchCondition3(DWORD This, DWORD OutClass, char* name, DWORD index);
100+
97101
#endif

Development/Editor/Plugin/WE/YDTrigger/Core/CC_PutActionEx_Hook.cpp

+75-22
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,14 @@ void CC_PutActionEx_ForGroupConditionBegin(DWORD This, DWORD OutClass, char* nam
190190
switch (*(uint32_t*)(This+0x138))
191191
{
192192
case CC_GUIID_GetUnitsInRangeOfLocMatching:
193+
CC_PutSearchCondition(GetGUIVar_Class(This, 2), OutClass, name);
193194
PUT_CONST("if (", 0);
194195
CC_PutVar_Code(This, OutClass, name, 2, CC_GUI_TYPE_CONDITION);
195196
PUT_CONST(") then", 1);
196197
return;
197198
case CC_GUIID_GetUnitsInRectMatching:
198199
case CC_GUIID_GetUnitsOfPlayerMatching:
200+
CC_PutSearchCondition(GetGUIVar_Class(This, 1), OutClass, name);
199201
PUT_CONST("if (", 0);
200202
CC_PutVar_Code(This, OutClass, name, 1, CC_GUI_TYPE_CONDITION);
201203
PUT_CONST(") then", 1);
@@ -303,17 +305,21 @@ void CC_PutActionEx_ForGroupMatching(DWORD This, DWORD OutClass, char* name)
303305
PUT_CONST("set ydl_unit = FirstOfGroup(ydl_tmp_group)", 1);
304306
PUT_CONST("exitwhen ydl_unit == null", 1);
305307
PUT_CONST("call GroupRemoveUnit(ydl_tmp_group, ydl_unit)", 1);
306-
PUT_CONST("if (", 0);
307308
if (ui_type == CC_GUIID_GetUnitsInRangeOfLocMatching)
308309
{
310+
CC_PutSearchCondition(GetGUIVar_Class(This, 2), OutClass, name);
311+
PUT_CONST("if (", 0);
309312
CC_PutVar_Code(This, OutClass, name, 2, CC_GUI_TYPE_CONDITION);
313+
PUT_CONST(") then", 1);
310314
}
311315
else
312316
{
317+
CC_PutSearchCondition(GetGUIVar_Class(This, 1), OutClass, name);
318+
PUT_CONST("if (", 0);
313319
CC_PutVar_Code(This, OutClass, name, 1, CC_GUI_TYPE_CONDITION);
320+
PUT_CONST(") then", 1);
314321
}
315322

316-
PUT_CONST(") then", 1);
317323
CC_PutBegin();
318324
PUT_CONST("call GroupAddUnit(ydl_group, ydl_unit)", 1);
319325
CC_PutEnd();
@@ -344,6 +350,7 @@ void CC_PutActionEx_ForForce(DWORD This, DWORD OutClass, char* name)
344350
PUT_CONST("loop", 1);
345351
CC_PutBegin();
346352
PUT_CONST("exitwhen ydl_index >= 16", 1);
353+
CC_PutSearchCondition(GetGUIVar_Class(This, 0), OutClass, name);
347354
PUT_CONST("if (GetPlayerSlotState(Player(ydl_index)) != PLAYER_SLOT_STATE_EMPTY) and (", 0);
348355
CC_PutVar_Code(GetGUIVar_Class(This, 0), OutClass, name, 0, CC_GUI_TYPE_CONDITION);
349356
PUT_CONST(") then", 1);
@@ -413,6 +420,7 @@ void CC_PutActionEx_ForForceMatching(DWORD This, DWORD OutClass, char* name)
413420
PUT_CONST("loop", 1);
414421
CC_PutBegin();
415422
PUT_CONST("exitwhen ydl_index >= 16", 1);
423+
CC_PutSearchCondition(GetGUIVar_Class(This, 0), OutClass, name);
416424
PUT_CONST("if (GetPlayerSlotState(Player(ydl_index)) != PLAYER_SLOT_STATE_EMPTY) and (", 0);
417425
CC_PutVar_Code(This, OutClass, name, 0, CC_GUI_TYPE_CONDITION);
418426
PUT_CONST(") then", 1);
@@ -429,6 +437,62 @@ void CC_PutActionEx_ForForceMatching(DWORD This, DWORD OutClass, char* name)
429437
}
430438
}
431439

440+
void CC_PutSearchCondition(DWORD This, DWORD OutClass, char* name)
441+
{
442+
cc_search_var(This, [&](uint32_t var_ptr)
443+
{
444+
switch (*(uint32_t*)(var_ptr+0x138))
445+
{
446+
case CC_GUIID_GetUnitsInRectMatching:
447+
case CC_GUIID_GetUnitsInRangeOfLocMatching:
448+
case CC_GUIID_GetUnitsOfPlayerMatching:
449+
{
450+
CC_PutActionEx_ForGroupMatching(var_ptr, OutClass, name);
451+
}
452+
break;
453+
case CC_GUIID_GetPlayersMatching:
454+
{
455+
CC_PutActionEx_ForForceMatching(var_ptr, OutClass, name);
456+
}
457+
break;
458+
}
459+
});
460+
}
461+
462+
void CC_PutSearchCondition2(DWORD This, DWORD OutClass, char* name)
463+
{
464+
DWORD nItemCount = *(DWORD*)(This+0xC);
465+
for (DWORD i = 0; i < nItemCount; i++)
466+
{
467+
DWORD nItemClass = ((DWORD*)(*(DWORD*)(This+0x10)))[i];
468+
if (Proc_GetGUIType(nItemClass) == CC_GUI_TYPE_CONDITION)
469+
{
470+
if (*(DWORD*)(nItemClass+0x13C) != 0)
471+
{
472+
CC_PutSearchCondition(nItemClass, OutClass, name);
473+
}
474+
}
475+
}
476+
}
477+
478+
void CC_PutSearchCondition3(DWORD This, DWORD OutClass, char* name, DWORD index)
479+
{
480+
DWORD nItemCount = *(DWORD*)(This+0xC);
481+
482+
for (DWORD i = 0; i < nItemCount; i++)
483+
{
484+
DWORD nItemClass = ((DWORD*)(*(DWORD*)(This+0x10)))[i];
485+
if (*(DWORD*)(nItemClass+0x13C) != 0)
486+
{
487+
if ((index) == -1 || (*(DWORD*)(nItemClass+0x154) == index))
488+
{
489+
CC_PutSearchCondition(nItemClass, OutClass, name);
490+
}
491+
}
492+
}
493+
}
494+
495+
432496
void _fastcall
433497
CC_PutActionEx_Hook(DWORD This, DWORD EDX, DWORD OutClass, char* name, DWORD Type, DWORD Endl)
434498
{
@@ -448,30 +512,14 @@ void _fastcall
448512
}
449513
else
450514
{
451-
cc_search_var(This, [&](uint32_t var_ptr)
452-
{
453-
switch (*(uint32_t*)(var_ptr+0x138))
454-
{
455-
case CC_GUIID_GetUnitsInRectMatching:
456-
case CC_GUIID_GetUnitsInRangeOfLocMatching:
457-
case CC_GUIID_GetUnitsOfPlayerMatching:
458-
{
459-
CC_PutActionEx_ForGroupMatching(var_ptr, OutClass, name);
460-
}
461-
break;
462-
case CC_GUIID_GetPlayersMatching:
463-
{
464-
CC_PutActionEx_ForForceMatching(var_ptr, OutClass, name);
465-
}
466-
break;
467-
}
468-
});
515+
CC_PutSearchCondition(This, OutClass, name);
469516
}
470517

471518
switch (*(DWORD*)(This+0x138))
472519
{
473520
case CC_GUIID_IfThenElse:
474521
{
522+
CC_PutSearchCondition(GetGUIVar_Class(This, 0), OutClass, name);
475523
CC_PutBegin();
476524
PUT_CONST("if (", 0);
477525
CC_PutVar_Code(This, OutClass, name, 0, CC_GUI_TYPE_CONDITION);
@@ -486,6 +534,7 @@ void _fastcall
486534
}
487535
case CC_GUIID_IfThenElseMultiple:
488536
{
537+
CC_PutSearchCondition3(This, OutClass, name, 0);
489538
CC_PutBegin();
490539
PUT_CONST("if (", 0);
491540
CC_PutBlock_Condition_And(This, OutClass, name, 0);
@@ -543,17 +592,21 @@ void _fastcall
543592
PUT_CONST("set ydl_unit = FirstOfGroup(ydl_tmp_group)", 1);
544593
PUT_CONST("exitwhen ydl_unit == null", 1);
545594
PUT_CONST("call GroupRemoveUnit(ydl_tmp_group, ydl_unit)", 1);
546-
PUT_CONST("if (", 0);
547595
if (ui_type == CC_GUIID_GroupEnumUnitsInRangeOfLoc
548596
|| ui_type == CC_GUIID_GroupEnumUnitsInRangeOfLocCounted)
549597
{
598+
CC_PutSearchCondition(GetGUIVar_Class(This, 3), OutClass, name);
599+
PUT_CONST("if (", 0);
550600
CC_PutVar_Code(This, OutClass, name, 3, CC_GUI_TYPE_CONDITION);
601+
PUT_CONST(") then", 1);
551602
}
552603
else
553604
{
605+
CC_PutSearchCondition(GetGUIVar_Class(This, 4), OutClass, name);
606+
PUT_CONST("if (", 0);
554607
CC_PutVar_Code(This, OutClass, name, 4, CC_GUI_TYPE_CONDITION);
608+
PUT_CONST(") then", 1);
555609
}
556-
PUT_CONST(") then", 1);
557610
CC_PutBegin();
558611
PUT_CONST("call GroupAddUnit(ydl_group, ydl_unit)", 1);
559612
CC_PutEnd();

Development/Editor/Plugin/WE/YDTrigger/Core/CC_PutLocal.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ void _fastcall
7878
CC_PutLocal_LocalVar(OutClass, CC_TYPE_group, "ydl", "group");
7979
CC_PutLocal_LocalVar(OutClass, CC_TYPE_unit, "ydl", "unit");
8080
break;
81+
case CC_GUIID_GetPlayersMatching:
82+
CC_PutLocal_LocalVar(OutClass, CC_TYPE_integer, "ydl", "index");
83+
CC_PutLocal_LocalVar(OutClass, CC_TYPE_force, "ydl", "force");
84+
break;
8185
default:
8286
break;
8387
}

Development/Editor/Plugin/WE/YDTrigger/Core/CC_PutTrigger_Hook.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "CC_Include.h"
22

3+
bool g_bBuildTriggerCondition = false;
4+
35
int _fastcall
46
CC_PutTrigger_Count(DWORD This, DWORD cc_gui_type)
57
{
@@ -65,12 +67,14 @@ CC_PutTrigger_ECA_ExternProc(DWORD This, DWORD OutClass)
6567

6668
BLZSStrPrintf(buff, 260, "function %sConditions takes nothing returns boolean", name);
6769
PUT_CONST(buff, 1);
68-
70+
71+
g_bBuildTriggerCondition = true;
6972
CC_PutBegin();
7073
PUT_CONST("return (", 0);
7174
CC_PutTrigger_Condition_And(This, OutClass, name);
7275
PUT_CONST(")", 1);
73-
CC_PutEnd();
76+
CC_PutEnd();
77+
g_bBuildTriggerCondition = false;
7478

7579
PUT_CONST("endfunction", 1);
7680
PUT_CONST("", 1);

Development/Editor/Plugin/WE/YDTrigger/Core/CC_PutVar_Other_Hook.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
extern BOOL g_bYDWEEnumUnitsInRangeMultipleFlag;
55
extern BOOL g_bForForceMultipleFlag;
6+
extern bool g_bBuildTriggerCondition;
67

78
void _fastcall
89
CC_PutVar_Other_Hook(DWORD This, DWORD EDX, DWORD OutClass, char* name, DWORD index, DWORD type)
@@ -58,10 +59,24 @@ CC_PutVar_Other_Hook(DWORD This, DWORD EDX, DWORD OutClass, char* name, DWORD in
5859
case CC_GUIID_GetUnitsInRectMatching:
5960
case CC_GUIID_GetUnitsInRangeOfLocMatching:
6061
case CC_GUIID_GetUnitsOfPlayerMatching:
61-
PUT_CONST("ydl_group", 0);
62+
if (!g_bBuildTriggerCondition)
63+
{
64+
PUT_CONST("ydl_group", 0);
65+
}
66+
else
67+
{
68+
CC_PutVar_Other(This, EDX, OutClass, name, index, type);
69+
}
6270
return;
6371
case CC_GUIID_GetPlayersMatching:
64-
PUT_CONST("ydl_force", 0);
72+
if (!g_bBuildTriggerCondition)
73+
{
74+
PUT_CONST("ydl_force", 0);
75+
}
76+
else
77+
{
78+
CC_PutVar_Other(This, EDX, OutClass, name, index, type);
79+
}
6580
return;
6681
case CC_GUIID_YDWECustomScriptCode:
6782
BLZSStrPrintf(NewName, 260, "%sFunc%03d", name, index+1);

0 commit comments

Comments
 (0)