Some beautifies

This commit is contained in:
momo5502 2015-12-30 15:37:53 +01:00
parent 9818fa7b21
commit 3000a11785
9 changed files with 60 additions and 57 deletions

View File

@ -257,7 +257,7 @@ namespace Components
*substr2 = 0;
////DBG(("Connecting to: %s", substr));
Game::Cbuf_AddText(0, Utils::VA("connect %s;", substr));
Command::Execute(Utils::VA("connect %s;", substr), false);
}
BOOL ConnectProtocol::InvokeConnect()
@ -321,12 +321,11 @@ namespace Components
ConnectProtocol::ConnectProtocol()
{
ConnectProtocol::InstallProtocol();
}
//Send Connect Command to running iw4x instance
BOOL CALLBACK enumWindowsProc(__in HWND hWnd, __in LPARAM lParam) {
BOOL CALLBACK ConnectProtocol::EnumWindowsProc(__in HWND hWnd, __in LPARAM lParam) {
DWORD id = GetWindowThreadProcessId(hWnd, &id);
DWORD id2 = GetWindowThreadProcessId(FindWindowFromProcessId(proc_id), &id2);
@ -353,7 +352,7 @@ namespace Components
return TRUE;
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {
BOOL CALLBACK ConnectProtocol::EnumChildProc(HWND hwnd, LPARAM lParam) {
char buffer[256];
GetClassName(hwnd, (LPSTR)buffer, 255);
@ -375,7 +374,7 @@ namespace Components
HWND hWnd;
};
BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam) {
BOOL CALLBACK ConnectProtocol::EnumProc(HWND hWnd, LPARAM lParam) {
// Retrieve storage location for communication data
EnumData& ed = *(EnumData*)lParam;
DWORD dwProcessId = 0x0;
@ -395,7 +394,7 @@ namespace Components
return TRUE;
}
void FindEditHandle(__in_z LPCTSTR lpcszFileName)
void ConnectProtocol::FindEditHandle(__in_z LPCTSTR lpcszFileName)
{
LPDWORD lpdwProcessIds;
LPTSTR lpszBaseName;
@ -425,7 +424,7 @@ namespace Components
dwProcessId = lpdwProcessIds[i];
CloseHandle(hProcess);
proc_id = dwProcessId;
EnumWindows(enumWindowsProc, NULL);
EnumWindows(EnumWindowsProc, NULL);
if (con_in != NULL)
{
break;
@ -445,7 +444,7 @@ namespace Components
//return dwProcessId;
}
// Main entry
HWND FindWindowFromProcessId(DWORD dwProcessId) {
HWND ConnectProtocol::FindWindowFromProcessId(DWORD dwProcessId) {
EnumData ed = { dwProcessId };
if (!EnumWindows(EnumProc, (LPARAM)&ed) &&
(GetLastError() == ERROR_SUCCESS)) {
@ -454,7 +453,7 @@ namespace Components
return NULL;
}
// Helper method for convenience
HWND FindWindowFromProcess(HANDLE hProcess) {
HWND ConnectProtocol::FindWindowFromProcess(HANDLE hProcess) {
return FindWindowFromProcessId(GetProcessId(hProcess));
}
}

View File

@ -6,14 +6,16 @@ namespace Components
ConnectProtocol();
void EvaluateProtocol();
static BOOL InvokeConnect();
private:
static bool InstallProtocol();
//Additional Functions for InvokeConnect
static void FindEditHandle(__in_z LPCTSTR lpcszFileName);
static BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam);
static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
static BOOL CALLBACK EnumWindowsProc(__in HWND hWnd, __in LPARAM lParam);
static HWND FindWindowFromProcessId(DWORD dwProcessId);
static HWND FindWindowFromProcess(HANDLE hProcess);
};
//Additional Functions for InvokeConnect
void FindEditHandle(__in_z LPCTSTR lpcszFileName);
BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam);
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
HWND FindWindowFromProcessId(DWORD dwProcessId);
HWND FindWindowFromProcess(HANDLE hProcess);
}

View File

@ -57,6 +57,7 @@ namespace Components
std::string rotation = Dvar::Var("sv_mapRotationCurrent").Get<std::string>();
// Ignores " for now, too lazy to implement
// TODO: Implement!
auto tokens = Utils::Explode(rotation, ' ');
for (unsigned int i = 0; i < (tokens.size() - 1); i += 2)

View File

@ -129,18 +129,6 @@ namespace Components
{
// TODO: Register string dvars here
// TODO: Support multiple languages here and find a better place for this. :/
if (std::string(Game::Win_GetLanguage()) == "german")
{
Localization::Set("MP_SEARCHING_FOR_PLAYER", "Warte");
Localization::Set("MENU_WAITING_FOR_MORE_PLAYERS_TEAMS", "Auf weitere Spieler zum Teamausgleich warten");
}
else
{
Localization::Set("MP_SEARCHING_FOR_PLAYER", "Waiting");
Localization::Set("MENU_WAITING_FOR_MORE_PLAYERS_TEAMS", "Waiting for more players to balance teams");
}
return Dvar::Register<const char*>(name, "Unknown Soldier", Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).Get<Game::dvar_t*>();
}

View File

@ -33,9 +33,13 @@ namespace Components
{
Utils::Hook(0x629B90, Localization::Get, HOOK_JUMP).Install()->Quick();
//Localization::Set("MENU_MULTIPLAYER_CAPS", "^5Fotze");
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");
// 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");
}

View File

@ -2,6 +2,7 @@
namespace Components
{
std::vector<std::string> Menus::CustomMenus;
std::vector<Game::menuDef_t*> Menus::MenuList;
std::vector<Game::MenuList*> Menus::MenuListList;
@ -181,12 +182,7 @@ namespace Components
{
Game::PC_ReadTokenHandle(handle, &token);
std::vector<Game::menuDef_t*> newMenus = Menus::LoadMenu(Utils::VA("ui_mp\\%s.menu", token.string));
for (auto newMenu : newMenus)
{
menus.push_back(newMenu);
}
Utils::Merge(menus, Menus::LoadMenu(Utils::VA("ui_mp\\%s.menu", token.string)));
}
if (!_stricmp(token.string, "menudef"))
@ -244,22 +240,16 @@ namespace Components
continue;
}
std::vector<Game::menuDef_t*> newMenus = Menus::LoadMenu(menuList->menus[i]);
for (auto newMenu : newMenus)
{
menus.push_back(newMenu);
}
Utils::Merge(menus, Menus::LoadMenu(menuList->menus[i]));
}
// TODO: beautify
if (!_stricmp(menuList->name, "ui_mp/code.txt"))
// Load custom menus
if (std::string(menuList->name) == "ui_mp/code.txt")
{
std::vector<Game::menuDef_t*> _menus = Menus::LoadMenu("ui_mp/theater_menu.menu");
std::vector<Game::menuDef_t*> _menus2 = Menus::LoadMenu("ui_mp/pc_options_multi.menu");
for (auto newMenu : _menus) { menus.push_back(newMenu); }
for (auto newMenu : _menus2) { menus.push_back(newMenu); }
for (auto menu : Menus::CustomMenus)
{
Utils::Merge(menus, Menus::LoadMenu(menu));
}
}
// Allocate new menu list
@ -483,6 +473,11 @@ namespace Components
return nullptr;
}
void Menus::Add(std::string menu)
{
Menus::CustomMenus.push_back(menu);
}
Menus::Menus()
{
if (Dedicated::IsDedicated()) return;
@ -538,10 +533,15 @@ namespace Components
Game::Menus_OpenByName(Game::uiContext, "main_text");
}
});
// Define custom menus here
Menus::Add("ui_mp/theater_menu.menu");
Menus::Add("ui_mp/pc_options_multi.menu");
}
Menus::~Menus()
{
Menus::CustomMenus.clear();
Menus::FreeEverything();
}
}

View File

@ -11,9 +11,12 @@ namespace Components
static void FreeEverything();
static void Add(std::string menu);
private:
static std::vector<Game::menuDef_t*> MenuList;
static std::vector<Game::MenuList*> MenuListList;
static std::vector<std::string> CustomMenus;
static Game::XAssetHeader MenuFileLoad(Game::XAssetType type, const char* filename);
static Game::MenuList* LoadMenuList(Game::MenuList* menuList);

View File

@ -139,15 +139,10 @@ namespace Components
Network::Handle("getInfo", [] (Network::Address address, std::string data)
{
int clientCount = 0;
int maxclientCount = *Game::svs_numclients;
if (!maxclientCount) maxclientCount = Dvar::Var("sv_maxclients").Get<int>();
int maxClients = *Game::svs_numclients;
if (!maxClients)
{
maxClients = Dvar::Var("sv_maxclients").Get<int>();
}
for (int i = 0; i < maxClients; i++)
for (int i = 0; i < maxclientCount; i++)
{
if (Game::svs_clients[i].state >= 3)
{
@ -155,6 +150,9 @@ namespace Components
}
}
// Ensure line break
data.append("\n");
Utils::InfoString info;
info.Set("challenge", data.substr(0, data.find_first_of("\n")).data());
info.Set("gamename", "IW4");
@ -164,7 +162,7 @@ namespace Components
info.Set("fs_game", Dvar::Var("fs_game").Get<const char*>());
info.Set("xuid", Utils::VA("%llX", Steam::SteamUser()->GetSteamID().Bits));
info.Set("clients", Utils::VA("%i", clientCount));
info.Set("sv_maxclients", Utils::VA("%i", maxClients));
info.Set("sv_maxclients", Utils::VA("%i", maxclientCount));
info.Set("protocol", Utils::VA("%i", PROTOCOL));
info.Set("checksum", Utils::VA("%d", Game::Com_Milliseconds()));

View File

@ -25,4 +25,12 @@ namespace Utils
std::map<std::string, std::string> KeyValuePairs;
void Parse(std::string buffer);
};
template <typename T> void Merge(std::vector<T> &target, std::vector<T> &source)
{
for (auto &entry : source)
{
target.push_back(entry);
}
}
}