From 621375c2af76ef55b0835002140b4c7827bef9f9 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 3 Jan 2016 02:37:06 +0100 Subject: [PATCH] Fix team shit. --- src/Components/Modules/Dedicated.cpp | 16 ++++-------- src/Components/Modules/Dvar.cpp | 18 ++++++++++++- src/Components/Modules/Dvar.hpp | 7 +++++ src/Components/Modules/Party.cpp | 38 +++++++++++++++++++++++++++- src/Components/Modules/Party.hpp | 2 ++ src/Components/Modules/Playlist.cpp | 15 +++-------- 6 files changed, 71 insertions(+), 25 deletions(-) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 28325a3c..91ebc5c4 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -35,13 +35,14 @@ namespace Components Command::Execute("onlinegame 1"); Command::Execute("exec default_xboxlive.cfg"); Command::Execute("xblive_rankedmatch 1"); - Command::Execute("xblive_privatematch 0"); - //Command::Execute("xstartprivatematch"); + Command::Execute("xblive_privatematch 1"); + Command::Execute("xstartprivatematch"); + //Command::Execute("xstartlobby"); Command::Execute("sv_network_fps 1000"); Command::Execute("com_maxfps 125"); // Process command line? - Utils::Hook::Call(0x60C3D0)(); + //Utils::Hook::Call(0x60C3D0)(); } void __declspec(naked) Dedicated::PostInitializationStub() @@ -58,7 +59,7 @@ namespace Components void Dedicated::MapRotate() { - if (Dvar::Var("party_host").Get()) + if (Dvar::Var("party_enable").Get() && Dvar::Var("party_host").Get()) { Logger::Print("Not performing map rotation as we are hosting a party!\n"); return; @@ -257,13 +258,6 @@ namespace Components Dedicated::Heartbeat(); } }); - - // Wrap xstartprivatematch - Command::Add("lobby_start", [] (Command::Params params) - { - Playlist::LoadPlaylist(); - Command::Execute("xstartprivatematch", false); - }); } } diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index ca5049c2..6b2217ad 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -2,6 +2,8 @@ namespace Components { + std::vector Dvar::RegistrationCallbacks; + Dvar::Var::Var(std::string dvarName) : Var() { this->dvar = Game::Dvar_FindVar(dvarName.data()); @@ -125,9 +127,18 @@ namespace Components return Game::Dvar_RegisterInt(name, value, min, max, flag.val, description); } + void Dvar::OnInit(Dvar::Callback callback) + { + Dvar::RegistrationCallbacks.push_back(callback); + } + Game::dvar_t* Dvar::RegisterName(const char* name, const char* default, Game::dvar_flag flag, const char* description) { - // TODO: Register string dvars here + // Run callbacks + for (auto callback : Dvar::RegistrationCallbacks) + { + callback(); + } // Name watcher Renderer::OnFrame([] () @@ -171,4 +182,9 @@ namespace Components // Hook dvar 'name' registration Utils::Hook(0x40531C, Dvar::RegisterName, HOOK_CALL).Install()->Quick(); } + + Dvar::~Dvar() + { + Dvar::RegistrationCallbacks.clear(); + } } diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index 7b4f026f..af326a9e 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -3,6 +3,8 @@ namespace Components class Dvar : public Component { public: + typedef void(*Callback)(); + struct Flag { Flag(Game::dvar_flag flag) : val(flag){}; @@ -37,13 +39,18 @@ namespace Components }; Dvar(); + ~Dvar(); const char* GetName() { return "Dvar"; }; + static void OnInit(Callback callback); + // Only strings and bools use this type of declaration template static Var Register(const char* name, T value, Flag flag, const char* description); template static Var Register(const char* name, T value, T min, T max, Flag flag, const char* description); private: + static std::vector RegistrationCallbacks; + static Game::dvar_t* RegisterName(const char* name, const char* default, Game::dvar_flag flag, const char* description); }; } diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 9e821ee8..18360034 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -97,8 +97,21 @@ namespace Components if (Party::LobbyMap.size() <= 1) Game::Steam_JoinLobby(id, 0); } + DWORD Party::UIDvarIntStub(char* dvar) + { + if (!_stricmp(dvar, "onlinegame")) + { + return 0x649E660; + } + + return Utils::Hook::Call(0x4D5390)(dvar); + } + Party::Party() { + Dvar::Register("party_enable", false, Game::dvar_flag::DVAR_FLAG_NONE, "Enable party system"); + Dvar::Register("xblive_privatematch", true, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED, "").Get(); + // various changes to SV_DirectConnect-y stuff to allow non-party joinees Utils::Hook::Set(0x460D96, 0x90E9); Utils::Hook::Set(0x460F0A, 0xEB); @@ -140,6 +153,29 @@ namespace Components // Allow xpartygo in public lobbies Utils::Hook::Set(0x5A969E, 0xEB); + // Always open lobby menu when connecting + // It's not possible to entirely patch it via code + //Utils::Hook::Set(0x5B1698, 0xEB); + //Utils::Hook::Nop(0x5029F2, 6); + //Utils::Hook::SetString(0x70573C, "menu_xboxlive_lobby"); + + // Disallow selecting team in private match + //Utils::Hook::Nop(0x5B2BD8, 6); + + // Force teams, even if not private match + Utils::Hook::Set(0x487BB2, 0xEB); + + // Force xblive_privatematch 0 and rename it + Utils::Hook::Set(0x420A6A, 4); + Utils::Hook::Set(0x420A6C, 0); + Utils::Hook::Set(0x420A6E, "xblive_privatematch2"); + + // Enable XP Bar + Utils::Hook(0x62A2A7, Party::UIDvarIntStub, HOOK_CALL).Install()->Quick(); + + // Fix xstartlobby + //Utils::Hook::Set(0x5B71CD, 0xEB); + // Patch party_minplayers to 1 and protect it //Utils::Hook(0x4D5D51, Party::RegisterMinPlayers, HOOK_CALL).Install()->Quick(); @@ -225,7 +261,7 @@ namespace Components // 1 - Party, use Steam_JoinLobby to connect // 2 - Match, use CL_ConnectFromParty to connect - if (Dvar::Var("party_host").Get()) // Party hosting + if (Dvar::Var("party_enable").Get() && Dvar::Var("party_host").Get()) // Party hosting { info.Set("matchtype", "1"); } diff --git a/src/Components/Modules/Party.hpp b/src/Components/Modules/Party.hpp index c5af0afa..352a7a2b 100644 --- a/src/Components/Modules/Party.hpp +++ b/src/Components/Modules/Party.hpp @@ -36,5 +36,7 @@ namespace Components static Game::dvar_t* RegisterMinPlayers(const char* name, int value, int min, int max, Game::dvar_flag flag, const char* description); static void ConnectError(std::string message); + + static DWORD UIDvarIntStub(char* dvar); }; } diff --git a/src/Components/Modules/Playlist.cpp b/src/Components/Modules/Playlist.cpp index 49d6d60c..6071fb50 100644 --- a/src/Components/Modules/Playlist.cpp +++ b/src/Components/Modules/Playlist.cpp @@ -59,17 +59,8 @@ namespace Components Playlist::Playlist() { - // Apply new playlist - char* playlist = "mp_playlists_dlc2"; - Utils::Hook::Set(0x494803, playlist); - Utils::Hook::Set(0x4C6EC1, playlist); - Utils::Hook::Set(0x4CF7F9, playlist); - Utils::Hook::Set(0x4D6E63, playlist); - Utils::Hook::Set(0x4D7358, playlist); - Utils::Hook::Set(0x4D73C8, playlist); - Utils::Hook::Set(0x4F4EA1, playlist); - Utils::Hook::Set(0x4D47FB, "mp_playlists_dlc2.ff"); - Utils::Hook::Set(0x60B06E, "playlists.patch2"); + // Default playlists + Utils::Hook::Set(0x60B06E, "playlists_default.info"); // disable playlist download function Utils::Hook::Set(0x4D4790, 0xC3); @@ -92,7 +83,7 @@ namespace Components // Store playlist buffer on load Utils::Hook(0x42961C, Playlist::StorePlaylistStub, HOOK_CALL).Install()->Quick(); - if (Dedicated::IsDedicated()) + //if (Dedicated::IsDedicated()) { // Custom playlist loading Utils::Hook(0x420B5A, Playlist::LoadPlaylist, HOOK_JUMP).Install()->Quick();