Guest User

Untitled

a guest
Jun 1st, 2026
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.56 KB | None | 0 0
  1. Dvar::Dvar_RegisterInt("bg_bounces", 0, 0, 2, Game::DVAR_CODINFO, "Bounce glitch settings"); // 0 = disabled, 1 = enabled, 2 = double
  2. Dvar::Dvar_RegisterInt("bg_bouncesAllAngles", 0, 0, 2, Game::DVAR_CODINFO, "Force bounce from all angles"); // 0 = disabled, 1 = simple, 2 = all surfaces
  3. Dvar::Dvar_RegisterInt("bg_elevators", 1, 0, 2, Game::DVAR_CODINFO, "Elevators glitch settings"); // 0 = off, 1 = normal, 2 = easy
  4.  
  5. //////////////////////////////////////////////////////////////////////////////////////////////////////
  6.  
  7. namespace
  8. {
  9.     struct Site
  10.     {
  11.         uintptr_t address;
  12.         uint32_t original;
  13.     };
  14.  
  15.     static uint32_t ReadInstruction(uintptr_t Address)
  16.     {
  17.         return *reinterpret_cast<const uint32_t *>(Address);
  18.     }
  19.  
  20.     namespace BouncePatches
  21.     {
  22.         struct PatchState
  23.         {
  24.             bool Init;
  25.             bool HasLast;
  26.             int LastBounces;
  27.             int LastAllAngles;
  28.             Site StepSlideMode;
  29.             Site ProjectVelocityRet;
  30.             Site JumpClear[3];
  31.         };
  32.  
  33.         static PatchState S = {};
  34.  
  35.         static void InitializeIfNeeded()
  36.         {
  37.             if (S.Init)
  38.                 return;
  39.  
  40.             S.StepSlideMode.address = 0x8210CB74;
  41.             S.StepSlideMode.original = ReadInstruction(0x8210CB74);
  42.  
  43.             S.ProjectVelocityRet.address = 0x82104008;
  44.             S.ProjectVelocityRet.original = ReadInstruction(0x82104008);
  45.  
  46.             S.JumpClear[0].address = 0x8210A650;
  47.             S.JumpClear[0].original = ReadInstruction(0x8210A650);
  48.             S.JumpClear[1].address = 0x8210C8A8;
  49.             S.JumpClear[1].original = ReadInstruction(0x8210C8A8);
  50.             S.JumpClear[2].address = 0x8210C954;
  51.             S.JumpClear[2].original = ReadInstruction(0x8210C954);
  52.  
  53.             S.Init = true;
  54.         }
  55.  
  56.         void Apply()
  57.         {
  58.             InitializeIfNeeded();
  59.  
  60.             const int BgBounces = dvar::Dvar_GetInt("bg_bounces");
  61.             const int BgAllAngles = dvar::Dvar_GetInt("bg_bouncesAllAngles");
  62.  
  63.             if (S.HasLast
  64.                 && BgBounces == S.LastBounces
  65.                 && BgAllAngles == S.LastAllAngles)
  66.             {
  67.                 return;
  68.             }
  69.  
  70.             if (BgBounces <= 0)
  71.             {
  72.                 Memory::Write32(S.StepSlideMode.address, S.StepSlideMode.original);
  73.             }
  74.             else if (BgAllAngles == 2)
  75.             {
  76.                 Memory::WriteBranch(S.StepSlideMode.address, 0x8210CB8C);
  77.             }
  78.             else
  79.             {
  80.                 Memory::Write32(S.StepSlideMode.address, Memory::Nop());
  81.             }
  82.  
  83.             Memory::Write32(
  84.                 S.ProjectVelocityRet.address,
  85.                 BgAllAngles > 0 ? Memory::Nop() : S.ProjectVelocityRet.original);
  86.  
  87.             const bool DisableJumpClear = BgBounces == 2;
  88.             for (size_t I = 0; I < (sizeof(S.JumpClear) / sizeof(S.JumpClear[0])); ++I)
  89.             {
  90.                 const Site &Cur = S.JumpClear[I];
  91.                 Memory::Write32(Cur.address, DisableJumpClear ? Memory::Nop() : Cur.original);
  92.             }
  93.  
  94.             S.LastBounces = BgBounces;
  95.             S.LastAllAngles = BgAllAngles;
  96.             S.HasLast = true;
  97.         }
  98.     }
  99.  
  100.     namespace ElevatorPatches
  101.     {
  102.         struct PatchState
  103.         {
  104.             bool Init;
  105.             bool HasLast;
  106.             int LastMode;
  107.             Site FirstStartSolid;
  108.             Site SecondStartSolid;
  109.             Site AllSolid[3];
  110.         };
  111.  
  112.         static PatchState S = {};
  113.  
  114.         static void InitializeIfNeeded()
  115.         {
  116.             if (S.Init)
  117.                 return;
  118.  
  119.             S.FirstStartSolid.address = 0x8210A2A0;
  120.             S.FirstStartSolid.original = ReadInstruction(0x8210A2A0);
  121.  
  122.             S.SecondStartSolid.address = 0x8210A2F0;
  123.             S.SecondStartSolid.original = ReadInstruction(0x8210A2F0);
  124.  
  125.             S.AllSolid[0].address = 0x82106DB8;
  126.             S.AllSolid[0].original = ReadInstruction(0x82106DB8);
  127.             S.AllSolid[1].address = 0x82106E64;
  128.             S.AllSolid[1].original = ReadInstruction(0x82106E64);
  129.             S.AllSolid[2].address = 0x82106F30;
  130.             S.AllSolid[2].original = ReadInstruction(0x82106F30);
  131.  
  132.             S.Init = true;
  133.         }
  134.  
  135.         void Apply()
  136.         {
  137.             InitializeIfNeeded();
  138.  
  139.             const int BgElevators = dvar::Dvar_GetInt("bg_elevators");
  140.             if (S.HasLast && BgElevators == S.LastMode)
  141.                 return;
  142.  
  143.             const bool EasyElevators = BgElevators == 2;
  144.             const bool NormalOrEasy = BgElevators >= 1;
  145.  
  146.             Memory::Write32(
  147.                 S.FirstStartSolid.address,
  148.                 EasyElevators ? Memory::Nop() : S.FirstStartSolid.original);
  149.  
  150.             if (NormalOrEasy)
  151.                 Memory::WriteBranch(S.SecondStartSolid.address, 0x8210A334);
  152.             else
  153.                 Memory::Write32(S.SecondStartSolid.address, S.SecondStartSolid.original);
  154.  
  155.             for (size_t I = 0; I < (sizeof(S.AllSolid) / sizeof(S.AllSolid[0])); ++I)
  156.             {
  157.                 const Site &Cur = S.AllSolid[I];
  158.                 Memory::Write32(Cur.address, EasyElevators ? Memory::Nop() : Cur.original);
  159.             }
  160.  
  161.             S.LastMode = BgElevators;
  162.             S.HasLast = true;
  163.         }
  164.     }
  165.  
  166. }
  167.  
  168. void iw4mpHooks::ScrDrawScreenFieldHook(int localClientNum, int refreshedUI)
  169. {
  170.     s_pInstance->m_pScrDrawScreenFieldHook->GetOriginal(&ScrDrawScreenFieldHook)(localClientNum, refreshedUI);
  171.  
  172.     BouncePatches::Apply();
  173.     ElevatorPatches::Apply();
  174. }
Advertisement
Add Comment
Please, Sign In to add comment