Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,34 @@ int WINAPI Mine_connect(SOCKET s, const sockaddr* name, int namelen)
return ret;
}

/**
* @brief Locates profile server port addresses and sets the profile server port
*
* @return Failed to find the patterns or succeeded to write
*/
bool SetProfileServerPort(uint16_t profileServerPort)
{
const char* module = (globals::g_Language == xiloader::Language::European) ? "polcoreeu.dll" : "polcore.dll";
auto profileServerPortAddress = (DWORD)xiloader::functions::FindPattern(module, (BYTE*)"\x66\xC7\x46\x26\x14\xC8\x88\x46\x09\x8D\x46\x24", "xxxxxxxxxxx");
if (profileServerPortAddress == 0)
{
xiloader::console::output(xiloader::color::error, "Failed to locate profileServerPortAddress!");
return false;
}

auto profileServerPortAddress2 = (DWORD)xiloader::functions::FindPattern(module, (BYTE*)"\x66\xC7\x05\xBA\x4A\x3F\x04\x14\xC8", "xxxxx??xx"); // This pattern changed slightly on a few month old polcore, it used to be a total match but some bytes changed.
if (profileServerPortAddress2 == 0)
{
xiloader::console::output(xiloader::color::error, "Failed to locate profileServerPortAddress2!");
return false;
}

*((uint16_t*)(profileServerPortAddress + 4)) = profileServerPort;
*((uint16_t*)(profileServerPortAddress2 + 7)) = profileServerPort;

return true;
}

/**
* @brief Locates the INET mutex function call inside of polcore.dll
*
Expand Down Expand Up @@ -701,6 +729,15 @@ int __cdecl main(int argc, char* argv[])
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ApplyHairpinFixThread, NULL, 0, NULL);
}

struct sockaddr_in pol_sin;
int pol_len = sizeof(pol_sin);
unsigned short profileServerPort = 0;

if (getsockname(polsock, (struct sockaddr*)&pol_sin, &pol_len) == 0)
{
profileServerPort = ntohs(pol_sin.sin_port);
}

/* Create listen servers.. */
globals::g_IsRunning = true;
HANDLE hFFXiServer = CreateThread(NULL, 0, xiloader::network::FFXiServer, &sock, 0, NULL);
Expand Down Expand Up @@ -747,6 +784,11 @@ int __cdecl main(int argc, char* argv[])
lpCommandTable[POLFUNC_INSTALL_FOLDER](xiloader::functions::GetRegistryPlayOnlineInstallFolder(globals::g_Language));
lpCommandTable[POLFUNC_INET_MUTEX]();

if (!SetProfileServerPort(profileServerPort))
{
return 1;
}

/* Attempt to create FFXi instance..*/
IFFXiEntry* ffxi = NULL;
if (CoCreateInstance(xiloader::CLSID_FFXiEntry, NULL, 0x17, xiloader::IID_IFFXiEntry, (LPVOID*)&ffxi) != S_OK)
Expand Down
2 changes: 1 addition & 1 deletion src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace xiloader
sockaddr_in sin = {};
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
sin.sin_port = htons(51220);
sin.sin_port = htons(0);

/* Create the listening socket.. */
*sock = socket(AF_INET, protocol == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM, protocol);
Expand Down