-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
class FLHook; | ||
class InfocardManager | ||
{ | ||
std::map<uint, std::wstring> infocardOverride; | ||
std::vector<HMODULE> loadedDlls; | ||
|
||
InfocardManager(); | ||
~InfocardManager(); | ||
|
||
public: | ||
InfocardManager(const InfocardManager&) = delete; | ||
InfocardManager& operator=(InfocardManager) = delete; | ||
InfocardManager(InfocardManager&&) = delete; | ||
InfocardManager& operator=(InfocardManager&&) = delete; | ||
|
||
std::wstring_view GetInfocard(uint ids) const; | ||
|
||
/** | ||
* \brief Allows you to override the specified infocard number with a new string. This functionality will be limited to server-side only without a | ||
* client hook. \param ids The infocard/name number that you wish to replace, this does not technically need to exist already. \param override The | ||
* string that you would like to replace it with. \param client An optional client id to only override an infocard for one client in particular. | ||
* Otherwise the change will be sent to all connected clients. | ||
*/ | ||
void OverrideInfocard(uint ids, const std::wstring& override, ClientId client = ClientId()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "PCH.hpp" | ||
|
||
#include "API/FLHook/InfocardManager.hpp" | ||
|
||
InfocardManager::InfocardManager() | ||
{ | ||
HINSTANCE hDll = LoadLibraryExW(L"resources.dll", nullptr, LOAD_LIBRARY_AS_DATAFILE); // typically resources.dll | ||
if (hDll) | ||
{ | ||
loadedDlls.push_back(hDll); | ||
} | ||
|
||
INI_Reader ini; | ||
if (!ini.open("freelancer.ini", false)) | ||
{ | ||
return; | ||
} | ||
|
||
if (!ini.find_header("Resources")) | ||
{ | ||
ini.close(); | ||
return; | ||
} | ||
|
||
while (ini.read_value()) | ||
{ | ||
if (!ini.is_value("DLL")) | ||
{ | ||
continue; | ||
} | ||
|
||
// TODO: Log loaded dll file | ||
hDll = LoadLibraryExA(ini.get_value_string(0), nullptr, LOAD_LIBRARY_AS_DATAFILE); | ||
if (hDll) | ||
{ | ||
loadedDlls.push_back(hDll); | ||
} | ||
} | ||
|
||
ini.close(); | ||
} | ||
|
||
InfocardManager::~InfocardManager() | ||
{ | ||
for (const auto& dll : loadedDlls) | ||
{ | ||
// TODO: Log unloaded dll file | ||
FreeLibrary(dll); | ||
} | ||
} | ||
|
||
std::wstring_view InfocardManager::GetInfocard(const uint ids) const | ||
{ | ||
if (const auto found = infocardOverride.find(ids); found != infocardOverride.end()) | ||
{ | ||
return { found->second.data(), found->second.size() }; | ||
} | ||
|
||
wchar_t* destStr; | ||
const size_t length = LoadStringW(loadedDlls[ids >> 16], ids & 0xFFFF, reinterpret_cast<wchar_t*>(&destStr), 0); | ||
|
||
return { destStr, length }; | ||
} | ||
|
||
void InfocardManager::OverrideInfocard(const uint ids, const std::wstring& override, ClientId client) | ||
{ | ||
infocardOverride[ids] = override; | ||
// TODO: Send update to client | ||
} |