Skip to content

Commit

Permalink
feat: add infocard manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazrius committed Nov 11, 2023
1 parent 6d3163b commit f40747d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
27 changes: 27 additions & 0 deletions include/API/FLHook/InfocardManager.hpp
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());
};
4 changes: 4 additions & 0 deletions include/Core/FLHook.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "API/FLHook/InfocardManager.hpp"
#include "AddressList.hpp"
#include "ClientServerInterface.hpp"
#include "StartupCache.hpp"
Expand Down Expand Up @@ -89,6 +90,7 @@ class FLHook final
// Non-Static things

std::unique_ptr<StartupCache> startupCache;
InfocardManager infocardManager;

bool OnServerStart();
void InitHookExports();
Expand Down Expand Up @@ -138,4 +140,6 @@ class FLHook final
static const std::list<BaseInfo>& GetBases() { return instance->allBases; }
static std::wstring_view GetAccountPath() { return instance->accPath; }
static bool GetShipInspect(uint& ship, IObjInspectImpl*& inspect, uint& dunno) { return getShipInspect(ship, inspect, dunno); }

InfocardManager& GetInfocardManager() { return infocardManager; }
};
1 change: 1 addition & 0 deletions project/FLHook.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Global_0020variables/@EntryIndexedValue">&lt;NamingElement Priority="7"&gt;&lt;Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"&gt;&lt;type Name="global variable" /&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="g_" Suffix="" Style="AaBb" /&gt;&lt;/NamingElement&gt;</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dlls/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hardpoint/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=iter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nullopt/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 2 additions & 0 deletions project/FLHook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\source\API\Api.cpp" />
<ClCompile Include="..\source\API\FLHook\InfocardManager.cpp" />
<ClCompile Include="..\Source\API\FLHook\Mail.cpp" />
<ClCompile Include="..\Source\API\FLHook\MessageHandler.cpp" />
<ClCompile Include="..\Source\API\FLServer\Admin.cpp" />
Expand Down Expand Up @@ -116,6 +117,7 @@
<ClInclude Include="..\FLHookSDK\include\Utils\Utils.hpp" />
<ClInclude Include="..\Include\API\API.hpp" />
<ClInclude Include="..\include\API\FLHook\ClientInfo.hpp" />
<ClInclude Include="..\include\API\FLHook\InfocardManager.hpp" />
<ClInclude Include="..\Include\API\FLHook\MailManager.hpp" />
<ClInclude Include="..\Include\API\FLHook\Plugin.hpp" />
<ClInclude Include="..\Include\API\FLServer\Admin.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions project/FLHook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@
<ClCompile Include="..\source\API\Types\ShipId.cpp">
<Filter>Source\API\Types</Filter>
</ClCompile>
<ClCompile Include="..\source\API\FLHook\InfocardManager.cpp">
<Filter>Source\API\FLHook</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Include\Core\Commands\AbstractAdminCommandProcessor.hpp">
Expand Down Expand Up @@ -534,6 +537,9 @@
<ClInclude Include="..\FLHookSDK\include\Exceptions\InvalidPtrException.hpp">
<Filter>Include\SDK\Exceptions</Filter>
</ClInclude>
<ClInclude Include="..\include\API\FLHook\InfocardManager.hpp">
<Filter>Include\API\FLHook</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
69 changes: 69 additions & 0 deletions source/API/FLHook/InfocardManager.cpp
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
}

0 comments on commit f40747d

Please sign in to comment.