Merge branch 'master'
This commit is contained in:
commit
45f7b15612
@ -25,6 +25,10 @@ newaction {
|
||||
if oldVersionHeader ~=nil then
|
||||
local oldVersionHeaderContent = assert(oldVersionHeader:read('*a'))
|
||||
oldRevNumber = string.match(oldVersionHeaderContent, "#define REVISION (%d+)")
|
||||
if oldRevNumber == nil then
|
||||
-- old version.hpp format?
|
||||
oldRevNumber = "(none)"
|
||||
end
|
||||
end
|
||||
|
||||
-- generate version.hpp with a revision number if not equal
|
||||
|
@ -27,6 +27,7 @@ namespace Components
|
||||
Loader::Register(new UIFeeder());
|
||||
Loader::Register(new UIScript());
|
||||
Loader::Register(new FastFiles());
|
||||
Loader::Register(new Discovery());
|
||||
Loader::Register(new Materials());
|
||||
Loader::Register(new FileSystem());
|
||||
Loader::Register(new QuickPatch());
|
||||
|
@ -38,6 +38,7 @@ namespace Components
|
||||
#include "Modules\UIFeeder.hpp"
|
||||
#include "Modules\UIScript.hpp"
|
||||
#include "Modules\Dedicated.hpp"
|
||||
#include "Modules\Discovery.hpp"
|
||||
#include "Modules\FastFiles.hpp"
|
||||
#include "Modules\Materials.hpp"
|
||||
#include "Modules\Singleton.hpp"
|
||||
|
24
src/Components/Modules/Discovery.cpp
Normal file
24
src/Components/Modules/Discovery.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "..\..\STDInclude.hpp"
|
||||
#include <future>
|
||||
|
||||
namespace Components
|
||||
{
|
||||
Discovery::Discovery()
|
||||
{
|
||||
Command::Add("bcast", [] (Command::Params params)
|
||||
{
|
||||
std::async([]()
|
||||
{
|
||||
int start = Game::Com_Milliseconds();
|
||||
OutputDebugStringA("Start!");
|
||||
Network::BroadcastAll("getinfo xxx\n");
|
||||
OutputDebugStringA(Utils::VA("End: %d", Game::Com_Milliseconds() - start));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Discovery::~Discovery()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
10
src/Components/Modules/Discovery.hpp
Normal file
10
src/Components/Modules/Discovery.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Components
|
||||
{
|
||||
class Discovery : public Component
|
||||
{
|
||||
public:
|
||||
Discovery();
|
||||
~Discovery();
|
||||
const char* GetName() { return "Discovery"; };
|
||||
};
|
||||
}
|
@ -29,10 +29,31 @@ namespace Components
|
||||
return key;
|
||||
}
|
||||
|
||||
void __stdcall Localization::SetStringStub(const char* key, const char* value, bool isEnglish)
|
||||
{
|
||||
Localization::Set(key, value);
|
||||
}
|
||||
|
||||
DWORD Localization::SELoadLanguageStub()
|
||||
{
|
||||
//'official' iw4m localized strings
|
||||
Game::SE_Load("localizedstrings/iw4m.str", 0);
|
||||
|
||||
return Utils::Hook::Call<DWORD()>(0x629E20)();
|
||||
}
|
||||
|
||||
Localization::Localization()
|
||||
{
|
||||
// Resolving hook
|
||||
Utils::Hook(0x629B90, Localization::Get, HOOK_JUMP).Install()->Quick();
|
||||
|
||||
// Set loading entry point
|
||||
Utils::Hook(0x41D859, Localization::SELoadLanguageStub, HOOK_CALL).Install()->Quick();
|
||||
|
||||
// Overwrite SetString
|
||||
Utils::Hook(0x4CE5EE, Localization::SetStringStub, HOOK_CALL).Install()->Quick();
|
||||
|
||||
// TODO: Get rid of those!
|
||||
Localization::Set("MENU_SEARCHINGFORGAMES_100MS", "");
|
||||
Localization::Set("MP_SEARCHING_FOR_PLAYER", "Waiting");
|
||||
Localization::Set("MENU_WAITING_FOR_MORE_PLAYERS_TEAMS", "Waiting for more players to balance teams");
|
||||
@ -59,10 +80,6 @@ namespace Components
|
||||
Localization::Set("PLATFORM_REFRESH_LIST", "Refresh List ^0- ^3F5");
|
||||
Localization::Set("PLATFORM_REFRESH_LIST_CAPS", "REFRESH LIST ^0- ^3F5");
|
||||
|
||||
// Don't perform non-english localization here, do it in fastfiles instead
|
||||
//Localization::Set("MP_SEARCHING_FOR_PLAYER", "Warte");
|
||||
//Localization::Set("MENU_WAITING_FOR_MORE_PLAYERS_TEAMS", "Auf weitere Spieler zum Teamausgleich warten");
|
||||
|
||||
Localization::UseLocalization = Dvar::Register<bool>("ui_localize", true, Game::dvar_flag::DVAR_FLAG_NONE, "Use localization strings");
|
||||
}
|
||||
|
||||
|
@ -13,5 +13,8 @@ namespace Components
|
||||
private:
|
||||
static std::map<std::string, std::string> LocalizeMap;
|
||||
static Dvar::Var UseLocalization;
|
||||
|
||||
static void __stdcall SetStringStub(const char* key, const char* value, bool isEnglish);
|
||||
static DWORD SELoadLanguageStub();
|
||||
};
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ namespace Components
|
||||
}
|
||||
void Network::Address::SetPort(unsigned short port)
|
||||
{
|
||||
this->address.port = port;
|
||||
this->address.port = htons(port);
|
||||
};
|
||||
unsigned short Network::Address::GetPort()
|
||||
{
|
||||
return this->address.port;
|
||||
return ntohs(this->address.port);
|
||||
}
|
||||
void Network::Address::SetIP(DWORD ip)
|
||||
{
|
||||
@ -29,6 +29,14 @@ namespace Components
|
||||
{
|
||||
return *(DWORD*)this->address.ip;
|
||||
}
|
||||
void Network::Address::SetType(Game::netadrtype_t type)
|
||||
{
|
||||
this->address.type = type;
|
||||
}
|
||||
Game::netadrtype_t Network::Address::GetType()
|
||||
{
|
||||
return this->address.type;
|
||||
}
|
||||
Game::netadr_t* Network::Address::Get()
|
||||
{
|
||||
return &this->address;
|
||||
@ -53,6 +61,47 @@ namespace Components
|
||||
Network::Send(Game::netsrc_t::NS_CLIENT, target, data);
|
||||
}
|
||||
|
||||
void Network::SendRaw(Game::netsrc_t type, Address target, std::string data)
|
||||
{
|
||||
DWORD header = 0xFFFFFFFF;
|
||||
|
||||
std::string rawData;
|
||||
rawData.append(reinterpret_cast<char*>(&header), 4);
|
||||
rawData.append(data.begin(), data.end());
|
||||
rawData.append("\0", 1);
|
||||
|
||||
Game::OOBPrintRaw(type, *target.Get(), rawData.data(), rawData.size());
|
||||
}
|
||||
|
||||
void Network::SendRaw(Address target, std::string data)
|
||||
{
|
||||
Network::SendRaw(Game::netsrc_t::NS_CLIENT, target, data);
|
||||
}
|
||||
|
||||
void Network::Broadcast(unsigned short port, std::string data)
|
||||
{
|
||||
Address target;
|
||||
|
||||
target.SetPort(port);
|
||||
target.SetIP(INADDR_BROADCAST);
|
||||
target.SetType(Game::netadrtype_t::NA_BROADCAST);
|
||||
|
||||
Network::SendRaw(Game::netsrc_t::NS_CLIENT, target, data);
|
||||
}
|
||||
|
||||
void Network::BroadcastRange(unsigned int min, unsigned int max, std::string data)
|
||||
{
|
||||
for (unsigned int i = min; i < max; i++)
|
||||
{
|
||||
Network::Broadcast((unsigned short)(i & 0xFFFF), data);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::BroadcastAll(std::string data)
|
||||
{
|
||||
Network::BroadcastRange(100, 65536, data);
|
||||
}
|
||||
|
||||
int Network::PacketInterceptionHandler(const char* packet)
|
||||
{
|
||||
// Check if custom handler exists
|
||||
@ -74,7 +123,13 @@ namespace Components
|
||||
if (Network::PacketHandlers.find(Network::SelectedPacket) != Network::PacketHandlers.end())
|
||||
{
|
||||
size_t offset = Network::SelectedPacket.size() + 4 + 1;
|
||||
Network::PacketHandlers[Network::SelectedPacket](from, std::string(msg->data + offset, msg->cursize - offset));
|
||||
|
||||
std::string data(msg->data + offset, msg->cursize - offset);
|
||||
|
||||
// Remove trailing 0x00 byte
|
||||
if (data.size() && !data[data.size() - 1]) data.pop_back();
|
||||
|
||||
Network::PacketHandlers[Network::SelectedPacket](from, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -20,6 +20,9 @@ namespace Components
|
||||
void SetIP(DWORD ip);
|
||||
DWORD GetIP();
|
||||
|
||||
void SetType(Game::netadrtype_t type);
|
||||
Game::netadrtype_t GetType();
|
||||
|
||||
Game::netadr_t* Get();
|
||||
const char* GetString();
|
||||
|
||||
@ -35,9 +38,19 @@ namespace Components
|
||||
const char* GetName() { return "Network"; };
|
||||
|
||||
static void Handle(std::string packet, Callback callback);
|
||||
|
||||
// Only non-binary data
|
||||
static void Send(Address target, std::string data);
|
||||
static void Send(Game::netsrc_t type, Address target, std::string data);
|
||||
|
||||
// Allows sending binary data
|
||||
static void SendRaw(Address target, std::string data);
|
||||
static void SendRaw(Game::netsrc_t type, Address target, std::string data);
|
||||
|
||||
static void Broadcast(unsigned short port, std::string data);
|
||||
static void BroadcastRange(unsigned int min, unsigned int max, std::string data);
|
||||
static void BroadcastAll(std::string data);
|
||||
|
||||
private:
|
||||
static std::string SelectedPacket;
|
||||
static std::map<std::string, Callback> PacketHandlers;
|
||||
|
@ -97,6 +97,14 @@ namespace Components
|
||||
if (Party::LobbyMap.size() <= 1) Game::Steam_JoinLobby(id, 0);
|
||||
}
|
||||
|
||||
void Party::PlaylistError(std::string error)
|
||||
{
|
||||
Party::Container.Valid = false;
|
||||
Party::Container.AwaitingPlaylist = false;
|
||||
|
||||
Party::ConnectError(error);
|
||||
}
|
||||
|
||||
DWORD Party::UIDvarIntStub(char* dvar)
|
||||
{
|
||||
if (!_stricmp(dvar, "onlinegame"))
|
||||
@ -220,6 +228,7 @@ namespace Components
|
||||
// Basic info handler
|
||||
Network::Handle("getInfo", [] (Network::Address address, std::string data)
|
||||
{
|
||||
OutputDebugStringA(Utils::VA("Received inforequest from: %s", address.GetString()));
|
||||
int clientCount = 0;
|
||||
int maxclientCount = *Game::svs_numclients;
|
||||
|
||||
@ -286,6 +295,7 @@ namespace Components
|
||||
|
||||
Network::Handle("infoResponse", [] (Network::Address address, std::string data)
|
||||
{
|
||||
OutputDebugStringA(Utils::VA("Received inforesponse from: %s", address.GetString()));
|
||||
Utils::InfoString info(data);
|
||||
|
||||
// Handle connection
|
||||
@ -313,6 +323,13 @@ namespace Components
|
||||
Party::Container.RequestTime = Game::Com_Milliseconds();
|
||||
Party::Container.AwaitingPlaylist = true;
|
||||
Network::Send(address, "getplaylist\n");
|
||||
|
||||
// This is not a safe method
|
||||
// TODO: Fix actual error!
|
||||
if (Game::CL_IsCgameInitialized())
|
||||
{
|
||||
Command::Execute("disconnect", true);
|
||||
}
|
||||
}
|
||||
else if (matchType == 2) // Match
|
||||
{
|
||||
@ -326,7 +343,6 @@ namespace Components
|
||||
}
|
||||
else
|
||||
{
|
||||
Dvar::Var("xblive_privatematch").Set(1);
|
||||
Game::Menus_CloseAll(Game::uiContext);
|
||||
|
||||
char xnaddr[32];
|
||||
|
@ -14,6 +14,7 @@ namespace Components
|
||||
|
||||
static bool PlaylistAwaiting();
|
||||
static void PlaylistContinue();
|
||||
static void PlaylistError(std::string error);
|
||||
|
||||
private:
|
||||
struct JoinContainer
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Components
|
||||
{
|
||||
std::string Playlist::CurrentPlaylistBuffer;
|
||||
std::string Playlist::ReceivedPlaylistBuffer;
|
||||
|
||||
void Playlist::LoadPlaylist()
|
||||
{
|
||||
@ -33,7 +34,24 @@ namespace Components
|
||||
void Playlist::PlaylistRequest(Network::Address address, std::string data)
|
||||
{
|
||||
Logger::Print("Received playlist request, sending currently stored buffer.\n");
|
||||
Network::Send(address, std::string("playlistresponse\n") + Playlist::CurrentPlaylistBuffer);
|
||||
|
||||
// Split playlist data
|
||||
unsigned int maxPacketSize = 1000;
|
||||
unsigned int maxBytes = Playlist::CurrentPlaylistBuffer.size();
|
||||
|
||||
for (unsigned int i = 0; i < maxBytes; i += maxPacketSize)
|
||||
{
|
||||
unsigned int sendBytes = min(maxPacketSize, maxBytes - i);
|
||||
unsigned int sentBytes = i + sendBytes;
|
||||
|
||||
std::string data;
|
||||
data.append(reinterpret_cast<char*>(&sentBytes), 4); // Sent bytes
|
||||
data.append(reinterpret_cast<char*>(&maxBytes), 4); // Max bytes
|
||||
|
||||
data.append(Playlist::CurrentPlaylistBuffer.data() + i, sendBytes);
|
||||
|
||||
Network::SendRaw(address, std::string("playlistresponse\n") + data);
|
||||
}
|
||||
}
|
||||
|
||||
void Playlist::PlaylistReponse(Network::Address address, std::string data)
|
||||
@ -42,9 +60,43 @@ namespace Components
|
||||
{
|
||||
if (address == Party::Target())
|
||||
{
|
||||
Logger::Print("Received playlist response, loading and continuing connection.\n");
|
||||
Game::Live_ParsePlaylists(data.data());
|
||||
Party::PlaylistContinue();
|
||||
if (data.size() <= 8)
|
||||
{
|
||||
Party::PlaylistError(Utils::VA("Received playlist response, but it is invalid."));
|
||||
Playlist::ReceivedPlaylistBuffer.clear();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int sentBytes = *(unsigned int*)(data.data() + 0);
|
||||
unsigned int maxBytes = *(unsigned int*)(data.data() + 4);
|
||||
|
||||
// Clear current buffer, if we receive a new packet
|
||||
if (data.size() - 8 == sentBytes) Playlist::ReceivedPlaylistBuffer.clear();
|
||||
|
||||
// Append received data
|
||||
Playlist::ReceivedPlaylistBuffer.append(data.data() + 8, data.size() - 8);
|
||||
|
||||
if (Playlist::ReceivedPlaylistBuffer.size() != sentBytes)
|
||||
{
|
||||
Party::PlaylistError(Utils::VA("Received playlist data, but it seems invalid: %d != %d", sentBytes, Playlist::ReceivedPlaylistBuffer.size()));
|
||||
Playlist::ReceivedPlaylistBuffer.clear();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Print("Received playlist data: %d/%d (%d%%)\n", sentBytes, maxBytes, ((100 * sentBytes) / maxBytes));
|
||||
}
|
||||
|
||||
if (Playlist::ReceivedPlaylistBuffer.size() == maxBytes)
|
||||
{
|
||||
Logger::Print("Received playlist response, loading and continuing connection.\n");
|
||||
Game::Live_ParsePlaylists(Playlist::ReceivedPlaylistBuffer.data());
|
||||
Party::PlaylistContinue();
|
||||
|
||||
Playlist::ReceivedPlaylistBuffer.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -99,5 +151,6 @@ namespace Components
|
||||
Playlist::~Playlist()
|
||||
{
|
||||
Playlist::CurrentPlaylistBuffer.clear();
|
||||
Playlist::ReceivedPlaylistBuffer.clear();
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,10 @@ namespace Components
|
||||
|
||||
static void LoadPlaylist();
|
||||
|
||||
static std::string ReceivedPlaylistBuffer;
|
||||
|
||||
private:
|
||||
static std::string CurrentPlaylistBuffer;
|
||||
|
||||
static DWORD StorePlaylistStub(const char** buffer);
|
||||
|
||||
static void PlaylistRequest(Network::Address address, std::string data);
|
||||
|
@ -70,8 +70,9 @@ namespace Components
|
||||
// splash logo
|
||||
Utils::Hook::Set<char*>(0x475F9E, "data/images/splash.bmp");
|
||||
|
||||
// Numeric ping
|
||||
// Numerical ping (cg_scoreboardPingText 1)
|
||||
Utils::Hook::Set<BYTE>(0x45888E, 1);
|
||||
Utils::Hook::Set<BYTE>(0x45888C, Game::dvar_flag::DVAR_FLAG_CHEAT);
|
||||
|
||||
// increase font sizes for chat on higher resolutions
|
||||
static float float13 = 13.0f;
|
||||
|
@ -247,6 +247,7 @@ namespace Components
|
||||
|
||||
// Display in the menu, like in COD4
|
||||
//Logger::Print("Sent %d/%d\n", ServerList::RefreshContainer.SentCount, ServerList::RefreshContainer.SendCount);
|
||||
Localization::Set("MPUI_SERVERQUERIED", Utils::VA("Queried: %d/%d", ServerList::RefreshContainer.SentCount, ServerList::RefreshContainer.SendCount));
|
||||
|
||||
if (SendServers <= 0) break;
|
||||
}
|
||||
@ -259,6 +260,8 @@ namespace Components
|
||||
ServerList::OnlineList.clear();
|
||||
ServerList::VisibleList.clear();
|
||||
|
||||
Localization::Set("MPUI_SERVERQUERIED", "Queried: 0/0");
|
||||
|
||||
Network::Handle("getServersResponse", [] (Network::Address address, std::string data)
|
||||
{
|
||||
if (ServerList::RefreshContainer.Host != address) return; // Only parse from host we sent to
|
||||
|
@ -74,6 +74,9 @@ namespace Game
|
||||
LocalizeMapString_t LocalizeMapString = (LocalizeMapString_t)0x44BB30;
|
||||
|
||||
sendOOB_t OOBPrint = (sendOOB_t)0x4AEF00;
|
||||
sendOOBRaw_t OOBPrintRawData = (sendOOBRaw_t)0x60FDC0;
|
||||
|
||||
SE_Load_t SE_Load = (SE_Load_t)0x502A30;
|
||||
|
||||
PC_ReadToken_t PC_ReadToken = (PC_ReadToken_t)0x4ACCD0;
|
||||
PC_ReadTokenHandle_t PC_ReadTokenHandle = (PC_ReadTokenHandle_t)0x4D2060;
|
||||
@ -151,6 +154,13 @@ namespace Game
|
||||
OOBPrint(type, *adr, *(adr + 1), *(adr + 2), 0xFFFFFFFF, *(adr + 4), message);
|
||||
}
|
||||
|
||||
void OOBPrintRaw(int type, netadr_t netadr, const char* message, size_t length)
|
||||
{
|
||||
int* adr = (int*)&netadr;
|
||||
|
||||
OOBPrintRawData(type, length, message, *adr, *(adr + 1), *(adr + 2), 0xFFFFFFFF, *(adr + 4));
|
||||
}
|
||||
|
||||
const char* UI_LocalizeMapName(const char* mapName)
|
||||
{
|
||||
for (int i = 0; i < *arenaCount; i++)
|
||||
|
@ -169,6 +169,12 @@ namespace Game
|
||||
typedef void(__cdecl* sendOOB_t)(int, int, int, int, int, int, const char*);
|
||||
extern sendOOB_t OOBPrint;
|
||||
|
||||
typedef void(__cdecl* sendOOBRaw_t)(int, size_t, const char*, int, int, int, int, int);
|
||||
extern sendOOBRaw_t OOBPrintRawData;
|
||||
|
||||
typedef char* (__cdecl * SE_Load_t)(char* file, int Unk);
|
||||
extern SE_Load_t SE_Load;
|
||||
|
||||
typedef int(__cdecl * PC_ReadToken_t)(source_t*, token_t*);
|
||||
extern PC_ReadToken_t PC_ReadToken;
|
||||
|
||||
@ -244,6 +250,7 @@ namespace Game
|
||||
void* ReallocateAssetPool(XAssetType type, unsigned int newSize);
|
||||
void Menu_FreeItemMemory(Game::itemDef_t* item);
|
||||
void OOBPrintT(int type, netadr_t netadr, const char* message);
|
||||
void OOBPrintRaw(int type, netadr_t netadr, const char* message, size_t length);
|
||||
const char* UI_LocalizeMapName(const char* mapName);
|
||||
const char* UI_LocalizeGameType(const char* gameType);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user