Skip to content

Commit 58ce067

Browse files
committed
Revert "fix(profile): move clanName handling into profile patches"
This reverts commit 383f078.
1 parent 383f078 commit 58ce067

2 files changed

Lines changed: 101 additions & 95 deletions

File tree

src/component/engine/console/command.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ namespace command
2020
constexpr int CLIENT_REAL_PLAYER_OFFSET = 0x20;
2121
constexpr int CLIENT_USERINFO_OFFSET = 1604;
2222
constexpr int CLIENT_USERINFO_SIZE = 1024;
23+
constexpr int ACTIVE_PROFILE_INDEX = 0;
2324
constexpr auto BOT_NAMES_FILE = "consolation/bots.txt";
25+
constexpr auto LIVE_CLAN_TARGET_PRIMARY = 0x111CF170;
26+
constexpr auto LIVE_CLAN_TARGET_SECONDARY = 0x111F1C00;
27+
constexpr auto CLAN_DIRTY_FLAGS = 0x1149E6BC;
2428

2529
std::unordered_map<std::string, std::function<void(params&)>> handlers;
2630
int next_bot_number = 1;
@@ -210,6 +214,49 @@ namespace command
210214
return std::format("consolation_bot{}", next_bot_number++ - 1);
211215
}
212216

217+
std::string normalize_clan_name(const std::string& raw_value)
218+
{
219+
std::string result{};
220+
result.reserve(4);
221+
222+
for (const auto ch : raw_value)
223+
{
224+
if (result.size() >= 4)
225+
{
226+
break;
227+
}
228+
229+
auto normalized = static_cast<unsigned char>(ch);
230+
if (normalized == '^')
231+
{
232+
normalized = ' ';
233+
}
234+
235+
if (normalized < 32)
236+
{
237+
continue;
238+
}
239+
240+
result.push_back(static_cast<char>(normalized));
241+
}
242+
243+
return result;
244+
}
245+
246+
const char* get_dvar_string(game::dvar_s* dvar)
247+
{
248+
return dvar && dvar->current.string ? dvar->current.string : "";
249+
}
250+
251+
void update_clan_name_state(const std::string& clan_name)
252+
{
253+
game::Dvar_SetString("clanName", clan_name.c_str());
254+
game::GamerProfile_UpdateProfileFromDvars(ACTIVE_PROFILE_INDEX, 1);
255+
game::Live_UpdateClan(game::game_offset(LIVE_CLAN_TARGET_PRIMARY), const_cast<char*>(clan_name.c_str()));
256+
game::Live_UpdateClan(game::game_offset(LIVE_CLAN_TARGET_SECONDARY), const_cast<char*>(clan_name.c_str()));
257+
*reinterpret_cast<std::uint32_t*>(game::game_offset(CLAN_DIRTY_FLAGS)) |= 2u;
258+
}
259+
213260
int rename_new_bot_client()
214261
{
215262
for (int i = 0; i < get_max_clients(); ++i)
@@ -386,6 +433,27 @@ namespace command
386433
console::info("addbot: spawned %i bot(s)\n", spawned);
387434
});
388435

436+
add("clanName", [](const params& args)
437+
{
438+
auto* const clan_name = game::Dvar_FindVar("clanName");
439+
if (!clan_name)
440+
{
441+
console::error("clanName: dvar is unavailable\n");
442+
return;
443+
}
444+
445+
if (args.size() < 2)
446+
{
447+
console::info("clanName: current tag is \"%s\"\n", get_dvar_string(clan_name));
448+
console::info("usage: clanName <tag>\n");
449+
return;
450+
}
451+
452+
const auto normalized = normalize_clan_name(args.join(1));
453+
update_clan_name_state(normalized);
454+
console::info("clanName: set tag to \"%s\"\n", normalized.c_str());
455+
});
456+
389457
add("dvarDump", [](const params& argument)
390458
{
391459
std::string filename;

src/component/engine/patches/profile_patches.cpp

Lines changed: 33 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ namespace profile_patches
1717
const char default_profile_config_name[] = "config_mp.cfg";
1818
const char custom_profile_config_name[] = "consolation_mp.cfg";
1919
const char decrypted_profile_config_name[] = "consolation_mp_decrypted.cfg";
20-
constexpr int active_profile_index = 0;
21-
constexpr auto live_clan_target_primary = 0x111CF170;
22-
constexpr auto live_clan_target_secondary = 0x111F1C00;
23-
constexpr auto clan_dirty_flags = 0x1149E6BC;
2420
void print_profile_message(const char* fmt, ...);
2521
std::string build_profile_file_path(const char* filename);
26-
2722
const char* get_dvar_string(const std::size_t dvar_ptr_address)
2823
{
2924
const auto dvar = *reinterpret_cast<game::dvar_s**>(game::game_offset(dvar_ptr_address));
@@ -35,11 +30,6 @@ namespace profile_patches
3530
return dvar->current.string;
3631
}
3732

38-
const char* get_dvar_string(game::dvar_s* dvar)
39-
{
40-
return dvar && dvar->current.string ? dvar->current.string : "";
41-
}
42-
4333
std::string join_path(const std::string& base, const std::string& leaf)
4434
{
4535
if (base.empty())
@@ -185,54 +175,6 @@ namespace profile_patches
185175
return value.substr(first, last - first + 1);
186176
}
187177

188-
std::string normalize_clan_name(const std::string& raw_value)
189-
{
190-
std::string result{};
191-
result.reserve(4);
192-
193-
for (const auto ch : raw_value)
194-
{
195-
if (result.size() >= 4)
196-
{
197-
break;
198-
}
199-
200-
const auto normalized = static_cast<unsigned char>(ch);
201-
if (normalized < 32
202-
|| normalized == '^'
203-
|| normalized == 0xA4
204-
|| normalized == '{'
205-
|| normalized == '}'
206-
|| normalized == '@')
207-
{
208-
continue;
209-
}
210-
211-
result.push_back(static_cast<char>(normalized));
212-
}
213-
214-
return trim_copy(result);
215-
}
216-
217-
bool is_developer_reserved_clan_tag(const std::string& clan_name)
218-
{
219-
static const std::unordered_set<std::string> reserved_tags =
220-
{
221-
"csl",
222-
};
223-
224-
return reserved_tags.find(to_lower(clan_name)) != reserved_tags.end();
225-
}
226-
227-
void update_clan_name_state(const std::string& clan_name)
228-
{
229-
game::Dvar_SetString("clanName", clan_name.c_str());
230-
game::GamerProfile_UpdateProfileFromDvars(active_profile_index, 1);
231-
game::Live_UpdateClan(game::game_offset(live_clan_target_primary), clan_name.c_str());
232-
game::Live_UpdateClan(game::game_offset(live_clan_target_secondary), clan_name.c_str());
233-
*reinterpret_cast<std::uint32_t*>(game::game_offset(clan_dirty_flags)) |= 2u;
234-
}
235-
236178
const char* find_canonical_dvar_name(const std::string& key)
237179
{
238180
static const std::unordered_map<std::string, const char*> canonical_names =
@@ -576,8 +518,9 @@ namespace profile_patches
576518
public:
577519
void post_load() override
578520
{
579-
// Keep the profile helper commands available, but avoid touching the
580-
// stock signed-in config on the profile-login hot path.
521+
// Keep the profile helper commands available, but do not alter the
522+
// game's active config filename or save path automatically while we
523+
// investigate signed-in startup freezes.
581524

582525
scheduler::once([]()
583526
{
@@ -588,41 +531,6 @@ namespace profile_patches
588531
migrate_config();
589532
});
590533

591-
command::add("clanName", [](const command::params& args)
592-
{
593-
auto* const clan_name = game::Dvar_FindVar("clanName");
594-
if (!clan_name)
595-
{
596-
print_profile_message("^1clanName: dvar is unavailable\n");
597-
return;
598-
}
599-
600-
if (args.size() < 2)
601-
{
602-
print_profile_message("^3clanName: current tag is \"%s\"\n", get_dvar_string(clan_name));
603-
print_profile_message("^3usage: clanName <tag>\n");
604-
return;
605-
}
606-
607-
const auto normalized = normalize_clan_name(args.join(1));
608-
if (normalized.empty())
609-
{
610-
print_profile_message("^1clanName: tag is empty or contains unsupported characters\n");
611-
return;
612-
}
613-
614-
#ifndef DEBUG
615-
if (is_developer_reserved_clan_tag(normalized))
616-
{
617-
print_profile_message("^1clanName: tag \"%s\" is reserved for developer builds\n", normalized.c_str());
618-
return;
619-
}
620-
#endif
621-
622-
update_clan_name_state(normalized);
623-
print_profile_message("^3clanName: set tag to \"%s\"\n", normalized.c_str());
624-
});
625-
626534
command::add("profile_convert_config", []()
627535
{
628536
convert_config();
@@ -657,6 +565,36 @@ namespace profile_patches
657565
});
658566
}, scheduler::main);
659567

568+
scheduler::loop([]()
569+
{
570+
static std::string imported_profile{};
571+
static std::string missing_profile{};
572+
573+
const auto profile_name = get_profile_name();
574+
if (profile_name.empty())
575+
{
576+
return;
577+
}
578+
579+
if (profile_name == imported_profile || profile_name == missing_profile)
580+
{
581+
return;
582+
}
583+
584+
const auto source_path = get_custom_profile_import_path();
585+
if (source_path.empty())
586+
{
587+
missing_profile = profile_name;
588+
return;
589+
}
590+
591+
if (import_custom_profile_config_into_stock())
592+
{
593+
imported_profile = profile_name;
594+
missing_profile.clear();
595+
}
596+
}, scheduler::main, 250ms);
597+
660598
scheduler::on_shutdown([]()
661599
{
662600
export_stock_profile_config_to_custom();

0 commit comments

Comments
 (0)