This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Plugin.cs
executable file
·323 lines (303 loc) · 12 KB
/
Plugin.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
using Dalamud.Configuration;
using Dalamud.Game;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.IoC;
using Dalamud.Logging;
using Dalamud.Plugin;
using DalamudPluginProjectTemplate.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace DalamudPluginProjectTemplate
{
public class Plugin : IDalamudPlugin, IDisposable
{
internal static Configuration config;
private static IntPtr lootsAddr;
internal static RollItemRaw rollItemRaw;
private readonly PluginCommandManager<Plugin> commandManager;
private readonly PluginUI ui;
[PluginService]
public static CommandManager CommandManager { get; set; }
[PluginService]
public static DalamudPluginInterface PluginInterface { get; set; }
[PluginService]
public static SigScanner SigScanner { get; set; }
[PluginService]
public static ChatGui ChatGui { get; set; }
public static List<LootItem> LootItems => ReadArray<LootItem>(lootsAddr + 16, 16).Where(i => i.Valid).ToList();
public string Name => "LootMaster";
public Plugin()
{
lootsAddr = SigScanner.GetStaticAddressFromSig("48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 89 44 24 60", 0);
rollItemRaw = Marshal.GetDelegateForFunctionPointer<RollItemRaw>(SigScanner.ScanText("41 83 F8 ?? 0F 83 ?? ?? ?? ?? 48 89 5C 24 08"));
config = (Configuration)PluginInterface.GetPluginConfig() ?? new Configuration();
config.Initialize(PluginInterface);
ui = new PluginUI();
PluginInterface.UiBuilder.Draw += new System.Action(ui.Draw);
PluginInterface.UiBuilder.OpenConfigUi += () =>
{
PluginUI ui = this.ui;
ui.IsVisible = !ui.IsVisible;
};
commandManager = new PluginCommandManager<Plugin>(this, PluginInterface);
}
private void RollItem(RollOption option, int index)
{
LootItem lootItem = LootItems[index];
PluginLog.Information(string.Format("{0} [{1}] {2} Id: {3:X} rollState: {4} rollOption: {5}", option, index, lootItem.ItemId, lootItem.ObjectId, lootItem.RollState, lootItem.RolledState), Array.Empty<object>());
rollItemRaw(lootsAddr, option, (uint)index);
}
[Command("/need")]
[HelpMessage("Roll need for everything. If impossible, roll greed. Else, roll pass")]
public async void NeedCommand(string command, string args)
{
int num1 = 0;
int num2 = 0;
int num3 = 0;
for (int index = 0; index < LootItems.Count; ++index)
{
if (!LootItems[index].Rolled)
{
if (LootItems[index].RollState == RollState.UpToNeed && !LootItems[index].Rolled)
{
RollItem(RollOption.Need, index);
await Task.Delay(500);
if (LootItems[index].Rolled)
{
++num1;
}
else
{
RollItem(RollOption.Pass, index);
++num3;
}
}
else if (LootItems[index].RollState == RollState.UpToGreed && !LootItems[index].Rolled)
{
RollItem(RollOption.Greed, index);
await Task.Delay(500);
if (LootItems[index].Rolled)
{
++num2;
}
else
{
RollItem(RollOption.Pass, index);
++num3;
}
}
else
{
RollItem(RollOption.Pass, index);
await Task.Delay(500);
if (LootItems[index].Rolled)
{
++num3;
}
}
}
}
if (!config.EnableChatLogMessage)
return;
ChatGui chatGui = ChatGui;
List<Payload> payloadList = new()
{
new TextPayload("Need "),
new UIForegroundPayload(575),
new TextPayload(num1.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num1 > 1 ? "s" : "") + ", greed "),
new UIForegroundPayload(575),
new TextPayload(num2.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num2 > 1 ? "s" : "") + ", pass "),
new UIForegroundPayload(575),
new TextPayload(num3.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num3 > 1 ? "s" : "") + ".")
};
SeString seString = new(payloadList);
chatGui.Print(seString);
}
[Command("/needonly")]
[HelpMessage("Roll need for everything. If impossible, roll greed. Else, roll pass")]
public async void NeedOnlyCommand(string command, string args)
{
int num1 = 0;
int num2 = 0;
for (int index = 0; index < LootItems.Count; ++index)
{
if (!LootItems[index].Rolled)
{
if (LootItems[index].RollState == RollState.UpToNeed)
{
RollItem(RollOption.Need, index);
await Task.Delay(500);
if (LootItems[index].Rolled)
{
++num1;
}
else
{
RollItem(RollOption.Pass, index);
++num2;
}
}
else
{
RollItem(RollOption.Pass, index);
++num2;
}
}
}
if (!config.EnableChatLogMessage)
return;
ChatGui chatGui = ChatGui;
List<Payload> payloadList = new()
{
new TextPayload("Need Only"),
new UIForegroundPayload(575),
new TextPayload(num1.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num1 > 1 ? "s" : "") + ", pass "),
new UIForegroundPayload(575),
new TextPayload(num2.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num2 > 1 ? "s" : "") + ".")
};
SeString seString = new(payloadList);
chatGui.Print(seString);
}
[Command("/greed")]
[HelpMessage("Greed on all items.")]
public async void GreedCommand(string command, string args)
{
int num = 0;
int num1 = 0;
for (int index = 0; index < LootItems.Count; ++index)
{
if (!LootItems[index].Rolled)
{
RollItem(RollOption.Greed, index);
await Task.Delay(500);
if (LootItems[index].Rolled)
{
++num;
}
else
{
RollItem(RollOption.Pass, index);
++num1;
}
}
else
{
RollItem(RollOption.Pass, index);
++num1;
}
}
if (!config.EnableChatLogMessage)
return;
ChatGui chatGui = ChatGui;
List<Payload> payloadList = new()
{
new TextPayload("Greed "),
new UIForegroundPayload(575),
new TextPayload(num.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num > 1 ? "s" : "") + ", pass "),
new UIForegroundPayload(575),
new TextPayload(num.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num1 > 1 ? "s" : "") + "."),
};
SeString seString = new(payloadList);
chatGui.Print(seString);
}
[Command("/pass")]
[HelpMessage("Pass on things you haven't rolled for yet.")]
public void PassCommand(string command, string args)
{
int num = 0;
for (int index = 0; index < LootItems.Count; ++index)
{
if (!LootItems[index].Rolled)
{
RollItem(RollOption.Pass, index);
++num;
}
}
if (!config.EnableChatLogMessage)
return;
ChatGui chatGui = ChatGui;
List<Payload> payloadList = new()
{
new TextPayload("Pass "),
new UIForegroundPayload(575),
new TextPayload(num.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num > 1 ? "s" : "") + ".")
};
SeString seString = new(payloadList);
chatGui.Print(seString);
}
[Command("/passall")]
[HelpMessage("Passes on all, even if you rolled on them previously.")]
public void PassAllCommand(string command, string args)
{
int num = 0;
for (int index = 0; index < LootItems.Count; ++index)
{
if (LootItems[index].RolledState != RollOption.Pass)
{
RollItem(RollOption.Pass, index);
++num;
}
}
if (!config.EnableChatLogMessage)
return;
ChatGui chatGui = ChatGui;
List<Payload> payloadList = new()
{
new TextPayload("Pass all "),
new UIForegroundPayload(575),
new TextPayload(num.ToString()),
new UIForegroundPayload(0),
new TextPayload(" item" + (num > 1 ? "s" : "") + ".")
};
SeString seString = new(payloadList);
chatGui.Print(seString);
}
public static T[] ReadArray<T>(IntPtr unmanagedArray, int length) where T : struct
{
int num = Marshal.SizeOf(typeof(T));
T[] objArray = new T[length];
for (int index = 0; index < length; ++index)
{
IntPtr ptr = new(unmanagedArray.ToInt64() + index * num);
objArray[index] = Marshal.PtrToStructure<T>(ptr);
}
return objArray;
}
protected virtual void Dispose(bool disposing)
{
if (!disposing)
return;
commandManager.Dispose();
PluginInterface.SavePluginConfig(config);
PluginInterface.UiBuilder.Draw -= new System.Action(ui.Draw);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
internal delegate void RollItemRaw(IntPtr lootIntPtr, RollOption option, uint lootItemIndex);
}
}