Browse Source

Added exception handling to catch bind errors to prevent crashes.

pull/2/head
atom0s 8 years ago
parent
commit
e1502a5d6b
  1. BIN
      Release/Plugins/Servo.dll
  2. 1
      Source/Servo.vcxproj
  3. 42
      Source/main.cpp

BIN
Release/Plugins/Servo.dll

Binary file not shown.

1
Source/Servo.vcxproj

@ -68,6 +68,7 @@ @@ -68,6 +68,7 @@
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<IgnoreSpecificDefaultLibraries>libci.lib</IgnoreSpecificDefaultLibraries>
<OutputFile>C:\Ashita\plugins\$(TargetName)$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

42
Source/main.cpp

@ -45,8 +45,6 @@ static inline std::string trimmed(std::string s) { @@ -45,8 +45,6 @@ static inline std::string trimmed(std::string s) {
return s;
}
std::string Servo::StringSub(std::string instring, std::string subin, std::string subout)
{
if (instring.find(subin) != std::string::npos)
@ -140,7 +138,7 @@ void Servo::SetState(ServoMode::Mode mode) @@ -140,7 +138,7 @@ void Servo::SetState(ServoMode::Mode mode)
void Servo::Sync(std::string host)
{
me = m_AshitaCore->GetDataManager()->GetParty()->GetMemberName(0);
log << Chat::Format::RoyalBlue << "Servo started in client mode, connected to: ";
log << Chat::Format::RoyalBlue << "[Servo] Servo started in client mode, connected to: ";
while (!lservAddr.try_lock())
std::this_thread::sleep_for(std::chrono::milliseconds(50));
if (host != "")
@ -171,17 +169,16 @@ bool Servo::Initialize(IAshitaCore* ashitaCore, ILogManager* logManager, uint32_ @@ -171,17 +169,16 @@ bool Servo::Initialize(IAshitaCore* ashitaCore, ILogManager* logManager, uint32_
if (!::GetModuleInformation(::GetCurrentProcess(), ::GetModuleHandle("FFXiMain.dll"), &mod, sizeof(MODULEINFO)))
return false;
// Cast the data and scan for the pattern..
std::vector<uint8_t> data((uint8_t*)(uintptr_t)mod.lpBaseOfDll, (uint8_t*)(uintptr_t)mod.lpBaseOfDll + mod.SizeOfImage);
unsigned char* Pointer = (unsigned char*)Ashita::Memory::FindPattern(std::ref(data), (uintptr_t)mod.lpBaseOfDll, "8BCDE87F7????F8B0D7F7F7F7FE87F7F7F7F8BF885??750CB9", 0, 0);
StructPointer = NULL;
if (Pointer != NULL)
auto Pointer = (unsigned char*)Ashita::Memory::FindPattern((uintptr_t)mod.lpBaseOfDll, mod.SizeOfImage, "8BCFE8????????8B0D????????E8????????8BE885??750CB9", 0, 0);
StructPointer = nullptr;
if (Pointer != nullptr)
{
Pointer += 25;
StructPointer = (auto_follow*)(*((DWORD*)Pointer));
}
else
ashitaCore->GetChatManager()->Write("[Servo] Failed to locate required signature for autofollow!");
if (StructPointer)
{
@ -221,7 +218,14 @@ void Servo::Serv() @@ -221,7 +218,14 @@ void Servo::Serv()
hostmask.append("127.0.0.1");
lservAddr.unlock();
hostmask.append(":56556");
publisher.bind(hostmask.c_str());
try {
publisher.bind(hostmask.c_str());
}
catch (...) {
this->m_AshitaCore->GetChatManager()->Write("[Servo] Failed to bind to socket.");
publisher.close();
return;
}
connected = true;
@ -256,7 +260,15 @@ void Servo::ServPos() @@ -256,7 +260,15 @@ void Servo::ServPos()
hostmask.append("127.0.0.1");
lservAddr.unlock();
hostmask.append(":56557");
publisher.bind(hostmask.c_str());
try {
publisher.bind(hostmask.c_str());
}
catch (...) {
this->m_AshitaCore->GetChatManager()->Write("[Servo] Failed to bind to socket.");
publisher.close();
return;
}
if (!connected)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
@ -418,7 +430,7 @@ bool Servo::HandleCommand(const char* szCommand, int iType) @@ -418,7 +430,7 @@ bool Servo::HandleCommand(const char* szCommand, int iType)
cmdParse->GetNextCommand(&arg);
if (arg == "on")
{
log << Chat::Format::RoyalBlue << "Servo started in server mode, with a hostmask of: ";
log << Chat::Format::RoyalBlue << "[Servo] Servo started in server mode, with a hostmask of: ";
while (!lservAddr.try_lock())
std::this_thread::sleep_for(std::chrono::milliseconds(50));
if (cmdParse->GetNextCommand(&arg))
@ -447,7 +459,7 @@ bool Servo::HandleCommand(const char* szCommand, int iType) @@ -447,7 +459,7 @@ bool Servo::HandleCommand(const char* szCommand, int iType)
else if (arg == "off")
{
SetState(ServoMode::Mode::Standby);
log << Chat::Format::RoyalBlue << "Servo set to standy!" << Chat::Control::flush;
log << Chat::Format::RoyalBlue << "[Servo] Servo set to standy!" << Chat::Control::flush;
}
else if (arg == "command" || arg == "send")
{
@ -588,10 +600,10 @@ __declspec(dllexport) void __stdcall CreatePluginInfo(plugininfo_t* lpBuffer) @@ -588,10 +600,10 @@ __declspec(dllexport) void __stdcall CreatePluginInfo(plugininfo_t* lpBuffer)
g_PluginInfo = lpBuffer;
strcpy_s(g_PluginInfo->Name, sizeof(g_PluginInfo->Name), "Servo");
strcpy_s(g_PluginInfo->Author, sizeof(g_PluginInfo->Author), "bluekirby0");
strcpy_s(g_PluginInfo->Author, sizeof(g_PluginInfo->Author), "bluekirby0 & atom0s");
g_PluginInfo->InterfaceVersion = ASHITA_INTERFACE_VERSION;
g_PluginInfo->PluginVersion = 3.00f;
g_PluginInfo->PluginVersion = 3.01f;
g_PluginInfo->Priority = 0;
}

Loading…
Cancel
Save