@@ -65,9 +65,6 @@ Variable mm_session_sys_delay_create_host;
6565Variable hide_gun_when_holding;
6666Variable r_flashlightbrightness;
6767
68- int origPortal2PromoFlagsValue;
69- int *g_nPortal2PromoFlags = nullptr ;
70-
7168// TSP only
7269void IN_BhopDown (const CCommand& args) {
7370 if (!client->KeyDown || !client->in_jump ) return ;
@@ -334,6 +331,7 @@ Memory::Patch *g_floorReportalPatch;
334331Memory::Patch *g_coopLoadingDotsPatch;
335332Memory::Patch *g_autoGrabPatchServer;
336333Memory::Patch *g_autoGrabPatchClient;
334+ Memory::Patch *g_promoFlagsPatch;
337335
338336void Cheats::Init () {
339337 sv_laser_cube_autoaim = Variable (" sv_laser_cube_autoaim" );
@@ -402,7 +400,13 @@ void Cheats::Init() {
402400 g_autoGrabPatchClient->Restore ();
403401 }
404402
405- g_nPortal2PromoFlags = *reinterpret_cast <int **>(Memory::Scan (MODULE (" server" ), Offsets::Portal2PromoFlags_ADDR, 2 )); // Note: Has to be active before map loads.
403+ g_promoFlagsPatch = new Memory::Patch ();
404+ auto portal2PromoFlags = Memory::Scan (MODULE (" server" ), Offsets::Portal2PromoFlagsSig, Offsets::Portal2PromoFlagsOff);
405+ if (portal2PromoFlags) {
406+ unsigned char promoFlagsByte = 0x00 ;
407+ g_promoFlagsPatch->Execute (portal2PromoFlags, &promoFlagsByte, 1 ); // Note: Has to be active before map loads.
408+ g_promoFlagsPatch->Restore ();
409+ }
406410
407411 Variable::RegisterAll ();
408412 Command::RegisterAll ();
@@ -427,6 +431,8 @@ void Cheats::Shutdown() {
427431 SAFE_DELETE (g_autoGrabPatchServer);
428432 g_autoGrabPatchClient->Restore ();
429433 SAFE_DELETE (g_autoGrabPatchClient);
434+ g_promoFlagsPatch->Restore ();
435+ SAFE_DELETE (g_promoFlagsPatch);
430436}
431437
432438
@@ -596,46 +602,35 @@ void Cheats::CheckAutoGrab() {
596602}
597603
598604DECL_AUTO_COMMAND_COMPLETION (sar_set_promo_items_state, ({" skins" , " helmet" , " antenna" })) // TODO: Add support for autofilling multiple args.
599- CON_COMMAND_F_COMPLETION(sar_set_promo_items_state, " Enables coop promotional items on spawn." , FCVAR_CHEAT, AUTOCOMPLETION_FUNCTION(sar_set_promo_items_state)) {
600- if (!g_nPortal2PromoFlags) {
601- console->Print (" Could not find PromoFlags global!\n " );
602- return ;
605+ CON_COMMAND_F_COMPLETION(sar_set_promo_items_state, " sar_set_promo_items_state <off|all|skins|helmet|antenna>... - enables coop promotional items on spawn.\n " , FCVAR_CHEAT, AUTOCOMPLETION_FUNCTION(sar_set_promo_items_state)) {
606+ if (!g_promoFlagsPatch || !g_promoFlagsPatch->IsInit ()) {
607+ return console->Print (" sar_set_promo_items_state is not available.\n " );
603608 }
604- static bool hasCheckedOriginalValue = false ;
605- if (!hasCheckedOriginalValue) {
606- origPortal2PromoFlagsValue = *g_nPortal2PromoFlags;
607- hasCheckedOriginalValue = true ;
608- }
609- bool bSkin = (_stricmp (args[1 ], " skins" ) == 0 );
610- bool bHelmet = (_stricmp (args[1 ], " helmet" ) == 0 );
611- bool bAntenna = (_stricmp (args[1 ], " antenna" ) == 0 );
612- if (!bSkin && !bHelmet && !bAntenna) {
613- console->Print (" Invalid first argument.\n " );
614- return ;
615- }
616- bool bAdding = (_stricmp (args[2 ], " add" ) == 0 );
617- bool bRemoving = (_stricmp (args[2 ], " remove" ) == 0 );
618- if (!bAdding && !bRemoving) {
619- console->Print (" Invalid second argument.\n " );
620- return ;
609+
610+ if (args.ArgC () < 2 ) {
611+ return console->Print (sar_set_promo_items_state.ThisPtr ()->m_pszHelpString );
621612 }
622- if (bSkin) {
623- if (bAdding) {
624- *g_nPortal2PromoFlags |= (1 << 0 );
625- } else if (bRemoving) {
626- *g_nPortal2PromoFlags &= ~(1 << 0 );
613+
614+ unsigned char targetFlags = 0 ;
615+ for (int i = 1 ; i < args.ArgC (); i++) {
616+ if (strcasecmp (args[i], " off" ) == 0 ) {
617+ g_promoFlagsPatch->Restore ();
618+ return ;
627619 }
628- } else if (bHelmet) {
629- if (bAdding) {
630- *g_nPortal2PromoFlags |= (1 << 1 );
631- } else if (bRemoving) {
632- *g_nPortal2PromoFlags &= ~(1 << 1 );
620+ if (strcasecmp (args[i], " all" ) == 0 ) {
621+ targetFlags = 0b111 ;
622+ break ;
633623 }
634- } else if (bAntenna) {
635- if (bAdding) {
636- *g_nPortal2PromoFlags |= (1 << 2 );
637- } else if (bRemoving) {
638- *g_nPortal2PromoFlags &= ~(1 << 2 );
624+ if (strcasecmp (args[i], " skins" ) == 0 ) {;
625+ targetFlags |= 0b001 ;
626+ } else if (strcasecmp (args[i], " helmet" ) == 0 ) {
627+ targetFlags |= 0b010 ;
628+ } else if (strcasecmp (args[i], " antenna" ) == 0 ) {
629+ targetFlags |= 0b100 ;
630+ } else {
631+ return console->Print (sar_set_promo_items_state.ThisPtr ()->m_pszHelpString );
639632 }
640633 }
634+ g_promoFlagsPatch->Restore ();
635+ g_promoFlagsPatch->Execute (&targetFlags, 1 );
641636}
0 commit comments