1+ local AVGControllerHotfixer = Class (" AVGControllerHotfixer" , HotfixBase )
2+
3+ local function _FindDecisionPanel (controller )
4+ if controller == nil then
5+ return nil
6+ end
7+ local comps = controller .m_components
8+ if comps == nil then
9+ return nil
10+ end
11+ for i = 0 , comps .Length - 1 do
12+ local comp = comps [i ]
13+ if comp ~= nil and comp :GetType () == typeof (CS .Torappu .AVG .DecisionPanel ) then
14+ return comp
15+ end
16+ end
17+ return nil
18+ end
19+
20+ local function _TryGetDecisionExecutorFromPanel (decisionPanel )
21+ if decisionPanel == nil then
22+ return nil
23+ end
24+
25+ local panelExecutors = decisionPanel .m_executorWrappers
26+
27+ if panelExecutors == nil then
28+ return nil
29+ end
30+
31+ for e = 0 , panelExecutors .Length - 1 do
32+ local ex = panelExecutors [e ]
33+ if ex ~= nil and ex .command == " decision" then
34+ return ex
35+ end
36+ end
37+
38+ return nil
39+ end
40+
41+
42+
43+ local function _SnapshotDecisionExecutors (csList )
44+ if csList == nil or csList .Count <= 0 then
45+ return nil
46+ end
47+ local snapshot = {}
48+ for i = 0 , csList .Count - 1 do
49+ snapshot [i + 1 ] = csList [i ]
50+ end
51+ return snapshot
52+ end
53+
54+ local function _FinishDecisionExecutors (snapshot , decisionPanel , decisionExecutor )
55+ local finishedDecisionPanel = false
56+ for i = # snapshot , 1 , - 1 do
57+ local executor = snapshot [i ]
58+ if executor ~= nil then
59+ if (not finishedDecisionPanel ) and decisionPanel ~= nil and decisionExecutor ~= nil and executor == decisionExecutor then
60+ finishedDecisionPanel = true
61+ decisionPanel :FinishCommand ()
62+ else
63+ executor :ForceEnd ()
64+ end
65+ end
66+ end
67+ end
68+
69+ local function _TryFinishDecisionExecutors (controller , snapshot )
70+ if controller == nil then
71+ return
72+ end
73+ if snapshot == nil or # snapshot == 0 then
74+ return
75+ end
76+
77+ local decisionPanel = _FindDecisionPanel (controller )
78+ local decisionExecutor = _TryGetDecisionExecutorFromPanel (decisionPanel )
79+ _FinishDecisionExecutors (snapshot , decisionPanel , decisionExecutor )
80+ end
81+
82+ local function OnDecisionSelectedFix (self , decisionValue , decisionIndex )
83+ local snapshot = _SnapshotDecisionExecutors (self .m_decisionExecutors )
84+ self :OnDecisionSelected (decisionValue , decisionIndex )
85+ _TryFinishDecisionExecutors (self , snapshot )
86+ snapshot = nil
87+ end
88+
89+ function AVGControllerHotfixer :OnInit ()
90+ xlua .private_accessible (CS .Torappu .AVG .AVGController )
91+ xlua .private_accessible (CS .Torappu .AVG .ExecutorComponent )
92+ xlua .private_accessible (CS .Torappu .AVG .DecisionPanel )
93+ self :Fix_ex (CS .Torappu .AVG .AVGController , " OnDecisionSelected" , function (self ,decisionValue , decisionIndex )
94+ local ok , errorInfo = xpcall (OnDecisionSelectedFix , debug.traceback , self , decisionValue ,
95+ decisionIndex )
96+ if not ok then
97+ LogError (" [AVGControllerHotfixer] OnDecisionSelected fix: " .. tostring (errorInfo ))
98+ self :OnDecisionSelected (decisionValue , decisionIndex )
99+ end
100+ end )
101+ end
102+
103+ function AVGControllerHotfixer :OnDispose ()
104+ end
105+
106+ return AVGControllerHotfixer
0 commit comments