Skip to content

Commit

Permalink
修正在条件中错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Sep 22, 2013
1 parent 5903455 commit 2da5cb9
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 26 deletions.
4 changes: 4 additions & 0 deletions Development/Editor/Plugin/WE/YDTrigger/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ inline void cc_search_var(uint32_t ptr, std::function<void(uint32_t)> func)
}
}

void CC_PutSearchCondition (DWORD This, DWORD OutClass, char* name);
void CC_PutSearchCondition2(DWORD This, DWORD OutClass, char* name);
void CC_PutSearchCondition3(DWORD This, DWORD OutClass, char* name, DWORD index);

#endif
97 changes: 75 additions & 22 deletions Development/Editor/Plugin/WE/YDTrigger/Core/CC_PutActionEx_Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@ void CC_PutActionEx_ForGroupConditionBegin(DWORD This, DWORD OutClass, char* nam
switch (*(uint32_t*)(This+0x138))
{
case CC_GUIID_GetUnitsInRangeOfLocMatching:
CC_PutSearchCondition(GetGUIVar_Class(This, 2), OutClass, name);
PUT_CONST("if (", 0);
CC_PutVar_Code(This, OutClass, name, 2, CC_GUI_TYPE_CONDITION);
PUT_CONST(") then", 1);
return;
case CC_GUIID_GetUnitsInRectMatching:
case CC_GUIID_GetUnitsOfPlayerMatching:
CC_PutSearchCondition(GetGUIVar_Class(This, 1), OutClass, name);
PUT_CONST("if (", 0);
CC_PutVar_Code(This, OutClass, name, 1, CC_GUI_TYPE_CONDITION);
PUT_CONST(") then", 1);
Expand Down Expand Up @@ -303,17 +305,21 @@ void CC_PutActionEx_ForGroupMatching(DWORD This, DWORD OutClass, char* name)
PUT_CONST("set ydl_unit = FirstOfGroup(ydl_tmp_group)", 1);
PUT_CONST("exitwhen ydl_unit == null", 1);
PUT_CONST("call GroupRemoveUnit(ydl_tmp_group, ydl_unit)", 1);
PUT_CONST("if (", 0);
if (ui_type == CC_GUIID_GetUnitsInRangeOfLocMatching)
{
CC_PutSearchCondition(GetGUIVar_Class(This, 2), OutClass, name);
PUT_CONST("if (", 0);
CC_PutVar_Code(This, OutClass, name, 2, CC_GUI_TYPE_CONDITION);
PUT_CONST(") then", 1);
}
else
{
CC_PutSearchCondition(GetGUIVar_Class(This, 1), OutClass, name);
PUT_CONST("if (", 0);
CC_PutVar_Code(This, OutClass, name, 1, CC_GUI_TYPE_CONDITION);
PUT_CONST(") then", 1);
}

PUT_CONST(") then", 1);
CC_PutBegin();
PUT_CONST("call GroupAddUnit(ydl_group, ydl_unit)", 1);
CC_PutEnd();
Expand Down Expand Up @@ -344,6 +350,7 @@ void CC_PutActionEx_ForForce(DWORD This, DWORD OutClass, char* name)
PUT_CONST("loop", 1);
CC_PutBegin();
PUT_CONST("exitwhen ydl_index >= 16", 1);
CC_PutSearchCondition(GetGUIVar_Class(This, 0), OutClass, name);
PUT_CONST("if (GetPlayerSlotState(Player(ydl_index)) != PLAYER_SLOT_STATE_EMPTY) and (", 0);
CC_PutVar_Code(GetGUIVar_Class(This, 0), OutClass, name, 0, CC_GUI_TYPE_CONDITION);
PUT_CONST(") then", 1);
Expand Down Expand Up @@ -413,6 +420,7 @@ void CC_PutActionEx_ForForceMatching(DWORD This, DWORD OutClass, char* name)
PUT_CONST("loop", 1);
CC_PutBegin();
PUT_CONST("exitwhen ydl_index >= 16", 1);
CC_PutSearchCondition(GetGUIVar_Class(This, 0), OutClass, name);
PUT_CONST("if (GetPlayerSlotState(Player(ydl_index)) != PLAYER_SLOT_STATE_EMPTY) and (", 0);
CC_PutVar_Code(This, OutClass, name, 0, CC_GUI_TYPE_CONDITION);
PUT_CONST(") then", 1);
Expand All @@ -429,6 +437,62 @@ void CC_PutActionEx_ForForceMatching(DWORD This, DWORD OutClass, char* name)
}
}

void CC_PutSearchCondition(DWORD This, DWORD OutClass, char* name)
{
cc_search_var(This, [&](uint32_t var_ptr)
{
switch (*(uint32_t*)(var_ptr+0x138))
{
case CC_GUIID_GetUnitsInRectMatching:
case CC_GUIID_GetUnitsInRangeOfLocMatching:
case CC_GUIID_GetUnitsOfPlayerMatching:
{
CC_PutActionEx_ForGroupMatching(var_ptr, OutClass, name);
}
break;
case CC_GUIID_GetPlayersMatching:
{
CC_PutActionEx_ForForceMatching(var_ptr, OutClass, name);
}
break;
}
});
}

void CC_PutSearchCondition2(DWORD This, DWORD OutClass, char* name)
{
DWORD nItemCount = *(DWORD*)(This+0xC);
for (DWORD i = 0; i < nItemCount; i++)
{
DWORD nItemClass = ((DWORD*)(*(DWORD*)(This+0x10)))[i];
if (Proc_GetGUIType(nItemClass) == CC_GUI_TYPE_CONDITION)
{
if (*(DWORD*)(nItemClass+0x13C) != 0)
{
CC_PutSearchCondition(nItemClass, OutClass, name);
}
}
}
}

void CC_PutSearchCondition3(DWORD This, DWORD OutClass, char* name, DWORD index)
{
DWORD nItemCount = *(DWORD*)(This+0xC);

for (DWORD i = 0; i < nItemCount; i++)
{
DWORD nItemClass = ((DWORD*)(*(DWORD*)(This+0x10)))[i];
if (*(DWORD*)(nItemClass+0x13C) != 0)
{
if ((index) == -1 || (*(DWORD*)(nItemClass+0x154) == index))
{
CC_PutSearchCondition(nItemClass, OutClass, name);
}
}
}
}


void _fastcall
CC_PutActionEx_Hook(DWORD This, DWORD EDX, DWORD OutClass, char* name, DWORD Type, DWORD Endl)
{
Expand All @@ -448,30 +512,14 @@ void _fastcall
}
else
{
cc_search_var(This, [&](uint32_t var_ptr)
{
switch (*(uint32_t*)(var_ptr+0x138))
{
case CC_GUIID_GetUnitsInRectMatching:
case CC_GUIID_GetUnitsInRangeOfLocMatching:
case CC_GUIID_GetUnitsOfPlayerMatching:
{
CC_PutActionEx_ForGroupMatching(var_ptr, OutClass, name);
}
break;
case CC_GUIID_GetPlayersMatching:
{
CC_PutActionEx_ForForceMatching(var_ptr, OutClass, name);
}
break;
}
});
CC_PutSearchCondition(This, OutClass, name);
}

switch (*(DWORD*)(This+0x138))
{
case CC_GUIID_IfThenElse:
{
CC_PutSearchCondition(GetGUIVar_Class(This, 0), OutClass, name);
CC_PutBegin();
PUT_CONST("if (", 0);
CC_PutVar_Code(This, OutClass, name, 0, CC_GUI_TYPE_CONDITION);
Expand All @@ -486,6 +534,7 @@ void _fastcall
}
case CC_GUIID_IfThenElseMultiple:
{
CC_PutSearchCondition3(This, OutClass, name, 0);
CC_PutBegin();
PUT_CONST("if (", 0);
CC_PutBlock_Condition_And(This, OutClass, name, 0);
Expand Down Expand Up @@ -543,17 +592,21 @@ void _fastcall
PUT_CONST("set ydl_unit = FirstOfGroup(ydl_tmp_group)", 1);
PUT_CONST("exitwhen ydl_unit == null", 1);
PUT_CONST("call GroupRemoveUnit(ydl_tmp_group, ydl_unit)", 1);
PUT_CONST("if (", 0);
if (ui_type == CC_GUIID_GroupEnumUnitsInRangeOfLoc
|| ui_type == CC_GUIID_GroupEnumUnitsInRangeOfLocCounted)
{
CC_PutSearchCondition(GetGUIVar_Class(This, 3), OutClass, name);
PUT_CONST("if (", 0);
CC_PutVar_Code(This, OutClass, name, 3, CC_GUI_TYPE_CONDITION);
PUT_CONST(") then", 1);
}
else
{
CC_PutSearchCondition(GetGUIVar_Class(This, 4), OutClass, name);
PUT_CONST("if (", 0);
CC_PutVar_Code(This, OutClass, name, 4, CC_GUI_TYPE_CONDITION);
PUT_CONST(") then", 1);
}
PUT_CONST(") then", 1);
CC_PutBegin();
PUT_CONST("call GroupAddUnit(ydl_group, ydl_unit)", 1);
CC_PutEnd();
Expand Down
4 changes: 4 additions & 0 deletions Development/Editor/Plugin/WE/YDTrigger/Core/CC_PutLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ void _fastcall
CC_PutLocal_LocalVar(OutClass, CC_TYPE_group, "ydl", "group");
CC_PutLocal_LocalVar(OutClass, CC_TYPE_unit, "ydl", "unit");
break;
case CC_GUIID_GetPlayersMatching:
CC_PutLocal_LocalVar(OutClass, CC_TYPE_integer, "ydl", "index");
CC_PutLocal_LocalVar(OutClass, CC_TYPE_force, "ydl", "force");
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "CC_Include.h"

bool g_bBuildTriggerCondition = false;

int _fastcall
CC_PutTrigger_Count(DWORD This, DWORD cc_gui_type)
{
Expand Down Expand Up @@ -65,12 +67,14 @@ CC_PutTrigger_ECA_ExternProc(DWORD This, DWORD OutClass)

BLZSStrPrintf(buff, 260, "function %sConditions takes nothing returns boolean", name);
PUT_CONST(buff, 1);


g_bBuildTriggerCondition = true;
CC_PutBegin();
PUT_CONST("return (", 0);
CC_PutTrigger_Condition_And(This, OutClass, name);
PUT_CONST(")", 1);
CC_PutEnd();
CC_PutEnd();
g_bBuildTriggerCondition = false;

PUT_CONST("endfunction", 1);
PUT_CONST("", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

extern BOOL g_bYDWEEnumUnitsInRangeMultipleFlag;
extern BOOL g_bForForceMultipleFlag;
extern bool g_bBuildTriggerCondition;

void _fastcall
CC_PutVar_Other_Hook(DWORD This, DWORD EDX, DWORD OutClass, char* name, DWORD index, DWORD type)
Expand Down Expand Up @@ -58,10 +59,24 @@ CC_PutVar_Other_Hook(DWORD This, DWORD EDX, DWORD OutClass, char* name, DWORD in
case CC_GUIID_GetUnitsInRectMatching:
case CC_GUIID_GetUnitsInRangeOfLocMatching:
case CC_GUIID_GetUnitsOfPlayerMatching:
PUT_CONST("ydl_group", 0);
if (!g_bBuildTriggerCondition)
{
PUT_CONST("ydl_group", 0);
}
else
{
CC_PutVar_Other(This, EDX, OutClass, name, index, type);
}
return;
case CC_GUIID_GetPlayersMatching:
PUT_CONST("ydl_force", 0);
if (!g_bBuildTriggerCondition)
{
PUT_CONST("ydl_force", 0);
}
else
{
CC_PutVar_Other(This, EDX, OutClass, name, index, type);
}
return;
case CC_GUIID_YDWECustomScriptCode:
BLZSStrPrintf(NewName, 260, "%sFunc%03d", name, index+1);
Expand Down

0 comments on commit 2da5cb9

Please sign in to comment.