public static void Paste(string text) { if (!Monitor.TryEnter(Lock)) { return; } TeraWindow.SendString(text); Monitor.Exit(Lock); }
private void Add(string sender, string message, ChatType chatType, ChannelEnum?channel = null) { var time = DateTime.Now.ToString("HH:mm:ss"); var rgx = new Regex("<[^>]+>"); message = rgx.Replace(message, ""); message = WebUtility.HtmlDecode(message); if (string.IsNullOrWhiteSpace(message)) { return; } if (_chat.Count == _maxMessage) { _chat.RemoveFirst(); } var chatMessage = new ChatMessage(sender, message, chatType, channel, time); _chat.AddLast(chatMessage); if (PacketProcessor.Instance.EntityTracker?.MeterUser == null) { return; } if (chatType == ChatType.Whisper && PacketProcessor.Instance.EntityTracker.MeterUser.Name != sender && (BasicTeraData.Instance.WindowData.ShowAfkEventsIngame || !TeraWindow.IsTeraActive())) { PacketProcessor.Instance.FlashMessage.Add(NotifyProcessor.Instance.DefaultNotifyAction(LP.Whisper + ": " + sender, message, EventType.Whisper)); } if (chatType != ChatType.Whisper && PacketProcessor.Instance.EntityTracker.MeterUser.Name != sender && (BasicTeraData.Instance.WindowData.ShowAfkEventsIngame || !TeraWindow.IsTeraActive()) && message.Contains("@" + PacketProcessor.Instance.EntityTracker.MeterUser.Name)) { PacketProcessor.Instance.FlashMessage.Add(NotifyProcessor.Instance.DefaultNotifyAction(LP.Chat + ": " + sender, message, EventType.Mention)); } if ((chatType == ChatType.PrivateChannel || chatType == ChatType.Normal && (channel == ChannelEnum.Group || channel == ChannelEnum.Guild || channel == ChannelEnum.Raid)) && (BasicTeraData.Instance.WindowData.ShowAfkEventsIngame || !TeraWindow.IsTeraActive()) && message.Contains("@@")) { PacketProcessor.Instance.FlashMessage.Add(NotifyProcessor.Instance.DefaultNotifyAction("Wake up, " + PacketProcessor.Instance.EntityTracker.MeterUser.Name, "Wake up, " + PacketProcessor.Instance.EntityTracker.MeterUser.Name, EventType.WakeUp)); } // Trolling if (sender == "YukipƩdia" && PacketProcessor.Instance.Server.Name == "Seren" && message.Contains("@#")) { PacketProcessor.Instance.FlashMessage.Add(NotifyProcessor.Instance.DefaultNotifyAction("", message.Replace("@#", ""), EventType.WakeUp)); } }
public static void Paste(string text) { if (BasicTeraData.Instance.WindowData.NoPaste) { return; } if (!Monitor.TryEnter(Lock)) { return; } TeraWindow.SendString(text); Monitor.Exit(Lock); }
private void Add(string sender, string message, ChatType chatType, ChannelEnum?channel = null) { var time = DateTime.Now.ToString("HH:mm:ss"); var rgx = new Regex("<[^>]+>"); message = rgx.Replace(message, ""); message = WebUtility.HtmlDecode(message); if (string.IsNullOrWhiteSpace(message)) { return; } if (_chat.Count == _maxMessage) { _chat.RemoveFirst(); } if (chatType == ChatType.Whisper && NetworkController.Instance.EntityTracker.MeterUser.Name != sender && !TeraWindow.IsTeraActive()) { NetworkController.Instance.FlashMessage = new Tuple <string, string>(LP.Whisper + ": " + sender, message); } if (chatType != ChatType.Whisper && NetworkController.Instance.EntityTracker.MeterUser.Name != sender && !TeraWindow.IsTeraActive() && message.Contains("@" + NetworkController.Instance.EntityTracker.MeterUser.Name)) { NetworkController.Instance.FlashMessage = new Tuple <string, string>(LP.Chat + ": " + sender, message); } if ((chatType == ChatType.PrivateChannel || (chatType == ChatType.Normal && (channel == ChannelEnum.Group || channel == ChannelEnum.Guild || channel == ChannelEnum.Raid))) && !TeraWindow.IsTeraActive() && message.Contains("@@")) { NetworkController.Instance.FlashMessage = new Tuple <string, string>("Wake up, " + NetworkController.Instance.EntityTracker.MeterUser.Name, "Wake up, " + NetworkController.Instance.EntityTracker.MeterUser.Name); } var chatMessage = new ChatMessage(sender, message, chatType, channel, time); _chat.AddLast(chatMessage); }
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))); } }