Esempio n. 1
0
        public SkillReader(ProcessMemoryReader reader, GameMemoryTable memory)
        {
            this.reader = reader;

            globals      = reader.Read <D2GlobalData>(reader.ReadAddress32(memory.Address.GlobalData, AddressingMode.Relative));
            stringReader = new StringLookupTable(reader, memory.Address);
        }
Esempio n. 2
0
        public SkillReader(IProcessMemoryReader reader, GameMemoryTable memory)
        {
            this.reader = reader;

            globals      = reader.Read <D2GlobalData>(reader.ReadAddress32(memory.GlobalData));
            stringReader = new StringReader(reader, memory);
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        public StringLookupTable(IProcessMemoryReader reader, GameMemoryTable memory)
        {
            this.reader = reader;
            this.memory = memory;

            Language = DetectLanguage();
            if (!Cache.ContainsKey(Language))
            {
                Cache[Language] = new Dictionary <ushort, string>();
            }
        }
Esempio n. 5
0
 public UnitReader(
     ProcessMemoryReader reader,
     GameMemoryTable memory,
     StringLookupTable stringReader
     )
 {
     this.reader       = reader;
     this.memory       = memory;
     this.stringReader = stringReader;
     skillReader       = new SkillReader(reader, memory);
     inventoryReader   = createInventoryReader();
 }
Esempio n. 6
0
        public ItemReader(ProcessMemoryReader reader, GameMemoryTable memory) : base(reader, memory)
        {
            cachedItemData     = new Dictionary <IntPtr, D2ItemData>();
            cachedDescriptions = new Dictionary <int, D2ItemDescription>();

            globals          = reader.Read <D2GlobalData>(reader.ReadAddress32(memory.Address.GlobalData, AddressingMode.Relative));
            lowQualityTable  = reader.Read <D2SafeArray>(memory.Address.LowQualityItems, AddressingMode.Relative);
            descriptionTable = reader.Read <D2SafeArray>(memory.Address.ItemDescriptions, AddressingMode.Relative);
            magicModifiers   = reader.Read <ModifierTable>(memory.Address.MagicModifierTable, AddressingMode.Relative);
            rareModifiers    = reader.Read <ModifierTable>(memory.Address.RareModifierTable, AddressingMode.Relative);
            skillReader      = new SkillReader(reader, memory);
            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);
                }
            }
        }
Esempio n. 7
0
        public void ShouldDetermineIfNewChar()
        {
            var unit = new D2Unit();

            unit.eClass       = 0;
            unit.actNo        = 0;
            unit.StatListNode = new DataPointer(1);

            var processMemoryReader = new Mock <IProcessMemoryReader>();
            var gameMemoryTable     = new GameMemoryTable();
            var stringReader        = new Mock <IStringReader>().Object;

            var statsList = new D2StatListEx();

            statsList.BaseStats         = new D2StatArray();
            statsList.BaseStats.Address = new DataPointer();
            statsList.ListFlags         = StatListFlag.HasCompleteStats;
            statsList.FullStats         = new D2StatArray();
            statsList.FullStats.Length  = 1;
            statsList.FullStats.Address = new DataPointer();

            processMemoryReader
            .Setup(x => x.Read <D2StatListEx>(
                       It.Is <IntPtr>(p => p.Equals(unit.StatListNode.Address)),
                       It.Is <AddressingMode>(m => m == AddressingMode.Absolute)
                       ))
            .Returns(statsList);

            var lvlStat = new D2Stat();

            lvlStat.LoStatID = (ushort)StatIdentifier.Level;
            lvlStat.Value    = 1;
            var xpStat = new D2Stat();

            xpStat.LoStatID = (ushort)StatIdentifier.Experience;
            xpStat.Value    = 0;

            var d2StatArray = new D2Stat[] { lvlStat, xpStat };

            processMemoryReader
            .Setup(x => x.ReadArray <D2Stat>(
                       It.Is <IntPtr>(p => p.Equals(statsList.FullStats.Address.Address)),
                       It.IsAny <int>(),
                       It.Is <AddressingMode>(m => m == AddressingMode.Absolute)
                       ))
            .Returns <IntPtr, int, AddressingMode>((p, i, m) => i == 0 ? new D2Stat[] { } : d2StatArray);

            // starting items for amazon
            var startingItems = new Item[] {
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x2f
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x148
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x211
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x212
                    }
                },
            };

            var inventoryReader = new Mock <IInventoryReader>();

            inventoryReader
            .Setup(x => x.EnumerateInventoryForward(
                       It.Is <D2Unit>(p => p.Equals(unit))
                       ))
            .Returns(startingItems);

            // starting skills for amazon
            var skillData = new Dictionary <D2Skill, D2SkillData>();

            skillData.Add(new D2Skill(), new D2SkillData {
                SkillId = (uint)Skill.UNKNOWN
            });
            skillData.Add(new D2Skill(), new D2SkillData {
                SkillId = (uint)Skill.THROW
            });
            skillData.Add(new D2Skill(), new D2SkillData {
                SkillId = (uint)Skill.KICK
            });
            skillData.Add(new D2Skill(), new D2SkillData {
                SkillId = (uint)Skill.SCROLL_IDENT
            });
            skillData.Add(new D2Skill(), new D2SkillData {
                SkillId = (uint)Skill.TOME_IDENT
            });
            skillData.Add(new D2Skill(), new D2SkillData {
                SkillId = (uint)Skill.SCROLL_TP
            });
            skillData.Add(new D2Skill(), new D2SkillData {
                SkillId = (uint)Skill.TOME_TP
            });
            skillData.Add(new D2Skill(), new D2SkillData {
                SkillId = (uint)Skill.UNSUMMON
            });

            var skillReader = new Mock <ISkillReader>();

            skillReader
            .Setup(x => x.EnumerateSkills(
                       It.Is <D2Unit>(p => p.Equals(unit))
                       ))
            .Returns(skillData.Keys);
            skillReader
            .Setup(x => x.ReadSkillData(
                       It.Is <D2Skill>(s => skillData.ContainsKey(s))
                       ))
            .Returns <D2Skill>((skill) => skillData[skill]);
            skillReader
            .Setup(x => x.GetTotalNumberOfSkillPoints(
                       It.Is <D2Skill>(s => skillData.ContainsKey(s))
                       ))
            .Returns(1);     // TODO: isnt 1 for all cases. should test other values

            var unitReader = new UnitReader(processMemoryReader.Object, gameMemoryTable, stringReader, skillReader.Object);

            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));

            lvlStat.Value = 2;
            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));
            lvlStat.Value = 1;
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));

            xpStat.Value = 1;
            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));
            xpStat.Value = 0;
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));

            inventoryReader
            .Setup(x => x.EnumerateInventoryForward(
                       It.Is <D2Unit>(p => p.Equals(unit))
                       ))
            .Returns(new Item[] {
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x211
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x212
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x2f
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x148
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
            });

            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));
            inventoryReader
            .Setup(x => x.EnumerateInventoryForward(
                       It.Is <D2Unit>(p => p.Equals(unit))
                       ))
            .Returns(startingItems);
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));

            var skillRaiseSkeleton = new D2Skill();

            skillData.Add(skillRaiseSkeleton, new D2SkillData {
                SkillId = (uint)Skill.RAISE_SKELETON
            });
            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));
            skillData.Remove(skillRaiseSkeleton);
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));

            statsList.FullStats.Length = 0;
            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));
            statsList.FullStats.Length = 5;
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));
            statsList.FullStats.Length = 1;
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skillReader.Object));
        }
Esempio n. 8
0
 public UnitReader(ProcessMemoryReader reader, GameMemoryTable memory)
 {
     this.reader  = reader;
     this.memory  = memory;
     stringReader = new StringLookupTable(reader, memory.Address);
 }
Esempio n. 9
0
        public void ShouldDetermineIfNewChar()
        {
            var unit = new D2Unit();

            unit.eClass       = 0;
            unit.actNo        = 0;
            unit.StatListNode = new DataPointer(1);

            var processMemoryReader = new Mock <IProcessMemoryReader>();
            var gameMemoryTable     = new GameMemoryTable();
            var stringReader        = new Mock <IStringReader>().Object;

            var statsList = new D2StatListEx();

            statsList.BaseStats         = new D2StatArray();
            statsList.BaseStats.Address = new DataPointer();
            statsList.ListFlags         = StatListFlag.HasCompleteStats;
            statsList.FullStats         = new D2StatArray();
            statsList.FullStats.Length  = 1;
            statsList.FullStats.Address = new DataPointer();

            processMemoryReader
            .Setup(x => x.Read <D2StatListEx>(
                       It.Is <IntPtr>(p => p.Equals(unit.StatListNode.Address))
                       ))
            .Returns(statsList);

            var lvlStat = new D2Stat();

            lvlStat.LoStatID = (ushort)StatIdentifier.Level;
            lvlStat.Value    = 1;
            var xpStat = new D2Stat();

            xpStat.LoStatID = (ushort)StatIdentifier.Experience;
            xpStat.Value    = 0;

            var d2StatArray = new D2Stat[] { lvlStat, xpStat };

            processMemoryReader
            .Setup(x => x.ReadArray <D2Stat>(
                       It.Is <IntPtr>(p => p.Equals(statsList.FullStats.Address.Address)),
                       It.IsAny <int>()
                       ))
            .Returns <IntPtr, int>((p, i) => i == 0 ? new D2Stat[] { } : d2StatArray);

            // starting items for amazon
            var startingItems = new Item[] {
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x2f
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x148
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x211
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x212
                    }
                },
            };

            var inventoryReader = new Mock <IInventoryReader>();

            inventoryReader
            .Setup(x => x.EnumerateInventoryForward(
                       It.Is <D2Unit>(p => p.Equals(unit))
                       ))
            .Returns(startingItems);

            var skillReader = new Mock <ISkillReader>();

            // starting skills for amazon
            var skills = new List <SkillInfo>
            {
                new SkillInfo {
                    Id = (uint)Skill.UNKNOWN, Points = 1
                },
                new SkillInfo {
                    Id = (uint)Skill.THROW, Points = 1
                },
                new SkillInfo {
                    Id = (uint)Skill.KICK, Points = 1
                },
                new SkillInfo {
                    Id = (uint)Skill.SCROLL_IDENT, Points = 1
                },
                new SkillInfo {
                    Id = (uint)Skill.TOME_IDENT, Points = 1
                },
                new SkillInfo {
                    Id = (uint)Skill.SCROLL_TP, Points = 1
                },
                new SkillInfo {
                    Id = (uint)Skill.TOME_TP, Points = 1
                },
                new SkillInfo {
                    Id = (uint)Skill.UNSUMMON, Points = 1
                },
            };

            var unitReader = new UnitReader(processMemoryReader.Object, gameMemoryTable, stringReader, skillReader.Object);

            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));

            lvlStat.Value = 2;
            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));
            lvlStat.Value = 1;
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));

            xpStat.Value = 1;
            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));
            xpStat.Value = 0;
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));

            inventoryReader
            .Setup(x => x.EnumerateInventoryForward(
                       It.Is <D2Unit>(p => p.Equals(unit))
                       ))
            .Returns(new Item[] {
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x211
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x212
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x2f
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x148
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
                new Item {
                    Unit = new D2Unit {
                        eClass = 0x24b
                    }
                },
            });

            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));
            inventoryReader
            .Setup(x => x.EnumerateInventoryForward(
                       It.Is <D2Unit>(p => p.Equals(unit))
                       ))
            .Returns(startingItems);
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));

            var skillRaiseSkeleton = new SkillInfo {
                Id = (uint)Skill.RAISE_SKELETON, Points = 0
            };

            skills.Add(skillRaiseSkeleton);
            Assert.AreEqual(false, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));
            skills.Remove(skillRaiseSkeleton);
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));

            statsList.FullStats.Length = 0;
            try
            {
                Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills);
                Assert.Fail();
            } catch (Exception e)
            {
                Assert.AreEqual("Invalid level", e.Message);
            }
            statsList.FullStats.Length = 5;
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));
            statsList.FullStats.Length = 1;
            Assert.AreEqual(true, Character.DetermineIfNewChar(unit, unitReader, inventoryReader.Object, skills));
        }
Esempio n. 10
0
 public InventoryReader(ProcessMemoryReader reader, GameMemoryTable memory)
 {
     processReader = reader;
     this.memory   = memory;
     itemReader    = new ItemReader(processReader, memory);
 }