forked from sruon/ffxivlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
506 lines (340 loc) · 16.3 KB
/
Player.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
namespace ffxivlib
{
public class Player : BaseObject<Player.PLAYERINFO>
{
/*
* At 0x1 the character name is available, but C# throws a Run time error because it's not aligned on proper boundaries,
* therefore I'm not making it available for now as that'd require me to unalign everything else.
* Refer to ENTITYINFO(0) for name.
*/
#region Constructor
public Player(PLAYERINFO structure, IntPtr address)
: base(structure, address)
{
Initialize();
string temp = Encoding.Default.GetString(new ArraySegment<byte> (structure.MarkName, 1, 32).ToArray());
for (int i = 0; i < 32; ++i)
{
if (temp [i] == 0)
{
Name = temp.Substring (0, i);
break;
}
}
}
#endregion
#region Properties
public string Name;
public int Zone
{
get { return GetZone(); }
}
public int Subzone
{
get { return GetSubzone(); }
}
public JOB Job { get; set; }
#region Job Levels
public byte PGL { get; set; }
public byte GLD { get; set; }
public byte MRD { get; set; }
public byte ARC { get; set; }
public byte LNC { get; set; }
public byte THM { get; set; }
public byte CNJ { get; set; }
public byte CPT { get; set; }
public byte BSM { get; set; }
public byte ARM { get; set; }
public byte GSM { get; set; }
public byte LTW { get; set; }
public byte WVR { get; set; }
public byte ALC { get; set; }
public byte CUL { get; set; }
public byte MIN { get; set; }
public byte BOT { get; set; }
public byte FSH { get; set; }
public byte ACN { get; set; }
#endregion
#region Job Exp In Level
public int PGL_EIL { get; set; }
public int GLD_EIL { get; set; }
public int MRD_EIL { get; set; }
public int ARC_EIL { get; set; }
public int LNC_EIL { get; set; }
public int THM_EIL { get; set; }
public int CNJ_EIL { get; set; }
public int ACN_EIL { get; set; }
public int BSM_EIL { get; set; }
public int CPT_EIL { get; set; }
public int GSM_EIL { get; set; }
public int ARM_EIL { get; set; }
public int WVR_EIL { get; set; }
public int LTW_EIL { get; set; }
public int CUL_EIL { get; set; }
public int MIN_EIL { get; set; }
public int BOT_EIL { get; set; }
public int FSH_EIL { get; set; }
#endregion
#region Base Stats
public short BaseSTR { get; set; }
public short BaseDEX { get; set; }
public short BaseVIT { get; set; }
public short BaseINT { get; set; }
public short BaseMND { get; set; }
public short BasePIE { get; set; }
#endregion
#region Stats (base+gear+bonus)
public short STR { get; set; }
public short DEX { get; set; }
public short VIT { get; set; }
public short INT { get; set; }
public short MND { get; set; }
public short PIE { get; set; }
#endregion
#region Basic infos
public int MaxHP { get; set; }
public int MaxMP { get; set; }
public int MaxTP { get; set; }
public int MaxGP { get; set; }
public int MaxCP { get; set; }
#endregion
#region Defensive stats
public short Parry { get; set; }
public short Defense { get; set; }
public short Evasion { get; set; }
public short MagicDefense { get; set; }
public short SlashingRes { get; set; }
public short PiercingRes { get; set; }
public short BluntRes { get; set; }
public short FireRes { get; set; }
public short IceRes { get; set; }
public short WindRes { get; set; }
public short EarthRes { get; set; }
public short LightningRes { get; set; }
public short WaterRes { get; set; }
#endregion
#region Offensive stats
public short AttackPow { get; set; }
public short Accuracy { get; set; }
public short CritRate { get; set; }
public short AttackMagPot { get; set; }
public short HealMagPot { get; set; }
public short Determination { get; set; }
public short SkillSpeed { get; set; }
public short SpellSpeed { get; set; }
#endregion
#region DoH/DoL stats
public short Craftmanship { get; set; }
public short Control { get; set; }
public short Gathering { get; set; }
public short Perception { get; set; }
#endregion
#region Companion Stats
public int CompanionEil { get; set; }
public byte CompanionLevel { get; set; }
public byte CompanionDefenderLevel { get; set; }
public byte CompanionAttackerLevel { get; set; }
public byte CompanionHealerLevel { get; set; }
#endregion
#region PvP Stats
public byte PvpLevel { get; set; }
public short PvpTotalEXP { get; set; }
public short PvpTotalMatches { get; set; }
public short PvpTotalWins { get; set; }
public short PvpWeeklyMatches { get; set; }
public short PvpWeeklyWins { get; set; }
#endregion
#endregion
#region Methods
/// <summary>
/// Retrieves the ZoneID
/// </summary>
/// <returns>Zone ID</returns>
private int GetZone()
{
IntPtr ptr = MemoryReader.GetInstance().ResolvePointerPath(Constants.ZONEPTR);
return MemoryReader.GetInstance().ReadInt4(ptr);
}
/// <summary>
/// Retrieves the Subzone ID
/// </summary>
/// <returns>Subzone ID or 0</returns>
private int GetSubzone()
{
IntPtr ptr = MemoryReader.GetInstance().ResolvePointerPath(Constants.SUBZONEPTR);
return MemoryReader.GetInstance().ReadInt4(ptr);
}
#endregion
#region Unmanaged structure
[StructLayout(LayoutKind.Explicit, Pack = 1)]
public struct PLAYERINFO
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=33)] [FieldOffset(0x00)] public byte[] MarkName;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x64)] public JOB Job;
#region Job Levels
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x66)] public byte PGL;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x68)] public byte GLD;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x6A)] public byte MRD;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x6C)] public byte ARC;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x6E)] public byte LNC;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x70)] public byte THM;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x72)] public byte CNJ;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x74)] public byte CPT;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x76)] public byte BSM;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x78)] public byte ARM;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x7A)] public byte GSM;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x7C)] public byte LTW;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x7E)] public byte WVR;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x80)] public byte ALC;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x82)] public byte CUL;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x84)] public byte MIN;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x86)] public byte BOT;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x88)] public byte FSH;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x8A)] public byte ACN;
#endregion
#region Job Exp In Level
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x8C)] public int PGL_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x90)] public int GLD_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x94)] public int MRD_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x98)] public int ARC_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x9C)] public int LNC_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xA0)] public int THM_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xA4)] public int CNJ_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xA8)] public int CPT_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xAC)] public int BSM_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xB0)] public int ACN_EIL; // Not sure about that one
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xB4)] public int GSM_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xB8)] public int ARM_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xBC)] public int WVR_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xC0)] public int LTW_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xC4)] public int CUL_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xC8)] public int MIN_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xCC)] public int BOT_EIL;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0xD0)] public int FSH_EIL;
#endregion
#region Base Stats
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0xE4)] public short BaseSTR;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0xE8)] public short BaseDEX;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0xEC)] public short BaseVIT;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0xF0)] public short BaseINT;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0xF4)] public short BaseMND;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0xF8)] public short BasePIE;
#endregion
#region Stats (base+gear+bonus)
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x100)] public short STR;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x104)] public short DEX;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x108)] public short VIT;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x10C)] public short INT;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x110)] public short MND;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x114)] public short PIE;
#endregion
#region Basic infos
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x118)] public int MaxHP;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x11C)] public int MaxMP;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x120)] public int MaxTP;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x124)] public int MaxGP;
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x128)] public int MaxCP;
#endregion
#region Defensive stats
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x148)] public short Parry;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x150)] public short Defense;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x158)] public short Evasion;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x15C)] public short MagicDefense;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x170)] public short SlashingRes;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x174)] public short PiercingRes;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x178)] public short BluntRes;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x190)] public short FireRes;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x194)] public short IceRes;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x198)] public short WindRes;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x19C)] public short EarthRes;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x1A0)] public short LightningRes;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x1A4)] public short WaterRes;
#endregion
#region Offensive stats
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x14C)] public short AttackPow;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x154)] public short Accuracy;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x168)] public short CritRate;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x180)] public short AttackMagPot;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x184)] public short HealMagPot;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x1AC)] public short Determination;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x1B0)] public short SkillSpeed;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x1B4)] public short SpellSpeed;
#endregion
#region DoH/DoL stats
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x214)] public short Craftmanship;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x218)] public short Control;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x21C)] public short Gathering;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x220)] public short Perception;
#endregion
#region Companion stats
[MarshalAs(UnmanagedType.I4)] [FieldOffset(0x5A8)] public int CompanionEil;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x5AC)] public byte CompanionLevel;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x5AE)] public byte CompanionDefenderLevel;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x5AF)] public byte CompanionAttackerLevel;
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x5B0)] public byte CompanionHealerLevel;
#endregion
#region PvP Stats
[MarshalAs(UnmanagedType.I1)] [FieldOffset(0x755)] public byte PvpLevel;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x756)] public short PvpTotalEXP;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x758)] public short PvpTotalMatches;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x75A)] public short PvpTotalWins;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x75C)] public short PvpWeeklyMatches;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(0x75E)] public short PvpWeeklyWins;
#endregion
};
#endregion
}
public partial class FFXIVLIB
{
#region Internal Items
private IntPtr PlayerStructLocation = IntPtr.Zero;
#endregion
#region Public methods
/// <summary>
/// TL;DR : Returns current server, testing, might not work reliably.
/// Longer version : This is set by the Lobby widgets, which no longer exist
/// while in-game, as such the memory space they used can be under some condition
/// garbage collected/wiped.
/// </summary>
/// <returns></returns>
public string GetServerName()
{
IntPtr ptr = _mr.ResolvePointerPath(Constants.SERVERPTR);
byte[] server = ReadMemory(ptr, 32);
string ret = Encoding.UTF8.GetString(server);
return ret.Split('\0')[0];
}
/// <summary>
/// This function retrieves the current Player info
/// </summary>
/// <returns>Player object</returns>
public Player GetPlayerInfo()
{
if (this.PlayerStructLocation == IntPtr.Zero)
{
IntPtr ptr = _ss.SigScan (Constants.PLAYERADDRSIG);
ptr = IntPtr.Add (ptr, Constants.PLAYERADDRSIG.Length);
this.PlayerStructLocation = _mr.ResolvePointer (ptr);
}
var p = new Player (_mr.CreateStructFromAddress<Player.PLAYERINFO> (this.PlayerStructLocation), this.PlayerStructLocation);
return p;
}
public bool PlayerInBattle()
{
IntPtr pointer = _mr.ResolvePointerPath (Constants.PARTYINBATTLEPTR);
byte[] value = ReadMemory (pointer, 1);
return value [0] == 1;
}
public bool PlayerFollowing()
{
//IntPtr pointer = _mr.ResolvePointerPath (Constants.PLAYERFOLLOWINGPTR);
byte[] value = ReadMemory (IntPtr.Zero + Constants.PLAYERFOLLOWINGADDR, 1);
return value[0] == 1;
}
#endregion
}
}