void UpdateName(ProcessMemoryAccessor accessor) { if (accessor == null) { throw new ArgumentNullException("accessor"); } string name = null; if (version != null && version.ContainsVariable(CharacterNameKey)) { Debug.WriteLine($"Updating character name (pid={accessor.ProcessId})..."); Stream stream = null; try { stream = accessor.GetStream(); using (var reader = new BinaryReader(stream, Encoding.ASCII)) { stream = null; var nameVariable = version.GetVariable(CharacterNameKey); nameVariable.TryReadString(reader, out name); } } finally { stream?.Dispose(); } Debug.WriteLine($"CharacterName = {name}"); } if (!string.IsNullOrWhiteSpace(name)) { Name = name; } }
public void Update(ProcessMemoryAccessor accessor) { if (accessor == null) { throw new ArgumentNullException("accessor"); } var version = this.Owner.Version; if (version == null) { ResetDefaults(); return; } var equipmentVariable = version.GetVariable(EquipmentKey); if (equipmentVariable == null) { ResetDefaults(); return; } Debug.WriteLine($"Updating equipment (pid={accessor.ProcessId})..."); Stream stream = null; try { stream = accessor.GetStream(); using (var reader = new BinaryReader(stream, Encoding.ASCII)) { stream = null; var equipmentPointer = equipmentVariable.DereferenceValue(reader); if (equipmentPointer == 0) { ResetDefaults(); return; } reader.BaseStream.Position = equipmentPointer; for (int i = 0; i < equipmentVariable.Count; i++) { try { string name = reader.ReadFixedString(equipmentVariable.MaxLength); equipment[i].IsEmpty = string.IsNullOrWhiteSpace(name); equipment[i].IconIndex = 0; equipment[i].Name = name.StripNumbers(); } catch { } } } } finally { stream?.Dispose(); } }
public void Update(ProcessMemoryAccessor accessor) { if (accessor == null) { throw new ArgumentNullException("accessor"); } var version = this.Owner.Version; if (version == null) { ResetDefaults(); return; } var inventoryVariable = version.GetVariable(InventoryKey); if (inventoryVariable == null) { ResetDefaults(); return; } Debug.WriteLine($"Updating inventory (pid={accessor.ProcessId})..."); Stream stream = null; try { stream = accessor.GetStream(); using (var reader = new BinaryReader(stream, Encoding.ASCII)) { stream = null; var inventoryPointer = inventoryVariable.DereferenceValue(reader); if (inventoryPointer == 0) { ResetDefaults(); return; } reader.BaseStream.Position = inventoryPointer; for (int i = 0; i < inventoryVariable.Count; i++) { try { bool hasItem = reader.ReadInt16() != 0; ushort iconIndex = reader.ReadUInt16(); reader.ReadByte(); string name = reader.ReadFixedString(inventoryVariable.MaxLength); reader.ReadByte(); inventory[i].IsEmpty = !hasItem; inventory[i].IconIndex = iconIndex; inventory[i].Name = name.StripNumbers(); if (!inventory[i].IsEmpty) { Debug.WriteLine($"Inventory slot {i + 1}: {inventory[i].Name} (icon={inventory[i].IconIndex.ToString("X")})"); } } catch { } } } } finally { stream?.Dispose(); } }
public void Update(ProcessMemoryAccessor accessor) { if (accessor == null) { throw new ArgumentNullException("accessor"); } var version = Owner.Version; if (version == null) { ResetDefaults(); return; } var currentHealthVariable = version.GetVariable(CurrentHealthKey); var maximumHealthVariable = version.GetVariable(MaximumHealthKey); var currentManaVariable = version.GetVariable(CurrentManaKey); var maximumManaVariable = version.GetVariable(MaximumManaKey); var levelVariable = version.GetVariable(LevelKey); var abilityLevelVariable = version.GetVariable(AbilityLevelKey); long currentHealth, maximumHealth; long currentMana, maximumMana; long level, abilityLevel; Debug.WriteLine($"Updating stats (pid={accessor.ProcessId})..."); Stream stream = null; try { stream = accessor.GetStream(); using (var reader = new BinaryReader(stream, Encoding.ASCII)) { stream = null; // Current Health if (currentHealthVariable != null && currentHealthVariable.TryReadIntegerString(reader, out currentHealth)) { CurrentHealth = (int)currentHealth; } else { CurrentHealth = 0; } // Max Health if (maximumHealthVariable != null && maximumHealthVariable.TryReadIntegerString(reader, out maximumHealth)) { MaximumHealth = (int)maximumHealth; } else { MaximumHealth = 0; } // Current Mana if (currentManaVariable != null && currentManaVariable.TryReadIntegerString(reader, out currentMana)) { CurrentMana = (int)currentMana; } else { CurrentMana = 0; } // Max Mana if (maximumManaVariable != null && maximumManaVariable.TryReadIntegerString(reader, out maximumMana)) { MaximumMana = (int)maximumMana; } else { MaximumMana = 0; } // Level if (levelVariable != null && levelVariable.TryReadIntegerString(reader, out level)) { Level = (int)level; } else { Level = 0; } // Ability Level if (abilityLevelVariable != null && abilityLevelVariable.TryReadIntegerString(reader, out abilityLevel)) { AbilityLevel = (int)abilityLevel; } else { AbilityLevel = 0; } } } finally { stream?.Dispose(); } Debug.WriteLine($"CurrentHealth = {CurrentHealth}"); Debug.WriteLine($"MaximumHealth = {MaximumHealth}"); Debug.WriteLine($"CurrentMana = {CurrentMana}"); Debug.WriteLine($"MaximumMana = {MaximumMana}"); Debug.WriteLine($"Level = { Level}"); Debug.WriteLine($"AbilityLevel = {AbilityLevel}"); }
public void Update(ProcessMemoryAccessor accessor) { if (accessor == null) { throw new ArgumentNullException("accessor"); } var version = Owner.Version; if (version == null) { ResetDefaults(); return; } var spellbookVariable = version.GetVariable(SpellbookKey); if (spellbookVariable == null) { ResetDefaults(); return; } Debug.WriteLine($"Updating spellbook (pid={accessor.ProcessId})..."); Stream stream = null; try { stream = accessor.GetStream(); using (var reader = new BinaryReader(stream, Encoding.ASCII)) { stream = null; var spellbookPointer = spellbookVariable.DereferenceValue(reader); if (spellbookPointer == 0) { ResetDefaults(); return; } reader.BaseStream.Position = spellbookPointer; bool foundFasSpiorad = false; bool foundLyliacVineyard = false; bool foundLyliacPlant = false; for (int i = 0; i < spellbookVariable.Count; i++) { SpellMetadata metadata = null; try { bool hasSpell = reader.ReadInt16() != 0; ushort iconIndex = reader.ReadUInt16(); SpellTargetMode targetMode = (SpellTargetMode)reader.ReadByte(); string name = reader.ReadFixedString(spellbookVariable.MaxLength); string prompt = reader.ReadFixedString(spellbookVariable.MaxLength); reader.ReadByte(); int currentLevel, maximumLevel; if (!Ability.TryParseLevels(name, out name, out currentLevel, out maximumLevel)) { if (!string.IsNullOrWhiteSpace(name)) { spells[i].Name = name.Trim(); } } spells[i].IsEmpty = !hasSpell; spells[i].IconIndex = iconIndex; spells[i].Icon = IconManager.Instance.GetSpellIcon(iconIndex); spells[i].TargetMode = targetMode; spells[i].Name = name; spells[i].Prompt = prompt; spells[i].CurrentLevel = currentLevel; spells[i].MaximumLevel = maximumLevel; if (!spells[i].IsEmpty && !string.IsNullOrWhiteSpace(spells[i].Name)) { metadata = SpellMetadataManager.Instance.GetSpell(name); } spells[i].IsActive = this.IsActive(spells[i].Name); foundFasSpiorad |= string.Equals(spells[i].Name, Spell.FasSpioradKey, StringComparison.OrdinalIgnoreCase); foundLyliacPlant |= string.Equals(spells[i].Name, Spell.LyliacPlantKey, StringComparison.OrdinalIgnoreCase); foundLyliacVineyard |= string.Equals(spells[i].Name, Spell.LyliacVineyardKey, StringComparison.OrdinalIgnoreCase); if (metadata != null) { spells[i].NumberOfLines = metadata.NumberOfLines; spells[i].ManaCost = metadata.ManaCost; spells[i].Cooldown = metadata.Cooldown; spells[i].CanImprove = metadata.CanImprove; DateTime timestamp = DateTime.MinValue; if (spells[i].Cooldown > TimeSpan.Zero && spellCooldownTimestamps.TryGetValue(name, out timestamp)) { var elapsed = DateTime.Now - timestamp; spells[i].IsOnCooldown = elapsed < (spells[i].Cooldown + TimeSpan.FromMilliseconds(500)); } } else { spells[i].NumberOfLines = 1; spells[i].ManaCost = 0; spells[i].Cooldown = TimeSpan.Zero; spells[i].CanImprove = true; spells[i].IsOnCooldown = false; } if (!spells[i].IsEmpty) { Debug.WriteLine($"Spell slot {i + 1}: {spells[i].Name} (cur={spells[i].CurrentLevel}, max={spells[i].MaximumLevel}, lines={spells[i].NumberOfLines}, icon={spells[i].IconIndex})"); } } catch { } } owner.HasFasSpiorad = foundFasSpiorad; owner.HasLyliacPlant = foundLyliacPlant; owner.HasLyliacVineyard = foundLyliacVineyard; } } finally { stream?.Dispose(); } }
public void Update(ProcessMemoryAccessor accessor) { if (accessor == null) { throw new ArgumentNullException("accessor"); } var version = Owner.Version; if (version == null) { ResetDefaults(); return; } var mapNumberVariable = version.GetVariable(MapNumberKey); var mapXVariable = version.GetVariable(MapXKey); var mapYVariable = version.GetVariable(MapYKey); var mapNameVariable = version.GetVariable(MapNameKey); int mapNumber; int mapX, mapY; string mapName; Debug.WriteLine($"Updating map location (pid={accessor.ProcessId})..."); Stream stream = null; try { stream = accessor.GetStream(); using (var reader = new BinaryReader(stream, Encoding.ASCII)) { stream = null; if (mapNumberVariable != null && mapNumberVariable.TryReadInt32(reader, out mapNumber)) { MapNumber = mapNumber; } else { MapNumber = 0; } if (mapXVariable != null && mapXVariable.TryReadInt32(reader, out mapX)) { X = mapX; } else { X = 0; } if (mapYVariable != null && mapYVariable.TryReadInt32(reader, out mapY)) { Y = mapY; } else { Y = 0; } if (mapNameVariable != null && mapNameVariable.TryReadString(reader, out mapName)) { MapName = mapName; } else { MapName = null; } } } finally { stream?.Dispose(); } Debug.WriteLine($"MapNumber = {MapNumber}"); Debug.WriteLine($"MapName = {MapName}"); Debug.WriteLine($"X = {X}"); Debug.WriteLine($"Y = {Y}"); }
public void Update(ProcessMemoryAccessor accessor) { if (accessor == null) { throw new ArgumentNullException("accessor"); } var version = Owner.Version; if (version == null) { ResetDefaults(); return; } var skillbookVariable = version.GetVariable(SkillbookKey); if (skillbookVariable == null) { ResetDefaults(); return; } Debug.WriteLine($"Updating skillbok (pid={accessor.ProcessId})..."); Stream stream = null; try { stream = accessor.GetStream(); using (var reader = new BinaryReader(stream, Encoding.ASCII)) { stream = null; var skillbookPointer = skillbookVariable.DereferenceValue(reader); if (skillbookPointer == 0) { ResetDefaults(); return; } reader.BaseStream.Position = skillbookPointer; for (int i = 0; i < skillbookVariable.Count; i++) { SkillMetadata metadata = null; try { bool hasSkill = reader.ReadInt16() != 0; ushort iconIndex = reader.ReadUInt16(); string name = reader.ReadFixedString(skillbookVariable.MaxLength); int currentLevel, maximumLevel; if (!Ability.TryParseLevels(name, out name, out currentLevel, out maximumLevel)) { if (!string.IsNullOrWhiteSpace(name)) { skills[i].Name = name.Trim(); } } skills[i].IsEmpty = !hasSkill; skills[i].IconIndex = iconIndex; skills[i].Icon = IconManager.Instance.GetSkillIcon(iconIndex); skills[i].Name = name; skills[i].CurrentLevel = currentLevel; skills[i].MaximumLevel = maximumLevel; if (!skills[i].IsEmpty && !string.IsNullOrWhiteSpace(skills[i].Name)) { metadata = SkillMetadataManager.Instance.GetSkill(name); } var isActive = this.IsActive(skills[i].Name); skills[i].IsActive = isActive.HasValue && isActive.Value; if (metadata != null) { skills[i].Cooldown = metadata.Cooldown; skills[i].ManaCost = metadata.ManaCost; skills[i].CanImprove = metadata.CanImprove; skills[i].IsAssail = metadata.IsAssail; skills[i].OpensDialog = metadata.OpensDialog; skills[i].RequiresDisarm = metadata.RequiresDisarm; } else { skills[i].Cooldown = TimeSpan.Zero; skills[i].ManaCost = 0; skills[i].CanImprove = true; skills[i].IsAssail = false; skills[i].OpensDialog = false; skills[i].RequiresDisarm = false; } skills[i].IsOnCooldown = IsSkillOnCooldown(i, version, reader); if (!skills[i].IsEmpty) { Debug.WriteLine($"Skill slot {i + 1}: {skills[i].Name} (cur={skills[i].CurrentLevel}, max={skills[i].MaximumLevel}, icon={skills[i].IconIndex})"); } } catch { } } } } finally { stream?.Dispose(); } }
public void Update(ProcessMemoryAccessor accessor) { if (accessor == null) { throw new ArgumentNullException("accessor"); } var version = Owner.Version; if (version == null) { ResetDefaults(); return; } var activePanelVariable = version.GetVariable(ActivePanelKey); var inventoryExpandedVariable = version.GetVariable(InventoryExpandedKey); var minimizedModeVariable = version.GetVariable(MinimizedModeKey); var dialogOpenVariable = version.GetVariable(DialogOpenKey); var senseOpenVariable = version.GetVariable(SenseOpenKey); var userChattingVariable = version.GetVariable(UserChattingKey); byte activePanelByte; bool isInventoryExpanded; bool isMinimizedMode; bool isDialogOpen; bool isUserChatting; Debug.WriteLine($"Updating client state (pid={accessor.ProcessId})..."); Stream stream = null; try { stream = accessor.GetStream(); using (var reader = new BinaryReader(stream, Encoding.ASCII)) { stream = null; if (activePanelVariable != null && activePanelVariable.TryReadByte(reader, out activePanelByte)) { ActivePanel = (InterfacePanel)activePanelByte; } else { ActivePanel = InterfacePanel.Unknown; } if (inventoryExpandedVariable != null && inventoryExpandedVariable.TryReadBoolean(reader, out isInventoryExpanded)) { IsInventoryExpanded = isInventoryExpanded; } else { IsInventoryExpanded = false; } if (minimizedModeVariable != null && minimizedModeVariable.TryReadBoolean(reader, out isMinimizedMode)) { IsMinimizedMode = isMinimizedMode; } else { IsMinimizedMode = false; } if (dialogOpenVariable != null && dialogOpenVariable.TryReadBoolean(reader, out isDialogOpen)) { IsDialogOpen = isDialogOpen; } else { IsDialogOpen = false; } if (senseOpenVariable != null && senseOpenVariable.TryReadBoolean(reader, out isSenseOpen)) { IsSenseOpen = isSenseOpen; } else { IsSenseOpen = false; } if (userChattingVariable != null && userChattingVariable.TryReadBoolean(reader, out isUserChatting)) { IsUserChatting = isUserChatting; } else { IsUserChatting = false; } } } finally { stream?.Dispose(); } Debug.WriteLine($"ActivePanel = {ActivePanel}"); Debug.WriteLine($"IsInventoryExpanded = {IsInventoryExpanded}"); Debug.WriteLine($"IsMinimizedMode = {IsMinimizedMode}"); Debug.WriteLine($"IsDialogOpen = {IsDialogOpen}"); Debug.WriteLine($"IsSenseOpen = {IsSenseOpen}"); Debug.WriteLine($"IsUserChatting = {IsUserChatting}"); }