Skip to content

Commit

Permalink
feat: implement rep, rep group, and group ids, as well as polish more…
Browse files Browse the repository at this point in the history
… of the client id functions.
  • Loading branch information
Lazrius committed Nov 11, 2023
1 parent 8e63970 commit c2ceb40
Show file tree
Hide file tree
Showing 22 changed files with 630 additions and 199 deletions.
2 changes: 1 addition & 1 deletion FLHookSDK
38 changes: 17 additions & 21 deletions include/API/FLServer/Chat.hpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
#pragma once
//TODO: Reimplement DLL loader and De-loader
// TODO: Reimplement DLL loader and De-loader
namespace Hk::Chat
{
DLL Action<void, Error> Msg(const std::variant<uint, std::wstring_view>& player, std::wstring_view message);
DLL Action<void, Error> MsgS(const std::variant<std::wstring_view, uint>& system, std::wstring_view message);
DLL Action<void, Error> MsgU(std::wstring_view message);
DLL Action<void, Error> FMsgEncodeXml(std::wstring_view xml, char* buf, uint size, uint& ret);
DLL Action<void, Error> FMsg(ClientId client, std::wstring_view xml);
DLL Action<void, Error> FMsg(const std::variant<uint, std::wstring_view>& player, std::wstring_view XML);
DLL Action<void, Error> FMsgS(const std::variant<std::wstring_view, uint>& system, std::wstring_view XML);
DLL Action<void, Error> FMsgU(const std::wstring& xml);
DLL std::wstring FormatMsg(MessageColor color, MessageFormat format, const std::wstring& msg);
DLL std::wstring GetWStringFromIdS(uint idS);
DLL Action<void, Error> FormatSendChat(uint toClientId, const std::wstring& sender, const std::wstring& text, const std::wstring& textColor);
DLL void SendGroupChat(uint fromClientId, const std::wstring& text);
DLL void SendLocalSystemChat(uint fromClientId, const std::wstring& text);
DLL Action<void, Error> SendPrivateChat(uint fromClientId, uint toClientId, const std::wstring& text);
DLL void SendSystemChat(uint fromClientId, const std::wstring& text);
DLL void FMsgSendChat(ClientId client, char* buffer, uint size);
// TODO: Move DLL loading and IDS accessing to its own class
DLL void UnloadStringDLLs();
DLL void LoadStringDLLs();
}
DLL Action<void, Error> Msg(const std::variant<uint, std::wstring_view>& player, std::wstring_view message);
DLL Action<void, Error> MsgS(const std::variant<std::wstring_view, uint>& system, std::wstring_view message);
DLL Action<void, Error> MsgU(std::wstring_view message);
DLL Action<void, Error> FMsgEncodeXml(std::wstring_view xml, char* buf, uint size, uint& ret);
DLL Action<void, Error> FMsg(ClientId client, std::wstring_view xml);
DLL Action<void, Error> FMsg(const std::variant<uint, std::wstring_view>& player, std::wstring_view XML);
DLL Action<void, Error> FMsgS(const std::variant<std::wstring_view, uint>& system, std::wstring_view XML);
DLL Action<void, Error> FMsgU(const std::wstring& xml);
DLL std::wstring FormatMsg(MessageColor color, MessageFormat format, const std::wstring& msg);
DLL Action<void, Error> FormatSendChat(uint toClientId, const std::wstring& sender, const std::wstring& text, const std::wstring& textColor);
DLL void SendGroupChat(uint fromClientId, const std::wstring& text);
DLL void SendLocalSystemChat(uint fromClientId, const std::wstring& text);
DLL Action<void, Error> SendPrivateChat(uint fromClientId, uint toClientId, const std::wstring& text);
DLL void SendSystemChat(uint fromClientId, const std::wstring& text);
DLL void FMsgSendChat(ClientId client, char* buffer, uint size);
} // namespace Hk::Chat
14 changes: 5 additions & 9 deletions include/API/Types/BaseId.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#pragma once

#include "API/Types/ClientId.hpp"

class ClientId;

class BaseId
{
const uint value;
Expand All @@ -12,17 +9,16 @@ class BaseId
explicit BaseId(const uint val) : value(val) {}
explicit BaseId(std::wstring_view name, bool isWildCard = false);
explicit operator uint() const noexcept { return value; }
explicit BaseId() : value(0){}
explicit BaseId() : value(0) {}
bool operator==(const BaseId next) const { return value == next.value; }
bool operator!() const; // TODO: Check if BaseId is valid here

Action<std::vector<ClientId>, Error> GetDockedPlayers();
void* GetMarket(); // Grab the bases market data.
std::optional<std::wstring> GetAffiliation();
//TODO: @Laz, look into getting the physical base from abstract baseID.
// TODO: @Laz, look into getting the physical base from abstract baseID.
std::wstring GetName();
// std::pair<std::wstring, uint> GetDescription();

bool ToggleDocking(bool locked); //TODO: THis would be done via the CSolar.
// std::pair<std::wstring, uint> GetDescription();

};
bool ToggleDocking(bool locked); // TODO: THis would be done via the CSolar.
};
53 changes: 39 additions & 14 deletions include/API/Types/ClientId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class ClientId
{
const uint value = 0;

Action<void, Error> AdjustCash(int amount);
[[nodiscard]]
Action<void, Error> AdjustCash(int amount) const;

[[nodiscard]]
bool IsValidClientId() const;

[[nodiscard]]
static uint GetClientIdFromCharacterName(std::wstring_view name);

public:
Expand All @@ -36,41 +38,64 @@ class ClientId

// Type Conversions

Action<std::wstring, Error> GetCharacterName();
[[nodiscard]]
Action<std::wstring, Error> GetCharacterName() const;
// TODO: These eventually will be their own types as well
Action<BaseId, Error> GetCurrentBase();
Action<SystemId, Error> GetSystemId();
Action<CAccount*, Error> GetAccount();
Action<const Archetype::Ship*, Error> GetShipArch();
[[nodiscard]]
Action<BaseId, Error> GetCurrentBase() const;
[[nodiscard]]
Action<SystemId, Error> GetSystemId() const;
[[nodiscard]]
Action<CAccount *, Error> GetAccount() const;
[[nodiscard]]
Action<const Archetype::Ship *, Error> GetShipArch();
[[nodiscard]]
Action<ShipId, Error> GetShipId();
Action<std::list<EquipDesc>, Error> GetEquipment();
Action<CPlayerGroup*, Error> GetGroup();
Action<std::optional<std::wstring>, Error> GetAffiliation();
Action<CShip*, Error> GetShip();
[[nodiscard]]
Action<CPlayerGroup *, Error> GetGroup();
[[nodiscard]]
Action<RepId, Error> GetReputation() const;
[[nodiscard]]
Action<CShip *, Error> GetShip();
[[nodiscard]]
Action<uint, Error> GetRank();
[[nodiscard]]
Action<uint, Error> GetWealth();
[[nodiscard]]
Action<int, Error> GetPvpKills();
[[nodiscard]]
Action<uint, Error> GetCash();
[[nodiscard]]
Action<std::wstring_view, Error> GetActiveCharacterName();
[[nodiscard]]
Action<std::list<CargoInfo>, Error> EnumCargo(int &remainingHoldSize) const;

// State Checks

[[nodiscard]]
bool InSpace();
[[nodiscard]]
bool IsDocked();
bool InCharacterSelect();
[[nodiscard]]
bool InCharacterSelect() const;
[[nodiscard]]
bool IsAlive();

// Manipulation

Action<void, Error> Kick(std::optional<std::wstring_view> reason = {}, std::optional<uint> delay);
Action<void, Error> AddToGroup(uint group);
Action<void, Error> Kick(const std::optional<std::wstring_view> &reason = {}, std::optional<uint> delay);
Action<void, Error> MessageAndKick(std::wstring_view reason, uint delay = 10);
Action<void, Error> SaveChar();
Action<void, Error> SetPvpKills(uint killAmount);
Action<void, Error> AddCash(uint amount);
Action<void, Error> RemoveCash(uint amount);
Action<void, Error> Beam(std::variant<BaseId, std::wstring_view> base);
Action<void, Error> Message(std::wstring message, MessageFormat format = MessageFormat::Normal, MessageColor color = MessageColor::Green);
Action<void, Error> SetRep(std::variant<ushort, std::wstring_view> repGroup, float rep);
Action<void, Error> Rename(std::wstring_view);
void MarkObject(uint objId, int markStatus);

// Chat

Action<void, Error> Message(const std::wstring &message, MessageFormat format = MessageFormat::Normal, MessageColor color = MessageColor::Green) const;
Action<void, Error> MessageFrom(ClientId destinationClient, std::wstring message) const;
};
41 changes: 41 additions & 0 deletions include/API/Types/GroupId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

class GroupId final
{
uint value = 0;

Action<void, Error> ForEachGroupMember(const std::function<std::optional<Error>(ClientId client)>& func, bool stopIfErr = true) const;

template <typename T, T>
struct Proxy;

template <typename T, typename R, typename... Args, R (T::*MemberFunc)(Args...)>
struct Proxy<R (T::*)(Args...), MemberFunc>
{
static R Call(T& obj, Args&&... args) { return (obj.*MemberFunc)(std::forward<Args>(args)...); }
};

public:
explicit GroupId(const uint val) : value(val) {}
explicit GroupId() = default;
~GroupId() = default;
GroupId(const GroupId&) = default;
GroupId& operator=(GroupId) = default;
GroupId(GroupId&&) = default;
GroupId& operator=(GroupId&&) = delete;

bool operator==(const GroupId& next) const { return value == next.value; }
explicit operator bool() const { return value != 0; }

uint GetValue() const { return value; }

Action<std::vector<ClientId>, Error> GetGroupMembers() const;
Action<uint, Error> GetGroupSize() const;

template <typename FunctionPtr, typename... Args>
requires std::is_same_v<typename MemberFunctionPointerClassType<FunctionPtr>::type, ClientId>
Action<void, Error> GroupAction(FunctionPtr ptr, bool stopIfErr, Args... args) const
{
return ForEachGroupMember([ptr, args](ClientId client) { Proxy<void (ClientId::*)(), ptr>::Call(client, args...); }, stopIfErr);
}
};
7 changes: 3 additions & 4 deletions include/API/Types/ObjectId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ class ObjectId
explicit ObjectId() = default;
virtual ~ObjectId() = default;
ObjectId(const ObjectId&) = default;
ObjectId& operator=(ObjectId) = default;
ObjectId& operator=(ObjectId) = delete;
ObjectId(ObjectId&&) = default;
ObjectId& operator=(ObjectId&&) = delete;

bool operator==(const ObjectId& next) const { return value == next.value; }
explicit virtual operator bool() const;

uint GetValue() const { return value; }

[[nodiscard]]
Action<CObject::Class, Error> GetObjectType() const;

[[nodiscard]]
Action<std::wstring, Error> GetNickName() const;

[[nodiscard]]
Action<std::wstring, Error> GetName() const;

[[nodiscard]]
Action<CObjPtr, Error> GetCObject(bool increment = false) const;

Expand Down
23 changes: 23 additions & 0 deletions include/API/Types/RepGroupId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

class RepGroupId final
{
uint value = 0;

public:
explicit RepGroupId(const uint val) : value(val) {}
explicit RepGroupId() = default;
~RepGroupId() = default;
RepGroupId(const RepGroupId&) = default;
RepGroupId& operator=(RepGroupId) = delete;
RepGroupId(RepGroupId&&) = default;
RepGroupId& operator=(RepGroupId&&) = delete;

bool operator==(const RepGroupId& next) const { return value == next.value; }
explicit operator bool() const { return value != 0; };

uint GetValue() const { return value; }

Action<std::wstring_view, Error> GetName() const;
Action<std::wstring_view, Error> GetShortName() const;
};
32 changes: 32 additions & 0 deletions include/API/Types/RepId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
#include "RepGroupId.hpp"

class RepId final
{
int value = 0;

public:
explicit RepId(const ObjectId& spaceObj, bool isSolar);
explicit RepId(const int val) : value(val) {}
explicit RepId() = default;
~RepId() = default;
RepId(const RepId&) = default;
RepId& operator=(RepId) = delete;
RepId(RepId&&) = default;
RepId& operator=(RepId&&) = delete;

bool operator==(const RepId& next) const { return value == next.value; }
explicit operator bool() const;

int GetValue() const { return value; }

Action<RepGroupId, Error> GetAffiliation() const;
Action<float, Error> GetAttitudeTowardsRepId(const RepId& target) const;
Action<float, Error> GetAttitudeTowardsFaction(const RepGroupId& group) const;
Action<int, Error> GetRank() const;
Action<std::pair<FmtStr, FmtStr>, Error> GetName() const;

Action<void, Error> SetRank(int rank) const;
Action<void, Error> SetAttitudeTowardsRepId(RepId target, float newAttitude) const;
Action<void, Error> SetAffiliation(RepGroupId group) const;
};
44 changes: 34 additions & 10 deletions include/API/Types/ShipId.hpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
#pragma once

#include "ObjectId.hpp"

class SystemId;
#include "RepId.hpp"

class ShipId final : ObjectId
{
public:
explicit ShipId(const uint val) : ObjectId(val) {}
explicit ShipId() {}

Action<CShipPtr, Error> GetCShip(bool increment) const;
[[nodiscard]]
Action<CShipPtr, Error> GetCShip(bool increment);
Action<Archetype::Ship*, Error> GetShipArchetype();
Action<float,Error> GetHealth(bool percentage = false);
st6::list<EquipDesc>& GetEquipment(); // TODO: We should define a lambda to make it easy for people to get Equip lists.
Action<float,Error> GetShields(bool percentage = false);
void* GetCargo(); // TODO: Similar to equipment but for cargo (duh).
Action<float, Error> GetHealth(bool percentage = false);
Action<float, Error> GetShields(bool percentage = false);
void* GetNpcPersonality();
std::optional<ShipId> GetTarget();
Action<RepId, Error> GetReputation();
std::wstring GetAffiliation();
// TODO: AI states such as formation, go to, dock etc.
Action<float,Error> GetSpeed();
Action<float, Error> GetSpeed();

bool IsPlayer();
bool IsNpc();
bool IsInTradeLane();

void Destroy(DestroyType type = DestroyType::Fuse);
Action<void,Error> SetHealth(float amount, bool percentage = false);
Action<void,Error> AddCargo(std::wstring good, int count, bool mission);
Action<void, Error> SetHealth(float amount, bool percentage = false);
Action<void, Error> AddCargo(uint good, uint count, bool mission);
void SetEquip(const st6::list<EquipDesc>& equip);
void AddEquip(uint goodId, const std::wstring& hardpoint);
void Relocate(Vector, std::optional<Matrix> orientation);

template <typename EquipType = CEquip>
requires std::is_base_of_v<CEquip, EquipType>
Action<std::list<EquipType*>, Error> GetEquipment(EquipmentClass equipmentType = EquipmentClass::All)
{
auto ship = GetCShip(false).Unwrap();
if (!ship)
{
return { cpp::fail(Error::InvalidShip) };
}

CEquipTraverser traverser(equipmentType);
CEquipManager* manager = GetEquipManager(ship.get());
CEquip* equip = manager->Traverse(traverser);

std::list<EquipType*> equipment;

while (equip)
{
equipment.emplace_back(static_cast<EquipType*>(equip));
equip = manager->Traverse(traverser);
}

return { equipment };
}
};
2 changes: 1 addition & 1 deletion include/Core/FLHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ class FLHook final
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; }
static InfocardManager& GetInfocardManager() { return instance->infocardManager; }
};
2 changes: 1 addition & 1 deletion include/Defs/Structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct BaseInfo

struct GroupMember
{
ClientId client;
uint client;
std::wstring character;
};

Expand Down
Loading

0 comments on commit c2ceb40

Please sign in to comment.