This repository was archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathRepair.cs
197 lines (168 loc) · 6.98 KB
/
Repair.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
AutoRepair is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
Original work done by Kayla D'orden
*/
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Media;
using Buddy.Coroutines;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Helpers;
using ff14bot.Managers;
using ff14bot.RemoteWindows;
using GreyMagic;
using TreeSharp;
using Action = TreeSharp.Action;
namespace AutoRepair
{
public class AutoRepair : BotPlugin
{
public static int RepairThreshold = 30;
public static int AgentId = 36;
private static IntPtr off;
private static IntPtr func;
private static IntPtr vtable;
private static ActionRunCoroutine s_hook;
private Composite _root;
public override string Author => "Kayla D'orden";
public override Version Version => new Version(1, 7);
public override string Name => _Name;
public override bool WantButton => false;
public static string _Name => "AutoRepair";
public Composite CreateVendorBehavior
{
get
{
return new Decorator(r => !Core.Me.InCombat && !MovementManager.IsOccupied && !Repairing,
new PrioritySelector(
new Decorator(r => InventoryManager.EquippedItems.Any(item => item.Item != null && item.Item.RepairItemId != 0 && item.Condition < RepairThreshold),
new Sequence(
new Action(r => Log("Start")),
new Action(r => TreeRoot.StatusText = "Should be repairing"),
//new Action(r => Run()),
new Action(r => Repairing = true),
new Action(r => Log("Stop")),
new Action(r => TreeRoot.StatusText = "Should be done repairing")
)
)
)
);
}
}
public Composite RepairBehavior
{
get
{
return new PrioritySelector(
new Decorator(r => Repairing,
new PrioritySelector(
new Decorator(r => SelectYesno.IsOpen,
new Sequence(
new Action(r => Log("At Select Yes/No")),
new Sleep(500),
//new Action(r => Thread.Sleep(1000)),
new Action(r => SelectYesno.ClickYes()),
new Sleep(1000),
new Action(r => Repairing = false),
new Action(r => Repair.Close())
)
),
new Decorator(r => Repair.IsOpen,
new Sequence(
new Action(r => Log("Window open so repairing")),
new Action(r => Repair.RepairAll())
)
),
new Decorator(r => !Repair.IsOpen,
new Sequence(
new Action(r => Log("Window not open so opening")),
new Action(r => OpenRepair()),
new WaitContinue(TimeSpan.FromMilliseconds(1500.0), r => !Repair.IsOpen, new Action(r => RunStatus.Success))
)
)
)
),
new Decorator(r => !Repairing && Repair.IsOpen, new Action(r => Repair.Close()))
);
}
}
public static bool Repairing { get; set; }
public override void OnInitialize()
{
TreeRoot.OnStart += OnBotStart;
TreeRoot.OnStop += OnBotStop;
Repairing = false;
var patternFinder = new PatternFinder(Core.Memory);
var off = patternFinder.Find("4C 8D 0D ? ? ? ? 45 33 C0 33 D2 48 8B C8 E8 ? ? ? ? Add 3 TraceRelative");
var func = patternFinder.Find("48 89 5C 24 ? 57 48 83 EC ? 88 51 ? 49 8B F9");
var vtable = patternFinder.Find("48 8D 05 ? ? ? ? 48 89 03 B9 ? ? ? ? 4C 89 43 ? Add 3 TraceRelative");
var repairAgent = AgentModule.FindAgentIdByVtable(vtable);
//Core.Memory.CallInjected64<IntPtr>(func, AgentModule.GetAgentInterfaceById(AgentId).Pointer, 0, 0, off);
Log($"AgentId {AgentId} Offset {off.ToInt64():X} Func {func.ToInt64():X}");
AgentId = repairAgent;
_root = new Decorator(r => Repairing, RepairBehavior);
//_root = new Decorator(r => Repairing, new ActionAlwaysSucceed());
}
private void OnBotStop(BotBase bot)
{
RemoveHooks();
}
private void OnBotStart(BotBase bot)
{
AddHooks();
}
public override void OnShutdown()
{
TreeRoot.OnStart -= OnBotStart;
TreeRoot.OnStop -= OnBotStop;
RemoveHooks();
}
private void AddHooks()
{
Log("Adding Hook");
Repairing = false;
TreeHooks.Instance.AddHook("TreeStart", _root);
TreeHooks.Instance.AddHook("TreeStart", CreateVendorBehavior);
}
private void RemoveHooks()
{
Log("Removing Hook");
Repairing = false;
TreeHooks.Instance.RemoveHook("TreeStart", CreateVendorBehavior);
TreeHooks.Instance.RemoveHook("TreeStart", _root);
}
private void OnHooksCleared(object sender, EventArgs e)
{
AddHooks();
}
public override void OnEnabled()
{
Repairing = false;
TreeRoot.OnStart += OnBotStart;
TreeRoot.OnStop += OnBotStop;
TreeHooks.Instance.OnHooksCleared += OnHooksCleared;
if (TreeRoot.IsRunning) AddHooks();
}
public override void OnDisabled()
{
TreeRoot.OnStart -= OnBotStart;
TreeRoot.OnStop -= OnBotStop;
RemoveHooks();
}
public async static Task OpenRepair()
{
Core.Memory.CallInjected64<IntPtr>(func, AgentModule.GetAgentInterfaceById(AgentId).Pointer, 0, 0, off);
await Coroutine.Wait(5000, () => Repair.IsOpen);
}
public static void Log(string text)
{
Logging.Write(Colors.OrangeRed, string.Format("[{1}] {0}", text, _Name));
}
}
}