Skip to content

Commit

Permalink
feat: account/character loading in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazrius committed Jan 16, 2024
1 parent e92baa0 commit ca37e2a
Show file tree
Hide file tree
Showing 16 changed files with 1,835 additions and 179 deletions.
2 changes: 1 addition & 1 deletion FLHookSDK
106 changes: 106 additions & 0 deletions include/API/FLHook/AccountManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#pragma once

#include "Utils/Detour.hpp"

class AccountManager
{
friend FLHook;
friend IServerImplHook;
inline static AccountManager* instance = nullptr;

inline static struct NewPlayerTemplate
{
std::string initialRep;
int rank = 0;
int money = 0;
std::string costume;
std::string commCostume;
std::string system;
std::string base;
std::map<std::string, float> reputationOverrides;
std::map<uint, uint> visitValues;
bool hasPackage = false;
} newPlayerTemplate;

struct VanillaLoadData
{
uint padding[128];
st6::wstring name; // 512
st6::wstring description; // 528
uint descripStrId; // 532
uint datetimeHigh;
uint datetimeLow;
uint shipHash; // 544
uint money; // 548
uint numOfKills; // 552
uint numOfSuccessMissions; // 556
uint numOfFailedMissions; // 560
float hullStatus; // 564
st6::list<EquipDesc> currentEquipAndCargo; // 572
st6::list<CollisionGroupDesc> currentCollisionGroups;
float baseHullStatus; // 592
st6::list<EquipDesc> baseEquipAndCargo; // 600
st6::list<CollisionGroupDesc> baseCollisionGroups;
uint currentBase; // 620
uint lastDockedBase; // 624
uint currentRoom; // 628
uint system; // 632
Vector pos;
Matrix rot;
uint startingRing;
uint rank; // 688
uint unused1; // 692
st6::vector<uint> someBinaryTreeAboutGroups; // SP only
Costume costume; // 712
uint voiceLen; // 764
char voice[32]; // 768
Costume baseCostume; // 800
uint tempCargoIdEnumerator; // 852
st6::string prefilledWeaponGroupIni; // 860
st6::list<FmtStr> neuralNetLog; // 872 - probably wrong, 'log' entries from character file. Also 'mostly' SP only.
uint interfaceState; // 884
uint unused2; // 888
BinarySearchTree<uint> visitLists; // actually binary search tree
};

struct AccountData
{
CAccount* account;
std::map<std::string, VanillaLoadData> characters;
};

inline static std::array<AccountData, 256> accounts;

enum class LoginReturnCode
{
Banned,
AlreadyLoggedIn,
InvalidUsernamePassword,
Success
};

// The current account string we are loading
std::wstring currentAccountString;
static void LoadCharacter(VanillaLoadData* data, std::wstring_view characterName);
LoginReturnCode AccountLoginInternal(PlayerData* data, uint clientId);
static void LoadNewPlayerFLInfo();

// Detours/Assembly
using DbInitType = void(__fastcall*)(PlayerDB* db, void* edx, uint unk, bool unk2);
using OnPlayerSaveType = bool(__fastcall*)(PlayerData* data);
using OnCreateNewCharacterType = bool(__fastcall*)(PlayerData* data, void* edx, SCreateCharacterInfo* character);

inline static std::unique_ptr<FunctionDetour<DbInitType>> dbInitDetour;
inline static std::unique_ptr<FunctionDetour<OnPlayerSaveType>> onPlayerSaveDetour;
inline static std::unique_ptr<FunctionDetour<OnCreateNewCharacterType>> onCreateNewCharacterDetour;
bool static __fastcall OnCreateNewCharacter(PlayerData* data, void* edx, SCreateCharacterInfo* character);
bool static __fastcall OnPlayerSave(PlayerData* data);
void static __fastcall PlayerDbInitDetour(PlayerDB* db, void* edx, uint unk, bool unk2);
void static PlayerDbLoadUserDataNaked();

AccountManager();

public:
void DeleteCharacter(const std::wstring& characterName);
void OnLogin(const ClientId& client);
};
4 changes: 3 additions & 1 deletion include/Core/FLHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TempBanManager;
class FlPacket;
class PersonalityHelper;
class Database;
class AccountManager;

class FLHook final
{
Expand Down Expand Up @@ -94,12 +95,12 @@ class FLHook final

// Non-Static things

StartupCache* startupCache;
ClientList* clientList;
Database* database;
InfocardManager* infocardManager;
TempBanManager* tempbanManager;
PersonalityHelper* personalityHelper;
AccountManager* accountManager;

bool OnServerStart();
void InitHookExports();
Expand Down Expand Up @@ -166,6 +167,7 @@ class FLHook final
static TempBanManager& GetTempBanManager() { return *instance->tempbanManager; }
static LastHitInformation GetLastHitInformation() { return { nonGunHitsBase, lastHitPts, dmgToClient, dmgToSpaceId }; }
static Action<pub::AI::Personality, Error> GetPersonality(const std::wstring& pilotNickname);
static AccountManager& GetAccountManager() { return *instance->accountManager; }

static Action<void, Error> MessageUniverse(std::wstring_view message);
};
30 changes: 0 additions & 30 deletions include/Core/StartupCache.hpp

This file was deleted.

Loading

0 comments on commit ca37e2a

Please sign in to comment.