예제 #1
0
        public UnitReader(
            IProcessMemoryReader reader,
            GameMemoryTable memory,
            IStringReader stringReader,
            ISkillReader skillReader
            )
        {
            this.reader       = reader;
            this.stringReader = stringReader;
            this.skillReader  = skillReader;

            cachedItemData     = new Dictionary <IntPtr, D2ItemData>();
            cachedDescriptions = new Dictionary <int, D2ItemDescription>();

            globals          = reader.Read <D2GlobalData>(reader.ReadAddress32(memory.GlobalData));
            lowQualityTable  = reader.Read <D2SafeArray>(memory.LowQualityItems);
            descriptionTable = reader.Read <D2SafeArray>(memory.ItemDescriptions);
            magicModifiers   = reader.Read <ModifierTable>(memory.MagicModifierTable);
            rareModifiers    = reader.Read <ModifierTable>(memory.RareModifierTable);
            if (globals != null)
            {
                opNestings = reader.ReadArray <ushort>(globals.OpStatNesting, (int)globals.OpStatNestingCount);

                if (ItemStatCost == null && !globals.ItemStatCost.IsNull)
                {
                    ItemStatCost = reader.ReadArray <D2ItemStatCost>(globals.ItemStatCost, (int)globals.ItemStatCostCount);
                }
            }
        }
예제 #2
0
 void CleanUpDataReaders()
 {
     reader?.Dispose();
     reader          = null;
     memory          = null;
     inventoryReader = null;
     unitReader      = null;
     skillReader     = null;
 }
예제 #3
0
        void CreateReaders()
        {
            stringReader = new StringReader(reader, memory);
            skillReader  = new SkillReader(reader, memory);

            // note: readers need to be recreated everytime before read.. at least unitReader
            // unitReader fails sometimes... if this is not done .. why? not sure yet ~_~
            unitReader      = new UnitReader(reader, memory, stringReader, skillReader);
            inventoryReader = new InventoryReader(reader, unitReader);
        }
예제 #4
0
 public static bool IsNewChar(
     D2Unit unit,
     UnitReader unitReader,
     IInventoryReader inventoryReader,
     ISkillReader skillReader
     )
 {
     return(MatchesStartingProps(unit, unitReader) &&
            MatchesStartingItems(unit, inventoryReader) &&
            MatchesStartingSkills(unit, skillReader));
 }
예제 #5
0
        internal void Parse(
            D2Unit unit,
            UnitReader unitReader,
            ISkillReader skillReader,
            IProcessMemoryReader reader,
            GameInfo gameInfo
            )
        {
            var monsterData = unitReader.GetMonsterData(unit);

            Name = reader.ReadNullTerminatedString(monsterData.szMonName, 300, System.Text.Encoding.Unicode);

            Class = unit.eClass;

            var skillIds = new List <uint>();

            foreach (var skill in skillReader.EnumerateSkills(unit))
            {
                var d = skillReader.ReadSkillData(skill);
                skillIds.Add(d.SkillId);
            }
            SkillIds = skillIds;

            var data = unitReader.GetStatsMap(unit);

            int penalty = ResistancePenalty.GetPenaltyByGame(gameInfo.Game);

            int ValueByStatID(Dictionary <StatIdentifier, D2Stat> d, StatIdentifier statID)
            {
                // Get the value if if the key exists, else assume zero.
                return(d.TryGetValue(statID, out D2Stat stat) ? stat.Value : 0);
            }

            int getStat(StatIdentifier statID) => ValueByStatID(data, statID);

            Level      = getStat(StatIdentifier.Level);
            Experience = getStat(StatIdentifier.Experience);

            Strength  = getStat(StatIdentifier.Strength);
            Dexterity = getStat(StatIdentifier.Dexterity);

            int maxFire      = BASE_MAX_RESIST + getStat(StatIdentifier.ResistFireMax);
            int maxCold      = BASE_MAX_RESIST + getStat(StatIdentifier.ResistColdMax);
            int maxLightning = BASE_MAX_RESIST + getStat(StatIdentifier.ResistLightningMax);
            int maxPoison    = BASE_MAX_RESIST + getStat(StatIdentifier.ResistPoisonMax);

            FireResist      = Utility.Clamp(getStat(StatIdentifier.ResistFire) + penalty, MIN_RESIST, maxFire);
            ColdResist      = Utility.Clamp(getStat(StatIdentifier.ResistCold) + penalty, MIN_RESIST, maxCold);
            LightningResist = Utility.Clamp(getStat(StatIdentifier.ResistLightning) + penalty, MIN_RESIST, maxLightning);
            PoisonResist    = Utility.Clamp(getStat(StatIdentifier.ResistPoison) + penalty, MIN_RESIST, maxPoison);
        }
예제 #6
0
        private static List <SkillInfo> ReadSkillInfos(D2Unit p, ISkillReader skillReader)
        {
            var skills = new List <SkillInfo>();

            foreach (var skill in skillReader.EnumerateSkills(p))
            {
                var skillData = skillReader.ReadSkillData(skill);
                var skillInfo = new SkillInfo
                {
                    Id     = skillData.SkillId,
                    Points = skillReader.GetTotalNumberOfSkillPoints(skill),
                };
                skills.Add(skillInfo);
            }
            return(skills);
        }
예제 #7
0
        private static bool MatchesStartingSkills(D2Unit p, ISkillReader skillReader)
        {
            int skillCount = 0;

            foreach (D2Skill skill in skillReader.EnumerateSkills(p))
            {
                var   skillData = skillReader.ReadSkillData(skill);
                Skill skillId   = (Skill)skillData.SkillId;
                if (!StartingSkills[(CharacterClass)p.eClass].ContainsKey(skillId))
                {
                    return(false);
                }

                if (StartingSkills[(CharacterClass)p.eClass][skillId] != skillReader.GetTotalNumberOfSkillPoints(skill))
                {
                    return(false);
                }
                skillCount++;
            }

            return(skillCount == StartingSkills[(CharacterClass)p.eClass].Count);
        }
예제 #8
0
 public static bool DetermineIfNewChar(
     D2Unit unit,
     UnitReader unitReader,
     IInventoryReader inventoryReader,
     ISkillReader skillReader
     )
 {
     if (!MatchesStartingProps(unit, unitReader))
     {
         Logger.Info("Starting Props don't match");
         return(false);
     }
     if (!MatchesStartingItems(unit, inventoryReader))
     {
         Logger.Info("Starting Items don't match");
         return(false);
     }
     if (!MatchesStartingSkills(unit, skillReader))
     {
         Logger.Info("Starting Skills don't match");
         return(false);
     }
     return(true);
 }
예제 #9
0
 public SkillLoader(ISkillReader reader)
 {
     _reader = reader;
 }
예제 #10
0
 public SkillLoader(ISkillReader reader)
 {
     _reader = reader;
 }