Some cleanup

This commit is contained in:
momo5502 2020-04-17 21:29:34 +02:00
parent bd7bdaeda2
commit 64a90a5573
26 changed files with 80 additions and 45 deletions

View File

@ -266,7 +266,7 @@ namespace demonware
bool byte_buffer::write(const int bytes, const void* data)
{
this->buffer_.append(reinterpret_cast<const char*>(data), bytes);
this->buffer_.append(static_cast<const char*>(data), bytes);
this->current_byte_ += bytes;
return true;
}

View File

@ -9,7 +9,7 @@ namespace demonware
public:
std::string file_data;
explicit bdFileData(const std::string& buffer) : file_data(buffer)
explicit bdFileData(std::string buffer) : file_data(std::move(buffer))
{
}
@ -165,11 +165,11 @@ namespace demonware
void deserialize(byte_buffer* buffer) override
{
int size;
char* data;
int size{};
char* data{};
buffer->read_blob(&data, &size);
if (data && size >= sizeof this->session_id)
if (data && uint32_t(size) >= sizeof(this->session_id))
{
this->session_id = *reinterpret_cast<uint64_t*>(data);
}

View File

@ -19,8 +19,8 @@ namespace demonware
buffer.read_uint32(&seed);
buffer.read_uint32(&title_id);
unsigned char rsakey[140];
buffer.read_bytes(sizeof(rsakey), rsakey);
unsigned char rsa_key[140];
buffer.read_bytes(sizeof(rsa_key), rsa_key);
uint8_t ticket[1024];
buffer.read_bytes(std::min(ticket_size, static_cast<uint32_t>(sizeof(ticket))), ticket);
@ -52,9 +52,9 @@ namespace demonware
register_hash(&sha1_desc);
register_prng(&yarrow_desc);
std::string encrypted_key = utils::cryptography::rsa::encrypt(std::string(SERVER_CD_KEY, 24),
auto encrypted_key = utils::cryptography::rsa::encrypt(std::string(SERVER_CD_KEY, 24),
std::string("DW-RSAENC", 10),
std::string(PCHAR(rsakey), sizeof(rsakey)));
std::string(PCHAR(rsa_key), sizeof(rsa_key)));
bit_buffer response;
response.set_use_data_types(false);

View File

@ -264,7 +264,7 @@ namespace demonware
const auto path = get_user_file_path(filename);
utils::io::write_file(path, data);
auto info = new bdFileInfo;
auto* info = new bdFileInfo;
info->file_id = *reinterpret_cast<const uint64_t*>(utils::cryptography::sha1::compute(filename).data());
info->filename = filename;
@ -281,7 +281,7 @@ namespace demonware
void bdStorage::get_user_file(i_server* server, byte_buffer* buffer) const
{
uint64_t owner;
uint64_t owner{};
std::string game, filename, platform, data;
buffer->read_string(&game);

View File

@ -3,12 +3,15 @@
#include "loader/loader.hpp"
#include "loader/module_loader.hpp"
#include "game/game.hpp"
#include "loader/binary_loader.hpp"
#include "utils/string.hpp"
#include "utils/flags.hpp"
//#define GENERATE_DIFFS
#ifdef GENERATE_DIFFS
#include "loader/binary_loader.hpp"
#endif
DECLSPEC_NORETURN void WINAPI exit_hook(const int code)
{
module_loader::pre_destroy();
@ -18,11 +21,8 @@ DECLSPEC_NORETURN void WINAPI exit_hook(const int code)
void verify_tls()
{
const utils::nt::module self;
const auto self_tls = reinterpret_cast<PIMAGE_TLS_DIRECTORY>(self.get_ptr() + self
.get_optional_header()
->
DataDirectory
[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress);
const auto self_tls = reinterpret_cast<PIMAGE_TLS_DIRECTORY>(self.get_ptr()
+ self.get_optional_header()->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress);
const auto ref = DWORD(&tls_data);
const auto tls_index = *reinterpret_cast<DWORD*>(self_tls->AddressOfIndex);

View File

@ -36,7 +36,7 @@ private:
static void launch_game(const bool singleplayer)
{
utils::nt::module self;
const utils::nt::module self;
STARTUPINFOA s_info;
PROCESS_INFORMATION p_info;

View File

@ -1,7 +1,6 @@
#include <std_include.hpp>
#include "scheduler.hpp"
#include "utils/string.hpp"
#include "game/structs.hpp"
#include "game/game.hpp"
#include "utils/hook.hpp"
@ -60,8 +59,8 @@ void scheduler::execute_safe()
void scheduler::execute_error()
{
const char* message;
int level;
const char* message = nullptr;
int level = 0;
if (get_next_error(&message, &level) && message)
{

View File

@ -120,13 +120,13 @@ private:
static void start_execution_stub()
{
module_loader::get<scripting>()->start_execution();
reinterpret_cast<void(*)()>(start_hook_.get_original())();
static_cast<void(*)()>(start_hook_.get_original())();
}
static void stop_execution_stub()
{
module_loader::get<scripting>()->stop_execution();
reinterpret_cast<void(*)()>(stop_hook_.get_original())();
static_cast<void(*)()>(stop_hook_.get_original())();
}
static void vm_notify_stub(const unsigned int notify_id, const unsigned short type,
@ -142,7 +142,7 @@ private:
//printf("%X: %s\n", e.entity_id, e.name.data());
for (auto value = stack; value->type != game::native::SCRIPT_END; --value)
for (auto* value = stack; value->type != game::native::SCRIPT_END; --value)
{
e.arguments.emplace_back(*value);
}

View File

@ -12,8 +12,9 @@ namespace steam
};
template <size_t X, size_t ... Xs>
struct argument_size_calculator<X, Xs...> final : std::integral_constant<
size_t, X + ((argument_size_calculator<Xs...>::value + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1))>
struct argument_size_calculator<X, Xs...> final
: std::integral_constant<size_t, X + ((argument_size_calculator<Xs...>::value
+ (sizeof(void*) - 1)) & ~(sizeof(void*) - 1))>
{
};

View File

@ -2,8 +2,11 @@
namespace steam
{
class apps final
class apps
{
protected:
~apps() = default;
public:
virtual bool BIsSubscribed();
virtual bool BIsLowViolence();

View File

@ -2,8 +2,11 @@
namespace steam
{
class friends final
class friends
{
protected:
~friends() = default;
public:
virtual const char* GetPersonaName();
virtual void SetPersonaName(const char* pchPersonaName);

View File

@ -2,8 +2,11 @@
namespace steam
{
class game_server final
class game_server
{
protected:
~game_server() = default;
public:
virtual void LogOn();
virtual void LogOff();

View File

@ -2,8 +2,11 @@
namespace steam
{
class master_server_updater final
class master_server_updater
{
protected:
~master_server_updater() = default;
public:
virtual void SetActive(bool bActive);
virtual void SetHeartbeatInterval(int iHeartbeatInterval);

View File

@ -21,8 +21,11 @@ namespace steam
int m_e_chat_room_enter_response;
};
class matchmaking final
class matchmaking
{
protected:
~matchmaking() = default;
public:
virtual int GetFavoriteGameCount();
virtual bool GetFavoriteGame(int iGame, unsigned int* pnAppID, unsigned int* pnIP, unsigned short* pnConnPort,

View File

@ -2,8 +2,11 @@
namespace steam
{
class matchmaking_servers final
class matchmaking_servers
{
protected:
~matchmaking_servers() = default;
public:
virtual void* RequestInternetServerList(unsigned int iApp, void** ppchFilters, unsigned int nFilters,
void* pRequestServersResponse);

View File

@ -2,8 +2,11 @@
namespace steam
{
class networking final
class networking
{
protected:
~networking() = default;
public:
virtual bool SendP2PPacket(steam_id steamIDRemote, const void* pubData, unsigned int cubData, int eP2PSendType);
virtual bool IsP2PPacketAvailable(unsigned int* pcubMsgSize, int idk);

View File

@ -2,8 +2,11 @@
namespace steam
{
class remote_storage final
class remote_storage
{
protected:
~remote_storage() = default;
public:
virtual bool FileWrite(const char* pchFile, const void* pvData, int cubData);
virtual int GetFileSize(const char* pchFile);

View File

@ -9,8 +9,11 @@ namespace steam
int m_e_result;
};
class user final
class user
{
protected:
~user() = default;
public:
virtual int GetHSteamUser();
virtual bool LoggedOn();

View File

@ -2,8 +2,11 @@
namespace steam
{
class user_stats final
class user_stats
{
protected:
~user_stats() = default;
public:
virtual bool RequestCurrentStats();
virtual bool GetStat(const char* pchName, int* pData);

View File

@ -2,8 +2,11 @@
namespace steam
{
class utils final
class utils
{
protected:
~utils() = default;
public:
virtual unsigned int GetSecondsSinceAppActive();
virtual unsigned int GetSecondsSinceComputerActive();

View File

@ -64,6 +64,8 @@ namespace steam
void set_i_callback(const int i_callback) { callback_ = i_callback; }
protected:
~base() = default;
unsigned char flags_;
int callback_;
};

View File

@ -7,7 +7,7 @@ namespace utils
{
if (this->signatures_.empty()) return;
const auto start = reinterpret_cast<char*>(this->start_);
const auto start = static_cast<char*>(this->start_);
const unsigned int sig_count = this->signatures_.size();
const auto containers = this->signatures_.data();

View File

@ -91,7 +91,7 @@ namespace utils
bool memory::is_set(const void* mem, const char chr, const size_t length)
{
const auto mem_arr = reinterpret_cast<const char*>(mem);
const auto mem_arr = static_cast<const char*>(mem);
for (size_t i = 0; i < length; ++i)
{

View File

@ -16,16 +16,16 @@ namespace utils
void free(const void* data);
void* allocate(const size_t length);
void* allocate(size_t length);
template <typename T>
inline T* allocate()
T* allocate()
{
return this->allocate_array<T>(1);
}
template <typename T>
inline T* allocate_array(const size_t count = 1)
T* allocate_array(const size_t count = 1)
{
return static_cast<T*>(this->allocate(count * sizeof(T)));
}

View File

@ -11,7 +11,7 @@ namespace utils::nt
module module::get_by_address(void* address)
{
HMODULE handle = nullptr;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCSTR>(address), &handle);
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast<LPCSTR>(address), &handle);
return module(handle);
}

View File

@ -45,7 +45,7 @@ namespace utils::nt
std::function<T> get(const std::string& process) const
{
if (!this->is_valid()) std::function<T>();
return reinterpret_cast<T*>(this->get_proc<void*>(process));
return static_cast<T*>(this->get_proc<void*>(process));
}
template <typename T, typename... Args>