dxbydt

Untitled

Jun 28th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.99 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using PoeHUD.Poe.FilesInMemory;
  5. using PoeHUD.Poe.RemoteMemoryObjects;
  6. using PoeHUD.Controllers;
  7. using PoeHUD.Models.Attributes;
  8. using System.Linq;
  9.  
  10. namespace PoeHUD.Poe.Components
  11. {
  12.     public class Player : Component
  13.     {
  14.         public string PlayerName => GetObject<NativeStringReader>(Address + 0x58).Value;
  15.  
  16.         public uint XP => Address != 0 ? M.ReadUInt(Address + 0x80) : 0;
  17.         public int Strength => Address != 0 ? M.ReadInt(Address + 0x84) : 0;
  18.         public int Dexterity => Address != 0 ? M.ReadInt(Address + 0x88) : 0;
  19.         public int Intelligence => Address != 0 ? M.ReadInt(Address + 0x8C) : 0;
  20.         public int Level => Address != 0 ? M.ReadByte(Address + 0x90) : 1;
  21.         public int AllocatedLootId => Address != 0 ? M.ReadByte(Address + 0x7C) : 1;
  22.  
  23.         public int HideoutLevel => M.ReadByte(Address + 0x28E);
  24.         public HideoutWrapper Hideout => ReadObject<HideoutWrapper>(Address + 0x268);
  25.  
  26.         public PantheonGod PantheonMinor => (PantheonGod)M.ReadByte(Address + 0x93);
  27.         public PantheonGod PantheonMajor => (PantheonGod)M.ReadByte(Address + 0x94);
  28.  
  29.         #region Prophecy
  30.         public byte PropheciesCount => M.ReadByte(Address + 0x112);
  31.  
  32.         //How to fix prophecies:
  33.         //PropheciesCount is ez to find (use Structure Spider Advanced)
  34.         //Prophecies reading offset:
  35.         //seek some prophecy, find it in GameFiles.Prophecies.List (qvin debug plugin), read it's id and search it in Structure Spider Advanced
  36.         //Fx prophecy The Cursed Choir has ProphecyId 18633 (use Id, not prophecy index!)
  37.         //Prophecies offset goes directly after PropheciesCount offset, maybe 1 byte distance.
  38.         public List<ProphecyDat> Prophecies
  39.         {
  40.             get
  41.             {
  42.                 var result = new List<ProphecyDat>();
  43.                 var readAddr = Address + 0x114;
  44.  
  45.                 for (int i = 0; i < 7; i++)
  46.                 {
  47.                     var prophecyId = M.ReadUShort(readAddr);
  48.                     //if(prophacyId > 0)//Dunno why it will never be 0 even if there is no prophecy
  49.                     {
  50.                         var prophecy = GameController.Instance.Files.Prophecies.GetProphecyById(prophecyId);
  51.                         //if (prophecy != null)
  52.                             result.Add(prophecy);
  53.                     }
  54.                     readAddr += 4;//prophecy prophecyId(UShort), Skip index(byte), Skip unknown(byte)
  55.                 }
  56.                 return result;
  57.             }
  58.         }
  59.         #endregion
  60.         #region Passives
  61.         public List<PassiveSkill> AllocatedPassives
  62.         {
  63.             get
  64.             {
  65.                 var result = new List<PassiveSkill>();
  66.                 var passiveIds = GameController.Instance.Game.IngameState.ServerData.PassiveSkillIds;
  67.  
  68.                 foreach(var id in passiveIds)
  69.                 {
  70.                     var passive = GameController.Instance.Files.PassiveSkills.GetPassiveSkillByPassiveId(id);
  71.                     if(passive == null)
  72.                     {
  73.                         DebugPlug.DebugPlugin.LogMsg($"Can't find passive with id: {id}", 10, SharpDX.Color.Red);
  74.                         continue;
  75.                     }
  76.                     result.Add(passive);
  77.                 }
  78.                 return result;
  79.             }
  80.         }
  81.         #endregion
  82.         #region Trials
  83.         public bool IsTrialCompleted(string trialId)
  84.         {
  85.             var trialWrapper = GameController.Instance.Files.LabyrinthTrials.GetLabyrinthTrialByAreaId(trialId);
  86.             if(trialWrapper == null)
  87.                 throw new ArgumentException($"Trial with id '{trialId}' is not found. Use WorldArea.Id or LabyrinthTrials.LabyrinthTrialAreaIds[]");
  88.  
  89.             return TrialPassStates.Get(trialWrapper.Id - 1);
  90.         }
  91.         public bool IsTrialCompleted(LabyrinthTrial trialWrapper)
  92.         {
  93.             if (trialWrapper == null)
  94.                 throw new ArgumentException($"Argument {nameof(trialWrapper)} should not be null");
  95.  
  96.             return TrialPassStates.Get(trialWrapper.Id - 1);
  97.         }
  98.         public bool IsTrialCompleted(WorldArea area)
  99.         {
  100.             if (area == null)
  101.                 throw new ArgumentException($"Argument {nameof(area)} should not be null");
  102.  
  103.             var trialWrapper = GameController.Instance.Files.LabyrinthTrials.GetLabyrinthTrialByArea(area);
  104.  
  105.             if (trialWrapper == null)
  106.                 throw new ArgumentException($"Can't find trial wrapper for area '{area.Name}' (seems not a trial area).");
  107.  
  108.             return TrialPassStates.Get(trialWrapper.Id - 1);
  109.         }
  110.  
  111.         /*
  112.          How to fix TrialPassStates offsets. Detailed example.
  113.  
  114.         Update. New way: Uncomment argument (StaticOffsetFieldDebugAttribute) from:
  115.         public static int DebugPlayerTrialStates
  116.         Use "Qvin Debug Tree" plugin. Change slider DebugPlayerTrialStates to pick the right offset. Convert slider number to hex
  117.            
  118.         Old way:
  119.          Better to use ReClass.Net for that (or program that can show bits of byte on some offset)
  120.          Go to some uncompleted trial but do not activate it!
  121.          Open ReClass on Player component address (get it from "Qvin Debug Tree" (QDT) plugin)
  122.          Scroll to offset near (0x180) (Use "Add bytes->2048" command to increase view range).
  123.          Switch all next data to display as bits (better to switch them to Hex8 first, then to bits, to see bits of each byte on a new line)
  124.          Detect which bit is changed after activating trial (make 2 screenshots then compare)
  125.          In my case I got this:
  126.             0x180:  11000000
  127.             0x181:  01111111
  128.             after activating "The Bath House" trial:
  129.             0x180:  11000000
  130.             0x181:  11111111   <<here
  131.         so after activating trial the last (8) bit of 0x181 byte was changed (count bits from right to left).
  132.         Open in QDT GameController->Files->LabyrinthTrials->EntriesList. Here we can see that area Id of "The Bath House" trial is 272
  133.         So the 8th bit of 0x181 byte is "The Bath House" trial
  134.         The first trial (Lower Prison) id is 263 (at this moment), so Bath House is 272-263= 9th bit from our data bits,
  135.  
  136.         Byte have 8 bits (yes, obviously), so we going to start read bytes array data from 0x180 (ignoring first 7 bits)
  137.         And to simplify it we will read whole array (286 bits (as 286 is the last trial area id) = 35,75(36) bytes).
  138.         So 263 - 7(skipped) = 256.  256/8bits = 0x20 back from 0x180. So 0x180 - 0x20 = 0x160. Read offset is 0x160
  139.         */
  140.  
  141.         //[StaticOffsetFieldDebugAttribute]
  142.         public static int DebugPlayerTrialStates = 0x17E;
  143.  
  144.         [HideInReflection]//Comment this attribute to see it in "Qvin Debug Tree" plugin.
  145.         private BitArray TrialPassStates
  146.         {
  147.             get
  148.             {
  149.                 var stateBuff = M.ReadBytes(Address + DebugPlayerTrialStates, 36);// (286+) bytes of info.
  150.                 return new BitArray(stateBuff);
  151.             }
  152.         }
  153.  
  154.         #region Debug things
  155.  
  156.         public List<TrialState> TrialStates
  157.         {
  158.             get
  159.             {
  160.                 var result = new List<TrialState>();
  161.                 var passStates = TrialPassStates;
  162.                 foreach (var trialAreaId in LabyrinthTrials.LabyrinthTrialAreaIds)
  163.                 {
  164.                     var wrapper = GameController.Instance.Files.LabyrinthTrials.GetLabyrinthTrialByAreaId(trialAreaId);
  165.                     result.Add(new TrialState { TrialAreaId = trialAreaId, TrialArea = wrapper, IsCompleted = passStates.Get(wrapper.Id - 1) });
  166.                 }
  167.                 return result;
  168.             }
  169.         }
  170.        
  171.         public class TrialState
  172.         {
  173.             public LabyrinthTrial TrialArea { get; internal set; }
  174.             public string TrialAreaId { get; internal set; }
  175.             public bool IsCompleted { get; internal set; }
  176.             public string AreaAddr => TrialArea.Address.ToString("x");
  177.  
  178.             public override string ToString()
  179.             {
  180.                 return $"Completed: {IsCompleted}, {TrialArea.Area.Name}";//, TrialAreaId: {TrialAreaId}
  181.             }
  182.         }
  183.         #endregion
  184.         #endregion
  185.  
  186.         public override string ToString()
  187.         {
  188.             return $"{PlayerName} ({Level})";
  189.         }
  190.  
  191.         /*//TODO fixme https://pathofexile.gamepedia.com/Master
  192.         #region Master Exp Levels
  193.         public uint CurrentExperienceTora => M.ReadUInt(Address + 0x198);
  194.         public uint CurrentExperienceVorici => M.ReadUInt(Address + 0x188);
  195.         public uint CurrentExperienceCatarina => M.ReadUInt(Address + 0x1a8);
  196.         public uint CurrentExperienceZana => M.ReadUInt(Address + 0x1b8);
  197.         public uint CurrentExperienceVagan => M.ReadUInt(Address + 0x1c8);
  198.         public uint CurrentExperienceElreon => M.ReadUInt(Address + 0x1d8);
  199.         public uint CurrentExperienceHaku => M.ReadUInt(Address + 0x1e8);
  200.         public uint CurrentExperienceLeo => M.ReadUInt(Address + 0x1f8);
  201.  
  202.         public int CurrentLevelTora => Constants.GetLevel(Constants.ToraExperienceLevels, CurrentExperienceVorici);
  203.         public int CurrentLevelVorici => Constants.GetLevel(Constants.VoriciExperienceLevels, CurrentExperienceVorici);
  204.         public int CurrentLevelCatarina => Constants.GetLevel(Constants.CatarinaExperienceLevels, CurrentExperienceVorici);
  205.         public int CurrentLevelZana => Constants.GetLevel(Constants.ZanaExperienceLevels, CurrentExperienceVorici);
  206.         public int CurrentLevelVagan => Constants.GetLevel(Constants.VaganExperienceLevels, CurrentExperienceVorici);
  207.         public int CurrentLevelElreon => Constants.GetLevel(Constants.ElreonExperienceLevels, CurrentExperienceVorici);
  208.         public int CurrentLevelHaku => Constants.GetLevel(Constants.HakuExperienceLevels, CurrentExperienceVorici);
  209.         public int CurrentLevelLeo => Constants.GetLevel(Constants.LeoExperienceLevels, CurrentExperienceVorici);
  210.  
  211.         public uint CurrentFullLevelTora => Constants.GetFullCurrentLevel(Constants.ToraExperienceLevels, CurrentExperienceVorici);
  212.         public uint CurrentFullLevelVorici => Constants.GetFullCurrentLevel(Constants.VoriciExperienceLevels, CurrentExperienceVorici);
  213.         public uint CurrentFullLevelCatarina => Constants.GetFullCurrentLevel(Constants.CatarinaExperienceLevels, CurrentExperienceVorici);
  214.         public uint CurrentFullLevelZana => Constants.GetFullCurrentLevel(Constants.ZanaExperienceLevels, CurrentExperienceVorici);
  215.         public uint CurrentFullLevelVagan => Constants.GetFullCurrentLevel(Constants.VaganExperienceLevels, CurrentExperienceVorici);
  216.         public uint CurrentFullLevelElreon => Constants.GetFullCurrentLevel(Constants.ElreonExperienceLevels, CurrentExperienceVorici);
  217.         public uint CurrentFullLevelHaku => Constants.GetFullCurrentLevel(Constants.HakuExperienceLevels, CurrentExperienceVorici);
  218.         public uint CurrentFullLevelLeo => Constants.GetFullCurrentLevel(Constants.LeoExperienceLevels, CurrentExperienceVorici);
  219.         #endregion
  220.         */
  221.  
  222.         public enum PantheonGod
  223.         {
  224.             None,
  225.             TheBrineKing,
  226.             Arakaali,
  227.             Solaris,
  228.             Lunaris,
  229.             MinorGod1,
  230.             MinorGod2,
  231.             Abberath,
  232.             MinorGod4,
  233.             Gruthkul,
  234.             Yugul,
  235.             Shakari,
  236.             Tukohama,
  237.             MinorGod9,
  238.             Ralakesh,
  239.             Garukhan,
  240.             Ryslatha
  241.         }
  242.     }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment