private void HandleMessageReceived(Message obj) { var message = _messageFactory.Create(obj); _entityRegistry.Update(message); var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { _damageTracker.Update(skillResultMessage); } }
private void HandleMessageReceived(Message obj) { var message = _messageFactory.Create(obj); _entityTracker?.Update(message); var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { var skillResult = new SkillResult(skillResultMessage, _entityTracker, _playerTracker, _teraData.SkillDatabase); _damageTracker.Update(skillResult); } var cVersion = message as C_CHECK_VERSION; if (cVersion != null) { var opCodeNamer = new OpCodeNamer(Path.Combine(_basicTeraData.ResourceDirectory, $"opcodes/{cVersion.Versions[0]}.txt")); _messageFactory = new MessageFactory(opCodeNamer, _server.Region, cVersion.Versions[0]); return; } var sLoginMessage = message as LoginServerMessage; if (sLoginMessage != null) { if (_needInit) { _server = _basicTeraData.Servers.GetServer(sLoginMessage.ServerId, _server); _messageFactory.Region = _server.Region; Text = string.Format("Damage Meter connected to {0}", _server.Name); _teraData = _basicTeraData.DataForRegion(_server.Region); _entityTracker = new EntityTracker(_teraData.NpcDatabase); _playerTracker = new PlayerTracker(_entityTracker, _basicTeraData.Servers); _damageTracker = new DamageTracker(_settings.OnlyBosses, _settings.IgnoreOneshots); _entityTracker.Update(message); _needInit = false; } } }
private void OnMessageReceived(Message obj) { var message = _messageFactory.Create(obj); _entityTracker.Update(message); var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage?.IsUseless == false) { var skillResult = new SkillResult(skillResultMessage, _entityTracker, _playerTracker, _teraData.SkillDatabase); if (skillResult.Skill != null) { var args = new SkillEventArgs { SkillResult = skillResult }; SkillEvent?.Invoke(this, args); Console.WriteLine($@"Skill: {skillResult.Skill.Name} did {skillResult.Damage} to {skillResult.Target} from {skillResult.Source}"); } } }
private void HandleMessageReceived(Message obj) { var message = _messageFactory.Create(obj); if (DamageTracker.IsArchived) { var npcOccupier = message as SNpcOccupierInfo; if (npcOccupier != null) { Entity ent = _entityTracker.GetOrPlaceholder(npcOccupier.NPC); if (ent is NpcEntity) { var npce = ent as NpcEntity; if (npce.Info.Boss && npcOccupier.Target != EntityId.Empty) { CasualMessenger.Instance.ResetPlayerStats(true); //Stop viewing saved encounter on boss aggro } } return; } } _entityTracker?.Update(message); var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { if (skillResultMessage.IsValid(DamageTracker)) { var skillResult = new SkillResult(skillResultMessage, _entityTracker, _playerTracker, _teraData.SkillDatabase, null, _abnormalityTracker); CheckUpdate(skillResult); } return; } _playerTracker?.UpdateParty(message); _abnormalityTracker?.Update(message); var despawnNpc = message as SDespawnNpc; if (despawnNpc != null) { Entity ent = _entityTracker.GetOrPlaceholder(despawnNpc.Npc); if (ent is NpcEntity) { var npce = ent as NpcEntity; if (npce.Info.Boss && despawnNpc.Dead && !DamageTracker.IsArchived) { //no need to do something if we didn't count any skill against this boss if (DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Any(x => x.Target == npce)) { DamageTracker.PrimaryTarget = npce; //Name encounter with the last dead boss DamageTracker.IsPrimaryTargetDead = despawnNpc.Dead; //determine type ExportType exportType = ExportType.None; if (SettingsHelper.Instance.Settings.ExcelExport) { exportType = exportType | ExportType.Excel; } if (SettingsHelper.Instance.Settings.SiteExport) { exportType = exportType | ExportType.Upload; } if (exportType != ExportType.None) { DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData); } if (AutosaveEncounters) { ResetDamageTracker(new ResetPlayerStatsMessage { ShouldSaveCurrent = true }); } } } } return; } var spawnNpc = message as SpawnNpcServerMessage; if (spawnNpc != null) { if (spawnNpc.NpcArea == 950 && spawnNpc.NpcId == 9501) { var bosses = DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Select(x => x.Target).OfType <NpcEntity>().ToList(); var vergosPhase2Part1 = bosses.FirstOrDefault(x => x.Info.HuntingZoneId == 950 && x.Info.TemplateId == 1000); var vergosPhase2Part2 = bosses.FirstOrDefault(x => x.Info.HuntingZoneId == 950 && x.Info.TemplateId == 2000); //determine type ExportType exportType = ExportType.None; if (SettingsHelper.Instance.Settings.ExcelExport) { exportType = exportType | ExportType.Excel; } if (SettingsHelper.Instance.Settings.SiteExport) { exportType = exportType | ExportType.Upload; } if (exportType != ExportType.None) { DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData, vergosPhase2Part1); } DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData, vergosPhase2Part2); if (AutosaveEncounters) { ResetDamageTracker(new ResetPlayerStatsMessage { ShouldSaveCurrent = true }); } } if (spawnNpc.NpcArea == 950 && spawnNpc.NpcId == 9502) { var bosses = DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Select(x => x.Target).OfType <NpcEntity>().ToList(); var vergosPhase3 = bosses.FirstOrDefault(x => x.Info.HuntingZoneId == 950 && x.Info.TemplateId == 3000); //determine type ExportType exportType = ExportType.None; if (SettingsHelper.Instance.Settings.ExcelExport) { exportType = exportType | ExportType.Excel; } if (SettingsHelper.Instance.Settings.SiteExport) { exportType = exportType | ExportType.Upload; } if (exportType != ExportType.None) { DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData, vergosPhase3); } if (AutosaveEncounters) { ResetDamageTracker(new ResetPlayerStatsMessage { ShouldSaveCurrent = true }); } } return; } var sLogin = message as LoginServerMessage; if (sLogin != null) { if (_needInit) { Server = BasicTeraData.Servers.GetServer(sLogin.ServerId, Server); _messageFactory.Region = Server.Region; Logger.Info($"Logged in to server {Server.Name}."); _teraData = BasicTeraData.DataForRegion(Server.Region); _entityTracker = new EntityTracker(_teraData.NpcDatabase, _userLogoTracker); _playerTracker = new PlayerTracker(_entityTracker, BasicTeraData.Servers); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); _entityTracker.Update(message); if (!DamageTracker.IsArchived) { DamageTracker.MeterPlayer = _playerTracker.Me(); } _needInit = false; } _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); return; } var cVersion = message as C_CHECK_VERSION; if (cVersion != null) { var opCodeNamer = new OpCodeNamer(Path.Combine(BasicTeraData.ResourceDirectory, $"opcodes/{cVersion.Versions[0]}.txt")); _messageFactory = new MessageFactory(opCodeNamer, Server.Region, cVersion.Versions[0]); return; } var sGetUserList = message as S_GET_USER_LIST; if (sGetUserList != null) { _userLogoTracker.SetUserList(sGetUserList); return; } }
private void HandleMessageReceived(Message obj) { var message = _messageFactory.Create(obj); if (DamageTracker.IsArchived) { var npcOccupier = message as SNpcOccupierInfo; if (npcOccupier != null) { Entity ent = _entityTracker.GetOrPlaceholder(npcOccupier.NPC); if (ent is NpcEntity) { var npce = ent as NpcEntity; if (npce.Info.Boss && npcOccupier.Target != EntityId.Empty) { CasualMessenger.Instance.ResetPlayerStats(true); //Stop viewing saved encounter on boss aggro } } return; } } _entityTracker?.Update(message); var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { if (skillResultMessage.IsValid(DamageTracker)) { var skillResult = new SkillResult(skillResultMessage, _entityTracker, _playerTracker, _teraData.SkillDatabase, null, _abnormalityTracker); CheckUpdate(skillResult); } return; } _playerTracker?.UpdateParty(message); _abnormalityTracker?.Update(message); var despawnNpc = message as SDespawnNpc; if (despawnNpc != null) { Entity ent = _entityTracker.GetOrPlaceholder(despawnNpc.Npc); if (ent is NpcEntity) { var npce = ent as NpcEntity; if (npce.Info.Boss && despawnNpc.Dead && !DamageTracker.IsArchived) { //no need to do something if we didn't count any skill against this boss if (DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Any(x => x.Target == npce)) { DamageTracker.PrimaryTarget = npce; //Name encounter with the last dead boss DamageTracker.IsPrimaryTargetDead = despawnNpc.Dead; //determine type ExportType exportType = ExportType.None; if (SettingsHelper.Instance.Settings.ExcelExport) exportType = exportType | ExportType.Excel; if (SettingsHelper.Instance.Settings.SiteExport) exportType = exportType | ExportType.Upload; if (exportType != ExportType.None) DataExporter.ToTeraDpsApi(exportType, DamageTracker, _teraData); if (AutosaveEncounters) ResetDamageTracker(new ResetPlayerStatsMessage { ShouldSaveCurrent = true }); } } } return; } var sLogin = message as LoginServerMessage; if (sLogin != null) { if (_needInit) { Server = BasicTeraData.Servers.GetServer(sLogin.ServerId, Server); _messageFactory.Version = Server.Region; Logger.Info($"Logged in to server {Server.Name}."); _teraData = BasicTeraData.DataForRegion(Server.Region); _entityTracker = new EntityTracker(_teraData.NpcDatabase); _playerTracker = new PlayerTracker(_entityTracker, BasicTeraData.Servers); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); _entityTracker.Update(message); _needInit = false; } _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); return; } var cVersion = message as C_CHECK_VERSION; if (cVersion != null) { var opCodeNamer = new OpCodeNamer(Path.Combine(BasicTeraData.ResourceDirectory, $"opcodes/{cVersion.Versions[0]}.txt")); _messageFactory = new MessageFactory(opCodeNamer, Server.Region); return; } }
private void PacketAnalysisLoop() { while (true) { if (ForceUpdate) { ForceUpdate = false; UpdateUi(); } CheckUpdateUi(); Message obj; var successDequeue = TeraSniffer.Instance.Packets.TryDequeue(out obj); if (!successDequeue) { Thread.Sleep(10); continue; } if (TeraSniffer.Instance.Packets.Count > 3000) { MessageBox.Show( "Your computer is too slow to use this DPS meter. Can't analyse all those packet in decent amount of time. Shutting down now."); Exit(); } var message = _messageFactory.Create(obj); EntityTracker.Update(message); var sLogin = message as LoginServerMessage; if (sLogin != null) { Connected(BasicTeraData.Instance.Servers.GetServerName(sLogin.ServerId, Server)); continue; } var npcOccupier = message as SNpcOccupierInfo; if (npcOccupier != null) { DamageTracker.Instance.UpdateEntities(new NpcOccupierResult(npcOccupier), npcOccupier.Time.Ticks); continue; } var changeHp = message as SCreatureChangeHp; if (changeHp != null) { AbnormalityTracker.Instance.Update(changeHp); continue; } var changeMp = message as SPlayerChangeMp; if (changeMp != null) { AbnormalityTracker.Instance.Update(changeMp); continue; } var abnormalityBegin = message as SAbnormalityBegin; if (abnormalityBegin != null) { AbnormalityTracker.Instance.AddAbnormality(abnormalityBegin); continue; } var abnormalityEnd = message as SAbnormalityEnd; if (abnormalityEnd != null) { AbnormalityTracker.Instance.DeleteAbnormality(abnormalityEnd); continue; } var abnormalityRefresh = message as SAbnormalityRefresh; if (abnormalityRefresh != null) { AbnormalityTracker.Instance.RefreshAbnormality(abnormalityRefresh); continue; } var despawnNpc = message as SDespawnNpc; if (despawnNpc != null) { AbnormalityTracker.Instance.DeleteAbnormality(despawnNpc); continue; } var despawnUser = message as SDespawnUser; if (despawnUser != null) { AbnormalityTracker.Instance.DeleteAbnormality(despawnUser); continue; } var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage == null) { continue; } var amount = skillResultMessage.Amount; if (!skillResultMessage.IsHeal && skillResultMessage.IsHp && amount > 0) { amount *= -1; } var skillResult = ForgeSkillResult( false, amount, skillResultMessage.IsCritical, skillResultMessage.IsHp, skillResultMessage.SkillId, skillResultMessage.Source, skillResultMessage.Target); DamageTracker.Instance.Update(skillResult, skillResultMessage.Time.Ticks); } }
private void PacketAnalysisLoop() { try { Database.Database.Instance.DeleteAll(); } catch (Exception ex) { BasicTeraData.LogError(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.Source + "\r\n" + ex + "\r\n" + ex.Data + "\r\n" + ex.InnerException + "\r\n" + ex.TargetSite, true); MessageBox.Show(LP.MainWindow_Fatal_error); Exit(); } while (true) { if (NeedToCopy != null) { var currentBoss = Encounter; var timedEncounter = TimedEncounter; var entityInfo = Database.Database.Instance.GlobalInformationEntity(currentBoss, timedEncounter); var skills = Database.Database.Instance.GetSkills(entityInfo.BeginTime, entityInfo.EndTime); var playersInfo = timedEncounter ? Database.Database.Instance.PlayerDamageInformation(entityInfo.BeginTime, entityInfo.EndTime) : Database.Database.Instance.PlayerDamageInformation(currentBoss); var heals = Database.Database.Instance.PlayerHealInformation(entityInfo.BeginTime, entityInfo.EndTime); var statsSummary = new StatsSummary(playersInfo, heals, entityInfo); var tmpcopy = NeedToCopy; var abnormals = _abnormalityStorage.Clone(currentBoss, entityInfo.BeginTime, entityInfo.EndTime); var pasteThread = new Thread(() => CopyThread(statsSummary, skills, abnormals, timedEncounter, tmpcopy)) { Priority = ThreadPriority.Highest }; pasteThread.SetApartmentState(ApartmentState.STA); pasteThread.Start(); NeedToCopy = null; } if (NeedToReset) { Reset(); NeedToReset = false; } if (NeedToResetCurrent) { ResetCurrent(); NeedToResetCurrent = false; } if (NeedToExport) { DataExporter.Export(Encounter, _abnormalityStorage); NeedToExport = false; } Encounter = NewEncounter; var packetsWaiting = TeraSniffer.Instance.Packets.Count; if (packetsWaiting > 3000) { MessageBox.Show( LP.Your_computer_is_too_slow); Exit(); } if (_forceUiUpdate) { UpdateUi(packetsWaiting); _forceUiUpdate = false; } CheckUpdateUi(packetsWaiting); Message obj; var successDequeue = TeraSniffer.Instance.Packets.TryDequeue(out obj); if (!successDequeue) { Thread.Sleep(1); continue; } var message = _messageFactory.Create(obj); EntityTracker?.Update(message); var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { var skillResult = new SkillResult(skillResultMessage, EntityTracker, PlayerTracker, BasicTeraData.Instance.SkillDatabase, BasicTeraData.Instance.PetSkillDatabase); DamageTracker.Instance.Update(skillResult); continue; } var changeHp = message as SCreatureChangeHp; if (changeHp != null) { if (changeHp.SourceId != EntityTracker.MeterUser.Id && changeHp.TargetId != EntityTracker.MeterUser.Id && EntityTracker.GetOrPlaceholder(changeHp.TargetId).RootOwner == EntityTracker.MeterUser // don't care about damage received by our pets ) { BasicTeraData.LogError("SCreatureChangeHP need rootowner update1", false, true); } _abnormalityTracker.Update(changeHp); continue; } var pchangeHp = message as SPartyMemberChangeHp; if (pchangeHp != null) { var user = PlayerTracker.GetOrNull(pchangeHp.ServerId, pchangeHp.PlayerId); if (user == null) { continue; } _abnormalityTracker.RegisterSlaying(user.User, pchangeHp.Slaying, pchangeHp.Time.Ticks); continue; } var pmstatupd = message as S_PARTY_MEMBER_STAT_UPDATE; if (pmstatupd != null) { var user = PlayerTracker.GetOrNull(pmstatupd.ServerId, pmstatupd.PlayerId); if (user == null) { continue; } _abnormalityTracker.RegisterSlaying(user.User, pmstatupd.Slaying, pmstatupd.Time.Ticks); continue; } var pstatupd = message as S_PLAYER_STAT_UPDATE; if (pstatupd != null) { _abnormalityTracker.RegisterSlaying(EntityTracker.MeterUser, pstatupd.Slaying, pstatupd.Time.Ticks); continue; } var changeMp = message as SPlayerChangeMp; if (changeMp != null) { if (changeMp.SourceId != EntityTracker.MeterUser.Id && changeMp.TargetId != EntityTracker.MeterUser.Id) { BasicTeraData.LogError("SPlayerChangeMp need rootowner", false, true); } _abnormalityTracker.Update(changeMp); continue; } var npcStatus = message as SNpcStatus; if (npcStatus != null) { _abnormalityTracker.RegisterNpcStatus(npcStatus); continue; } var dead = message as SCreatureLife; if (dead != null) { _abnormalityTracker.RegisterDead(dead); continue; } var abnormalityBegin = message as SAbnormalityBegin; if (abnormalityBegin != null) { _abnormalityTracker.AddAbnormality(abnormalityBegin); continue; } var abnormalityEnd = message as SAbnormalityEnd; if (abnormalityEnd != null) { _abnormalityTracker.DeleteAbnormality(abnormalityEnd); continue; } var abnormalityRefresh = message as SAbnormalityRefresh; if (abnormalityRefresh != null) { _abnormalityTracker.RefreshAbnormality(abnormalityRefresh); continue; } var npcOccupier = message as SNpcOccupierInfo; if (npcOccupier != null) { DamageTracker.Instance.UpdateEntities(new NpcOccupierResult(npcOccupier), npcOccupier.Time.Ticks); continue; } var despawnNpc = message as SDespawnNpc; if (despawnNpc != null) { _abnormalityTracker.StopAggro(despawnNpc); _abnormalityTracker.DeleteAbnormality(despawnNpc); DataExporter.Export(despawnNpc, _abnormalityStorage); continue; } var chatMessage = message as S_CHAT; if (chatMessage != null) { Chat.Instance.Add(chatMessage); continue; } var whisperMessage = message as S_WHISPER; if (whisperMessage != null) { Chat.Instance.Add(whisperMessage); continue; } var despawnUser = message as SDespawnUser; if (despawnUser != null) { _charmTracker.CharmReset(despawnUser.User, new List <CharmStatus>(), despawnUser.Time.Ticks); _abnormalityTracker.DeleteAbnormality(despawnUser); continue; } var charmEnable = message as SEnableCharmStatus; if (charmEnable != null) { _charmTracker.CharmEnable(EntityTracker.MeterUser.Id, charmEnable.CharmId, charmEnable.Time.Ticks); continue; } var pcharmEnable = message as SPartyMemberCharmEnable; if (pcharmEnable != null) { var player = PlayerTracker.GetOrNull(pcharmEnable.ServerId, pcharmEnable.PlayerId); if (player == null) { continue; } _charmTracker.CharmEnable(player.User.Id, pcharmEnable.CharmId, pcharmEnable.Time.Ticks); continue; } var charmReset = message as SResetCharmStatus; if (charmReset != null) { _charmTracker.CharmReset(charmReset.TargetId, charmReset.Charms, charmReset.Time.Ticks); continue; } var pcharmReset = message as SPartyMemberCharmReset; if (pcharmReset != null) { var player = PlayerTracker.GetOrNull(pcharmReset.ServerId, pcharmReset.PlayerId); if (player == null) { continue; } _charmTracker.CharmReset(player.User.Id, pcharmReset.Charms, pcharmReset.Time.Ticks); continue; } var charmDel = message as SRemoveCharmStatus; if (charmDel != null) { _charmTracker.CharmDel(EntityTracker.MeterUser.Id, charmDel.CharmId, charmDel.Time.Ticks); continue; } var pcharmDel = message as SPartyMemberCharmDel; if (pcharmDel != null) { var player = PlayerTracker.GetOrNull(pcharmDel.ServerId, pcharmDel.PlayerId); if (player == null) { continue; } _charmTracker.CharmDel(player.User.Id, pcharmDel.CharmId, pcharmDel.Time.Ticks); continue; } var charmAdd = message as SAddCharmStatus; if (charmAdd != null) { _charmTracker.CharmAdd(charmAdd.TargetId, charmAdd.CharmId, charmAdd.Status, charmAdd.Time.Ticks); continue; } var pcharmAdd = message as SPartyMemberCharmAdd; if (pcharmAdd != null) { var player = PlayerTracker.GetOrNull(pcharmAdd.ServerId, pcharmAdd.PlayerId); if (player == null) { continue; } _charmTracker.CharmAdd(player.User.Id, pcharmAdd.CharmId, pcharmAdd.Status, pcharmAdd.Time.Ticks); continue; } PlayerTracker?.UpdateParty(message); var sSpawnUser = message as SpawnUserServerMessage; if (sSpawnUser != null) { _abnormalityTracker.RegisterDead(sSpawnUser.Id, sSpawnUser.Time.Ticks, sSpawnUser.Dead); //Debug.WriteLine(sSpawnUser.Name + " : " + BitConverter.ToString(BitConverter.GetBytes(sSpawnUser.Id.Id)) + " : " + BitConverter.ToString(BitConverter.GetBytes(sSpawnUser.ServerId)) + " " + BitConverter.ToString(BitConverter.GetBytes(sSpawnUser.PlayerId))); continue; } var spawnMe = message as SpawnMeServerMessage; if (spawnMe != null) { _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(EntityTracker, PlayerTracker, BasicTeraData.Instance.HotDotDatabase, _abnormalityStorage, DamageTracker.Instance.Update); _charmTracker = new CharmTracker(_abnormalityTracker); _abnormalityTracker.RegisterDead(spawnMe.Id, spawnMe.Time.Ticks, spawnMe.Dead); continue; } var guildIcon = message as S_GET_USER_GUILD_LOGO; if (guildIcon != null) { UserLogoTracker.AddLogo(guildIcon); continue; } var user_list = message as S_GET_USER_LIST; if (user_list != null) { UserLogoTracker.SetUserList(user_list); continue; } var cVersion = message as C_CHECK_VERSION; if (cVersion != null) { Console.WriteLine("VERSION0 = " + cVersion.Versions[0]); Console.WriteLine("VERSION1 = " + cVersion.Versions[1]); var opCodeNamer = new OpCodeNamer(Path.Combine(BasicTeraData.Instance.ResourceDirectory, $"data/opcodes/{cVersion.Versions[0]}.txt")); _messageFactory = new MessageFactory(opCodeNamer, Server.Region); continue; } var sLogin = message as LoginServerMessage; if (sLogin == null) { continue; } if (_needInit) { Connected(BasicTeraData.Instance.Servers.GetServerName(sLogin.ServerId, Server)); Server = BasicTeraData.Instance.Servers.GetServer(sLogin.ServerId, Server); _messageFactory.Version = Server.Region; TeraData = BasicTeraData.Instance.DataForRegion(Server.Region); BasicTeraData.Instance.HotDotDatabase.Get(8888888).Name = LP.Enrage; BasicTeraData.Instance.HotDotDatabase.Get(8888889).Name = LP.Slaying; BasicTeraData.Instance.HotDotDatabase.Get(8888889).Tooltip = LP.SlayingTooltip; EntityTracker = new EntityTracker(BasicTeraData.Instance.MonsterDatabase); PlayerTracker = new PlayerTracker(EntityTracker, BasicTeraData.Instance.Servers); PlayerTracker.PlayerIdChangedAction += PlayerTrackerOnPlayerIdChangedAction; EntityTracker.Update(message); PlayerTracker.UpdateParty(message); _needInit = false; } _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(EntityTracker, PlayerTracker, BasicTeraData.Instance.HotDotDatabase, _abnormalityStorage, DamageTracker.Instance.Update); _charmTracker = new CharmTracker(_abnormalityTracker); OnGuildIconAction(UserLogoTracker.GetLogo(sLogin.PlayerId)); //Debug.WriteLine(sLogin.Name + " : " + BitConverter.ToString(BitConverter.GetBytes(sLogin.Id.Id))); } }
private void HandleMessageReceived(Message obj) { var message = _messageFactory.Create(obj); var despawnNpc = message as SDespawnNpc; if (despawnNpc != null) { Entity ent = _entityTracker.GetOrPlaceholder(despawnNpc.NPC); if (ent is NpcEntity) { _abnormalityTracker.StopAggro(despawnNpc); _abnormalityTracker.DeleteAbnormality(despawnNpc); var npce = ent as NpcEntity; if (npce.Info.Boss && despawnNpc.Dead && !DamageTracker.IsArchived) { //no need to do something if we didn't count any skill against this boss if (DamageTracker.StatsByUser.SelectMany(x => x.SkillLog).Any(x => x.Target == npce)) { DataExporter.ToTeraDpsApi(despawnNpc, DamageTracker, _entityTracker, _teraData); DamageTracker.Name = npce.Info.Name; //Name encounter with the last dead boss if (AutosaveEncounters) { CasualMessenger.Instance.ResetPlayerStats(true); } } } } return; } if (DamageTracker.IsArchived) { var npcOccupier = message as SNpcOccupierInfo; if (npcOccupier != null) { Entity ent = _entityTracker.GetOrPlaceholder(npcOccupier.NPC); if (ent is NpcEntity) { var npce = ent as NpcEntity; if (npce.Info.Boss && npcOccupier.Target != EntityId.Empty) { CasualMessenger.Instance.ResetPlayerStats(true); //Stop viewing saved encounter on boss aggro } } return; } } var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { if (skillResultMessage.IsValid(DamageTracker)) { var skillResult = new SkillResult(skillResultMessage, _entityTracker, _playerTracker, _teraData.SkillDatabase); CheckUpdate(skillResult); } return; } var changeHp = message as SCreatureChangeHp; if (changeHp != null) { _abnormalityTracker.Update(changeHp); return; } var pchangeHp = message as SPartyMemberChangeHp; if (pchangeHp != null) { var user = _playerTracker.GetOrNull(pchangeHp.ServerId, pchangeHp.PlayerId); if (user == null) { return; } _abnormalityTracker.RegisterSlaying(user.User, pchangeHp.Slaying, pchangeHp.Time.Ticks); return; } var pmstatupd = message as S_PARTY_MEMBER_STAT_UPDATE; if (pmstatupd != null) { var user = _playerTracker.GetOrNull(pmstatupd.ServerId, pmstatupd.PlayerId); if (user == null) { return; } _abnormalityTracker.RegisterSlaying(user.User, pmstatupd.Slaying, pmstatupd.Time.Ticks); return; } var pstatupd = message as S_PLAYER_STAT_UPDATE; if (pstatupd != null) { _abnormalityTracker.RegisterSlaying(_entityTracker.MeterUser, pstatupd.Slaying, pstatupd.Time.Ticks); return; } var changeMp = message as SPlayerChangeMp; if (changeMp != null) { _abnormalityTracker.Update(changeMp); return; } var npcStatus = message as SNpcStatus; if (npcStatus != null) { _abnormalityTracker.RegisterNpcStatus(npcStatus); return; } var dead = message as SCreatureLife; if (dead != null) { _abnormalityTracker.RegisterDead(dead); return; } var abnormalityBegin = message as SAbnormalityBegin; if (abnormalityBegin != null) { _abnormalityTracker.AddAbnormality(abnormalityBegin); return; } var abnormalityEnd = message as SAbnormalityEnd; if (abnormalityEnd != null) { _abnormalityTracker.DeleteAbnormality(abnormalityEnd); return; } var abnormalityRefresh = message as SAbnormalityRefresh; if (abnormalityRefresh != null) { _abnormalityTracker.RefreshAbnormality(abnormalityRefresh); return; } var despawnUser = message as SDespawnUser; if (despawnUser != null) { _charmTracker.CharmReset(despawnUser.User, new List <CharmStatus>(), despawnUser.Time.Ticks); _abnormalityTracker.DeleteAbnormality(despawnUser); return; } var charmEnable = message as SEnableCharmStatus; if (charmEnable != null) { _charmTracker.CharmEnable(_entityTracker.MeterUser.Id, charmEnable.CharmId, charmEnable.Time.Ticks); return; } var pcharmEnable = message as SPartyMemberCharmEnable; if (pcharmEnable != null) { var player = _playerTracker.GetOrNull(pcharmEnable.ServerId, pcharmEnable.PlayerId); if (player == null) { return; } _charmTracker.CharmEnable(player.User.Id, pcharmEnable.CharmId, pcharmEnable.Time.Ticks); return; } var charmReset = message as SResetCharmStatus; if (charmReset != null) { _charmTracker.CharmReset(charmReset.TargetId, charmReset.Charms, charmReset.Time.Ticks); return; } var pcharmReset = message as SPartyMemberCharmReset; if (pcharmReset != null) { var player = _playerTracker.GetOrNull(pcharmReset.ServerId, pcharmReset.PlayerId); if (player == null) { return; } _charmTracker.CharmReset(player.User.Id, pcharmReset.Charms, pcharmReset.Time.Ticks); return; } var charmDel = message as SRemoveCharmStatus; if (charmDel != null) { _charmTracker.CharmDel(_entityTracker.MeterUser.Id, charmDel.CharmId, charmDel.Time.Ticks); return; } var pcharmDel = message as SPartyMemberCharmDel; if (pcharmDel != null) { var player = _playerTracker.GetOrNull(pcharmDel.ServerId, pcharmDel.PlayerId); if (player == null) { return; } _charmTracker.CharmDel(player.User.Id, pcharmDel.CharmId, pcharmDel.Time.Ticks); return; } var charmAdd = message as SAddCharmStatus; if (charmAdd != null) { _charmTracker.CharmAdd(charmAdd.TargetId, charmAdd.CharmId, charmAdd.Status, charmAdd.Time.Ticks); return; } var pcharmAdd = message as SPartyMemberCharmAdd; if (pcharmAdd != null) { var player = _playerTracker.GetOrNull(pcharmAdd.ServerId, pcharmAdd.PlayerId); if (player == null) { return; } _charmTracker.CharmAdd(player.User.Id, pcharmAdd.CharmId, pcharmAdd.Status, pcharmAdd.Time.Ticks); return; } _entityTracker.Update(message); _playerTracker.UpdateParty(message); var spawnMe = message as SpawnMeServerMessage; if (spawnMe != null) { _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); _charmTracker = new CharmTracker(_abnormalityTracker); return; } var sLogin = message as LoginServerMessage; if (sLogin != null) { _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(_entityTracker, _playerTracker, _teraData.HotDotDatabase, _abnormalityStorage, CheckUpdate); _charmTracker = new CharmTracker(_abnormalityTracker); Server = BasicTeraData.Servers.GetServer(sLogin.ServerId, Server); return; } }
private void PacketAnalysisLoop() { try { Database.Database.Instance.DeleteAll(); } catch (Exception ex) { BasicTeraData.LogError(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.Source + "\r\n" + ex + "\r\n" + ex.Data + "\r\n" + ex.InnerException + "\r\n" + ex.TargetSite, true); MessageBox.Show(LP.MainWindow_Fatal_error); Exit(); } while (true) { if (NeedToCopy != null) { var currentBoss = Encounter; var timedEncounter = TimedEncounter; var entityInfo = Database.Database.Instance.GlobalInformationEntity(currentBoss, timedEncounter); var skills = Database.Database.Instance.GetSkills(entityInfo.BeginTime, entityInfo.EndTime); var playersInfo = timedEncounter ? Database.Database.Instance.PlayerDamageInformation(entityInfo.BeginTime, entityInfo.EndTime) : Database.Database.Instance.PlayerDamageInformation(currentBoss); var heals = Database.Database.Instance.PlayerHealInformation(entityInfo.BeginTime, entityInfo.EndTime); var statsSummary = new StatsSummary(playersInfo, heals, entityInfo); var tmpcopy = NeedToCopy; var abnormals = _abnormalityStorage.Clone(currentBoss, entityInfo.BeginTime, entityInfo.EndTime); var pasteThread = new Thread(() => CopyThread(statsSummary, skills, abnormals, timedEncounter, tmpcopy)) { Priority = ThreadPriority.Highest }; pasteThread.SetApartmentState(ApartmentState.STA); pasteThread.Start(); NeedToCopy = null; } if (NeedToReset) { Reset(); NeedToReset = false; } if (NeedToResetCurrent) { ResetCurrent(); NeedToResetCurrent = false; } if (NeedToExport) { DataExporter.Export(Encounter, _abnormalityStorage); NeedToExport = false; } Encounter = NewEncounter; var packetsWaiting = TeraSniffer.Instance.Packets.Count; if (packetsWaiting > 3000) { MessageBox.Show( LP.Your_computer_is_too_slow); Exit(); } if (_forceUiUpdate) { UpdateUi(packetsWaiting); _forceUiUpdate = false; } CheckUpdateUi(packetsWaiting); Message obj; var successDequeue = TeraSniffer.Instance.Packets.TryDequeue(out obj); if (!successDequeue) { Thread.Sleep(1); continue; } var message = _messageFactory.Create(obj); var cVersion = message as C_CHECK_VERSION; if (cVersion != null) { Console.WriteLine("VERSION0 = " + cVersion.Versions[0]); Console.WriteLine("VERSION1 = " + cVersion.Versions[1]); var opCodeNamer = new OpCodeNamer(Path.Combine(BasicTeraData.Instance.ResourceDirectory, $"data/opcodes/{cVersion.Versions[0]}.txt")); _messageFactory = new MessageFactory(opCodeNamer, Server.Region); continue; } var sLogin = message as LoginServerMessage; if (sLogin != null) { if (_needInit) { Connected(BasicTeraData.Instance.Servers.GetServerName(sLogin.ServerId, Server)); bool trackerreset = true; if (EntityTracker != null) { try { var oldregion = BasicTeraData.Instance.Servers.GetServer(EntityTracker.MeterUser.ServerId).Region; trackerreset = Server.Region != oldregion; } catch (Exception e) { BasicTeraData.LogError("New server:" + Server + ";Old server Id:" + EntityTracker.MeterUser.ServerId, false, true); throw; } } Server = BasicTeraData.Instance.Servers.GetServer(sLogin.ServerId, Server); _messageFactory.Version = Server.Region; if (trackerreset) { TeraData = BasicTeraData.Instance.DataForRegion(Server.Region); BasicTeraData.Instance.HotDotDatabase.Get(8888888).Name = LP.Enrage; BasicTeraData.Instance.HotDotDatabase.Get(8888889).Name = LP.Slaying; BasicTeraData.Instance.HotDotDatabase.Get(8888889).Tooltip = LP.SlayingTooltip; EntityTracker = new EntityTracker(BasicTeraData.Instance.MonsterDatabase); PlayerTracker = new PlayerTracker(EntityTracker, BasicTeraData.Instance.Servers); Database.Database.Instance.DeleteAll(); } _needInit = false; } _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(EntityTracker, PlayerTracker, BasicTeraData.Instance.HotDotDatabase, _abnormalityStorage, DamageTracker.Instance.Update); _charmTracker = new CharmTracker(_abnormalityTracker); OnGuildIconAction(UserLogoTracker.GetLogo(sLogin.PlayerId)); } if (_needInit) { //Wait for initialization continue; } EntityTracker.Update(message); var skillResultMessage = message as EachSkillResultServerMessage; if (skillResultMessage != null) { var skillResult = new SkillResult(skillResultMessage, EntityTracker, PlayerTracker, BasicTeraData.Instance.SkillDatabase, BasicTeraData.Instance.PetSkillDatabase); DamageTracker.Instance.Update(skillResult); continue; } var changeHp = message as SCreatureChangeHp; if (changeHp != null) { _abnormalityTracker.Update(changeHp); continue; } var pchangeHp = message as SPartyMemberChangeHp; if (pchangeHp != null) { var user = PlayerTracker.GetOrNull(pchangeHp.ServerId, pchangeHp.PlayerId); if (user == null) { continue; } _abnormalityTracker.RegisterSlaying(user.User, pchangeHp.Slaying, pchangeHp.Time.Ticks); continue; } var pmstatupd = message as S_PARTY_MEMBER_STAT_UPDATE; if (pmstatupd != null) { var user = PlayerTracker.GetOrNull(pmstatupd.ServerId, pmstatupd.PlayerId); if (user == null) { continue; } _abnormalityTracker.RegisterSlaying(user.User, pmstatupd.Slaying, pmstatupd.Time.Ticks); continue; } var pstatupd = message as S_PLAYER_STAT_UPDATE; if (pstatupd != null) { _abnormalityTracker.RegisterSlaying(EntityTracker.MeterUser, pstatupd.Slaying, pstatupd.Time.Ticks); continue; } var changeMp = message as SPlayerChangeMp; if (changeMp != null) { if (changeMp.SourceId != EntityTracker.MeterUser.Id && changeMp.TargetId != EntityTracker.MeterUser.Id && EntityTracker.GetOrPlaceholder(changeHp.TargetId).RootOwner != EntityTracker.MeterUser) { var source = EntityTracker.GetOrPlaceholder(changeMp.SourceId); BasicTeraData.LogError("SPlayerChangeMp need rootowner update2:" + (source as NpcEntity)?.Info.Name ?? source.GetType() + ": " + source, false, true); } _abnormalityTracker.Update(changeMp); continue; } var npcStatus = message as SNpcStatus; if (npcStatus != null) { _abnormalityTracker.RegisterNpcStatus(npcStatus); continue; } var dead = message as SCreatureLife; if (dead != null) { _abnormalityTracker.RegisterDead(dead); continue; } var abnormalityBegin = message as SAbnormalityBegin; if (abnormalityBegin != null) { _abnormalityTracker.AddAbnormality(abnormalityBegin); continue; } var abnormalityEnd = message as SAbnormalityEnd; if (abnormalityEnd != null) { _abnormalityTracker.DeleteAbnormality(abnormalityEnd); continue; } var abnormalityRefresh = message as SAbnormalityRefresh; if (abnormalityRefresh != null) { _abnormalityTracker.RefreshAbnormality(abnormalityRefresh); continue; } var npcOccupier = message as SNpcOccupierInfo; if (npcOccupier != null) { DamageTracker.Instance.UpdateEntities(new NpcOccupierResult(npcOccupier), npcOccupier.Time.Ticks); continue; } var despawnNpc = message as SDespawnNpc; if (despawnNpc != null) { _abnormalityTracker.StopAggro(despawnNpc); _abnormalityTracker.DeleteAbnormality(despawnNpc); DataExporter.Export(despawnNpc, _abnormalityStorage); continue; } var despawnUser = message as SDespawnUser; if (despawnUser != null) { _charmTracker.CharmReset(despawnUser.User, new List <CharmStatus>(), despawnUser.Time.Ticks); _abnormalityTracker.DeleteAbnormality(despawnUser); continue; } var charmEnable = message as SEnableCharmStatus; if (charmEnable != null) { _charmTracker.CharmEnable(EntityTracker.MeterUser.Id, charmEnable.CharmId, charmEnable.Time.Ticks); continue; } var pcharmEnable = message as SPartyMemberCharmEnable; if (pcharmEnable != null) { var player = PlayerTracker.GetOrNull(pcharmEnable.ServerId, pcharmEnable.PlayerId); if (player == null) { continue; } _charmTracker.CharmEnable(player.User.Id, pcharmEnable.CharmId, pcharmEnable.Time.Ticks); continue; } var charmReset = message as SResetCharmStatus; if (charmReset != null) { _charmTracker.CharmReset(charmReset.TargetId, charmReset.Charms, charmReset.Time.Ticks); continue; } var pcharmReset = message as SPartyMemberCharmReset; if (pcharmReset != null) { var player = PlayerTracker.GetOrNull(pcharmReset.ServerId, pcharmReset.PlayerId); if (player == null) { continue; } _charmTracker.CharmReset(player.User.Id, pcharmReset.Charms, pcharmReset.Time.Ticks); continue; } var charmDel = message as SRemoveCharmStatus; if (charmDel != null) { _charmTracker.CharmDel(EntityTracker.MeterUser.Id, charmDel.CharmId, charmDel.Time.Ticks); continue; } var pcharmDel = message as SPartyMemberCharmDel; if (pcharmDel != null) { var player = PlayerTracker.GetOrNull(pcharmDel.ServerId, pcharmDel.PlayerId); if (player == null) { continue; } _charmTracker.CharmDel(player.User.Id, pcharmDel.CharmId, pcharmDel.Time.Ticks); continue; } var charmAdd = message as SAddCharmStatus; if (charmAdd != null) { _charmTracker.CharmAdd(charmAdd.TargetId, charmAdd.CharmId, charmAdd.Status, charmAdd.Time.Ticks); continue; } var pcharmAdd = message as SPartyMemberCharmAdd; if (pcharmAdd != null) { var player = PlayerTracker.GetOrNull(pcharmAdd.ServerId, pcharmAdd.PlayerId); if (player == null) { continue; } _charmTracker.CharmAdd(player.User.Id, pcharmAdd.CharmId, pcharmAdd.Status, pcharmAdd.Time.Ticks); continue; } PlayerTracker.UpdateParty(message); var sSpawnUser = message as SpawnUserServerMessage; if (sSpawnUser != null) { _abnormalityTracker.RegisterDead(sSpawnUser.Id, sSpawnUser.Time.Ticks, sSpawnUser.Dead); //Debug.WriteLine(sSpawnUser.Name + " : " + BitConverter.ToString(BitConverter.GetBytes(sSpawnUser.Id.Id)) + " : " + BitConverter.ToString(BitConverter.GetBytes(sSpawnUser.ServerId)) + " " + BitConverter.ToString(BitConverter.GetBytes(sSpawnUser.PlayerId))); continue; } if (BasicTeraData.Instance.WindowData.EnableChat) { var chatMessage = message as S_CHAT; if (chatMessage != null) { Chat.Instance.Add(chatMessage); continue; } var whisperMessage = message as S_WHISPER; if (whisperMessage != null) { Chat.Instance.Add(whisperMessage); continue; } var privateChatMessage = message as S_PRIVATE_CHAT; if (privateChatMessage != null) { Chat.Instance.Add(privateChatMessage); continue; } var trading = message as S_TRADE_BROKER_DEAL_SUGGESTED; if (trading != null) { if (!TeraWindow.IsTeraActive()) { FlashMessage = new Tuple <string, string>( LP.Trading + ": " + trading.PlayerName, LP.SellerPrice + ": " + S_TRADE_BROKER_DEAL_SUGGESTED.Gold(trading.SellerPrice) + Environment.NewLine + LP.OfferedPrice + ": " + S_TRADE_BROKER_DEAL_SUGGESTED.Gold(trading.OfferedPrice) ); } continue; } var userApply = message as S_OTHER_USER_APPLY_PARTY; if (userApply != null) { if (!TeraWindow.IsTeraActive()) { FlashMessage = new Tuple <string, string>( userApply.PlayerName + " " + LP.ApplyToYourParty, LP.Class + ": " + LP.ResourceManager.GetString(userApply.PlayerClass.ToString(), LP.Culture) + Environment.NewLine + LP.Lvl + ": " + userApply.Lvl + Environment.NewLine ); } for (var i = 0; i < 3; i++) { try { Clipboard.SetDataObject("/inspect " + userApply.PlayerName); break; } catch { Thread.Sleep(100); //Ignore } } continue; } var contact = message as S_REQUEST_CONTRACT; if (contact != null) { if (!TeraWindow.IsTeraActive()) { if (contact.Type == S_REQUEST_CONTRACT.RequestType.PartyInvite) { FlashMessage = new Tuple <string, string>( LP.PartyInvite + ": " + contact.Sender, contact.Sender ); } else if (contact.Type == S_REQUEST_CONTRACT.RequestType.TradeRequest) { FlashMessage = new Tuple <string, string>( LP.Trading + ": " + contact.Sender, contact.Sender ); } else { FlashMessage = new Tuple <string, string>( LP.ContactTry, LP.ContactTry ); } } continue; } var partyMatch = message as S_FIN_INTER_PARTY_MATCH; var bgMatch = message as S_BATTLE_FIELD_ENTRANCE_INFO; if (partyMatch != null || bgMatch != null) { if (!TeraWindow.IsTeraActive()) { FlashMessage = new Tuple <string, string>( LP.PartyMatchingSuccess, LP.PartyMatchingSuccess ); } continue; } } var spawnMe = message as SpawnMeServerMessage; if (spawnMe != null) { _abnormalityStorage.EndAll(message.Time.Ticks); _abnormalityTracker = new AbnormalityTracker(EntityTracker, PlayerTracker, BasicTeraData.Instance.HotDotDatabase, _abnormalityStorage, DamageTracker.Instance.Update); _charmTracker = new CharmTracker(_abnormalityTracker); _abnormalityTracker.RegisterDead(spawnMe.Id, spawnMe.Time.Ticks, spawnMe.Dead); continue; } var guildIcon = message as S_GET_USER_GUILD_LOGO; if (guildIcon != null) { UserLogoTracker.AddLogo(guildIcon); continue; } var user_list = message as S_GET_USER_LIST; if (user_list != null) { UserLogoTracker.SetUserList(user_list); continue; } //Debug.WriteLine(sLogin.Name + " : " + BitConverter.ToString(BitConverter.GetBytes(sLogin.Id.Id))); } }