#include "MultiSend.h" bool MultiSend::ReadCommand() { if (MMF_Pointer->Command.Command[Position].Active) { if (MatchID(MMF_Pointer->Command.Command[Position].Targets)) { if ((!IgnoreSelf) || (GetCurrentProcessId() != MMF_Pointer->Command.Command[Position].SendProcess)) { const char* text = new char[248]; memset((void*)text, 0, 248); memcpy((void*)text, &(MMF_Pointer->Command.Command[Position].Command), 248); if (_Debug) { m_AshitaCore->GetChatManager()->Writef("Sending command: %s", text); } if (m_AshitaCore->GetPluginManager()->GetPlugin("Shorthand")) { m_AshitaCore->GetChatManager()->QueueCommand(text, -1); } else { m_AshitaCore->GetChatManager()->QueueCommand(text, 0); } delete text; } } Position++; if (Position == 100) Position = 0; return true; } return false; } void MultiSend::SetFollow(bool Active) { if (Active) { Following = false; uint16_t myindex = m_AshitaCore->GetDataManager()->GetParty()->GetMemberTargetIndex(0); uint32_t mPosX = (uint32_t)floor(m_AshitaCore->GetDataManager()->GetEntity()->GetLocalX(myindex) * 100); uint32_t mPosZ = (uint32_t)floor(m_AshitaCore->GetDataManager()->GetEntity()->GetLocalZ(myindex) * 100); MMF_Pointer->Follow.PosX = mPosX; MMF_Pointer->Follow.PosZ = mPosZ; MMF_Pointer->Follow.Follow = 1; } else { MMF_Pointer->Follow.Follow = 0; } } void MultiSend::SendCommand(uint32_t ID, const char* Command) { char* Text = new char[248]; memset((void*)Text, 0, 248); memcpy(Text, Command, strlen(Command)); if (_SafeMode) SanitizeCommand(Text); SubValues(Text); Claim(&(MMF_Pointer->Command.ProcessID), 0); int NextPosition = MMF_Pointer->Command.Position + 1; if (NextPosition == 100) NextPosition = 0; MMF_Pointer->Command.Command[NextPosition].Active = false; memset(&(MMF_Pointer->Command.Command[MMF_Pointer->Command.Position].Command), 0, 248); if (strlen(Text) > 247) { memcpy(&(MMF_Pointer->Command.Command[MMF_Pointer->Command.Position].Command), Text, 247); } else { memcpy(&(MMF_Pointer->Command.Command[MMF_Pointer->Command.Position].Command), Text, strlen(Text)); } if (_Debug) { m_AshitaCore->GetChatManager()->Writef("Publishing position %d : %s", MMF_Pointer->Command.Position, Text); } MMF_Pointer->Command.Command[MMF_Pointer->Command.Position].SendProcess = GetCurrentProcessId(); MMF_Pointer->Command.Command[MMF_Pointer->Command.Position].Targets = ID; MMF_Pointer->Command.Command[MMF_Pointer->Command.Position].Active = true; MMF_Pointer->Command.Position = NextPosition; InterlockedExchange(&(MMF_Pointer->Command.ProcessID), 0); delete Text; } void MultiSend::UpdateName(std::string Name) { Claim(&(MMF_Pointer->Name.ProcessID), 0xFFFF0000); bool Written = false; for (int x = 0; x < 100; x++) { if (!MMF_Pointer->Name.Names[x].Active) { if (!Written) { memcpy(&(MMF_Pointer->Name.Names[x].Name), Name.c_str(), strlen(Name.c_str()) + 1); MMF_Pointer->Name.Names[x].Process = GetCurrentProcessId(); MMF_Pointer->Name.Names[x].Active = 1; Written = true; } continue; } else if (MMF_Pointer->Name.Names[x].Process == GetCurrentProcessId()) { memset(&(MMF_Pointer->Name.Names[x]), 0, sizeof(MMF_Name_Single)); if (!Written) { memcpy(&(MMF_Pointer->Name.Names[x].Name), Name.c_str(), strlen(Name.c_str()) + 1); MMF_Pointer->Name.Names[x].Process = GetCurrentProcessId(); MMF_Pointer->Name.Names[x].Active = 1; Written = true; } } else if (strcmp((const char*)&(MMF_Pointer->Name.Names[x].Name), Name.c_str()) == 0) { memset(&(MMF_Pointer->Name.Names[x]), 0, sizeof(MMF_Name_Single)); if (!Written) { memcpy(&(MMF_Pointer->Name.Names[x].Name), Name.c_str(), strlen(Name.c_str()) + 1); MMF_Pointer->Name.Names[x].Process = GetCurrentProcessId(); MMF_Pointer->Name.Names[x].Active = 1; Written = true; } } } CurrentName = Name; MatchGroups(); InterlockedExchange(&(MMF_Pointer->Name.ProcessID), 0); } void MultiSend::Claim(uint32_t* Target, uint32_t Mod) { uint32_t val = GetCurrentProcessId() + Mod; int FailCount = 0; InterlockedCompareExchange(Target, val, 0); while (*Target != val) { FailCount++; if (FailCount == 50) { InterlockedExchange(Target, val); return; } ::Sleep(1); InterlockedCompareExchange(Target, val, 0); } }