Facebook
From Ivory Pheasant, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 4923
  1. #include "Menu.h"
  2. #include "Controls.h"
  3. #include "Hooks.h" // for the unload meme
  4. #include "Interfaces.h"
  5.  
  6. #define WINDOW_WIDTH 800
  7. #define WINDOW_HEIGHT 600
  8.  
  9. AimWareWindow Menu::Window;
  10.  
  11. void UnLoadCallbk()
  12. {
  13.     DoUnload = true;
  14. }
  15.  
  16. void KnifeApplyCallbk()
  17. {
  18.     static ConVar* Meme = Interfaces::CVar->FindVar("cl_fullupdate");
  19.     Meme->nFlags &= ~FCVAR_CHEAT;
  20.     Interfaces::Engine->ClientCmd_Unrestricted("cl_fullupdate");
  21. }
  22.  
  23. void AimWareWindow::Setup()
  24. {
  25.     SetPosition(50, 50);
  26.     SetSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  27.     SetTitle(" PatrickHook-BestPrivateCheats);
  28.  
  29.     RegisterTab(&RageBotTab);
  30.     RegisterTab(&LegitBotTab);
  31.     RegisterTab(&VisualsTab);
  32.     RegisterTab(&MiscTab);
  33.  
  34.     RECT Client = GetClientArea();
  35.     Client.bottom -= 29;
  36.  
  37.     RageBotTab.Setup();
  38.     LegitBotTab.Setup();
  39.     VisualsTab.Setup();
  40.     MiscTab.Setup();
  41.  
  42. #pragma region Bottom Buttons
  43.     UnloadButton.SetText("PANIC");
  44.     UnloadButton.SetCallback(UnLoadCallbk);
  45.     UnloadButton.SetPosition(16, Client.bottom - 42);
  46.  
  47.     RageBotTab.RegisterControl(&UnloadButton);
  48.     LegitBotTab.RegisterControl(&UnloadButton);
  49.     VisualsTab.RegisterControl(&UnloadButton);
  50.     MiscTab.RegisterControl(&UnloadButton);
  51.  
  52.     //SaveButton.SetText("Save Settings");
  53.     //SaveButton.SetCallback(Call);
  54.     //SaveButton.SetPosition(112, Client.bottom - 42);
  55.  
  56.     //RageBotTab.RegisterControl(&SaveButton);
  57.     //LegitBotTab.RegisterControl(&SaveButton);
  58.     //VisualsTab.RegisterControl(&SaveButton);
  59.     //MiscTab.RegisterControl(&SaveButton);
  60.  
  61.  
  62. #pragma endregion Setting up the settings buttons
  63. }
  64.  
  65. void CRageBotTab::Setup()
  66. {
  67.     SetTitle("Rage Aimbot");
  68.  
  69.     ActiveLabel.SetPosition(16, 16);
  70.     ActiveLabel.SetText("Active");
  71.     RegisterControl(&ActiveLabel);
  72.  
  73.     Active.SetFileId("active");
  74.     Active.SetPosition(66, 16);
  75.     RegisterControl(&Active);
  76.  
  77. #pragma region Aimbot
  78.  
  79.     AimbotGroup.SetPosition(16, 48);
  80.     AimbotGroup.SetText("Aimbot");
  81.     AimbotGroup.SetSize(376, 280);
  82.     RegisterControl(&AimbotGroup);
  83.  
  84.     AimbotEnable.SetFileId("aim_enable");
  85.     AimbotGroup.PlaceLabledControl("Enable", this, &AimbotEnable);
  86.  
  87.     AimbotAutoFire.SetFileId("aim_autofire");
  88.     AimbotGroup.PlaceLabledControl("Auto Fire", this, &AimbotAutoFire);
  89.  
  90.     AimbotFov.SetFileId("aim_fov");
  91.     AimbotFov.SetBoundaries(0.f, 180.f);
  92.     AimbotFov.SetValue(39.f);
  93.     AimbotGroup.PlaceLabledControl("FOV Range", this, &AimbotFov);
  94.  
  95.     AimbotSilentAim.SetFileId("aim_silent");
  96.     AimbotGroup.PlaceLabledControl("Silent Aim", this, &AimbotSilentAim);
  97.  
  98.     AimbotPSilent.SetFileId("aim_psilent");
  99.     AimbotGroup.PlaceLabledControl("Perfect Silent", this, &AimbotPSilent);
  100.  
  101.     AimbotAutoPistol.SetFileId("aim_autopistol");
  102.     AimbotGroup.PlaceLabledControl("Auto Pistol", this, &AimbotAutoPistol);
  103.  
  104.     AimbotAimStep.SetFileId("aim_aimstep");
  105.     AimbotGroup.PlaceLabledControl("Aim Step", this, &AimbotAimStep);
  106.  
  107.     AimbotKeyPress.SetFileId("aim_usekey");
  108.     AimbotGroup.PlaceLabledControl("On Key Press", this, &AimbotKeyPress);
  109.  
  110.     AimbotKeyBind.SetFileId("aim_key");
  111.     AimbotGroup.PlaceLabledControl("Key", this, &AimbotKeyBind);
  112.  
  113.     AimbotChicken.SetFileId("aim_chicken");
  114.     AimbotGroup.PlaceLabledControl("Chikens", this, &AimbotChicken);
  115.  
  116. #pragma endregion Aimbot Controls Get Setup in here
  117.  
  118. #pragma region Target
  119.     TargetGroup.SetPosition(16, 344);
  120.     TargetGroup.SetText("Target");
  121.     TargetGroup.SetSize(376, 134);
  122.     RegisterControl(&TargetGroup);
  123.  
  124.     TargetSelection.SetFileId("tgt_selection");
  125.     TargetSelection.AddItem("Closest To Crosshair");
  126.     TargetSelection.AddItem("Distance");
  127.     TargetSelection.AddItem("Lowest Health");
  128.     TargetGroup.PlaceLabledControl("Selection", this, &TargetSelection);
  129.  
  130.     TargetFriendlyFire.SetFileId("tgt_friendlyfire");
  131.     TargetGroup.PlaceLabledControl("Friendly Fire", this, &TargetFriendlyFire);
  132.  
  133.     TargetHitbox.SetFileId("tgt_hitbox");
  134.     TargetHitbox.AddItem("Head");
  135.     TargetHitbox.AddItem("Neck");
  136.     TargetHitbox.AddItem("Chest");
  137.     TargetHitbox.AddItem("Stomach");
  138.     TargetGroup.PlaceLabledControl("Hitbox", this, &TargetHitbox);
  139.  
  140.     TargetHitscan.SetFileId("tgt_hitscan");
  141.     TargetHitscan.AddItem("Off"); //0
  142.     TargetHitscan.AddItem("Head / Body"); // 1
  143.     TargetHitscan.AddItem("All Basic"); // 2
  144.     TargetHitscan.AddItem("All Fucking Heaps"); // 3
  145.     TargetGroup.PlaceLabledControl("Hit Scan", this, &TargetHitscan);
  146. #pragma endregion Targetting controls
  147.  
  148. #pragma region Accuracy
  149.     AccuracyGroup.SetPosition(408, 48);
  150.     AccuracyGroup.SetText("Accuracy");
  151.     AccuracyGroup.SetSize(360, 280);
  152.     RegisterControl(&AccuracyGroup);
  153.  
  154.     AccuracySpread.SetFileId("acc_nospread");
  155.     AccuracyGroup.PlaceLabledControl("Anti Spread", this, &AccuracySpread);
  156.  
  157.     AccuracyRecoil.SetFileId("acc_norecoil");
  158.     AccuracyGroup.PlaceLabledControl("Anti Recoil", this, &AccuracyRecoil);
  159.  
  160.     AccuracyAutoWall.SetFileId("acc_awall");
  161.     AccuracyGroup.PlaceLabledControl("Auto Wall", this, &AccuracyAutoWall);
  162.  
  163.     AccuracyMinimumDamage.SetFileId("acc_mindmg");
  164.     AccuracyMinimumDamage.SetBoundaries(1.f, 100.f);
  165.     AccuracyMinimumDamage.SetValue(1.f);
  166.     AccuracyGroup.PlaceLabledControl("Min AWall Damage", this, &AccuracyMinimumDamage);
  167.  
  168.     AccuracyAutoStop.SetFileId("acc_stop");
  169.     AccuracyGroup.PlaceLabledControl("Auto Stop", this, &AccuracyAutoStop);
  170.  
  171.     AccuracyAutoCrouch.SetFileId("acc_crouch");
  172.     AccuracyGroup.PlaceLabledControl("Auto Crouch", this, &AccuracyAutoCrouch);
  173.  
  174.     AccuracyAutoScope.SetFileId("acc_scope");
  175.     AccuracyGroup.PlaceLabledControl("Auto Scope", this, &AccuracyAutoScope);
  176.  
  177.     AccuracySpreadLimit.SetFileId("acc_spreadlimon");
  178.     AccuracyGroup.PlaceLabledControl("Spread Limit", this, &AccuracySpreadLimit);
  179.  
  180.     AccuracyMinimumSpread.SetFileId("acc_spreadlim");
  181.     AccuracyMinimumSpread.SetBoundaries(0.f, 5.0f);
  182.     AccuracyMinimumSpread.SetValue(1.5f);
  183.     AccuracyGroup.PlaceLabledControl("Spread Limit Value", this, &AccuracyMinimumSpread);
  184.  
  185.     AccuracyAngleFix.SetFileId("acc_aaa");
  186.     AccuracyGroup.PlaceLabledControl("AngleFix", this, &AccuracyAngleFix);
  187. #pragma endregion  Accuracy controls get Setup in here
  188.  
  189. #pragma region AntiAim
  190.     AntiAimGroup.SetPosition(408, 344);
  191.     AntiAimGroup.SetText("Anti-Aim");
  192.     AntiAimGroup.SetSize(360, 134);
  193.     RegisterControl(&AntiAimGroup);
  194.  
  195.     AntiAimEnable.SetFileId("aa_enable");
  196.     AntiAimGroup.PlaceLabledControl("Enable", this, &AntiAimEnable);
  197.  
  198.     AntiAimPitch.SetFileId("aa_x");
  199.     AntiAimPitch.AddItem("None");
  200.     AntiAimPitch.AddItem("Up");
  201.     AntiAimPitch.AddItem("Down");
  202.     AntiAimPitch.AddItem("Jitter");
  203.     AntiAimGroup.PlaceLabledControl("X", this, &AntiAimPitch);
  204.  
  205.     AntiAimYaw.SetFileId("aa_y");
  206.     AntiAimYaw.AddItem("None");
  207.     AntiAimYaw.AddItem("Spin Fast");
  208.     AntiAimYaw.AddItem("Spin Slow");
  209.     AntiAimYaw.AddItem("Inverse");
  210.     AntiAimYaw.AddItem("Jitter");
  211.     AntiAimYaw.AddItem("Flip");
  212.     AntiAimGroup.PlaceLabledControl("Y", this, &AntiAimYaw);
  213.  
  214. #pragma endregion  AntiAim controls get setup in here
  215. }
  216.  
  217. void CLegitBotTab::Setup()
  218. {
  219.     SetTitle("Legit Aimbot");
  220.  
  221.     ActiveLabel.SetPosition(16, 16);
  222.     ActiveLabel.SetText("Active");
  223.     RegisterControl(&ActiveLabel);
  224.  
  225.     Active.SetFileId("active");
  226.     Active.SetPosition(66, 16);
  227.     RegisterControl(&Active);
  228.  
  229. #pragma region Aimbot
  230.     AimbotGroup.SetPosition(16, 48);
  231.     AimbotGroup.SetText("Aimbot");
  232.     AimbotGroup.SetSize(240, 210);
  233.     RegisterControl(&AimbotGroup);
  234.  
  235.     AimbotEnable.SetFileId("aim_enable");
  236.     AimbotGroup.PlaceLabledControl("Enable", this, &AimbotEnable);
  237.  
  238.     AimbotAutoFire.SetFileId("aim_autofire");
  239.     AimbotGroup.PlaceLabledControl("Auto Fire", this, &AimbotAutoFire);
  240.  
  241.     AimbotFriendlyFire.SetFileId("aim_friendfire");
  242.     AimbotGroup.PlaceLabledControl("Friendly Fire", this, &AimbotFriendlyFire);
  243.  
  244.     AimbotKeyPress.SetFileId("aim_usekey");
  245.     AimbotGroup.PlaceLabledControl("On Key Press", this, &AimbotKeyPress);
  246.  
  247.     AimbotKeyBind.SetFileId("aim_key");
  248.     AimbotGroup.PlaceLabledControl("Key Bind", this, &AimbotKeyBind);
  249.  
  250.     AimbotAutoPistol.SetFileId("aim_apistol");
  251.     AimbotGroup.PlaceLabledControl("Auto Pistol", this, &AimbotAutoPistol);
  252.  
  253. #pragma endregion Aimbot shit
  254.  
  255. #pragma region Triggerbot
  256.     TriggerGroup.SetPosition(272, 48);
  257.     TriggerGroup.SetText("Triggerbot");
  258.     TriggerGroup.SetSize(240, 210);
  259.     RegisterControl(&TriggerGroup);
  260.  
  261.     TriggerEnable.SetFileId("trig_enable");
  262.     TriggerGroup.PlaceLabledControl("Enable", this, &TriggerEnable);
  263.  
  264.     TriggerKeyPress.SetFileId("trig_onkey");
  265.     TriggerGroup.PlaceLabledControl("On Key Press", this, &TriggerKeyPress);
  266.  
  267.     TriggerKeyBind.SetFileId("trig_key");
  268.     TriggerGroup.PlaceLabledControl("Key Bind", this, &TriggerKeyBind);
  269.  
  270.     TriggerDelay.SetFileId("trig_delay");
  271.     TriggerDelay.SetBoundaries(1, 1000);
  272.     TriggerDelay.SetValue(50);
  273.     TriggerGroup.PlaceLabledControl("Delay", this, &TriggerDelay);
  274. #pragma endregion Triggerbot stuff
  275.  
  276. #pragma region Main Weapon
  277.     WeaponMainGroup.SetPosition(16, 274);
  278.     WeaponMainGroup.SetText("Rifles/Other");
  279.     WeaponMainGroup.SetSize(240, 210);
  280.     RegisterControl(&WeaponMainGroup);
  281.  
  282.     WeaponMainSpeed.SetFileId("main_speed");
  283.     WeaponMainSpeed.SetBoundaries(0.1f, 2.f);
  284.     WeaponMainSpeed.SetValue(1.0f);
  285.     WeaponMainGroup.PlaceLabledControl("Max Speed", this, &WeaponMainSpeed);
  286.  
  287.     WeaponMainFoV.SetFileId("main_fov");
  288.     WeaponMainFoV.SetBoundaries(0.1f, 30.f);
  289.     WeaponMainFoV.SetValue(5.f);
  290.     WeaponMainGroup.PlaceLabledControl("FOV", this, &WeaponMainFoV);
  291.  
  292.     WeaponMainRecoil.SetFileId("main_recoil");
  293.     WeaponMainGroup.PlaceLabledControl("Recoil", this, &WeaponMainRecoil);
  294.  
  295.     WeaponMainHitbox.SetFileId("main_hitbox");
  296.     WeaponMainHitbox.AddItem("Head");
  297.     WeaponMainHitbox.AddItem("Neck");
  298.     WeaponMainHitbox.AddItem("Chest");
  299.     WeaponMainHitbox.AddItem("Stomach");
  300.     WeaponMainGroup.PlaceLabledControl("Hitbox", this, &WeaponMainHitbox);
  301. #pragma endregion
  302.  
  303. #pragma region Pistols
  304.     WeaponPistGroup.SetPosition(272, 274);
  305.     WeaponPistGroup.SetText("Pistols");
  306.     WeaponPistGroup.SetSize(240, 210);
  307.     RegisterControl(&WeaponPistGroup);
  308.  
  309.     WeaponPistSpeed.SetFileId("pist_speed");
  310.     WeaponPistSpeed.SetBoundaries(0.1f, 2.f);
  311.     WeaponPistSpeed.SetValue(1.0f);
  312.     WeaponPistGroup.PlaceLabledControl("Max Speed", this, &WeaponPistSpeed);
  313.  
  314.     WeaponPistFoV.SetFileId("pist_fov");
  315.     WeaponPistFoV.SetBoundaries(0.1f, 30.f);
  316.     WeaponPistFoV.SetValue(5.f);
  317.     WeaponPistGroup.PlaceLabledControl("FOV", this, &WeaponPistFoV);
  318.  
  319.     WeaponPistRecoil.SetFileId("pist_recoil");
  320.     WeaponPistGroup.PlaceLabledControl("Recoil", this, &WeaponPistRecoil);
  321.  
  322.     WeaponPistHitbox.SetFileId("pist_hitbox");
  323.     WeaponPistHitbox.AddItem("Head");
  324.     WeaponPistHitbox.AddItem("Neck");
  325.     WeaponPistHitbox.AddItem("Chest");
  326.     WeaponPistHitbox.AddItem("Stomach");
  327.     WeaponPistGroup.PlaceLabledControl("Hitbox", this, &WeaponPistHitbox);
  328. #pragma endregion
  329.  
  330. #pragma region Snipers
  331.     WeaponSnipGroup.SetPosition(528, 274);
  332.     WeaponSnipGroup.SetText("Snipers");
  333.     WeaponSnipGroup.SetSize(240, 210);
  334.     RegisterControl(&WeaponSnipGroup);
  335.  
  336.     WeaponSnipSpeed.SetFileId("snip_speed");
  337.     WeaponSnipSpeed.SetBoundaries(0.1f, 2.f);
  338.     WeaponSnipSpeed.SetValue(1.0f);
  339.     WeaponSnipGroup.PlaceLabledControl("Max Speed", this, &WeaponSnipSpeed);
  340.  
  341.     WeaponSnipFoV.SetFileId("snip_fov");
  342.     WeaponSnipFoV.SetBoundaries(0.1f, 30.f);
  343.     WeaponSnipFoV.SetValue(5.f);
  344.     WeaponSnipGroup.PlaceLabledControl("FOV", this, &WeaponSnipFoV);
  345.  
  346.     WeaponSnipRecoil.SetFileId("snip_recoil");
  347.     WeaponSnipGroup.PlaceLabledControl("Recoil", this, &WeaponSnipRecoil);
  348.  
  349.     WeaponSnipHitbox.SetFileId("snip_hitbox");
  350.     WeaponSnipHitbox.AddItem("Head");
  351.     WeaponSnipHitbox.AddItem("Neck");
  352.     WeaponSnipHitbox.AddItem("Chest");
  353.     WeaponSnipHitbox.AddItem("Stomach");
  354.     WeaponSnipGroup.PlaceLabledControl("Hitbox", this, &WeaponSnipHitbox);
  355. #pragma endregion
  356. }
  357.  
  358. void CVisualTab::Setup()
  359. {
  360.     SetTitle("Visuals & Misc");
  361.  
  362.     ActiveLabel.SetPosition(16, 16);
  363.     ActiveLabel.SetText("Active");
  364.     RegisterControl(&ActiveLabel);
  365.  
  366.     Active.SetFileId("active");
  367.     Active.SetPosition(66, 16);
  368.     RegisterControl(&Active);
  369.  
  370. #pragma region Options
  371.     OptionsGroup.SetText("Options");
  372.     OptionsGroup.SetPosition(16, 48);
  373.     OptionsGroup.SetSize(193, 430);
  374.     RegisterControl(&OptionsGroup);
  375.  
  376.     OptionsBox.SetFileId("opt_box");
  377.     OptionsGroup.PlaceLabledControl("Box", this, &OptionsBox);
  378.  
  379.     OptionsName.SetFileId("opt_name");
  380.     OptionsGroup.PlaceLabledControl("Name", this, &OptionsName);
  381.  
  382.     OptionsHealth.SetFileId("opt_hp");
  383.     OptionsGroup.PlaceLabledControl("Health", this, &OptionsHealth);
  384.  
  385.     OptionsWeapon.SetFileId("opt_weapon");
  386.     OptionsGroup.PlaceLabledControl("Weapon", this, &OptionsWeapon);
  387.  
  388.     OptionsInfo.SetFileId("opt_info");
  389.     OptionsGroup.PlaceLabledControl("Info", this, &OptionsInfo);
  390.  
  391.     OptionsChams.SetFileId("opt_chams");
  392.     OptionsChams.AddItem("Off");
  393.     OptionsChams.AddItem("Normal");
  394.     OptionsChams.AddItem("Flat");
  395.     OptionsGroup.PlaceLabledControl("Chams", this, &OptionsChams);
  396.  
  397.     OptionsSkeleton.SetFileId("opt_bone");
  398.     OptionsGroup.PlaceLabledControl("Skeleton", this, &OptionsSkeleton);
  399.  
  400.     OptionsAimSpot.SetFileId("opt_aimspot");
  401.     OptionsGroup.PlaceLabledControl("Aim Spot", this, &OptionsAimSpot);
  402.  
  403.     OptionsCompRank.SetFileId("opt_comprank");
  404.     OptionsGroup.PlaceLabledControl("Competitive Rank", this, &OptionsCompRank);
  405.  
  406. #pragma endregion Setting up the Options controls
  407.  
  408. #pragma region Filters
  409.     FiltersGroup.SetText("Filters");
  410.     FiltersGroup.SetPosition(225, 48);
  411.     FiltersGroup.SetSize(193, 430);
  412.     RegisterControl(&FiltersGroup);
  413.  
  414.     FiltersAll.SetFileId("ftr_all");
  415.     FiltersGroup.PlaceLabledControl("All", this, &FiltersAll);
  416.  
  417.     FiltersPlayers.SetFileId("ftr_players");
  418.     FiltersGroup.PlaceLabledControl("Players", this, &FiltersPlayers);
  419.  
  420.     FiltersEnemiesOnly.SetFileId("ftr_enemyonly");
  421.     FiltersGroup.PlaceLabledControl("Enemies Only", this, &FiltersEnemiesOnly);
  422.  
  423.     FiltersWeapons.SetFileId("ftr_weaps");
  424.     FiltersGroup.PlaceLabledControl("Weapons", this, &FiltersWeapons);
  425.  
  426.     FiltersChickens.SetFileId("ftr_chickens");
  427.     FiltersGroup.PlaceLabledControl("Chickens", this, &FiltersChickens);
  428.  
  429.     FiltersC4.SetFileId("ftr_c4");
  430.     FiltersGroup.PlaceLabledControl("C4", this, &FiltersC4);
  431. #pragma endregion Setting up the Filters controls
  432.  
  433. #pragma region Other
  434.     OtherGroup.SetText("Other");
  435.     OtherGroup.SetPosition(434, 48);
  436.     OtherGroup.SetSize(334, 430);
  437.     RegisterControl(&OtherGroup);
  438.  
  439.     OtherCrosshair.SetFileId("otr_xhair");
  440.     OtherGroup.PlaceLabledControl("Crosshair", this, &OtherCrosshair);
  441.  
  442.     OtherRecoilCrosshair.SetFileId("otr_recoilhair");
  443.     OtherRecoilCrosshair.AddItem("Off");
  444.     OtherRecoilCrosshair.AddItem("Recoil Position");
  445.     OtherRecoilCrosshair.AddItem("Radius");
  446.     OtherGroup.PlaceLabledControl("Recoil Crosshair", this, &OtherRecoilCrosshair);
  447.  
  448.     OtherRadar.SetFileId("otr_radar");
  449.     OtherGroup.PlaceLabledControl("Radar", this, &OtherRadar);
  450.  
  451.     OtherNoVisualRecoil.SetFileId("otr_visrecoil");
  452.     OtherGroup.PlaceLabledControl("No Visual Recoil", this, &OtherNoVisualRecoil);
  453.  
  454.     OtherNoSky.SetFileId("otr_nosky");
  455.     OtherGroup.PlaceLabledControl("No Sky", this, &OtherNoSky);
  456.  
  457.     OtherNoFlash.SetFileId("otr_noflash");
  458.     OtherGroup.PlaceLabledControl("No Flash", this, &OtherNoFlash);
  459.  
  460.     OtherNoSmoke.SetFileId("otr_nosmoke");
  461.     OtherGroup.PlaceLabledControl("No Smoke", this, &OtherNoSmoke);
  462.  
  463.     OtherNoHands.SetFileId("otr_hands");
  464.     OtherNoHands.AddItem("Off");
  465.     OtherNoHands.AddItem("None");
  466.     OtherNoHands.AddItem("Transparent");
  467.     OtherNoHands.AddItem("Chams");
  468.     OtherNoHands.AddItem("Rainbow");
  469.     OtherGroup.PlaceLabledControl("Hands", this, &OtherNoHands);
  470.  
  471.     OtherAutoJump.SetFileId("otr_autojump");
  472.     OtherGroup.PlaceLabledControl("Auto Jump", this, &OtherAutoJump);
  473.  
  474.     OtherAutoStrafe.SetFileId("otr_autostrafe");
  475.     OtherGroup.PlaceLabledControl("Auto Strafe", this, &OtherAutoStrafe);
  476.  
  477.     OtherSafeMode.SetFileId("otr_safemode");
  478.     OtherSafeMode.SetState(true);
  479.     OtherGroup.PlaceLabledControl("Safe Mode", this, &OtherSafeMode);
  480.  
  481.     OtherChatSpam.SetFileId("otr_spam");
  482.     OtherChatSpam.AddItem("Off");
  483.     OtherChatSpam.AddItem("Round-Say");
  484.     OtherChatSpam.AddItem("Regular");
  485.     OtherChatSpam.AddItem("Report Text Spam");
  486.     OtherGroup.PlaceLabledControl("Chat Spam", this, &OtherChatSpam);
  487.  
  488.     OtherAirStuck.SetFileId("otr_astuck");
  489.     OtherGroup.PlaceLabledControl("Air Stuck", this, &OtherAirStuck);
  490.  
  491.     OtherSpectators.SetFileId("otr_speclist");
  492.     OtherGroup.PlaceLabledControl("Spectators List", this, &OtherSpectators);
  493. #pragma endregion Setting up the Other controls
  494. }
  495.  
  496. void CMiscTab::Setup()
  497. {
  498.     SetTitle("Skins");
  499.  
  500. #pragma region Knife
  501.     KnifeGroup.SetPosition(16, 16);
  502.     KnifeGroup.SetSize(360, 400);
  503.     KnifeGroup.SetText("Skin Changer");
  504.     RegisterControl(&KnifeGroup);
  505.  
  506.     KnifeEnable.SetFileId("knife_enable");
  507.     KnifeGroup.PlaceLabledControl("Enable", this, &KnifeEnable);
  508.  
  509.     KnifeModel.SetFileId("knife_model");
  510.     KnifeModel.AddItem("Karambit");
  511.     KnifeModel.AddItem("Bayonet");
  512.     KnifeModel.AddItem("Huntsman Knife");
  513.     KnifeModel.AddItem("Gut Knife");
  514.     KnifeModel.AddItem("Walmart Knife");
  515.     KnifeModel.AddItem("Shadow Daggers");
  516.     KnifeModel.AddItem("Butterfly Knife");
  517.     KnifeModel.AddItem("Flip Knife");
  518.     KnifeGroup.PlaceLabledControl("Knife", this, &KnifeModel);
  519.  
  520.     KnifeSkin.SetFileId("knife_skin");
  521.     KnifeSkin.AddItem("Fade");
  522.     KnifeSkin.AddItem("Damascus Steel");
  523.     KnifeSkin.AddItem("Doppler Phase 1");
  524.     KnifeSkin.AddItem("Doppler Phase 2");
  525.     KnifeSkin.AddItem("Doppler Phase 3");
  526.     KnifeSkin.AddItem("Doppler Phase 4");
  527.     KnifeSkin.AddItem("Doppler (Ruby)");
  528.     KnifeSkin.AddItem("Doppler (Sapphire)");
  529.     KnifeSkin.AddItem("Doppler (Blackpearl)");
  530.     KnifeSkin.AddItem("Marble Fade");
  531.     KnifeSkin.AddItem("Tiger Tooth");
  532.     KnifeSkin.AddItem("Ultraviolet");
  533.     KnifeSkin.AddItem("Crimson Web");
  534.     KnifeSkin.AddItem("Slaughter");
  535.     KnifeSkin.AddItem("Night");
  536.     KnifeGroup.PlaceLabledControl("Skin", this, &KnifeSkin);
  537.  
  538.     M41SSkin.SetFileId("m4a1s_skin");
  539.     M41SSkin.AddItem("Masterpiece");
  540.     M41SSkin.AddItem("Hyper Beast");
  541.     M41SSkin.AddItem("Cyrex");
  542.     M41SSkin.AddItem("Hot Rod");
  543.     KnifeGroup.PlaceLabledControl("M4A1-S", this, &M41SSkin);
  544.  
  545.     M4A4Skin.SetFileId("m4a4_skin");
  546.     M4A4Skin.AddItem("Royal Paladin");
  547.     M4A4Skin.AddItem("Howl");
  548.     M4A4Skin.AddItem("Bullet Rain");
  549.     M4A4Skin.AddItem("Dragon King");
  550.     M4A4Skin.AddItem("Asiimov");
  551.     KnifeGroup.PlaceLabledControl("M4A4", this, &M4A4Skin);
  552.  
  553.     AK47Skin.SetFileId("ak47_skin");
  554.     AK47Skin.AddItem("Point Disarray");
  555.     AK47Skin.AddItem("Aquamarine Revenge");
  556.     AK47Skin.AddItem("Vulcan");
  557.     AK47Skin.AddItem("Fire Serpent");
  558.     AK47Skin.AddItem("Jaguar");
  559.     KnifeGroup.PlaceLabledControl("AK-47", this, &AK47Skin);
  560.  
  561.     AWPSkin.SetFileId("awp_skin");
  562.     AWPSkin.AddItem("Hyper Beast");
  563.     AWPSkin.AddItem("Asiimov");
  564.     AWPSkin.AddItem("Dragon Lore");
  565.     AWPSkin.AddItem("Lightning Strike");
  566.     KnifeGroup.PlaceLabledControl("AWP", this, &AWPSkin);
  567.  
  568.     GLOCKSkin.SetFileId("glock_skin");
  569.     GLOCKSkin.AddItem("Water Elemental");
  570.     GLOCKSkin.AddItem("Fade");
  571.     GLOCKSkin.AddItem("Twilight Galaxy");
  572.     GLOCKSkin.AddItem("Bunsen Burner");
  573.     KnifeGroup.PlaceLabledControl("Glock", this, &GLOCKSkin);
  574.  
  575.     USPSSkin.SetFileId("m4a1s_skin");
  576.     USPSSkin.AddItem("Kill Confirmed");
  577.     USPSSkin.AddItem("Caiman");
  578.     USPSSkin.AddItem("Orion");
  579.     USPSSkin.AddItem("Guardian");
  580.     KnifeGroup.PlaceLabledControl("USP-S", this, &USPSSkin);
  581.  
  582.     MAGNUMSkin.SetFileId("357_skin");
  583.     MAGNUMSkin.AddItem("Crimson Web");
  584.     MAGNUMSkin.AddItem("Fade");
  585.     MAGNUMSkin.AddItem("Amber Fade");
  586.     KnifeGroup.PlaceLabledControl("R8 Revolver", this, &MAGNUMSkin);
  587.  
  588.     KnifeApply.SetText("Apply Changes");
  589.     KnifeApply.SetCallback(KnifeApplyCallbk);
  590.     KnifeGroup.PlaceLabledControl("", this, &KnifeApply);
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597. #pragma endregion
  598.  
  599. #pragma endregion other random options
  600. }
  601.  
  602. void Menu::SetupMenu()
  603. {
  604.     Window.Setup();
  605.  
  606.     GUI.RegisterWindow(&Window);
  607.     GUI.BindWindow(VK_INSERT, &Window);
  608. }
  609.  
  610. void Menu::DoUIFrame()
  611. {
  612.     // General Processing
  613.  
  614.     // If the "all filter is selected tick all the others
  615.     if (Window.VisualsTab.FiltersAll.GetState())
  616.     {
  617.         Window.VisualsTab.FiltersC4.SetState(true);
  618.         Window.VisualsTab.FiltersChickens.SetState(true);
  619.         Window.VisualsTab.FiltersPlayers.SetState(true);
  620.         Window.VisualsTab.FiltersWeapons.SetState(true);
  621.     }
  622.  
  623.     GUI.Update();
  624.     GUI.Draw();
  625.  
  626.  
  627. }
  628.  
  629.  
  630. #include "GUI.h"
  631.  
  632. #include "RenderManager.h"
  633.  
  634. #include <algorithm>
  635. #include "tinyxml2.h"
  636. #include "Controls.h"
  637.  
  638. CGUI GUI;
  639.  
  640. CGUI::CGUI()
  641. {
  642.  
  643. }
  644.  
  645. // Draws all windows
  646. void CGUI::Draw()
  647. {
  648.     bool ShouldDrawCursor = false;
  649.  
  650.     for (auto window : Windows)
  651.     {
  652.         if (window->m_bIsOpen)
  653.         {
  654.             ShouldDrawCursor = true;
  655.             DrawWindow(window);
  656.         }
  657.  
  658.     }
  659.  
  660.     if (ShouldDrawCursor)
  661.     {
  662.         static Vertex_t MouseVt[3];
  663.  
  664.         MouseVt[0].Init(Vector2D(Mouse.x, Mouse.y));
  665.         MouseVt[1].Init(Vector2D(Mouse.x + 16, Mouse.y));
  666.         MouseVt[2].Init(Vector2D(Mouse.x, Mouse.y + 16));
  667.  
  668.         Render::PolygonOutline(3, MouseVt, Color(150, 0, 0, 230), Color(0, 0, 0, 150));
  669.     }
  670. }
  671.  
  672. // Handle all input etc
  673. void CGUI::Update()
  674. {
  675.     //Key Array
  676.     std::copy(keys, keys + 255, oldKeys);
  677.     for (int x = 0; x < 255; x++)
  678.     {
  679.         //oldKeys[x] = oldKeys[x] & keys[x];
  680.         keys[x] = (GetAsyncKeyState(x));
  681.     }
  682.  
  683.     // Mouse Location
  684.     POINT mp; GetCursorPos(&mp);
  685.     Mouse.x = mp.x; Mouse.y = mp.y;
  686.  
  687.     RECT Screen = Render::GetViewport();
  688.  
  689.     // Window Binds
  690.     for (auto & bind : WindowBinds)
  691.     {
  692.         if (GetKeyPress(bind.first))
  693.         {
  694.             bind.second->Toggle();
  695.         }
  696.     }
  697.  
  698.     // Stop dragging
  699.     if (IsDraggingWindow && !GetKeyState(VK_LBUTTON))
  700.     {
  701.         IsDraggingWindow = false;
  702.         DraggingWindow = nullptr;
  703.     }
  704.  
  705.     // If we are in the proccess of dragging a window
  706.     if (IsDraggingWindow && GetKeyState(VK_LBUTTON) && !GetKeyPress(VK_LBUTTON))
  707.     {
  708.         if (DraggingWindow)
  709.         {
  710.             DraggingWindow->m_x = Mouse.x - DragOffsetX;
  711.             DraggingWindow->m_y = Mouse.y - DragOffsetY;
  712.         }
  713.     }
  714.  
  715.     // Process some windows
  716.     for (auto window : Windows)
  717.     {
  718.         if (window->m_bIsOpen)
  719.         {
  720.             // Used to tell the widget processing that there could be a click
  721.             bool bCheckWidgetClicks = false;
  722.  
  723.             // If the user clicks inside the window
  724.             if (GetKeyPress(VK_LBUTTON))
  725.             {
  726.                 if (IsMouseInRegion(window->m_x, window->m_y, window->m_x + window->m_iWidth, window->m_y + window->m_iHeight))
  727.                 {
  728.                     // Is it inside the client area?
  729.                     if (IsMouseInRegion(window->GetClientArea()))
  730.                     {
  731.                         // User is selecting a new tab
  732.                         if (IsMouseInRegion(window->GetTabArea()))
  733.                         {
  734.                             // Loose focus on the control
  735.                             window->IsFocusingControl = false;
  736.                             window->FocusedControl = nullptr;
  737.  
  738.                             int iTab = 0;
  739.                             int TabCount = window->Tabs.size();
  740.                             if (TabCount) // If there are some tabs
  741.                             {
  742.                                 int TabSize = (window->m_iWidth - 4 - 12) / TabCount;
  743.                                 int Dist = Mouse.x - (window->m_x + 8);
  744.                                 while (Dist > TabSize)
  745.                                 {
  746.                                     if (Dist > TabSize)
  747.                                     {
  748.                                         iTab++;
  749.                                         Dist -= TabSize;
  750.                                     }
  751.                                 }
  752.                                 window->SelectedTab = window->Tabs[iTab];
  753.                             }
  754.  
  755.                         }
  756.                         else
  757.                             bCheckWidgetClicks = true;
  758.                     }
  759.                     else
  760.                     {
  761.                         // Must be in the around the title or side of the window
  762.                         // So we assume the user is trying to drag the window
  763.                         IsDraggingWindow = true;
  764.                         DraggingWindow = window;
  765.                         DragOffsetX = Mouse.x - window->m_x;
  766.                         DragOffsetY = Mouse.y - window->m_y;
  767.  
  768.                         // Loose focus on the control
  769.                         window->IsFocusingControl = false;
  770.                         window->FocusedControl = nullptr;
  771.                     }
  772.                 }
  773.                 else
  774.                 {
  775.                     // Loose focus on the control
  776.                     window->IsFocusingControl = false;
  777.                     window->FocusedControl = nullptr;
  778.                 }
  779.             }
  780.  
  781.  
  782.             // Controls
  783.             if (window->SelectedTab != nullptr)
  784.             {
  785.                 // Focused widget
  786.                 bool SkipWidget = false;
  787.                 CControl* SkipMe = nullptr;
  788.  
  789.                 // this window is focusing on a widget??
  790.                 if (window->IsFocusingControl)
  791.                 {
  792.                     if (window->FocusedControl != nullptr)
  793.                     {
  794.                         // We've processed it once, skip it later
  795.                         SkipWidget = true;
  796.                         SkipMe = window->FocusedControl;
  797.  
  798.                         POINT cAbs = window->FocusedControl->GetAbsolutePos();
  799.                         RECT controlRect = { cAbs.x, cAbs.y, window->FocusedControl->m_iWidth, window->FocusedControl->m_iHeight };
  800.                         window->FocusedControl->OnUpdate();
  801.  
  802.                         if (window->FocusedControl->Flag(UIFlags::UI_Clickable) && IsMouseInRegion(controlRect) && bCheckWidgetClicks)
  803.                         {
  804.                             window->FocusedControl->OnClick();
  805.  
  806.                             // If it gets clicked we loose focus
  807.                             window->IsFocusingControl = false;
  808.                             window->FocusedControl = nullptr;
  809.                             bCheckWidgetClicks = false;
  810.                         }
  811.                     }
  812.                 }
  813.  
  814.                 // Itterate over the rest of the control
  815.                 for (auto control : window->SelectedTab->Controls)
  816.                 {
  817.                     if (control != nullptr)
  818.                     {
  819.                         if (SkipWidget && SkipMe == control)
  820.                             continue;
  821.  
  822.                         POINT cAbs = control->GetAbsolutePos();
  823.                         RECT controlRect = { cAbs.x, cAbs.y, control->m_iWidth, control->m_iHeight };
  824.                         control->OnUpdate();
  825.  
  826.                         if (control->Flag(UIFlags::UI_Clickable) && IsMouseInRegion(controlRect) && bCheckWidgetClicks)
  827.                         {
  828.                             control->OnClick();
  829.                             bCheckWidgetClicks = false;
  830.  
  831.                             // Change of focus
  832.                             if (control->Flag(UIFlags::UI_Focusable))
  833.                             {
  834.                                 window->IsFocusingControl = true;
  835.                                 window->FocusedControl = control;
  836.                             }
  837.                             else
  838.                             {
  839.                                 window->IsFocusingControl = false;
  840.                                 window->FocusedControl = nullptr;
  841.                             }
  842.  
  843.                         }
  844.                     }
  845.                 }
  846.  
  847.                 // We must have clicked whitespace
  848.                 if (bCheckWidgetClicks)
  849.                 {
  850.                     // Loose focus on the control
  851.                     window->IsFocusingControl = false;
  852.                     window->FocusedControl = nullptr;
  853.                 }
  854.             }
  855.         }
  856.     }
  857. }
  858.  
  859. // Returns
  860. bool CGUI::GetKeyPress(unsigned int key)
  861. {
  862.     if (keys[key] == true && oldKeys[key] == false)
  863.         return true;
  864.     else
  865.         return false;
  866. }
  867.  
  868. bool CGUI::GetKeyState(unsigned int key)
  869. {
  870.     return keys[key];
  871. }
  872.  
  873. bool CGUI::IsMouseInRegion(int x, int y, int x2, int y2)
  874. {
  875.     if (Mouse.x > x && Mouse.y > y && Mouse.x < x2 && Mouse.y < y2)
  876.         return true;
  877.     else
  878.         return false;
  879. }
  880.  
  881. bool CGUI::IsMouseInRegion(RECT region)
  882. {
  883.     return IsMouseInRegion(region.left, region.top, region.left + region.right, region.top + region.bottom);
  884. }
  885.  
  886. POINT CGUI::GetMouse()
  887. {
  888.     return Mouse;
  889. }
  890.  
  891. bool CGUI::DrawWindow(CWindow* window)
  892. {
  893.     // Main Window
  894.     Render::Outline(window->m_x, window->m_y, window->m_iWidth, window->m_iHeight, Color(20, 20, 20, 80));
  895.     Render::GradientV(window->m_x + 2, window->m_y + 2, window->m_iWidth - 4, 26, Color(0, 0, 0, 255), Color(0, 0, 0, 255));
  896.     Render::Clear(window->m_x + 2, window->m_y + 2 + 26, window->m_iWidth - 4, window->m_iHeight - 4 - 26, Color(0, 0, 0, 255));
  897.     Render::Outline(window->m_x + 1, window->m_y + 1, window->m_iWidth - 2, window->m_iHeight - 2, Color(255, 0, 0, 255));
  898.     Render::Text(window->m_x + 8, window->m_y + 8, Color(255, 255, 255, 255), Render::Fonts::MenuBold, window->Title.c_str());
  899.  
  900.     //Inner
  901.     Render::Outline(window->m_x + 7, window->m_y + 1 + 26, window->m_iWidth - 4 - 10, window->m_iHeight - 2 - 6 - 26, Color(255, 0, 0, 255));
  902.     Render::Clear(window->m_x + 8, window->m_y + 1 + 27, window->m_iWidth - 4 - 12, window->m_iHeight - 2 - 8 - 26, Color(255, 255, 255, 255));
  903.  
  904.     //Tab
  905.     Render::GradientV(window->m_x + 8, window->m_y + 1 + 27, window->m_iWidth - 4 - 12, 29, Color(52, 52, 52, 255), Color(6, 6, 6, 255));
  906.     int TabCount = window->Tabs.size();
  907.     if (TabCount) // If there are some tabs
  908.     {
  909.         int TabSize = (window->m_iWidth - 4 - 12) / TabCount;
  910.         for (int i = 0; i < TabCount; i++)
  911.         {
  912.             RECT TabArea = { window->m_x + 8 + (i * TabSize), window->m_y + 1 + 27, TabSize, 29 };
  913.             CTab* tab = window->Tabs[i];
  914.             if (window->SelectedTab == tab)
  915.             {
  916.                 Render::GradientV(window->m_x + 8 + (i * TabSize), window->m_y + 1 + 27, TabSize, 29, Color(52, 52, 52, 255), Color(106, 106, 106, 255));
  917.             }
  918.             else if (IsMouseInRegion(TabArea))
  919.             {
  920.                 Render::GradientV(window->m_x + 8 + (i * TabSize), window->m_y + 1 + 27, TabSize, 29, Color(106, 106, 106, 255), Color(52, 52, 52, 255));
  921.             }
  922.             RECT TextSize = Render::GetTextSize(Render::Fonts::MenuBold, tab->Title.c_str());
  923.             Render::Text(TabArea.left + (TabSize / 2) - (TextSize.right / 2), TabArea.top + 8, Color(255, 255, 255, 255), Render::Fonts::MenuBold, tab->Title.c_str());
  924.             Render::Clear(window->m_x + 8, window->m_y + 1 + 27, window->m_iWidth - 4 - 12, 2, Color(66, 66, 66, 255));
  925.         }
  926.     }
  927.  
  928.  
  929.     // Controls
  930.     if (window->SelectedTab != nullptr)
  931.     {
  932.         // Focused widget
  933.         bool SkipWidget = false;
  934.         CControl* SkipMe = nullptr;
  935.  
  936.         // this window is focusing on a widget??
  937.         if (window->IsFocusingControl)
  938.         {
  939.             if (window->FocusedControl != nullptr)
  940.             {
  941.                 // We need to draw it last, so skip it in the regular loop
  942.                 SkipWidget = true;
  943.                 SkipMe = window->FocusedControl;
  944.             }
  945.         }
  946.  
  947.  
  948.         // Itterate over all the other controls
  949.         for (auto control : window->SelectedTab->Controls)
  950.         {
  951.             if (SkipWidget && SkipMe == control)
  952.                 continue;
  953.  
  954.             if (control != nullptr && control->Flag(UIFlags::UI_Drawable))
  955.             {
  956.                 POINT cAbs = control->GetAbsolutePos();
  957.                 RECT controlRect = { cAbs.x, cAbs.y, control->m_iWidth, control->m_iHeight };
  958.                 bool hover = false;
  959.                 if (IsMouseInRegion(controlRect))
  960.                 {
  961.                     hover = true;
  962.                 }
  963.                 control->Draw(hover);
  964.             }
  965.         }
  966.  
  967.         // Draw the skipped widget last
  968.         if (SkipWidget)
  969.         {
  970.             auto control = window->FocusedControl;
  971.  
  972.             if (control != nullptr && control->Flag(UIFlags::UI_Drawable))
  973.             {
  974.                 POINT cAbs = control->GetAbsolutePos();
  975.                 RECT controlRect = { cAbs.x, cAbs.y, control->m_iWidth, control->m_iHeight };
  976.                 bool hover = false;
  977.                 if (IsMouseInRegion(controlRect))
  978.                 {
  979.                     hover = true;
  980.                 }
  981.                 control->Draw(hover);
  982.             }
  983.         }
  984.  
  985.     }
  986.  
  987.  
  988.     return true;
  989. }
  990.  
  991. void CGUI::RegisterWindow(CWindow* window)
  992. {
  993.     Windows.push_back(window);
  994.  
  995.     // Resorting to put groupboxes at the start
  996.     for (auto tab : window->Tabs)
  997.     {
  998.         for (auto control : tab->Controls)
  999.         {
  1000.             if (control->Flag(UIFlags::UI_RenderFirst))
  1001.             {
  1002.                 CControl* c = control;
  1003.                 tab->Controls.erase(std::remove(tab->Controls.begin(), tab->Controls.end(), control), tab->Controls.end());
  1004.                 tab->Controls.insert(tab->Controls.begin(), control);
  1005.             }
  1006.         }
  1007.     }
  1008. }
  1009.  
  1010. void CGUI::BindWindow(unsigned char Key, CWindow* window)
  1011. {
  1012.     if (window)
  1013.         WindowBinds[Key] = window;
  1014.     else
  1015.         WindowBinds.erase(Key);
  1016. }
  1017.  
  1018. void CGUI::SaveWindowState(CWindow* window, std::string Filename)
  1019. {
  1020.     // Create a whole new document and we'll just save over top of the old one
  1021.     tinyxml2::XMLDocument Doc;
  1022.  
  1023.     // Root Element is called "ayy"
  1024.     tinyxml2::XMLElement* Root = Doc.NewElement("ayy");
  1025.     Doc.LinkEndChild(Root);
  1026.  
  1027.     Utilities::Log("Saving Window %s", window->Title.c_str());
  1028.  
  1029.     // If the window has some tabs..
  1030.     if (Root && window->Tabs.size() > 0)
  1031.     {
  1032.         for (auto Tab : window->Tabs)
  1033.         {
  1034.             // Add a new section for this tab
  1035.             tinyxml2::XMLElement* TabElement = Doc.NewElement(Tab->Title.c_str());
  1036.             Root->LinkEndChild(TabElement);
  1037.  
  1038.             Utilities::Log("Saving Tab %s", Tab->Title.c_str());
  1039.  
  1040.             // Now we itterate the controls this tab contains
  1041.             if (TabElement && Tab->Controls.size() > 0)
  1042.             {
  1043.                 for (auto Control : Tab->Controls)
  1044.                 {
  1045.                     // If the control is ok to be saved
  1046.                     if (Control && Control->Flag(UIFlags::UI_SaveFile) && Control->FileIdentifier.length() > 1 && Control->FileControlType)
  1047.                     {
  1048.                         // Create an element for the control
  1049.                         tinyxml2::XMLElement* ControlElement = Doc.NewElement(Control->FileIdentifier.c_str());
  1050.                         TabElement->LinkEndChild(ControlElement);
  1051.  
  1052.                         Utilities::Log("Saving control %s", Control->FileIdentifier.c_str());
  1053.  
  1054.                         if (!ControlElement)
  1055.                         {
  1056.                             Utilities::Log("Errorino :(");
  1057.                             return;
  1058.                         }
  1059.  
  1060.                         CCheckBox* cbx = nullptr;
  1061.                         CComboBox* cbo = nullptr;
  1062.                         CKeyBind* key = nullptr;
  1063.                         CSlider* sld = nullptr;
  1064.  
  1065.                         // Figure out what kind of control and data this is
  1066.                         switch (Control->FileControlType)
  1067.                         {
  1068.                             case UIControlTypes::UIC_CheckBox:
  1069.                                 cbx = (CCheckBox*)Control;
  1070.                                 ControlElement->SetText(cbx->GetState());
  1071.                                 break;
  1072.                             case UIControlTypes::UIC_ComboBox:
  1073.                                 cbo = (CComboBox*)Control;
  1074.                                 ControlElement->SetText(cbo->GetIndex());
  1075.                                 break;
  1076.                             case UIControlTypes::UIC_KeyBind:
  1077.                                 key = (CKeyBind*)Control;
  1078.                                 ControlElement->SetText(key->GetKey());
  1079.                                 break;
  1080.                             case UIControlTypes::UIC_Slider:
  1081.                                 sld = (CSlider*)Control;
  1082.                                 ControlElement->SetText(sld->GetValue());
  1083.                                 break;
  1084.                         }
  1085.                     }
  1086.                 }
  1087.             }
  1088.         }
  1089.     }
  1090.  
  1091.     //Save the file
  1092.     if (Doc.SaveFile(Filename.c_str()) != tinyxml2::XML_NO_ERROR)
  1093.     {
  1094.         MessageBox(NULL, "Failed To Save Config File!", "AyyWare", MB_OK);
  1095.     }
  1096.  
  1097. }
  1098.  
  1099. void CGUI::LoadWindowState(CWindow* window, std::string Filename)
  1100. {
  1101.     // Lets load our meme
  1102.     tinyxml2::XMLDocument Doc;
  1103.     if (Doc.LoadFile(Filename.c_str()) == tinyxml2::XML_NO_ERROR)
  1104.     {
  1105.         tinyxml2::XMLElement* Root = Doc.RootElement();
  1106.  
  1107.         // The root "ayy" element
  1108.         if (Root)
  1109.         {
  1110.             // If the window has some tabs..
  1111.             if (Root && window->Tabs.size() > 0)
  1112.             {
  1113.                 for (auto Tab : window->Tabs)
  1114.                 {
  1115.                     // We find the corresponding element for this tab
  1116.                     tinyxml2::XMLElement* TabElement = Root->FirstChildElement(Tab->Title.c_str());
  1117.                     if (TabElement)
  1118.                     {
  1119.                         // Now we itterate the controls this tab contains
  1120.                         if (TabElement && Tab->Controls.size() > 0)
  1121.                         {
  1122.                             for (auto Control : Tab->Controls)
  1123.                             {
  1124.                                 // If the control is ok to be saved
  1125.                                 if (Control && Control->Flag(UIFlags::UI_SaveFile) && Control->FileIdentifier.length() > 1 && Control->FileControlType)
  1126.                                 {
  1127.                                     // Get the controls element
  1128.                                     tinyxml2::XMLElement* ControlElement = TabElement->FirstChildElement(Control->FileIdentifier.c_str());
  1129.  
  1130.                                     if (ControlElement)
  1131.                                     {
  1132.                                         Utilities::Log("We tryin to load fam");
  1133.                                         CCheckBox* cbx = nullptr;
  1134.                                         CComboBox* cbo = nullptr;
  1135.                                         CKeyBind* key = nullptr;
  1136.                                         CSlider* sld = nullptr;
  1137.  
  1138.                                         // Figure out what kind of control and data this is
  1139.                                         switch (Control->FileControlType)
  1140.                                         {
  1141.                                             case UIControlTypes::UIC_CheckBox:
  1142.                                                 cbx = (CCheckBox*)Control;
  1143.                                                 cbx->SetState(ControlElement->GetText()[0] == '1' ? true : false);
  1144.                                                 break;
  1145.                                             case UIControlTypes::UIC_ComboBox:
  1146.                                                 cbo = (CComboBox*)Control;
  1147.                                                 cbo->SelectIndex(atoi(ControlElement->GetText()));
  1148.                                                 break;
  1149.                                             case UIControlTypes::UIC_KeyBind:
  1150.                                                 key = (CKeyBind*)Control;
  1151.                                                 key->SetKey(atoi(ControlElement->GetText()));
  1152.                                                 break;
  1153.                                             case UIControlTypes::UIC_Slider:
  1154.                                                 sld = (CSlider*)Control;
  1155.                                                 sld->SetValue(atof(ControlElement->GetText()));
  1156.                                                 break;
  1157.                                         }
  1158.                                     }
  1159.                                 }
  1160.                             }
  1161.                         }
  1162.                     }
  1163.                 }
  1164.             }
  1165.         }
  1166.     }
  1167. }/*
  1168. Syn's AYYWAREFramework 2015
  1169. */
  1170.  
  1171. // Credits to Valve and Shad0w
  1172. #include "Interfaces.h"
  1173. #include "Menu.h"
  1174.  
  1175. // Shad0ws Yaw fix
  1176. // (FIX ME UP LATER)
  1177. void FixY(const CRecvProxyData* pData, void* pStruct, void* pOut)
  1178. {
  1179.     static Vector vLast[65];
  1180.     static bool bShotLastTime[65];
  1181.     static bool bJitterFix[65];
  1182.  
  1183.     float* flPitch = (float*)((DWORD)pOut - 4);
  1184.     float flYaw = pData->m_Value.m_Float;
  1185.     bool bHasAA;
  1186.     bool bSpinbot;
  1187.  
  1188.     if (Menu::Window.RageBotTab.AccuracyAngleFix.GetState())
  1189.     {
  1190.         bHasAA = ((*flPitch == 90.0f) || (*flPitch == 270.0f));
  1191.         bSpinbot = false;
  1192.  
  1193.         if (!bShotLastTime[((IClientEntity*)(pStruct))->GetIndex()]
  1194.             && (fabsf(flYaw - vLast[((IClientEntity*)(pStruct))->GetIndex()].y) > 15.0f) && !bHasAA)
  1195.         {
  1196.             flYaw = vLast[((IClientEntity*)(pStruct))->GetIndex()].y;
  1197.             bShotLastTime[((IClientEntity*)(pStruct))->GetIndex()] = true;
  1198.         }
  1199.         else
  1200.         {
  1201.             if (bShotLastTime[((IClientEntity*)(pStruct))->GetIndex()]
  1202.                 && (fabsf(flYaw - vLast[((IClientEntity*)(pStruct))->GetIndex()].y) > 15.0f))
  1203.             {
  1204.                 bShotLastTime[((IClientEntity*)(pStruct))->GetIndex()] = true;
  1205.                 bSpinbot = true;
  1206.             }
  1207.             else
  1208.             {
  1209.                 bShotLastTime[((IClientEntity*)(pStruct))->GetIndex()] = false;
  1210.             }
  1211.         }
  1212.  
  1213.         vLast[((IClientEntity*)(pStruct))->GetIndex()].y = flYaw;
  1214.  
  1215.  
  1216.         bool bTmp = bJitterFix[((IClientEntity*)(pStruct))->GetIndex()];
  1217.  
  1218.         bJitterFix[((IClientEntity*)(pStruct))->GetIndex()] = (flYaw >= 180.0f && flYaw <= 360.0f);
  1219.  
  1220.         if (bTmp && (flYaw >= 0.0f && flYaw <= 180.0f))
  1221.         {
  1222.             flYaw += 359.0f;
  1223.         }
  1224.  
  1225.     }
  1226.  
  1227.     *(float*)(pOut) = flYaw;
  1228. }
  1229.  
  1230. // Simple fix for some Fake-Downs
  1231. void FixX(const CRecvProxyData* pData, void* pStruct, void* pOut)
  1232. {
  1233.     float* ang = (float*)pOut;
  1234.     *ang = pData->m_Value.m_Float;
  1235.  
  1236.     if (!Menu::Window.RageBotTab.AccuracyAngleFix.GetState()) return;
  1237.  
  1238.     if (pData->m_Value.m_Float > 180.0f)
  1239.         *ang -= 360.0f;
  1240.     else if (pData->m_Value.m_Float < -180.0f)
  1241.         *ang += 360.0f;
  1242. }
  1243.  
  1244.  
  1245. RecvVarProxyFn oRecvnModelIndex;
  1246.  
  1247. void Hooked_RecvProxy_Viewmodel(CRecvProxyData* pData, void* pStruct, void* pOut)
  1248. {
  1249.     // Get the knife view model id's
  1250.     static int default_t = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_default_t.mdl");
  1251.     static int default_ct = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_default_ct.mdl");
  1252.     int iBayonet = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_bayonet.mdl");
  1253.     int iButterfly = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_butterfly.mdl");
  1254.     int iFlip = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_flip.mdl");
  1255.     int iGunGame = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_gg.mdl");
  1256.     int iGut = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_gut.mdl");
  1257.     int iKarambit = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_karam.mdl");
  1258.     int iM9Bayonet = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_m9_bay.mdl");
  1259.     int iHuntsman = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_tactical.mdl");
  1260.  
  1261.     int iFalchion = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_falchion_advanced.mdl");
  1262.     int iDagger = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_push.mdl");
  1263.  
  1264.     // Get local player (just to stop replacing spectators knifes)
  1265.     IClientEntity* pLocal = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  1266.     if (Menu::Window.MiscTab.KnifeEnable.GetState() && pLocal)
  1267.     {
  1268.         // If we are alive and holding a default knife(if we already have a knife don't worry about changing)
  1269.         if (pLocal->IsAlive() && (pData->m_Value.m_Int == default_t || pData->m_Value.m_Int == default_ct))
  1270.         {
  1271.             // Set whatever knife we want
  1272.             if (Menu::Window.MiscTab.KnifeModel.GetIndex() == 0)
  1273.                 pData->m_Value.m_Int = iKarambit;
  1274.             else if (Menu::Window.MiscTab.KnifeModel.GetIndex() == 1)
  1275.                 pData->m_Value.m_Int = iBayonet;
  1276.             else if (Menu::Window.MiscTab.KnifeModel.GetIndex() == 2)
  1277.                 pData->m_Value.m_Int = iHuntsman;
  1278.             else if (Menu::Window.MiscTab.KnifeModel.GetIndex() == 3)
  1279.                 pData->m_Value.m_Int = iGut;
  1280.             else if (Menu::Window.MiscTab.KnifeModel.GetIndex() == 4)
  1281.                 pData->m_Value.m_Int = iFalchion;
  1282.             else if (Menu::Window.MiscTab.KnifeModel.GetIndex() == 5)
  1283.                 pData->m_Value.m_Int = iDagger;
  1284.             else if (Menu::Window.MiscTab.KnifeModel.GetIndex() == 6)
  1285.                 pData->m_Value.m_Int = iButterfly;
  1286.             else if (Menu::Window.MiscTab.KnifeModel.GetIndex() == 7)
  1287.                 pData->m_Value.m_Int = iFlip;
  1288.         }
  1289.     }
  1290.  
  1291.     // Carry on the to original proxy
  1292.     oRecvnModelIndex(pData, pStruct, pOut);
  1293. }
  1294.  
  1295. void ApplyAAAHooks()
  1296. {
  1297.     ClientClass* pClass = Interfaces::Client->GetAllClasses();
  1298.     while (pClass)
  1299.     {
  1300.         const char* pszName = pClass->m_pRecvTable->m_pNetTableName;
  1301.         if (!strcmp(pszName, "DT_CSPlayer"))
  1302.         {
  1303.             for (int i = 0; i < pClass->m_pRecvTable->m_nProps; i++)
  1304.             {
  1305.                 RecvProp* pProp = &(pClass->m_pRecvTable->m_pProps[i]);
  1306.                 const char* name = pProp->m_pVarName;
  1307.  
  1308.                 // Pitch Fix
  1309.                 if (!strcmp(name, "m_angEyeAngles[0]"))
  1310.                 {
  1311.                     pProp->m_ProxyFn = FixX;
  1312.                 }
  1313.  
  1314.                 // Yaw Fix
  1315.                 if (!strcmp(name, "m_angEyeAngles[1]"))
  1316.                 {
  1317.                     //Utilities::Log("Yaw Fix Applied");
  1318.                     pProp->m_ProxyFn = FixY;
  1319.                 }
  1320.             }
  1321.         }
  1322.         else if (!strcmp(pszName, "DT_BaseViewModel"))
  1323.         {
  1324.             for (int i = 0; i < pClass->m_pRecvTable->m_nProps; i++)
  1325.             {
  1326.                 RecvProp* pProp = &(pClass->m_pRecvTable->m_pProps[i]);
  1327.                 const char* name = pProp->m_pVarName;
  1328.  
  1329.                 // Knives
  1330.                 if (!strcmp(name, "m_nModelIndex"))
  1331.                 {
  1332.                     oRecvnModelIndex = (RecvVarProxyFn)pProp->m_ProxyFn;
  1333.                     pProp->m_ProxyFn = Hooked_RecvProxy_Viewmodel;
  1334.                 }
  1335.             }
  1336.         }
  1337.         pClass = pClass->m_pNext;
  1338.     }
  1339. }/*
  1340. Syn's AYYWAREFramework 2015
  1341. */
  1342.  
  1343. // Credits to Valve and Shad0w
  1344. #pragma once
  1345.  
  1346. void ApplyAAAHooks();
  1347. #include "AutoWall.h"
  1348.  
  1349. #define    HITGROUP_GENERIC    0
  1350. #define    HITGROUP_HEAD        1
  1351. #define    HITGROUP_CHEST        2
  1352. #define    HITGROUP_STOMACH    3
  1353. #define HITGROUP_LEFTARM    4    
  1354. #define HITGROUP_RIGHTARM    5
  1355. #define HITGROUP_LEFTLEG    6
  1356. #define HITGROUP_RIGHTLEG    7
  1357. #define HITGROUP_GEAR        10
  1358.  
  1359. inline bool CGameTrace::DidHitWorld() const
  1360. {
  1361.         return m_pEnt->GetIndex() == 0;
  1362. }
  1363.  
  1364. inline bool CGameTrace::DidHitNonWorldEntity() const
  1365. {
  1366.         return m_pEnt != NULL && !DidHitWorld();
  1367. }
  1368.  
  1369. bool HandleBulletPenetration(CSWeaponInfo* wpn_data, FireBulletData &data);
  1370.  
  1371. float GetHitgroupDamageMult(int iHitGroup)
  1372. {
  1373.     switch (iHitGroup)
  1374.     {
  1375.         case HITGROUP_GENERIC:
  1376.             return 1.0f;
  1377.  
  1378.         case HITGROUP_HEAD:
  1379.             return 2.0f;
  1380.  
  1381.         case HITGROUP_CHEST:
  1382.             return 1.0f;
  1383.  
  1384.         case HITGROUP_STOMACH:
  1385.             return 1.0f;
  1386.  
  1387.         case HITGROUP_LEFTARM:
  1388.         case HITGROUP_RIGHTARM:
  1389.             return 1.0f;
  1390.  
  1391.         case HITGROUP_LEFTLEG:
  1392.         case HITGROUP_RIGHTLEG:
  1393.             return 1.0f;
  1394.  
  1395.         default:
  1396.             return 1.0f;
  1397.     }
  1398. }
  1399.  
  1400. void ScaleDamage(int hitgroup, IClientEntity* enemy, float weapon_armor_ratio, float &current_damage)
  1401. {
  1402.     current_damage *= GetHitgroupDamageMult(hitgroup);
  1403.  
  1404.     if (enemy->ArmorValue() > 0)
  1405.     {
  1406.         if (hitgroup == HITGROUP_HEAD)
  1407.         {
  1408.             if (enemy->HasHelmet())
  1409.                 current_damage *= (weapon_armor_ratio * .5f);
  1410.         }
  1411.         else
  1412.         {
  1413.             current_damage *= (weapon_armor_ratio * .5f);
  1414.         }
  1415.     }
  1416. }
  1417.  
  1418. bool SimulateFireBullet(IClientEntity* local, CBaseCombatWeapon* weapon, FireBulletData &data)
  1419. {
  1420.     //Utils::ToLog("SimulateFireBullet");
  1421.     data.penetrate_count = 4;
  1422.     data.trace_length = 0.0f;
  1423.     auto* wpn_data = weapon->GetCSWpnData();
  1424.  
  1425.     data.current_damage = (float)wpn_data->m_iDamage;
  1426.  
  1427.     while ((data.penetrate_count > 0) && (data.current_damage >= 1.0f))
  1428.     {
  1429.         data.trace_length_remaining = wpn_data->m_flRange - data.trace_length;
  1430.  
  1431.         Vector end = data.src + data.direction * data.trace_length_remaining;
  1432.  
  1433.         UTIL_TraceLine(data.src, end, 0x4600400B, local, 0, &data.enter_trace);
  1434.         UTIL_ClipTraceToPlayers(data.src, end + data.direction * 40.f, 0x4600400B, &data.filter, &data.enter_trace);
  1435.  
  1436.         if (data.enter_trace.fraction == 1.0f)
  1437.             break;
  1438.  
  1439.         if ((data.enter_trace.hitgroup <= 7)
  1440.             && (data.enter_trace.hitgroup > 0)
  1441.             && (local->GetTeamNum() != data.enter_trace.m_pEnt->GetTeamNum())
  1442.             /*&& (DoesRayTouchHitbox(end, &data))*/)
  1443.         {
  1444.             data.trace_length += data.enter_trace.fraction * data.trace_length_remaining;
  1445.             data.current_damage *= pow(wpn_data->m_flRangeModifier, data.trace_length * 0.002);
  1446.             ScaleDamage(data.enter_trace.hitgroup, data.enter_trace.m_pEnt, wpn_data->m_flArmorRatio, data.current_damage);
  1447.  
  1448.             return true;
  1449.         }
  1450.  
  1451.         if (!HandleBulletPenetration(wpn_data, data))
  1452.             break;
  1453.     }
  1454.  
  1455.     return false;
  1456. }
  1457.  
  1458. bool HandleBulletPenetration(CSWeaponInfo* wpn_data, FireBulletData &data)
  1459. {
  1460.     surfacedata_t* enter_surface_data = Interfaces::PhysProps->GetSurfaceData(data.enter_trace.surface.surfaceProps);
  1461.     int enter_material = enter_surface_data->game.material;
  1462.     float enter_surf_penetration_mod = enter_surface_data->game.flPenetrationModifier;
  1463.  
  1464.  
  1465.     data.trace_length += data.enter_trace.fraction * data.trace_length_remaining;
  1466.     data.current_damage *= pow(wpn_data->m_flRangeModifier, (data.trace_length * 0.002));
  1467.  
  1468.     if ((data.trace_length > 3000.f) || (enter_surf_penetration_mod < 0.1f))
  1469.         data.penetrate_count = 0;
  1470.  
  1471.     if (data.penetrate_count <= 0)
  1472.         return false;
  1473.  
  1474.     Vector dummy;
  1475.     trace_t trace_exit;
  1476.     if (!TraceToExit(dummy, data.enter_trace, data.enter_trace.endpos, data.direction, &trace_exit))
  1477.         return false;
  1478.  
  1479.     surfacedata_t* exit_surface_data = Interfaces::PhysProps->GetSurfaceData(trace_exit.surface.surfaceProps);
  1480.     int exit_material = exit_surface_data->game.material;
  1481.  
  1482.     float exit_surf_penetration_mod = exit_surface_data->game.flPenetrationModifier;
  1483.     float final_damage_modifier = 0.16f;
  1484.     float combined_penetration_modifier = 0.0f;
  1485.  
  1486.     if (((data.enter_trace.contents & CONTENTS_GRATE) != 0) || (enter_material == 89) || (enter_material == 71))
  1487.     {
  1488.         combined_penetration_modifier = 3.0f;
  1489.         final_damage_modifier = 0.05f;
  1490.     }
  1491.     else
  1492.     {
  1493.         combined_penetration_modifier = (enter_surf_penetration_mod + exit_surf_penetration_mod) * 0.5f;
  1494.     }
  1495.  
  1496.     if (enter_material == exit_material)
  1497.     {
  1498.         if (exit_material == 87 || exit_material == 85)
  1499.             combined_penetration_modifier = 3.0f;
  1500.         else if (exit_material == 76)
  1501.             combined_penetration_modifier = 2.0f;
  1502.     }
  1503.  
  1504.     float v34 = fmaxf(0.f, 1.0f / combined_penetration_modifier);
  1505.     float v35 = (data.current_damage * final_damage_modifier) + v34 * 3.0f * fmaxf(0.0f, (3.0f / wpn_data->m_flPenetration) * 1.25f);
  1506.     float thickness = VectorLength(trace_exit.endpos - data.enter_trace.endpos);
  1507.  
  1508.     thickness *= thickness;
  1509.     thickness *= v34;
  1510.     thickness /= 24.0f;
  1511.  
  1512.  
  1513.     float lost_damage = fmaxf(0.0f, v35 + thickness);
  1514.  
  1515.     if (lost_damage > data.current_damage)
  1516.         return false;
  1517.  
  1518.     if (lost_damage >= 0.0f)
  1519.         data.current_damage -= lost_damage;
  1520.  
  1521.     if (data.current_damage < 1.0f)
  1522.         return false;
  1523.  
  1524.     data.src = trace_exit.endpos;
  1525.     data.penetrate_count--;
  1526.  
  1527.     return true;
  1528. }
  1529.  
  1530.  
  1531. /*
  1532. *    CanHit() - example of how to use the code
  1533. *     @in  point: target hitbox vector
  1534. *     @out damage_given: amount of damage the shot would do
  1535. */
  1536. bool CanHit(const Vector &point, float* damage_given)
  1537. {
  1538.     auto* local = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  1539.     auto data = FireBulletData(local->GetOrigin() + local->GetViewOffset());
  1540.     data.filter = CTraceFilter();
  1541.     data.filter.pSkip = local;
  1542.  
  1543.     Vector angles;
  1544.     CalcAngle(data.src, point, angles);
  1545.     AngleVectors(angles, &data.direction);
  1546.     VectorNormalize(data.direction);
  1547.  
  1548.     if (SimulateFireBullet(local, (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle((HANDLE)local->GetActiveWeaponHandle()), data))
  1549.     {
  1550.         *damage_given = data.current_damage;
  1551.         return true;
  1552.     }
  1553.  
  1554.     return false;
  1555. }
  1556. #pragma once
  1557.  
  1558. # include "Hacks.h"
  1559.  
  1560. struct FireBulletData
  1561. {
  1562.     FireBulletData(const Vector &eye_pos):src(eye_pos)
  1563.     {
  1564.     }
  1565.  
  1566.     Vector src;
  1567.     trace_t enter_trace;
  1568.     Vector direction;
  1569.     CTraceFilter filter;
  1570.     float trace_length;
  1571.     float trace_length_remaining;
  1572.     float current_damage;
  1573.     int penetrate_count;
  1574. };/*
  1575. Syn's AYYWAREFramework 2015
  1576. */
  1577.  
  1578. #pragma once
  1579.  
  1580. #include "MiscDefinitions.h"
  1581. #include "ClientRecvProps.h"
  1582. #include "offsets.h"
  1583.  
  1584. class IBaseClientDLL
  1585. {
  1586.     public:
  1587.  
  1588.         ClientClass* GetAllClasses(void)
  1589.     {
  1590.         typedef ClientClass*(__thiscall * OriginalFn)(PVOID); //Anything inside a VTable is a __thiscall unless it completly disregards the thisptr. You can also call them as __stdcalls, but you won't have access to the __thisptr.
  1591.         return call_vfunc<OriginalFn>(this, Offsets::VMT::CHL_GetAllClasses)(this); //Return the pointer to the head CClientClass.
  1592.     }
  1593. };//========= Copyright Valve Corporation, All rights reserved. ============//
  1594. //
  1595. // Purpose:
  1596. //
  1597. // $Workfile:     $
  1598. // $Date:         $
  1599. // $NoKeywords: $
  1600. //=============================================================================//
  1601.  
  1602. #ifndef BSPFLAGS_H
  1603. #define BSPFLAGS_H
  1604.  
  1605. #ifdef _WIN32
  1606. #pragma once
  1607. #endif
  1608.  
  1609. // contents flags are seperate bits
  1610. // a given brush can contribute multiple content bits
  1611. // multiple brushes can be in a single leaf
  1612.  
  1613. // these definitions also need to be in q_shared.h!
  1614.  
  1615. // lower bits are stronger, and will eat weaker brushes completely
  1616. #define CONTENTS_EMPTY                  0               // No contents
  1617.  
  1618. #define CONTENTS_SOLID                  0x1             // an eye is never valid in a solid
  1619. #define CONTENTS_WINDOW                 0x2             // translucent, but not watery (glass)
  1620. #define CONTENTS_AUX                    0x4
  1621. #define CONTENTS_GRATE                  0x8             // alpha-tested "grate" textures.  Bullets/sight pass through, but solids don't
  1622. #define CONTENTS_SLIME                  0x10
  1623. #define CONTENTS_WATER                  0x20
  1624. #define CONTENTS_BLOCKLOS               0x40    // block AI line of sight
  1625. #define CONTENTS_OPAQUE                 0x80    // things that cannot be seen through (may be non-solid though)
  1626. #define LAST_VISIBLE_CONTENTS   0x80
  1627.  
  1628. #define ALL_VISIBLE_CONTENTS (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))
  1629.  
  1630. #define CONTENTS_TESTFOGVOLUME  0x100
  1631. #define CONTENTS_UNUSED                 0x200  
  1632.  
  1633. // unused
  1634. // NOTE: If it's visible, grab from the top + update LAST_VISIBLE_CONTENTS
  1635. // if not visible, then grab from the bottom.
  1636. #define CONTENTS_UNUSED6                0x400
  1637.  
  1638. #define CONTENTS_TEAM1                  0x800   // per team contents used to differentiate collisions
  1639. #define CONTENTS_TEAM2                  0x1000  // between players and objects on different teams
  1640.  
  1641. // ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW
  1642. #define CONTENTS_IGNORE_NODRAW_OPAQUE   0x2000
  1643.  
  1644. // hits entities which are MOVETYPE_PUSH (doors, plats, etc.)
  1645. #define CONTENTS_MOVEABLE               0x4000
  1646.  
  1647. // remaining contents are non-visible, and don't eat brushes
  1648. #define CONTENTS_AREAPORTAL             0x8000
  1649.  
  1650. #define CONTENTS_PLAYERCLIP             0x10000
  1651. #define CONTENTS_MONSTERCLIP    0x20000
  1652.  
  1653. // currents can be added to any other contents, and may be mixed
  1654. #define CONTENTS_CURRENT_0              0x40000
  1655. #define CONTENTS_CURRENT_90             0x80000
  1656. #define CONTENTS_CURRENT_180    0x100000
  1657. #define CONTENTS_CURRENT_270    0x200000
  1658. #define CONTENTS_CURRENT_UP             0x400000
  1659. #define CONTENTS_CURRENT_DOWN   0x800000
  1660.  
  1661. #define CONTENTS_ORIGIN                 0x1000000       // removed before bsping an entity
  1662.  
  1663. #define CONTENTS_MONSTER                0x2000000       // should never be on a brush, only in game
  1664. #define CONTENTS_DEBRIS                 0x4000000
  1665. #define CONTENTS_DETAIL                 0x8000000       // brushes to be added after vis leafs
  1666. #define CONTENTS_TRANSLUCENT    0x10000000      // auto set if any surface has trans
  1667. #define CONTENTS_LADDER                 0x20000000
  1668. #define CONTENTS_HITBOX                 0x40000000      // use accurate hitboxes on trace
  1669.  
  1670.  
  1671. // NOTE: These are stored in a short in the engine now.  Don't use more than 16 bits
  1672. #define SURF_LIGHT              0x0001          // value will hold the light strength
  1673. #define SURF_SKY2D              0x0002          // don't draw, indicates we should skylight + draw 2d sky but not draw the 3D skybox
  1674. #define SURF_SKY                0x0004          // don't draw, but add to skybox
  1675. #define SURF_WARP               0x0008          // turbulent water warp
  1676. #define SURF_TRANS              0x0010
  1677. #define SURF_NOPORTAL   0x0020  // the surface can not have a portal placed on it
  1678. #define SURF_TRIGGER    0x0040  // FIXME: This is an xbox hack to work around elimination of trigger surfaces, which breaks occluders
  1679. #define SURF_NODRAW             0x0080  // don't bother referencing the texture
  1680.  
  1681. #define SURF_HINT               0x0100  // make a primary bsp splitter
  1682.  
  1683. #define SURF_SKIP               0x0200  // completely ignore, allowing non-closed brushes
  1684. #define SURF_NOLIGHT    0x0400  // Don't calculate light
  1685. #define SURF_BUMPLIGHT  0x0800  // calculate three lightmaps for the surface for bumpmapping
  1686. #define SURF_NOSHADOWS  0x1000  // Don't receive shadows
  1687. #define SURF_NODECALS   0x2000  // Don't receive decals
  1688. #define SURF_NOCHOP             0x4000  // Don't subdivide patches on this surface
  1689. #define SURF_HITBOX             0x8000  // surface is part of a hitbox
  1690.  
  1691.  
  1692.  
  1693. // -----------------------------------------------------
  1694. // spatial content masks - used for spatial queries (traceline,etc.)
  1695. // -----------------------------------------------------
  1696. #define MASK_ALL                                        (0xFFFFFFFF)
  1697. // everything that is normally solid
  1698. #define MASK_SOLID                                      (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)
  1699. // everything that blocks player movement
  1700. #define MASK_PLAYERSOLID                        (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)
  1701. // blocks npc movement
  1702. #define MASK_NPCSOLID                           (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE)
  1703. // water physics in these contents
  1704. #define MASK_WATER                                      (CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME)
  1705. // everything that blocks lighting
  1706. #define MASK_OPAQUE                                     (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE)
  1707. // everything that blocks lighting, but with monsters added.
  1708. #define MASK_OPAQUE_AND_NPCS            (MASK_OPAQUE|CONTENTS_MONSTER)
  1709. // everything that blocks line of sight for AI
  1710. #define MASK_BLOCKLOS                           (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_BLOCKLOS)
  1711. // everything that blocks line of sight for AI plus NPCs
  1712. #define MASK_BLOCKLOS_AND_NPCS          (MASK_BLOCKLOS|CONTENTS_MONSTER)
  1713. // everything that blocks line of sight for players
  1714. #define MASK_VISIBLE                                    (MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE)
  1715. // everything that blocks line of sight for players, but with monsters added.
  1716. #define MASK_VISIBLE_AND_NPCS           (MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE)
  1717. // bullets see these as solid
  1718. #define MASK_SHOT                                       (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX)
  1719. // non-raycasted weapons see this as solid (includes grates)
  1720. #define MASK_SHOT_HULL                          (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_GRATE)
  1721. // hits solids (not grates) and passes through everything else
  1722. #define MASK_SHOT_PORTAL                        (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER)
  1723. // everything normally solid, except monsters (world+brush only)
  1724. #define MASK_SOLID_BRUSHONLY            (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE)
  1725. // everything normally solid for player movement, except monsters (world+brush only)
  1726. #define MASK_PLAYERSOLID_BRUSHONLY      (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_PLAYERCLIP|CONTENTS_GRATE)
  1727. // everything normally solid for npc movement, except monsters (world+brush only)
  1728. #define MASK_NPCSOLID_BRUSHONLY         (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE)
  1729. // just the world, used for route rebuilding
  1730. #define MASK_NPCWORLDSTATIC                     (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE)
  1731. // These are things that can split areaportals
  1732. #define MASK_SPLITAREAPORTAL            (CONTENTS_WATER|CONTENTS_SLIME)
  1733.  
  1734. // UNDONE: This is untested, any moving water
  1735. #define MASK_CURRENT                            (CONTENTS_CURRENT_0|CONTENTS_CURRENT_90|CONTENTS_CURRENT_180|CONTENTS_CURRENT_270|CONTENTS_CURRENT_UP|CONTENTS_CURRENT_DOWN)
  1736.  
  1737. // everything that blocks corpse movement
  1738. // UNDONE: Not used yet / may be deleted
  1739. #define MASK_DEADSOLID                          (CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_GRATE)
  1740.  
  1741. #endif // BSPFLAGS_H
  1742.  
  1743. bool CanHit(const Vector &point, float* damage_given);
  1744.  
  1745. #include "Chams.h"
  1746. #include "offsets.h"
  1747. #include "SDK.h"
  1748. #include "Interfaces.h"
  1749.  
  1750. void InitKeyValues(KeyValues* keyValues, char* name)
  1751. {
  1752.     DWORD dwFunction = (DWORD)Offsets::Functions::KeyValues_KeyValues;
  1753.     __asm
  1754.  
  1755.     {
  1756.         push name
  1757.  
  1758.             mov ecx, keyValues
  1759.  
  1760.             call dwFunction
  1761.  
  1762.     }
  1763. }
  1764.  
  1765. void LoadFromBuffer(KeyValues* keyValues, char const *resourceName, const char* pBuffer)
  1766. {
  1767.     DWORD dwFunction = (DWORD)Offsets::Functions::KeyValues_LoadFromBuffer;
  1768.  
  1769.     __asm
  1770.  
  1771.     {
  1772.         push 0
  1773.  
  1774.             push 0
  1775.  
  1776.             push 0
  1777.  
  1778.             push pBuffer
  1779.  
  1780.             push resourceName
  1781.  
  1782.             mov ecx, keyValues
  1783.  
  1784.             call dwFunction
  1785.  
  1786.     }
  1787. }
  1788.  
  1789. IMaterial* CreateMaterial(bool shouldIgnoreZ, bool isLit, bool isWireframe) //credits to ph0ne
  1790. {
  1791.     static int created = 0;
  1792.  
  1793.     static const char tmp[] =
  1794.     {
  1795.         "\"%s\"\
  1796.                 \n{\
  1797.                 \n\t\"$basetexture\" \"vgui/white_additive\"\
  1798.                 \n\t\"$envmap\" \"\"\
  1799.                 \n\t\"$model\" \"1\"\
  1800.                 \n\t\"$flat\" \"1\"\
  1801.                 \n\t\"$nocull\" \"0\"\
  1802.                 \n\t\"$selfillum\" \"1\"\
  1803.                 \n\t\"$halflambert\" \"1\"\
  1804.                 \n\t\"$nofog\" \"0\"\
  1805.                 \n\t\"$ignorez\" \"%i\"\
  1806.                 \n\t\"$znearer\" \"0\"\
  1807.                 \n\t\"$wireframe\" \"%i\"\
  1808.         \n}\n"
  1809.     };
  1810.  
  1811.     char* baseType = (isLit == true ? "VertexLitGeneric" : "UnlitGeneric");
  1812.     char material[512];
  1813.     sprintf_s(material, sizeof(material), tmp, baseType, (shouldIgnoreZ) ? 1 : 0, (isWireframe) ? 1 : 0);
  1814.  
  1815.     char name[512];
  1816.     sprintf_s(name, sizeof(name), "#ayy_meme_%i.vmt", created);
  1817.     ++created;
  1818.  
  1819.     KeyValues* keyValues = (KeyValues*)malloc(sizeof(KeyValues));
  1820.     InitKeyValues(keyValues, baseType);
  1821.     LoadFromBuffer(keyValues, name, material);
  1822.  
  1823.     IMaterial* createdMaterial = Interfaces::MaterialSystem->CreateMaterial(name, keyValues);
  1824.     createdMaterial->IncrementReferenceCount();
  1825.  
  1826.     return createdMaterial;
  1827. }
  1828.  
  1829. void ForceMaterial(Color color, IMaterial* material, bool useColor, bool forceMaterial)
  1830. {
  1831.     if (useColor)
  1832.     {
  1833.         float temp[3] =
  1834.         {
  1835.             color.r(),
  1836.             color.g(),
  1837.             color.b()
  1838.         };
  1839.  
  1840.         temp[0] /= 255.f;
  1841.         temp[1] /= 255.f;
  1842.         temp[2] /= 255.f;
  1843.  
  1844.  
  1845.         float alpha = color.a();
  1846.  
  1847.         Interfaces::RenderView->SetBlend(1.0f);
  1848.         Interfaces::RenderView->SetColorModulation(temp);
  1849.     }
  1850.  
  1851.     if (forceMaterial)
  1852.         Interfaces::ModelRender->ForcedMaterialOverride(material);
  1853.     else
  1854.         Interfaces::ModelRender->ForcedMaterialOverride(NULL);
  1855.  
  1856. }/*
  1857. Syn's AYYWAREFramework 2015
  1858. */
  1859.  
  1860. #pragma once
  1861. #include "SDK.h"
  1862.  
  1863. void InitKeyValues(KeyValues* keyValues, char* name);
  1864.  
  1865. void LoadFromBuffer(KeyValues* keyValues, char const *resourceName, const char* pBuffer);
  1866.  
  1867. void ForceMaterial(Color color, IMaterial* material, bool useColor = true, bool forceMaterial = true);
  1868.  
  1869. IMaterial* CreateMaterial(bool shouldIgnoreZ, bool isLit = true, bool isWireframe = false);
  1870. /*
  1871. Syn's AYYWAREFramework 2015
  1872. */
  1873.  
  1874. // Credits to Valve and Shad0w
  1875.  
  1876. #pragma once
  1877.  
  1878. struct RecvProp;
  1879.  
  1880. class DVariant
  1881. {
  1882.     public:
  1883.         union
  1884.         {
  1885.                 float m_Float;
  1886.     long m_Int;
  1887.     char* m_pString;
  1888.     void* m_pData;
  1889.     float m_Vector[3];
  1890. };
  1891. };
  1892.  
  1893. class CRecvProxyData
  1894. {
  1895.     public:
  1896.         const RecvProp* m_pRecvProp;
  1897.     char _pad[4];//csgo ( for l4d keep it commented out :) )
  1898.     DVariant m_Value;
  1899.     int m_iElement;
  1900.     int m_ObjectID;
  1901. };
  1902.  
  1903. typedef void(* RecvVarProxyFn)(const CRecvProxyData* pData, void* pStruct, void* pOut);
  1904.  
  1905. struct RecvTable
  1906. {
  1907.     RecvProp* m_pProps;
  1908.     int m_nProps;
  1909.     void* m_pDecoder;
  1910.     char* m_pNetTableName;
  1911.     bool m_bInitialized;
  1912.     bool m_bInMainList;
  1913. };
  1914.  
  1915. struct RecvProp
  1916. {
  1917.     char* m_pVarName;
  1918.     int m_RecvType;
  1919.     int m_Flags;
  1920.     int m_StringBufferSize;
  1921.     bool m_bInsideArray;
  1922.     const void* m_pExtraData;
  1923.     RecvProp* m_pArrayProp;
  1924.     void* m_ArrayLengthProxy;
  1925.     void* m_ProxyFn;
  1926.     void* m_DataTableProxyFn;
  1927.     RecvTable* m_pDataTable;
  1928.     int m_Offset;
  1929.     int m_ElementStride;
  1930.     int m_nElements;
  1931.     const char* m_pParentArrayPropName;
  1932. };
  1933.  
  1934. class ClientClass
  1935. {
  1936.     public:
  1937.         void* m_pCreateFn;
  1938.     void* m_pCreateEventFn;
  1939.     char* m_pNetworkName;
  1940.     RecvTable* m_pRecvTable;
  1941.     ClientClass* m_pNext;
  1942.     int m_ClassID;
  1943. };
  1944. #pragma once
  1945. #define _WINSOCKAPI_
  1946.  
  1947. // Includes
  1948. # include <Windows.h>
  1949. # include <cstdlib>
  1950. # include <cstdio>
  1951. # include <math.h>
  1952. # include <string>
  1953. # include <conio.h>
  1954. # include <vector>
  1955. #pragma once
  1956. #define _WINSOCKAPI_
  1957.  
  1958. // Includes
  1959. # include <Windows.h>
  1960. # include <cstdlib>
  1961. # include <cstdio>
  1962. # include <math.h>
  1963. # include <string>
  1964. # include <conio.h>
  1965. # include <vector>
  1966. /*
  1967. Syn's AYYWAREFramework 2015
  1968. */
  1969.  
  1970. #pragma once
  1971.  
  1972. # include "GUI.h"
  1973.  
  1974. class CCheckBox : public CControl
  1975. {
  1976. public:
  1977.  
  1978.     CCheckBox();
  1979. void SetState(bool s);
  1980. bool GetState();
  1981. protected:
  1982.         bool Checked;
  1983. void Draw(bool hover);
  1984. void OnUpdate();
  1985. void OnClick();
  1986. };
  1987.  
  1988. class CLabel : public CControl
  1989. {
  1990. public:
  1991.  
  1992.     CLabel();
  1993. void SetText(std::string text);
  1994. protected:
  1995.         std::string Text;
  1996. void Draw(bool hover);
  1997. void OnUpdate();
  1998. void OnClick();
  1999. };
  2000.  
  2001. class CGroupBox : public CControl
  2002. {
  2003. public:
  2004.  
  2005.     CGroupBox();
  2006. void SetText(std::string text);
  2007. void PlaceLabledControl(std::string Label, CTab* Tab, CControl* control);
  2008. protected:
  2009.         int Items;
  2010. std::string Text;
  2011. void Draw(bool hover);
  2012. void OnUpdate();
  2013. void OnClick();
  2014. };
  2015.  
  2016. class CSlider : public CControl
  2017. {
  2018. public:
  2019.  
  2020.     CSlider();
  2021. float GetValue();
  2022. void SetValue(float v);
  2023. void SetBoundaries(float min, float max);
  2024. protected:
  2025.         float Value;
  2026. float Min;
  2027. float Max;
  2028. bool DoDrag;
  2029. void Draw(bool hover);
  2030. void OnUpdate();
  2031. void OnClick();
  2032. };
  2033.  
  2034. class CKeyBind : public CControl
  2035. {
  2036. public:
  2037.  
  2038.     CKeyBind();
  2039. int GetKey();
  2040. void SetKey(int key);
  2041. protected:
  2042.         int Key;
  2043. bool IsGettingKey;
  2044. void Draw(bool hover);
  2045. void OnUpdate();
  2046. void OnClick();
  2047. };
  2048.  
  2049. class CButton : public CControl
  2050. {
  2051. public:
  2052.         typedef void(* ButtonCallback_t)(void);
  2053.  
  2054.     CButton();
  2055. void SetCallback(ButtonCallback_t callback);
  2056. void SetText(std::string text);
  2057. protected:
  2058.         ButtonCallback_t CallBack;
  2059. std::string Text;
  2060. void Draw(bool hover);
  2061. void OnUpdate();
  2062. void OnClick();
  2063. };
  2064.  
  2065. class CComboBox : public CControl
  2066. {
  2067. public:
  2068.  
  2069.     CComboBox();
  2070. void AddItem(std::string text);
  2071. void SelectIndex(int idx);
  2072. int GetIndex();
  2073. std::string GetItem();
  2074. protected:
  2075.         std::vector<std::string> Items;
  2076. int SelectedIndex;
  2077. bool IsOpen;
  2078. void Draw(bool hover);
  2079. void OnUpdate();
  2080. void OnClick();
  2081. };/*
  2082. Syn's AYYWAREFramework 2015
  2083. */
  2084.  
  2085. #include "CRC32.h"
  2086.  
  2087. unsigned int uiCRC32_Table[256] = {
  2088.     0x00000000L, 0x77073096L, 0xEE0E612CL,
  2089.     0x990951BAL, 0x076DC419L, 0x706AF48FL,
  2090.     0xE963A535L, 0x9E6495A3L, 0x0EDB8832L,
  2091.     0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L,
  2092.     0x09B64C2BL, 0x7EB17CBDL, 0xE7B82D07L,
  2093.     0x90BF1D91L, 0x1DB71064L, 0x6AB020F2L,
  2094.     0xF3B97148L, 0x84BE41DEL, 0x1ADAD47DL,
  2095.     0x6DDDE4EBL, 0xF4D4B551L, 0x83D385C7L,
  2096.     0x136C9856L, 0x646BA8C0L, 0xFD62F97AL,
  2097.     0x8A65C9ECL, 0x14015C4FL, 0x63066CD9L,
  2098.     0xFA0F3D63L, 0x8D080DF5L, 0x3B6E20C8L,
  2099.     0x4C69105EL, 0xD56041E4L, 0xA2677172L,
  2100.     0x3C03E4D1L, 0x4B04D447L, 0xD20D85FDL,
  2101.     0xA50AB56BL, 0x35B5A8FAL, 0x42B2986CL,
  2102.     0xDBBBC9D6L, 0xACBCF940L, 0x32D86CE3L,
  2103.     0x45DF5C75L, 0xDCD60DCFL, 0xABD13D59L,
  2104.     0x26D930ACL, 0x51DE003AL, 0xC8D75180L,
  2105.     0xBFD06116L, 0x21B4F4B5L, 0x56B3C423L,
  2106.     0xCFBA9599L, 0xB8BDA50FL, 0x2802B89EL,
  2107.     0x5F058808L, 0xC60CD9B2L, 0xB10BE924L,
  2108.     0x2F6F7C87L, 0x58684C11L, 0xC1611DABL,
  2109.     0xB6662D3DL, 0x76DC4190L, 0x01DB7106L,
  2110.     0x98D220BCL, 0xEFD5102AL, 0x71B18589L,
  2111.     0x06B6B51FL, 0x9FBFE4A5L, 0xE8B8D433L,
  2112.     0x7807C9A2L, 0x0F00F934L, 0x9609A88EL,
  2113.     0xE10E9818L, 0x7F6A0DBBL, 0x086D3D2DL,
  2114.     0x91646C97L, 0xE6635C01L, 0x6B6B51F4L,
  2115.     0x1C6C6162L, 0x856530D8L, 0xF262004EL,
  2116.     0x6C0695EDL, 0x1B01A57BL, 0x8208F4C1L,
  2117.     0xF50FC457L, 0x65B0D9C6L, 0x12B7E950L,
  2118.     0x8BBEB8EAL, 0xFCB9887CL, 0x62DD1DDFL,
  2119.     0x15DA2D49L, 0x8CD37CF3L, 0xFBD44C65L,
  2120.     0x4DB26158L, 0x3AB551CEL, 0xA3BC0074L,
  2121.     0xD4BB30E2L, 0x4ADFA541L, 0x3DD895D7L,
  2122.     0xA4D1C46DL, 0xD3D6F4FBL, 0x4369E96AL,
  2123.     0x346ED9FCL, 0xAD678846L, 0xDA60B8D0L,
  2124.     0x44042D73L, 0x33031DE5L, 0xAA0A4C5FL,
  2125.     0xDD0D7CC9L, 0x5005713CL, 0x270241AAL,
  2126.     0xBE0B1010L, 0xC90C2086L, 0x5768B525L,
  2127.     0x206F85B3L, 0xB966D409L, 0xCE61E49FL,
  2128.     0x5EDEF90EL, 0x29D9C998L, 0xB0D09822L,
  2129.     0xC7D7A8B4L, 0x59B33D17L, 0x2EB40D81L,
  2130.     0xB7BD5C3BL, 0xC0BA6CADL, 0xEDB88320L,
  2131.     0x9ABFB3B6L, 0x03B6E20CL, 0x74B1D29AL,
  2132.     0xEAD54739L, 0x9DD277AFL, 0x04DB2615L,
  2133.     0x73DC1683L, 0xE3630B12L, 0x94643B84L,
  2134.     0x0D6D6A3EL, 0x7A6A5AA8L, 0xE40ECF0BL,
  2135.     0x9309FF9DL, 0x0A00AE27L, 0x7D079EB1L,
  2136.     0xF00F9344L, 0x8708A3D2L, 0x1E01F268L,
  2137.     0x6906C2FEL, 0xF762575DL, 0x806567CBL,
  2138.     0x196C3671L, 0x6E6B06E7L, 0xFED41B76L,
  2139.     0x89D32BE0L, 0x10DA7A5AL, 0x67DD4ACCL,
  2140.     0xF9B9DF6FL, 0x8EBEEFF9L, 0x17B7BE43L,
  2141.     0x60B08ED5L, 0xD6D6A3E8L, 0xA1D1937EL,
  2142.     0x38D8C2C4L, 0x4FDFF252L, 0xD1BB67F1L,
  2143.     0xA6BC5767L, 0x3FB506DDL, 0x48B2364BL,
  2144.     0xD80D2BDAL, 0xAF0A1B4CL, 0x36034AF6L,
  2145.     0x41047A60L, 0xDF60EFC3L, 0xA867DF55L,
  2146.     0x316E8EEFL, 0x4669BE79L, 0xCB61B38CL,
  2147.     0xBC66831AL, 0x256FD2A0L, 0x5268E236L,
  2148.     0xCC0C7795L, 0xBB0B4703L, 0x220216B9L,
  2149.     0x5505262FL, 0xC5BA3BBEL, 0xB2BD0B28L,
  2150.     0x2BB45A92L, 0x5CB36A04L, 0xC2D7FFA7L,
  2151.     0xB5D0CF31L, 0x2CD99E8BL, 0x5BDEAE1DL,
  2152.     0x9B64C2B0L, 0xEC63F226L, 0x756AA39CL,
  2153.     0x026D930AL, 0x9C0906A9L, 0xEB0E363FL,
  2154.     0x72076785L, 0x05005713L, 0x95BF4A82L,
  2155.     0xE2B87A14L, 0x7BB12BAEL, 0x0CB61B38L,
  2156.     0x92D28E9BL, 0xE5D5BE0DL, 0x7CDCEFB7L,
  2157.     0x0BDBDF21L, 0x86D3D2D4L, 0xF1D4E242L,
  2158.     0x68DDB3F8L, 0x1FDA836EL, 0x81BE16CDL,
  2159.     0xF6B9265BL, 0x6FB077E1L, 0x18B74777L,
  2160.     0x88085AE6L, 0xFF0F6A70L, 0x66063BCAL,
  2161.     0x11010B5CL, 0x8F659EFFL, 0xF862AE69L,
  2162.     0x616BFFD3L, 0x166CCF45L, 0xA00AE278L,
  2163.     0xD70DD2EEL, 0x4E048354L, 0x3903B3C2L,
  2164.     0xA7672661L, 0xD06016F7L, 0x4969474DL,
  2165.     0x3E6E77DBL, 0xAED16A4AL, 0xD9D65ADCL,
  2166.     0x40DF0B66L, 0x37D83BF0L, 0xA9BCAE53L,
  2167.     0xDEBB9EC5L, 0x47B2CF7FL, 0x30B5FFE9L,
  2168.     0xBDBDF21CL, 0xCABAC28AL, 0x53B39330L,
  2169.     0x24B4A3A6L, 0xBAD03605L, 0xCDD70693L,
  2170.     0x54DE5729L, 0x23D967BFL, 0xB3667A2EL,
  2171.     0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L,
  2172.     0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL,
  2173.     0x2D02EF8DL };
  2174.  
  2175. unsigned int CRC32(void* pData, size_t iLen)
  2176. {
  2177.     unsigned int uiCRC32 = 0xFFFFFFFF;
  2178.     unsigned char* pszData = (unsigned char*)pData;
  2179.  
  2180.     for (size_t i = 0; i < iLen; ++i)
  2181.         uiCRC32 = ((uiCRC32 >> 8) & 0x00FFFFFF) ^ uiCRC32_Table[(uiCRC32 ^ (unsigned int)*pszData++) &0xFF];
  2182.  
  2183.     return (uiCRC32 ^ 0xFFFFFFFF);
  2184. }/*
  2185. Syn's AYYWAREFramework 2015
  2186. */
  2187.  
  2188. // Credits Valve / Shad0w
  2189.  
  2190. #pragma once
  2191.  
  2192. unsigned int CRC32(void* pData, size_t iLen);
  2193. /*
  2194. Syn's AYYWAREFramework 2015
  2195. */
  2196.  
  2197. #include "Utilities.h"
  2198.  
  2199. // Stuff to initialise
  2200. #include "Offsets.h"
  2201. #include "Interfaces.h"
  2202. #include "Hooks.h"
  2203. #include "RenderManager.h"
  2204. #include "Hacks.h"
  2205. #include "Menu.h"
  2206. #include "AntiAntiAim.h"
  2207.  
  2208. #include "Dumping.h"
  2209.  
  2210. bool DoUnload;
  2211.  
  2212. HINSTANCE HThisModule;
  2213.  
  2214. // Our thread we use to setup everything we need
  2215. // Everything appart from code in hooks get's called from inside
  2216. // here.
  2217.  
  2218. int InitialThread(LPVOID lpArguments)
  2219. {
  2220.     Utilities::OpenConsole("Cebula.dll");
  2221.  
  2222.     //---------------------------------------------------------
  2223.     // Initialise all our shit
  2224.  
  2225.     Offsets::Initialise(); // Set our VMT offsets and do any pattern scans
  2226.     Interfaces::Initialise(); // Get pointers to the valve classes
  2227.     NetVar.RetrieveClasses(); // Setup our NetVar manager (thanks shad0w bby)
  2228.     Render::Initialise();
  2229.     Hacks::SetupHacks();
  2230.     Menu::SetupMenu();
  2231.     Hooks::Initialise();
  2232.     ApplyAAAHooks();
  2233.     // Dumping
  2234.     //Dump::DumpClassIds();
  2235.  
  2236.     //---------------------------------------------------------
  2237.     Utilities::Log("Ready");
  2238.  
  2239.     // While our cheat is running
  2240.     while (DoUnload == false)
  2241.     {
  2242.         Sleep(1000);
  2243.     }
  2244.  
  2245.     Hooks::UndoHooks();
  2246.     Sleep(2000); // Make sure none of our hooks are running
  2247.     FreeLibraryAndExitThread(HThisModule, 0);
  2248.  
  2249.     return 0;
  2250. }
  2251.  
  2252. // DllMain
  2253. // Entry point for our module
  2254. bool _stdcall DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
  2255. {
  2256.     if (dwReason == DLL_PROCESS_ATTACH)
  2257.     {
  2258.         CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)InitialThread, NULL, NULL, NULL);
  2259.     }
  2260.     return true;
  2261. }
  2262. #include "Dumping.h"
  2263.  
  2264. #define DUMPIDTOFILE
  2265.  
  2266. void Dump::DumpClassIds()
  2267. {
  2268. # ifdef DUMPIDTOFILE
  2269.     Utilities::EnableLogFile("ClassID.txt");
  2270. #endif
  2271.     ClientClass* cClass = Interfaces::Client->GetAllClasses();
  2272.     while (cClass)
  2273.     {
  2274.         Utilities::Log("%s = %d,", cClass->m_pNetworkName, cClass->m_ClassID);
  2275.         cClass = cClass->m_pNext;
  2276.     }
  2277. }/*
  2278. Syn's AYYWAREFramework 2015
  2279. */
  2280.  
  2281. #pragma once
  2282.  
  2283. #include "Interfaces.h"
  2284. #include "Utilities.h"
  2285.  
  2286. namespace Dump
  2287. {
  2288.     void DumpClassIds();
  2289. };/*
  2290. Syn's AYYWAREFramework 2015
  2291. */
  2292.  
  2293. #pragma once
  2294.  
  2295. #include "MiscDefinitions.h"
  2296. #include "ClientRecvProps.h"
  2297. #include "offsets.h"
  2298. #include "Vector.h"
  2299.  
  2300. // EngineClient
  2301. class IVEngineClient
  2302. {
  2303.     public:
  2304.         void GetScreenSize(int& width, int& height)
  2305.     {
  2306.         typedef void(__thiscall * oGetScreenSize)(PVOID, int &, int &);
  2307.         return call_vfunc<oGetScreenSize>(this, Offsets::VMT::Engine_GetScreenSize)(this, width, height);
  2308.     }
  2309.     bool GetPlayerInfo(int ent_num, player_info_t* pinfo)
  2310.     {
  2311.         typedef bool(__thiscall * oGetPlayerInfo)(PVOID, int, player_info_t *);
  2312.         return call_vfunc<oGetPlayerInfo>(this, Offsets::VMT::Engine_GetPlayerInfo)(this, ent_num, pinfo);
  2313.     }
  2314.     int GetLocalPlayer()
  2315.     {
  2316.         typedef int(__thiscall * oLocal)(PVOID);
  2317.         return call_vfunc<oLocal>(this, Offsets::VMT::Engine_GetLocalPlayer)(this);
  2318.     }
  2319.     float Time()
  2320.     {
  2321.         typedef float(__thiscall * oTime)(PVOID);
  2322.         return call_vfunc<oTime>(this, Offsets::VMT::Engine_Time)(this);
  2323.     }
  2324.     void GetViewAngles(Vector& vAngles)
  2325.     {
  2326.         typedef void(__thiscall * oSetViewAngles)(PVOID, Vector &);
  2327.         return call_vfunc<oSetViewAngles>(this, Offsets::VMT::Engine_GetViewAngles)(this, vAngles);
  2328.     }
  2329.     void SetViewAngles(Vector& vAngles)
  2330.     {
  2331.         typedef void(__thiscall * oSetViewAngles)(PVOID, Vector &);
  2332.         return call_vfunc<oSetViewAngles>(this, Offsets::VMT::Engine_SetViewAngles)(this, vAngles);
  2333.     }
  2334.     int GetMaxClients()
  2335.     {
  2336.         typedef bool(__thiscall * oGetMaxClients)(PVOID);
  2337.         return call_vfunc<oGetMaxClients>(this, Offsets::VMT::Engine_GetMaxClients)(this);
  2338.     }
  2339.     bool IsConnected()
  2340.     {
  2341.         typedef bool(__thiscall * oGetScreenSize)(PVOID);
  2342.         return call_vfunc<oGetScreenSize>(this, Offsets::VMT::Engine_IsConnected)(this);
  2343.     }
  2344.     bool IsInGame()
  2345.     {
  2346.         typedef bool(__thiscall * oLocal)(PVOID);
  2347.         return call_vfunc<oLocal>(this, Offsets::VMT::Engine_IsInGame)(this);
  2348.     }
  2349.     const matrix3x4& WorldToScreenMatrix()
  2350.     {
  2351.         typedef const matrix3x4&(__thiscall * oWorldToScreenMatrix)(PVOID);
  2352.         return call_vfunc<oWorldToScreenMatrix>(this, Offsets::VMT::Engine_WorldToScreenMatrix)(this);
  2353.     }
  2354.     void ClientCmd_Unrestricted(char  const* cmd)
  2355.         {
  2356.  
  2357.         typedef void(__thiscall* oClientCmdUnres)(PVOID, const char*);
  2358.                 return call_vfunc<oClientCmdUnres>(this, Offsets::VMT::Engine_ClientCmd_Unrestricted)(this, cmd);
  2359.         }
  2360. };/*
  2361. Syn's AyyWare Framework 2015
  2362. */
  2363.  
  2364. #pragma once
  2365.  
  2366. #include "MiscDefinitions.h"
  2367. #include "ClientRecvProps.h"
  2368. #include "offsets.h"
  2369. #include "Vector.h"
  2370.  
  2371. #define TEAM_CS_T 2
  2372. #define TEAM_CS_CT 3
  2373.  
  2374. #define BONE_USED_BY_HITBOX                     0x00000100
  2375.  
  2376. class IClientRenderable;
  2377. class IClientNetworkable;
  2378. class IClientUnknown;
  2379. class IClientThinkable;
  2380. class IClientEntity;
  2381. class CSWeaponInfo;
  2382.  
  2383. class CSWeaponInfo
  2384. {
  2385.     public:
  2386.         virtual void Function0(); //
  2387.     virtual void Function1(); //
  2388.     virtual void Parse(KeyValues* pKeyValuesData, const char* szWeaponName); //
  2389.     virtual void RefreshDynamicParameters(void); //
  2390.     virtual void Function4(); //
  2391.     virtual void Function5(); //
  2392.     virtual void Function6(); //
  2393.     virtual void Function7(); //
  2394.     virtual void Function8(); //
  2395.  
  2396.     char pad_0x0004[0x2]; //0x0004
  2397.     char m_pszName[32]; //0x0006
  2398.     char pad_0x0026[0x7E]; //0x0026
  2399.     __int16 N0000002E; //0x00A4
  2400.     char m_pszModelName[32]; //0x00A6
  2401.     char pad_0x00C6[0x6DE]; //0x00C6
  2402.     BYTE m_IsFullAuto; //0x07A4
  2403.     char pad_0x07A5[0x7]; //0x07A5
  2404.     __int32 m_iPrice; //0x07AC
  2405.     float m_flArmorRatio; //0x07B0
  2406.     char pad_0x07B4[0x10]; //0x07B4
  2407.     float m_flPenetration; //0x07C4
  2408.     __int32 m_iDamage; //0x07C8
  2409.     float m_flRange; //0x07CC
  2410.     float m_flRangeModifier; //0x07D0
  2411.     char pad_0x07D4[0x4]; //0x07D4
  2412.     float m_flCycleTime; //0x07D8
  2413.  
  2414. };
  2415.  
  2416. enum class CSGOClassID
  2417. {
  2418.     CTestTraceline = 189,
  2419.         CTEWorldDecal = 190,
  2420.         CTESpriteSpray = 187,
  2421.         CTESprite = 186,
  2422.         CTESparks = 185,
  2423.         CTESmoke = 184,
  2424.         CTEShowLine = 182,
  2425.         CTEProjectedDecal = 179,
  2426.         CTEPlayerDecal = 178,
  2427.         CTEPhysicsProp = 175,
  2428.         CTEParticleSystem = 174,
  2429.         CTEMuzzleFlash = 173,
  2430.         CTELargeFunnel = 171,
  2431.         CTEKillPlayerAttachments = 170,
  2432.         CTEImpact = 169,
  2433.         CTEGlowSprite = 168,
  2434.         CTEShatterSurface = 181,
  2435.         CTEFootprintDecal = 165,
  2436.         CTEFizz = 164,
  2437.         CTEExplosion = 162,
  2438.         CTEEnergySplash = 161,
  2439.         CTEEffectDispatch = 160,
  2440.         CTEDynamicLight = 159,
  2441.         CTEDecal = 157,
  2442.         CTEClientProjectile = 156,
  2443.         CTEBubbleTrail = 155,
  2444.         CTEBubbles = 154,
  2445.         CTEBSPDecal = 153,
  2446.         CTEBreakModel = 152,
  2447.         CTEBloodStream = 151,
  2448.         CTEBloodSprite = 150,
  2449.         CTEBeamSpline = 149,
  2450.         CTEBeamRingPoint = 148,
  2451.         CTEBeamRing = 147,
  2452.         CTEBeamPoints = 146,
  2453.         CTEBeamLaser = 145,
  2454.         CTEBeamFollow = 144,
  2455.         CTEBeamEnts = 143,
  2456.         CTEBeamEntPoint = 142,
  2457.         CTEBaseBeam = 141,
  2458.         CTEArmorRicochet = 140,
  2459.         CTEMetalSparks = 172,
  2460.         CSteamJet = 135,
  2461.         CSmokeStack = 128,
  2462.         DustTrail = 238,
  2463.         CFireTrail = 62,
  2464.         SporeTrail = 244,
  2465.         SporeExplosion = 243,
  2466.         RocketTrail = 241,
  2467.         SmokeTrail = 242,
  2468.         CPropVehicleDriveable = 117,
  2469.         ParticleSmokeGrenade = 240,
  2470.         CParticleFire = 96,
  2471.         MovieExplosion = 239,
  2472.         CTEGaussExplosion = 167,
  2473.         CEnvQuadraticBeam = 55,
  2474.         CEmbers = 45,
  2475.         CEnvWind = 59,
  2476.         CPrecipitation = 111,
  2477.         CPrecipitationBlocker = 112,
  2478.         CBaseTempEntity = 18,
  2479.         NextBotCombatCharacter = 0,
  2480.         CBaseAttributableItem = 4,
  2481.         CEconEntity = 44,
  2482.         CWeaponXM1014 = 236,
  2483.         CWeaponTaser = 231,
  2484.         CSmokeGrenade = 126,
  2485.         CWeaponSG552 = 228,
  2486.         CWeaponSawedoff = 224,
  2487.         CWeaponNOVA = 220,
  2488.         CIncendiaryGrenade = 85,
  2489.         CMolotovGrenade = 93,
  2490.         CWeaponM3 = 212,
  2491.         CKnifeGG = 90,
  2492.         CKnife = 89,
  2493.         CHEGrenade = 82,
  2494.         CFlashbang = 64,
  2495.         CWeaponElite = 203,
  2496.         CDecoyGrenade = 40,
  2497.         CDEagle = 39,
  2498.         CWeaponUSP = 235,
  2499.         CWeaponM249 = 211,
  2500.         CWeaponUMP45 = 234,
  2501.         CWeaponTMP = 233,
  2502.         CWeaponTec9 = 232,
  2503.         CWeaponSSG08 = 230,
  2504.         CWeaponSG556 = 229,
  2505.         CWeaponSG550 = 227,
  2506.         CWeaponScout = 226,
  2507.         CWeaponSCAR20 = 225,
  2508.         CSCAR17 = 122,
  2509.         CWeaponP90 = 223,
  2510.         CWeaponP250 = 222,
  2511.         CWeaponP228 = 221,
  2512.         CWeaponNegev = 219,
  2513.         CWeaponMP9 = 218,
  2514.         CWeaponMP7 = 217,
  2515.         CWeaponMP5Navy = 216,
  2516.         CWeaponMag7 = 215,
  2517.         CWeaponMAC10 = 214,
  2518.         CWeaponM4A1 = 213,
  2519.         CWeaponHKP2000 = 210,
  2520.         CWeaponGlock = 209,
  2521.         CWeaponGalilAR = 208,
  2522.         CWeaponGalil = 207,
  2523.         CWeaponG3SG1 = 206,
  2524.         CWeaponFiveSeven = 205,
  2525.         CWeaponFamas = 204,
  2526.         CWeaponBizon = 199,
  2527.         CWeaponAWP = 198,
  2528.         CWeaponAug = 197,
  2529.         CAK47 = 1,
  2530.         CWeaponCSBaseGun = 201,
  2531.         CWeaponCSBase = 200,
  2532.         CC4 = 29,
  2533.         CBaseCSGrenade = 8,
  2534.         CSmokeGrenadeProjectile = 127,
  2535.         CMolotovProjectile = 94,
  2536.         CDecoyProjectile = 41,
  2537.         CFireCrackerBlast = 60,
  2538.         CInferno = 86,
  2539.         CChicken = 31,
  2540.         CFootstepControl = 66,
  2541.         CCSGameRulesProxy = 34,
  2542.         CWeaponCubemap = 0,
  2543.         CWeaponCycler = 202,
  2544.         CTEPlantBomb = 176,
  2545.         CTEFireBullets = 163,
  2546.         CTERadioIcon = 180,
  2547.         CPlantedC4 = 104,
  2548.         CCSTeam = 38,
  2549.         CCSPlayerResource = 36,
  2550.         CCSPlayer = 35,
  2551.         CCSRagdoll = 37,
  2552.         CTEPlayerAnimEvent = 177,
  2553.         CHostage = 83,
  2554.         CHostageCarriableProp = 84,
  2555.         CBaseCSGrenadeProjectile = 9,
  2556.         CHandleTest = 81,
  2557.         CTeamplayRoundBasedRulesProxy = 139,
  2558.         CSpriteTrail = 133,
  2559.         CSpriteOriented = 132,
  2560.         CSprite = 131,
  2561.         CRagdollPropAttached = 120,
  2562.         CRagdollProp = 119,
  2563.         CPredictedViewModel = 113,
  2564.         CPoseController = 109,
  2565.         CGameRulesProxy = 80,
  2566.         CInfoLadderDismount = 87,
  2567.         CFuncLadder = 72,
  2568.         CTEFoundryHelpers = 166,
  2569.         CEnvDetailController = 51,
  2570.         CWorld = 237,
  2571.         CWaterLODControl = 196,
  2572.         CWaterBullet = 195,
  2573.         CVoteController = 194,
  2574.         CVGuiScreen = 193,
  2575.         CPropJeep = 116,
  2576.         CPropVehicleChoreoGeneric = 0,
  2577.         CTriggerSoundOperator = 192,
  2578.         CBaseVPhysicsTrigger = 22,
  2579.         CTriggerPlayerMovement = 191,
  2580.         CBaseTrigger = 20,
  2581.         CTest_ProxyToggle_Networkable = 188,
  2582.         CTesla = 183,
  2583.         CBaseTeamObjectiveResource = 17,
  2584.         CTeam = 138,
  2585.         CSunlightShadowControl = 137,
  2586.         CSun = 136,
  2587.         CParticlePerformanceMonitor = 97,
  2588.         CSpotlightEnd = 130,
  2589.         CSpatialEntity = 129,
  2590.         CSlideshowDisplay = 125,
  2591.         CShadowControl = 124,
  2592.         CSceneEntity = 123,
  2593.         CRopeKeyframe = 121,
  2594.         CRagdollManager = 118,
  2595.         CPhysicsPropMultiplayer = 102,
  2596.         CPhysBoxMultiplayer = 100,
  2597.         CPropDoorRotating = 115,
  2598.         CBasePropDoor = 16,
  2599.         CDynamicProp = 43,
  2600.         CProp_Hallucination = 114,
  2601.         CPostProcessController = 110,
  2602.         CPointCommentaryNode = 108,
  2603.         CPointCamera = 107,
  2604.         CPlayerResource = 106,
  2605.         CPlasma = 105,
  2606.         CPhysMagnet = 103,
  2607.         CPhysicsProp = 101,
  2608.         CStatueProp = 134,
  2609.         CPhysBox = 99,
  2610.         CParticleSystem = 98,
  2611.         CMovieDisplay = 95,
  2612.         CMaterialModifyControl = 92,
  2613.         CLightGlow = 91,
  2614.         CInfoOverlayAccessor = 88,
  2615.         CFuncTrackTrain = 79,
  2616.         CFuncSmokeVolume = 78,
  2617.         CFuncRotating = 77,
  2618.         CFuncReflectiveGlass = 76,
  2619.         CFuncOccluder = 75,
  2620.         CFuncMoveLinear = 74,
  2621.         CFuncMonitor = 73,
  2622.         CFunc_LOD = 68,
  2623.         CTEDust = 158,
  2624.         CFunc_Dust = 67,
  2625.         CFuncConveyor = 71,
  2626.         CFuncBrush = 70,
  2627.         CBreakableSurface = 28,
  2628.         CFuncAreaPortalWindow = 69,
  2629.         CFish = 63,
  2630.         CFireSmoke = 61,
  2631.         CEnvTonemapController = 58,
  2632.         CEnvScreenEffect = 56,
  2633.         CEnvScreenOverlay = 57,
  2634.         CEnvProjectedTexture = 54,
  2635.         CEnvParticleScript = 53,
  2636.         CFogController = 65,
  2637.         CEnvDOFController = 52,
  2638.         CCascadeLight = 30,
  2639.         CEnvAmbientLight = 50,
  2640.         CEntityParticleTrail = 49,
  2641.         CEntityFreezing = 48,
  2642.         CEntityFlame = 47,
  2643.         CEntityDissolve = 46,
  2644.         CDynamicLight = 42,
  2645.         CColorCorrectionVolume = 33,
  2646.         CColorCorrection = 32,
  2647.         CBreakableProp = 27,
  2648.         CBeamSpotlight = 25,
  2649.         CBaseButton = 5,
  2650.         CBaseToggle = 19,
  2651.         CBasePlayer = 15,
  2652.         CBaseFlex = 12,
  2653.         CBaseEntity = 11,
  2654.         CBaseDoor = 10,
  2655.         CBaseCombatCharacter = 6,
  2656.         CBaseAnimatingOverlay = 3,
  2657.         CBoneFollower = 26,
  2658.         CBaseAnimating = 2,
  2659.         CAI_BaseNPC = 0,
  2660.         CBeam = 24,
  2661.         CBaseViewModel = 21,
  2662.         CBaseParticleEntity = 14,
  2663.         CBaseGrenade = 13,
  2664.         CBaseCombatWeapon = 7,
  2665.         CBaseWeaponWorldModel = 23
  2666. };
  2667.  
  2668. enum class CSGOHitboxID
  2669. {
  2670.     Head = 0,
  2671.         Neck,
  2672.         NeckLower,
  2673.         Pelvis,
  2674.         Stomach,
  2675.         LowerChest,
  2676.         Chest,
  2677.         UpperChest,
  2678.         RightThigh,
  2679.         LeftThigh,
  2680.         RightShin,
  2681.         LeftShin,
  2682.         RightFoot,
  2683.         LeftFoot,
  2684.         RightHand,
  2685.         LeftHand,
  2686.         RightUpperArm,
  2687.         RightLowerArm,
  2688.         LeftUpperArm,
  2689.         LeftLowerArm
  2690. };
  2691.  
  2692. class ScriptCreatedItem
  2693. {
  2694.     public:
  2695.  
  2696.     CPNETVAR_FUNC(int*, ItemDefinitionIndex, 0xE67AB3B8); //m_iItemDefinitionIndex
  2697.  
  2698.     CPNETVAR_FUNC(int*, ItemIDHigh, 0x714778A); //m_iItemIDHigh
  2699.  
  2700.     CPNETVAR_FUNC(int*, ItemIDLow, 0x3A3DFC74); //m_iItemIDLow
  2701. };
  2702.  
  2703. class AttributeContainer
  2704. {
  2705.     public:
  2706.  
  2707.     CPNETVAR_FUNC(ScriptCreatedItem*, m_Item, 0x7E029CE5);
  2708. };
  2709.  
  2710.  
  2711. class CBaseCombatWeapon
  2712. {
  2713.     public:
  2714.  
  2715.     CNETVAR_FUNC(float, GetNextPrimaryAttack, 0xDB7B106E); //m_flNextPrimaryAttack
  2716.  
  2717.     CNETVAR_FUNC(int, GetAmmoInClip, 0x97B6F70C); //m_iClip1
  2718.  
  2719.     CNETVAR_FUNC(HANDLE, GetOwnerHandle, 0xC32DF98D); //m_hOwner
  2720.  
  2721.     CNETVAR_FUNC(Vector, GetOrigin, 0x1231CE10); //m_vecOrigin
  2722.  
  2723.  
  2724.     CPNETVAR_FUNC(int*, FallbackPaintKit, 0xADE4C870); // m_nFallbackPaintKit
  2725.  
  2726.     CPNETVAR_FUNC(int*, FallbackSeed, 0xC2D0683D); // m_nFallbackSeed
  2727.  
  2728.     CPNETVAR_FUNC(float*, FallbackWear, 0xA263576C); //m_flFallbackWear
  2729.  
  2730.     CPNETVAR_FUNC(int*, FallbackStatTrak, 0x1ED78768); //m_nFallbackStatTrak
  2731.  
  2732.     CPNETVAR_FUNC(int*, OwnerXuidLow, 0xAD8D897F);
  2733.  
  2734.     CPNETVAR_FUNC(int*, OwnerXuidHigh, 0x90511E77);
  2735.  
  2736.     CPNETVAR_FUNC(int*, ViewModelIndex, 0x7F7C89C1);
  2737.  
  2738.     CPNETVAR_FUNC(int*, WorldModelIndex, 0x4D8AD9F3);
  2739.  
  2740.  
  2741.     CPNETVAR_FUNC(AttributeContainer*, m_AttributeManager, 0xCFFCE089);
  2742.  
  2743.     float GetInaccuracy()
  2744.     {
  2745.         typedef float(__thiscall * oGetSpread)(PVOID);
  2746.         return call_vfunc<oGetSpread>(this, Offsets::VMT::Weapon_GetSpread)(this);
  2747.     }
  2748.  
  2749.     float GetSpread()
  2750.     {
  2751.         typedef float(__thiscall * oGetInac)(PVOID);
  2752.         return call_vfunc<oGetInac>(this, Offsets::VMT::Weapon_GetSpread + 1)(this);
  2753.     }
  2754.  
  2755.     void UpdateAccuracyPenalty()
  2756.     {
  2757.         typedef void(__thiscall * oUpdateAccuracyPenalty)(PVOID);
  2758.         return call_vfunc<oUpdateAccuracyPenalty>(this, Offsets::VMT::Weapon_GetSpread + 2)(this);
  2759.     }
  2760.  
  2761.     CSWeaponInfo* GetCSWpnData()
  2762.     {
  2763.         static DWORD GetCSWpnDataAddr = Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x55\x8B\xEC\x81\xEC\x00\x00\x00\x00\xB8\x00\x00\x00\x00\x57", "xxxxx????x????x");
  2764.         if (GetCSWpnDataAddr)
  2765.         {
  2766.             CSWeaponInfo* retData;
  2767.             __asm
  2768.  
  2769.             {
  2770.                 mov ecx, this
  2771.  
  2772.                     call GetCSWpnDataAddr
  2773.  
  2774.                     mov retData, eax
  2775.  
  2776.             }
  2777.             return retData;
  2778.         }
  2779.         else
  2780.         {
  2781.             return nullptr;
  2782.         }
  2783.     }
  2784. };
  2785.  
  2786. class CCSBomb
  2787. {
  2788.     public:
  2789.  
  2790.     CNETVAR_FUNC(HANDLE, GetOwnerHandle, 0xC32DF98D); //m_hOwner
  2791.  
  2792.     CNETVAR_FUNC(float, GetC4BlowTime, 0xB5E0CA1C); //m_flC4Blow
  2793.  
  2794.     CNETVAR_FUNC(float, GetC4DefuseCountDown, 0xB959B4A6); //m_flDefuseCountDown
  2795. };
  2796.  
  2797. class CLocalPlayerExclusive
  2798. {
  2799.     public:
  2800.  
  2801.     CNETVAR_FUNC(Vector, GetViewPunchAngle, 0x68F014C0);//m_viewPunchAngle
  2802.  
  2803.     CNETVAR_FUNC(Vector, GetAimPunchAngle, 0xBF25C290);//m_aimPunchAngle
  2804.  
  2805.     CNETVAR_FUNC(Vector, GetAimPunchAngleVel, 0x8425E045);//m_aimPunchAngleVel
  2806. };
  2807.  
  2808. class CollisionProperty
  2809. {
  2810.     public:
  2811.  
  2812.     CNETVAR_FUNC(Vector, GetMins, 0xF6F78BAB);//m_vecMins
  2813.  
  2814.     CNETVAR_FUNC(Vector, GetMaxs, 0xE47C6FC4);//m_vecMaxs
  2815.  
  2816.     CNETVAR_FUNC(unsigned char, GetSolidType, 0xB86722A1);//m_nSolidType
  2817.  
  2818.     CNETVAR_FUNC(unsigned short, GetSolidFlags, 0x63BB24C1);//m_usSolidFlags
  2819.  
  2820.     CNETVAR_FUNC(int, GetSurroundsType, 0xB677A0BB); //m_nSurroundType
  2821.  
  2822.     bool IsSolid()
  2823.     {
  2824.         return (GetSolidType() != SOLID_NONE) && ((GetSolidFlags() & FSOLID_NOT_SOLID) == 0);
  2825.     }
  2826. };
  2827.  
  2828. class IClientRenderable
  2829. {
  2830.     public:
  2831.         //virtual void*                                 GetIClientUnknown() = 0;
  2832.         virtual Vector const&                   GetRenderOrigin(void) = 0;
  2833.         virtual Vector const&                   GetRenderAngles(void) = 0;
  2834.         virtual bool ShouldDraw(void) = 0;
  2835.         virtual bool IsTransparent(void) = 0;
  2836.         virtual bool UsesPowerOfTwoFrameBufferTexture() = 0;
  2837.         virtual bool UsesFullFrameBufferTexture() = 0;
  2838.         virtual void GetShadowHandle() const = 0;
  2839.     virtual void* RenderHandle() = 0;
  2840.         virtual const model_t* GetModel() const = 0;
  2841.     virtual int DrawModel(int flags) = 0;
  2842.         virtual int GetBody() = 0;
  2843.         virtual void ComputeFxBlend() = 0;
  2844.  
  2845.         bool SetupBones(matrix3x4* pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime)
  2846.     {
  2847.         typedef bool(__thiscall * oSetupBones)(PVOID, matrix3x4 *, int, int, float);
  2848.         return call_vfunc<oSetupBones>(this, 13)(this, pBoneToWorldOut, nMaxBones, boneMask, currentTime);
  2849.     }
  2850. };
  2851.  
  2852. class IClientNetworkable
  2853. {
  2854.     public:
  2855.         virtual IClientUnknown* GetIClientUnknown() = 0;
  2856.         virtual void Release() = 0;
  2857.         virtual ClientClass* GetClientClass() = 0;// FOR NETVARS FIND YOURSELF ClientClass* stuffs
  2858.         virtual void NotifyShouldTransmit( /* ShouldTransmitState_t state*/) = 0;
  2859.         virtual void OnPreDataChanged( /*DataUpdateType_t updateType*/) = 0;
  2860.         virtual void OnDataChanged( /*DataUpdateType_t updateType*/) = 0;
  2861.         virtual void PreDataUpdate( /*DataUpdateType_t updateType*/) = 0;
  2862.         virtual void PostDataUpdate( /*DataUpdateType_t updateType*/) = 0;
  2863.         virtual void unknown();
  2864.     virtual bool IsDormant(void) = 0;
  2865.         virtual int GetIndex(void) const = 0;
  2866.     virtual void ReceiveMessage(int classID /*, bf_read &msg*/) = 0;
  2867.         virtual void* GetDataTableBasePtr() = 0;
  2868.         virtual void SetDestroyedOnRecreateEntities(void) = 0;
  2869. };
  2870.  
  2871. class IClientUnknown
  2872. {
  2873.     public:
  2874.         virtual void* GetCollideable() = 0;
  2875.         virtual IClientNetworkable* GetClientNetworkable() = 0;
  2876.         virtual IClientRenderable* GetClientRenderable() = 0;
  2877.         virtual IClientEntity* GetIClientEntity() = 0;
  2878.         virtual IClientEntity* GetBaseEntity() = 0;
  2879.         virtual IClientThinkable* GetClientThinkable() = 0;
  2880. };
  2881.  
  2882. class IClientThinkable
  2883. {
  2884.     public:
  2885.         virtual IClientUnknown* GetIClientUnknown() = 0;
  2886.         virtual void ClientThink() = 0;
  2887.         virtual void* GetThinkHandle() = 0;
  2888.         virtual void SetThinkHandle(void* hThink) = 0;
  2889.         virtual void Release() = 0;
  2890. };
  2891.  
  2892. class __declspec (novtable)IClientEntity : public IClientUnknown, public IClientRenderable, public IClientNetworkable, public IClientThinkable
  2893. {
  2894. public:
  2895. public:
  2896.         virtual void Release(void) = 0;
  2897.         virtual void blahblahpad(void) = 0;
  2898.         virtual Vector& GetAbsOrigin(void) const = 0;//in broken place use GetOrigin Below
  2899. virtual const Vector&   GetAbsAngles(void) const = 0;
  2900.  
  2901.     //---                 NetVars                  ---//
  2902.  
  2903.     CPNETVAR_FUNC(CLocalPlayerExclusive*, localPlayerExclusive, 0x7177BC3E);// m_Local
  2904.  
  2905.     CPNETVAR_FUNC(CollisionProperty*, collisionProperty, 0xE477CBD0);//m_Collision
  2906.  
  2907.  
  2908.     CNETVAR_FUNC(int, GetFlags, 0xE456D580); //m_fFlags
  2909.  
  2910.     CNETVAR_FUNC(Vector, GetOrigin, 0x1231CE10); //m_vecOrigin
  2911.  
  2912.     CNETVAR_FUNC(Vector, GetRotation, 0x6BEA197A); //m_angRotation
  2913.  
  2914.     CNETVAR_FUNC(int, GetTeamNum, 0xC08B6C6E); //m_iTeamNum
  2915.  
  2916.     CNETVAR_FUNC(int, GetMaxHealth, 0xC52E1C28); //m_iMaxHealth
  2917.  
  2918.     CNETVAR_FUNC(int, GetHealth, 0xA93054E3); //m_iHealth
  2919.  
  2920.     CNETVAR_FUNC(unsigned char, GetLifeState, 0xD795CCFC); //m_lifeState
  2921.  
  2922.     CNETVAR_FUNC(HANDLE, GetActiveWeaponHandle, 0xB4FECDA3); //m_hActiveWeapon
  2923.  
  2924.     CNETVAR_FUNC(int, GetTickBase, 0xD472B079); //m_nTickBase
  2925.  
  2926.     CNETVAR_FUNC(Vector, GetViewOffset, 0xA9F74931); //m_vecViewOffset[0]
  2927.  
  2928.     CNETVAR_FUNC(Vector, GetVelocity, 0x40C1CA24); //m_vecVelocity[0]
  2929.  
  2930.     CNETVAR_FUNC(bool, HasGunGameImmunity, 0x6AD6FA0D); //m_bGunGameImmunity
  2931.  
  2932.     CNETVAR_FUNC(bool, IsDefusing, 0xA2C14106); //m_bIsDefusing
  2933.  
  2934.     CNETVAR_FUNC(int, ArmorValue, 0x3898634); //m_ArmorValue
  2935.  
  2936.     CNETVAR_FUNC(bool, HasHelmet, 0x7B97F18A); //m_bHasHelmet
  2937.  
  2938.     CNETVAR_FUNC(bool, IsScoped, 0x61B9C22C); //m_bIsScoped
  2939.  
  2940.     CNETVAR_FUNC(int, GetMoney, 0xF4B3E183); //m_iAccount
  2941.  
  2942.     CNETVAR_FUNC(HANDLE, GetObserverTargetHandle, 0x8660FD83); //m_hObserverTarget
  2943.                                                                // ----------------------------------------------//
  2944.  
  2945. bool IsAlive()
  2946. {
  2947.     return (GetLifeState() == LIFE_ALIVE && GetHealth() > 0);
  2948. }
  2949.  
  2950. Vector GetBonePos(int i)
  2951. {
  2952.     matrix3x4 boneMatrix[128];
  2953.     if (this->SetupBones(boneMatrix, 128, BONE_USED_BY_HITBOX, GetTickCount64()))
  2954.     {
  2955.         return Vector(boneMatrix[i][0][3], boneMatrix[i][1][3], boneMatrix[i][2][3]);
  2956.     }
  2957.     return Vector(0, 0, 0);
  2958. }
  2959.  
  2960. Vector GetHeadPos()
  2961. {
  2962.     return this->GetBonePos(6);
  2963. }
  2964.  
  2965. };/*
  2966. Syn's AYYWAREFramework 2015
  2967. */
  2968.  
  2969. #include "ESP.h"
  2970. #include "Interfaces.h"
  2971. #include "RenderManager.h"
  2972.  
  2973. void CEsp::Init()
  2974. {
  2975.     BombCarrier = nullptr;
  2976. }
  2977.  
  2978. // Yeah dude we're defo gunna do some sick moves for the esp yeah
  2979. void CEsp::Move(CUserCmd* pCmd) { }
  2980.  
  2981. // Main ESP Drawing loop
  2982. void CEsp::Draw()
  2983. {
  2984.     IClientEntity* pLocal = hackManager.pLocal();
  2985.  
  2986.     // Loop through all active entitys
  2987.     for (int i = 0; i < Interfaces::EntList->GetHighestEntityIndex(); i++)
  2988.     {
  2989.         // Get the entity
  2990.         IClientEntity* pEntity = Interfaces::EntList->GetClientEntity(i);
  2991.         player_info_t pinfo;
  2992.  
  2993.         // The entity isn't some laggy peice of shit or something
  2994.         if (pEntity && pEntity != pLocal && !pEntity->IsDormant())
  2995.         {
  2996.             // Is it a player?!
  2997.             if (Menu::Window.VisualsTab.FiltersPlayers.GetState() && Interfaces::Engine->GetPlayerInfo(i, &pinfo) && pEntity->IsAlive())
  2998.             {
  2999.                 DrawPlayer(pEntity, pinfo);
  3000.             }
  3001.  
  3002.             // ~ Other ESP's here (items and shit) ~ //
  3003.             ClientClass* cClass = (ClientClass*)pEntity->GetClientClass();
  3004.  
  3005.             // Dropped weapons
  3006.             if (Menu::Window.VisualsTab.FiltersWeapons.GetState() && cClass->m_ClassID != (int)CSGOClassID::CBaseWeaponWorldModel && ((strstr(cClass->m_pNetworkName, "Weapon") || cClass->m_ClassID == (int)CSGOClassID::CDEagle || cClass->m_ClassID == (int)CSGOClassID::CAK47)))
  3007.             {
  3008.                 DrawDrop(pEntity, cClass);
  3009.             }
  3010.  
  3011.             // If entity is the bomb
  3012.             if (Menu::Window.VisualsTab.FiltersC4.GetState())
  3013.             {
  3014.                 if (cClass->m_ClassID == (int)CSGOClassID::CPlantedC4)
  3015.                     DrawBombPlanted(pEntity, cClass);
  3016.  
  3017.                 if (cClass->m_ClassID == (int)CSGOClassID::CC4)
  3018.                     DrawBomb(pEntity, cClass);
  3019.             }
  3020.  
  3021.             // If entity is a chicken
  3022.             if (Menu::Window.VisualsTab.FiltersChickens.GetState())
  3023.             {
  3024.                 if (cClass->m_ClassID == (int)CSGOClassID::CChicken)
  3025.                     DrawChicken(pEntity, cClass);
  3026.             }
  3027.         }
  3028.     }
  3029. }
  3030.  
  3031. //  Yeah m8
  3032. void CEsp::DrawPlayer(IClientEntity* pEntity, player_info_t pinfo)
  3033. {
  3034.     ESPBox Box;
  3035.     Color Color;
  3036.  
  3037.     // Show own team false? well gtfo teammate
  3038.     if (Menu::Window.VisualsTab.FiltersEnemiesOnly.GetState() && (pEntity->GetTeamNum() == hackManager.pLocal()->GetTeamNum()))
  3039.         return;
  3040.  
  3041.     if (GetBox(pEntity, Box))
  3042.     {
  3043.         Color = GetPlayerColor(pEntity);
  3044.  
  3045.         if (Menu::Window.VisualsTab.OptionsBox.GetState())
  3046.             DrawBox(Box, Color);
  3047.  
  3048.         if (Menu::Window.VisualsTab.OptionsName.GetState())
  3049.             DrawName(pinfo, Box);
  3050.  
  3051.         if (Menu::Window.VisualsTab.OptionsHealth.GetState())
  3052.             DrawHealth(pEntity, Box);
  3053.  
  3054.         if (Menu::Window.VisualsTab.OptionsInfo.GetState() || Menu::Window.VisualsTab.OptionsWeapon.GetState())
  3055.             DrawInfo(pEntity, Box);
  3056.  
  3057.         if (Menu::Window.VisualsTab.OptionsAimSpot.GetState())
  3058.             DrawCross(pEntity);
  3059.  
  3060.         if (Menu::Window.VisualsTab.OptionsSkeleton.GetState())
  3061.             DrawSkeleton(pEntity);
  3062.     }
  3063. }
  3064.  
  3065. // Gets the 2D bounding box for the entity
  3066. // Returns false on failure nigga don't fail me
  3067. bool CEsp::GetBox(IClientEntity* pEntity, CEsp::ESPBox &result)
  3068. {
  3069.     // Variables
  3070.     Vector vOrigin, min, max, sMin, sMax, sOrigin,
  3071.         flb, brt, blb, frt, frb, brb, blt, flt;
  3072.     float left, top, right, bottom;
  3073.  
  3074.     // Get the locations
  3075.     vOrigin = pEntity->GetOrigin();
  3076.     min = pEntity->collisionProperty()->GetMins() + vOrigin;
  3077.     max = pEntity->collisionProperty()->GetMaxs() + vOrigin;
  3078.  
  3079.     // Points of a 3d bounding box
  3080.     Vector points[] = { Vector(min.x, min.y, min.z),
  3081.         Vector(min.x, max.y, min.z),
  3082.         Vector(max.x, max.y, min.z),
  3083.         Vector(max.x, min.y, min.z),
  3084.         Vector(max.x, max.y, max.z),
  3085.         Vector(min.x, max.y, max.z),
  3086.         Vector(min.x, min.y, max.z),
  3087.         Vector(max.x, min.y, max.z) };
  3088.  
  3089.     // Get screen positions
  3090.     if (!Render::WorldToScreen(points[3], flb) || !Render::WorldToScreen(points[5], brt)
  3091.         || !Render::WorldToScreen(points[0], blb) || !Render::WorldToScreen(points[4], frt)
  3092.         || !Render::WorldToScreen(points[2], frb) || !Render::WorldToScreen(points[1], brb)
  3093.         || !Render::WorldToScreen(points[6], blt) || !Render::WorldToScreen(points[7], flt))
  3094.         return false;
  3095.  
  3096.     // Put them in an array (maybe start them off in one later for speed?)
  3097.     Vector arr[] = { flb, brt, blb, frt, frb, brb, blt, flt };
  3098.  
  3099.     // Init this shit
  3100.     left = flb.x;
  3101.     top = flb.y;
  3102.     right = flb.x;
  3103.     bottom = flb.y;
  3104.  
  3105.     // Find the bounding corners for our box
  3106.     for (int i = 1; i < 8; i++)
  3107.     {
  3108.         if (left > arr[i].x)
  3109.             left = arr[i].x;
  3110.         if (bottom < arr[i].y)
  3111.             bottom = arr[i].y;
  3112.         if (right < arr[i].x)
  3113.             right = arr[i].x;
  3114.         if (top > arr[i].y)
  3115.             top = arr[i].y;
  3116.     }
  3117.  
  3118.     // Width / height
  3119.     result.x = left;
  3120.     result.y = top;
  3121.     result.w = right - left;
  3122.     result.h = bottom - top;
  3123.  
  3124.     return true;
  3125. }
  3126.  
  3127. // Get an entities color depending on team and vis ect
  3128. Color CEsp::GetPlayerColor(IClientEntity* pEntity)
  3129. {
  3130.     int TeamNum = pEntity->GetTeamNum();
  3131.     bool IsVis = GameUtils::IsVisible(hackManager.pLocal(), pEntity, (int)CSGOHitboxID::Head);
  3132.  
  3133.     Color color;
  3134.  
  3135.     if (TeamNum == TEAM_CS_T)
  3136.     {
  3137.         if (IsVis)
  3138.             color = Color(235, 200, 0, 255);
  3139.         else
  3140.             color = Color(235, 50, 0, 255);
  3141.     }
  3142.     else
  3143.     {
  3144.         if (IsVis)
  3145.             color = Color(120, 210, 26, 255);
  3146.         else
  3147.             color = Color(15, 110, 220, 255);
  3148.     }
  3149.  
  3150.  
  3151.     return color;
  3152. }
  3153.  
  3154. // 2D  Esp box
  3155. void CEsp::DrawBox(CEsp::ESPBox size, Color color)
  3156. {
  3157.     //if (PlayerBoxes->GetStringIndex() == 1)
  3158.     //{
  3159.     //  // Full Box
  3160.     //  renderMan->Outline(size.x, size.y, size.w, size.h, color);
  3161.     //  renderMan->Outline(size.x - 1, size.y - 1, size.w + 2, size.h + 2, COLORCODE(10, 10, 10, 150));
  3162.     //  renderMan->Outline(size.x + 1, size.y + 1, size.w - 2, size.h - 2, COLORCODE(10, 10, 10, 150));
  3163.     //}
  3164.     //else
  3165.     //{
  3166.     // Corner Box
  3167.     int VertLine = (((float)size.w) * (0.20f));
  3168.     int HorzLine = (((float)size.h) * (0.20f));
  3169.  
  3170.     Render::Clear(size.x, size.y - 1, VertLine, 1, Color(10, 10, 10, 150));
  3171.     Render::Clear(size.x + size.w - VertLine, size.y - 1, VertLine, 1, Color(10, 10, 10, 150));
  3172.     Render::Clear(size.x, size.y + size.h - 1, VertLine, 1, Color(10, 10, 10, 150));
  3173.     Render::Clear(size.x + size.w - VertLine, size.y + size.h - 1, VertLine, 1, Color(10, 10, 10, 150));
  3174.  
  3175.     Render::Clear(size.x - 1, size.y, 1, HorzLine, Color(10, 10, 10, 150));
  3176.     Render::Clear(size.x - 1, size.y + size.h - HorzLine, 1, HorzLine, Color(10, 10, 10, 150));
  3177.     Render::Clear(size.x + size.w - 1, size.y, 1, HorzLine, Color(10, 10, 10, 150));
  3178.     Render::Clear(size.x + size.w - 1, size.y + size.h - HorzLine, 1, HorzLine, Color(10, 10, 10, 150));
  3179.  
  3180.     Render::Clear(size.x, size.y, VertLine, 1, color);
  3181.     Render::Clear(size.x + size.w - VertLine, size.y, VertLine, 1, color);
  3182.     Render::Clear(size.x, size.y + size.h, VertLine, 1, color);
  3183.     Render::Clear(size.x + size.w - VertLine, size.y + size.h, VertLine, 1, color);
  3184.  
  3185.     Render::Clear(size.x, size.y, 1, HorzLine, color);
  3186.     Render::Clear(size.x, size.y + size.h - HorzLine, 1, HorzLine, color);
  3187.     Render::Clear(size.x + size.w, size.y, 1, HorzLine, color);
  3188.     Render::Clear(size.x + size.w, size.y + size.h - HorzLine, 1, HorzLine, color);
  3189.     //}
  3190. }
  3191.  
  3192. // Unicode Conversions
  3193. static wchar_t* CharToWideChar(const char* text)
  3194. {
  3195.     size_t size = strlen(text) + 1;
  3196.     wchar_t* wa = new wchar_t[size];
  3197.     mbstowcs_s(NULL, wa, size / 4, text, size);
  3198.     return wa;
  3199. }
  3200.  
  3201. // Player name
  3202. void CEsp::DrawName(player_info_t pinfo, CEsp::ESPBox size)
  3203. {
  3204.     RECT nameSize = Render::GetTextSize(Render::Fonts::ESP, pinfo.name);
  3205.     Render::Text(size.x + (size.w / 2) - (nameSize.right / 2), size.y - 16,
  3206.         Color(255, 255, 255, 255), Render::Fonts::ESP, pinfo.name);
  3207. }
  3208.  
  3209. // Draw a health bar. For Tf2 when a bar is bigger than max health a second bar is displayed
  3210. void CEsp::DrawHealth(IClientEntity* pEntity, CEsp::ESPBox size)
  3211. {
  3212.     ESPBox HealthBar = size;
  3213.     HealthBar.y += (HealthBar.h + 6);
  3214.     HealthBar.h = 4;
  3215.  
  3216.     float HealthValue = pEntity->GetHealth();
  3217.     float HealthPerc = HealthValue / 100.f;
  3218.     float Width = (size.w * HealthPerc);
  3219.     HealthBar.w = Width;
  3220.  
  3221.     // --  Main Bar -- //
  3222.  
  3223.     Vertex_t Verts[4];
  3224.     Verts[0].Init(Vector2D(HealthBar.x, HealthBar.y));
  3225.     Verts[1].Init(Vector2D(HealthBar.x + size.w + 5, HealthBar.y));
  3226.     Verts[2].Init(Vector2D(HealthBar.x + size.w, HealthBar.y + 5));
  3227.     Verts[3].Init(Vector2D(HealthBar.x - 5, HealthBar.y + 5));
  3228.  
  3229.     Render::PolygonOutline(4, Verts, Color(10, 10, 10, 255), Color(255, 255, 255, 170));
  3230.  
  3231.     Vertex_t Verts2[4];
  3232.     Verts2[0].Init(Vector2D(HealthBar.x + 1, HealthBar.y + 1));
  3233.     Verts2[1].Init(Vector2D(HealthBar.x + HealthBar.w + 4, HealthBar.y + 1));
  3234.     Verts2[2].Init(Vector2D(HealthBar.x + HealthBar.w, HealthBar.y + 5));
  3235.     Verts2[3].Init(Vector2D(HealthBar.x - 4, HealthBar.y + 5));
  3236.  
  3237.     Color c = GetPlayerColor(pEntity);
  3238.     Render::Polygon(4, Verts2, c);
  3239.  
  3240.     Verts2[0].Init(Vector2D(HealthBar.x + 1, HealthBar.y + 1));
  3241.     Verts2[1].Init(Vector2D(HealthBar.x + HealthBar.w + 2, HealthBar.y + 1));
  3242.     Verts2[2].Init(Vector2D(HealthBar.x + HealthBar.w, HealthBar.y + 2));
  3243.     Verts2[3].Init(Vector2D(HealthBar.x - 2, HealthBar.y + 2));
  3244.  
  3245.     Render::Polygon(4, Verts2, Color(255, 255, 255, 40));
  3246.  
  3247. }
  3248.  
  3249. // Cleans the internal class name up to something human readable and nice
  3250. std::string CleanItemName(std::string name)
  3251. {
  3252.     std::string Name = name;
  3253.     // Tidy up the weapon Name
  3254.     if (Name[0] == 'C')
  3255.         Name.erase(Name.begin());
  3256.  
  3257.     // Remove the word Weapon
  3258.     auto startOfWeap = Name.find("Weapon");
  3259.     if (startOfWeap != std::string::npos)
  3260.                 Name.erase(Name.begin() + startOfWeap, Name.begin() + startOfWeap + 6);
  3261.  
  3262.     return Name;
  3263. }
  3264.  
  3265. // Anything else: weapons, class state? idk
  3266. void CEsp::DrawInfo(IClientEntity* pEntity, CEsp::ESPBox size)
  3267. {
  3268.     std::vector < std::string> Info;
  3269.  
  3270.     // Player Weapon ESP
  3271.     IClientEntity* pWeapon = Interfaces::EntList->GetClientEntityFromHandle((HANDLE)pEntity->GetActiveWeaponHandle());
  3272.     if (Menu::Window.VisualsTab.OptionsWeapon.GetState() && pWeapon)
  3273.     {
  3274.         ClientClass* cClass = (ClientClass*)pWeapon->GetClientClass();
  3275.         if (cClass)
  3276.         {
  3277.             // Draw it
  3278.             Info.push_back(CleanItemName(cClass->m_pNetworkName));
  3279.         }
  3280.     }
  3281.  
  3282.     // Bomb Carrier
  3283.     if (Menu::Window.VisualsTab.OptionsInfo.GetState() && pEntity == BombCarrier)
  3284.     {
  3285.         Info.push_back("Bomb Carrier");
  3286.     }
  3287.  
  3288.     // Comp Rank
  3289.     if (Menu::Window.VisualsTab.OptionsInfo.GetState())
  3290.     {
  3291.         int CompRank = GameUtils::GetPlayerCompRank(pEntity);
  3292.         static const char* Ranks[] =
  3293.         {
  3294.             "",
  3295.             "Silver I",
  3296.             "Silver II",
  3297.             "Silver III",
  3298.             "Silver IV",
  3299.             "Silver Elite",
  3300.             "Silver Elite Master",
  3301.  
  3302.             "Gold Nova I",
  3303.             "Gold Nova II",
  3304.             "Gold Nova III",
  3305.             "Gold Nova Master",
  3306.             "Master Guardian I",
  3307.             "Master Guardian II",
  3308.  
  3309.             "Master Guardian Elite",
  3310.             "Distinguished Master Guardian",
  3311.             "Legendary Eagle",
  3312.             "Legendary Eagle Master",
  3313.             "Supreme Master First Class",
  3314.             "Global Elite"
  3315.         };
  3316.         if (CompRank >= 0 && CompRank <= 18)
  3317.             Info.push_back(Ranks[CompRank]);
  3318.     }
  3319.  
  3320.     static RECT Size = Render::GetTextSize(Render::Fonts::Default, "Hi");
  3321.     int i = 0;
  3322.     for (auto Text : Info)
  3323.     {
  3324.         Render::Text(size.x + size.w + 3, size.y + (i * (Size.bottom + 2)), Color(255, 255, 255, 255), Render::Fonts::ESP, Text.c_str());
  3325.         i++;
  3326.     }
  3327.  
  3328. }
  3329.  
  3330. // Little cross on their heads
  3331. void CEsp::DrawCross(IClientEntity* pEntity)
  3332. {
  3333.     Vector cross = pEntity->GetHeadPos(), screen;
  3334.     static int Scale = 2;
  3335.     if (Render::WorldToScreen(cross, screen))
  3336.     {
  3337.         Render::Clear(screen.x - Scale, screen.y - (Scale * 2), (Scale * 2), (Scale * 4), Color(20, 20, 20, 160));
  3338.         Render::Clear(screen.x - (Scale * 2), screen.y - Scale, (Scale * 4), (Scale * 2), Color(20, 20, 20, 160));
  3339.         Render::Clear(screen.x - Scale - 1, screen.y - (Scale * 2) - 1, (Scale * 2) - 2, (Scale * 4) - 2, Color(250, 250, 250, 160));
  3340.         Render::Clear(screen.x - (Scale * 2) - 1, screen.y - Scale - 1, (Scale * 4) - 2, (Scale * 2) - 2, Color(250, 250, 250, 160));
  3341.     }
  3342. }
  3343.  
  3344. // Draws a dropped CS:GO Item
  3345. void CEsp::DrawDrop(IClientEntity* pEntity, ClientClass* cClass)
  3346. {
  3347.     Vector Box;
  3348.     CBaseCombatWeapon* Weapon = (CBaseCombatWeapon*)pEntity;
  3349.     IClientEntity* plr = Interfaces::EntList->GetClientEntityFromHandle((HANDLE)Weapon->GetOwnerHandle());
  3350.     if (!plr && Render::WorldToScreen(Weapon->GetOrigin(), Box))
  3351.     {
  3352.         if (Menu::Window.VisualsTab.OptionsBox.GetState())
  3353.         {
  3354.             Render::Outline(Box.x - 2, Box.y - 2, 4, 4, Color(255, 255, 255, 255));
  3355.             Render::Outline(Box.x - 3, Box.y - 3, 6, 6, Color(10, 10, 10, 150));
  3356.         }
  3357.  
  3358.         if (Menu::Window.VisualsTab.OptionsInfo.GetState())
  3359.         {
  3360.             std::string ItemName = CleanItemName(cClass->m_pNetworkName);
  3361.             RECT TextSize = Render::GetTextSize(Render::Fonts::ESP, ItemName.c_str());
  3362.             Render::Text(Box.x - (TextSize.right / 2), Box.y - 16, Color(255, 255, 255, 255), Render::Fonts::ESP, ItemName.c_str());
  3363.         }
  3364.     }
  3365. }
  3366.  
  3367. // Draws a chicken
  3368. void CEsp::DrawChicken(IClientEntity* pEntity, ClientClass* cClass)
  3369. {
  3370.     ESPBox Box;
  3371.  
  3372.     if (GetBox(pEntity, Box))
  3373.     {
  3374.         player_info_t pinfo; strcpy_s(pinfo.name, "Chicken");
  3375.         if (Menu::Window.VisualsTab.OptionsBox.GetState())
  3376.             DrawBox(Box, Color(255, 255, 255, 255));
  3377.  
  3378.         if (Menu::Window.VisualsTab.OptionsName.GetState())
  3379.             DrawName(pinfo, Box);
  3380.     }
  3381. }
  3382.  
  3383. // Draw the planted bomb and timer
  3384. void CEsp::DrawBombPlanted(IClientEntity* pEntity, ClientClass* cClass)
  3385. {
  3386.     // Null it out incase bomb has been dropped or planted
  3387.     BombCarrier = nullptr;
  3388.  
  3389.     Vector vOrig; Vector vScreen;
  3390.     vOrig = pEntity->GetOrigin();
  3391.     CCSBomb* Bomb = (CCSBomb*)pEntity;
  3392.  
  3393.     if (Render::WorldToScreen(vOrig, vScreen))
  3394.     {
  3395.         float flBlow = Bomb->GetC4BlowTime();
  3396.         float TimeRemaining = flBlow - (Interfaces::Globals->interval_per_tick * hackManager.pLocal()->GetTickBase());
  3397.         char buffer[64];
  3398.         sprintf_s(buffer, "Bomb: %.1f", TimeRemaining);
  3399.         Render::Text(vScreen.x, vScreen.y, Color(250, 42, 42, 255), Render::Fonts::ESP, buffer);
  3400.     }
  3401. }
  3402.  
  3403. // Draw the bomb if it's dropped, or store the player who's carrying
  3404. void CEsp::DrawBomb(IClientEntity* pEntity, ClientClass* cClass)
  3405. {
  3406.     // Null it out incase bomb has been dropped or planted
  3407.     BombCarrier = nullptr;
  3408.     CBaseCombatWeapon* BombWeapon = (CBaseCombatWeapon*)pEntity;
  3409.     Vector vOrig; Vector vScreen;
  3410.     vOrig = pEntity->GetOrigin();
  3411.     bool adopted = true;
  3412.     HANDLE parent = BombWeapon->GetOwnerHandle();
  3413.     if (parent || (vOrig.x == 0 && vOrig.y == 0 && vOrig.z == 0))
  3414.     {
  3415.         IClientEntity* pParentEnt = (Interfaces::EntList->GetClientEntityFromHandle(parent));
  3416.         if (pParentEnt && pParentEnt->IsAlive())
  3417.         {
  3418.             BombCarrier = pParentEnt;
  3419.             adopted = false;
  3420.         }
  3421.     }
  3422.  
  3423.     if (adopted)
  3424.     {
  3425.         if (Render::WorldToScreen(vOrig, vScreen))
  3426.         {
  3427.             Render::Text(vScreen.x, vScreen.y, Color(112, 230, 20, 255), Render::Fonts::ESP, "Bomb");
  3428.         }
  3429.     }
  3430. }
  3431.  
  3432. void DrawBoneArray(int* boneNumbers, int amount, IClientEntity* pEntity, Color color)
  3433. {
  3434.     Vector LastBoneScreen;
  3435.     for (int i = 0; i < amount; i++)
  3436.     {
  3437.         Vector Bone = pEntity->GetBonePos(boneNumbers[i]);
  3438.         Vector BoneScreen;
  3439.  
  3440.         if (Render::WorldToScreen(Bone, BoneScreen))
  3441.         {
  3442.             if (i > 0)
  3443.             {
  3444.                 Render::Line(LastBoneScreen.x, LastBoneScreen.y, BoneScreen.x, BoneScreen.y, color);
  3445.             }
  3446.         }
  3447.         LastBoneScreen = BoneScreen;
  3448.     }
  3449. }
  3450.  
  3451. void DrawBoneTest(IClientEntity* pEntity)
  3452. {
  3453.     for (int i = 0; i < 127; i++)
  3454.     {
  3455.         Vector BoneLoc = pEntity->GetBonePos(i);
  3456.         Vector BoneScreen;
  3457.         if (Render::WorldToScreen(BoneLoc, BoneScreen))
  3458.         {
  3459.             char buf[10];
  3460.             _itoa_s(i, buf, 10);
  3461.             Render::Text(BoneScreen.x, BoneScreen.y, Color(255, 255, 255, 180), Render::Fonts::ESP, buf);
  3462.         }
  3463.     }
  3464. }
  3465.  
  3466. void CEsp::DrawSkeleton(IClientEntity* pEntity)
  3467. {
  3468.     studiohdr_t* pStudioHdr = Interfaces::ModelInfo->GetStudiomodel(pEntity->GetModel());
  3469.  
  3470.     if (!pStudioHdr)
  3471.         return;
  3472.  
  3473.     Vector vParent, vChild, sParent, sChild;
  3474.  
  3475.     for (int j = 0; j < pStudioHdr->numbones; j++)
  3476.     {
  3477.         mstudiobone_t* pBone = pStudioHdr->GetBone(j);
  3478.  
  3479.         if (pBone && (pBone->flags & BONE_USED_BY_HITBOX) && (pBone->parent != -1))
  3480.         {
  3481.             vChild = pEntity->GetBonePos(j);
  3482.             vParent = pEntity->GetBonePos(pBone->parent);
  3483.  
  3484.             if (Render::WorldToScreen(vParent, sParent) && Render::WorldToScreen(vChild, sChild))
  3485.             {
  3486.                 Render::Line(sParent[0], sParent[1], sChild[0], sChild[1], Color(255, 255, 255, 255));
  3487.             }
  3488.         }
  3489.     }
  3490. }/*
  3491. Syn's AYYWAREFramework 2015
  3492. */
  3493.  
  3494. #pragma once
  3495.  
  3496. #include "Hacks.h"
  3497.  
  3498. class CEsp : public CHack
  3499. {
  3500. public:
  3501.         void Init();
  3502. void Draw();
  3503. void Move(CUserCmd* pCmd);
  3504. private:
  3505.  
  3506.         // Other shit
  3507.         IClientEntity* BombCarrier;
  3508.  
  3509. struct ESPBox
  3510. {
  3511.     int x, y, w, h;
  3512. };
  3513.  
  3514. // Draw a player
  3515. void DrawPlayer(IClientEntity* pEntity, player_info_t pinfo);
  3516.  
  3517. // Get player info
  3518. Color GetPlayerColor(IClientEntity* pEntity);
  3519. bool GetBox(IClientEntity* pEntity, ESPBox &result);
  3520.  
  3521. // Draw shit about player
  3522. void DrawBox(ESPBox size, Color color);
  3523. void DrawName(player_info_t pinfo, ESPBox size);
  3524. void DrawHealth(IClientEntity* pEntity, ESPBox size);
  3525. void DrawInfo(IClientEntity* pEntity, ESPBox size);
  3526. void DrawCross(IClientEntity* pEntity);
  3527. void DrawSkeleton(IClientEntity* pEntity);
  3528.  
  3529. void DrawChicken(IClientEntity* pEntity, ClientClass* cClass);
  3530. void DrawDrop(IClientEntity* pEntity, ClientClass* cClass);
  3531. void DrawBombPlanted(IClientEntity* pEntity, ClientClass* cClass);
  3532. void DrawBomb(IClientEntity* pEntity, ClientClass* cClass);
  3533. };
  3534.  
  3535.  
  3536.  
  3537. #include "GUI.h"
  3538.  
  3539. #include "RenderManager.h"
  3540.  
  3541. #include <algorithm>
  3542. #include "tinyxml2.h"
  3543. #include "Controls.h"
  3544.  
  3545. CGUI GUI;
  3546.  
  3547. CGUI::CGUI()
  3548. {
  3549.  
  3550. }
  3551.  
  3552. // Draws all windows
  3553. void CGUI::Draw()
  3554. {
  3555.     bool ShouldDrawCursor = false;
  3556.  
  3557.     for (auto window : Windows)
  3558.     {
  3559.         if (window->m_bIsOpen)
  3560.         {
  3561.             ShouldDrawCursor = true;
  3562.             DrawWindow(window);
  3563.         }
  3564.  
  3565.     }
  3566.  
  3567.     if (ShouldDrawCursor)
  3568.     {
  3569.         static Vertex_t MouseVt[3];
  3570.  
  3571.         MouseVt[0].Init(Vector2D(Mouse.x, Mouse.y));
  3572.         MouseVt[1].Init(Vector2D(Mouse.x + 16, Mouse.y));
  3573.         MouseVt[2].Init(Vector2D(Mouse.x, Mouse.y + 16));
  3574.  
  3575.         Render::PolygonOutline(3, MouseVt, Color(255, 0, 0, 230), Color(0, 0, 0, 240));
  3576.     }
  3577. }
  3578.  
  3579. // Handle all input etc
  3580. void CGUI::Update()
  3581. {
  3582.     //Key Array
  3583.     std::copy(keys, keys + 255, oldKeys);
  3584.     for (int x = 0; x < 255; x++)
  3585.     {
  3586.         //oldKeys[x] = oldKeys[x] & keys[x];
  3587.         keys[x] = (GetAsyncKeyState(x));
  3588.     }
  3589.  
  3590.     // Mouse Location
  3591.     POINT mp; GetCursorPos(&mp);
  3592.     Mouse.x = mp.x; Mouse.y = mp.y;
  3593.  
  3594.     RECT Screen = Render::GetViewport();
  3595.  
  3596.     // Window Binds
  3597.     for (auto & bind : WindowBinds)
  3598.     {
  3599.         if (GetKeyPress(bind.first))
  3600.         {
  3601.             bind.second->Toggle();
  3602.         }
  3603.     }
  3604.  
  3605.     // Stop dragging
  3606.     if (IsDraggingWindow && !GetKeyState(VK_LBUTTON))
  3607.     {
  3608.         IsDraggingWindow = false;
  3609.         DraggingWindow = nullptr;
  3610.     }
  3611.  
  3612.     // If we are in the proccess of dragging a window
  3613.     if (IsDraggingWindow && GetKeyState(VK_LBUTTON) && !GetKeyPress(VK_LBUTTON))
  3614.     {
  3615.         if (DraggingWindow)
  3616.         {
  3617.             DraggingWindow->m_x = Mouse.x - DragOffsetX;
  3618.             DraggingWindow->m_y = Mouse.y - DragOffsetY;
  3619.         }
  3620.     }
  3621.  
  3622.     // Process some windows
  3623.     for (auto window : Windows)
  3624.     {
  3625.         if (window->m_bIsOpen)
  3626.         {
  3627.             // Used to tell the widget processing that there could be a click
  3628.             bool bCheckWidgetClicks = false;
  3629.  
  3630.             // If the user clicks inside the window
  3631.             if (GetKeyPress(VK_LBUTTON))
  3632.             {
  3633.                 if (IsMouseInRegion(window->m_x, window->m_y, window->m_x + window->m_iWidth, window->m_y + window->m_iHeight))
  3634.                 {
  3635.                     // Is it inside the client area?
  3636.                     if (IsMouseInRegion(window->GetClientArea()))
  3637.                     {
  3638.                         // User is selecting a new tab
  3639.                         if (IsMouseInRegion(window->GetTabArea()))
  3640.                         {
  3641.                             // Loose focus on the control
  3642.                             window->IsFocusingControl = false;
  3643.                             window->FocusedControl = nullptr;
  3644.  
  3645.                             int iTab = 0;
  3646.                             int TabCount = window->Tabs.size();
  3647.                             if (TabCount) // If there are some tabs
  3648.                             {
  3649.                                 int TabSize = (window->m_iWidth - 4 - 12) / TabCount;
  3650.                                 int Dist = Mouse.x - (window->m_x + 8);
  3651.                                 while (Dist > TabSize)
  3652.                                 {
  3653.                                     if (Dist > TabSize)
  3654.                                     {
  3655.                                         iTab++;
  3656.                                         Dist -= TabSize;
  3657.                                     }
  3658.                                 }
  3659.                                 window->SelectedTab = window->Tabs[iTab];
  3660.                             }
  3661.  
  3662.                         }
  3663.                         else
  3664.                             bCheckWidgetClicks = true;
  3665.                     }
  3666.                     else
  3667.                     {
  3668.                         // Must be in the around the title or side of the window
  3669.                         // So we assume the user is trying to drag the window
  3670.                         IsDraggingWindow = true;
  3671.                         DraggingWindow = window;
  3672.                         DragOffsetX = Mouse.x - window->m_x;
  3673.                         DragOffsetY = Mouse.y - window->m_y;
  3674.  
  3675.                         // Loose focus on the control
  3676.                         window->IsFocusingControl = false;
  3677.                         window->FocusedControl = nullptr;
  3678.                     }
  3679.                 }
  3680.                 else
  3681.                 {
  3682.                     // Loose focus on the control
  3683.                     window->IsFocusingControl = false;
  3684.                     window->FocusedControl = nullptr;
  3685.                 }
  3686.             }
  3687.  
  3688.  
  3689.             // Controls
  3690.             if (window->SelectedTab != nullptr)
  3691.             {
  3692.                 // Focused widget
  3693.                 bool SkipWidget = false;
  3694.                 CControl* SkipMe = nullptr;
  3695.  
  3696.                 // this window is focusing on a widget??
  3697.                 if (window->IsFocusingControl)
  3698.                 {
  3699.                     if (window->FocusedControl != nullptr)
  3700.                     {
  3701.                         // We've processed it once, skip it later
  3702.                         SkipWidget = true;
  3703.                         SkipMe = window->FocusedControl;
  3704.  
  3705.                         POINT cAbs = window->FocusedControl->GetAbsolutePos();
  3706.                         RECT controlRect = { cAbs.x, cAbs.y, window->FocusedControl->m_iWidth, window->FocusedControl->m_iHeight };
  3707.                         window->FocusedControl->OnUpdate();
  3708.  
  3709.                         if (window->FocusedControl->Flag(UIFlags::UI_Clickable) && IsMouseInRegion(controlRect) && bCheckWidgetClicks)
  3710.                         {
  3711.                             window->FocusedControl->OnClick();
  3712.  
  3713.                             // If it gets clicked we loose focus
  3714.                             window->IsFocusingControl = false;
  3715.                             window->FocusedControl = nullptr;
  3716.                             bCheckWidgetClicks = false;
  3717.                         }
  3718.                     }
  3719.                 }
  3720.  
  3721.                 // Itterate over the rest of the control
  3722.                 for (auto control : window->SelectedTab->Controls)
  3723.                 {
  3724.                     if (control != nullptr)
  3725.                     {
  3726.                         if (SkipWidget && SkipMe == control)
  3727.                             continue;
  3728.  
  3729.                         POINT cAbs = control->GetAbsolutePos();
  3730.                         RECT controlRect = { cAbs.x, cAbs.y, control->m_iWidth, control->m_iHeight };
  3731.                         control->OnUpdate();
  3732.  
  3733.                         if (control->Flag(UIFlags::UI_Clickable) && IsMouseInRegion(controlRect) && bCheckWidgetClicks)
  3734.                         {
  3735.                             control->OnClick();
  3736.                             bCheckWidgetClicks = false;
  3737.  
  3738.                             // Change of focus
  3739.                             if (control->Flag(UIFlags::UI_Focusable))
  3740.                             {
  3741.                                 window->IsFocusingControl = true;
  3742.                                 window->FocusedControl = control;
  3743.                             }
  3744.                             else
  3745.                             {
  3746.                                 window->IsFocusingControl = false;
  3747.                                 window->FocusedControl = nullptr;
  3748.                             }
  3749.  
  3750.                         }
  3751.                     }
  3752.                 }
  3753.  
  3754.                 // We must have clicked whitespace
  3755.                 if (bCheckWidgetClicks)
  3756.                 {
  3757.                     // Loose focus on the control
  3758.                     window->IsFocusingControl = false;
  3759.                     window->FocusedControl = nullptr;
  3760.                 }
  3761.             }
  3762.         }
  3763.     }
  3764. }
  3765.  
  3766. // Returns
  3767. bool CGUI::GetKeyPress(unsigned int key)
  3768. {
  3769.     if (keys[key] == true && oldKeys[key] == false)
  3770.         return true;
  3771.     else
  3772.         return false;
  3773. }
  3774.  
  3775. bool CGUI::GetKeyState(unsigned int key)
  3776. {
  3777.     return keys[key];
  3778. }
  3779.  
  3780. bool CGUI::IsMouseInRegion(int x, int y, int x2, int y2)
  3781. {
  3782.     if (Mouse.x > x && Mouse.y > y && Mouse.x < x2 && Mouse.y < y2)
  3783.         return true;
  3784.     else
  3785.         return false;
  3786. }
  3787.  
  3788. bool CGUI::IsMouseInRegion(RECT region)
  3789. {
  3790.     return IsMouseInRegion(region.left, region.top, region.left + region.right, region.top + region.bottom);
  3791. }
  3792.  
  3793. POINT CGUI::GetMouse()
  3794. {
  3795.     return Mouse;
  3796. }
  3797.  
  3798. bool CGUI::DrawWindow(CWindow* window)
  3799. {
  3800.     // Main Window
  3801.     Render::Outline(window->m_x, window->m_y, window->m_iWidth, window->m_iHeight, Color(20, 20, 20, 80));
  3802.     Render::GradientV(window->m_x + 2, window->m_y + 2, window->m_iWidth - 4, 26, Color(0, 0, 0, 255), Color(0, 0, 0, 255));
  3803.     Render::Clear(window->m_x + 2, window->m_y + 2 + 26, window->m_iWidth - 4, window->m_iHeight - 4 - 26, Color(0, 0, 0, 255));
  3804.     Render::Outline(window->m_x + 1, window->m_y + 1, window->m_iWidth - 2, window->m_iHeight - 2, Color(255, 0, 0, 255));
  3805.     Render::Text(window->m_x + 8, window->m_y + 8, Color(255, 255, 255, 255), Render::Fonts::MenuBold, window->Title.c_str());
  3806.  
  3807.     //Inner
  3808.     Render::Outline(window->m_x + 7, window->m_y + 1 + 26, window->m_iWidth - 4 - 10, window->m_iHeight - 2 - 6 - 26, Color(255, 0, 0, 255));
  3809.     Render::Clear(window->m_x + 8, window->m_y + 1 + 27, window->m_iWidth - 4 - 12, window->m_iHeight - 2 - 8 - 26, Color(255, 255, 255, 255));
  3810.  
  3811.     //Tab
  3812.     Render::GradientV(window->m_x + 8, window->m_y + 1 + 27, window->m_iWidth - 4 - 12, 29, Color(52, 52, 52, 255), Color(6, 6, 6, 255));
  3813.     int TabCount = window->Tabs.size();
  3814.     if (TabCount) // If there are some tabs
  3815.     {
  3816.         int TabSize = (window->m_iWidth - 4 - 12) / TabCount;
  3817.         for (int i = 0; i < TabCount; i++)
  3818.         {
  3819.             RECT TabArea = { window->m_x + 8 + (i * TabSize), window->m_y + 1 + 27, TabSize, 29 };
  3820.             CTab* tab = window->Tabs[i];
  3821.             if (window->SelectedTab == tab)
  3822.             {
  3823.                 Render::GradientV(window->m_x + 8 + (i * TabSize), window->m_y + 1 + 27, TabSize, 29, Color(52, 52, 52, 255), Color(106, 106, 106, 255));
  3824.             }
  3825.             else if (IsMouseInRegion(TabArea))
  3826.             {
  3827.                 Render::GradientV(window->m_x + 8 + (i * TabSize), window->m_y + 1 + 27, TabSize, 29, Color(106, 106, 106, 255), Color(52, 52, 52, 255));
  3828.             }
  3829.             RECT TextSize = Render::GetTextSize(Render::Fonts::MenuBold, tab->Title.c_str());
  3830.             Render::Text(TabArea.left + (TabSize / 2) - (TextSize.right / 2), TabArea.top + 8, Color(255, 255, 255, 255), Render::Fonts::MenuBold, tab->Title.c_str());
  3831.             Render::Clear(window->m_x + 8, window->m_y + 1 + 27, window->m_iWidth - 4 - 12, 2, Color(66, 66, 66, 255));
  3832.         }
  3833.     }
  3834.  
  3835.  
  3836.     // Controls
  3837.     if (window->SelectedTab != nullptr)
  3838.     {
  3839.         // Focused widget
  3840.         bool SkipWidget = false;
  3841.         CControl* SkipMe = nullptr;
  3842.  
  3843.         // this window is focusing on a widget??
  3844.         if (window->IsFocusingControl)
  3845.         {
  3846.             if (window->FocusedControl != nullptr)
  3847.             {
  3848.                 // We need to draw it last, so skip it in the regular loop
  3849.                 SkipWidget = true;
  3850.                 SkipMe = window->FocusedControl;
  3851.             }
  3852.         }
  3853.  
  3854.  
  3855.         // Itterate over all the other controls
  3856.         for (auto control : window->SelectedTab->Controls)
  3857.         {
  3858.             if (SkipWidget && SkipMe == control)
  3859.                 continue;
  3860.  
  3861.             if (control != nullptr && control->Flag(UIFlags::UI_Drawable))
  3862.             {
  3863.                 POINT cAbs = control->GetAbsolutePos();
  3864.                 RECT controlRect = { cAbs.x, cAbs.y, control->m_iWidth, control->m_iHeight };
  3865.                 bool hover = false;
  3866.                 if (IsMouseInRegion(controlRect))
  3867.                 {
  3868.                     hover = true;
  3869.                 }
  3870.                 control->Draw(hover);
  3871.             }
  3872.         }
  3873.  
  3874.         // Draw the skipped widget last
  3875.         if (SkipWidget)
  3876.         {
  3877.             auto control = window->FocusedControl;
  3878.  
  3879.             if (control != nullptr && control->Flag(UIFlags::UI_Drawable))
  3880.             {
  3881.                 POINT cAbs = control->GetAbsolutePos();
  3882.                 RECT controlRect = { cAbs.x, cAbs.y, control->m_iWidth, control->m_iHeight };
  3883.                 bool hover = false;
  3884.                 if (IsMouseInRegion(controlRect))
  3885.                 {
  3886.                     hover = true;
  3887.                 }
  3888.                 control->Draw(hover);
  3889.             }
  3890.         }
  3891.  
  3892.     }
  3893.  
  3894.  
  3895.     return true;
  3896. }
  3897.  
  3898. void CGUI::RegisterWindow(CWindow* window)
  3899. {
  3900.     Windows.push_back(window);
  3901.  
  3902.     // Resorting to put groupboxes at the start
  3903.     for (auto tab : window->Tabs)
  3904.     {
  3905.         for (auto control : tab->Controls)
  3906.         {
  3907.             if (control->Flag(UIFlags::UI_RenderFirst))
  3908.             {
  3909.                 CControl* c = control;
  3910.                 tab->Controls.erase(std::remove(tab->Controls.begin(), tab->Controls.end(), control), tab->Controls.end());
  3911.                 tab->Controls.insert(tab->Controls.begin(), control);
  3912.             }
  3913.         }
  3914.     }
  3915. }
  3916.  
  3917. void CGUI::BindWindow(unsigned char Key, CWindow* window)
  3918. {
  3919.     if (window)
  3920.         WindowBinds[Key] = window;
  3921.     else
  3922.         WindowBinds.erase(Key);
  3923. }
  3924.  
  3925. void CGUI::SaveWindowState(CWindow* window, std::string Filename)
  3926. {
  3927.     // Create a whole new document and we'll just save over top of the old one
  3928.     tinyxml2::XMLDocument Doc;
  3929.  
  3930.     // Root Element is called "ayy"
  3931.     tinyxml2::XMLElement* Root = Doc.NewElement("ayy");
  3932.     Doc.LinkEndChild(Root);
  3933.  
  3934.     Utilities::Log("Saving Window %s", window->Title.c_str());
  3935.  
  3936.     // If the window has some tabs..
  3937.     if (Root && window->Tabs.size() > 0)
  3938.     {
  3939.         for (auto Tab : window->Tabs)
  3940.         {
  3941.             // Add a new section for this tab
  3942.             tinyxml2::XMLElement* TabElement = Doc.NewElement(Tab->Title.c_str());
  3943.             Root->LinkEndChild(TabElement);
  3944.  
  3945.             Utilities::Log("Saving Tab %s", Tab->Title.c_str());
  3946.  
  3947.             // Now we itterate the controls this tab contains
  3948.             if (TabElement && Tab->Controls.size() > 0)
  3949.             {
  3950.                 for (auto Control : Tab->Controls)
  3951.                 {
  3952.                     // If the control is ok to be saved
  3953.                     if (Control && Control->Flag(UIFlags::UI_SaveFile) && Control->FileIdentifier.length() > 1 && Control->FileControlType)
  3954.                     {
  3955.                         // Create an element for the control
  3956.                         tinyxml2::XMLElement* ControlElement = Doc.NewElement(Control->FileIdentifier.c_str());
  3957.                         TabElement->LinkEndChild(ControlElement);
  3958.  
  3959.                         Utilities::Log("Saving control %s", Control->FileIdentifier.c_str());
  3960.  
  3961.                         if (!ControlElement)
  3962.                         {
  3963.                             Utilities::Log("Errorino :(");
  3964.                             return;
  3965.                         }
  3966.  
  3967.                         CCheckBox* cbx = nullptr;
  3968.                         CComboBox* cbo = nullptr;
  3969.                         CKeyBind* key = nullptr;
  3970.                         CSlider* sld = nullptr;
  3971.  
  3972.                         // Figure out what kind of control and data this is
  3973.                         switch (Control->FileControlType)
  3974.                         {
  3975.                             case UIControlTypes::UIC_CheckBox:
  3976.                                 cbx = (CCheckBox*)Control;
  3977.                                 ControlElement->SetText(cbx->GetState());
  3978.                                 break;
  3979.                             case UIControlTypes::UIC_ComboBox:
  3980.                                 cbo = (CComboBox*)Control;
  3981.                                 ControlElement->SetText(cbo->GetIndex());
  3982.                                 break;
  3983.                             case UIControlTypes::UIC_KeyBind:
  3984.                                 key = (CKeyBind*)Control;
  3985.                                 ControlElement->SetText(key->GetKey());
  3986.                                 break;
  3987.                             case UIControlTypes::UIC_Slider:
  3988.                                 sld = (CSlider*)Control;
  3989.                                 ControlElement->SetText(sld->GetValue());
  3990.                                 break;
  3991.                         }
  3992.                     }
  3993.                 }
  3994.             }
  3995.         }
  3996.     }
  3997.  
  3998.     //Save the file
  3999.     if (Doc.SaveFile(Filename.c_str()) != tinyxml2::XML_NO_ERROR)
  4000.     {
  4001.         MessageBox(NULL, "Failed To Save Config File!", "AyyWare", MB_OK);
  4002.     }
  4003.  
  4004. }
  4005.  
  4006. void CGUI::LoadWindowState(CWindow* window, std::string Filename)
  4007. {
  4008.     // Lets load our meme
  4009.     tinyxml2::XMLDocument Doc;
  4010.     if (Doc.LoadFile(Filename.c_str()) == tinyxml2::XML_NO_ERROR)
  4011.     {
  4012.         tinyxml2::XMLElement* Root = Doc.RootElement();
  4013.  
  4014.         // The root "ayy" element
  4015.         if (Root)
  4016.         {
  4017.             // If the window has some tabs..
  4018.             if (Root && window->Tabs.size() > 0)
  4019.             {
  4020.                 for (auto Tab : window->Tabs)
  4021.                 {
  4022.                     // We find the corresponding element for this tab
  4023.                     tinyxml2::XMLElement* TabElement = Root->FirstChildElement(Tab->Title.c_str());
  4024.                     if (TabElement)
  4025.                     {
  4026.                         // Now we itterate the controls this tab contains
  4027.                         if (TabElement && Tab->Controls.size() > 0)
  4028.                         {
  4029.                             for (auto Control : Tab->Controls)
  4030.                             {
  4031.                                 // If the control is ok to be saved
  4032.                                 if (Control && Control->Flag(UIFlags::UI_SaveFile) && Control->FileIdentifier.length() > 1 && Control->FileControlType)
  4033.                                 {
  4034.                                     // Get the controls element
  4035.                                     tinyxml2::XMLElement* ControlElement = TabElement->FirstChildElement(Control->FileIdentifier.c_str());
  4036.  
  4037.                                     if (ControlElement)
  4038.                                     {
  4039.                                         Utilities::Log("We tryin to load fam");
  4040.                                         CCheckBox* cbx = nullptr;
  4041.                                         CComboBox* cbo = nullptr;
  4042.                                         CKeyBind* key = nullptr;
  4043.                                         CSlider* sld = nullptr;
  4044.  
  4045.                                         // Figure out what kind of control and data this is
  4046.                                         switch (Control->FileControlType)
  4047.                                         {
  4048.                                             case UIControlTypes::UIC_CheckBox:
  4049.                                                 cbx = (CCheckBox*)Control;
  4050.                                                 cbx->SetState(ControlElement->GetText()[0] == '1' ? true : false);
  4051.                                                 break;
  4052.                                             case UIControlTypes::UIC_ComboBox:
  4053.                                                 cbo = (CComboBox*)Control;
  4054.                                                 cbo->SelectIndex(atoi(ControlElement->GetText()));
  4055.                                                 break;
  4056.                                             case UIControlTypes::UIC_KeyBind:
  4057.                                                 key = (CKeyBind*)Control;
  4058.                                                 key->SetKey(atoi(ControlElement->GetText()));
  4059.                                                 break;
  4060.                                             case UIControlTypes::UIC_Slider:
  4061.                                                 sld = (CSlider*)Control;
  4062.                                                 sld->SetValue(atof(ControlElement->GetText()));
  4063.                                                 break;
  4064.                                         }
  4065.                                     }
  4066.                                 }
  4067.                             }
  4068.                         }
  4069.                     }
  4070.                 }
  4071.             }
  4072.         }
  4073.     }
  4074. }/*
  4075. Syn's AYYWAREFramework 2015
  4076. */
  4077.  
  4078. #pragma once
  4079.  
  4080. #include "CommonIncludes.h"
  4081.  
  4082. #include <map>
  4083.  
  4084. class CControl;
  4085. class CTab;
  4086. class CWindow;
  4087. class CGUI;
  4088.  
  4089. extern CGUI GUI;
  4090.  
  4091. enum UIFlags
  4092. {
  4093.     UI_None = 0x00,
  4094.     UI_Drawable = 0x01,
  4095.     UI_Clickable = 0x02,
  4096.     UI_Focusable = 0x04,
  4097.     UI_RenderFirst = 0x08,
  4098.     UI_SaveFile = 0x10
  4099. };
  4100.  
  4101. enum UIControlTypes
  4102. {
  4103.     UIC_CheckBox = 1,
  4104.     UIC_Slider,
  4105.     UIC_KeyBind,
  4106.     UIC_ComboBox
  4107. };
  4108.  
  4109. // Base class for GUI controls
  4110. class CControl
  4111. {
  4112.     friend class CGUI;
  4113.     friend class CTab;
  4114.     friend class CWindow;
  4115.     public:
  4116.         void SetPosition(int x, int y);
  4117.     void SetSize(int w, int h);
  4118.     void GetSize(int &w, int &h);
  4119.     void SetFileId(std::string fid);
  4120.  
  4121.     bool Flag(int f);
  4122.     protected:
  4123.         int m_x, m_y;
  4124.     int m_iWidth, m_iHeight;
  4125.     int m_Flags;
  4126.     CWindow* parent;
  4127.  
  4128.     std::string FileIdentifier;
  4129.     int FileControlType;
  4130.  
  4131.     virtual void Draw(bool) = 0;
  4132.         virtual void OnUpdate() = 0;
  4133.         virtual void OnClick() = 0;
  4134.  
  4135.         POINT GetAbsolutePos();
  4136. };
  4137.  
  4138. // A GUI Control Container
  4139. class CTab
  4140. {
  4141.     friend class CControl;
  4142.     friend class CGUI;
  4143.     friend class CWindow;
  4144.     public:
  4145.         void SetTitle(std::string name);
  4146.     void RegisterControl(CControl* control);
  4147.     private:
  4148.         std::string Title;
  4149.     std::vector<CControl*> Controls;
  4150.     CWindow* parent;
  4151. };
  4152.  
  4153. // Base class for a simple GUI window
  4154. class CWindow
  4155. {
  4156.     friend class CControl;
  4157.     friend class CGUI;
  4158.     public:
  4159.         void SetPosition(int x, int y);
  4160.     void SetSize(int w, int h);
  4161.     void SetTitle(std::string title);
  4162.     void Open();
  4163.     void Close();
  4164.     void Toggle();
  4165.     CControl* GetFocus();
  4166.  
  4167.     void RegisterTab(CTab* Tab);
  4168.  
  4169.     RECT GetClientArea();
  4170.     RECT GetTabArea();
  4171.  
  4172.     private:
  4173.         void DrawControls();
  4174.  
  4175.     bool m_bIsOpen;
  4176.  
  4177.     std::vector<CTab*> Tabs;
  4178.     CTab* SelectedTab;
  4179.  
  4180.     bool IsFocusingControl;
  4181.     CControl* FocusedControl;
  4182.  
  4183.     std::string Title;
  4184.     int m_x;
  4185.     int m_y;
  4186.     int m_iWidth;
  4187.     int m_iHeight;
  4188.  
  4189. };
  4190.  
  4191. // User interface manager
  4192. class CGUI
  4193. {
  4194.     public:
  4195.         CGUI();
  4196.  
  4197.     // Draws all windows
  4198.     void Draw();
  4199.  
  4200.     // Handle all input etc
  4201.     void Update();
  4202.  
  4203.     // Draws a single window
  4204.     bool DrawWindow(CWindow* window);
  4205.  
  4206.     // Registers a window
  4207.     void RegisterWindow(CWindow* window);
  4208.  
  4209.     // Config saving/loading
  4210.     void SaveWindowState(CWindow* window, std::string Filename);
  4211.     void LoadWindowState(CWindow* window, std::string Filename);
  4212.  
  4213.     // Window Binds
  4214.     void BindWindow(unsigned char Key, CWindow* window);
  4215.  
  4216.     // Input
  4217.     bool GetKeyPress(unsigned int key);
  4218.     bool GetKeyState(unsigned int key);
  4219.     bool IsMouseInRegion(int x, int y, int x2, int y2);
  4220.     bool IsMouseInRegion(RECT region);
  4221.     POINT GetMouse();
  4222.  
  4223.     private:
  4224.         // Input
  4225.         // keyboard
  4226.         bool keys[256];
  4227.     bool oldKeys[256];
  4228.     // Mouse
  4229.     POINT Mouse;
  4230.     bool MenuOpen;
  4231.  
  4232.     // Window Dragging
  4233.     bool IsDraggingWindow;
  4234.     CWindow* DraggingWindow;
  4235.     int DragOffsetX; int DragOffsetY;
  4236.  
  4237.     // Windows
  4238.     std::vector<CWindow*> Windows;
  4239.  
  4240.     // KeyBinds -> Windows Map
  4241.     std::map<int, CWindow*> WindowBinds;
  4242.  
  4243. };/*
  4244. Syn's Payhake Framework for Insanity & Razor
  4245. */
  4246.  
  4247. #include "Hacks.h"
  4248. #include "Interfaces.h"
  4249. #include "RenderManager.h"
  4250.  
  4251. #include "ESP.h"
  4252. #include "Visuals.h"
  4253. #include "RageBot.h"
  4254. #include "MiscHacks.h"
  4255. #include "LegitBot.h"
  4256.  
  4257. CEsp Esp;
  4258. CVisuals Visuals;
  4259. CMiscHacks MiscHacks;
  4260. CRageBot RageBot;
  4261. CLegitBot LegitBot;
  4262.  
  4263. // Initialise and register ALL hackmanager hacks in here nigga
  4264. void Hacks::SetupHacks()
  4265. {
  4266.     Esp.Init();
  4267.     Visuals.Init();
  4268.     MiscHacks.Init();
  4269.     RageBot.Init();
  4270.     LegitBot.Init();
  4271.  
  4272.     hackManager.RegisterHack(&Esp);
  4273.     hackManager.RegisterHack(&Visuals);
  4274.     hackManager.RegisterHack(&MiscHacks);
  4275.     hackManager.RegisterHack(&RageBot);
  4276.     hackManager.RegisterHack(&LegitBot);
  4277.  
  4278.     //--------------------------------
  4279.     hackManager.Ready();
  4280. }
  4281.  
  4282. void SpecList()
  4283. {
  4284.     IClientEntity* pLocal = hackManager.pLocal();
  4285.  
  4286.     RECT scrn = Render::GetViewport();
  4287.     int ayy = 0;
  4288.  
  4289.     // Loop through all active entitys
  4290.     for (int i = 0; i < Interfaces::EntList->GetHighestEntityIndex(); i++)
  4291.     {
  4292.         // Get the entity
  4293.         IClientEntity* pEntity = Interfaces::EntList->GetClientEntity(i);
  4294.         player_info_t pinfo;
  4295.  
  4296.         // The entity isn't some laggy peice of shit or something
  4297.         if (pEntity && pEntity != pLocal)
  4298.         {
  4299.             if (Interfaces::Engine->GetPlayerInfo(i, &pinfo) && !pEntity->IsAlive() && !pEntity->IsDormant())
  4300.             {
  4301.                 HANDLE obs = pEntity->GetObserverTargetHandle();
  4302.  
  4303.                 if (obs)
  4304.                 {
  4305.                     IClientEntity* pTarget = Interfaces::EntList->GetClientEntityFromHandle(obs);
  4306.                     player_info_t pinfo2;
  4307.                     if (pTarget)
  4308.                     {
  4309.                         if (Interfaces::Engine->GetPlayerInfo(pTarget->GetIndex(), &pinfo2))
  4310.                         {
  4311.                             char buf[255]; sprintf_s(buf, "%s => %s", pinfo.name, pinfo2.name);
  4312.                             RECT TextSize = Render::GetTextSize(Render::Fonts::ESP, buf);
  4313.                             Render::Clear(scrn.right - 260, (scrn.bottom / 2) + (16 * ayy), 260, 16, Color(0, 0, 0, 140));
  4314.                             Render::Text(scrn.right - TextSize.right - 4, (scrn.bottom / 2) + (16 * ayy), pTarget->GetIndex() == pLocal->GetIndex() ? Color(240, 70, 80, 255) : Color(255, 255, 255, 255), Render::Fonts::ESP, buf);
  4315.                             ayy++;
  4316.                         }
  4317.                     }
  4318.                 }
  4319.             }
  4320.         }
  4321.     }
  4322.  
  4323.     Render::Outline(scrn.right - 261, (scrn.bottom / 2) - 1, 262, (16 * ayy) + 2, Color(23, 23, 23, 255));
  4324.     Render::Outline(scrn.right - 260, (scrn.bottom / 2), 260, (16 * ayy), Color(90, 90, 90, 255));
  4325. }
  4326.  
  4327. // Only gets called in game, use a seperate draw UI call for menus in the hook
  4328. void Hacks::DrawHacks()
  4329. {
  4330.     // Spectator List
  4331.     if (Menu::Window.VisualsTab.OtherSpectators.GetState())
  4332.         SpecList();
  4333.  
  4334.     // Check the master visuals switch, just to be sure
  4335.     if (!Menu::Window.VisualsTab.Active.GetState())
  4336.         return;
  4337.  
  4338.     hackManager.Draw();
  4339.     //--------------------------------
  4340.  
  4341. }
  4342.  
  4343. // Game Cmd Changes
  4344. void Hacks::MoveHacks(CUserCmd* pCmd)
  4345. {
  4346.     Vector origView = pCmd->viewangles;
  4347.     hackManager.Move(pCmd);
  4348.     // ------------------------------
  4349.  
  4350.     // Put it in here so it's applied AFTER the aimbot
  4351.     int AirStuckKey = Menu::Window.VisualsTab.OtherAirStuck.GetKey();
  4352.     if (AirStuckKey > 0 && GUI.GetKeyState(AirStuckKey))
  4353.     {
  4354.         if (!(pCmd->buttons & IN_ATTACK))
  4355.             pCmd->tick_count = 0xFFFFF;
  4356.     }
  4357. }
  4358.  
  4359. //---------------------------------------------------------------------//
  4360. HackManager hackManager;
  4361.  
  4362. // Register a new hack
  4363. void HackManager::RegisterHack(CHack* hake)
  4364. {
  4365.     Hacks.push_back(hake);
  4366.     hake->Init();
  4367. }
  4368.  
  4369. // Draw all the hakes
  4370. void HackManager::Draw()
  4371. {
  4372.     if (!IsReady)
  4373.         return;
  4374.  
  4375.     // Grab the local player for drawing related hacks
  4376.     pLocalInstance = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  4377.     if (!pLocalInstance) return;
  4378.  
  4379.     for (auto & hack : Hacks)
  4380.     {
  4381.         hack->Draw();
  4382.     }
  4383. }
  4384.  
  4385. // Handle all the move hakes
  4386. void HackManager::Move(CUserCmd* pCmd)
  4387. {
  4388.     if (!IsReady)
  4389.         return;
  4390.  
  4391.     // Grab the local player for move related hacks
  4392.     pLocalInstance = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  4393.     if (!pLocalInstance) return;
  4394.  
  4395.     for (auto & hack : Hacks)
  4396.     {
  4397.         hack->Move(pCmd);
  4398.     }
  4399. }
  4400.  
  4401. //---------------------------------------------------------------------//
  4402. // Other Utils and shit
  4403.  
  4404. // Saves hacks needing to call a bunch of virtuals to get the instance
  4405. // Saves on cycles and file size. Recycle your plastic kids
  4406. IClientEntity* HackManager::pLocal()
  4407. {
  4408.     return pLocalInstance;
  4409. }
  4410.  
  4411. // Makes sure none of the hacks are called in their
  4412. // hooks until they are completely ready for use
  4413. void HackManager::Ready()
  4414. {
  4415.     IsReady = true;
  4416. }
  4417. #pragma once
  4418.  
  4419. #pragma once
  4420.  
  4421. # include "SDK.h"
  4422. # include "Menu.h"
  4423. # include <vector>
  4424.  
  4425. namespace Hacks
  4426. {
  4427.     void SetupHacks();
  4428.     void DrawHacks();
  4429.     void MoveHacks(CUserCmd* pCmd);
  4430. }
  4431.  
  4432. class CHack
  4433. {
  4434.     public:
  4435.         virtual void Draw() = 0;
  4436.         virtual void Move(CUserCmd* pCmd) = 0;
  4437.         virtual void Init() = 0;
  4438. };
  4439.  
  4440. class HackManager
  4441. {
  4442.     public:
  4443.         void RegisterHack(CHack* hake);
  4444.     void Ready();
  4445.  
  4446.     void Draw();
  4447.     void Move(CUserCmd* pCmd);
  4448.     IClientEntity* pLocal();
  4449.     private:
  4450.         std::vector<CHack*> Hacks;
  4451.     IClientEntity* pLocalInstance;
  4452.     bool IsReady;
  4453. };
  4454.  
  4455. extern HackManager hackManager;
  4456.     /*
  4457. Syn's AYYWAREFramework 2015
  4458. */
  4459.  
  4460. #include "Hooks.h"
  4461. #include "Hacks.h"
  4462. #include "Chams.h"
  4463. #include "Menu.h"
  4464.  
  4465. #include "Interfaces.h"
  4466. #include "RenderManager.h"
  4467. #include "MiscHacks.h"
  4468.  
  4469. // Funtion Typedefs
  4470. typedef void(__thiscall* DrawModelEx_)(void*, void*, void*, const ModelRenderInfo_t&, matrix3x4*);
  4471. typedef void(__thiscall* PaintTraverse_)(PVOID, unsigned int, bool, bool);
  4472. typedef bool(__thiscall* InPrediction_)(PVOID);
  4473. typedef void(__stdcall* FrameStageNotifyFn)(ClientFrameStage_t);
  4474.  
  4475. // Function Pointers to the originals
  4476. PaintTraverse_ oPaintTraverse;
  4477. DrawModelEx_ oDrawModelExecute;
  4478. FrameStageNotifyFn oFrameStageNotify;
  4479.  
  4480. // Hook function prototypes
  4481. void __fastcall PaintTraverse_Hooked(PVOID pPanels, int edx, unsigned int vguiPanel, bool forceRepaint, bool allowForce);
  4482. bool __stdcall Hooked_InPrediction();
  4483. void __fastcall Hooked_DrawModelExecute(void* thisptr, int edx, void* ctx, void* state, const ModelRenderInfo_t &pInfo, matrix3x4* pCustomBoneToWorld);
  4484. bool __fastcall CreateMoveClient_Hooked(void* self, int edx, float frametime, CUserCmd* pCmd);
  4485. void __stdcall Hooked_FrameStageNotify(ClientFrameStage_t curStage);
  4486.  
  4487. // VMT Managers
  4488. namespace Hooks
  4489. {
  4490.     // VMT Managers
  4491.     Utilities::Memory::VMTManager VMTPanel; // Hooking drawing functions
  4492.     Utilities::Memory::VMTManager VMTClient; // Maybe CreateMove
  4493.     Utilities::Memory::VMTManager VMTClientMode; // CreateMove for functionality
  4494.     Utilities::Memory::VMTManager VMTModelRender; // DrawModelEx for chams
  4495.     Utilities::Memory::VMTManager VMTPrediction; // InPrediction for no vis recoil
  4496. };
  4497.  
  4498. // Initialise all our hooks
  4499. void Hooks::Initialise()
  4500. {
  4501.     // Panel hooks for drawing to the screen via surface functions
  4502.     VMTPanel.Initialise((DWORD*)Interfaces::Panels);
  4503.     oPaintTraverse = (PaintTraverse_)VMTPanel.HookMethod((DWORD) & PaintTraverse_Hooked, Offsets::VMT::Panel_PaintTraverse);
  4504.     Utilities::Log("Paint Traverse Hooked");
  4505.  
  4506.     // No Visual Recoil
  4507.     VMTPrediction.Initialise((DWORD*)Interfaces::Prediction);
  4508.     VMTPrediction.HookMethod((DWORD) & Hooked_InPrediction, 14);
  4509.     Utilities::Log("InPrediction Hooked");
  4510.  
  4511.     // Chams
  4512.     VMTModelRender.Initialise((DWORD*)Interfaces::ModelRender);
  4513.     oDrawModelExecute = (DrawModelEx_)VMTModelRender.HookMethod((DWORD) & Hooked_DrawModelExecute, Offsets::VMT::ModelRender_DrawModelExecute);
  4514.     Utilities::Log("DrawModelExecute Hooked");
  4515.  
  4516.     // Setup ClientMode Hooks
  4517.     VMTClientMode.Initialise((DWORD*)Interfaces::ClientMode);
  4518.     VMTClientMode.HookMethod((DWORD) & CreateMoveClient_Hooked, 24);
  4519.     //oFrameStageNotify = (FrameStageNotifyFn)VMTClientMode.HookMethod((DWORD)Hooked_FrameStageNotify, 36);
  4520.     Utilities::Log("CreateMove");
  4521.  
  4522.     // Setup client hooks
  4523.     VMTClient.Initialise((DWORD*)Interfaces::Client);
  4524.     oFrameStageNotify = (FrameStageNotifyFn)VMTClient.HookMethod((DWORD) & Hooked_FrameStageNotify, 36);
  4525.     Utilities::Log("FrameStage Hey whats up hello?");
  4526. }
  4527.  
  4528. // Undo our hooks
  4529. void Hooks::UndoHooks()
  4530. {
  4531.     VMTPanel.RestoreOriginal();
  4532.     VMTPrediction.RestoreOriginal();
  4533.     VMTModelRender.RestoreOriginal();
  4534.     VMTClientMode.RestoreOriginal();
  4535.     VMTClient.RestoreOriginal();
  4536. }
  4537.  
  4538. void MovementCorrection(CUserCmd* pCmd)
  4539. {
  4540.  
  4541. }
  4542.  
  4543. //---------------------------------------------------------------------------------------------------------
  4544. //                                         Hooked Functions
  4545. //---------------------------------------------------------------------------------------------------------
  4546.  
  4547. // Paint Traverse Hooked function
  4548. void __fastcall PaintTraverse_Hooked(PVOID pPanels, int edx, unsigned int vguiPanel, bool forceRepaint, bool allowForce)
  4549. {
  4550.     oPaintTraverse(pPanels, vguiPanel, forceRepaint, allowForce);
  4551.  
  4552.     static unsigned int FocusOverlayPanel = 0;
  4553.     static bool FoundPanel = false;
  4554.  
  4555.     if (!FoundPanel)
  4556.     {
  4557.         PCHAR szPanelName = (PCHAR)Interfaces::Panels->GetName(vguiPanel);
  4558.         if (strstr(szPanelName, "MatSystemTopPanel"))
  4559.         {
  4560.             FocusOverlayPanel = vguiPanel;
  4561.             FoundPanel = true;
  4562.         }
  4563.     }
  4564.     else if (FocusOverlayPanel == vguiPanel)
  4565.     {
  4566.  
  4567.         Render::Text(10, 10, Color(255, 255, 255, 220), Render::Fonts::Menu, "AYYWARE New Meme of 2015 Fixed By UnnAmE1337");
  4568.         if (Interfaces::Engine->IsConnected() && Interfaces::Engine->IsInGame())
  4569.             Hacks::DrawHacks();
  4570.  
  4571.         // Update and draw the menu
  4572.         Menu::DoUIFrame();
  4573.     }
  4574. }
  4575.  
  4576. // InPrediction Hooked Function
  4577. bool __stdcall Hooked_InPrediction()
  4578. {
  4579.     bool result;
  4580.     static InPrediction_ origFunc = (InPrediction_)Hooks::VMTPrediction.GetOriginalFunction(14);
  4581.     static DWORD* ecxVal = Interfaces::Prediction;
  4582.     result = origFunc(ecxVal);
  4583.  
  4584.     // If we are in the right place where the player view is calculated
  4585.     // Calculate the change in the view and get rid of it
  4586.     if (Menu::Window.VisualsTab.OtherNoVisualRecoil.GetState() && (DWORD)(_ReturnAddress()) == Offsets::Functions::dwCalcPlayerView)
  4587.     {
  4588.         IClientEntity* pLocalEntity = NULL;
  4589.  
  4590.         float* m_LocalViewAngles = NULL;
  4591.  
  4592.         __asm
  4593.  
  4594.         {
  4595.             MOV pLocalEntity, ESI
  4596.  
  4597.             MOV m_LocalViewAngles, EBX
  4598.  
  4599.         }
  4600.  
  4601.         Vector viewPunch = pLocalEntity->localPlayerExclusive()->GetViewPunchAngle();
  4602.         Vector aimPunch = pLocalEntity->localPlayerExclusive()->GetAimPunchAngle();
  4603.  
  4604.         m_LocalViewAngles[0] -= (viewPunch[0] + (aimPunch[0] * 2 * 0.4499999f));
  4605.         m_LocalViewAngles[1] -= (viewPunch[1] + (aimPunch[1] * 2 * 0.4499999f));
  4606.         m_LocalViewAngles[2] -= (viewPunch[2] + (aimPunch[2] * 2 * 0.4499999f));
  4607.         return true;
  4608.     }
  4609.  
  4610.     return result;
  4611. }
  4612.  
  4613. // DrawModelExec for chams and shit
  4614. void __fastcall Hooked_DrawModelExecute(void* thisptr, int edx, void* ctx, void* state, const ModelRenderInfo_t &pInfo, matrix3x4* pCustomBoneToWorld)
  4615. {
  4616.     Color color;
  4617.     float flColor[3] = { 0.f };
  4618.     static IMaterial* CoveredLit = CreateMaterial(true);
  4619.     static IMaterial* OpenLit = CreateMaterial(false);
  4620.     static IMaterial* CoveredFlat = CreateMaterial(true, false);
  4621.     static IMaterial* OpenFlat = CreateMaterial(false, false);
  4622.     bool DontDraw = false;
  4623.  
  4624.     const char* ModelName = Interfaces::ModelInfo->GetModelName((model_t*)pInfo.pModel);
  4625.     IClientEntity* pModelEntity = (IClientEntity*)Interfaces::EntList->GetClientEntity(pInfo.entity_index);
  4626.     IClientEntity* pLocal = (IClientEntity*)Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  4627.  
  4628.     if (Menu::Window.VisualsTab.Active.GetState())
  4629.     {
  4630.         // Player Chams
  4631.         int ChamsStyle = Menu::Window.VisualsTab.OptionsChams.GetIndex();
  4632.         int HandsStyle = Menu::Window.VisualsTab.OtherNoHands.GetIndex();
  4633.         if (ChamsStyle != 0 && Menu::Window.VisualsTab.FiltersPlayers.GetState() && strstr(ModelName, "models/player"))
  4634.         {
  4635.             if (pLocal && (!Menu::Window.VisualsTab.FiltersEnemiesOnly.GetState() ||
  4636.                 pModelEntity->GetTeamNum() != pLocal->GetTeamNum()))
  4637.             {
  4638.                 IMaterial* covered = ChamsStyle == 1 ? CoveredLit : CoveredFlat;
  4639.                 IMaterial* open = ChamsStyle == 1 ? OpenLit : OpenFlat;
  4640.  
  4641.                 IClientEntity* pModelEntity = (IClientEntity*)Interfaces::EntList->GetClientEntity(pInfo.entity_index);
  4642.                 if (pModelEntity)
  4643.                 {
  4644.                     IClientEntity* local = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  4645.                     if (local)
  4646.                     {
  4647.                         if (pModelEntity->IsAlive() && pModelEntity->GetHealth() > 0 /*&& pModelEntity->GetTeamNum() != local->GetTeamNum()*/)
  4648.                         {
  4649.                             float alpha = 1.f;
  4650.  
  4651.                             if (pModelEntity->HasGunGameImmunity())
  4652.                                 alpha = 0.5f;
  4653.  
  4654.                             if (pModelEntity->GetTeamNum() == 2)
  4655.                             {
  4656.                                 flColor[0] = 240.f / 255.f;
  4657.                                 flColor[1] = 30.f / 255.f;
  4658.                                 flColor[2] = 35.f / 255.f;
  4659.                             }
  4660.                             else
  4661.                             {
  4662.                                 flColor[0] = 63.f / 255.f;
  4663.                                 flColor[1] = 72.f / 255.f;
  4664.                                 flColor[2] = 205.f / 255.f;
  4665.                             }
  4666.  
  4667.                             Interfaces::RenderView->SetColorModulation(flColor);
  4668.                             Interfaces::RenderView->SetBlend(alpha);
  4669.                             Interfaces::ModelRender->ForcedMaterialOverride(covered);
  4670.                             oDrawModelExecute(thisptr, ctx, state, pInfo, pCustomBoneToWorld);
  4671.  
  4672.                             if (pModelEntity->GetTeamNum() == 2)
  4673.                             {
  4674.                                 flColor[0] = 247.f / 255.f;
  4675.                                 flColor[1] = 180.f / 255.f;
  4676.                                 flColor[2] = 20.f / 255.f;
  4677.                             }
  4678.                             else
  4679.                             {
  4680.                                 flColor[0] = 32.f / 255.f;
  4681.                                 flColor[1] = 180.f / 255.f;
  4682.                                 flColor[2] = 57.f / 255.f;
  4683.                             }
  4684.  
  4685.                             Interfaces::RenderView->SetColorModulation(flColor);
  4686.                             Interfaces::RenderView->SetBlend(alpha);
  4687.                             Interfaces::ModelRender->ForcedMaterialOverride(open);
  4688.                         }
  4689.                         else
  4690.                         {
  4691.                             color.SetColor(255, 255, 255, 255);
  4692.                             ForceMaterial(color, open);
  4693.                         }
  4694.                     }
  4695.                 }
  4696.             }
  4697.         }
  4698.         else if (HandsStyle != 0 && strstr(ModelName, "arms"))
  4699.         {
  4700.             if (HandsStyle == 1)
  4701.             {
  4702.                 DontDraw = true;
  4703.             }
  4704.             else if (HandsStyle == 2)
  4705.             {
  4706.                 Interfaces::RenderView->SetBlend(0.3);
  4707.             }
  4708.             else if (HandsStyle == 3)
  4709.             {
  4710.                 IMaterial* covered = ChamsStyle == 1 ? CoveredLit : CoveredFlat;
  4711.                 IMaterial* open = ChamsStyle == 1 ? OpenLit : OpenFlat;
  4712.                 if (pLocal)
  4713.                 {
  4714.                     if (pLocal->IsAlive())
  4715.                     {
  4716.                         int alpha = pLocal->HasGunGameImmunity() ? 150 : 255;
  4717.  
  4718.                         if (pLocal->GetTeamNum() == 2)
  4719.                             color.SetColor(240, 30, 35, alpha);
  4720.                         else
  4721.                             color.SetColor(63, 72, 205, alpha);
  4722.  
  4723.                         ForceMaterial(color, covered);
  4724.                         oDrawModelExecute(thisptr, ctx, state, pInfo, pCustomBoneToWorld);
  4725.  
  4726.                         if (pLocal->GetTeamNum() == 2)
  4727.                             color.SetColor(247, 180, 20, alpha);
  4728.                         else
  4729.                             color.SetColor(32, 180, 57, alpha);
  4730.                     }
  4731.                     else
  4732.                     {
  4733.                         color.SetColor(255, 255, 255, 255);
  4734.                     }
  4735.  
  4736.                     ForceMaterial(color, open);
  4737.                 }
  4738.             }
  4739.             else
  4740.             {
  4741.                 static int counter = 0;
  4742.                 static float colors[3] = { 1.f, 0.f, 0.f };
  4743.  
  4744.                 if (colors[counter] >= 1.0f)
  4745.                 {
  4746.                     colors[counter] = 1.0f;
  4747.                     counter += 1;
  4748.                     if (counter > 2)
  4749.                         counter = 0;
  4750.                 }
  4751.                 else
  4752.                 {
  4753.                     int prev = counter - 1;
  4754.                     if (prev < 0) prev = 2;
  4755.                     colors[prev] -= 0.05f;
  4756.                     colors[counter] += 0.05f;
  4757.                 }
  4758.  
  4759.                 Interfaces::RenderView->SetColorModulation(colors);
  4760.                 Interfaces::RenderView->SetBlend(0.3);
  4761.                 Interfaces::ModelRender->ForcedMaterialOverride(OpenLit);
  4762.             }
  4763.         }
  4764.         else if (ChamsStyle != 0 && Menu::Window.VisualsTab.FiltersWeapons.GetState() && strstr(ModelName, "_dropped.mdl"))
  4765.         {
  4766.             IMaterial* covered = ChamsStyle == 1 ? CoveredLit : CoveredFlat;
  4767.             color.SetColor(255, 255, 255, 255);
  4768.             ForceMaterial(color, covered);
  4769.         }
  4770.     }
  4771.  
  4772.     if (!DontDraw)
  4773.         oDrawModelExecute(thisptr, ctx, state, pInfo, pCustomBoneToWorld);
  4774.     Interfaces::ModelRender->ForcedMaterialOverride(NULL);
  4775. }
  4776.  
  4777. // ClientMode CreateMove
  4778. bool __fastcall CreateMoveClient_Hooked(void* self, int edx, float frametime, CUserCmd* pCmd)
  4779. {
  4780.     // Backup for safety
  4781.     Vector origView = pCmd->viewangles;
  4782.     Vector viewforward, viewright, viewup, aimforward, aimright, aimup;
  4783.     Vector qAimAngles;
  4784.     qAimAngles.Init(0.0f, pCmd->viewangles.y, 0.0f);
  4785.     AngleVectors(qAimAngles, &viewforward, &viewright, &viewup);
  4786.  
  4787.     // Do da hacks
  4788.     IClientEntity* pLocal = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  4789.     if (Interfaces::Engine->IsConnected() && Interfaces::Engine->IsInGame() && pLocal && pLocal->IsAlive())
  4790.         Hacks::MoveHacks(pCmd);
  4791.  
  4792.     //Movement Fix
  4793.     //GameUtils::CL_FixMove(pCmd, origView);
  4794.     qAimAngles.Init(0.0f, GetAutostrafeView().y, 0.0f);
  4795.     AngleVectors(qAimAngles, &viewforward, &viewright, &viewup);
  4796.     qAimAngles.Init(0.0f, pCmd->viewangles.y, 0.0f);
  4797.     AngleVectors(qAimAngles, &aimforward, &aimright, &aimup);
  4798.     Vector vForwardNorm; Normalize(viewforward, vForwardNorm);
  4799.     Vector vRightNorm; Normalize(viewright, vRightNorm);
  4800.     Vector vUpNorm; Normalize(viewup, vUpNorm);
  4801.  
  4802.     // Original shit for movement correction
  4803.     float forward = pCmd->forwardmove;
  4804.     float right = pCmd->sidemove;
  4805.     float up = pCmd->upmove;
  4806.     if (forward > 450) forward = 450;
  4807.     if (right > 450) right = 450;
  4808.     if (up > 450) up = 450;
  4809.     if (forward < -450) forward = -450;
  4810.     if (right < -450) right = -450;
  4811.     if (up < -450) up = -450;
  4812.     pCmd->forwardmove = DotProduct(forward * vForwardNorm, aimforward) + DotProduct(right * vRightNorm, aimforward) + DotProduct(up * vUpNorm, aimforward);
  4813.     pCmd->sidemove = DotProduct(forward * vForwardNorm, aimright) + DotProduct(right * vRightNorm, aimright) + DotProduct(up * vUpNorm, aimright);
  4814.     pCmd->upmove = DotProduct(forward * vForwardNorm, aimup) + DotProduct(right * vRightNorm, aimup) + DotProduct(up * vUpNorm, aimup);
  4815.  
  4816.     // Angle normalisation
  4817.     if (Menu::Window.VisualsTab.OtherSafeMode.GetState())
  4818.     {
  4819.         GameUtils::NormaliseViewAngle(pCmd->viewangles);
  4820.  
  4821.         if (pCmd->viewangles.z != 0.0f)
  4822.         {
  4823.             pCmd->viewangles.z = 0.00;
  4824.         }
  4825.  
  4826.         if (pCmd->viewangles.x < -89 || pCmd->viewangles.x > 89 || pCmd->viewangles.y < -180 || pCmd->viewangles.y > 180)
  4827.         {
  4828.             Utilities::Log("Having to re-normalise!");
  4829.             GameUtils::NormaliseViewAngle(pCmd->viewangles);
  4830.             Beep(750, 800);
  4831.             if (pCmd->viewangles.x < -89 || pCmd->viewangles.x > 89 || pCmd->viewangles.y < -180 || pCmd->viewangles.y > 180)
  4832.             {
  4833.                 pCmd->viewangles = origView;
  4834.                 pCmd->sidemove = right;
  4835.                 pCmd->forwardmove = forward;
  4836.             }
  4837.         }
  4838.     }
  4839.  
  4840.     return false;
  4841. }
  4842.  
  4843. /*void  __stdcall Hooked_FrameStageNotify(ClientFrameStage_t curStage)
  4844. {
  4845.         oFrameStageNotify(curStage);
  4846.  
  4847.         if (curStage == FRAME_NET_UPDATE_POSTDATAUPDATE_START)
  4848.         {
  4849.                 IClientEntity *pLocal = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  4850.                 if (Menu::Window.MiscTab.KnifeEnable.GetState() && pLocal)
  4851.                 {
  4852.                         IClientEntity* WeaponEnt = Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  4853.                         CBaseCombatWeapon* Weapon = (CBaseCombatWeapon*)WeaponEnt;
  4854.                         if (Weapon)
  4855.                         {
  4856.                                 //Utilities::Log("NIGGA WE CLOSE!");
  4857.                                 static bool LastItemWasKnife = false;
  4858.                                 if (WeaponEnt->GetClientClass()->m_ClassID == (int)CSGOClassID::CKnife)
  4859.                                 {
  4860.                                         *Weapon->FallbackStatTrak() = 1337;
  4861.                                         int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  4862.                                         if (Skin == 0) *Weapon->FallbackPaintKit() = 416;
  4863.                                         if (Skin == 1) *Weapon->FallbackPaintKit() = 415;
  4864.                                         if (Skin == 3) *Weapon->FallbackPaintKit() = 409;
  4865.                                         if (Skin == 4) *Weapon->FallbackPaintKit() = 0;
  4866.                                         *Weapon->FallbackWear() = 0.0001;
  4867.  
  4868.                                         *Weapon->m_AttributeManager()->m_Item()->ItemIDLow() = 7;
  4869.                                         int Model = Menu::Window.MiscTab.KnifeModel.GetIndex();
  4870.                                         *Weapon->m_AttributeManager()->m_Item()->ItemIDHigh() = (Model == 0) ? 507 : 500;
  4871.                                         *Weapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = (Model == 0) ? 507 : 500;
  4872.  
  4873.                                         if (GUI.GetKeyState(VK_END))
  4874.                                                 ForceUpdate();
  4875.                                 }
  4876.                         }
  4877.                 }
  4878.         }
  4879. }*/
  4880.  
  4881.  
  4882. void __stdcall Hooked_FrameStageNotify(ClientFrameStage_t curStage)
  4883. {
  4884.     oFrameStageNotify(curStage);
  4885.  
  4886.     //Utilities::Log("plsplspls");
  4887.  
  4888.     if (curStage == FRAME_NET_UPDATE_POSTDATAUPDATE_START)
  4889.     {
  4890.         //Utilities::Log("APPLY SKIN APPLY SKIN");
  4891.         IClientEntity* pLocal = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
  4892.         int iBayonet = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_bayonet.mdl");
  4893.         int iButterfly = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_butterfly.mdl");
  4894.         int iFlip = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_flip.mdl");
  4895.         int iGunGame = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_gg.mdl");
  4896.         int iGut = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_gut.mdl");
  4897.         int iKarambit = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_karam.mdl");
  4898.         int iM9Bayonet = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_m9_bay.mdl");
  4899.         int iHuntsman = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_tactical.mdl");
  4900.  
  4901.         int iFalchion = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_falchion_advanced.mdl");
  4902.         int iDagger = Interfaces::ModelInfo->GetModelIndex("models/weapons/v_knife_push.mdl");
  4903.  
  4904.         for (int i = Interfaces::EntList->GetHighestEntityIndex(); i >= 0; --i)
  4905.         {
  4906.             IClientEntity* pEntity = Interfaces::EntList->GetClientEntity(i);
  4907.  
  4908.             if (pEntity)
  4909.             {
  4910.                 ULONG hOwnerEntity = *(PULONG)((DWORD)pEntity + 0x148);
  4911.  
  4912.                 IClientEntity* pOwner = Interfaces::EntList->GetClientEntityFromHandle((HANDLE)hOwnerEntity);
  4913.  
  4914.                 if (pOwner)
  4915.                 {
  4916.                     if (pOwner == pLocal)
  4917.                     {
  4918.                         std::string sWeapon = Interfaces::ModelInfo->GetModelName(pEntity->GetModel());
  4919.  
  4920.                         if (!(sWeapon.find("models/weapons", 0) != std::string::npos))
  4921.                                                         continue;
  4922.  
  4923.         if (sWeapon.find("c4_planted", 0) != std::string::npos)
  4924.                                                         continue;
  4925.  
  4926.         if (sWeapon.find("thrown", 0) != std::string::npos)
  4927.                                                         continue;
  4928.  
  4929.         if (sWeapon.find("smokegrenade", 0) != std::string::npos)
  4930.                                                         continue;
  4931.  
  4932.         if (sWeapon.find("flashbang", 0) != std::string::npos)
  4933.                                                         continue;
  4934.  
  4935.         if (sWeapon.find("fraggrenade", 0) != std::string::npos)
  4936.                                                         continue;
  4937.  
  4938.         if (sWeapon.find("molotov", 0) != std::string::npos)
  4939.                                                         continue;
  4940.  
  4941.         if (sWeapon.find("decoy", 0) != std::string::npos)
  4942.                                                         continue;
  4943.  
  4944.         if (sWeapon.find("incendiarygrenade", 0) != std::string::npos)
  4945.                                                         continue;
  4946.  
  4947.         if (sWeapon.find("ied", 0) != std::string::npos)
  4948.                                                         continue;
  4949.  
  4950.         if (sWeapon.find("w_eq_", 0) != std::string::npos)
  4951.                                                         continue;
  4952.  
  4953.         CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)pEntity;
  4954.  
  4955.         ClientClass* pClass = Interfaces::Client->GetAllClasses();
  4956.  
  4957.         if (Menu::Window.MiscTab.KnifeEnable.GetState())
  4958.         {
  4959.             int Model = Menu::Window.MiscTab.KnifeModel.GetIndex();
  4960.  
  4961.             int M41S = Menu::Window.MiscTab.M41SSkin.GetIndex();
  4962.             int M4A4 = Menu::Window.MiscTab.M4A4Skin.GetIndex();
  4963.             int AK47 = Menu::Window.MiscTab.AK47Skin.GetIndex();
  4964.             int AWP = Menu::Window.MiscTab.AWPSkin.GetIndex();
  4965.             int Glock = Menu::Window.MiscTab.GLOCKSkin.GetIndex();
  4966.             int USPS = Menu::Window.MiscTab.USPSSkin.GetIndex();
  4967.             int Deagle = Menu::Window.MiscTab.DEAGLESkin.GetIndex();
  4968.             int Magnum = Menu::Window.MiscTab.DEAGLESkin.GetIndex();
  4969.  
  4970.             if (*pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() == 26) // M41S
  4971.             {
  4972.                 if (M41S == 0)
  4973.                 {
  4974.                     *pWeapon->FallbackPaintKit() = 321;
  4975.                 }
  4976.                 else if (M41S == 1)
  4977.                 {
  4978.                     *pWeapon->FallbackPaintKit() = 430;
  4979.                 }
  4980.                 else if (M41S == 2)
  4981.                 {
  4982.                     *pWeapon->FallbackPaintKit() = 360;
  4983.                 }
  4984.                 else if (M41S == 3)
  4985.                 {
  4986.                     *pWeapon->FallbackPaintKit() = 445;
  4987.                 }
  4988.             }
  4989.             else if (*pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() == 60) // M4A4
  4990.             {
  4991.                 if (M4A4 == 0)
  4992.                 {
  4993.                     *pWeapon->FallbackPaintKit() = 512;
  4994.                 }
  4995.                 else if (M4A4 == 1)
  4996.                 {
  4997.                     *pWeapon->FallbackPaintKit() = 309;
  4998.                 }
  4999.                 else if (M4A4 == 2)
  5000.                 {
  5001.                     *pWeapon->FallbackPaintKit() = 155;
  5002.                 }
  5003.                 else if (M4A4 == 3)
  5004.                 {
  5005.                     *pWeapon->FallbackPaintKit() = 400;
  5006.                 }
  5007.                 else if (M4A4 == 4)
  5008.                 {
  5009.                     *pWeapon->FallbackPaintKit() = 255;
  5010.                 }
  5011.             }
  5012.             else if (*pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() == 7) // AK47
  5013.             {
  5014.                 if (AK47 == 0)
  5015.                 {
  5016.                     *pWeapon->FallbackPaintKit() = 506;
  5017.                 }
  5018.                 else if (AK47 == 1)
  5019.                 {
  5020.                     *pWeapon->FallbackPaintKit() = 474;
  5021.                 }
  5022.                 else if (AK47 == 2)
  5023.                 {
  5024.                     *pWeapon->FallbackPaintKit() = 302;
  5025.                 }
  5026.                 else if (AK47 == 3)
  5027.                 {
  5028.                     *pWeapon->FallbackPaintKit() = 180;
  5029.                 }
  5030.                 else if (AK47 == 4)
  5031.                 {
  5032.                     *pWeapon->FallbackPaintKit() = 316;
  5033.                 }
  5034.             }
  5035.             else if (*pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() == 9) // AWP
  5036.             {
  5037.                 if (AWP == 0)
  5038.                 {
  5039.                     *pWeapon->FallbackPaintKit() = 475;
  5040.                 }
  5041.                 else if (AWP == 1)
  5042.                 {
  5043.                     *pWeapon->FallbackPaintKit() = 279;
  5044.                 }
  5045.                 else if (AWP == 2)
  5046.                 {
  5047.                     *pWeapon->FallbackPaintKit() = 344;
  5048.                 }
  5049.                 else if (AWP == 3)
  5050.                 {
  5051.                     *pWeapon->FallbackPaintKit() = 51;
  5052.                 }
  5053.             }
  5054.             else if (*pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() == 4) // GLOCK
  5055.             {
  5056.                 if (Glock == 0)
  5057.                 {
  5058.                     *pWeapon->FallbackPaintKit() = 353;
  5059.                 }
  5060.                 else if (Glock == 1)
  5061.                 {
  5062.                     *pWeapon->FallbackPaintKit() = 38;
  5063.                 }
  5064.                 else if (Glock == 2)
  5065.                 {
  5066.                     *pWeapon->FallbackPaintKit() = 437;
  5067.                 }
  5068.                 else if (Glock == 3)
  5069.                 {
  5070.                     *pWeapon->FallbackPaintKit() = 479;
  5071.                 }
  5072.             }
  5073.             else if (*pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() == 61) // USPS
  5074.             {
  5075.                 if (USPS == 0)
  5076.                 {
  5077.                     *pWeapon->FallbackPaintKit() = 504;
  5078.                 }
  5079.                 else if (USPS == 1)
  5080.                 {
  5081.                     *pWeapon->FallbackPaintKit() = 339;
  5082.                 }
  5083.                 else if (USPS == 2)
  5084.                 {
  5085.                     *pWeapon->FallbackPaintKit() = 313;
  5086.                 }
  5087.                 else if (USPS == 3)
  5088.                 {
  5089.                     *pWeapon->FallbackPaintKit() = 290;
  5090.                 }
  5091.             }
  5092.  
  5093.             else if (*pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() == 64) // USPS
  5094.             {
  5095.                 if (Magnum == 0)
  5096.                 {
  5097.                     *pWeapon->FallbackPaintKit() = 12;
  5098.                 }
  5099.                 else if (Magnum == 1)
  5100.                 {
  5101.                     *pWeapon->FallbackPaintKit() = 522;
  5102.                 }
  5103.                 else if (Magnum == 2)
  5104.                 {
  5105.                     *pWeapon->FallbackPaintKit() = 523;
  5106.                 }
  5107.             }
  5108.  
  5109.             if (pEntity->GetClientClass()->m_ClassID == (int)CSGOClassID::CKnife)
  5110.             {
  5111.                 if (Model == 0) // Karambit
  5112.                 {
  5113.                     *pWeapon->ViewModelIndex() = iKarambit;
  5114.                     *pWeapon->WorldModelIndex() = iKarambit + 1;
  5115.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 507;
  5116.  
  5117.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5118.  
  5119.                     if (Skin == 0)
  5120.                     {
  5121.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5122.                     }
  5123.                     else if (Skin == 1)
  5124.                     {
  5125.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5126.                     }
  5127.                     else if (Skin == 2)
  5128.                     {
  5129.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5130.                     }
  5131.                     else if (Skin == 3)
  5132.                     {
  5133.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5134.                     }
  5135.                     else if (Skin == 4)
  5136.                     {
  5137.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5138.                     }
  5139.                     else if (Skin == 5)
  5140.                     {
  5141.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5142.                     }
  5143.                     else if (Skin == 6)
  5144.                     {
  5145.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5146.                     }
  5147.                     else if (Skin == 7)
  5148.                     {
  5149.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5150.                     }
  5151.                     else if (Skin == 8)
  5152.                     {
  5153.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5154.                     }
  5155.                     else if (Skin == 9)
  5156.                     {
  5157.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5158.                     }
  5159.                     else if (Skin == 10)
  5160.                     {
  5161.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5162.                     }
  5163.                     else if (Skin == 11)
  5164.                     {
  5165.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5166.                     }
  5167.                     else if (Skin == 12)
  5168.                     {
  5169.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5170.                     }
  5171.                     else if (Skin == 13)
  5172.                     {
  5173.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5174.                     }
  5175.                     else if (Skin == 14)
  5176.                     {
  5177.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5178.                     }
  5179.                 }
  5180.                 else if (Model == 1) // Bayonet
  5181.                 {
  5182.  
  5183.                     *pWeapon->ViewModelIndex() = iBayonet;
  5184.                     *pWeapon->WorldModelIndex() = iBayonet + 1;
  5185.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 500;
  5186.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5187.  
  5188.                     if (Skin == 0)
  5189.                     {
  5190.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5191.                     }
  5192.                     else if (Skin == 1)
  5193.                     {
  5194.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5195.                     }
  5196.                     else if (Skin == 2)
  5197.                     {
  5198.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5199.                     }
  5200.                     else if (Skin == 3)
  5201.                     {
  5202.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5203.                     }
  5204.                     else if (Skin == 4)
  5205.                     {
  5206.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5207.                     }
  5208.                     else if (Skin == 5)
  5209.                     {
  5210.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5211.                     }
  5212.                     else if (Skin == 6)
  5213.                     {
  5214.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5215.                     }
  5216.                     else if (Skin == 7)
  5217.                     {
  5218.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5219.                     }
  5220.                     else if (Skin == 8)
  5221.                     {
  5222.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5223.                     }
  5224.                     else if (Skin == 9)
  5225.                     {
  5226.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5227.                     }
  5228.                     else if (Skin == 10)
  5229.                     {
  5230.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5231.                     }
  5232.                     else if (Skin == 11)
  5233.                     {
  5234.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5235.                     }
  5236.                     else if (Skin == 12)
  5237.                     {
  5238.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5239.                     }
  5240.                     else if (Skin == 13)
  5241.                     {
  5242.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5243.                     }
  5244.                     else if (Skin == 14)
  5245.                     {
  5246.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5247.                     }
  5248.                 }
  5249.                 else if (Model == 2) // Huntsman Knife
  5250.                 {
  5251.  
  5252.                     *pWeapon->ViewModelIndex() = iHuntsman;
  5253.                     *pWeapon->WorldModelIndex() = iHuntsman + 1;
  5254.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 509;
  5255.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5256.  
  5257.                     if (Skin == 0)
  5258.                     {
  5259.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5260.                     }
  5261.                     else if (Skin == 1)
  5262.                     {
  5263.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5264.                     }
  5265.                     else if (Skin == 2)
  5266.                     {
  5267.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5268.                     }
  5269.                     else if (Skin == 3)
  5270.                     {
  5271.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5272.                     }
  5273.                     else if (Skin == 4)
  5274.                     {
  5275.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5276.                     }
  5277.                     else if (Skin == 5)
  5278.                     {
  5279.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5280.                     }
  5281.                     else if (Skin == 6)
  5282.                     {
  5283.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5284.                     }
  5285.                     else if (Skin == 7)
  5286.                     {
  5287.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5288.                     }
  5289.                     else if (Skin == 8)
  5290.                     {
  5291.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5292.                     }
  5293.                     else if (Skin == 9)
  5294.                     {
  5295.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5296.                     }
  5297.                     else if (Skin == 10)
  5298.                     {
  5299.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5300.                     }
  5301.                     else if (Skin == 11)
  5302.                     {
  5303.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5304.                     }
  5305.                     else if (Skin == 12)
  5306.                     {
  5307.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5308.                     }
  5309.                     else if (Skin == 13)
  5310.                     {
  5311.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5312.                     }
  5313.                     else if (Skin == 14)
  5314.                     {
  5315.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5316.                     }
  5317.                 }
  5318.                 else if (Model == 3) // Gut Knife
  5319.                 {
  5320.  
  5321.                     *pWeapon->ViewModelIndex() = iGut;
  5322.                     *pWeapon->WorldModelIndex() = iGut + 1;
  5323.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 506;
  5324.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5325.  
  5326.                     if (Skin == 0)
  5327.                     {
  5328.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5329.                     }
  5330.                     else if (Skin == 1)
  5331.                     {
  5332.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5333.                     }
  5334.                     else if (Skin == 2)
  5335.                     {
  5336.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5337.                     }
  5338.                     else if (Skin == 3)
  5339.                     {
  5340.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5341.                     }
  5342.                     else if (Skin == 4)
  5343.                     {
  5344.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5345.                     }
  5346.                     else if (Skin == 5)
  5347.                     {
  5348.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5349.                     }
  5350.                     else if (Skin == 6)
  5351.                     {
  5352.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5353.                     }
  5354.                     else if (Skin == 7)
  5355.                     {
  5356.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5357.                     }
  5358.                     else if (Skin == 8)
  5359.                     {
  5360.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5361.                     }
  5362.                     else if (Skin == 9)
  5363.                     {
  5364.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5365.                     }
  5366.                     else if (Skin == 10)
  5367.                     {
  5368.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5369.                     }
  5370.                     else if (Skin == 11)
  5371.                     {
  5372.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5373.                     }
  5374.                     else if (Skin == 12)
  5375.                     {
  5376.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5377.                     }
  5378.                     else if (Skin == 13)
  5379.                     {
  5380.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5381.                     }
  5382.                     else if (Skin == 14)
  5383.                     {
  5384.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5385.                     }
  5386.                 }
  5387.                 else if (Model == 4) // Walmart Knife
  5388.                 {
  5389.  
  5390.                     *pWeapon->ViewModelIndex() = iFalchion;
  5391.                     *pWeapon->WorldModelIndex() = iFalchion + 1;
  5392.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 512;
  5393.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5394.  
  5395.                     if (Skin == 0)
  5396.                     {
  5397.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5398.                     }
  5399.                     else if (Skin == 1)
  5400.                     {
  5401.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5402.                     }
  5403.                     else if (Skin == 2)
  5404.                     {
  5405.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5406.                     }
  5407.                     else if (Skin == 3)
  5408.                     {
  5409.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5410.                     }
  5411.                     else if (Skin == 4)
  5412.                     {
  5413.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5414.                     }
  5415.                     else if (Skin == 5)
  5416.                     {
  5417.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5418.                     }
  5419.                     else if (Skin == 6)
  5420.                     {
  5421.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5422.                     }
  5423.                     else if (Skin == 7)
  5424.                     {
  5425.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5426.                     }
  5427.                     else if (Skin == 8)
  5428.                     {
  5429.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5430.                     }
  5431.                     else if (Skin == 9)
  5432.                     {
  5433.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5434.                     }
  5435.                     else if (Skin == 10)
  5436.                     {
  5437.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5438.                     }
  5439.                     else if (Skin == 11)
  5440.                     {
  5441.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5442.                     }
  5443.                     else if (Skin == 12)
  5444.                     {
  5445.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5446.                     }
  5447.                     else if (Skin == 13)
  5448.                     {
  5449.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5450.                     }
  5451.                     else if (Skin == 14)
  5452.                     {
  5453.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5454.                     }
  5455.                 }
  5456.                 else if (Model == 5) // Shadow Daggers Knife
  5457.                 {
  5458.  
  5459.                     *pWeapon->ViewModelIndex() = iDagger;
  5460.                     *pWeapon->WorldModelIndex() = iDagger + 1;
  5461.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 516;
  5462.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5463.  
  5464.                     if (Skin == 0)
  5465.                     {
  5466.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5467.                     }
  5468.                     else if (Skin == 1)
  5469.                     {
  5470.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5471.                     }
  5472.                     else if (Skin == 2)
  5473.                     {
  5474.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5475.                     }
  5476.                     else if (Skin == 3)
  5477.                     {
  5478.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5479.                     }
  5480.                     else if (Skin == 4)
  5481.                     {
  5482.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5483.                     }
  5484.                     else if (Skin == 5)
  5485.                     {
  5486.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5487.                     }
  5488.                     else if (Skin == 6)
  5489.                     {
  5490.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5491.                     }
  5492.                     else if (Skin == 7)
  5493.                     {
  5494.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5495.                     }
  5496.                     else if (Skin == 8)
  5497.                     {
  5498.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5499.                     }
  5500.                     else if (Skin == 9)
  5501.                     {
  5502.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5503.                     }
  5504.                     else if (Skin == 10)
  5505.                     {
  5506.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5507.                     }
  5508.                     else if (Skin == 11)
  5509.                     {
  5510.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5511.                     }
  5512.                     else if (Skin == 12)
  5513.                     {
  5514.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5515.                     }
  5516.                     else if (Skin == 13)
  5517.                     {
  5518.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5519.                     }
  5520.                     else if (Skin == 14)
  5521.                     {
  5522.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5523.                     }
  5524.                 }
  5525.                 else if (Model == 6) // Butterfly Knife
  5526.                 {
  5527.  
  5528.                     *pWeapon->ViewModelIndex() = iButterfly;
  5529.                     *pWeapon->WorldModelIndex() = iButterfly + 1;
  5530.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 515;
  5531.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5532.  
  5533.                     if (Skin == 0)
  5534.                     {
  5535.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5536.                     }
  5537.                     else if (Skin == 1)
  5538.                     {
  5539.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5540.                     }
  5541.                     else if (Skin == 2)
  5542.                     {
  5543.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5544.                     }
  5545.                     else if (Skin == 3)
  5546.                     {
  5547.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5548.                     }
  5549.                     else if (Skin == 4)
  5550.                     {
  5551.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5552.                     }
  5553.                     else if (Skin == 5)
  5554.                     {
  5555.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5556.                     }
  5557.                     else if (Skin == 6)
  5558.                     {
  5559.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5560.                     }
  5561.                     else if (Skin == 7)
  5562.                     {
  5563.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5564.                     }
  5565.                     else if (Skin == 8)
  5566.                     {
  5567.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5568.                     }
  5569.                     else if (Skin == 9)
  5570.                     {
  5571.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5572.                     }
  5573.                     else if (Skin == 10)
  5574.                     {
  5575.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5576.                     }
  5577.                     else if (Skin == 11)
  5578.                     {
  5579.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5580.                     }
  5581.                     else if (Skin == 12)
  5582.                     {
  5583.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5584.                     }
  5585.                     else if (Skin == 13)
  5586.                     {
  5587.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5588.                     }
  5589.                     else if (Skin == 14)
  5590.                     {
  5591.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5592.                     }
  5593.                 }
  5594.                 else if (Model == 7) // Flip Knife
  5595.                 {
  5596.  
  5597.                     *pWeapon->ViewModelIndex() = iFlip;
  5598.                     *pWeapon->WorldModelIndex() = iFlip + 1;
  5599.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 505;
  5600.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5601.  
  5602.                     if (Skin == 0)
  5603.                     {
  5604.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5605.                     }
  5606.                     else if (Skin == 1)
  5607.                     {
  5608.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5609.                     }
  5610.                     else if (Skin == 2)
  5611.                     {
  5612.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5613.                     }
  5614.                     else if (Skin == 3)
  5615.                     {
  5616.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5617.                     }
  5618.                     else if (Skin == 4)
  5619.                     {
  5620.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5621.                     }
  5622.                     else if (Skin == 5)
  5623.                     {
  5624.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5625.                     }
  5626.                     else if (Skin == 6)
  5627.                     {
  5628.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5629.                     }
  5630.                     else if (Skin == 7)
  5631.                     {
  5632.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5633.                     }
  5634.                     else if (Skin == 8)
  5635.                     {
  5636.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5637.                     }
  5638.                     else if (Skin == 9)
  5639.                     {
  5640.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5641.                     }
  5642.                     else if (Skin == 10)
  5643.                     {
  5644.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5645.                     }
  5646.                     else if (Skin == 11)
  5647.                     {
  5648.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5649.                     }
  5650.                     else if (Skin == 12)
  5651.                     {
  5652.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5653.                     }
  5654.                     else if (Skin == 13)
  5655.                     {
  5656.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5657.                     }
  5658.                     else if (Skin == 14)
  5659.                     {
  5660.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5661.                     }
  5662.                 }
  5663.                 else if (Model == 8) // M9 Bayonet
  5664.                 {
  5665.  
  5666.                     *pWeapon->ViewModelIndex() = iM9Bayonet;
  5667.                     *pWeapon->WorldModelIndex() = iM9Bayonet + 1;
  5668.                     *pWeapon->m_AttributeManager()->m_Item()->ItemDefinitionIndex() = 508;
  5669.                     int Skin = Menu::Window.MiscTab.KnifeSkin.GetIndex();
  5670.  
  5671.                     if (Skin == 0)
  5672.                     {
  5673.                         *pWeapon->FallbackPaintKit() = 38; // Fade
  5674.                     }
  5675.                     else if (Skin == 1)
  5676.                     {
  5677.                         *pWeapon->FallbackPaintKit() = 410; // Damascus Steel
  5678.                     }
  5679.                     else if (Skin == 2)
  5680.                     {
  5681.                         *pWeapon->FallbackPaintKit() = 418; // Doppler Phase 1
  5682.                     }
  5683.                     else if (Skin == 3)
  5684.                     {
  5685.                         *pWeapon->FallbackPaintKit() = 419; // Doppler Phase 2
  5686.                     }
  5687.                     else if (Skin == 4)
  5688.                     {
  5689.                         *pWeapon->FallbackPaintKit() = 420; // Doppler Phase 3
  5690.                     }
  5691.                     else if (Skin == 5)
  5692.                     {
  5693.                         *pWeapon->FallbackPaintKit() = 421; // Doppler Phase 4
  5694.                     }
  5695.                     else if (Skin == 6)
  5696.                     {
  5697.                         *pWeapon->FallbackPaintKit() = 415; // Doppler (Ruby)
  5698.                     }
  5699.                     else if (Skin == 7)
  5700.                     {
  5701.                         *pWeapon->FallbackPaintKit() = 416; // Doppler (Sapphire)
  5702.                     }
  5703.                     else if (Skin == 8)
  5704.                     {
  5705.                         *pWeapon->FallbackPaintKit() = 417; // Doppler (Blackpearl)
  5706.                     }
  5707.                     else if (Skin == 9)
  5708.                     {
  5709.                         *pWeapon->FallbackPaintKit() = 413; // Marble Fade
  5710.                     }
  5711.                     else if (Skin == 10)
  5712.                     {
  5713.                         *pWeapon->FallbackPaintKit() = 409; // Tiger Tooth
  5714.                     }
  5715.                     else if (Skin == 11)
  5716.                     {
  5717.                         *pWeapon->FallbackPaintKit() = 98; // Ultraviolet
  5718.                     }
  5719.                     else if (Skin == 12)
  5720.                     {
  5721.                         *pWeapon->FallbackPaintKit() = 12; // Crimson Web
  5722.                     }
  5723.                     else if (Skin == 13)
  5724.                     {
  5725.                         *pWeapon->FallbackPaintKit() = 59; // Slaughter
  5726.                     }
  5727.                     else if (Skin == 14)
  5728.                     {
  5729.                         *pWeapon->FallbackPaintKit() = 40; // Night
  5730.                     }
  5731.                 }
  5732.             }
  5733.             *pWeapon->OwnerXuidLow() = 0;
  5734.             *pWeapon->OwnerXuidHigh() = 0;
  5735.             *pWeapon->FallbackWear() = 0.001f;
  5736.             *pWeapon->m_AttributeManager()->m_Item()->ItemIDHigh() = 1;
  5737.         }
  5738.     }
  5739. }
  5740.  
  5741.                         }
  5742.                 }
  5743.         }
  5744. }
  5745. /*
  5746. Syn's AYYWAREFramework 2015
  5747. */
  5748.  
  5749. #pragma once
  5750.  
  5751. // It's actually in DLLMain but w/e
  5752. extern bool DoUnload;
  5753.  
  5754. #include "Utilities.h"
  5755.  
  5756. namespace Hooks
  5757. {
  5758.     void Initialise();
  5759.     void UndoHooks();
  5760.  
  5761.         // VMT Managers
  5762.         extern Utilities::Memory::VMTManager VMTPanel; // Hooking drawing functions
  5763.         extern Utilities::Memory::VMTManager VMTClient; // Maybe CreateMove
  5764.         extern Utilities::Memory::VMTManager VMTClientMode; // CreateMove for functionality
  5765.         extern Utilities::Memory::VMTManager VMTModelRender; // DrawModelEx for chams
  5766.         extern Utilities::Memory::VMTManager VMTPrediction; // InPrediction for no vis recoil
  5767. };/*
  5768. Syn's AYYWAREFramework 2015
  5769. */
  5770.  
  5771. #include "Interfaces.h"
  5772. #include "Utilities.h"
  5773. #include "Menu.h"
  5774.  
  5775. //SDK Specific Definitions
  5776. typedef void* (__cdecl* CreateInterface_t)(const char*, int*);
  5777. typedef void* (* CreateInterfaceFn)(const char* pName, int* pReturnCode);
  5778.  
  5779. //Some globals for later
  5780. CreateInterface_t EngineFactory = NULL; // These are used to store the individual
  5781. CreateInterface_t ClientFactory = NULL; //  CreateInterface functions for each game
  5782. CreateInterface_t VGUISurfaceFactory = NULL; //  dll that we need access to. Can call
  5783. CreateInterface_t VGUI2Factory = NULL; //  them to recieve pointers to game classes.
  5784. CreateInterface_t MatFactory = NULL;
  5785. CreateInterface_t PhysFactory = NULL;
  5786. CreateInterface_t StdFactory = NULL;
  5787.  
  5788. void Interfaces::Initialise()
  5789. {
  5790.  
  5791.     //Get function pointers to the CreateInterface function of each module
  5792.     EngineFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::Engine, "CreateInterface");
  5793.     ClientFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::Client, "CreateInterface");
  5794.     VGUI2Factory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::VGUI2, "CreateInterface");
  5795.     VGUISurfaceFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::VGUISurface, "CreateInterface");
  5796.     MatFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::Material, "CreateInterface");
  5797.     PhysFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::VPhysics, "CreateInterface");
  5798.     StdFactory = (CreateInterface_t)GetProcAddress((HMODULE)Offsets::Modules::Stdlib, "CreateInterface");
  5799.  
  5800.     //Get the interface names regardless of their version number by scanning for each string
  5801.     char* CHLClientInterfaceName = (char*)Utilities::Memory::FindTextPattern("client.dll", "VClient0");
  5802.     char* VGUI2PanelsInterfaceName = (char*)Utilities::Memory::FindTextPattern("vgui2.dll", "VGUI_Panel0");
  5803.     char* VGUISurfaceInterfaceName = (char*)Utilities::Memory::FindTextPattern("vguimatsurface.dll", "VGUI_Surface0");
  5804.     char* EntityListInterfaceName = (char*)Utilities::Memory::FindTextPattern("client.dll", "VClientEntityList0");
  5805.     char* EngineDebugThingInterface = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VDebugOverlay0");
  5806.     char* EngineClientInterfaceName = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VEngineClient0");
  5807.     char* ClientPredictionInterface = (char*)Utilities::Memory::FindTextPattern("client.dll", "VClientPrediction0");
  5808.     char* MatSystemInterfaceName = (char*)Utilities::Memory::FindTextPattern("materialsystem.dll", "VMaterialSystem0");
  5809.     char* EngineRenderViewInterface = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VEngineRenderView0");
  5810.     char* EngineModelRenderInterface = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VEngineModel0");
  5811.     char* EngineModelInfoInterface = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VModelInfoClient0");
  5812.     char* EngineTraceInterfaceName = (char*)Utilities::Memory::FindTextPattern("engine.dll", "EngineTraceClient0");
  5813.     char* PhysPropsInterfaces = (char*)Utilities::Memory::FindTextPattern("client.dll", "VPhysicsSurfaceProps0");
  5814.     char* VEngineCvarName = (char*)Utilities::Memory::FindTextPattern("engine.dll", "VEngineCvar00");
  5815.  
  5816.     // Use the factory function pointers along with the interface versions to grab
  5817.     //  pointers to the interfaces
  5818.     Client = (IBaseClientDLL*)ClientFactory(CHLClientInterfaceName, NULL);
  5819.     Engine = (IVEngineClient*)EngineFactory(EngineClientInterfaceName, NULL);
  5820.     Panels = (IPanel*)VGUI2Factory(VGUI2PanelsInterfaceName, NULL);
  5821.     Surface = (ISurface*)VGUISurfaceFactory(VGUISurfaceInterfaceName, NULL);
  5822.     EntList = (IClientEntityList*)ClientFactory(EntityListInterfaceName, NULL);
  5823.     DebugOverlay = (IVDebugOverlay*)EngineFactory(EngineDebugThingInterface, NULL);
  5824.     Prediction = (DWORD*)ClientFactory(ClientPredictionInterface, NULL);
  5825.     MaterialSystem = (CMaterialSystem*)MatFactory(MatSystemInterfaceName, NULL);
  5826.     RenderView = (CVRenderView*)EngineFactory(EngineRenderViewInterface, NULL);
  5827.     ModelRender = (IVModelRender*)EngineFactory(EngineModelRenderInterface, NULL);
  5828.     ModelInfo = (CModelInfo*)EngineFactory(EngineModelInfoInterface, NULL);
  5829.     Trace = (IEngineTrace*)EngineFactory(EngineTraceInterfaceName, NULL);
  5830.     PhysProps = (IPhysicsSurfaceProps*)PhysFactory(PhysPropsInterfaces, NULL);
  5831.     CVar = (ICVar*)StdFactory(VEngineCvarName, NULL);
  5832.  
  5833.     // Get ClientMode Pointer
  5834.     DWORD* ppClientMode;
  5835.     ppClientMode = nullptr; // before "scripts/vgui_screens.txt"
  5836.     DWORD p = Utilities::Memory::FindPattern("client.dll", (BYTE*)"\xC7\x05\x00\x00\x00\x00\x00\x00\x00\x00\xA8\x01\x75\x1A\x83\xC8\x01\xA3\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x68\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x83\xC4\x04\xA1\x00\x00\x00\x00\xB9\x00\x00\x00\x00\x56", "xx????????xxxxxxxx????x????x????x????xxxx????x????x");
  5837.     if (p)
  5838.     {
  5839.         ppClientMode = **(DWORD***)(p + 2);
  5840.         ClientMode = ppClientMode;
  5841.     }
  5842.  
  5843.     // Search through the first entry of the Client VTable
  5844.     // The initializer contains a pointer to the 'GlobalsVariables' Table
  5845.     PDWORD pdwClient = (PDWORD) * (PDWORD)Client;
  5846.     DWORD dwInitAddr = (DWORD)(pdwClient[0]);
  5847.     for (DWORD dwIter = 0; dwIter <= 0xFF; dwIter++)
  5848.     {
  5849.         if (*(PBYTE)(dwInitAddr + dwIter - 1) == 0x08 && *(PBYTE)(dwInitAddr + dwIter) == 0xA3)
  5850.         {
  5851.             Globals = (CGlobalVarsBase*)*(PDWORD) * (PDWORD)(dwInitAddr + dwIter + 1);
  5852.             break;
  5853.         }
  5854.     }
  5855.     Utilities::Log("Interfaces Readyz");
  5856. }
  5857.  
  5858. // Namespace to contain all the valve interfaces
  5859. namespace Interfaces
  5860. {
  5861.     IBaseClientDLL* Client;
  5862.     IVEngineClient* Engine;
  5863.     IPanel* Panels;
  5864.     IClientEntityList* EntList;
  5865.     ISurface* Surface;
  5866.     IVDebugOverlay* DebugOverlay;
  5867.     DWORD* ClientMode;
  5868.     CGlobalVarsBase* Globals;
  5869.     DWORD* Prediction;
  5870.     CMaterialSystem* MaterialSystem;
  5871.     CVRenderView* RenderView;
  5872.     IVModelRender* ModelRender;
  5873.     CModelInfo* ModelInfo;
  5874.     IEngineTrace* Trace;
  5875.     IPhysicsSurfaceProps* PhysProps;
  5876.     ICVar* CVar;
  5877. };/*
  5878. Syn's AYYWAREFramework
  5879. */
  5880.  
  5881. #pragma once
  5882.  
  5883. // Includes
  5884. #include "SDK.h"
  5885.  
  5886. // Namespace to contain all the valve interfaces
  5887. namespace Interfaces
  5888. {
  5889.     // Gets handles to all the interfaces needed
  5890.     void Initialise();
  5891.  
  5892.         extern IBaseClientDLL* Client;
  5893.         extern IVEngineClient* Engine;
  5894.         extern IPanel* Panels;
  5895.         extern IClientEntityList* EntList;
  5896.         extern ISurface* Surface;
  5897.         extern IVDebugOverlay* DebugOverlay;
  5898.         extern DWORD * ClientMode;
  5899.         extern CGlobalVarsBase * Globals;
  5900.         extern DWORD * Prediction;
  5901.         extern CMaterialSystem* MaterialSystem;
  5902.         extern CVRenderView* RenderView;
  5903.         extern IVModelRender* ModelRender;
  5904.         extern CModelInfo* ModelInfo;
  5905.         extern IEngineTrace* Trace;
  5906.         extern IPhysicsSurfaceProps* PhysProps;
  5907.         exte
  5908. #include "LegitBot.h"
  5909. #include "RenderManager.h"
  5910.  
  5911. void CLegitBot::Init()
  5912. {
  5913.         IsLocked = false;
  5914.         TargetID = -1;
  5915. }
  5916.  
  5917. void CLegitBot::Draw()
  5918. {
  5919.        
  5920. }
  5921.  
  5922. void CLegitBot::Move(CUserCmd *pCmd)
  5923. {
  5924.         // Master switch
  5925.         if (!Menu::Window.LegitBotTab.Active.GetState())
  5926.                 return;
  5927.  
  5928.         // Aimbot
  5929.         if (Menu::Window.LegitBotTab.AimbotEnable.GetState())
  5930.                 DoAimbot(pCmd);
  5931.  
  5932.         // Triggerbot / Trigger Delay
  5933.         static size_t CustomDelay = 0;
  5934.         if (Menu::Window.LegitBotTab.TriggerEnable.GetState() && (!Menu::Window.LegitBotTab.TriggerKeyPress.GetState() || GUI.GetKeyState(Menu::Window.LegitBotTab.TriggerKeyBind.GetKey())))
  5935.         {
  5936.  
  5937.                 if (Menu::Window.LegitBotTab.TriggerDelay.GetValue() > 1)
  5938.                 {
  5939.                         if (GetTickCount() > CustomDelay)
  5940.                         {
  5941.  
  5942.                                 DoTrigger(pCmd);
  5943.                                 CustomDelay = GetTickCount() + Menu::Window.LegitBotTab.TriggerDelay.GetValue();
  5944.                         }
  5945.                 }
  5946.                 else
  5947.                         DoTrigger(pCmd);
  5948.         }
  5949. }
  5950.  
  5951. void CLegitBot::SyncWeaponSettings()
  5952. {
  5953.         IClientEntity* pLocal = hackManager.pLocal();
  5954.         CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  5955.  
  5956.         if (!pWeapon)
  5957.                 return;
  5958.  
  5959.         if (GameUtils::IsPistol(pWeapon))
  5960.         {
  5961.                 Speed = Menu::Window.LegitBotTab.WeaponPistSpeed.GetValue();
  5962.                 FoV = Menu::Window.LegitBotTab.WeaponPistFoV.GetValue();
  5963.                 RecoilControl = Menu::Window.LegitBotTab.WeaponPistRecoil.GetState();
  5964.  
  5965.                 switch (Menu::Window.LegitBotTab.WeaponPistHitbox.GetIndex())
  5966.                 {
  5967.                 case 0:
  5968.                         HitBox = ((int)CSGOHitboxID::Head);
  5969.                         break;
  5970.                 case 1:
  5971.                         HitBox = ((int)CSGOHitboxID::Neck);
  5972.                         break;
  5973.                 case 2:
  5974.                         HitBox = ((int)CSGOHitboxID::Chest);
  5975.                         break;
  5976.                 case 3:
  5977.                         HitBox = ((int)CSGOHitboxID::Stomach);
  5978.                         break;
  5979.                 }
  5980.         }
  5981.         else if (GameUtils::IsSniper(pWeapon))
  5982.         {
  5983.                 Speed = Menu::Window.LegitBotTab.WeaponSnipSpeed.GetValue();
  5984.                 FoV = Menu::Window.LegitBotTab.WeaponSnipFoV.GetValue();
  5985.                 RecoilControl = Menu::Window.LegitBotTab.WeaponSnipRecoil.GetState();
  5986.  
  5987.                 switch (Menu::Window.LegitBotTab.WeaponSnipHitbox.GetIndex())
  5988.                 {
  5989.                 case 0:
  5990.                         HitBox = ((int)CSGOHitboxID::Head);
  5991.                         break;
  5992.                 case 1:
  5993.                         HitBox = ((int)CSGOHitboxID::Neck);
  5994.                         break;
  5995.                 case 2:
  5996.                         HitBox = ((int)CSGOHitboxID::Chest);
  5997.                         break;
  5998.                 case 3:
  5999.                         HitBox = ((int)CSGOHitboxID::Stomach);
  6000.                         break;
  6001.                 }
  6002.         }
  6003.         else
  6004.         {
  6005.                 Speed = Menu::Window.LegitBotTab.WeaponMainSpeed.GetValue();
  6006.                 FoV = Menu::Window.LegitBotTab.WeaponMainFoV.GetValue();
  6007.                 RecoilControl = Menu::Window.LegitBotTab.WeaponMainRecoil.GetState();
  6008.  
  6009.                 switch (Menu::Window.LegitBotTab.WeaponMainHitbox.GetIndex())
  6010.                 {
  6011.                 case 0:
  6012.                         HitBox = ((int)CSGOHitboxID::Head);
  6013.                         break;
  6014.                 case 1:
  6015.                         HitBox = ((int)CSGOHitboxID::Neck);
  6016.                         break;
  6017.                 case 2:
  6018.                         HitBox = ((int)CSGOHitboxID::Chest);
  6019.                         break;
  6020.                 case 3:
  6021.                         HitBox = ((int)CSGOHitboxID::Stomach);
  6022.                         break;
  6023.                 }
  6024.         }
  6025. }
  6026.  
  6027. // Functionality
  6028. void CLegitBot::DoAimbot(CUserCmd *pCmd)
  6029. {
  6030.         IClientEntity* pTarget = nullptr;
  6031.         IClientEntity* pLocal = hackManager.pLocal();
  6032.         bool FindNewTarget = true;
  6033.         //IsLocked = false;
  6034.  
  6035.         // Don't aimbot with the knife..
  6036.         CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  6037.         if (pWeapon)
  6038.         {
  6039.                 if (pWeapon->GetAmmoInClip() == 0 || !GameUtils::IsBallisticWeapon(pWeapon))
  6040.                 {
  6041.                         //TargetID = 0;
  6042.                         //pTarget = nullptr;
  6043.                         //HitBox = -1;
  6044.                         return;
  6045.                 }
  6046.                 SyncWeaponSettings();
  6047.                
  6048.         }
  6049.         else
  6050.                 return;
  6051.  
  6052.         // Make sure we have a good target
  6053.         if (IsLocked && TargetID >= 0 && HitBox >= 0)
  6054.         {
  6055.                 pTarget = Interfaces::EntList->GetClientEntity(TargetID);
  6056.                 if (pTarget  && TargetMeetsRequirements(pTarget))
  6057.                 {
  6058.                         SyncWeaponSettings();
  6059.                         if (HitBox >= 0)
  6060.                         {
  6061.                                 Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  6062.                                 Vector View; Interfaces::Engine->GetViewAngles(View);
  6063.                                 View += pLocal->localPlayerExclusive()->GetAimPunchAngle() * 2.f;
  6064.                                 float nFoV = FovToPlayer(ViewOffset, View, pTarget, HitBox);
  6065.                                 if (nFoV < FoV)
  6066.                                         FindNewTarget = false;
  6067.                         }
  6068.                 }
  6069.         }
  6070.  
  6071.         // Find a new target, apparently we need to
  6072.         if (FindNewTarget)
  6073.         {
  6074.                 TargetID = 0;
  6075.                 pTarget = nullptr;
  6076.                 HitBox = -1;
  6077.  
  6078.                 TargetID = GetTargetCrosshair();
  6079.  
  6080.                 // Memes
  6081.                 if (TargetID >= 0)
  6082.                 {
  6083.                         pTarget = Interfaces::EntList->GetClientEntity(TargetID);
  6084.                 }
  6085.                 else
  6086.                 {
  6087.                         pTarget = nullptr;
  6088.                         HitBox = -1;
  6089.                 }
  6090.         }
  6091.  
  6092.         SyncWeaponSettings();
  6093.  
  6094.         // If we finally have a good target
  6095.         if (TargetID >= 0 && pTarget)
  6096.         {
  6097.                 //HitBox = (int)CSGOHitboxID::Head;//
  6098.                 SyncWeaponSettings();
  6099.  
  6100.                 // Key
  6101.                 if (Menu::Window.LegitBotTab.AimbotKeyPress.GetState())
  6102.                 {
  6103.                         int Key = Menu::Window.LegitBotTab.AimbotKeyBind.GetKey();
  6104.                         if (Key >= 0 && !GUI.GetKeyState(Key))
  6105.                         {
  6106.                                 TargetID = -1;
  6107.                                 pTarget = nullptr;
  6108.                                 HitBox = -1;
  6109.                                 return;
  6110.                         }
  6111.                 }
  6112.  
  6113.                 Vector AimPoint = GetHitboxPosition(pTarget, HitBox);
  6114.  
  6115.                 if (AimAtPoint(pLocal, AimPoint, pCmd))
  6116.                 {
  6117.                         //IsLocked = true;
  6118.                         if (Menu::Window.LegitBotTab.AimbotAutoFire.GetState() && !(pCmd->buttons & IN_ATTACK))
  6119.                         {
  6120.                                 pCmd->buttons |= IN_ATTACK;
  6121.                         }
  6122.                 }
  6123.         }
  6124.  
  6125.         // Auto Pistol
  6126.         static bool WasFiring = false;
  6127.         CSWeaponInfo* WeaponInfo = pWeapon->GetCSWpnData();
  6128.         if (!WeaponInfo->m_IsFullAuto && Menu::Window.LegitBotTab.AimbotAutoPistol.GetState())
  6129.         {
  6130.                 if (pCmd->buttons & IN_ATTACK)
  6131.                 {
  6132.                         if (WasFiring)
  6133.                         {
  6134.                                 pCmd->buttons &= ~IN_ATTACK;
  6135.                         }
  6136.                 }
  6137.  
  6138.                 WasFiring = pCmd->buttons & IN_ATTACK ? true : false;
  6139.         }
  6140. }
  6141.  
  6142. bool TargetMeetsTriggerRequirements(IClientEntity* pEntity)
  6143. {
  6144.         // Is a valid player
  6145.         if (pEntity && pEntity->IsDormant() == false && pEntity->IsAlive() && pEntity->GetIndex() != hackManager.pLocal()->GetIndex())
  6146.         {
  6147.                 // Entity Type checks
  6148.                 ClientClass *pClientClass = pEntity->GetClientClass();
  6149.                 player_info_t pinfo;
  6150.                 if (pClientClass->m_ClassID == (int)CSGOClassID::CCSPlayer && Interfaces::Engine->GetPlayerInfo(pEntity->GetIndex(), &pinfo))
  6151.                 {
  6152.                         // Team Check
  6153.                         if (pEntity->GetTeamNum() != hackManager.pLocal()->GetTeamNum() || Menu::Window.LegitBotTab.AimbotFriendlyFire.GetState())
  6154.                         {
  6155.                                 // Spawn Check
  6156.                                 if (!pEntity->HasGunGameImmunity())
  6157.                                 {
  6158.                                         return true;
  6159.                                 }
  6160.                         }
  6161.                 }
  6162.         }
  6163.  
  6164.         // They must have failed a requirement
  6165.         return false;
  6166. }
  6167.  
  6168. void CLegitBot::DoTrigger(CUserCmd *pCmd)
  6169. {
  6170.         IClientEntity* pLocal = hackManager.pLocal();
  6171.  
  6172.         // Don't triggerbot with the knife..
  6173.         CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  6174.         if (pWeapon)
  6175.         {
  6176.                 if (pWeapon->GetAmmoInClip() == 0 || !GameUtils::IsBallisticWeapon(pWeapon))
  6177.                 {
  6178.                         return;
  6179.                 }
  6180.         }
  6181.         else
  6182.                 return;
  6183.  
  6184.         // Triggerbot
  6185.         // Get the view with the recoil
  6186.         Vector ViewAngles;
  6187.         Interfaces::Engine->GetViewAngles(ViewAngles);
  6188.         ViewAngles += pLocal->localPlayerExclusive()->GetAimPunchAngle() * 2.f;
  6189.  
  6190.         // Build a ray going fowards at that angle
  6191.         Vector fowardVec;
  6192.         AngleVectors(ViewAngles, &fowardVec);
  6193.         fowardVec *= 10000;
  6194.  
  6195.         // Get ray start / end
  6196.         Vector start = pLocal->GetOrigin() + pLocal->GetViewOffset();
  6197.         Vector end = start + fowardVec, endScreen;
  6198.  
  6199.         trace_t Trace;
  6200.         UTIL_TraceLine(start, end, MASK_SOLID, pLocal, 0, &Trace);
  6201.  
  6202.         if (Trace.m_pEnt && 0 < Trace.hitgroup <= 7)
  6203.         {
  6204.                 if (TargetMeetsTriggerRequirements(Trace.m_pEnt))
  6205.                 {
  6206.                         pCmd->buttons |= IN_ATTACK;
  6207.                 }
  6208.         }
  6209.  
  6210.         // Auto Pistol
  6211.         static bool WasFiring = false;
  6212.         CSWeaponInfo* WeaponInfo = pWeapon->GetCSWpnData();
  6213.         if (!WeaponInfo->m_IsFullAuto && Menu::Window.LegitBotTab.AimbotAutoPistol.GetState())
  6214.         {
  6215.                 if (pCmd->buttons & IN_ATTACK)
  6216.                 {
  6217.                         if (WasFiring)
  6218.                         {
  6219.                                 pCmd->buttons &= ~IN_ATTACK;
  6220.                         }
  6221.                 }
  6222.  
  6223.                 WasFiring = pCmd->buttons & IN_ATTACK ? true : false;
  6224.         }
  6225. }
  6226.  
  6227. bool CLegitBot::TargetMeetsRequirements(IClientEntity* pEntity)
  6228. {
  6229.         // Is a valid player
  6230.         if (pEntity && pEntity->IsDormant() == false && pEntity->IsAlive() && pEntity->GetIndex() != hackManager.pLocal()->GetIndex())
  6231.         {
  6232.                 // Entity Type checks
  6233.                 ClientClass *pClientClass = pEntity->GetClientClass();
  6234.                 player_info_t pinfo;
  6235.                 if (pClientClass->m_ClassID == (int)CSGOClassID::CCSPlayer && Interfaces::Engine->GetPlayerInfo(pEntity->GetIndex(), &pinfo))
  6236.                 {
  6237.                         // Team Check
  6238.                         if (pEntity->GetTeamNum() != hackManager.pLocal()->GetTeamNum() || Menu::Window.LegitBotTab.AimbotFriendlyFire.GetState())
  6239.                         {
  6240.                                 // Spawn Check
  6241.                                 if (!pEntity->HasGunGameImmunity() && GameUtils::IsVisible(hackManager.pLocal(), pEntity, HitBox))
  6242.                                 {
  6243.                                         return true;
  6244.                                 }
  6245.                         }
  6246.                 }
  6247.         }
  6248.  
  6249.         // They must have failed a requirement
  6250.         return false;
  6251. }
  6252.  
  6253. float CLegitBot::FovToPlayer(Vector ViewOffSet, Vector View, IClientEntity* pEntity, int aHitBox)
  6254. {
  6255.         // Anything past 180 degrees is just going to wrap around
  6256.         CONST FLOAT MaxDegrees = 180.0f;
  6257.  
  6258.         // Get local angles
  6259.         Vector Angles = View;
  6260.  
  6261.         // Get local view / eye position
  6262.         Vector Origin = ViewOffSet;
  6263.  
  6264.         // Create and intiialize vectors for calculations below
  6265.         Vector Delta(0, 0, 0);
  6266.         //Vector Origin(0, 0, 0);
  6267.         Vector Forward(0, 0, 0);
  6268.  
  6269.         // Convert angles to normalized directional forward vector
  6270.         AngleVectors(Angles, &Forward);
  6271.         Vector AimPos = GetHitboxPosition(pEntity, aHitBox);
  6272.         // Get delta vector between our local eye position and passed vector
  6273.         VectorSubtract(AimPos, Origin, Delta);
  6274.         //Delta = AimPos - Origin;
  6275.  
  6276.         // Normalize our delta vector
  6277.         Normalize(Delta, Delta);
  6278.  
  6279.         // Get dot product between delta position and directional forward vectors
  6280.         FLOAT DotProduct = Forward.Dot(Delta);
  6281.  
  6282.         // Time to calculate the field of view
  6283.         return (acos(DotProduct) * (MaxDegrees / PI));
  6284. }
  6285.  
  6286. int CLegitBot::GetTargetCrosshair()
  6287. {
  6288.         // Target selection
  6289.         SyncWeaponSettings();
  6290.         int target = -1;
  6291.         float minFoV = FoV;
  6292.  
  6293.         IClientEntity* pLocal = hackManager.pLocal();
  6294.         Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  6295.         Vector View; Interfaces::Engine->GetViewAngles(View);
  6296.         View += pLocal->localPlayerExclusive()->GetAimPunchAngle() * 2.f;
  6297.  
  6298.         for (int i = 0; i < Interfaces::EntList->GetHighestEntityIndex(); i++)
  6299.         {
  6300.                 IClientEntity *pEntity = Interfaces::EntList->GetClientEntity(i);
  6301.                 if (TargetMeetsRequirements(pEntity))
  6302.                 {
  6303.                         int NewHitBox = HitBox;
  6304.                         if (NewHitBox >= 0)
  6305.                         {
  6306.                                 float fov = FovToPlayer(ViewOffset, View, pEntity, 0);
  6307.                                 if (fov < minFoV)
  6308.                                 {
  6309.                                         minFoV = fov;
  6310.                                         target = i;
  6311.                                 }
  6312.                         }
  6313.                 }
  6314.         }
  6315.  
  6316.         return target;
  6317. }
  6318.  
  6319. bool CLegitBot::AimAtPoint(IClientEntity* pLocal, Vector point, CUserCmd *pCmd)
  6320. {
  6321.         // Get the full angles
  6322.         if (point.Length() == 0) return false;
  6323.  
  6324.         Vector angles;
  6325.         Vector src = pLocal->GetOrigin() + pLocal->GetViewOffset();
  6326.  
  6327.         CalcAngle(src, point, angles);
  6328.         GameUtils::NormaliseViewAngle(angles);
  6329.  
  6330.         if (angles[0] != angles[0] || angles[1] != angles[1])
  6331.         {
  6332.                 return false;
  6333.         }
  6334.  
  6335.         if (RecoilControl)
  6336.         {
  6337.                 Vector AimPunch = pLocal->localPlayerExclusive()->GetAimPunchAngle();
  6338.                 if (AimPunch.Length2D() > 0 && AimPunch.Length2D() < 150)
  6339.                 {
  6340.                         angles -= AimPunch * 2;
  6341.                         GameUtils::NormaliseViewAngle(angles);
  6342.                 }
  6343.         }
  6344.  
  6345.         IsLocked = true;
  6346.         //-----------------------------------------------
  6347.  
  6348.         Vector shit = angles - pCmd->viewangles;
  6349.         bool v = false;
  6350.  
  6351.         if (shit.Length() > Speed)
  6352.         {
  6353.                 Normalize(shit, shit);
  6354.                 shit *= Speed;
  6355.         }
  6356.         else
  6357.         {
  6358.                 v = true;
  6359.         }
  6360.  
  6361.         pCmd->viewangles += shit;
  6362.         Interfaces::Engine->SetViewAngles(pCmd->viewangles);
  6363.  
  6364.         return v;
  6365. }
  6366. rn ICVar * CVar;
  6367. };
  6368. #include "LegitBot.h"
  6369. #include "RenderManager.h"
  6370.  
  6371. void CLegitBot::Init()
  6372. {
  6373.     IsLocked = false;
  6374.     TargetID = -1;
  6375. }
  6376.  
  6377. void CLegitBot::Draw()
  6378. {
  6379.  
  6380. }
  6381.  
  6382. void CLegitBot::Move(CUserCmd* pCmd)
  6383. {
  6384.     // Master switch
  6385.     if (!Menu::Window.LegitBotTab.Active.GetState())
  6386.         return;
  6387.  
  6388.     // Aimbot
  6389.     if (Menu::Window.LegitBotTab.AimbotEnable.GetState())
  6390.         DoAimbot(pCmd);
  6391.  
  6392.     // Triggerbot / Trigger Delay
  6393.     static size_t CustomDelay = 0;
  6394.     if (Menu::Window.LegitBotTab.TriggerEnable.GetState() && (!Menu::Window.LegitBotTab.TriggerKeyPress.GetState() || GUI.GetKeyState(Menu::Window.LegitBotTab.TriggerKeyBind.GetKey())))
  6395.     {
  6396.  
  6397.         if (Menu::Window.LegitBotTab.TriggerDelay.GetValue() > 1)
  6398.         {
  6399.             if (GetTickCount() > CustomDelay)
  6400.             {
  6401.  
  6402.                 DoTrigger(pCmd);
  6403.                 CustomDelay = GetTickCount() + Menu::Window.LegitBotTab.TriggerDelay.GetValue();
  6404.             }
  6405.         }
  6406.         else
  6407.             DoTrigger(pCmd);
  6408.     }
  6409. }
  6410.  
  6411. void CLegitBot::SyncWeaponSettings()
  6412. {
  6413.     IClientEntity* pLocal = hackManager.pLocal();
  6414.     CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  6415.  
  6416.     if (!pWeapon)
  6417.         return;
  6418.  
  6419.     if (GameUtils::IsPistol(pWeapon))
  6420.     {
  6421.         Speed = Menu::Window.LegitBotTab.WeaponPistSpeed.GetValue();
  6422.         FoV = Menu::Window.LegitBotTab.WeaponPistFoV.GetValue();
  6423.         RecoilControl = Menu::Window.LegitBotTab.WeaponPistRecoil.GetState();
  6424.  
  6425.         switch (Menu::Window.LegitBotTab.WeaponPistHitbox.GetIndex())
  6426.         {
  6427.             case 0:
  6428.                 HitBox = ((int)CSGOHitboxID::Head);
  6429.                 break;
  6430.             case 1:
  6431.                 HitBox = ((int)CSGOHitboxID::Neck);
  6432.                 break;
  6433.             case 2:
  6434.                 HitBox = ((int)CSGOHitboxID::Chest);
  6435.                 break;
  6436.             case 3:
  6437.                 HitBox = ((int)CSGOHitboxID::Stomach);
  6438.                 break;
  6439.         }
  6440.     }
  6441.     else if (GameUtils::IsSniper(pWeapon))
  6442.     {
  6443.         Speed = Menu::Window.LegitBotTab.WeaponSnipSpeed.GetValue();
  6444.         FoV = Menu::Window.LegitBotTab.WeaponSnipFoV.GetValue();
  6445.         RecoilControl = Menu::Window.LegitBotTab.WeaponSnipRecoil.GetState();
  6446.  
  6447.         switch (Menu::Window.LegitBotTab.WeaponSnipHitbox.GetIndex())
  6448.         {
  6449.             case 0:
  6450.                 HitBox = ((int)CSGOHitboxID::Head);
  6451.                 break;
  6452.             case 1:
  6453.                 HitBox = ((int)CSGOHitboxID::Neck);
  6454.                 break;
  6455.             case 2:
  6456.                 HitBox = ((int)CSGOHitboxID::Chest);
  6457.                 break;
  6458.             case 3:
  6459.                 HitBox = ((int)CSGOHitboxID::Stomach);
  6460.                 break;
  6461.         }
  6462.     }
  6463.     else
  6464.     {
  6465.         Speed = Menu::Window.LegitBotTab.WeaponMainSpeed.GetValue();
  6466.         FoV = Menu::Window.LegitBotTab.WeaponMainFoV.GetValue();
  6467.         RecoilControl = Menu::Window.LegitBotTab.WeaponMainRecoil.GetState();
  6468.  
  6469.         switch (Menu::Window.LegitBotTab.WeaponMainHitbox.GetIndex())
  6470.         {
  6471.             case 0:
  6472.                 HitBox = ((int)CSGOHitboxID::Head);
  6473.                 break;
  6474.             case 1:
  6475.                 HitBox = ((int)CSGOHitboxID::Neck);
  6476.                 break;
  6477.             case 2:
  6478.                 HitBox = ((int)CSGOHitboxID::Chest);
  6479.                 break;
  6480.             case 3:
  6481.                 HitBox = ((int)CSGOHitboxID::Stomach);
  6482.                 break;
  6483.         }
  6484.     }
  6485. }
  6486.  
  6487. // Functionality
  6488. void CLegitBot::DoAimbot(CUserCmd* pCmd)
  6489. {
  6490.     IClientEntity* pTarget = nullptr;
  6491.     IClientEntity* pLocal = hackManager.pLocal();
  6492.     bool FindNewTarget = true;
  6493.     //IsLocked = false;
  6494.  
  6495.     // Don't aimbot with the knife..
  6496.     CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  6497.     if (pWeapon)
  6498.     {
  6499.         if (pWeapon->GetAmmoInClip() == 0 || !GameUtils::IsBallisticWeapon(pWeapon))
  6500.         {
  6501.             //TargetID = 0;
  6502.             //pTarget = nullptr;
  6503.             //HitBox = -1;
  6504.             return;
  6505.         }
  6506.         SyncWeaponSettings();
  6507.  
  6508.     }
  6509.     else
  6510.         return;
  6511.  
  6512.     // Make sure we have a good target
  6513.     if (IsLocked && TargetID >= 0 && HitBox >= 0)
  6514.     {
  6515.         pTarget = Interfaces::EntList->GetClientEntity(TargetID);
  6516.         if (pTarget && TargetMeetsRequirements(pTarget))
  6517.         {
  6518.             SyncWeaponSettings();
  6519.             if (HitBox >= 0)
  6520.             {
  6521.                 Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  6522.                 Vector View; Interfaces::Engine->GetViewAngles(View);
  6523.                 View += pLocal->localPlayerExclusive()->GetAimPunchAngle() * 2.f;
  6524.                 float nFoV = FovToPlayer(ViewOffset, View, pTarget, HitBox);
  6525.                 if (nFoV < FoV)
  6526.                     FindNewTarget = false;
  6527.             }
  6528.         }
  6529.     }
  6530.  
  6531.     // Find a new target, apparently we need to
  6532.     if (FindNewTarget)
  6533.     {
  6534.         TargetID = 0;
  6535.         pTarget = nullptr;
  6536.         HitBox = -1;
  6537.  
  6538.         TargetID = GetTargetCrosshair();
  6539.  
  6540.         // Memes
  6541.         if (TargetID >= 0)
  6542.         {
  6543.             pTarget = Interfaces::EntList->GetClientEntity(TargetID);
  6544.         }
  6545.         else
  6546.         {
  6547.             pTarget = nullptr;
  6548.             HitBox = -1;
  6549.         }
  6550.     }
  6551.  
  6552.     SyncWeaponSettings();
  6553.  
  6554.     // If we finally have a good target
  6555.     if (TargetID >= 0 && pTarget)
  6556.     {
  6557.         //HitBox = (int)CSGOHitboxID::Head;//
  6558.         SyncWeaponSettings();
  6559.  
  6560.         // Key
  6561.         if (Menu::Window.LegitBotTab.AimbotKeyPress.GetState())
  6562.         {
  6563.             int Key = Menu::Window.LegitBotTab.AimbotKeyBind.GetKey();
  6564.             if (Key >= 0 && !GUI.GetKeyState(Key))
  6565.             {
  6566.                 TargetID = -1;
  6567.                 pTarget = nullptr;
  6568.                 HitBox = -1;
  6569.                 return;
  6570.             }
  6571.         }
  6572.  
  6573.         Vector AimPoint = GetHitboxPosition(pTarget, HitBox);
  6574.  
  6575.         if (AimAtPoint(pLocal, AimPoint, pCmd))
  6576.         {
  6577.             //IsLocked = true;
  6578.             if (Menu::Window.LegitBotTab.AimbotAutoFire.GetState() && !(pCmd->buttons & IN_ATTACK))
  6579.             {
  6580.                 pCmd->buttons |= IN_ATTACK;
  6581.             }
  6582.         }
  6583.     }
  6584.  
  6585.     // Auto Pistol
  6586.     static bool WasFiring = false;
  6587.     CSWeaponInfo* WeaponInfo = pWeapon->GetCSWpnData();
  6588.     if (!WeaponInfo->m_IsFullAuto && Menu::Window.LegitBotTab.AimbotAutoPistol.GetState())
  6589.     {
  6590.         if (pCmd->buttons & IN_ATTACK)
  6591.         {
  6592.             if (WasFiring)
  6593.             {
  6594.                 pCmd->buttons &= ~IN_ATTACK;
  6595.             }
  6596.         }
  6597.  
  6598.         WasFiring = pCmd->buttons & IN_ATTACK ? true : false;
  6599.     }
  6600. }
  6601.  
  6602. bool TargetMeetsTriggerRequirements(IClientEntity* pEntity)
  6603. {
  6604.     // Is a valid player
  6605.     if (pEntity && pEntity->IsDormant() == false && pEntity->IsAlive() && pEntity->GetIndex() != hackManager.pLocal()->GetIndex())
  6606.     {
  6607.         // Entity Type checks
  6608.         ClientClass* pClientClass = pEntity->GetClientClass();
  6609.         player_info_t pinfo;
  6610.         if (pClientClass->m_ClassID == (int)CSGOClassID::CCSPlayer && Interfaces::Engine->GetPlayerInfo(pEntity->GetIndex(), &pinfo))
  6611.         {
  6612.             // Team Check
  6613.             if (pEntity->GetTeamNum() != hackManager.pLocal()->GetTeamNum() || Menu::Window.LegitBotTab.AimbotFriendlyFire.GetState())
  6614.             {
  6615.                 // Spawn Check
  6616.                 if (!pEntity->HasGunGameImmunity())
  6617.                 {
  6618.                     return true;
  6619.                 }
  6620.             }
  6621.         }
  6622.     }
  6623.  
  6624.     // They must have failed a requirement
  6625.     return false;
  6626. }
  6627.  
  6628. void CLegitBot::DoTrigger(CUserCmd* pCmd)
  6629. {
  6630.     IClientEntity* pLocal = hackManager.pLocal();
  6631.  
  6632.     // Don't triggerbot with the knife..
  6633.     CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  6634.     if (pWeapon)
  6635.     {
  6636.         if (pWeapon->GetAmmoInClip() == 0 || !GameUtils::IsBallisticWeapon(pWeapon))
  6637.         {
  6638.             return;
  6639.         }
  6640.     }
  6641.     else
  6642.         return;
  6643.  
  6644.     // Triggerbot
  6645.     // Get the view with the recoil
  6646.     Vector ViewAngles;
  6647.     Interfaces::Engine->GetViewAngles(ViewAngles);
  6648.     ViewAngles += pLocal->localPlayerExclusive()->GetAimPunchAngle() * 2.f;
  6649.  
  6650.     // Build a ray going fowards at that angle
  6651.     Vector fowardVec;
  6652.     AngleVectors(ViewAngles, &fowardVec);
  6653.     fowardVec *= 10000;
  6654.  
  6655.     // Get ray start / end
  6656.     Vector start = pLocal->GetOrigin() + pLocal->GetViewOffset();
  6657.     Vector end = start + fowardVec, endScreen;
  6658.  
  6659.     trace_t Trace;
  6660.     UTIL_TraceLine(start, end, MASK_SOLID, pLocal, 0, &Trace);
  6661.  
  6662.     if (Trace.m_pEnt && 0 < Trace.hitgroup <= 7)
  6663.     {
  6664.         if (TargetMeetsTriggerRequirements(Trace.m_pEnt))
  6665.         {
  6666.             pCmd->buttons |= IN_ATTACK;
  6667.         }
  6668.     }
  6669.  
  6670.     // Auto Pistol
  6671.     static bool WasFiring = false;
  6672.     CSWeaponInfo* WeaponInfo = pWeapon->GetCSWpnData();
  6673.     if (!WeaponInfo->m_IsFullAuto && Menu::Window.LegitBotTab.AimbotAutoPistol.GetState())
  6674.     {
  6675.         if (pCmd->buttons & IN_ATTACK)
  6676.         {
  6677.             if (WasFiring)
  6678.             {
  6679.                 pCmd->buttons &= ~IN_ATTACK;
  6680.             }
  6681.         }
  6682.  
  6683.         WasFiring = pCmd->buttons & IN_ATTACK ? true : false;
  6684.     }
  6685. }
  6686.  
  6687. bool CLegitBot::TargetMeetsRequirements(IClientEntity* pEntity)
  6688. {
  6689.     // Is a valid player
  6690.     if (pEntity && pEntity->IsDormant() == false && pEntity->IsAlive() && pEntity->GetIndex() != hackManager.pLocal()->GetIndex())
  6691.     {
  6692.         // Entity Type checks
  6693.         ClientClass* pClientClass = pEntity->GetClientClass();
  6694.         player_info_t pinfo;
  6695.         if (pClientClass->m_ClassID == (int)CSGOClassID::CCSPlayer && Interfaces::Engine->GetPlayerInfo(pEntity->GetIndex(), &pinfo))
  6696.         {
  6697.             // Team Check
  6698.             if (pEntity->GetTeamNum() != hackManager.pLocal()->GetTeamNum() || Menu::Window.LegitBotTab.AimbotFriendlyFire.GetState())
  6699.             {
  6700.                 // Spawn Check
  6701.                 if (!pEntity->HasGunGameImmunity() && GameUtils::IsVisible(hackManager.pLocal(), pEntity, HitBox))
  6702.                 {
  6703.                     return true;
  6704.                 }
  6705.             }
  6706.         }
  6707.     }
  6708.  
  6709.     // They must have failed a requirement
  6710.     return false;
  6711. }
  6712.  
  6713. float CLegitBot::FovToPlayer(Vector ViewOffSet, Vector View, IClientEntity* pEntity, int aHitBox)
  6714. {
  6715.     // Anything past 180 degrees is just going to wrap around
  6716.     CONST FLOAT MaxDegrees = 180.0f;
  6717.  
  6718.     // Get local angles
  6719.     Vector Angles = View;
  6720.  
  6721.     // Get local view / eye position
  6722.     Vector Origin = ViewOffSet;
  6723.  
  6724.     // Create and intiialize vectors for calculations below
  6725.     Vector Delta(0, 0, 0);
  6726.     //Vector Origin(0, 0, 0);
  6727.     Vector Forward(0, 0, 0);
  6728.  
  6729.     // Convert angles to normalized directional forward vector
  6730.     AngleVectors(Angles, &Forward);
  6731.     Vector AimPos = GetHitboxPosition(pEntity, aHitBox);
  6732.     // Get delta vector between our local eye position and passed vector
  6733.     VectorSubtract(AimPos, Origin, Delta);
  6734.     //Delta = AimPos - Origin;
  6735.  
  6736.     // Normalize our delta vector
  6737.     Normalize(Delta, Delta);
  6738.  
  6739.     // Get dot product between delta position and directional forward vectors
  6740.     FLOAT DotProduct = Forward.Dot(Delta);
  6741.  
  6742.     // Time to calculate the field of view
  6743.     return (acos(DotProduct) * (MaxDegrees / PI));
  6744. }
  6745.  
  6746. int CLegitBot::GetTargetCrosshair()
  6747. {
  6748.     // Target selection
  6749.     SyncWeaponSettings();
  6750.     int target = -1;
  6751.     float minFoV = FoV;
  6752.  
  6753.     IClientEntity* pLocal = hackManager.pLocal();
  6754.     Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  6755.     Vector View; Interfaces::Engine->GetViewAngles(View);
  6756.     View += pLocal->localPlayerExclusive()->GetAimPunchAngle() * 2.f;
  6757.  
  6758.     for (int i = 0; i < Interfaces::EntList->GetHighestEntityIndex(); i++)
  6759.     {
  6760.         IClientEntity* pEntity = Interfaces::EntList->GetClientEntity(i);
  6761.         if (TargetMeetsRequirements(pEntity))
  6762.         {
  6763.             int NewHitBox = HitBox;
  6764.             if (NewHitBox >= 0)
  6765.             {
  6766.                 float fov = FovToPlayer(ViewOffset, View, pEntity, 0);
  6767.                 if (fov < minFoV)
  6768.                 {
  6769.                     minFoV = fov;
  6770.                     target = i;
  6771.                 }
  6772.             }
  6773.         }
  6774.     }
  6775.  
  6776.     return target;
  6777. }
  6778.  
  6779. bool CLegitBot::AimAtPoint(IClientEntity* pLocal, Vector point, CUserCmd* pCmd)
  6780. {
  6781.     // Get the full angles
  6782.     if (point.Length() == 0) return false;
  6783.  
  6784.     Vector angles;
  6785.     Vector src = pLocal->GetOrigin() + pLocal->GetViewOffset();
  6786.  
  6787.     CalcAngle(src, point, angles);
  6788.     GameUtils::NormaliseViewAngle(angles);
  6789.  
  6790.     if (angles[0] != angles[0] || angles[1] != angles[1])
  6791.     {
  6792.         return false;
  6793.     }
  6794.  
  6795.     if (RecoilControl)
  6796.     {
  6797.         Vector AimPunch = pLocal->localPlayerExclusive()->GetAimPunchAngle();
  6798.         if (AimPunch.Length2D() > 0 && AimPunch.Length2D() < 150)
  6799.         {
  6800.             angles -= AimPunch * 2;
  6801.             GameUtils::NormaliseViewAngle(angles);
  6802.         }
  6803.     }
  6804.  
  6805.     IsLocked = true;
  6806.     //-----------------------------------------------
  6807.  
  6808.     Vector shit = angles - pCmd->viewangles;
  6809.     bool v = false;
  6810.  
  6811.     if (shit.Length() > Speed)
  6812.     {
  6813.         Normalize(shit, shit);
  6814.         shit *= Speed;
  6815.     }
  6816.     else
  6817.     {
  6818.         v = true;
  6819.     }
  6820.  
  6821.     pCmd->viewangles += shit;
  6822.     Interfaces::Engine->SetViewAngles(pCmd->viewangles);
  6823.  
  6824.     return v;
  6825. }
  6826. /*
  6827. Syn's AYYWAREFramework 2015
  6828. */
  6829.  
  6830. #pragma once
  6831.  
  6832. #include "Hacks.h"
  6833.  
  6834. class CLegitBot : public CHack
  6835. {
  6836. public:
  6837.         void Init();
  6838. void Draw();
  6839. void Move(CUserCmd* pCmd);
  6840. private:
  6841.         // Targetting
  6842.         int GetTargetCrosshair();
  6843. bool TargetMeetsRequirements(IClientEntity* pEntity);
  6844. float FovToPlayer(Vector ViewOffSet, Vector View, IClientEntity* pEntity, int HitBox);
  6845. bool AimAtPoint(IClientEntity* pLocal, Vector point, CUserCmd* pCmd);
  6846.  
  6847. void SyncWeaponSettings();
  6848.  
  6849. // Functionality
  6850. void DoAimbot(CUserCmd* pCmd);
  6851. void DoTrigger(CUserCmd* pCmd);
  6852.  
  6853. // Aimbot
  6854. bool IsLocked;
  6855. int TargetID;
  6856. int HitBox;
  6857. Vector AimPoint;
  6858.  
  6859. float Speed;
  6860. float FoV;
  6861. bool RecoilControl;
  6862.  
  6863. };/*
  6864. Syn's AYYWAREFramework 2015
  6865. */
  6866.  
  6867. #pragma once
  6868.  
  6869. #include "MiscDefinitions.h"
  6870. #include "ClientRecvProps.h"
  6871. #include "offsets.h"
  6872. #include "Vector.h"
  6873. #include "MiscClasses.h"
  6874. #include "Vector2D.h"
  6875.  
  6876.  
  6877. class IMaterial
  6878. {
  6879.     public:
  6880.         const char* GetName()
  6881.         {
  6882.  
  6883.         typedef const char*(__thiscall * oGetName)(PVOID);
  6884.                 return call_vfunc<oGetName>(this, Offsets::VMT::Material_GetName)(this);
  6885.         }
  6886.  
  6887. void SetMaterialVarFlag(MaterialVarFlags_t flag, bool value)
  6888. {
  6889.     typedef void(__thiscall * oSetMatFlag)(PVOID, MaterialVarFlags_t, bool);
  6890.     return call_vfunc<oSetMatFlag>(this, Offsets::VMT::Material_SetMaterialVarFlag)(this, flag, value);
  6891. }
  6892.  
  6893. bool GetMaterialVarFlag(MaterialVarFlags_t flag)
  6894. {
  6895.     typedef bool(__thiscall * oGetMatFlag)(PVOID, MaterialVarFlags_t);
  6896.     return call_vfunc<oGetMatFlag>(this, Offsets::VMT::Material_GetMaterialVarFlag)(this, flag);
  6897. }
  6898.  
  6899. void AlphaModulate(float a)
  6900. {
  6901.     typedef void(__thiscall * oAlphaModulate)(PVOID, float);
  6902.     return call_vfunc<oAlphaModulate>(this, Offsets::VMT::Material_AlphaModulate)(this, a);
  6903. }
  6904.  
  6905. void ColorModulate(float r, float g, float b)
  6906. {
  6907.     typedef void(__thiscall * oColorModulate)(PVOID, float, float, float);
  6908.     return call_vfunc<oColorModulate>(this, Offsets::VMT::Material_ColorModulate)(this, r, g, b);
  6909. }
  6910.  
  6911. void IncrementReferenceCount(void)
  6912. {
  6913.     typedef void(__thiscall * oIncrementReferenceCount)(PVOID);
  6914.     return call_vfunc<oIncrementReferenceCount>(this, Offsets::VMT::Material_IncrementReferenceCount)(this);
  6915. }
  6916. };
  6917.  
  6918. class CMaterialSystem
  6919. {
  6920.     public:
  6921.         IMaterial* FindMaterial(char const* pMaterialName, const char* pTextureGroupName, bool complain = true, const char* pComplainPrefix = NULL)
  6922.         {
  6923.  
  6924.         typedef IMaterial*(__thiscall* oFindMaterial)(PVOID, char const*, char const*, bool, char const*);
  6925.                 return call_vfunc<oFindMaterial>(this, Offsets::VMT::MaterialSystem_FindMaterial)(this, pMaterialName, pTextureGroupName, complain, pComplainPrefix);
  6926.         }
  6927.  
  6928. IMaterial* CreateMaterial(const char* pMaterialName, KeyValues* pVMTKeyValues)
  6929. {
  6930.     typedef IMaterial*(__thiscall * oCreateMaterial)(PVOID, const char*, KeyValues*);
  6931.     return call_vfunc<oCreateMaterial>(this, Offsets::VMT::MaterialSystem_CreateMaterial)(this, pMaterialName, pVMTKeyValues);
  6932. }
  6933. };
  6934.  
  6935. class IVModelRender
  6936. {
  6937.     public:
  6938.         void ForcedMaterialOverride(IMaterial* material, OverrideType_t type = OVERRIDE_NORMAL, int idk = NULL)
  6939.     {
  6940.         typedef void(__thiscall * Fn)(void*, IMaterial*, OverrideType_t, int);
  6941.         return call_vfunc<Fn>(this, Offsets::VMT::ModelRender_ForcedMaterialOverride)(this, material, type, idk);
  6942.     }
  6943.  
  6944. };
  6945.  
  6946. class CModelInfo
  6947. {
  6948.     public:
  6949.         int GetModelIndex(const char* name)
  6950.         {
  6951.  
  6952.         typedef int (__thiscall* oGetModelName)(PVOID, const char*);
  6953.                 return call_vfunc<oGetModelName>(this, 2)(this, name);
  6954.         }
  6955. const char* GetModelName(const model_t * mod)
  6956.         {
  6957.                 typedef const char*(__thiscall * oGetModelName)(PVOID, const model_t *);
  6958.                 return call_vfunc<oGetModelName>(this, Offsets::VMT::ModelInfo_GetModelName)(this, mod);
  6959. }
  6960.  
  6961. studiohdr_t* GetStudiomodel(const model_t* mod)
  6962. {
  6963.     typedef studiohdr_t *(__stdcall * oGetStudiomodel)(const model_t*);
  6964.     return call_vfunc<oGetStudiomodel>(this, Offsets::VMT::ModelInfo_GetStudiomodel)(mod);
  6965. }
  6966. };
  6967.  
  6968. class CVRenderView
  6969. {
  6970.     public:
  6971.         void SetBlend(float alpha)
  6972.     {
  6973.         typedef void(__thiscall * oDrawModelExecute)(PVOID, float);
  6974.         return call_vfunc<oDrawModelExecute>(this, Offsets::VMT::RenderView_SetBlend)(this, alpha);
  6975.     }
  6976.  
  6977.     void SetColorModulation(float const* colors)
  6978.         {
  6979.  
  6980.         typedef void(__thiscall* oDrawModelExecute)(PVOID, float const*);
  6981.                 return call_vfunc<oDrawModelExecute>(this, Offsets::VMT::RenderView_SetColorModulation)(this, colors);
  6982.         }
  6983. };#include "MathFunctions.h"
  6984.  
  6985. void AngleVectors(const Vector &angles, Vector* forward)
  6986. {
  6987.     Assert(s_bMathlibInitialized);
  6988.     Assert(forward);
  6989.  
  6990.     float sp, sy, cp, cy;
  6991.  
  6992.     sy = sin(DEG2RAD(angles[1]));
  6993.     cy = cos(DEG2RAD(angles[1]));
  6994.  
  6995.     sp = sin(DEG2RAD(angles[0]));
  6996.     cp = cos(DEG2RAD(angles[0]));
  6997.  
  6998.     forward->x = cp * cy;
  6999.     forward->y = cp * sy;
  7000.     forward->z = -sp;
  7001. }
  7002.  
  7003. void VectorTransform(const Vector in1, float in2[3][4], Vector &out)
  7004. {
  7005.         out[0] = DotProduct(in1, Vector(in2[0][0], in2[0][1], in2[0][2])) + in2[0][3];
  7006.         out[1] = DotProduct(in1, Vector(in2[1][0], in2[1][1], in2[1][2])) + in2[1][3];
  7007.         out[2] = DotProduct(in1, Vector(in2[2][0], in2[2][1], in2[2][2])) + in2[2][3];
  7008. }
  7009.  
  7010. void SinCos(float a, float* s, float* c)
  7011. {
  7012.     *s = sin(a);
  7013.     *c = cos(a);
  7014. }
  7015.  
  7016. void VectorAngles(Vector forward, Vector &angles)
  7017. {
  7018.     float tmp, yaw, pitch;
  7019.  
  7020.     if (forward[2] == 0 && forward[0] == 0)
  7021.     {
  7022.         yaw = 0;
  7023.  
  7024.         if (forward[2] > 0)
  7025.             pitch = 90;
  7026.         else
  7027.             pitch = 270;
  7028.     }
  7029.     else
  7030.     {
  7031.         yaw = (atan2(forward[1], forward[0]) * 180 / PI);
  7032.  
  7033.         if (yaw < 0)
  7034.             yaw += 360;
  7035.  
  7036.         tmp = sqrt(forward[0] * forward[0] + forward[1] * forward[1]);
  7037.         pitch = (atan2(-forward[2], tmp) * 180 / PI);
  7038.  
  7039.         if (pitch < 0)
  7040.             pitch += 360;
  7041.     }
  7042.  
  7043.     if (pitch > 180)
  7044.         pitch -= 360;
  7045.     else if (pitch < -180)
  7046.         pitch += 360;
  7047.  
  7048.     if (yaw > 180)
  7049.         yaw -= 360;
  7050.     else if (yaw < -180)
  7051.         yaw += 360;
  7052.  
  7053.     if (pitch > 89)
  7054.         pitch = 89;
  7055.     else if (pitch < -89)
  7056.         pitch = -89;
  7057.  
  7058.     if (yaw > 180)
  7059.         yaw = 180;
  7060.     else if (yaw < -180)
  7061.         yaw = -180;
  7062.  
  7063.     angles[0] = pitch;
  7064.     angles[1] = yaw;
  7065.     angles[2] = 0;
  7066. }
  7067.  
  7068. void AngleVectors(const Vector &angles, Vector* forward, Vector* right, Vector* up)
  7069. {
  7070.     float sr, sp, sy, cr, cp, cy;
  7071.  
  7072.     SinCos(DEG2RAD(angles[1]), &sy, &cy);
  7073.     SinCos(DEG2RAD(angles[0]), &sp, &cp);
  7074.     SinCos(DEG2RAD(angles[2]), &sr, &cr);
  7075.  
  7076.     if (forward)
  7077.     {
  7078.         forward->x = cp * cy;
  7079.         forward->y = cp * sy;
  7080.         forward->z = -sp;
  7081.     }
  7082.  
  7083.     if (right)
  7084.     {
  7085.         right->x = (-1 * sr * sp * cy + -1 * cr * -sy);
  7086.         right->y = (-1 * sr * sp * sy + -1 * cr * cy);
  7087.         right->z = -1 * sr * cp;
  7088.     }
  7089.  
  7090.     if (up)
  7091.     {
  7092.         up->x = (cr * sp * cy + -sr * -sy);
  7093.         up->y = (cr * sp * sy + -sr * cy);
  7094.         up->z = cr * cp;
  7095.     }
  7096. }
  7097.  
  7098. void Normalize(Vector &vIn, Vector &vOut)
  7099. {
  7100.     float flLen = vIn.Length();
  7101.     if (flLen == 0)
  7102.     {
  7103.         vOut.Init(0, 0, 1);
  7104.         return;
  7105.     }
  7106.     flLen = 1 / flLen;
  7107.     vOut.Init(vIn.x * flLen, vIn.y * flLen, vIn.z * flLen);
  7108. }
  7109.  
  7110.  
  7111. void CalcAngle(Vector src, Vector dst, Vector &angles)
  7112. {
  7113.     Vector delta = src - dst;
  7114.     double hyp = delta.Length2D();
  7115.     angles.y = (atan(delta.y / delta.x) * 57.295779513082f);
  7116.     angles.x = (atan(delta.z / hyp) * 57.295779513082f);
  7117.     angles[2] = 0.00;
  7118.  
  7119.     if (delta.x >= 0.0)
  7120.         angles.y += 180.0f;
  7121. }/*
  7122. Syn's AYYWAREFramework 2015
  7123. */
  7124.  
  7125. #pragma once
  7126.  
  7127. #include "Vector.h"
  7128.  
  7129. #include <stdint.h>
  7130.  
  7131. #define PI 3.14159265358979323846f
  7132. #define DEG2RAD( x ) ( ( float )( x ) * ( float )( ( float )( PI ) / 180.0f ) )
  7133. #define RAD2DEG( x ) ( ( float )( x ) * ( float )( 180.0f / ( float )( PI ) ) )
  7134. #define RADPI 57.295779513082f
  7135.  
  7136. void AngleVectors(const Vector &angles, Vector* forward);
  7137. void VectorTransform(const Vector in1, float in2[3][4], Vector &out);
  7138. void SinCos(float a, float* s, float* c);
  7139. void VectorAngles(Vector forward, Vector &angles);
  7140. void AngleVectors(const Vector &angles, Vector* forward, Vector* right, Vector* up);
  7141. void Normalize(Vector &vIn, Vector &vOut);
  7142. void CalcAngle(Vector src, Vector dst, Vector &angles);
  7143. /*
  7144. Syn's AYYWAREFramework 2015
  7145. */
  7146.  
  7147. #pragma once
  7148.  
  7149. #include "GUI.h"
  7150. #include "Controls.h"
  7151.  
  7152. class CRageBotTab : public CTab
  7153. {
  7154. public:
  7155.         void Setup();
  7156.  
  7157. // Master Switch
  7158. CLabel ActiveLabel;
  7159. CCheckBox Active;
  7160.  
  7161. // Aimbot Settings
  7162. CGroupBox AimbotGroup;
  7163. CCheckBox AimbotEnable;
  7164. CCheckBox AimbotAutoFire;
  7165. CSlider AimbotFov;
  7166. CCheckBox AimbotSilentAim;
  7167. CCheckBox AimbotPSilent;
  7168. CCheckBox AimbotAutoPistol;
  7169. CCheckBox AimbotAimStep;
  7170. CCheckBox AimbotKeyPress;
  7171. CKeyBind AimbotKeyBind;
  7172. CCheckBox AimbotChicken;
  7173.  
  7174. // Target Selection Settings
  7175. CGroupBox TargetGroup;
  7176. CComboBox TargetSelection;
  7177. CCheckBox TargetFriendlyFire;
  7178. CComboBox TargetHitbox;
  7179. CComboBox TargetHitscan;
  7180.  
  7181. // Accuracy Settings
  7182. CGroupBox AccuracyGroup;
  7183. CCheckBox AccuracySpread;
  7184. CCheckBox AccuracyRecoil;
  7185. CCheckBox AccuracyAutoWall;
  7186. CSlider AccuracyMinimumDamage;
  7187. CCheckBox AccuracyAutoStop;
  7188. CCheckBox AccuracyAutoCrouch;
  7189. CCheckBox AccuracyAutoScope;
  7190. CCheckBox AccuracySpreadLimit;
  7191. CSlider AccuracyMinimumSpread;
  7192. CCheckBox AccuracyAngleFix;
  7193.  
  7194.  
  7195. // Anti-Aim Settings
  7196. CGroupBox AntiAimGroup;
  7197. CCheckBox AntiAimEnable;
  7198. CComboBox AntiAimPitch;
  7199. CComboBox AntiAimYaw;
  7200. };
  7201.  
  7202. class CLegitBotTab : public CTab
  7203. {
  7204. public:
  7205.         void Setup();
  7206.  
  7207. // Master Switch
  7208. CLabel ActiveLabel;
  7209. CCheckBox Active;
  7210.  
  7211. // Aimbot Settings
  7212. CGroupBox AimbotGroup;
  7213. CCheckBox AimbotEnable;
  7214. CCheckBox AimbotAutoFire;
  7215. CCheckBox AimbotFriendlyFire;
  7216. CCheckBox AimbotKeyPress;
  7217. CKeyBind AimbotKeyBind;
  7218. CCheckBox AimbotAutoPistol;
  7219.  
  7220. // Main
  7221. CGroupBox TriggerGroup;
  7222. CCheckBox TriggerEnable;
  7223. CCheckBox TriggerKeyPress;
  7224. CKeyBind TriggerKeyBind;
  7225. CSlider TriggerDelay;
  7226.  
  7227. // Main
  7228. CGroupBox WeaponMainGroup;
  7229. CSlider WeaponMainSpeed;
  7230. CSlider WeaponMainFoV;
  7231. CCheckBox WeaponMainRecoil;
  7232. CComboBox WeaponMainHitbox;
  7233.  
  7234. // Pistol
  7235. CGroupBox WeaponPistGroup;
  7236. CSlider WeaponPistSpeed;
  7237. CSlider WeaponPistFoV;
  7238. CCheckBox WeaponPistRecoil;
  7239. CComboBox WeaponPistHitbox;
  7240.  
  7241. // Sniper
  7242. CGroupBox WeaponSnipGroup;
  7243. CSlider WeaponSnipSpeed;
  7244. CSlider WeaponSnipFoV;
  7245. CCheckBox WeaponSnipRecoil;
  7246. CComboBox WeaponSnipHitbox;
  7247.  
  7248. };
  7249.  
  7250. class CVisualTab : public CTab
  7251. {
  7252. public:
  7253.         void Setup();
  7254.  
  7255. // Master Switch
  7256. CLabel ActiveLabel;
  7257. CCheckBox Active;
  7258.  
  7259. // Options Settings
  7260. CGroupBox OptionsGroup;
  7261. CCheckBox OptionsBox;
  7262. CCheckBox OptionsName;
  7263. CCheckBox OptionsHealth;
  7264. CCheckBox OptionsWeapon;
  7265. CCheckBox OptionsInfo;
  7266. CComboBox OptionsChams;
  7267. CCheckBox OptionsSkeleton;
  7268. CCheckBox OptionsAimSpot;
  7269. CCheckBox OptionsCompRank;
  7270.  
  7271. // Filters Settings
  7272. CGroupBox FiltersGroup;
  7273. CCheckBox FiltersAll;
  7274. CCheckBox FiltersPlayers;
  7275. CCheckBox FiltersEnemiesOnly;
  7276. CCheckBox FiltersWeapons;
  7277. CCheckBox FiltersChickens;
  7278. CCheckBox FiltersC4;
  7279.  
  7280. // Other Settings
  7281. CGroupBox OtherGroup;
  7282. CCheckBox OtherCrosshair;
  7283. CComboBox OtherRecoilCrosshair;
  7284. CCheckBox OtherRadar;
  7285. CCheckBox OtherNoVisualRecoil;
  7286. CCheckBox OtherNoSky;
  7287. CCheckBox OtherNoFlash;
  7288. CCheckBox OtherNoSmoke;
  7289. CComboBox OtherNoHands;
  7290. CCheckBox OtherAutoJump;
  7291. CCheckBox OtherAutoStrafe;
  7292. CCheckBox OtherSafeMode;
  7293. CComboBox OtherChatSpam;
  7294. CKeyBind OtherAirStuck;
  7295. CCheckBox OtherSpectators;
  7296. };
  7297.  
  7298. class CMiscTab : public CTab
  7299. {
  7300. public:
  7301.         void Setup();
  7302.  
  7303. // Fake Lag Settings
  7304. CGroupBox FakeLagGroup;
  7305. CCheckBox FakeLagEnable;
  7306. CSlider FakeLagAmount;
  7307. CCheckBox FakeLagWhileShooting;
  7308.  
  7309. // Knife Changer/Skin Changer
  7310. CGroupBox KnifeGroup;
  7311. CCheckBox KnifeEnable;
  7312. CComboBox KnifeModel;
  7313. CComboBox KnifeSkin;
  7314. CComboBox M41SSkin;
  7315. CComboBox M4A4Skin;
  7316. CComboBox AK47Skin;
  7317. CComboBox AWPSkin;
  7318. CComboBox GLOCKSkin;
  7319. CComboBox USPSSkin;
  7320. CComboBox DEAGLESkin;
  7321. CComboBox MAGNUMSkin;
  7322. CButton KnifeApply;
  7323. };
  7324.  
  7325. class AimWareWindow : public CWindow
  7326. {
  7327. public:
  7328.         void Setup();
  7329.  
  7330. CRageBotTab RageBotTab;
  7331. CLegitBotTab LegitBotTab;
  7332. CVisualTab VisualsTab;
  7333. CMiscTab MiscTab;
  7334.  
  7335. CButton SaveButton;
  7336. CButton LoadButton;
  7337. CButton UnloadButton;
  7338. };
  7339.  
  7340. namespace Menu
  7341. {
  7342.     void SetupMenu();
  7343.     void DoUIFrame();
  7344.  
  7345.         extern AimWareWindow Window;
  7346. };/*
  7347. Syn's AYYWAREFramework
  7348. */
  7349. #include "Utilities.h"
  7350.  
  7351. #define AimWare_META_GAME "Counter-Strike: Global Offensive"
  7352.  
  7353. void PrintMetaHeader()
  7354. {
  7355.     printf("                                  Ayy");
  7356.     Utilities::SetConsoleColor(FOREGROUND_INTENSE_GREEN);
  7357.     printf("Ware\n");
  7358.     Utilities::SetConsoleColor(FOREGROUND_WHITE);
  7359.     Utilities::Log("Build %s", __DATE__);
  7360.     Utilities::Log("Setting Up AYYWAREfor %s", AimWare_META_GAME);
  7361. }/*
  7362. Syn's AYYWAREFramework 2015
  7363. */
  7364.  
  7365. #pragma once
  7366.  
  7367. #include "MiscDefinitions.h"
  7368. #include "ClientRecvProps.h"
  7369. #include "offsets.h"
  7370. #include "Vector.h"
  7371. #include "bspflags.h"
  7372.  
  7373. // Entity List
  7374. class IClientEntityList
  7375. {
  7376.     public:
  7377.         virtual void Function0();
  7378.     virtual void Function1();
  7379.     virtual void Function2();
  7380.     virtual IClientEntity* GetClientEntity(int entnum);
  7381.     virtual IClientEntity* GetClientEntityFromHandle(HANDLE hEnt) = 0;
  7382.         virtual int NumberOfEntities(bool bIncludeNonNetworkable) = 0;
  7383.         virtual int GetHighestEntityIndex(void);
  7384.     virtual void SetMaxEntities(int maxents);
  7385.     virtual int GetMaxEntities();
  7386. };
  7387.  
  7388. // Panels
  7389. class IPanel
  7390. {
  7391.     public:
  7392.         const char* GetName(unsigned int vguiPanel)
  7393.         {
  7394.  
  7395.         typedef const char* (__thiscall * OriginalFn)(PVOID, unsigned int);
  7396.                 return call_vfunc<OriginalFn>(this, Offsets::VMT::Panel_GetName)(this, vguiPanel);
  7397.         }
  7398. };
  7399.  
  7400. // Colors
  7401. class Color
  7402. {
  7403.     public:
  7404.         // constructors
  7405.         Color()
  7406.     {
  7407.         *((int*)this) = 0;
  7408.     }
  7409.     Color(int r, int g, int b)
  7410.     {
  7411.         SetColor(r, g, b, 0);
  7412.     }
  7413.     Color(int r, int g, int b, int a)
  7414.     {
  7415.         SetColor(r, g, b, a);
  7416.     }
  7417.     void SetColor(int r, int g, int b, int a = 0)
  7418.     {
  7419.         _color[0] = (unsigned char)r;
  7420.         _color[1] = (unsigned char)g;
  7421.         _color[2] = (unsigned char)b;
  7422.         _color[3] = (unsigned char)a;
  7423.     }
  7424.  
  7425.     void GetColor(int &r, int &g, int &b, int &a) const
  7426.         {
  7427.  
  7428.         r = _color[0];
  7429.                 g = _color[1];
  7430.                 b = _color[2];
  7431.                 a = _color[3];
  7432.         }
  7433.  
  7434. void SetRawColor(int color32)
  7435. {
  7436.     *((int*)this) = color32;
  7437. }
  7438.  
  7439. int GetRawColor() const
  7440.         {
  7441.                 return *((int*)this);
  7442. }
  7443.  
  7444. inline int r() const    { return _color[0]; }
  7445.         inline int g() const    { return _color[1]; }
  7446.         inline int b() const    { return _color[2]; }
  7447.         inline int a() const    { return _color[3]; }
  7448.  
  7449.         void SetAlpha(int a) { _color[0] = (unsigned char)a; }
  7450. int GetAlpha() { return _color[0]; }
  7451.  
  7452.  
  7453. unsigned char &operator[] (int index)
  7454. {
  7455.     return _color[index];
  7456. }
  7457.  
  7458. const unsigned char &operator[] (int index) const
  7459.         {
  7460.                 return _color[index];
  7461.         }
  7462.  
  7463.         bool operator ==(const Color &rhs) const
  7464.         {
  7465.                 return (*((int*)this) == *((int *)&rhs));
  7466. }
  7467.  
  7468. bool operator !=(const Color &rhs) const
  7469.         {
  7470.                 return !(operator ==(rhs));
  7471.         }
  7472.  
  7473.         Color &operator=(const Color &rhs)
  7474. {
  7475.     SetRawColor(rhs.GetRawColor());
  7476.     return *this;
  7477. }
  7478.  
  7479. private:
  7480.         unsigned char _color[4];
  7481. };
  7482.  
  7483. // Debug Overlay
  7484. class IVDebugOverlay
  7485. {
  7486.     public:
  7487.         virtual void AddEntityTextOverlay(int ent_index, int line_offset, float duration, int r, int g, int b, int a, const char* format, ...) = 0;
  7488.     virtual void AddBoxOverlay(const Vector& origin, const Vector& mins, const Vector& max, Vector const& orientation, int r, int g, int b, int a, float duration) = 0;
  7489.     virtual void AddSphereOverlay(const Vector& vOrigin, float flRadius, int nTheta, int nPhi, int r, int g, int b, int a, float flDuration) = 0;
  7490.     virtual void AddTriangleOverlay(const Vector& p1, const Vector& p2, const Vector& p3, int r, int g, int b, int a, bool noDepthTest, float duration) = 0;
  7491.     virtual void AddLineOverlay(const Vector& origin, const Vector& dest, int r, int g, int b, bool noDepthTest, float duration) = 0;
  7492.     virtual void AddTextOverlay(const Vector& origin, float duration, const char* format, ...) = 0;
  7493.     virtual void AddTextOverlay(const Vector& origin, int line_offset, float duration, const char* format, ...) = 0;
  7494.     virtual void AddScreenTextOverlay(float flXPos, float flYPos, float flDuration, int r, int g, int b, int a, const char* text) = 0;
  7495.     virtual void AddSweptBoxOverlay(const Vector& start, const Vector& end, const Vector& mins, const Vector& max, const Vector & angles, int r, int g, int b, int a, float flDuration) = 0;
  7496.     virtual void AddGridOverlay(const Vector& origin) = 0;
  7497.         virtual void AddCoordFrameOverlay(const matrix3x4& frame, float flScale, int vColorTable[3][3] = NULL) = 0;
  7498.  
  7499.         virtual int ScreenPosition(const Vector& point, Vector& screen) = 0;
  7500.         virtual int ScreenPosition(float flXPos, float flYPos, Vector& screen) = 0;
  7501.  
  7502.         virtual void* GetFirst(void) = 0;
  7503.         virtual void* GetNext(void* current) = 0;
  7504.         virtual void ClearDeadOverlays(void) = 0;
  7505.         virtual void ClearAllOverlays() = 0;
  7506.  
  7507.         virtual void AddTextOverlayRGB(const Vector& origin, int line_offset, float duration, float r, float g, float b, float alpha, const char* format, ...) = 0;
  7508.     virtual void AddTextOverlayRGB(const Vector& origin, int line_offset, float duration, int r, int g, int b, int a, const char* format, ...) = 0;
  7509.  
  7510.     virtual void AddLineOverlayAlpha(const Vector& origin, const Vector& dest, int r, int g, int b, int a, bool noDepthTest, float duration) = 0;
  7511.     virtual void AddBoxOverlay2(const Vector& origin, const Vector& mins, const Vector& max, Vector const& orientation, const Color& faceColor, const Color& edgeColor, float duration) = 0;
  7512.  
  7513.     virtual void PurgeTextOverlays() = 0;
  7514. };
  7515.  
  7516. // User Cmd's
  7517. class CUserCmd
  7518. {
  7519.     public:
  7520.         virtual ~CUserCmd() { }; //Destructor 0
  7521.     CUserCmd()
  7522.     {
  7523.         Reset();
  7524.     }
  7525.  
  7526.     void Reset()
  7527.     {
  7528.         command_number = 0;
  7529.         tick_count = 0;
  7530.         viewangles.Init();
  7531.         forwardmove = 0.0f;
  7532.         sidemove = 0.0f;
  7533.         upmove = 0.0f;
  7534.         buttons = 0;
  7535.         impulse = 0;
  7536.         weaponselect = 0;
  7537.         weaponsubtype = 0;
  7538.         random_seed = 0;
  7539.         mousedx = 0;
  7540.         mousedy = 0;
  7541.         headangles.Init();
  7542.         headoffset.Init();
  7543.  
  7544.         hasbeenpredicted = false;
  7545.     }
  7546.  
  7547.     CUserCmd& operator =(const CUserCmd& src)
  7548.         {
  7549.                 if (this == &src)
  7550.                         return *this;
  7551.  
  7552.                 command_number = src.command_number;
  7553.                 tick_count = src.tick_count;
  7554.                 viewangles = src.viewangles;
  7555.                 forwardmove = src.forwardmove;
  7556.                 sidemove = src.sidemove;
  7557.                 upmove = src.upmove;
  7558.                 buttons = src.buttons;
  7559.                 impulse = src.impulse;
  7560.                 weaponselect = src.weaponselect;
  7561.                 weaponsubtype = src.weaponsubtype;
  7562.                 random_seed = src.random_seed;
  7563.                 mousedx = src.mousedx;
  7564.                 mousedy = src.mousedy;
  7565.  
  7566.                 hasbeenpredicted = src.hasbeenpredicted;
  7567.                 headangles = src.headangles;
  7568.                 headoffset = src.headoffset;
  7569.                 return *this;
  7570.         }
  7571.  
  7572.  
  7573.     CUserCmd(const CUserCmd& src)
  7574. {
  7575.     *this = src;
  7576. }
  7577.  
  7578.  
  7579. int command_number;
  7580. int tick_count;
  7581. Vector viewangles;
  7582. Vector aimdirection;
  7583. float forwardmove;
  7584. float sidemove;
  7585. float upmove;
  7586. int buttons;
  7587. BYTE impulse;
  7588. int weaponselect;
  7589. int weaponsubtype;
  7590. int random_seed;
  7591. short mousedx;
  7592. short mousedy;
  7593. bool hasbeenpredicted;
  7594. Vector headangles;
  7595. Vector headoffset;
  7596. };
  7597.  
  7598. class CGlobalVarsBase
  7599. {
  7600.     public:
  7601.         float realtime;
  7602.     int framecount;
  7603.     float absoluteframetime;
  7604.     float absoluteframestarttimestddev;
  7605.     float curtime;
  7606.     float frametime;
  7607.     int maxClients;
  7608.     int tickcount;
  7609.     float interval_per_tick;
  7610.     float interpolation_amount;
  7611.     int simTicksThisFrame;
  7612.     int network_protocol;
  7613.     void* pSaveData;
  7614.     bool m_bClient;
  7615.     int nTimestampNetworkingBase;
  7616.     int nTimestampRandomizeWindow;
  7617. };
  7618.  
  7619. struct Ray_t
  7620. {
  7621.  
  7622.     __declspec(align(16)) Vector m_Start;
  7623.  
  7624.     __declspec(align(16)) Vector m_Delta;
  7625.  
  7626.     __declspec(align(16)) Vector m_StartOffset;
  7627.  
  7628.     __declspec(align(16)) Vector m_Extents;
  7629.     //without your matrix3x4
  7630.     bool m_IsRay;
  7631.     bool m_IsSwept;
  7632.  
  7633.     void Init(Vector& vecStart, Vector& vecEnd)
  7634.     {
  7635.         m_Delta = vecEnd - vecStart;
  7636.  
  7637.         m_IsSwept = (m_Delta.LengthSqr() != 0);
  7638.  
  7639.         m_Extents.x = m_Extents.y = m_Extents.z = 0.0f;
  7640.  
  7641.         m_IsRay = true;
  7642.  
  7643.         m_StartOffset.x = m_StartOffset.y = m_StartOffset.z = 0.0f;
  7644.  
  7645.         m_Start = vecStart;
  7646.     }
  7647. };
  7648.  
  7649. struct cplane_t
  7650. {
  7651.     Vector normal;
  7652.     float dist;
  7653.     BYTE type;
  7654.     BYTE signbits;
  7655.     BYTE pad[2];
  7656. };
  7657.  
  7658. class CBaseTrace
  7659. {
  7660.     public:
  7661.         Vector startpos;
  7662.     Vector endpos;
  7663.     cplane_t plane;
  7664.     float fraction;
  7665.     int contents;
  7666.     unsigned short dispFlags;
  7667.     bool allsolid;
  7668.     bool startsolid;
  7669. };
  7670.  
  7671. struct csurface_t
  7672. {
  7673.     const char* name;
  7674.     short surfaceProps;
  7675.     unsigned short flags;
  7676. };
  7677.  
  7678. class CGameTrace : public CBaseTrace
  7679. {
  7680. public:
  7681.         bool DidHitWorld() const;
  7682. bool DidHitNonWorldEntity() const;
  7683. int GetEntityIndex() const;
  7684. bool DidHit() const;
  7685. public:
  7686.         float fractionleftsolid;
  7687. csurface_t surface;
  7688. int hitgroup;
  7689. short physicsbone;
  7690. unsigned short worldSurfaceIndex;
  7691. IClientEntity* m_pEnt;
  7692. int hitbox;
  7693. char shit[0x24];
  7694. };
  7695.  
  7696. inline bool CGameTrace::DidHit() const
  7697. {
  7698.         return fraction< 1.0f || allsolid || startsolid;
  7699. }
  7700.  
  7701. typedef CGameTrace trace_t;
  7702.  
  7703. enum TraceType_t
  7704. {
  7705.     TRACE_EVERYTHING = 0,
  7706.     TRACE_WORLD_ONLY,
  7707.     TRACE_ENTITIES_ONLY,
  7708.     TRACE_EVERYTHING_FILTER_PROPS,
  7709. };
  7710.  
  7711. class ITraceFilter
  7712. {
  7713.     public:
  7714.         virtual bool ShouldHitEntity(IClientEntity* pEntity, int contentsMask) = 0;
  7715.         virtual TraceType_t GetTraceType() const = 0;
  7716. };
  7717.  
  7718. class CTraceFilter : public ITraceFilter
  7719. {
  7720. public:
  7721.         bool ShouldHitEntity(IClientEntity* pEntityHandle, int contentsMask)
  7722. {
  7723.     return !(pEntityHandle == pSkip);
  7724. }
  7725.  
  7726. TraceType_t GetTraceType() const
  7727.         {
  7728.                 return TRACE_EVERYTHING;
  7729.         }
  7730.  
  7731.         void* pSkip;
  7732. };
  7733.  
  7734. class IEngineTrace
  7735. {
  7736.     public:
  7737.         int GetPointContents(const Vector &vecAbsPosition, int contentsMask = MASK_ALL, IClientEntity** ppEntity = NULL)
  7738.         {
  7739.                 typedef int(__thiscall* fnGetPointContents)(void*, const Vector&, int, IClientEntity**);
  7740.                 return call_vfunc<fnGetPointContents>(this, 0)(this, vecAbsPosition, contentsMask, ppEntity);
  7741.         }
  7742.  
  7743. void TraceRay(const Ray_t &ray, unsigned int fMask, ITraceFilter* pTraceFilter, trace_t* pTrace)
  7744. {
  7745.     typedef void(__thiscall * fnTraceRay)(void*, const Ray_t&, unsigned int, ITraceFilter*, trace_t *);
  7746.     call_vfunc<fnTraceRay>(this, 5)(this, ray, fMask, pTraceFilter, pTrace);
  7747. }
  7748. };
  7749.  
  7750. struct mstudiobbox_t
  7751. {
  7752.     int bone;
  7753.     int group;
  7754.     Vector bbmin;
  7755.     Vector bbmax;
  7756.     int szhitboxnameindex;
  7757.     int unused[8];
  7758.  
  7759.     char* GetHitboxName(void)
  7760.     {
  7761.         if (szhitboxnameindex == 0)
  7762.             return "";
  7763.  
  7764.         return ((char*)this) + szhitboxnameindex;
  7765.     }
  7766. };
  7767. struct mstudiohitboxset_t
  7768. {
  7769.     int sznameindex;
  7770.     inline char* const GetName(void) const { return ((char*)this) + sznameindex; }
  7771. int numhitboxes;
  7772. int hitboxindex;
  7773. inline mstudiobbox_t* GetHitbox(int i) const { return (mstudiobbox_t*)(((byte*)this) + hitboxindex) + i; };
  7774. };
  7775. struct mstudiobone_t
  7776. {
  7777.     int sznameindex;
  7778.     inline char* const GetName(void) const { return ((char*)this) + sznameindex; }
  7779. int parent;
  7780. int bonecontroller[6];
  7781.  
  7782. Vector pos;
  7783. float quat[4];
  7784. Vector rot;
  7785. Vector posscale;
  7786. Vector rotscale;
  7787.  
  7788. matrix3x4 poseToBone;
  7789. float qAlignment[4];
  7790. int flags;
  7791. int proctype;
  7792. int procindex;              // procedural rule
  7793. mutable int physicsbone;    // index into physically simulated bone
  7794. inline void* GetProcedure() const { if (procindex == 0) return NULL; else return  (void*)(((byte*)this) + procindex); };
  7795. int surfacepropidx; // index into string tablefor property name
  7796. inline char* const GetSurfaceProps(void) const { return ((char*)this) + surfacepropidx; }
  7797.         int contents;               // See BSPFlags.h for the contents flags
  7798.  
  7799. int unused[8];              // remove as appropriate
  7800. };
  7801. struct studiohdr_t
  7802. {
  7803.     int id;
  7804.     int version;
  7805.  
  7806.     int checksum;
  7807.  
  7808.     char name[64];
  7809.     int length;
  7810.  
  7811.  
  7812.     Vector eyeposition;
  7813.  
  7814.     Vector illumposition;
  7815.  
  7816.     Vector hull_min;
  7817.     Vector hull_max;
  7818.  
  7819.     Vector view_bbmin;
  7820.     Vector view_bbmax;
  7821.  
  7822.     int flags;
  7823.  
  7824.     int numbones;
  7825.     int boneindex;
  7826.  
  7827.     inline mstudiobone_t *GetBone(int i) const { return (mstudiobone_t*)(((byte*)this) + boneindex) + i; };
  7828. //      inline mstudiobone_t *pBone(int i) const { Assert(i >= 0 && i < numbones); return (mstudiobone_t *)(((byte *)this) + boneindex) + i; };
  7829.  
  7830. int numbonecontrollers;
  7831. int bonecontrollerindex;
  7832.  
  7833. int numhitboxsets;
  7834. int hitboxsetindex;
  7835.  
  7836. mstudiohitboxset_t* GetHitboxSet(int i) const
  7837.         {
  7838.                 return (mstudiohitboxset_t*)(((byte*)this) + hitboxsetindex) + i;
  7839. }
  7840.  
  7841. inline mstudiobbox_t* GetHitbox(int i, int set) const
  7842.         {
  7843.                 mstudiohitboxset_t const* s = GetHitboxSet(set);
  7844.  
  7845.                 if (!s)
  7846.                         return NULL;
  7847.  
  7848.                 return s->GetHitbox(i);
  7849.         }
  7850.  
  7851.         inline int GetHitboxCount(int set) const
  7852.         {
  7853.                 mstudiohitboxset_t const* s = GetHitboxSet(set);
  7854.  
  7855.                 if (!s)
  7856.                         return 0;
  7857.  
  7858.                 return s->numhitboxes;
  7859.         }
  7860.  
  7861.         int numlocalanim;
  7862. int localanimindex;
  7863.  
  7864. int numlocalseq;
  7865. int localseqindex;
  7866.  
  7867. mutable int activitylistversion;
  7868. mutable int eventsindexed;
  7869.  
  7870. int numtextures;
  7871. int textureindex;
  7872.  
  7873. int numcdtextures;
  7874. int cdtextureindex;
  7875.  
  7876. int numskinref;
  7877. int numskinfamilies;
  7878. int skinindex;
  7879.  
  7880. int numbodyparts;
  7881. int bodypartindex;
  7882.  
  7883. int numlocalattachments;
  7884. int localattachmentindex;
  7885.  
  7886. int numlocalnodes;
  7887. int localnodeindex;
  7888. int localnodenameindex;
  7889.  
  7890. int numflexdesc;
  7891. int flexdescindex;
  7892.  
  7893. int numflexcontrollers;
  7894. int flexcontrollerindex;
  7895.  
  7896. int numflexrules;
  7897. int flexruleindex;
  7898.  
  7899. int numikchains;
  7900. int ikchainindex;
  7901.  
  7902. int nummouths;
  7903. int mouthindex;
  7904.  
  7905. int numlocalposeparameters;
  7906. int localposeparamindex;
  7907.  
  7908. int surfacepropindex;
  7909.  
  7910. int keyvalueindex;
  7911. int keyvaluesize;
  7912.  
  7913.  
  7914. int numlocalikautoplaylocks;
  7915. int localikautoplaylockindex;
  7916.  
  7917. float mass;
  7918. int contents;
  7919.  
  7920. int numincludemodels;
  7921. int includemodelindex;
  7922.  
  7923. mutable void* virtualModel;
  7924.  
  7925. int szanimblocknameindex;
  7926. int numanimblocks;
  7927. int animblockindex;
  7928.  
  7929. mutable void* animblockModel;
  7930.  
  7931. int bonetablebynameindex;
  7932.  
  7933. void* pVertexBase;
  7934. void* pIndexBase;
  7935.  
  7936. byte constdirectionallightdot;
  7937.  
  7938. byte rootLOD;
  7939.  
  7940. byte numAllowedRootLODs;
  7941.  
  7942. byte unused[1];
  7943.  
  7944. int unused4;
  7945.  
  7946. int numflexcontrollerui;
  7947. int flexcontrolleruiindex;
  7948. float flVertAnimFixedPointScale;
  7949. int unused3[1];
  7950. int studiohdr2index;
  7951. int unused2[1];
  7952. };
  7953.  
  7954. struct surfacephysicsparams_t
  7955. {
  7956.     float friction;
  7957.     float elasticity; // collision elasticity - used to compute coefficient of restitution
  7958.     float density;    // physical density (in kg / m^3)
  7959.     float thickness;    // material thickness if not solid (sheet materials) in inches
  7960.     float dampening;
  7961. };
  7962.  
  7963. struct surfaceaudioparams_t
  7964. {
  7965.     float reflectivity;            // like elasticity, but how much sound should be reflected by this surface
  7966.     float hardnessFactor;            // like elasticity, but only affects impact sound choices
  7967.     float roughnessFactor;        // like friction, but only affects scrape sound choices  
  7968.     float roughThreshold;            // surface roughness > this causes "rough" scrapes, < this causes "smooth" scrapes
  7969.     float hardThreshold;            // surface hardness > this causes "hard" impacts, < this causes "soft" impacts
  7970.     float hardVelocityThreshold;    // collision velocity > this causes "hard" impacts, < this causes "soft" impacts  
  7971. };
  7972.  
  7973. struct surfacesoundnames_t
  7974. {
  7975.     unsigned short stepleft;
  7976.     unsigned short stepright;
  7977.     unsigned short impactSoft;
  7978.     unsigned short impactHard;
  7979.     unsigned short scrapeSmooth;
  7980.     unsigned short scrapeRough;
  7981.     unsigned short bulletImpact;
  7982.     unsigned short rolling;
  7983.     unsigned short breakSound;
  7984.     unsigned short strainSound;
  7985. };
  7986.  
  7987. struct surfacegameprops_t
  7988. {
  7989.     public:
  7990.         float maxSpeedFactor; //0x0000
  7991.     float jumpFactor; //0x0004
  7992.     char pad00[0x4]; //0x0008
  7993.     float flPenetrationModifier; //0x000C
  7994.     float flDamageModifier; //0x0010
  7995.     unsigned short material; //0x0014
  7996.     char pad01[0x3];
  7997.  
  7998. };//Size=0x0019
  7999.  
  8000. struct surfacedata_t
  8001. {
  8002.     surfacephysicsparams_t physics;
  8003.     surfaceaudioparams_t audio;
  8004.     surfacesoundnames_t sounds;
  8005.     surfacegameprops_t game;
  8006. };
  8007.  
  8008. class IPhysicsSurfaceProps
  8009. {
  8010.     public:
  8011.  
  8012.         surfacedata_t* GetSurfaceData(int surfaceDataIndex)
  8013.     {
  8014.         typedef surfacedata_t*(__thiscall * fnGetSurfaceData)(void*, int);
  8015.         return call_vfunc<fnGetSurfaceData>(this, 5)(this, surfaceDataIndex);
  8016.     }
  8017. };
  8018.  
  8019. class ConVar
  8020. {
  8021.     public:
  8022.         //void SetString(const char *pValue)
  8023.         //{
  8024.         //      typedef void(__thiscall* SetStringFn)(void*, const char *);
  8025.         //      call_vfunc<SetStringFn>(this, 17)(this, pValue);
  8026.         //}
  8027.  
  8028.         void SetString(const char* str)
  8029.         {
  8030.  
  8031.         typedef void(__thiscall* SetStringFn)(void*, const char*);
  8032.                 return call_vfunc<SetStringFn>(this, 13)(this, str);
  8033.         }
  8034.  
  8035. void InternalSetString(const char* str)
  8036. {
  8037.     typedef void(__thiscall * SetStringFn)(void*, const char*);
  8038.     return call_vfunc<SetStringFn>(this, 17)(this, str);
  8039. }
  8040.  
  8041. char* GetBaseName()
  8042. {
  8043.     typedef char*(__thiscall * SetStringFn)(void*);
  8044.     return call_vfunc<SetStringFn>(this, 6)(this);
  8045. }
  8046.  
  8047. char pad_0x0000[0x4]; //0x0000
  8048. ConVar* pNext; //0x0004
  8049. __int32 bRegistered; //0x0008
  8050. char* pszName; //0x000C
  8051. char* pszHelpString; //0x0010
  8052. __int32 nFlags; //0x0014
  8053. char pad_0x0018[0x4]; //0x0018
  8054. ConVar* pParent; //0x001C
  8055. char* pszDefaultValue; //0x0020
  8056. char* strString; //0x0024
  8057. __int32 StringLength; //0x0028
  8058. float fValue; //0x002C
  8059. __int32 nValue; //0x0030
  8060. __int32 bHasMin; //0x0034
  8061. float fMinVal; //0x0038
  8062. __int32 bHasMax; //0x003C
  8063. float fMaxVal; //0x0040
  8064. void* fnChangeCallback; //0x0044
  8065.  
  8066. };//Size=0x0048
  8067.  
  8068. class ICVar
  8069. {
  8070.     public:
  8071.         ConVar* FindVar(const char* var_name)
  8072.         {
  8073.  
  8074.         typedef ConVar*(__thiscall* FindVarFn)(void*, const char*);
  8075.                 return call_vfunc<FindVarFn>(this, 15)(this, var_name);
  8076.         }
  8077. };/*
  8078. Syn's AYYWAREFramework 2015
  8079. */
  8080.  
  8081. #pragma once
  8082.  
  8083. #include "MiscDefinitions.h"
  8084. #include "ClientRecvProps.h"
  8085. #include "offsets.h"
  8086. #include "Vector.h"
  8087. #include "bspflags.h"
  8088.  
  8089. // Entity List
  8090. class IClientEntityList
  8091. {
  8092.     public:
  8093.         virtual void Function0();
  8094.     virtual void Function1();
  8095.     virtual void Function2();
  8096.     virtual IClientEntity* GetClientEntity(int entnum);
  8097.     virtual IClientEntity* GetClientEntityFromHandle(HANDLE hEnt) = 0;
  8098.         virtual int NumberOfEntities(bool bIncludeNonNetworkable) = 0;
  8099.         virtual int GetHighestEntityIndex(void);
  8100.     virtual void SetMaxEntities(int maxents);
  8101.     virtual int GetMaxEntities();
  8102. };
  8103.  
  8104. // Panels
  8105. class IPanel
  8106. {
  8107.     public:
  8108.         const char* GetName(unsigned int vguiPanel)
  8109.         {
  8110.  
  8111.         typedef const char* (__thiscall * OriginalFn)(PVOID, unsigned int);
  8112.                 return call_vfunc<OriginalFn>(this, Offsets::VMT::Panel_GetName)(this, vguiPanel);
  8113.         }
  8114. };
  8115.  
  8116. // Colors
  8117. class Color
  8118. {
  8119.     public:
  8120.         // constructors
  8121.         Color()
  8122.     {
  8123.         *((int*)this) = 0;
  8124.     }
  8125.     Color(int r, int g, int b)
  8126.     {
  8127.         SetColor(r, g, b, 0);
  8128.     }
  8129.     Color(int r, int g, int b, int a)
  8130.     {
  8131.         SetColor(r, g, b, a);
  8132.     }
  8133.     void SetColor(int r, int g, int b, int a = 0)
  8134.     {
  8135.         _color[0] = (unsigned char)r;
  8136.         _color[1] = (unsigned char)g;
  8137.         _color[2] = (unsigned char)b;
  8138.         _color[3] = (unsigned char)a;
  8139.     }
  8140.  
  8141.     void GetColor(int &r, int &g, int &b, int &a) const
  8142.         {
  8143.  
  8144.         r = _color[0];
  8145.                 g = _color[1];
  8146.                 b = _color[2];
  8147.                 a = _color[3];
  8148.         }
  8149.  
  8150. void SetRawColor(int color32)
  8151. {
  8152.     *((int*)this) = color32;
  8153. }
  8154.  
  8155. int GetRawColor() const
  8156.         {
  8157.                 return *((int*)this);
  8158. }
  8159.  
  8160. inline int r() const    { return _color[0]; }
  8161.         inline int g() const    { return _color[1]; }
  8162.         inline int b() const    { return _color[2]; }
  8163.         inline int a() const    { return _color[3]; }
  8164.  
  8165.         void SetAlpha(int a) { _color[0] = (unsigned char)a; }
  8166. int GetAlpha() { return _color[0]; }
  8167.  
  8168.  
  8169. unsigned char &operator[] (int index)
  8170. {
  8171.     return _color[index];
  8172. }
  8173.  
  8174. const unsigned char &operator[] (int index) const
  8175.         {
  8176.                 return _color[index];
  8177.         }
  8178.  
  8179.         bool operator ==(const Color &rhs) const
  8180.         {
  8181.                 return (*((int*)this) == *((int *)&rhs));
  8182. }
  8183.  
  8184. bool operator !=(const Color &rhs) const
  8185.         {
  8186.                 return !(operator ==(rhs));
  8187.         }
  8188.  
  8189.         Color &operator=(const Color &rhs)
  8190. {
  8191.     SetRawColor(rhs.GetRawColor());
  8192.     return *this;
  8193. }
  8194.  
  8195. private:
  8196.         unsigned char _color[4];
  8197. };
  8198.  
  8199. // Debug Overlay
  8200. class IVDebugOverlay
  8201. {
  8202.     public:
  8203.         virtual void AddEntityTextOverlay(int ent_index, int line_offset, float duration, int r, int g, int b, int a, const char* format, ...) = 0;
  8204.     virtual void AddBoxOverlay(const Vector& origin, const Vector& mins, const Vector& max, Vector const& orientation, int r, int g, int b, int a, float duration) = 0;
  8205.     virtual void AddSphereOverlay(const Vector& vOrigin, float flRadius, int nTheta, int nPhi, int r, int g, int b, int a, float flDuration) = 0;
  8206.     virtual void AddTriangleOverlay(const Vector& p1, const Vector& p2, const Vector& p3, int r, int g, int b, int a, bool noDepthTest, float duration) = 0;
  8207.     virtual void AddLineOverlay(const Vector& origin, const Vector& dest, int r, int g, int b, bool noDepthTest, float duration) = 0;
  8208.     virtual void AddTextOverlay(const Vector& origin, float duration, const char* format, ...) = 0;
  8209.     virtual void AddTextOverlay(const Vector& origin, int line_offset, float duration, const char* format, ...) = 0;
  8210.     virtual void AddScreenTextOverlay(float flXPos, float flYPos, float flDuration, int r, int g, int b, int a, const char* text) = 0;
  8211.     virtual void AddSweptBoxOverlay(const Vector& start, const Vector& end, const Vector& mins, const Vector& max, const Vector & angles, int r, int g, int b, int a, float flDuration) = 0;
  8212.     virtual void AddGridOverlay(const Vector& origin) = 0;
  8213.         virtual void AddCoordFrameOverlay(const matrix3x4& frame, float flScale, int vColorTable[3][3] = NULL) = 0;
  8214.  
  8215.         virtual int ScreenPosition(const Vector& point, Vector& screen) = 0;
  8216.         virtual int ScreenPosition(float flXPos, float flYPos, Vector& screen) = 0;
  8217.  
  8218.         virtual void* GetFirst(void) = 0;
  8219.         virtual void* GetNext(void* current) = 0;
  8220.         virtual void ClearDeadOverlays(void) = 0;
  8221.         virtual void ClearAllOverlays() = 0;
  8222.  
  8223.         virtual void AddTextOverlayRGB(const Vector& origin, int line_offset, float duration, float r, float g, float b, float alpha, const char* format, ...) = 0;
  8224.     virtual void AddTextOverlayRGB(const Vector& origin, int line_offset, float duration, int r, int g, int b, int a, const char* format, ...) = 0;
  8225.  
  8226.     virtual void AddLineOverlayAlpha(const Vector& origin, const Vector& dest, int r, int g, int b, int a, bool noDepthTest, float duration) = 0;
  8227.     virtual void AddBoxOverlay2(const Vector& origin, const Vector& mins, const Vector& max, Vector const& orientation, const Color& faceColor, const Color& edgeColor, float duration) = 0;
  8228.  
  8229.     virtual void PurgeTextOverlays() = 0;
  8230. };
  8231.  
  8232. // User Cmd's
  8233. class CUserCmd
  8234. {
  8235.     public:
  8236.         virtual ~CUserCmd() { }; //Destructor 0
  8237.     CUserCmd()
  8238.     {
  8239.         Reset();
  8240.     }
  8241.  
  8242.     void Reset()
  8243.     {
  8244.         command_number = 0;
  8245.         tick_count = 0;
  8246.         viewangles.Init();
  8247.         forwardmove = 0.0f;
  8248.         sidemove = 0.0f;
  8249.         upmove = 0.0f;
  8250.         buttons = 0;
  8251.         impulse = 0;
  8252.         weaponselect = 0;
  8253.         weaponsubtype = 0;
  8254.         random_seed = 0;
  8255.         mousedx = 0;
  8256.         mousedy = 0;
  8257.         headangles.Init();
  8258.         headoffset.Init();
  8259.  
  8260.         hasbeenpredicted = false;
  8261.     }
  8262.  
  8263.     CUserCmd& operator =(const CUserCmd& src)
  8264.         {
  8265.                 if (this == &src)
  8266.                         return *this;
  8267.  
  8268.                 command_number = src.command_number;
  8269.                 tick_count = src.tick_count;
  8270.                 viewangles = src.viewangles;
  8271.                 forwardmove = src.forwardmove;
  8272.                 sidemove = src.sidemove;
  8273.                 upmove = src.upmove;
  8274.                 buttons = src.buttons;
  8275.                 impulse = src.impulse;
  8276.                 weaponselect = src.weaponselect;
  8277.                 weaponsubtype = src.weaponsubtype;
  8278.                 random_seed = src.random_seed;
  8279.                 mousedx = src.mousedx;
  8280.                 mousedy = src.mousedy;
  8281.  
  8282.                 hasbeenpredicted = src.hasbeenpredicted;
  8283.                 headangles = src.headangles;
  8284.                 headoffset = src.headoffset;
  8285.                 return *this;
  8286.         }
  8287.  
  8288.  
  8289.     CUserCmd(const CUserCmd& src)
  8290. {
  8291.     *this = src;
  8292. }
  8293.  
  8294.  
  8295. int command_number;
  8296. int tick_count;
  8297. Vector viewangles;
  8298. Vector aimdirection;
  8299. float forwardmove;
  8300. float sidemove;
  8301. float upmove;
  8302. int buttons;
  8303. BYTE impulse;
  8304. int weaponselect;
  8305. int weaponsubtype;
  8306. int random_seed;
  8307. short mousedx;
  8308. short mousedy;
  8309. bool hasbeenpredicted;
  8310. Vector headangles;
  8311. Vector headoffset;
  8312. };
  8313.  
  8314. class CGlobalVarsBase
  8315. {
  8316.     public:
  8317.         float realtime;
  8318.     int framecount;
  8319.     float absoluteframetime;
  8320.     float absoluteframestarttimestddev;
  8321.     float curtime;
  8322.     float frametime;
  8323.     int maxClients;
  8324.     int tickcount;
  8325.     float interval_per_tick;
  8326.     float interpolation_amount;
  8327.     int simTicksThisFrame;
  8328.     int network_protocol;
  8329.     void* pSaveData;
  8330.     bool m_bClient;
  8331.     int nTimestampNetworkingBase;
  8332.     int nTimestampRandomizeWindow;
  8333. };
  8334.  
  8335. struct Ray_t
  8336. {
  8337.  
  8338.     __declspec(align(16)) Vector m_Start;
  8339.  
  8340.     __declspec(align(16)) Vector m_Delta;
  8341.  
  8342.     __declspec(align(16)) Vector m_StartOffset;
  8343.  
  8344.     __declspec(align(16)) Vector m_Extents;
  8345.     //without your matrix3x4
  8346.     bool m_IsRay;
  8347.     bool m_IsSwept;
  8348.  
  8349.     void Init(Vector& vecStart, Vector& vecEnd)
  8350.     {
  8351.         m_Delta = vecEnd - vecStart;
  8352.  
  8353.         m_IsSwept = (m_Delta.LengthSqr() != 0);
  8354.  
  8355.         m_Extents.x = m_Extents.y = m_Extents.z = 0.0f;
  8356.  
  8357.         m_IsRay = true;
  8358.  
  8359.         m_StartOffset.x = m_StartOffset.y = m_StartOffset.z = 0.0f;
  8360.  
  8361.         m_Start = vecStart;
  8362.     }
  8363. };
  8364.  
  8365. struct cplane_t
  8366. {
  8367.     Vector normal;
  8368.     float dist;
  8369.     BYTE type;
  8370.     BYTE signbits;
  8371.     BYTE pad[2];
  8372. };
  8373.  
  8374. class CBaseTrace
  8375. {
  8376.     public:
  8377.         Vector startpos;
  8378.     Vector endpos;
  8379.     cplane_t plane;
  8380.     float fraction;
  8381.     int contents;
  8382.     unsigned short dispFlags;
  8383.     bool allsolid;
  8384.     bool startsolid;
  8385. };
  8386.  
  8387. struct csurface_t
  8388. {
  8389.     const char* name;
  8390.     short surfaceProps;
  8391.     unsigned short flags;
  8392. };
  8393.  
  8394. class CGameTrace : public CBaseTrace
  8395. {
  8396. public:
  8397.         bool DidHitWorld() const;
  8398. bool DidHitNonWorldEntity() const;
  8399. int GetEntityIndex() const;
  8400. bool DidHit() const;
  8401. public:
  8402.         float fractionleftsolid;
  8403. csurface_t surface;
  8404. int hitgroup;
  8405. short physicsbone;
  8406. unsigned short worldSurfaceIndex;
  8407. IClientEntity* m_pEnt;
  8408. int hitbox;
  8409. char shit[0x24];
  8410. };
  8411.  
  8412. inline bool CGameTrace::DidHit() const
  8413. {
  8414.         return fraction< 1.0f || allsolid || startsolid;
  8415. }
  8416.  
  8417. typedef CGameTrace trace_t;
  8418.  
  8419. enum TraceType_t
  8420. {
  8421.     TRACE_EVERYTHING = 0,
  8422.     TRACE_WORLD_ONLY,
  8423.     TRACE_ENTITIES_ONLY,
  8424.     TRACE_EVERYTHING_FILTER_PROPS,
  8425. };
  8426.  
  8427. class ITraceFilter
  8428. {
  8429.     public:
  8430.         virtual bool ShouldHitEntity(IClientEntity* pEntity, int contentsMask) = 0;
  8431.         virtual TraceType_t GetTraceType() const = 0;
  8432. };
  8433.  
  8434. class CTraceFilter : public ITraceFilter
  8435. {
  8436. public:
  8437.         bool ShouldHitEntity(IClientEntity* pEntityHandle, int contentsMask)
  8438. {
  8439.     return !(pEntityHandle == pSkip);
  8440. }
  8441.  
  8442. TraceType_t GetTraceType() const
  8443.         {
  8444.                 return TRACE_EVERYTHING;
  8445.         }
  8446.  
  8447.         void* pSkip;
  8448. };
  8449.  
  8450. class IEngineTrace
  8451. {
  8452.     public:
  8453.         int GetPointContents(const Vector &vecAbsPosition, int contentsMask = MASK_ALL, IClientEntity** ppEntity = NULL)
  8454.         {
  8455.                 typedef int(__thiscall* fnGetPointContents)(void*, const Vector&, int, IClientEntity**);
  8456.                 return call_vfunc<fnGetPointContents>(this, 0)(this, vecAbsPosition, contentsMask, ppEntity);
  8457.         }
  8458.  
  8459. void TraceRay(const Ray_t &ray, unsigned int fMask, ITraceFilter* pTraceFilter, trace_t* pTrace)
  8460. {
  8461.     typedef void(__thiscall * fnTraceRay)(void*, const Ray_t&, unsigned int, ITraceFilter*, trace_t *);
  8462.     call_vfunc<fnTraceRay>(this, 5)(this, ray, fMask, pTraceFilter, pTrace);
  8463. }
  8464. };
  8465.  
  8466. struct mstudiobbox_t
  8467. {
  8468.     int bone;
  8469.     int group;
  8470.     Vector bbmin;
  8471.     Vector bbmax;
  8472.     int szhitboxnameindex;
  8473.     int unused[8];
  8474.  
  8475.     char* GetHitboxName(void)
  8476.     {
  8477.         if (szhitboxnameindex == 0)
  8478.             return "";
  8479.  
  8480.         return ((char*)this) + szhitboxnameindex;
  8481.     }
  8482. };
  8483. struct mstudiohitboxset_t
  8484. {
  8485.     int sznameindex;
  8486.     inline char* const GetName(void) const { return ((char*)this) + sznameindex; }
  8487. int numhitboxes;
  8488. int hitboxindex;
  8489. inline mstudiobbox_t* GetHitbox(int i) const { return (mstudiobbox_t*)(((byte*)this) + hitboxindex) + i; };
  8490. };
  8491. struct mstudiobone_t
  8492. {
  8493.     int sznameindex;
  8494.     inline char* const GetName(void) const { return ((char*)this) + sznameindex; }
  8495. int parent;
  8496. int bonecontroller[6];
  8497.  
  8498. Vector pos;
  8499. float quat[4];
  8500. Vector rot;
  8501. Vector posscale;
  8502. Vector rotscale;
  8503.  
  8504. matrix3x4 poseToBone;
  8505. float qAlignment[4];
  8506. int flags;
  8507. int proctype;
  8508. int procindex;              // procedural rule
  8509. mutable int physicsbone;    // index into physically simulated bone
  8510. inline void* GetProcedure() const { if (procindex == 0) return NULL; else return  (void*)(((byte*)this) + procindex); };
  8511. int surfacepropidx; // index into string tablefor property name
  8512. inline char* const GetSurfaceProps(void) const { return ((char*)this) + surfacepropidx; }
  8513.         int contents;               // See BSPFlags.h for the contents flags
  8514.  
  8515. int unused[8];              // remove as appropriate
  8516. };
  8517. struct studiohdr_t
  8518. {
  8519.     int id;
  8520.     int version;
  8521.  
  8522.     int checksum;
  8523.  
  8524.     char name[64];
  8525.     int length;
  8526.  
  8527.  
  8528.     Vector eyeposition;
  8529.  
  8530.     Vector illumposition;
  8531.  
  8532.     Vector hull_min;
  8533.     Vector hull_max;
  8534.  
  8535.     Vector view_bbmin;
  8536.     Vector view_bbmax;
  8537.  
  8538.     int flags;
  8539.  
  8540.     int numbones;
  8541.     int boneindex;
  8542.  
  8543.     inline mstudiobone_t *GetBone(int i) const { return (mstudiobone_t*)(((byte*)this) + boneindex) + i; };
  8544. //      inline mstudiobone_t *pBone(int i) const { Assert(i >= 0 && i < numbones); return (mstudiobone_t *)(((byte *)this) + boneindex) + i; };
  8545.  
  8546. int numbonecontrollers;
  8547. int bonecontrollerindex;
  8548.  
  8549. int numhitboxsets;
  8550. int hitboxsetindex;
  8551.  
  8552. mstudiohitboxset_t* GetHitboxSet(int i) const
  8553.         {
  8554.                 return (mstudiohitboxset_t*)(((byte*)this) + hitboxsetindex) + i;
  8555. }
  8556.  
  8557. inline mstudiobbox_t* GetHitbox(int i, int set) const
  8558.         {
  8559.                 mstudiohitboxset_t const* s = GetHitboxSet(set);
  8560.  
  8561.                 if (!s)
  8562.                         return NULL;
  8563.  
  8564.                 return s->GetHitbox(i);
  8565.         }
  8566.  
  8567.         inline int GetHitboxCount(int set) const
  8568.         {
  8569.                 mstudiohitboxset_t const* s = GetHitboxSet(set);
  8570.  
  8571.                 if (!s)
  8572.                         return 0;
  8573.  
  8574.                 return s->numhitboxes;
  8575.         }
  8576.  
  8577.         int numlocalanim;
  8578. int localanimindex;
  8579.  
  8580. int numlocalseq;
  8581. int localseqindex;
  8582.  
  8583. mutable int activitylistversion;
  8584. mutable int eventsindexed;
  8585.  
  8586. int numtextures;
  8587. int textureindex;
  8588.  
  8589. int numcdtextures;
  8590. int cdtextureindex;
  8591.  
  8592. int numskinref;
  8593. int numskinfamilies;
  8594. int skinindex;
  8595.  
  8596. int numbodyparts;
  8597. int bodypartindex;
  8598.  
  8599. int numlocalattachments;
  8600. int localattachmentindex;
  8601.  
  8602. int numlocalnodes;
  8603. int localnodeindex;
  8604. int localnodenameindex;
  8605.  
  8606. int numflexdesc;
  8607. int flexdescindex;
  8608.  
  8609. int numflexcontrollers;
  8610. int flexcontrollerindex;
  8611.  
  8612. int numflexrules;
  8613. int flexruleindex;
  8614.  
  8615. int numikchains;
  8616. int ikchainindex;
  8617.  
  8618. int nummouths;
  8619. int mouthindex;
  8620.  
  8621. int numlocalposeparameters;
  8622. int localposeparamindex;
  8623.  
  8624. int surfacepropindex;
  8625.  
  8626. int keyvalueindex;
  8627. int keyvaluesize;
  8628.  
  8629.  
  8630. int numlocalikautoplaylocks;
  8631. int localikautoplaylockindex;
  8632.  
  8633. float mass;
  8634. int contents;
  8635.  
  8636. int numincludemodels;
  8637. int includemodelindex;
  8638.  
  8639. mutable void* virtualModel;
  8640.  
  8641. int szanimblocknameindex;
  8642. int numanimblocks;
  8643. int animblockindex;
  8644.  
  8645. mutable void* animblockModel;
  8646.  
  8647. int bonetablebynameindex;
  8648.  
  8649. void* pVertexBase;
  8650. void* pIndexBase;
  8651.  
  8652. byte constdirectionallightdot;
  8653.  
  8654. byte rootLOD;
  8655.  
  8656. byte numAllowedRootLODs;
  8657.  
  8658. byte unused[1];
  8659.  
  8660. int unused4;
  8661.  
  8662. int numflexcontrollerui;
  8663. int flexcontrolleruiindex;
  8664. float flVertAnimFixedPointScale;
  8665. int unused3[1];
  8666. int studiohdr2index;
  8667. int unused2[1];
  8668. };
  8669.  
  8670. struct surfacephysicsparams_t
  8671. {
  8672.     float friction;
  8673.     float elasticity; // collision elasticity - used to compute coefficient of restitution
  8674.     float density;    // physical density (in kg / m^3)
  8675.     float thickness;    // material thickness if not solid (sheet materials) in inches
  8676.     float dampening;
  8677. };
  8678.  
  8679. struct surfaceaudioparams_t
  8680. {
  8681.     float reflectivity;            // like elasticity, but how much sound should be reflected by this surface
  8682.     float hardnessFactor;            // like elasticity, but only affects impact sound choices
  8683.     float roughnessFactor;        // like friction, but only affects scrape sound choices  
  8684.     float roughThreshold;            // surface roughness > this causes "rough" scrapes, < this causes "smooth" scrapes
  8685.     float hardThreshold;            // surface hardness > this causes "hard" impacts, < this causes "soft" impacts
  8686.     float hardVelocityThreshold;    // collision velocity > this causes "hard" impacts, < this causes "soft" impacts  
  8687. };
  8688.  
  8689. struct surfacesoundnames_t
  8690. {
  8691.     unsigned short stepleft;
  8692.     unsigned short stepright;
  8693.     unsigned short impactSoft;
  8694.     unsigned short impactHard;
  8695.     unsigned short scrapeSmooth;
  8696.     unsigned short scrapeRough;
  8697.     unsigned short bulletImpact;
  8698.     unsigned short rolling;
  8699.     unsigned short breakSound;
  8700.     unsigned short strainSound;
  8701. };
  8702.  
  8703. struct surfacegameprops_t
  8704. {
  8705.     public:
  8706.         float maxSpeedFactor; //0x0000
  8707.     float jumpFactor; //0x0004
  8708.     char pad00[0x4]; //0x0008
  8709.     float flPenetrationModifier; //0x000C
  8710.     float flDamageModifier; //0x0010
  8711.     unsigned short material; //0x0014
  8712.     char pad01[0x3];
  8713.  
  8714. };//Size=0x0019
  8715.  
  8716. struct surfacedata_t
  8717. {
  8718.     surfacephysicsparams_t physics;
  8719.     surfaceaudioparams_t audio;
  8720.     surfacesoundnames_t sounds;
  8721.     surfacegameprops_t game;
  8722. };
  8723.  
  8724. class IPhysicsSurfaceProps
  8725. {
  8726.     public:
  8727.  
  8728.         surfacedata_t* GetSurfaceData(int surfaceDataIndex)
  8729.     {
  8730.         typedef surfacedata_t*(__thiscall * fnGetSurfaceData)(void*, int);
  8731.         return call_vfunc<fnGetSurfaceData>(this, 5)(this, surfaceDataIndex);
  8732.     }
  8733. };
  8734.  
  8735. class ConVar
  8736. {
  8737.     public:
  8738.         //void SetString(const char *pValue)
  8739.         //{
  8740.         //      typedef void(__thiscall* SetStringFn)(void*, const char *);
  8741.         //      call_vfunc<SetStringFn>(this, 17)(this, pValue);
  8742.         //}
  8743.  
  8744.         void SetString(const char* str)
  8745.         {
  8746.  
  8747.         typedef void(__thiscall* SetStringFn)(void*, const char*);
  8748.                 return call_vfunc<SetStringFn>(this, 13)(this, str);
  8749.         }
  8750.  
  8751. void InternalSetString(const char* str)
  8752. {
  8753.     typedef void(__thiscall * SetStringFn)(void*, const char*);
  8754.     return call_vfunc<SetStringFn>(this, 17)(this, str);
  8755. }
  8756.  
  8757. char* GetBaseName()
  8758. {
  8759.     typedef char*(__thiscall * SetStringFn)(void*);
  8760.     return call_vfunc<SetStringFn>(this, 6)(this);
  8761. }
  8762.  
  8763. char pad_0x0000[0x4]; //0x0000
  8764. ConVar* pNext; //0x0004
  8765. __int32 bRegistered; //0x0008
  8766. char* pszName; //0x000C
  8767. char* pszHelpString; //0x0010
  8768. __int32 nFlags; //0x0014
  8769. char pad_0x0018[0x4]; //0x0018
  8770. ConVar* pParent; //0x001C
  8771. char* pszDefaultValue; //0x0020
  8772. char* strString; //0x0024
  8773. __int32 StringLength; //0x0028
  8774. float fValue; //0x002C
  8775. __int32 nValue; //0x0030
  8776. __int32 bHasMin; //0x0034
  8777. float fMinVal; //0x0038
  8778. __int32 bHasMax; //0x003C
  8779. float fMaxVal; //0x0040
  8780. void* fnChangeCallback; //0x0044
  8781.  
  8782. };//Size=0x0048
  8783.  
  8784. class ICVar
  8785. {
  8786.     public:
  8787.         ConVar* FindVar(const char* var_name)
  8788.         {
  8789.  
  8790.         typedef ConVar*(__thiscall* FindVarFn)(void*, const char*);
  8791.                 return call_vfunc<FindVarFn>(this, 15)(this, var_name);
  8792.         }
  8793. };#pragma once
  8794.  
  8795. #include "NetVars.h"
  8796. #include "Vector.h"
  8797.  
  8798. //-------------------------------------------------------------------------------------
  8799. //-------------------------------------------------------------------------------------
  8800.  
  8801. // For calling VMT functions in our classes
  8802. template<typename Function> Function call_vfunc(PVOID Base, DWORD Index)
  8803. {
  8804.     PDWORD* VTablePointer = (PDWORD*)Base;
  8805.     PDWORD VTableFunctionBase = *VTablePointer;
  8806.     DWORD dwAddress = VTableFunctionBase[Index];
  8807.     return (Function)(dwAddress);
  8808. }
  8809.  
  8810. // Netvar shit
  8811. #define dwThis (DWORD)this
  8812. #define NETVAR(type,offset) *(type*)(dwThis + offset)
  8813. #define CNETVAR(type,offset) (type)(dwThis + offset)
  8814.  
  8815. //CNETVAR_FUNC - creates a netvar function in a class that returns value(s) [type=class type & return type] [name=function name] [netvar_crc=crc32 of netvar of choice]
  8816. #define CNETVAR_FUNC(type,name,netvar_crc) \
  8817. type name() \
  8818.         { \
  8819.                 static DWORD dwObserverTarget = NetVar.GetNetVar(netvar_crc); \
  8820.                 return NETVAR(type, dwObserverTarget); \
  8821.         }
  8822.  
  8823. //CPNETVAR_FUNC - creates a netvar function in a class that returns a pointer [type=class type & return type] [name=function name] [netvar_crc=crc32 of netvar of choice]
  8824. #define CPNETVAR_FUNC(type,name,netvar_crc) \
  8825.         type name() \
  8826.         { \
  8827.                 static DWORD dwObserverTarget = NetVar.GetNetVar(netvar_crc); \
  8828.                 return CNETVAR(type, dwObserverTarget); \
  8829.         }
  8830.  
  8831. // Lifestates
  8832. enum source_lifestates
  8833. {
  8834.     LIFE_ALIVE,
  8835.     LIFE_DYING,
  8836.     LIFE_DEAD,
  8837.     LIFE_RESPAWNABLE,
  8838.     LIFE_DISCARDBODY,
  8839. };
  8840.  
  8841. // Player Controls for CS:GO
  8842. enum playercontrols
  8843. {
  8844.     IN_ATTACK = (1 << 0),
  8845.     IN_JUMP = (1 << 1),
  8846.     IN_DUCK = (1 << 2),
  8847.     IN_FORWARD = (1 << 3),
  8848.     IN_BACK = (1 << 4),
  8849.     IN_USE = (1 << 5),
  8850.     IN_CANCEL = (1 << 6),
  8851.     IN_LEFT = (1 << 7),
  8852.     IN_RIGHT = (1 << 8),
  8853.     IN_MOVELEFT = (1 << 9),
  8854.     IN_MOVERIGHT = (1 << 10),
  8855.     IN_ATTACK2 = (1 << 11),
  8856.     IN_RUN = (1 << 12),
  8857.     IN_RELOAD = (1 << 13),
  8858.     IN_ALT1 = (1 << 14),
  8859.     IN_ALT2 = (1 << 15),
  8860.     IN_SCORE = (1 << 16),   // Used by client.dll for when scoreboard is held down
  8861.     IN_SPEED = (1 << 17),   // Player is holding the speed key
  8862.     IN_WALK = (1 << 18),    // Player holding walk key
  8863.     IN_ZOOM = (1 << 19),    // Zoom key for HUD zoom
  8864.     IN_WEAPON1 = (1 << 20), // weapon defines these bits
  8865.     IN_WEAPON2 = (1 << 21), // weapon defines these bits
  8866.     IN_BULLRUSH = (1 << 22),
  8867. };
  8868.  
  8869. typedef float matrix3x4[3][4];
  8870.  
  8871. class player_info_t
  8872. {
  8873.     public:
  8874.         char pad_0x0000[0x10]; //0x0000
  8875.     char name[64]; //0x0010
  8876.     char pad_0x0050[0x40]; //0x0050
  8877.     __int32 userID; //0x0090
  8878.     char guid[32]; //0x0094
  8879.     char pad_0x00B4[0x180]; //0x00B4
  8880. };
  8881.  
  8882. enum SolidType_t
  8883. {
  8884.     SOLID_NONE = 0, // no solid model
  8885.     SOLID_BSP = 1,  // a BSP tree
  8886.     SOLID_BBOX = 2, // an AABB
  8887.     SOLID_OBB = 3,  // an OBB (not implemented yet)
  8888.     SOLID_OBB_YAW = 4,  // an OBB, constrained so that it can only yaw
  8889.     SOLID_CUSTOM = 5,   // Always call into the entity for tests
  8890.     SOLID_VPHYSICS = 6, // solid vphysics object, get vcollide from the model and collide with that
  8891.     SOLID_LAST,
  8892. };
  8893.  
  8894. enum SolidFlags_t
  8895. {
  8896.     FSOLID_CUSTOMRAYTEST = 0x0001,  // Ignore solid type + always call into the entity for ray tests
  8897.     FSOLID_CUSTOMBOXTEST = 0x0002,  // Ignore solid type + always call into the entity for swept box tests
  8898.     FSOLID_NOT_SOLID = 0x0004,  // Are we currently not solid?
  8899.     FSOLID_TRIGGER = 0x0008,    // This is something may be collideable but fires touch functions
  8900.                                 // even when it's not collideable (when the FSOLID_NOT_SOLID flag is set)
  8901.     FSOLID_NOT_STANDABLE = 0x0010,  // You can't stand on this
  8902.     FSOLID_VOLUME_CONTENTS = 0x0020,    // Contains volumetric contents (like water)
  8903.     FSOLID_FORCE_WORLD_ALIGNED = 0x0040,    // Forces the collision rep to be world-aligned even if it's SOLID_BSP or SOLID_VPHYSICS
  8904.     FSOLID_USE_TRIGGER_BOUNDS = 0x0080, // Uses a special trigger bounds separate from the normal OBB
  8905.     FSOLID_ROOT_PARENT_ALIGNED = 0x0100,    // Collisions are defined in root parent's local coordinate space
  8906.     FSOLID_TRIGGER_TOUCH_DEBRIS = 0x0200,   // This trigger will touch debris objects
  8907.  
  8908.     FSOLID_MAX_BITS = 10
  8909. };
  8910.  
  8911. // KeyValues
  8912. class KeyValues
  8913. {
  8914.     public:
  8915.         char _pad[0x20];//csgo, for css its a diff size
  8916. };
  8917.  
  8918. // Memes
  8919. struct ModelRenderInfo_t
  8920. {
  8921.     Vector origin;
  8922.     Vector angles;
  8923.     void* pRenderable;
  8924.     const void* pModel;
  8925.     const matrix3x4* pModelToWorld;
  8926.     const matrix3x4* pLightingOffset;
  8927.     const Vector* pLightingOrigin;
  8928.     int flags;
  8929.     int entity_index;
  8930.     int skin;
  8931.     int body;
  8932.     int hitboxset;
  8933.     unsigned short instance;
  8934.  
  8935.     ModelRenderInfo_t()
  8936.     {
  8937.         pModelToWorld = NULL;
  8938.         pLightingOffset = NULL;
  8939.         pLightingOrigin = NULL;
  8940.     }
  8941. };
  8942.  
  8943. typedef float vec_t;
  8944.  
  8945. inline unsigned long& FloatBits(vec_t& f)
  8946. {
  8947.     return *reinterpret_cast < unsigned long*> (&f);
  8948. }
  8949.  
  8950. inline bool IsFinite(vec_t f)
  8951. {
  8952.     return ((FloatBits(f) & 0x7F800000) != 0x7F800000);
  8953. }
  8954.  
  8955. struct model_t;
  8956.  
  8957. enum OverrideType_t
  8958. {
  8959.     OVERRIDE_NORMAL = 0,
  8960.     OVERRIDE_BUILD_SHADOWS,
  8961.     OVERRIDE_DEPTH_WRITE,
  8962. };
  8963.  
  8964. enum MaterialVarFlags_t
  8965. {
  8966.     MATERIAL_VAR_DEBUG = (1 << 0),
  8967.     MATERIAL_VAR_NO_DEBUG_OVERRIDE = (1 << 1),
  8968.     MATERIAL_VAR_NO_DRAW = (1 << 2),
  8969.     MATERIAL_VAR_USE_IN_FILLRATE_MODE = (1 << 3),
  8970.  
  8971.     MATERIAL_VAR_VERTEXCOLOR = (1 << 4),
  8972.     MATERIAL_VAR_VERTEXALPHA = (1 << 5),
  8973.     MATERIAL_VAR_SELFILLUM = (1 << 6),
  8974.     MATERIAL_VAR_ADDITIVE = (1 << 7),
  8975.     MATERIAL_VAR_ALPHATEST = (1 << 8),
  8976.     MATERIAL_VAR_MULTIPASS = (1 << 9),
  8977.     MATERIAL_VAR_ZNEARER = (1 << 10),
  8978.     MATERIAL_VAR_MODEL = (1 << 11),
  8979.     MATERIAL_VAR_FLAT = (1 << 12),
  8980.     MATERIAL_VAR_NOCULL = (1 << 13),
  8981.     MATERIAL_VAR_NOFOG = (1 << 14),
  8982.     MATERIAL_VAR_IGNOREZ = (1 << 15),
  8983.     MATERIAL_VAR_DECAL = (1 << 16),
  8984.     MATERIAL_VAR_ENVMAPSPHERE = (1 << 17),
  8985.     MATERIAL_VAR_NOALPHAMOD = (1 << 18),
  8986.     MATERIAL_VAR_ENVMAPCAMERASPACE = (1 << 19),
  8987.     MATERIAL_VAR_BASEALPHAENVMAPMASK = (1 << 20),
  8988.     MATERIAL_VAR_TRANSLUCENT = (1 << 21),
  8989.     MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK = (1 << 22),
  8990.     MATERIAL_VAR_NEEDS_SOFTWARE_SKINNING = (1 << 23),
  8991.     MATERIAL_VAR_OPAQUETEXTURE = (1 << 24),
  8992.     MATERIAL_VAR_ENVMAPMODE = (1 << 25),
  8993.     MATERIAL_VAR_SUPPRESS_DECALS = (1 << 26),
  8994.     MATERIAL_VAR_HALFLAMBERT = (1 << 27),
  8995.     MATERIAL_VAR_WIREFRAME = (1 << 28),
  8996.  
  8997.     // NOTE: Only add flags here that either should be read from
  8998.     // .vmts or can be set directly from client code. Other, internal
  8999.     // flags should to into the flag enum in IMaterialInternal.h
  9000. };
  9001.  
  9002. #define FL_ONGROUND                             (1<<0)  // At rest / on the ground
  9003. #define FL_DUCKING                              (1<<1)  // Player flag -- Player is fully crouched
  9004. #define FL_WATERJUMP                    (1<<2)  // player jumping out of water
  9005. #define FL_ONTRAIN                              (1<<3) // Player is _controlling_ a train, so movement commands should be ignored on client during prediction.
  9006. #define FL_INRAIN                               (1<<4)  // Indicates the entity is standing in rain
  9007. #define FL_FROZEN                               (1<<5) // Player is frozen for 3rd person camera
  9008. #define FL_ATCONTROLS                   (1<<6) // Player can't move, but keeps key inputs for controlling another entity
  9009. #define FL_CLIENT                               (1<<7)  // Is a player
  9010. #define FL_FAKECLIENT                   (1<<8)  // Fake client, simulated server side; don't send network messages to them
  9011. // NON-PLAYER SPECIFIC (i.e., not used by GameMovement or the client .dll ) -- Can still be applied to players, though
  9012. #define FL_INWATER                              (1<<9)  // In water
  9013.  
  9014. // NOTE if you move things up, make sure to change this value
  9015. #define PLAYER_FLAG_BITS                10
  9016.  
  9017. #define FL_FLY                                  (1<<10) // Changes the SV_Movestep() behavior to not need to be on ground
  9018. #define FL_SWIM                                 (1<<11) // Changes the SV_Movestep() behavior to not need to be on ground (but stay in water)
  9019. #define FL_CONVEYOR                             (1<<12)
  9020. #define FL_NPC                                  (1<<13)
  9021. #define FL_GODMODE                              (1<<14)
  9022. #define FL_NOTARGET                             (1<<15)
  9023. #define FL_AIMTARGET                    (1<<16) // set if the crosshair needs to aim onto the entity
  9024. #define FL_PARTIALGROUND                (1<<17) // not all corners are valid
  9025. #define FL_STATICPROP                   (1<<18) // Eetsa static prop!          
  9026. #define FL_GRAPHED                              (1<<19) // worldgraph has this ent listed as something that blocks a connection
  9027. #define FL_GRENADE                              (1<<20)
  9028. #define FL_STEPMOVEMENT                 (1<<21) // Changes the SV_Movestep() behavior to not do any processing
  9029. #define FL_DONTTOUCH                    (1<<22) // Doesn't generate touch functions, generates Untouch() for anything it was touching when this flag was set
  9030. #define FL_BASEVELOCITY                 (1<<23) // Base velocity has been applied this frame (used to convert base velocity into momentum)
  9031. #define FL_WORLDBRUSH                   (1<<24) // Not moveable/removeable brush entity (really part of the world, but represented as an entity for transparency or something)
  9032. #define FL_OBJECT                               (1<<25) // Terrible name. This is an object that NPCs should see. Missiles, for example.
  9033. #define FL_KILLME                               (1<<26) // This entity is marked for death -- will be freed by game DLL
  9034. #define FL_ONFIRE                               (1<<27) // You know...
  9035. #define FL_DISSOLVING                   (1<<28) // We're dissolving!
  9036. #define FL_TRANSRAGDOLL                 (1<<29) // In the process of turning into a client side ragdoll.
  9037. #define FL_UNBLOCKABLE_BY_PLAYER (1<<30) // pusher that can't be blocked by the player
  9038.  
  9039. enum ClientFrameStage_t
  9040. {
  9041.     FRAME_UNDEFINED = -1,           // (haven't run any frames yet)
  9042.     FRAME_START,
  9043.  
  9044.     // A network packet is being recieved
  9045.     FRAME_NET_UPDATE_START,
  9046.     // Data has been received and we're going to start calling PostDataUpdate
  9047.     FRAME_NET_UPDATE_POSTDATAUPDATE_START,
  9048.     // Data has been received and we've called PostDataUpdate on all data recipients
  9049.     FRAME_NET_UPDATE_POSTDATAUPDATE_END,
  9050.     // We've received all packets, we can now do interpolation, prediction, etc..
  9051.     FRAME_NET_UPDATE_END,
  9052.  
  9053.     // We're about to start rendering the scene
  9054.     FRAME_RENDER_START,
  9055.     // We've finished rendering the scene.
  9056.     FRAME_RENDER_END
  9057. };
  9058.  
  9059. // ConVar flags
  9060. #define FCVAR_NONE                              0
  9061.  
  9062. #define FCVAR_UNREGISTERED              (1<<0)
  9063. #define FCVAR_DEVELOPMENTONLY   (1<<1)
  9064. #define FCVAR_GAMEDLL                   (1<<2)
  9065. #define FCVAR_CLIENTDLL                 (1<<3)
  9066. #define FCVAR_HIDDEN                    (1<<4)
  9067.  
  9068. #define FCVAR_PROTECTED                 (1<<5)
  9069. #define FCVAR_SPONLY                    (1<<6)
  9070. #define FCVAR_ARCHIVE                   (1<<7)
  9071. #define FCVAR_NOTIFY                    (1<<8)
  9072. #define FCVAR_USERINFO                  (1<<9)
  9073. #define FCVAR_CHEAT                             (1<<14)
  9074.  
  9075. #define FCVAR_PRINTABLEONLY             (1<<10)
  9076. #define FCVAR_UNLOGGED                  (1<<11)
  9077. #define FCVAR_NEVER_AS_STRING   (1<<12)
  9078. #define FCVAR_RELEASE                   (1<<19)
  9079.  
  9080. #define FCVAR_REPLICATED                (1<<13)
  9081. #define FCVAR_DEMO                              (1<<16)
  9082. #define FCVAR_DONTRECORD                (1<<17)
  9083.  
  9084. #define FCVAR_NOT_CONNECTED             (1<<22)
  9085. #define FCVAR_ARCHIVE_XBOX              (1<<24)
  9086. #define FCVAR_SERVER_CAN_EXECUTE        (1<<28)
  9087. #define FCVAR_SERVER_CANNOT_QUERY       (1<<29)
  9088. #define FCVAR_CLIENTCMD_CAN_EXECUTE     (1<<30)
  9089. /*
  9090. Syn's AYYWAREFramework 2015
  9091. */
  9092.  
  9093. # include "MiscHacks.h"
  9094. # include "Interfaces.h"
  9095. # include "RenderManager.h"
  9096.  
  9097. # include <time.h>
  9098.  
  9099. Vector AutoStrafeView;
  9100.  
  9101. void CMiscHacks::Init()
  9102. {
  9103.     // Any init
  9104. }
  9105.  
  9106. void CMiscHacks::Draw()
  9107. {
  9108.     // Any drawing     
  9109. }
  9110.  
  9111. void CMiscHacks::Move(CUserCmd* pCmd)
  9112. {
  9113.     // Any Move Stuff
  9114.  
  9115.     // Bhop
  9116.     if (Menu::Window.VisualsTab.OtherAutoJump.GetState())
  9117.         AutoJump(pCmd);
  9118.  
  9119.     // Strafe
  9120.     Interfaces::Engine->GetViewAngles(AutoStrafeView);
  9121.     if (Menu::Window.VisualsTab.OtherAutoStrafe.GetState())
  9122.         AutoStrafe(pCmd);
  9123.  
  9124.     // Spams
  9125.     switch (Menu::Window.VisualsTab.OtherChatSpam.GetIndex())
  9126.     {
  9127.         case 0:
  9128.             // No Chat Spam
  9129.             break;
  9130.         case 1:
  9131.             // Round Say
  9132.             break;
  9133.         case 2:
  9134.             // Regular
  9135.             ChatSpamRegular();
  9136.             break;
  9137.         case 3:
  9138.             // Report Spam
  9139.             ChatSpamReports();
  9140.             break;
  9141.     }
  9142.  
  9143. }
  9144.  
  9145. void CMiscHacks::AutoJump(CUserCmd* pCmd)
  9146. {
  9147.     if (pCmd->buttons & IN_JUMP && GUI.GetKeyState(VK_SPACE))
  9148.     {
  9149.         int iFlags = hackManager.pLocal()->GetFlags();
  9150.         if (!(iFlags & FL_ONGROUND))
  9151.             pCmd->buttons &= ~IN_JUMP;
  9152.  
  9153.         if (hackManager.pLocal()->GetVelocity().Length() <= 50)
  9154.         {
  9155.             pCmd->forwardmove = 450.f;
  9156.         }
  9157.     }
  9158. }
  9159.  
  9160. void CMiscHacks::AutoStrafe(CUserCmd* pCmd)
  9161. {
  9162.     IClientEntity* pLocal = hackManager.pLocal();
  9163.     static bool bDirection = true;
  9164.  
  9165.     bool bKeysPressed = true;
  9166.     if (GUI.GetKeyState(0x41) || GUI.GetKeyState(0x57) || GUI.GetKeyState(0x53) || GUI.GetKeyState(0x44)) bKeysPressed = false;
  9167.     if (pCmd->buttons & IN_ATTACK) bKeysPressed = false;
  9168.  
  9169.     float flYawBhop = 0.f;
  9170.     if (pLocal->GetVelocity().Length() > 50.f)
  9171.     {
  9172.         float x = 30.f, y = pLocal->GetVelocity().Length(), z = 0.f, a = 0.f;
  9173.  
  9174.         z = x / y;
  9175.         z = fabsf(z);
  9176.  
  9177.         a = x * z;
  9178.  
  9179.         flYawBhop = a;
  9180.     }
  9181.  
  9182.     if ((GetAsyncKeyState(VK_SPACE) && !(pLocal->GetFlags() & FL_ONGROUND)) && bKeysPressed)
  9183.     {
  9184.  
  9185.         if (bDirection)
  9186.         {
  9187.             AutoStrafeView -= flYawBhop;
  9188.             GameUtils::NormaliseViewAngle(AutoStrafeView);
  9189.             pCmd->sidemove = -400.f;
  9190.             bDirection = false;
  9191.         }
  9192.         else
  9193.         {
  9194.             AutoStrafeView += flYawBhop;
  9195.             GameUtils::NormaliseViewAngle(AutoStrafeView);
  9196.             pCmd->sidemove = 400.f;
  9197.             bDirection = true;
  9198.         }
  9199.  
  9200.         if (pCmd->mousedx < 0)
  9201.         {
  9202.             pCmd->sidemove = -450.f;
  9203.         }
  9204.  
  9205.         if (pCmd->mousedx > 0)
  9206.         {
  9207.             pCmd->sidemove = 450.f;
  9208.         }
  9209.     }
  9210. }
  9211.  
  9212. Vector GetAutostrafeView()
  9213. {
  9214.     return AutoStrafeView;
  9215. }
  9216.  
  9217. void CMiscHacks::ChatSpamReports()
  9218. {
  9219.     // Don't spam it too fast so you can still do stuff
  9220.     static clock_t start_t = clock();
  9221.     double timeSoFar = (double)(clock() - start_t) / CLOCKS_PER_SEC;
  9222.     if (timeSoFar < 0.5)
  9223.         return;
  9224.  
  9225.     // Loop through all active entitys
  9226.     std::vector < std::string > Names;
  9227.  
  9228.     for (int i = 0; i < Interfaces::EntList->GetHighestEntityIndex(); i++)
  9229.     {
  9230.         // Get the entity
  9231.         IClientEntity* entity = Interfaces::EntList->GetClientEntity(i);
  9232.  
  9233.         player_info_t pInfo;
  9234.         // If it's a valid entity and isn't the player
  9235.         if (entity && hackManager.pLocal()->GetTeamNum() != entity->GetTeamNum())
  9236.         {
  9237.             ClientClass* cClass = (ClientClass*)entity->GetClientClass();
  9238.  
  9239.             // If entity is a player
  9240.             if (cClass->m_ClassID == (int)CSGOClassID::CCSPlayer)
  9241.             {
  9242.                 if (Interfaces::Engine->GetPlayerInfo(i, &pInfo))
  9243.                 {
  9244.                     if (!strstr(pInfo.name, "GOTV"))
  9245.                         Names.push_back(pInfo.name);
  9246.                 }
  9247.             }
  9248.         }
  9249.     }
  9250.  
  9251.     int randomIndex = rand() % Names.size();
  9252.     char buffer[128];
  9253.     static unsigned long int meme = 3091961887844204720;
  9254.     sprintf_s(buffer, "Report for %s submitted, report id %lu.", Names[randomIndex].c_str(), meme);
  9255.     meme += 1;
  9256.     SayInChat(buffer);
  9257.     start_t = clock();
  9258. }
  9259.  
  9260. void CMiscHacks::ChatSpamRegular()
  9261. {
  9262.     // Don't spam it too fast so you can still do stuff
  9263.     static clock_t start_t = clock();
  9264.     double timeSoFar = (double)(clock() - start_t) / CLOCKS_PER_SEC;
  9265.     if (timeSoFar < 0.5)
  9266.         return;
  9267.  
  9268.     SayInChat("Aliens exist. #AliensInCSGOConfirmed");
  9269.  
  9270.     start_t = clock();
  9271. }
  9272. /*
  9273. Syn's AYYWAREFramework 2015
  9274. */
  9275.  
  9276. #pragma once
  9277.  
  9278. #include "Hacks.h"
  9279.  
  9280. Vector GetAutostrafeView();
  9281.  
  9282. class CMiscHacks : public CHack
  9283. {
  9284. public:
  9285.         void Init();
  9286. void Draw();
  9287. void Move(CUserCmd* pCmd);
  9288. private:
  9289.         void AutoJump(CUserCmd* pCmd);
  9290. void AutoStrafe(CUserCmd* pCmd);
  9291. void ChatSpamRegular();
  9292. void ChatSpamReports();
  9293. };/*
  9294. Syn's AYYWAREFramework 2015
  9295. */
  9296.  
  9297. // Credits to Valve and Shad0w
  9298.  
  9299. #include "NetVars.h"
  9300. #include "ClientRecvProps.h"
  9301. #include "CRC32.h"
  9302. #include "Utilities.h"
  9303.  
  9304. #include "SDK.h"
  9305.  
  9306. CNetVar NetVar;
  9307.  
  9308. const char* AlignText(int align)
  9309. {
  9310.         static char buffer[256];
  9311. int i = 0;
  9312.         for (i = 0; i<align; i++)
  9313.         {
  9314.                 buffer[i] = ' ';
  9315.         }
  9316.         buffer[i + 1] = 0;
  9317.         return buffer;
  9318. }
  9319.  
  9320. void CNetVar::RetrieveClasses()
  9321. {
  9322.     Utilities::EnableLogFile(NETVAR_FILENAME);
  9323.  
  9324.     ClientClass* clientClass = Interfaces::Client->GetAllClasses();
  9325.  
  9326.     if (!clientClass)
  9327.         return;
  9328.  
  9329.     //Clear netvar vector incase of another call, not necesarry as it doesnt add duplicates
  9330.  
  9331.     vars.clear();
  9332.  
  9333.     while (clientClass != 0)
  9334.     {
  9335.         if (clientClass == 0)
  9336.             break;
  9337.  
  9338.         LogNetVar(clientClass->m_pRecvTable, 0);
  9339.  
  9340.         clientClass = clientClass->m_pNext;
  9341.     }
  9342. }
  9343.  
  9344. void CNetVar::LogNetVar(RecvTable* table, int align)
  9345. {
  9346.     if (table->m_nProps < 0)
  9347.         return;
  9348.  
  9349.     if (align)
  9350.         Utilities::Log("%s===%s===", AlignText(20 + align), table->m_pNetTableName);
  9351.     else
  9352.         Utilities::Log(table->m_pNetTableName);
  9353.  
  9354.     for (auto i = 0; i < table->m_nProps; ++i)
  9355.     {
  9356.         RecvProp* prop = &table->m_pProps[i];
  9357.  
  9358.         if (!prop)
  9359.             continue;
  9360.  
  9361.         char szCRC32[150];
  9362.  
  9363.         sprintf_s(szCRC32, "%s%s", table->m_pNetTableName, prop->m_pVarName);
  9364.  
  9365.         DWORD_PTR dwCRC32 = CRC32((void*)szCRC32, strlen(szCRC32));
  9366.  
  9367.         Utilities::Log("%s%s [0x%X] [CRC32::0x%X]", AlignText(15 + align), prop->m_pVarName, prop->m_Offset, dwCRC32);
  9368.  
  9369.         //Dont add duplicates
  9370.  
  9371.         bool bAddNetVar = true;
  9372.  
  9373.         for (auto netvar = 0; netvar < (int)vars.size(); ++netvar)
  9374.         {
  9375.             netvar_info_s* netvars = &vars[netvar];
  9376.  
  9377.             if (netvars->dwCRC32 == dwCRC32)
  9378.                 bAddNetVar = false;
  9379.  
  9380.  
  9381.             if (netvars->dwCRC32 == dwCRC32 && netvars->dwOffset != prop->m_Offset) //just a test if any crc collide with another (didnt happen obviously)
  9382.             {
  9383.                 Utilities::Log("^^^^ ERROR HASH %s%s::%s [0x%X] [CRC32::0x%X] ^^^^", AlignText(15 + align), table->m_pNetTableName, prop->m_pVarName, prop->m_Offset, dwCRC32);
  9384.                 Utilities::Log("^^^^ CONFLICT %s%s::%s [0x%X] [CRC32::0x%X] ^^^^", AlignText(15 + align), netvars->szTableName, netvars->szPropName, netvars->dwOffset, netvars->dwCRC32);
  9385.             }
  9386.         }
  9387.  
  9388.         if (bAddNetVar) //avoid adding duplicates (faster lookup)
  9389.         {
  9390.             netvar_info_s tmp;
  9391.             strcpy_s(tmp.szTableName, table->m_pNetTableName);
  9392.             strcpy_s(tmp.szPropName, prop->m_pVarName);
  9393.             tmp.dwCRC32 = dwCRC32;
  9394.  
  9395.             tmp.dwOffset = prop->m_Offset;
  9396.  
  9397.             vars.push_back(tmp);
  9398.         }
  9399.  
  9400.         if (prop->m_pDataTable)
  9401.             LogNetVar(prop->m_pDataTable, 5);
  9402.     }
  9403. }
  9404.  
  9405. DWORD_PTR CNetVar::GetNetVar(DWORD_PTR dwCRC32) //returns 0xFFFFFFFF (-1) if not found (ex: if(GetNetVar(0xD34DB33F)==-1) return false;
  9406. {
  9407.     for (auto i = 0; i < (int)vars.size(); ++i)
  9408.     {
  9409.         if (vars[i].dwCRC32 == dwCRC32)
  9410.             return vars[i].dwOffset;
  9411.     }
  9412.  
  9413.     return 0xFFFFFFFF;
  9414. }/*
  9415. Syn's AYYWAREFramework 2015
  9416. */
  9417.  
  9418. #include "Offsets.h"
  9419.  
  9420. void Offsets::Initialise()
  9421. {
  9422.     // Modules
  9423.     Modules::Client = Utilities::Memory::WaitOnModuleHandle("client.dll");
  9424.     Modules::Engine = Utilities::Memory::WaitOnModuleHandle("engine.dll");
  9425.     Modules::VGUI2 = Utilities::Memory::WaitOnModuleHandle("vgui2.dll");
  9426.     Modules::VGUISurface = Utilities::Memory::WaitOnModuleHandle("vguimatsurface.dll");
  9427.     Modules::Material = Utilities::Memory::WaitOnModuleHandle("materialsystem.dll");
  9428.     Modules::VPhysics = Utilities::Memory::WaitOnModuleHandle("vphysics.dll");
  9429.     Modules::Stdlib = Utilities::Memory::WaitOnModuleHandle("vstdlib.dll");
  9430.  
  9431.     //------------------------------------------------------------------------
  9432.     // VTables
  9433. #pragma region VTables
  9434.     VMT::CHL_GetAllClasses = 8;
  9435.  
  9436.     VMT::Engine_GetScreenSize = 5;
  9437.     VMT::Engine_GetPlayerInfo = 8;
  9438.     VMT::Engine_GetLocalPlayer = 12;
  9439.     VMT::Engine_Time = 14;
  9440.     VMT::Engine_GetViewAngles = 18;
  9441.     VMT::Engine_SetViewAngles = 19;
  9442.     VMT::Engine_GetMaxClients = 20;
  9443.     VMT::Engine_IsConnected = 27;
  9444.     VMT::Engine_IsInGame = 26;
  9445.     VMT::Engine_WorldToScreenMatrix = 37;
  9446.     VMT::Engine_ClientCmd_Unrestricted = 114;
  9447.  
  9448.     VMT::Panel_GetName = 36;
  9449.     VMT::Panel_PaintTraverse = 41;
  9450.  
  9451.     VMT::Surface_DrawSetColorA = 14;
  9452.     VMT::Surface_DrawSetColorB = 15;
  9453.     VMT::Surface_DrawFilledRect = 16;
  9454.     VMT::Surface_DrawOutlinedRect = 18;
  9455.     VMT::Surface_DrawLine = 19;
  9456.     VMT::Surface_DrawSetTextFont = 23;
  9457.     VMT::Surface_DrawSetTextColorA = 24;
  9458.     VMT::Surface_DrawSetTextColorB = 25;
  9459.     VMT::Surface_DrawSetTextPos = 26;
  9460.     VMT::Surface_DrawPrintText = 28;
  9461.     VMT::Surface_DrawSetTextureRGBA = 37;
  9462.     VMT::Surface_DrawSetTexture = 38;
  9463.     VMT::Surface_CreateNewTextureID = 43;
  9464.     VMT::Surface_FontCreate = 71;
  9465.     VMT::Surface_SetFontGlyphSet = 72;
  9466.     VMT::Surface_GetTextSize = 79;
  9467.     VMT::Surface_DrawOutlinedCircle = 103;
  9468.     VMT::Surface_SurfaceGetCursorPos = 66;
  9469.     VMT::Surface_DrawTexturedPolygon = 106;
  9470.  
  9471.     VMT::Material_GetName = 0;
  9472.     VMT::Material_SetMaterialVarFlag = 30;
  9473.     VMT::Material_GetMaterialVarFlag = 31;
  9474.     VMT::Material_AlphaModulate = 28;
  9475.     VMT::Material_ColorModulate = 29;
  9476.     VMT::Material_IncrementReferenceCount = 14;
  9477.  
  9478.     VMT::MaterialSystem_FindMaterial = 84;
  9479.     VMT::MaterialSystem_CreateMaterial = 83;
  9480.  
  9481.     VMT::ModelRender_ForcedMaterialOverride = 1;
  9482.     VMT::ModelRender_DrawModelExecute = 21;
  9483.  
  9484.     VMT::ModelInfo_GetModelName = 3;
  9485.     VMT::ModelInfo_GetStudiomodel = 30;
  9486.  
  9487.     VMT::RenderView_SetBlend = 4;
  9488.     VMT::RenderView_SetColorModulation = 6;
  9489.  
  9490. #pragma endregion Contains the VTable Indexs
  9491.  
  9492.     // An update changed the VTable offset for GetSpread.
  9493.     // Just incase ;)
  9494.     DWORD VMT_SpreadAddress = (DWORD)Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x8B\x80\x00\x00\x00\x00\xFF\xD0\x51\xD9\x1C\x24\x0F\xB6\xC3\x8B\x5C\x24\x30", "xx????xxxxxxxxxxxxx");
  9495.     if (VMT_SpreadAddress)
  9496.     {
  9497.         VMT::Weapon_GetSpread = *(DWORD*)(VMT_SpreadAddress + 2);
  9498.         VMT::Weapon_GetSpread = (VMT::Weapon_GetSpread / 4);
  9499.     }
  9500.  
  9501.     // I cbf trying to get the KeyValues part of the SDK working solo, so we'll just
  9502.     // Do some dirty shit
  9503.     Functions::KeyValues_KeyValues = Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x68\x00\x00\x00\x00\x8B\xC8\xE8\x00\x00\x00\x00\x89\x45\xFC\xEB\x07\xC7\x45\x00\x00\x00\x00\x00\x8B\x03\x56", "x????xxx????xxxxxxx?????xxx");
  9504.     Functions::KeyValues_KeyValues += 7;
  9505.     Functions::KeyValues_KeyValues = Functions::KeyValues_KeyValues + *reinterpret_cast<PDWORD_PTR>(Functions::KeyValues_KeyValues + 1) + 5;
  9506.  
  9507.     Functions::KeyValues_LoadFromBuffer = Utilities::Memory::FindPattern("client.dll", (PBYTE)"\xE8\x00\x00\x00\x00\x8A\xD8\xFF\x15\x00\x00\x00\x00\x84\xDB", "x????xxxx????xx");
  9508.     Functions::KeyValues_LoadFromBuffer = Functions::KeyValues_LoadFromBuffer + *reinterpret_cast<PDWORD_PTR>(Functions::KeyValues_LoadFromBuffer + 1) + 5;
  9509.  
  9510.     Functions::dwCalcPlayerView = Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x84\xC0\x75\x08\x57\x8B\xCE\xE8\x00\x00\x00\x00\x8B\x06", "xxxxxxxx????xx");
  9511.  
  9512.     Utilities::Log("Offsets/Indexes Up to Date");
  9513. }
  9514.  
  9515. namespace Offsets
  9516. {
  9517.     // Addresses of loaded game modules
  9518.     namespace Modules
  9519.     {
  9520.         DWORD Client;
  9521.         DWORD Engine;
  9522.         DWORD VGUI2;
  9523.         DWORD VGUISurface;
  9524.         DWORD Material;
  9525.         DWORD VPhysics;
  9526.         DWORD Stdlib;
  9527.     };
  9528.  
  9529.     // Virtual Method Table Indexes
  9530.     namespace VMT
  9531.     {
  9532.         //CHL Client
  9533.         DWORD CHL_GetAllClasses;
  9534.  
  9535.         //Engine Client
  9536.         DWORD Engine_GetScreenSize;
  9537.         DWORD Engine_GetPlayerInfo;
  9538.         DWORD Engine_GetLocalPlayer;
  9539.         DWORD Engine_Time;
  9540.         DWORD Engine_GetViewAngles;
  9541.         DWORD Engine_SetViewAngles;
  9542.         DWORD Engine_GetMaxClients;
  9543.         DWORD Engine_IsConnected;
  9544.         DWORD Engine_IsInGame;
  9545.         DWORD Engine_WorldToScreenMatrix;
  9546.         DWORD Engine_ClientCmd_Unrestricted;
  9547.  
  9548.         // Panels
  9549.         DWORD Panel_GetName;
  9550.         DWORD Panel_PaintTraverse;
  9551.  
  9552.         // Surface
  9553.         DWORD Surface_DrawSetColorA;
  9554.         DWORD Surface_DrawSetColorB;
  9555.         DWORD Surface_DrawFilledRect;
  9556.         DWORD Surface_DrawOutlinedRect;
  9557.         DWORD Surface_DrawLine;
  9558.         DWORD Surface_DrawSetTextFont;
  9559.         DWORD Surface_DrawSetTextColorA;
  9560.         DWORD Surface_DrawSetTextColorB;
  9561.         DWORD Surface_DrawSetTextPos;
  9562.         DWORD Surface_DrawPrintText;
  9563.         DWORD Surface_DrawSetTextureRGBA;
  9564.         DWORD Surface_DrawSetTexture;
  9565.         DWORD Surface_CreateNewTextureID;
  9566.         DWORD Surface_FontCreate;
  9567.         DWORD Surface_SetFontGlyphSet;
  9568.         DWORD Surface_GetTextSize;
  9569.         DWORD Surface_DrawOutlinedCircle;
  9570.         DWORD Surface_SurfaceGetCursorPos;
  9571.         DWORD Surface_DrawTexturedPolygon;
  9572.  
  9573.         DWORD Material_GetName;
  9574.         DWORD Material_SetMaterialVarFlag;
  9575.         DWORD Material_GetMaterialVarFlag;
  9576.         DWORD Material_AlphaModulate;
  9577.         DWORD Material_ColorModulate;
  9578.         DWORD Material_IncrementReferenceCount;
  9579.  
  9580.         DWORD MaterialSystem_FindMaterial;
  9581.         DWORD MaterialSystem_CreateMaterial;
  9582.  
  9583.         DWORD ModelRender_ForcedMaterialOverride;
  9584.         DWORD ModelRender_DrawModelExecute;
  9585.  
  9586.         DWORD ModelInfo_GetModelName;
  9587.         DWORD ModelInfo_GetStudiomodel;
  9588.  
  9589.         DWORD RenderView_SetBlend;
  9590.         DWORD RenderView_SetColorModulation;
  9591.  
  9592.         // Weapon entities
  9593.         DWORD Weapon_GetSpread;
  9594.     };
  9595.  
  9596.     // Addresses of engine functions to call
  9597.     namespace Functions
  9598.     {
  9599.         DWORD KeyValues_KeyValues;
  9600.         DWORD KeyValues_LoadFromBuffer;
  9601.         DWORD dwCalcPlayerView;
  9602.     };
  9603.  
  9604. };/*
  9605. Syn's AYYWAREFramework 2015
  9606. */
  9607.  
  9608. #pragma once
  9609.  
  9610. #include "Utilities.h"
  9611.  
  9612. // Various offsets
  9613. namespace Offsets
  9614. {
  9615.     // Sets up all the shit we need
  9616.     void Initialise();
  9617.  
  9618.     // Addresses of loaded game modules
  9619.     namespace Modules
  9620.     {
  9621.         extern DWORD Client;
  9622.                 extern DWORD Engine;
  9623.                 extern DWORD VGUI2;
  9624.                 extern DWORD VGUISurface;
  9625.                 extern DWORD Material;
  9626.                 extern DWORD VPhysics;
  9627.                 extern DWORD Stdlib;
  9628.         };
  9629.  
  9630.     // Virtual Method Table Indexes
  9631.     namespace VMT
  9632.     {
  9633.         //CHL Client
  9634.         extern DWORD CHL_GetAllClasses;
  9635.  
  9636.                 //Engine Client
  9637.                 extern DWORD Engine_GetScreenSize;
  9638.                 extern DWORD Engine_GetPlayerInfo;
  9639.                 extern DWORD Engine_GetLocalPlayer;
  9640.                 extern DWORD Engine_Time;
  9641.                 extern DWORD Engine_GetViewAngles;
  9642.                 extern DWORD Engine_SetViewAngles;
  9643.                 extern DWORD Engine_GetMaxClients;
  9644.                 extern DWORD Engine_IsConnected;
  9645.                 extern DWORD Engine_IsInGame;
  9646.                 extern DWORD Engine_WorldToScreenMatrix;
  9647.                 extern DWORD Engine_ClientCmd_Unrestricted;
  9648.  
  9649.                 // Panels
  9650.                 extern DWORD Panel_GetName;
  9651.                 extern DWORD Panel_PaintTraverse;
  9652.  
  9653.                 // Surface
  9654.                 extern DWORD Surface_DrawSetColorA;
  9655.                 extern DWORD Surface_DrawSetColorB;
  9656.                 extern DWORD Surface_DrawFilledRect;
  9657.                 extern DWORD Surface_DrawOutlinedRect;
  9658.                 extern DWORD Surface_DrawLine;
  9659.                 extern DWORD Surface_DrawSetTextFont;
  9660.                 extern DWORD Surface_DrawSetTextColorA;
  9661.                 extern DWORD Surface_DrawSetTextColorB;
  9662.                 extern DWORD Surface_DrawSetTextPos;
  9663.                 extern DWORD Surface_DrawPrintText;
  9664.                 extern DWORD Surface_DrawSetTextureRGBA;
  9665.                 extern DWORD Surface_DrawSetTexture;
  9666.                 extern DWORD Surface_CreateNewTextureID;
  9667.                 extern DWORD Surface_FontCreate;
  9668.                 extern DWORD Surface_SetFontGlyphSet;
  9669.                 extern DWORD Surface_GetTextSize;
  9670.                 extern DWORD Surface_DrawOutlinedCircle;
  9671.                 extern DWORD Surface_SurfaceGetCursorPos;
  9672.                 extern DWORD Surface_DrawTexturedPolygon;
  9673.  
  9674.                 extern DWORD Material_GetName;
  9675.                 extern DWORD Material_SetMaterialVarFlag;
  9676.                 extern DWORD Material_GetMaterialVarFlag;
  9677.                 extern DWORD Material_AlphaModulate;
  9678.                 extern DWORD Material_ColorModulate;
  9679.                 extern DWORD Material_IncrementReferenceCount;
  9680.  
  9681.                 extern DWORD MaterialSystem_FindMaterial;
  9682.                 extern DWORD MaterialSystem_CreateMaterial;
  9683.  
  9684.                 extern DWORD ModelRender_ForcedMaterialOverride;
  9685.                 extern DWORD ModelRender_DrawModelExecute;
  9686.  
  9687.                 extern DWORD ModelInfo_GetModelName;
  9688.                 extern DWORD ModelInfo_GetStudiomodel;
  9689.                
  9690.                 extern DWORD RenderView_SetBlend;
  9691.                 extern DWORD RenderView_SetColorModulation;
  9692.  
  9693.                 // Weapon entities
  9694.                 extern DWORD Weapon_GetSpread;
  9695.         };
  9696.  
  9697.     // Addresses of engine functions to call
  9698.     namespace Functions
  9699.     {
  9700.         extern DWORD KeyValues_KeyValues;
  9701.                 extern DWORD KeyValues_LoadFromBuffer;
  9702.                 extern DWORD dwCalcPlayerView;
  9703.         };
  9704.  
  9705. };#include "RageBot.h"
  9706. #include "RenderManager.h"
  9707. #include "Autowall.h"
  9708.  
  9709. void CRageBot::Init()
  9710. {
  9711.     IsAimStepping = false;
  9712.     IsLocked = false;
  9713.     TargetID = -1;
  9714. }
  9715.  
  9716. void CRageBot::Draw()
  9717. {
  9718.  
  9719. }
  9720.  
  9721. void CRageBot::Move(CUserCmd* pCmd)
  9722. {
  9723.     // Master switch
  9724.     if (!Menu::Window.RageBotTab.Active.GetState())
  9725.         return;
  9726.  
  9727.     // Aimbot
  9728.     if (Menu::Window.RageBotTab.AimbotEnable.GetState())
  9729.         DoAimbot(pCmd);
  9730.  
  9731.     // Recoil
  9732.     if (Menu::Window.RageBotTab.AccuracyRecoil.GetState())
  9733.         DoNoRecoil(pCmd);
  9734.  
  9735.     // No Spread
  9736.     if (Menu::Window.RageBotTab.AccuracySpread.GetState())
  9737.         DoNoSpread(pCmd);
  9738.  
  9739.     // Anti-Aim
  9740.     if (Menu::Window.RageBotTab.AntiAimEnable.GetState())
  9741.         DoAntiAim(pCmd);
  9742.  
  9743.     if (Menu::Window.RageBotTab.AimbotAimStep.GetState())
  9744.     {
  9745.         Vector AddAngs = pCmd->viewangles - LastAngle;
  9746.         if (AddAngs.Length2D() > 25.f)
  9747.         {
  9748.             Normalize(AddAngs, AddAngs);
  9749.             AddAngs *= 25;
  9750.             pCmd->viewangles = LastAngle + AddAngs;
  9751.             GameUtils::NormaliseViewAngle(pCmd->viewangles);
  9752.         }
  9753.     }
  9754.  
  9755.     LastAngle = pCmd->viewangles;
  9756. }
  9757.  
  9758. // Functionality
  9759. void CRageBot::DoAimbot(CUserCmd* pCmd)
  9760. {
  9761.     IClientEntity* pTarget = nullptr;
  9762.     IClientEntity* pLocal = hackManager.pLocal();
  9763.     bool FindNewTarget = true;
  9764.     //IsLocked = false;
  9765.  
  9766.     // Don't aimbot with the knife..
  9767.     CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
  9768.     if (pWeapon)
  9769.     {
  9770.         if (pWeapon->GetAmmoInClip() == 0 || !GameUtils::IsBallisticWeapon(pWeapon))
  9771.         {
  9772.             //TargetID = 0;
  9773.             //pTarget = nullptr;
  9774.             //HitBox = -1;
  9775.             return;
  9776.         }
  9777.     }
  9778.     else
  9779.         return;
  9780.  
  9781.     // Make sure we have a good target
  9782.     if (IsLocked && TargetID >= 0 && HitBox >= 0)
  9783.     {
  9784.         pTarget = Interfaces::EntList->GetClientEntity(TargetID);
  9785.         if (pTarget && TargetMeetsRequirements(pTarget))
  9786.         {
  9787.             HitBox = HitScan(pTarget);
  9788.             if (HitBox >= 0)
  9789.             {
  9790.                 Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  9791.                 Vector View; Interfaces::Engine->GetViewAngles(View);
  9792.                 float FoV = FovToPlayer(ViewOffset, View, pTarget, HitBox);
  9793.                 if (FoV < Menu::Window.RageBotTab.AimbotFov.GetValue())
  9794.                     FindNewTarget = false;
  9795.             }
  9796.         }
  9797.     }
  9798.  
  9799.     // Find a new target, apparently we need to
  9800.     if (FindNewTarget)
  9801.     {
  9802.         TargetID = 0;
  9803.         pTarget = nullptr;
  9804.         HitBox = -1;
  9805.  
  9806.         // Target selection type
  9807.         switch (Menu::Window.RageBotTab.TargetSelection.GetIndex())
  9808.         {
  9809.             case 0:
  9810.                 TargetID = GetTargetCrosshair();
  9811.                 break;
  9812.             case 1:
  9813.                 TargetID = GetTargetDistance();
  9814.                 break;
  9815.             case 2:
  9816.                 TargetID = GetTargetHealth();
  9817.                 break;
  9818.         }
  9819.  
  9820.         // Memes
  9821.         if (TargetID >= 0)
  9822.         {
  9823.             pTarget = Interfaces::EntList->GetClientEntity(TargetID);
  9824.         }
  9825.         else
  9826.         {
  9827.             pTarget = nullptr;
  9828.             HitBox = -1;
  9829.         }
  9830.     }
  9831.  
  9832.     // If we finally have a good target
  9833.     if (TargetID >= 0 && pTarget)
  9834.     {
  9835.         HitBox = HitScan(pTarget);
  9836.  
  9837.         // Key
  9838.         if (Menu::Window.RageBotTab.AimbotKeyPress.GetState())
  9839.         {
  9840.             int Key = Menu::Window.RageBotTab.AimbotKeyBind.GetKey();
  9841.             if (Key >= 0 && !GUI.GetKeyState(Key))
  9842.             {
  9843.                 TargetID = -1;
  9844.                 pTarget = nullptr;
  9845.                 HitBox = -1;
  9846.                 return;
  9847.             }
  9848.         }
  9849.  
  9850.         Vector AimPoint = GetHitboxPosition(pTarget, HitBox);
  9851.  
  9852.         float Spread = pWeapon->GetInaccuracy();
  9853.  
  9854.         if (!Menu::Window.RageBotTab.AccuracySpreadLimit.GetState() || Spread <= (Menu::Window.RageBotTab.AccuracyMinimumSpread.GetValue() / 100.f))
  9855.         {
  9856.             if (AimAtPoint(pLocal, AimPoint, pCmd))
  9857.             {
  9858.                 //IsLocked = true;
  9859.                 if (Menu::Window.RageBotTab.AimbotAutoFire.GetState() && !(pCmd->buttons & IN_ATTACK))
  9860.                 {
  9861.                     pCmd->buttons |= IN_ATTACK;
  9862.                 }
  9863.             }
  9864.         }
  9865.  
  9866.         if (Menu::Window.RageBotTab.AccuracyAutoStop.GetState())
  9867.         {
  9868.             pCmd->forwardmove = 0.f;
  9869.             pCmd->sidemove = 0.f;
  9870.         }
  9871.  
  9872.         if (Menu::Window.RageBotTab.AccuracyAutoCrouch.GetState())
  9873.         {
  9874.             pCmd->buttons |= IN_DUCK;
  9875.         }
  9876.  
  9877.     }
  9878.  
  9879.     // Auto Pistol
  9880.     static bool WasFiring = false;
  9881.     CSWeaponInfo* WeaponInfo = pWeapon->GetCSWpnData();
  9882.     if (!WeaponInfo->m_IsFullAuto && Menu::Window.RageBotTab.AimbotAutoPistol.GetState())
  9883.     {
  9884.         if (pCmd->buttons & IN_ATTACK)
  9885.         {
  9886.             if (WasFiring)
  9887.             {
  9888.                 pCmd->buttons &= ~IN_ATTACK;
  9889.             }
  9890.         }
  9891.  
  9892.         WasFiring = pCmd->buttons & IN_ATTACK ? true : false;
  9893.     }
  9894.  
  9895.  
  9896. }
  9897.  
  9898. bool CRageBot::TargetMeetsRequirements(IClientEntity* pEntity)
  9899. {
  9900.     // Is a valid player
  9901.     if (pEntity && pEntity->IsDormant() == false && pEntity->IsAlive() && pEntity->GetIndex() != hackManager.pLocal()->GetIndex())
  9902.     {
  9903.         // Entity Type checks
  9904.         ClientClass* pClientClass = pEntity->GetClientClass();
  9905.         player_info_t pinfo;
  9906.         if (pClientClass->m_ClassID == (int)CSGOClassID::CCSPlayer && Interfaces::Engine->GetPlayerInfo(pEntity->GetIndex(), &pinfo))
  9907.         {
  9908.             // Team Check
  9909.             if (pEntity->GetTeamNum() != hackManager.pLocal()->GetTeamNum() || Menu::Window.RageBotTab.TargetFriendlyFire.GetState())
  9910.             {
  9911.                 // Spawn Check
  9912.                 if (!pEntity->HasGunGameImmunity())
  9913.                 {
  9914.                     return true;
  9915.                 }
  9916.             }
  9917.         }
  9918.     }
  9919.  
  9920.     // They must have failed a requirement
  9921.     return false;
  9922. }
  9923.  
  9924. float CRageBot::FovToPlayer(Vector ViewOffSet, Vector View, IClientEntity* pEntity, int aHitBox)
  9925. {
  9926.     // Anything past 180 degrees is just going to wrap around
  9927.     CONST FLOAT MaxDegrees = 180.0f;
  9928.  
  9929.     // Get local angles
  9930.     Vector Angles = View;
  9931.  
  9932.     // Get local view / eye position
  9933.     Vector Origin = ViewOffSet;
  9934.  
  9935.     // Create and intiialize vectors for calculations below
  9936.     Vector Delta(0, 0, 0);
  9937.     //Vector Origin(0, 0, 0);
  9938.     Vector Forward(0, 0, 0);
  9939.  
  9940.     // Convert angles to normalized directional forward vector
  9941.     AngleVectors(Angles, &Forward);
  9942.     Vector AimPos = GetHitboxPosition(pEntity, aHitBox);
  9943.     // Get delta vector between our local eye position and passed vector
  9944.     VectorSubtract(AimPos, Origin, Delta);
  9945.     //Delta = AimPos - Origin;
  9946.  
  9947.     // Normalize our delta vector
  9948.     Normalize(Delta, Delta);
  9949.  
  9950.     // Get dot product between delta position and directional forward vectors
  9951.     FLOAT DotProduct = Forward.Dot(Delta);
  9952.  
  9953.     // Time to calculate the field of view
  9954.     return (acos(DotProduct) * (MaxDegrees / PI));
  9955. }
  9956.  
  9957. int CRageBot::GetTargetCrosshair()
  9958. {
  9959.     // Target selection
  9960.     int target = -1;
  9961.     float minFoV = Menu::Window.RageBotTab.AimbotFov.GetValue();
  9962.  
  9963.     IClientEntity* pLocal = hackManager.pLocal();
  9964.     Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  9965.     Vector View; Interfaces::Engine->GetViewAngles(View);
  9966.  
  9967.     for (int i = 0; i < Interfaces::EntList->GetHighestEntityIndex(); i++)
  9968.     {
  9969.         IClientEntity* pEntity = Interfaces::EntList->GetClientEntity(i);
  9970.         if (TargetMeetsRequirements(pEntity))
  9971.         {
  9972.             int NewHitBox = HitScan(pEntity);
  9973.             if (NewHitBox >= 0)
  9974.             {
  9975.                 float fov = FovToPlayer(ViewOffset, View, pEntity, 0);
  9976.                 if (fov < minFoV)
  9977.                 {
  9978.                     minFoV = fov;
  9979.                     target = i;
  9980.                 }
  9981.             }
  9982.         }
  9983.     }
  9984.  
  9985.     return target;
  9986. }
  9987.  
  9988. int CRageBot::GetTargetDistance()
  9989. {
  9990.     // Target selection
  9991.     int target = -1;
  9992.     int minDist = 99999;
  9993.  
  9994.     IClientEntity* pLocal = hackManager.pLocal();
  9995.     Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  9996.     Vector View; Interfaces::Engine->GetViewAngles(View);
  9997.  
  9998.     for (int i = 0; i < Interfaces::EntList->GetHighestEntityIndex(); i++)
  9999.     {
  10000.         IClientEntity* pEntity = Interfaces::EntList->GetClientEntity(i);
  10001.         if (TargetMeetsRequirements(pEntity))
  10002.         {
  10003.             int NewHitBox = HitScan(pEntity);
  10004.             if (NewHitBox >= 0)
  10005.             {
  10006.                 Vector Difference = pLocal->GetOrigin() - pEntity->GetOrigin();
  10007.                 int Distance = Difference.Length();
  10008.                 float fov = FovToPlayer(ViewOffset, View, pEntity, 0);
  10009.                 if (Distance < minDist && fov < Menu::Window.RageBotTab.AimbotFov.GetValue())
  10010.                 {
  10011.                     minDist = Distance;
  10012.                     target = i;
  10013.                 }
  10014.             }
  10015.         }
  10016.     }
  10017.  
  10018.     return target;
  10019. }
  10020.  
  10021. int CRageBot::GetTargetHealth()
  10022. {
  10023.     // Target selection
  10024.     int target = -1;
  10025.     int minHealth = 101;
  10026.  
  10027.     IClientEntity* pLocal = hackManager.pLocal();
  10028.     Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  10029.     Vector View; Interfaces::Engine->GetViewAngles(View);
  10030.  
  10031.     for (int i = 0; i < Interfaces::EntList->GetHighestEntityIndex(); i++)
  10032.     {
  10033.         IClientEntity* pEntity = Interfaces::EntList->GetClientEntity(i);
  10034.         if (TargetMeetsRequirements(pEntity))
  10035.         {
  10036.             int NewHitBox = HitScan(pEntity);
  10037.             if (NewHitBox >= 0)
  10038.             {
  10039.                 int Health = pEntity->GetHealth();
  10040.                 float fov = FovToPlayer(ViewOffset, View, pEntity, 0);
  10041.                 if (Health < minHealth && fov < Menu::Window.RageBotTab.AimbotFov.GetValue())
  10042.                 {
  10043.                     minHealth = Health;
  10044.                     target = i;
  10045.                 }
  10046.             }
  10047.         }
  10048.     }
  10049.  
  10050.     return target;
  10051. }
  10052.  
  10053. int CRageBot::HitScan(IClientEntity* pEntity)
  10054. {
  10055.     std::vector<int> HitBoxesToScan;
  10056.     bool AWall = Menu::Window.RageBotTab.AccuracyAutoWall.GetState();
  10057.  
  10058.     // Get the hitboxes to scan
  10059. #pragma region GetHitboxesToScan
  10060.     int HitScanMode = Menu::Window.RageBotTab.TargetHitscan.GetIndex();
  10061.     if (HitScanMode == 0)
  10062.     {
  10063.         // No Hitscan, just a single hitbox
  10064.         switch (Menu::Window.RageBotTab.TargetHitbox.GetIndex())
  10065.         {
  10066.             case 0:
  10067.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Head);
  10068.                 break;
  10069.             case 1:
  10070.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Neck);
  10071.                 break;
  10072.             case 2:
  10073.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Chest);
  10074.                 break;
  10075.             case 3:
  10076.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Stomach);
  10077.                 break;
  10078.         }
  10079.     }
  10080.     else
  10081.     {
  10082.         switch (HitScanMode)
  10083.         {
  10084.             case 1:
  10085.                 // head/body
  10086.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Head);
  10087.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Neck);
  10088.                 HitBoxesToScan.push_back((int)CSGOHitboxID::UpperChest);
  10089.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Chest);
  10090.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Stomach);
  10091.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Pelvis);
  10092.                 break;
  10093.             case 2:
  10094.                 // basic +(arms, thighs)
  10095.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Head);
  10096.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Neck);
  10097.                 HitBoxesToScan.push_back((int)CSGOHitboxID::UpperChest);
  10098.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Chest);
  10099.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Stomach);
  10100.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Pelvis);
  10101.                 HitBoxesToScan.push_back((int)CSGOHitboxID::LeftUpperArm);
  10102.                 HitBoxesToScan.push_back((int)CSGOHitboxID::RightUpperArm);
  10103.                 HitBoxesToScan.push_back((int)CSGOHitboxID::LeftThigh);
  10104.                 HitBoxesToScan.push_back((int)CSGOHitboxID::RightThigh);
  10105.             case 3:
  10106.                 // heaps ++(just all the random shit)
  10107.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Head);
  10108.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Neck);
  10109.                 HitBoxesToScan.push_back((int)CSGOHitboxID::UpperChest);
  10110.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Chest);
  10111.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Stomach);
  10112.                 HitBoxesToScan.push_back((int)CSGOHitboxID::Pelvis);
  10113.                 HitBoxesToScan.push_back((int)CSGOHitboxID::LeftUpperArm);
  10114.                 HitBoxesToScan.push_back((int)CSGOHitboxID::RightUpperArm);
  10115.                 HitBoxesToScan.push_back((int)CSGOHitboxID::LeftThigh);
  10116.                 HitBoxesToScan.push_back((int)CSGOHitboxID::RightThigh);
  10117.                 HitBoxesToScan.push_back((int)CSGOHitboxID::LeftHand);
  10118.                 HitBoxesToScan.push_back((int)CSGOHitboxID::RightHand);
  10119.                 HitBoxesToScan.push_back((int)CSGOHitboxID::LeftFoot);
  10120.                 HitBoxesToScan.push_back((int)CSGOHitboxID::RightFoot);
  10121.                 HitBoxesToScan.push_back((int)CSGOHitboxID::LeftShin);
  10122.                 HitBoxesToScan.push_back((int)CSGOHitboxID::RightShin);
  10123.                 HitBoxesToScan.push_back((int)CSGOHitboxID::LeftLowerArm);
  10124.                 HitBoxesToScan.push_back((int)CSGOHitboxID::RightLowerArm);
  10125.         }
  10126.     }
  10127. #pragma endregion Get the list of shit to scan
  10128.  
  10129.     // check hits
  10130.     for (auto HitBoxID : HitBoxesToScan)
  10131.     {
  10132.         if (AWall)
  10133.         {
  10134.             Vector Point = GetHitboxPosition(pEntity, HitBoxID);
  10135.             float Damage = 0.f;
  10136.             Color c = Color(255, 255, 255, 255);
  10137.             if (CanHit(Point, &Damage))
  10138.             {
  10139.                 c = Color(0, 255, 0, 255);
  10140.                 if (Damage >= Menu::Window.RageBotTab.AccuracyMinimumDamage.GetValue())
  10141.                 {
  10142.                     return HitBoxID;
  10143.                 }
  10144.             }
  10145.         }
  10146.         else
  10147.         {
  10148.             if (GameUtils::IsVisible(hackManager.pLocal(), pEntity, HitBoxID))
  10149.                 return HitBoxID;
  10150.         }
  10151.     }
  10152.  
  10153.     return -1;
  10154. }
  10155.  
  10156. void CRageBot::DoNoSpread(CUserCmd* pCmd)
  10157. {
  10158.  
  10159. }
  10160.  
  10161. void CRageBot::DoNoRecoil(CUserCmd* pCmd)
  10162. {
  10163.     // Ghetto rcs shit, implement properly later
  10164.     IClientEntity* pLocal = hackManager.pLocal();
  10165.     if (pLocal)
  10166.     {
  10167.         Vector AimPunch = pLocal->localPlayerExclusive()->GetAimPunchAngle();
  10168.         if (AimPunch.Length2D() > 0 && AimPunch.Length2D() < 150)
  10169.         {
  10170.             pCmd->viewangles -= AimPunch * 2;
  10171.             GameUtils::NormaliseViewAngle(pCmd->viewangles);
  10172.         }
  10173.     }
  10174. }
  10175.  
  10176. bool CRageBot::AimAtPoint(IClientEntity* pLocal, Vector point, CUserCmd* pCmd)
  10177. {
  10178.     bool ReturnValue = false;
  10179.     // Get the full angles
  10180.     if (point.Length() == 0) return ReturnValue;
  10181.  
  10182.     Vector angles;
  10183.     Vector src = pLocal->GetOrigin() + pLocal->GetViewOffset();
  10184.  
  10185.     CalcAngle(src, point, angles);
  10186.     GameUtils::NormaliseViewAngle(angles);
  10187.  
  10188.     if (angles[0] != angles[0] || angles[1] != angles[1])
  10189.     {
  10190.         return ReturnValue;
  10191.     }
  10192.  
  10193.  
  10194.     IsLocked = true;
  10195.     //-----------------------------------------------
  10196.  
  10197.     // Aim Step Calcs
  10198.     Vector ViewOffset = pLocal->GetOrigin() + pLocal->GetViewOffset();
  10199.     if (!IsAimStepping)
  10200.         LastAimstepAngle = LastAngle; // Don't just use the viewangs because you need to consider aa
  10201.  
  10202.     float fovLeft = FovToPlayer(ViewOffset, LastAimstepAngle, Interfaces::EntList->GetClientEntity(TargetID), 0);
  10203.  
  10204.     if (fovLeft > 25.0f && Menu::Window.RageBotTab.AimbotAimStep.GetState())
  10205.     {
  10206.         Vector AddAngs = angles - LastAimstepAngle;
  10207.         Normalize(AddAngs, AddAngs);
  10208.         AddAngs *= 25;
  10209.         LastAimstepAngle += AddAngs;
  10210.         GameUtils::NormaliseViewAngle(LastAimstepAngle);
  10211.         angles = LastAimstepAngle;
  10212.     }
  10213.     else
  10214.     {
  10215.         ReturnValue = true;
  10216.     }
  10217.  
  10218.     pCmd->viewangles = angles;
  10219.     if (!Menu::Window.RageBotTab.AimbotSilentAim.GetState())
  10220.         Interfaces::Engine->SetViewAngles(angles);
  10221.  
  10222.     return ReturnValue;
  10223. }
  10224.  
  10225. namespace AntiAims
  10226. {
  10227.     // Pitches
  10228.     void StaticPitch(CUserCmd* pCmd, bool up)
  10229.     {
  10230.         if (up)
  10231.             // Up
  10232.             pCmd->viewangles.x = -88;
  10233.         else
  10234.             // Up
  10235.             pCmd->viewangles.x = 88;
  10236.     }
  10237.  
  10238.     void JitterPitch(CUserCmd* pCmd)
  10239.     {
  10240.         static bool up = true;
  10241.         if (up) pCmd->viewangles.x = -88;
  10242.         else pCmd->viewangles.x = 88;
  10243.         up = !up;
  10244.     }
  10245.  
  10246.     // Yaws
  10247.     void FastSpint(CUserCmd* pCmd)
  10248.     {
  10249.         int random = 160 + rand() % 40;
  10250.         static float current_y = pCmd->viewangles.y;
  10251.         current_y += random;
  10252.         pCmd->viewangles.y = current_y;
  10253.     }
  10254.  
  10255.     void SlowSpin(CUserCmd* pCmd)
  10256.     {
  10257.         int random = rand() % 100;
  10258.         int random2 = rand() % 1000;
  10259.  
  10260.         static bool dir;
  10261.         static float current_y = pCmd->viewangles.y;
  10262.  
  10263.         if (random == 1) dir = !dir;
  10264.  
  10265.         if (dir)
  10266.             current_y += 5;
  10267.         else
  10268.             current_y -= 5;
  10269.  
  10270.         pCmd->viewangles.y = current_y;
  10271.  
  10272.         if (random == random2)
  10273.             pCmd->viewangles.y += random;
  10274.  
  10275.     }
  10276.  
  10277.     void BackJitter(CUserCmd* pCmd)
  10278.     {
  10279.         int random = rand() % 100;
  10280.  
  10281.         // Small chance of starting fowards
  10282.         if (random < 98)
  10283.             // Look backwards
  10284.             pCmd->viewangles.y -= 180;
  10285.  
  10286.         // Some gitter
  10287.         if (random < 15)
  10288.         {
  10289.             float change = -70 + (rand() % (int)(140 + 1));
  10290.             pCmd->viewangles.y += change;
  10291.         }
  10292.         if (random == 69)
  10293.         {
  10294.             float change = -90 + (rand() % (int)(180 + 1));
  10295.             pCmd->viewangles.y += change;
  10296.         }
  10297.  
  10298.     }
  10299.  
  10300.     void Flip(CUserCmd* pCmd)
  10301.     {
  10302.         static bool back = false;
  10303.         back = !back;
  10304.         if (back)
  10305.             pCmd->viewangles.y -= 180;
  10306.     }
  10307. }
  10308.  
  10309. // AntiAim
  10310. void CRageBot::DoAntiAim(CUserCmd* pCmd)
  10311. {
  10312.     // If the aimbot is doing something don't do anything
  10313.     if (IsAimStepping || pCmd->buttons & IN_ATTACK)
  10314.         return;
  10315.  
  10316.     // Weapon shit
  10317.     CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle(hackManager.pLocal()->GetActiveWeaponHandle());
  10318.     if (pWeapon)
  10319.     {
  10320.         CSWeaponInfo* pWeaponInfo = pWeapon->GetCSWpnData();
  10321.         // Knives or grenades
  10322.         if (!GameUtils::IsBallisticWeapon(pWeapon))
  10323.             return;
  10324.     }
  10325.  
  10326.     // Don't do antiaim
  10327.     // if (DoExit) return;
  10328.  
  10329.     // Anti-Aim Pitch
  10330.     switch (Menu::Window.RageBotTab.AntiAimPitch.GetIndex())
  10331.     {
  10332.         case 0:
  10333.             // No Pitch AA
  10334.             break;
  10335.         case 1:
  10336.             // up
  10337.             AntiAims::StaticPitch(pCmd, true);
  10338.             break;
  10339.         case 2:
  10340.             // Down
  10341.             AntiAims::StaticPitch(pCmd, false);
  10342.             break;
  10343.         case 3:
  10344.             // Jitter
  10345.             AntiAims::JitterPitch(pCmd);
  10346.             break;
  10347.     }
  10348.  
  10349.     //Anti-Aim Yaw
  10350.     switch (Menu::Window.RageBotTab.AntiAimYaw.GetIndex())
  10351.     {
  10352.         case 0:
  10353.             // No Yaw AA
  10354.             break;
  10355.         case 1:
  10356.             // Fast Spin
  10357.             AntiAims::FastSpint(pCmd);
  10358.             break;
  10359.         case 2:
  10360.             // Slow Spin
  10361.             AntiAims::SlowSpin(pCmd);
  10362.             break;
  10363.         case 3:
  10364.             // Inverse
  10365.             pCmd->viewangles.y -= 180;
  10366.             break;
  10367.         case 4:
  10368.             // Jitter
  10369.             AntiAims::BackJitter(pCmd);
  10370.             break;
  10371.         case 5:
  10372.             // Flip
  10373.             AntiAims::Flip(pCmd);
  10374.             break;
  10375.     }
  10376. }
  10377. /*
  10378. Syn's AYYWAREFramework 2015
  10379. */
  10380.  
  10381. #pragma once
  10382.  
  10383. #include "Hacks.h"
  10384.  
  10385. class CRageBot : public CHack
  10386. {
  10387. public:
  10388.         void Init();
  10389. void Draw();
  10390. void Move(CUserCmd* pCmd);
  10391. private:
  10392.         // Targetting
  10393.         int GetTargetCrosshair();
  10394. int GetTargetDistance();
  10395. int GetTargetHealth();
  10396. bool TargetMeetsRequirements(IClientEntity* pEntity);
  10397. float CRageBot::FovToPlayer(Vector ViewOffSet, Vector View, IClientEntity* pEntity, int HitBox);
  10398. int HitScan(IClientEntity* pEntity);
  10399. bool AimAtPoint(IClientEntity* pLocal, Vector point, CUserCmd* pCmd);
  10400.  
  10401. // Functionality
  10402. void DoAimbot(CUserCmd* pCmd);
  10403. void DoNoSpread(CUserCmd* pCmd);
  10404. void DoNoRecoil(CUserCmd* pCmd);
  10405.  
  10406. // AntiAim
  10407. void DoAntiAim(CUserCmd* pCmd);
  10408.  
  10409. // AimStep
  10410. bool IsAimStepping;
  10411. Vector LastAimstepAngle;
  10412. Vector LastAngle;
  10413.  
  10414. // Aimbot
  10415. bool IsLocked;
  10416. int TargetID;
  10417. int HitBox;
  10418. Vector AimPoint;
  10419. };/*
  10420. Syn's AYYWAREFramework 2015
  10421. */
  10422.  
  10423. #pragma once
  10424.  
  10425. #include "RenderManager.h"
  10426.  
  10427. #define _CRT_SECURE_NO_WARNINGS
  10428.  
  10429. // Font Instances
  10430. namespace Render
  10431. {
  10432.     // Text functions
  10433.     namespace Fonts
  10434.     {
  10435.         DWORD Default;
  10436.         DWORD Menu;
  10437.         DWORD MenuBold;
  10438.         DWORD ESP;
  10439.     };
  10440. };
  10441.  
  10442. // We don't use these anywhere else, no reason for them to be
  10443. // available anywhere else
  10444. enum EFontFlags
  10445. {
  10446.     FONTFLAG_NONE,
  10447.     FONTFLAG_ITALIC = 0x001,
  10448.     FONTFLAG_UNDERLINE = 0x002,
  10449.     FONTFLAG_STRIKEOUT = 0x004,
  10450.     FONTFLAG_SYMBOL = 0x008,
  10451.     FONTFLAG_ANTIALIAS = 0x010,
  10452.     FONTFLAG_GAUSSIANBLUR = 0x020,
  10453.     FONTFLAG_ROTARY = 0x040,
  10454.     FONTFLAG_DROPSHADOW = 0x080,
  10455.     FONTFLAG_ADDITIVE = 0x100,
  10456.     FONTFLAG_OUTLINE = 0x200,
  10457.     FONTFLAG_CUSTOM = 0x400,
  10458.     FONTFLAG_BITMAP = 0x800,
  10459. };
  10460.  
  10461. // Initialises the rendering system, setting up fonts etc
  10462. void Render::Initialise()
  10463. {
  10464.     Fonts::Default = 0x1D; // MainMenu Font from vgui_spew_fonts
  10465.     Fonts::Menu = Interfaces::Surface->FontCreate();
  10466.     Fonts::MenuBold = Interfaces::Surface->FontCreate();
  10467.     Fonts::ESP = Interfaces::Surface->FontCreate();
  10468.  
  10469.     Interfaces::Surface->SetFontGlyphSet(Fonts::Menu, "Terminal", 14, 500, 0, 0, FONTFLAG_ANTIALIAS);
  10470.     Interfaces::Surface->SetFontGlyphSet(Fonts::MenuBold, "Terminal", 14, 900, 0, 0, FONTFLAG_ANTIALIAS);
  10471.     Interfaces::Surface->SetFontGlyphSet(Fonts::ESP, "Terminal", 14, 500, 0, 0, FONTFLAG_ANTIALIAS /*| FONTFLAG_DROPSHADOW*/);
  10472.  
  10473.     Utilities::Log("Render System Ready");
  10474. }
  10475.  
  10476. RECT Render::GetViewport()
  10477. {
  10478.     RECT Viewport = { 0, 0, 0, 0 };
  10479.     int w, h;
  10480.     Interfaces::Engine->GetScreenSize(w, h);
  10481.     Viewport.right = w; Viewport.bottom = h;
  10482.     return Viewport;
  10483. }
  10484.  
  10485. void Render::Clear(int x, int y, int w, int h, Color color)
  10486. {
  10487.     Interfaces::Surface->DrawSetColor(color);
  10488.     Interfaces::Surface->DrawFilledRect(x, y, x + w, y + h);
  10489. }
  10490.  
  10491. void Render::Outline(int x, int y, int w, int h, Color color)
  10492. {
  10493.     Interfaces::Surface->DrawSetColor(color);
  10494.     Interfaces::Surface->DrawOutlinedRect(x, y, x + w, y + h);
  10495. }
  10496.  
  10497. void Render::Line(int x, int y, int x2, int y2, Color color)
  10498. {
  10499.     Interfaces::Surface->DrawSetColor(color);
  10500.     Interfaces::Surface->DrawLine(x, y, x2, y2);
  10501. }
  10502.  
  10503. void Render::PolyLine(int* x, int* y, int count, Color color)
  10504. {
  10505.     Interfaces::Surface->DrawSetColor(color);
  10506.     Interfaces::Surface->DrawPolyLine(x, y, count);
  10507. }
  10508.  
  10509. bool Render::WorldToScreen(Vector &in, Vector &out)
  10510. {
  10511.     const matrix3x4&worldToScreen = Interfaces::Engine->WorldToScreenMatrix(); //Grab the world to screen matrix from CEngineClient::WorldToScreenMatrix
  10512.  
  10513.     float w = worldToScreen[3][0] * in[0] + worldToScreen[3][1] * in[1] + worldToScreen[3][2] * in[2] + worldToScreen[3][3]; //Calculate the angle in compareson to the player's camera.
  10514.         out.z = 0; //Screen doesn't have a 3rd dimension.
  10515.  
  10516.         if (w > 0.001) //If the object is within view.
  10517.         {
  10518.                 RECT ScreenSize = GetViewport();
  10519. float fl1DBw = 1 / w; //Divide 1 by the angle.
  10520.                 out.x = (ScreenSize.right / 2) + (0.5f * ((worldToScreen[0][0] * in[0] + worldToScreen[0][1] * in[1] + worldToScreen[0][2] * in[2] + worldToScreen[0][3]) * fl1DBw) * ScreenSize.right + 0.5f); //Get the X dimension and push it in to the Vector.
  10521.                 out.y = (ScreenSize.bottom / 2) - (0.5f * ((worldToScreen[1][0] * in[0] + worldToScreen[1][1] * in[1] + worldToScreen[1][2] * in[2] + worldToScreen[1][3]) * fl1DBw) * ScreenSize.bottom + 0.5f); //Get the Y dimension and push it in to the Vector.
  10522.                 return true;
  10523.         }
  10524.  
  10525.         return false;
  10526. }
  10527.  
  10528. void Render::Text(int x, int y, Color color, DWORD font, const char* text)
  10529. {
  10530.     size_t origsize = strlen(text) + 1;
  10531.     const size_t newsize = 100;
  10532.     size_t convertedChars = 0;
  10533.     wchar_t wcstring[newsize];
  10534.     mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE);
  10535.  
  10536.     Interfaces::Surface->DrawSetTextFont(font);
  10537.  
  10538.     Interfaces::Surface->DrawSetTextColor(color);
  10539.     Interfaces::Surface->DrawSetTextPos(x, y);
  10540.     Interfaces::Surface->DrawPrintText(wcstring, wcslen(wcstring));
  10541.     return;
  10542. }
  10543.  
  10544. void Render::Text(int x, int y, Color color, DWORD font, const wchar_t* text)
  10545. {
  10546.     Interfaces::Surface->DrawSetTextFont(font);
  10547.     Interfaces::Surface->DrawSetTextColor(color);
  10548.     Interfaces::Surface->DrawSetTextPos(x, y);
  10549.     Interfaces::Surface->DrawPrintText(text, wcslen(text));
  10550. }
  10551.  
  10552. void Render::Textf(int x, int y, Color color, DWORD font, const char* fmt, ...)
  10553. {
  10554.     if (!fmt) return; //if the passed string is null return
  10555.     if (strlen(fmt) < 2) return;
  10556.  
  10557.     //Set up va_list and buffer to hold the params
  10558.     va_list va_alist;
  10559.     char logBuf[256] = { 0 };
  10560.  
  10561.     //Do sprintf with the parameters
  10562.     va_start(va_alist, fmt);
  10563.     _vsnprintf_s(logBuf + strlen(logBuf), 256 - strlen(logBuf), sizeof(logBuf) - strlen(logBuf), fmt, va_alist);
  10564.     va_end(va_alist);
  10565.  
  10566.     Text(x, y, color, font, logBuf);
  10567. }
  10568.  
  10569. RECT Render::GetTextSize(DWORD font, const char* text)
  10570. {
  10571.     size_t origsize = strlen(text) + 1;
  10572.     const size_t newsize = 100;
  10573.     size_t convertedChars = 0;
  10574.     wchar_t wcstring[newsize];
  10575.     mbstowcs_s(&convertedChars, wcstring, origsize, text, _TRUNCATE);
  10576.  
  10577.     RECT rect; int x, y;
  10578.     Interfaces::Surface->GetTextSize(font, wcstring, x, y);
  10579.     rect.left = x; rect.bottom = y;
  10580.     rect.right = x;
  10581.     return rect;
  10582. }
  10583.  
  10584. void Render::GradientV(int x, int y, int w, int h, Color c1, Color c2)
  10585. {
  10586.     Clear(x, y, w, h, c1);
  10587.     BYTE first = c2.r();
  10588.     BYTE second = c2.g();
  10589.     BYTE third = c2.b();
  10590.     for (int i = 0; i < h; i++)
  10591.     {
  10592.         float fi = i, fh = h;
  10593.         float a = fi / fh;
  10594.         DWORD ia = a * 255;
  10595.         Clear(x, y + i, w, 1, Color(first, second, third, ia));
  10596.     }
  10597. }
  10598.  
  10599. void Render::GradientH(int x, int y, int w, int h, Color c1, Color c2)
  10600. {
  10601.     Clear(x, y, w, h, c1);
  10602.     BYTE first = c2.r();
  10603.     BYTE second = c2.g();
  10604.     BYTE third = c2.b();
  10605.     for (int i = 0; i < w; i++)
  10606.     {
  10607.         float fi = i, fw = w;
  10608.         float a = fi / fw;
  10609.         DWORD ia = a * 255;
  10610.         Clear(x + i, y, 1, h, Color(first, second, third, ia));
  10611.     }
  10612. }
  10613.  
  10614. void Render::Polygon(int count, Vertex_t* Vertexs, Color color)
  10615. {
  10616.     static int Texture = Interfaces::Surface->CreateNewTextureID(true); //need to make a texture with procedural true
  10617.     unsigned char buffer[4] = { 255, 255, 255, 255 };//{ color.r(), color.g(), color.b(), color.a() };
  10618.  
  10619.     Interfaces::Surface->DrawSetTextureRGBA(Texture, buffer, 1, 1); //Texture, char array of texture, width, height
  10620.     Interfaces::Surface->DrawSetColor(color); // keep this full color and opacity use the RGBA @top to set values.
  10621.     Interfaces::Surface->DrawSetTexture(Texture); // bind texture
  10622.  
  10623.     Interfaces::Surface->DrawTexturedPolygon(count, Vertexs);
  10624. }
  10625.  
  10626. void Render::PolygonOutline(int count, Vertex_t* Vertexs, Color color, Color colorLine)
  10627. {
  10628.     static int x[128];
  10629.     static int y[128];
  10630.  
  10631.     Render::Polygon(count, Vertexs, color);
  10632.  
  10633.     for (int i = 0; i < count; i++)
  10634.     {
  10635.         x[i] = Vertexs[i].m_Position.x;
  10636.         y[i] = Vertexs[i].m_Position.y;
  10637.     }
  10638.  
  10639.     Render::PolyLine(x, y, count, colorLine);
  10640. }
  10641.  
  10642. void Render::PolyLine(int count, Vertex_t* Vertexs, Color colorLine)
  10643. {
  10644.     static int x[128];
  10645.     static int y[128];
  10646.  
  10647.     for (int i = 0; i < count; i++)
  10648.     {
  10649.         x[i] = Vertexs[i].m_Position.x;
  10650.         y[i] = Vertexs[i].m_Position.y;
  10651.     }
  10652.  
  10653.     Render::PolyLine(x, y, count, colorLine);
  10654. }/*
  10655. Syn's AYYWAREFramework 2015
  10656. */
  10657.  
  10658. #pragma once
  10659.  
  10660. #include "Interfaces.h"
  10661.  
  10662. #include "Vector2D.h"
  10663.  
  10664. void Quad();
  10665.  
  10666.  
  10667. namespace Render
  10668. {
  10669.     void Initialise();
  10670.  
  10671.     // Normal Drawing functions
  10672.     void Clear(int x, int y, int w, int h, Color color);
  10673.     void Outline(int x, int y, int w, int h, Color color);
  10674.     void Line(int x, int y, int x2, int y2, Color color);
  10675.     void PolyLine(int* x, int* y, int count, Color color);
  10676.     void Polygon(int count, Vertex_t* Vertexs, Color color);
  10677.     void PolygonOutline(int count, Vertex_t* Vertexs, Color color, Color colorLine);
  10678.     void PolyLine(int count, Vertex_t* Vertexs, Color colorLine);
  10679.  
  10680.     // Gradient Functions
  10681.     void GradientV(int x, int y, int w, int h, Color c1, Color c2);
  10682.     void GradientH(int x, int y, int w, int h, Color c1, Color c2);
  10683.  
  10684.     // Text functions
  10685.     namespace Fonts
  10686.     {
  10687.         extern DWORD Default;
  10688.                 extern DWORD Menu;
  10689.                 extern DWORD MenuBold;
  10690.                 extern DWORD ESP;
  10691.  
  10692.         };
  10693.  
  10694.     void Text(int x, int y, Color color, DWORD font, const char* text);
  10695.     void Textf(int x, int y, Color color, DWORD font, const char* fmt, ...);
  10696.     void Text(int x, int y, Color color, DWORD font, const wchar_t* text);
  10697.     RECT GetTextSize(DWORD font, const char* text);
  10698.  
  10699.     // Other rendering functions
  10700.     bool WorldToScreen(Vector &in, Vector &out);
  10701.     RECT GetViewport();
  10702. };
  10703.  
  10704. /*
  10705. Syn's AYYWAREFramework 2015
  10706. */
  10707.  
  10708. #pragma once
  10709.  
  10710. // Our stuff
  10711. # include "Entities.h"
  10712. # include "offsets.h"
  10713. # include "ClientRecvProps.h"
  10714. # include "BaseClient.h"
  10715. # include "EngineClient.h"
  10716. # include "MiscClasses.h"
  10717. # include "Surface.h"
  10718. # include "Materials.h"
  10719.  
  10720.  
  10721. // Valve
  10722. # include "Vector.h"
  10723. # include "Vector2D.h"
  10724. # include "bspflags.h"
  10725.  
  10726. // Management Classes
  10727. # include "Interfaces.h"
  10728.  
  10729. // Functions
  10730. # include "UTIL Functions.h"
  10731. # include "MathFunctions.h"
  10732. /*
  10733. Syn's AYYWAREFramework 2015
  10734. */
  10735.  
  10736. #pragma once
  10737.  
  10738. # include "MiscDefinitions.h"
  10739. # include "ClientRecvProps.h"
  10740. # include "offsets.h"
  10741. # include "Vector.h"
  10742. # include "MiscClasses.h"
  10743. # include "Vector2D.h"
  10744.  
  10745. struct Vertex_t
  10746. {
  10747.     Vector2D m_Position;
  10748.     Vector2D m_TexCoord;
  10749.  
  10750.     Vertex_t() { }
  10751.     Vertex_t(const Vector2D &pos, const Vector2D &coord = Vector2D(0, 0))
  10752.         {
  10753.                 m_Position = pos;
  10754.                 m_TexCoord = coord;
  10755.         }
  10756. void Init(const Vector2D &pos, const Vector2D &coord = Vector2D(0, 0))
  10757. {
  10758.     m_Position = pos;
  10759.     m_TexCoord = coord;
  10760. }
  10761. };
  10762.  
  10763. typedef Vertex_t FontVertex_t;
  10764.  
  10765. // Surface Drawing
  10766. class ISurface
  10767. {
  10768.     public:
  10769.         void DrawSetColor(Color col)
  10770.     {
  10771.         typedef void(__thiscall * oDrawSetColor)(PVOID, Color);
  10772.         return call_vfunc<oDrawSetColor>(this, Offsets::VMT::Surface_DrawSetColorA)(this, col);
  10773.     }
  10774.  
  10775.     void DrawSetColor(int r, int g, int b, int a)
  10776.     {
  10777.         typedef void(__thiscall * OriginalFn)(PVOID, int, int, int, int);
  10778.         call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawSetColorB)(this, r, g, b, a);
  10779.     }
  10780.  
  10781.     void DrawFilledRect(int x0, int y0, int x1, int y1)
  10782.     {
  10783.         typedef void(__thiscall * OriginalFn)(PVOID, int, int, int, int);
  10784.         call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawFilledRect)(this, x0, y0, x1, y1);
  10785.     }
  10786.  
  10787.     void DrawOutlinedRect(int x0, int y0, int x1, int y1)
  10788.     {
  10789.         typedef void(__thiscall * OriginalFn)(PVOID, int, int, int, int);
  10790.         call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawOutlinedRect)(this, x0, y0, x1, y1);
  10791.     }
  10792.  
  10793.     void DrawLine(int x0, int y0, int x1, int y1)
  10794.     {
  10795.         typedef void(__thiscall * OriginalFn)(PVOID, int, int, int, int);
  10796.         call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawLine)(this, x0, y0, x1, y1);
  10797.     }
  10798.  
  10799.     void DrawPolyLine(int* x, int* y, int count)
  10800.     {
  10801.         typedef void(__thiscall * OriginalFn)(PVOID, int *, int *, int);
  10802.         call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawLine + 1)(this, x, y, count);
  10803.     }
  10804.  
  10805.     void DrawSetTextFont(unsigned long font)
  10806.     {
  10807.         typedef void(__thiscall * OriginalFn)(PVOID, unsigned long);
  10808.         call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawSetTextFont)(this, font);
  10809.     }
  10810.  
  10811.     void DrawSetTextColor(int r, int g, int b, int a)
  10812.     {
  10813.         typedef void(__thiscall * OriginalFn)(PVOID, int, int, int, int);
  10814.         call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawSetTextColorB)(this, r, g, b, a);
  10815.     }
  10816.  
  10817.     void DrawSetTextColor(Color col)
  10818.     {
  10819.         typedef void(__thiscall * oDrawSetTextColor)(PVOID, Color);
  10820.         return call_vfunc<oDrawSetTextColor>(this, Offsets::VMT::Surface_DrawSetTextColorA)(this, col);
  10821.     }
  10822.  
  10823.     void DrawSetTextPos(int x, int y)
  10824.     {
  10825.         typedef void(__thiscall * OriginalFn)(PVOID, int, int);
  10826.         call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawSetTextPos)(this, x, y);
  10827.     }
  10828.  
  10829.     void DrawPrintText(const wchar_t* text, int textLen)
  10830.         {
  10831.  
  10832.         typedef void(__thiscall* OriginalFn)(PVOID, const wchar_t*, int, int);
  10833.                 call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_DrawPrintText)(this, text, textLen, 0);
  10834.         }
  10835.  
  10836. void DrawSetTexture(int textureID)
  10837. {
  10838.     typedef void(__thiscall * oDrawSetTextColor)(PVOID, int);
  10839.     return call_vfunc<oDrawSetTextColor>(this, Offsets::VMT::Surface_DrawSetTexture)(this, textureID);
  10840. }
  10841.  
  10842. void DrawSetTextureRGBA(int textureID, unsigned char  const* colors, int w, int h)
  10843. {
  10844.     typedef void(__thiscall * oDrawSetTextColor)(PVOID, int, unsigned char  const*, int, int);
  10845.     return call_vfunc<oDrawSetTextColor>(this, Offsets::VMT::Surface_DrawSetTextureRGBA)(this, textureID, colors, w, h);
  10846. }
  10847.  
  10848. int CreateNewTextureID(bool procedural)
  10849. {
  10850.     typedef int(__thiscall * oDrawSetTextColor)(PVOID, bool);
  10851.     return call_vfunc<oDrawSetTextColor>(this, Offsets::VMT::Surface_CreateNewTextureID)(this, procedural);
  10852. }
  10853.  
  10854. void DrawTexturedPolygon(int vtxCount, FontVertex_t* vtx, bool bClipVertices = true)
  10855. {
  10856.     typedef void(__thiscall * oDrawSetTextColor)(PVOID, int, FontVertex_t *, bool);
  10857.     return call_vfunc<oDrawSetTextColor>(this, Offsets::VMT::Surface_DrawTexturedPolygon)(this, vtxCount, vtx, bClipVertices);
  10858. }
  10859.  
  10860. unsigned long FontCreate()
  10861. {
  10862.     typedef unsigned int(__thiscall * OriginalFn)(PVOID);
  10863.     return call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_FontCreate)(this);
  10864. }
  10865.  
  10866. void SetFontGlyphSet(unsigned long font, const char* windowsFontName, int tall, int weight, int blur, int scanlines, int flags)
  10867. {
  10868.     typedef void(__thiscall * OriginalFn)(PVOID, unsigned long, const char*, int, int, int, int, int, int, int);
  10869.     call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_SetFontGlyphSet)(this, font, windowsFontName, tall, weight, blur, scanlines, flags, 0, 0);
  10870. }
  10871.  
  10872. void GetTextSize(unsigned long font, const wchar_t* text, int& wide, int& tall)
  10873. {
  10874.     typedef void(__thiscall * OriginalFn)(PVOID, unsigned long, const wchar_t*, int&, int&);
  10875.     call_vfunc<OriginalFn>(this, Offsets::VMT::Surface_GetTextSize)(this, font, text, wide, tall);
  10876. }
  10877.  
  10878. void DrawOutlinedCircle(int x, int y, int r, int seg)
  10879. {
  10880.     typedef void(__thiscall * oDrawOutlinedCircle)(PVOID, int, int, int, int);
  10881.     return call_vfunc<oDrawOutlinedCircle>(this, Offsets::VMT::Surface_DrawOutlinedCircle)(this, x, y, r, seg);
  10882. }
  10883.  
  10884. void SurfaceGetCursorPos(int &x, int &y)
  10885. {
  10886.     typedef void(__thiscall * oSurfaceGetCursorPos)(PVOID, int &, int &);
  10887.     return call_vfunc<oSurfaceGetCursorPos>(this, Offsets::VMT::Surface_SurfaceGetCursorPos)(this, x, y);
  10888. }
  10889. };/*
  10890. Original code by Lee Thomason (www.grinninglizard.com)
  10891.  
  10892. This software is provided 'as-is', without any express or implied
  10893. warranty. In no event will the authors be held liable for any
  10894. damages arising from the use of this software.
  10895.  
  10896. Permission is granted to anyone to use this software for any
  10897. purpose, including commercial applications, and to alter it and
  10898. redistribute it freely, subject to the following restrictions:
  10899.  
  10900. 1. The origin of this software must not be misrepresented; you must
  10901. not claim that you wrote the original software. If you use this
  10902. software in a product, an acknowledgment in the product documentation
  10903. would be appreciated but is not required.
  10904.  
  10905. 2. Altered source versions must be plainly marked as such, and
  10906. must not be misrepresented as being the original software.
  10907.  
  10908. 3. This notice may not be removed or altered from any source
  10909. distribution.
  10910. */
  10911.  
  10912. #include "tinyxml2.h"
  10913.  
  10914. #include <new>          // yes, this one new style header, is in the Android SDK.
  10915. #if defined(ANDROID_NDK) || defined(__QNXNTO__)
  10916. #   include <stddef.h>
  10917. #   include <stdarg.h>
  10918. #else
  10919. #   include <cstddef>
  10920. #   include <cstdarg>
  10921. #endif
  10922.  
  10923. #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
  10924.         // Microsoft Visual Studio, version 2005 and higher. Not WinCE.
  10925.         /*int _snprintf_s(
  10926.            char *buffer,
  10927.            size_t sizeOfBuffer,
  10928.            size_t count,
  10929.            const char *format [,
  10930.                   argument] ...
  10931.         );*/
  10932.         static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
  10933.         {
  10934.                 va_list va;
  10935.                 va_start( va, format );
  10936.                 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
  10937.                 va_end( va );
  10938.                 return result;
  10939.         }
  10940.  
  10941.         static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va )
  10942.         {
  10943.                 int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
  10944.                 return result;
  10945.         }
  10946.  
  10947.         #define TIXML_VSCPRINTF _vscprintf
  10948.         #define TIXML_SSCANF    sscanf_s
  10949. #elif defined _MSC_VER
  10950.         // Microsoft Visual Studio 2003 and earlier or WinCE
  10951.         #define TIXML_SNPRINTF  _snprintf
  10952.         #define TIXML_VSNPRINTF _vsnprintf
  10953.         #define TIXML_SSCANF    sscanf
  10954.         #if (_MSC_VER < 1400 ) && (!defined WINCE)
  10955.                 // Microsoft Visual Studio 2003 and not WinCE.
  10956.                 #define TIXML_VSCPRINTF   _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have.
  10957.         #else
  10958.                 // Microsoft Visual Studio 2003 and earlier or WinCE.
  10959.                 static inline int TIXML_VSCPRINTF( const char* format, va_list va )
  10960.                 {
  10961.                         int len = 512;
  10962.                         for (;;) {
  10963.                                 len = len*2;
  10964.                                 char* str = new char[len]();
  10965.                                 const int required = _vsnprintf(str, len, format, va);
  10966.                                 delete[] str;
  10967.                                 if ( required != -1 ) {
  10968.                                         TIXMLASSERT( required >= 0 );
  10969.                                         len = required;
  10970.                                         break;
  10971.                                 }
  10972.                         }
  10973.                         TIXMLASSERT( len >= 0 );
  10974.                         return len;
  10975.                 }
  10976.         #endif
  10977. #else
  10978.         // GCC version 3 and higher
  10979.         //#warning( "Using sn* functions." )
  10980.         #define TIXML_SNPRINTF  snprintf
  10981.         #define TIXML_VSNPRINTF vsnprintf
  10982.         static inline int TIXML_VSCPRINTF( const char* format, va_list va)
  10983. {
  10984.     int len = vsnprintf(0, 0, format, va);
  10985.     TIXMLASSERT(len >= 0);
  10986.     return len;
  10987. }
  10988. #define TIXML_SSCANF   sscanf
  10989. #endif
  10990.  
  10991.  
  10992. static const char LINE_FEED = (char)0x0a;                       // all line endings are normalized to LF
  10993. static const char LF = LINE_FEED;
  10994. static const char CARRIAGE_RETURN = (char)0x0d;                 // CR gets filtered out
  10995. static const char CR = CARRIAGE_RETURN;
  10996. static const char SINGLE_QUOTE = '\'';
  10997. static const char DOUBLE_QUOTE = '\"';
  10998.  
  10999. // Bunch of unicode info at:
  11000. //              http://www.unicode.org/faq/utf_bom.html
  11001. //      ef bb bf (Microsoft "lead bytes") - designates UTF-8
  11002.  
  11003. static const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
  11004. static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
  11005. static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
  11006.  
  11007. namespace tinyxml2
  11008. {
  11009.  
  11010.     struct Entity
  11011.     {
  11012.         const char* pattern;
  11013.         int length;
  11014.         char value;
  11015.     };
  11016.  
  11017.     static const int NUM_ENTITIES = 5;
  11018.     static const Entity entities[NUM_ENTITIES] = {
  11019.     { "quot", 4,    DOUBLE_QUOTE },
  11020.     { "amp", 3,     '&'  },
  11021.     { "apos", 4,    SINGLE_QUOTE },
  11022.     { "lt", 2,      '<'  },
  11023.     { "gt", 2,      '>'  }
  11024. };
  11025.  
  11026.  
  11027.     StrPair::~StrPair()
  11028.     {
  11029.         Reset();
  11030.     }
  11031.  
  11032.  
  11033.     void StrPair::TransferTo(StrPair* other)
  11034.     {
  11035.         if (this == other)
  11036.         {
  11037.             return;
  11038.         }
  11039.         // This in effect implements the assignment operator by "moving"
  11040.         // ownership (as in auto_ptr).
  11041.  
  11042.         TIXMLASSERT(other->_flags == 0);
  11043.         TIXMLASSERT(other->_start == 0);
  11044.         TIXMLASSERT(other->_end == 0);
  11045.  
  11046.         other->Reset();
  11047.  
  11048.         other->_flags = _flags;
  11049.         other->_start = _start;
  11050.         other->_end = _end;
  11051.  
  11052.         _flags = 0;
  11053.         _start = 0;
  11054.         _end = 0;
  11055.     }
  11056.  
  11057.     void StrPair::Reset()
  11058.     {
  11059.         if (_flags & NEEDS_DELETE)
  11060.         {
  11061.             delete[] _start;
  11062.         }
  11063.         _flags = 0;
  11064.         _start = 0;
  11065.         _end = 0;
  11066.     }
  11067.  
  11068.  
  11069.     void StrPair::SetStr( const char* str, int flags)
  11070.     {
  11071.         Reset();
  11072.         size_t len = strlen(str);
  11073.         TIXMLASSERT(_start == 0);
  11074.         _start = new char[len + 1];
  11075.         memcpy(_start, str, len + 1);
  11076.         _end = _start + len;
  11077.         _flags = flags | NEEDS_DELETE;
  11078.     }
  11079.  
  11080.  
  11081.     char* StrPair::ParseText(char* p, const char* endTag, int strFlags)
  11082.     {
  11083.         TIXMLASSERT(endTag && *endTag);
  11084.  
  11085.         char* start = p;
  11086.         char endChar = *endTag;
  11087.         size_t length = strlen(endTag);
  11088.  
  11089.         // Inner loop of text parsing.
  11090.         while (*p)
  11091.         {
  11092.             if (*p == endChar && strncmp(p, endTag, length) == 0)
  11093.             {
  11094.                 Set(start, p, strFlags);
  11095.                 return p + length;
  11096.             }
  11097.             ++p;
  11098.         }
  11099.         return 0;
  11100.     }
  11101.  
  11102.  
  11103.     char* StrPair::ParseName(char* p)
  11104.     {
  11105.         if (!p || !(*p))
  11106.         {
  11107.             return 0;
  11108.         }
  11109.         if (!XMLUtil::IsNameStartChar(*p))
  11110.         {
  11111.             return 0;
  11112.         }
  11113.  
  11114.         char* const start = p;
  11115.         ++p;
  11116.         while (*p && XMLUtil::IsNameChar(*p))
  11117.         {
  11118.             ++p;
  11119.         }
  11120.  
  11121.         Set(start, p, 0);
  11122.         return p;
  11123.     }
  11124.  
  11125.  
  11126.     void StrPair::CollapseWhitespace()
  11127.     {
  11128.         // Adjusting _start would cause undefined behavior on delete[]
  11129.         TIXMLASSERT((_flags & NEEDS_DELETE) == 0);
  11130.         // Trim leading space.
  11131.         _start = XMLUtil::SkipWhiteSpace(_start);
  11132.  
  11133.         if (*_start)
  11134.         {
  11135.             char* p = _start;   // the read pointer
  11136.             char* q = _start;   // the write pointer
  11137.  
  11138.             while (*p)
  11139.             {
  11140.                 if (XMLUtil::IsWhiteSpace(*p))
  11141.                 {
  11142.                     p = XMLUtil::SkipWhiteSpace(p);
  11143.                     if (*p == 0)
  11144.                     {
  11145.                         break;    // don't write to q; this trims the trailing space.
  11146.                     }
  11147.                     *q = ' ';
  11148.                     ++q;
  11149.                 }
  11150.                 *q = *p;
  11151.                 ++q;
  11152.                 ++p;
  11153.             }
  11154.             *q = 0;
  11155.         }
  11156.     }
  11157.  
  11158.  
  11159.     const char* StrPair::GetStr()
  11160.     {
  11161.         TIXMLASSERT(_start);
  11162.         TIXMLASSERT(_end);
  11163.         if (_flags & NEEDS_FLUSH)
  11164.         {
  11165.             *_end = 0;
  11166.             _flags ^= NEEDS_FLUSH;
  11167.  
  11168.             if (_flags)
  11169.             {
  11170.                 char* p = _start;   // the read pointer
  11171.                 char* q = _start;   // the write pointer
  11172.  
  11173.                 while (p < _end)
  11174.                 {
  11175.                     if ((_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR)
  11176.                     {
  11177.                         // CR-LF pair becomes LF
  11178.                         // CR alone becomes LF
  11179.                         // LF-CR becomes LF
  11180.                         if (*(p + 1) == LF)
  11181.                         {
  11182.                             p += 2;
  11183.                         }
  11184.                         else
  11185.                         {
  11186.                             ++p;
  11187.                         }
  11188.                         *q++ = LF;
  11189.                     }
  11190.                     else if ((_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF)
  11191.                     {
  11192.                         if (*(p + 1) == CR)
  11193.                         {
  11194.                             p += 2;
  11195.                         }
  11196.                         else
  11197.                         {
  11198.                             ++p;
  11199.                         }
  11200.                         *q++ = LF;
  11201.                     }
  11202.                     else if ((_flags & NEEDS_ENTITY_PROCESSING) && *p == '&')
  11203.                     {
  11204.                         // Entities handled by tinyXML2:
  11205.                         // - special entities in the entity table [in/out]
  11206.                         // - numeric character reference [in]
  11207.                         //   &#20013; or &#x4e2d;
  11208.  
  11209.                         if (*(p + 1) == '#')
  11210.                         {
  11211.                             const int buflen = 10;
  11212.                             char buf[buflen] = { 0 };
  11213.                             int len = 0;
  11214.                             char* adjusted = const_cast<char*>(XMLUtil::GetCharacterRef(p, buf, &len));
  11215.                             if (adjusted == 0)
  11216.                             {
  11217.                                 *q = *p;
  11218.                                 ++p;
  11219.                                 ++q;
  11220.                             }
  11221.                             else
  11222.                             {
  11223.                                 TIXMLASSERT(0 <= len && len <= buflen);
  11224.                                 TIXMLASSERT(q + len <= adjusted);
  11225.                                 p = adjusted;
  11226.                                 memcpy(q, buf, len);
  11227.                                 q += len;
  11228.                             }
  11229.                         }
  11230.                         else
  11231.                         {
  11232.                             bool entityFound = false;
  11233.                             for (int i = 0; i < NUM_ENTITIES; ++i)
  11234.                             {
  11235.                                 const Entity&entity = entities[i];
  11236.                                 if (strncmp(p + 1, entity.pattern, entity.length) == 0
  11237.                                         && *(p + entity.length + 1) == ';')
  11238.                                 {
  11239.                                     // Found an entity - convert.
  11240.                                     *q = entity.value;
  11241.                                     ++q;
  11242.                                     p += entity.length + 2;
  11243.                                     entityFound = true;
  11244.                                     break;
  11245.                                 }
  11246.                             }
  11247.                             if (!entityFound)
  11248.                             {
  11249.                                 // fixme: treat as error?
  11250.                                 ++p;
  11251.                                 ++q;
  11252.                             }
  11253.                         }
  11254.                     }
  11255.                     else
  11256.                     {
  11257.                         *q = *p;
  11258.                         ++p;
  11259.                         ++q;
  11260.                     }
  11261.                 }
  11262.                 *q = 0;
  11263.             }
  11264.             // The loop below has plenty going on, and this
  11265.             // is a less useful mode. Break it out.
  11266.             if (_flags & NEEDS_WHITESPACE_COLLAPSING)
  11267.             {
  11268.                 CollapseWhitespace();
  11269.             }
  11270.             _flags = (_flags & NEEDS_DELETE);
  11271.         }
  11272.         TIXMLASSERT(_start);
  11273.         return _start;
  11274.     }
  11275.  
  11276.  
  11277.  
  11278.  
  11279.     // --------- XMLUtil ----------- //
  11280.  
  11281.     const char* XMLUtil::ReadBOM( const char* p, bool* bom)
  11282.     {
  11283.         TIXMLASSERT(p);
  11284.         TIXMLASSERT(bom);
  11285.         *bom = false;
  11286.         const unsigned char* pu = reinterpret_cast <const unsigned char*> (p);
  11287.         // Check for BOM:
  11288.         if (*(pu + 0) == TIXML_UTF_LEAD_0
  11289.                 && *(pu + 1) == TIXML_UTF_LEAD_1
  11290.                 && *(pu + 2) == TIXML_UTF_LEAD_2)
  11291.         {
  11292.             *bom = true;
  11293.             p += 3;
  11294.         }
  11295.         TIXMLASSERT(p);
  11296.         return p;
  11297.     }
  11298.  
  11299.  
  11300.     void XMLUtil::ConvertUTF32ToUTF8(unsigned long input, char* output, int* length)
  11301.     {
  11302.         const unsigned long BYTE_MASK = 0xBF;
  11303.         const unsigned long BYTE_MARK = 0x80;
  11304.         const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
  11305.  
  11306.         if (input < 0x80)
  11307.         {
  11308.             *length = 1;
  11309.         }
  11310.         else if (input < 0x800)
  11311.         {
  11312.             *length = 2;
  11313.         }
  11314.         else if (input < 0x10000)
  11315.         {
  11316.             *length = 3;
  11317.         }
  11318.         else if (input < 0x200000)
  11319.         {
  11320.             *length = 4;
  11321.         }
  11322.         else
  11323.         {
  11324.             *length = 0;    // This code won't convert this correctly anyway.
  11325.             return;
  11326.         }
  11327.  
  11328.         output += *length;
  11329.  
  11330.         // Scary scary fall throughs.
  11331.         switch (*length)
  11332.         {
  11333.             case 4:
  11334.                 --output;
  11335.                 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
  11336.                 input >>= 6;
  11337.             case 3:
  11338.                 --output;
  11339.                 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
  11340.                 input >>= 6;
  11341.             case 2:
  11342.                 --output;
  11343.                 *output = (char)((input | BYTE_MARK) & BYTE_MASK);
  11344.                 input >>= 6;
  11345.             case 1:
  11346.                 --output;
  11347.                 *output = (char)(input | FIRST_BYTE_MARK[*length]);
  11348.                 break;
  11349.             default:
  11350.                 TIXMLASSERT(false);
  11351.         }
  11352.     }
  11353.  
  11354.  
  11355.     const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length)
  11356.     {
  11357.         // Presume an entity, and pull it out.
  11358.         *length = 0;
  11359.  
  11360.         if (*(p + 1) == '#' && *(p + 2))
  11361.         {
  11362.             unsigned long ucs = 0;
  11363.             TIXMLASSERT(sizeof(ucs) >= 4);
  11364.             ptrdiff_t delta = 0;
  11365.             unsigned mult = 1;
  11366.             static const char SEMICOLON = ';';
  11367.  
  11368.             if (*(p + 2) == 'x')
  11369.             {
  11370.                 // Hexadecimal.
  11371.                 const char* q = p + 3;
  11372.                 if (!(*q))
  11373.                 {
  11374.                     return 0;
  11375.                 }
  11376.  
  11377.                 q = strchr(q, SEMICOLON);
  11378.  
  11379.                 if (!q)
  11380.                 {
  11381.                     return 0;
  11382.                 }
  11383.                 TIXMLASSERT(*q == SEMICOLON);
  11384.  
  11385.                 delta = q - p;
  11386.                 --q;
  11387.  
  11388.                 while (*q != 'x')
  11389.                 {
  11390.                     unsigned int digit = 0;
  11391.  
  11392.                     if (*q >= '0' && *q <= '9')
  11393.                     {
  11394.                         digit = *q - '0';
  11395.                     }
  11396.                     else if (*q >= 'a' && *q <= 'f')
  11397.                     {
  11398.                         digit = *q - 'a' + 10;
  11399.                     }
  11400.                     else if (*q >= 'A' && *q <= 'F')
  11401.                     {
  11402.                         digit = *q - 'A' + 10;
  11403.                     }
  11404.                     else
  11405.                     {
  11406.                         return 0;
  11407.                     }
  11408.                     TIXMLASSERT(digit >= 0 && digit < 16);
  11409.                     TIXMLASSERT(digit == 0 || mult <= UINT_MAX / digit);
  11410.                     const unsigned int digitScaled = mult * digit;
  11411.                     TIXMLASSERT(ucs <= ULONG_MAX - digitScaled);
  11412.                     ucs += digitScaled;
  11413.                     TIXMLASSERT(mult <= UINT_MAX / 16);
  11414.                     mult *= 16;
  11415.                     --q;
  11416.                 }
  11417.             }
  11418.             else
  11419.             {
  11420.                 // Decimal.
  11421.                 const char* q = p + 2;
  11422.                 if (!(*q))
  11423.                 {
  11424.                     return 0;
  11425.                 }
  11426.  
  11427.                 q = strchr(q, SEMICOLON);
  11428.  
  11429.                 if (!q)
  11430.                 {
  11431.                     return 0;
  11432.                 }
  11433.                 TIXMLASSERT(*q == SEMICOLON);
  11434.  
  11435.                 delta = q - p;
  11436.                 --q;
  11437.  
  11438.                 while (*q != '#')
  11439.                 {
  11440.                     if (*q >= '0' && *q <= '9')
  11441.                     {
  11442.                         const unsigned int digit = *q - '0';
  11443.                         TIXMLASSERT(digit >= 0 && digit < 10);
  11444.                         TIXMLASSERT(digit == 0 || mult <= UINT_MAX / digit);
  11445.                         const unsigned int digitScaled = mult * digit;
  11446.                         TIXMLASSERT(ucs <= ULONG_MAX - digitScaled);
  11447.                         ucs += digitScaled;
  11448.                     }
  11449.                     else
  11450.                     {
  11451.                         return 0;
  11452.                     }
  11453.                     TIXMLASSERT(mult <= UINT_MAX / 10);
  11454.                     mult *= 10;
  11455.                     --q;
  11456.                 }
  11457.             }
  11458.             // convert the UCS to UTF-8
  11459.             ConvertUTF32ToUTF8(ucs, value, length);
  11460.             return p + delta + 1;
  11461.         }
  11462.         return p + 1;
  11463.     }
  11464.  
  11465.  
  11466.     void XMLUtil::ToStr(int v, char* buffer, int bufferSize)
  11467.     {
  11468.         TIXML_SNPRINTF(buffer, bufferSize, "%d", v);
  11469.     }
  11470.  
  11471.  
  11472.     void XMLUtil::ToStr(unsigned v, char* buffer, int bufferSize)
  11473.     {
  11474.         TIXML_SNPRINTF(buffer, bufferSize, "%u", v);
  11475.     }
  11476.  
  11477.  
  11478.     void XMLUtil::ToStr(bool v, char* buffer, int bufferSize)
  11479.     {
  11480.         TIXML_SNPRINTF(buffer, bufferSize, "%d", v ? 1 : 0);
  11481.     }
  11482.  
  11483.     /*
  11484.         ToStr() of a number is a very tricky topic.
  11485.         https://github.com/leethomason/tinyxml2/issues/106
  11486.     */
  11487.     void XMLUtil::ToStr(float v, char* buffer, int bufferSize)
  11488.     {
  11489.         TIXML_SNPRINTF(buffer, bufferSize, "%.8g", v);
  11490.     }
  11491.  
  11492.  
  11493.     void XMLUtil::ToStr(double v, char* buffer, int bufferSize)
  11494.     {
  11495.         TIXML_SNPRINTF(buffer, bufferSize, "%.17g", v);
  11496.     }
  11497.  
  11498.  
  11499.     bool XMLUtil::ToInt( const char* str, int* value)
  11500.     {
  11501.         if (TIXML_SSCANF(str, "%d", value) == 1)
  11502.         {
  11503.             return true;
  11504.         }
  11505.         return false;
  11506.     }
  11507.  
  11508.     bool XMLUtil::ToUnsigned( const char* str, unsigned* value)
  11509.     {
  11510.         if (TIXML_SSCANF(str, "%u", value) == 1)
  11511.         {
  11512.             return true;
  11513.         }
  11514.         return false;
  11515.     }
  11516.  
  11517.     bool XMLUtil::ToBool( const char* str, bool* value)
  11518.     {
  11519.         int ival = 0;
  11520.         if (ToInt(str, &ival))
  11521.         {
  11522.             *value = (ival == 0) ? false : true;
  11523.             return true;
  11524.         }
  11525.         if (StringEqual(str, "true"))
  11526.         {
  11527.             *value = true;
  11528.             return true;
  11529.         }
  11530.         else if (StringEqual(str, "false"))
  11531.         {
  11532.             *value = false;
  11533.             return true;
  11534.         }
  11535.         return false;
  11536.     }
  11537.  
  11538.  
  11539.     bool XMLUtil::ToFloat( const char* str, float* value)
  11540.     {
  11541.         if (TIXML_SSCANF(str, "%f", value) == 1)
  11542.         {
  11543.             return true;
  11544.         }
  11545.         return false;
  11546.     }
  11547.  
  11548.     bool XMLUtil::ToDouble( const char* str, double* value)
  11549.     {
  11550.         if (TIXML_SSCANF(str, "%lf", value) == 1)
  11551.         {
  11552.             return true;
  11553.         }
  11554.         return false;
  11555.     }
  11556.  
  11557.  
  11558.     char* XMLDocument::Identify(char* p, XMLNode** node)
  11559.     {
  11560.         TIXMLASSERT(node);
  11561.         TIXMLASSERT(p);
  11562.         char* const start = p;
  11563.         p = XMLUtil::SkipWhiteSpace(p);
  11564.         if (!*p)
  11565.         {
  11566.             *node = 0;
  11567.             TIXMLASSERT(p);
  11568.             return p;
  11569.         }
  11570.  
  11571.         // These strings define the matching patterns:
  11572.         static const char* xmlHeader = { "<?" };
  11573.         static const char* commentHeader = { "<!--" };
  11574.         static const char* cdataHeader = { "<![CDATA[" };
  11575.         static const char* dtdHeader = { "<!" };
  11576.         static const char* elementHeader = { "<" }; // and a header for everything else; check last.
  11577.  
  11578.         static const int xmlHeaderLen = 2;
  11579.         static const int commentHeaderLen = 4;
  11580.         static const int cdataHeaderLen = 9;
  11581.         static const int dtdHeaderLen = 2;
  11582.         static const int elementHeaderLen = 1;
  11583.  
  11584.         TIXMLASSERT(sizeof(XMLComment) == sizeof(XMLUnknown));      // use same memory pool
  11585.         TIXMLASSERT(sizeof(XMLComment) == sizeof(XMLDeclaration));  // use same memory pool
  11586.         XMLNode* returnNode = 0;
  11587.         if (XMLUtil::StringEqual(p, xmlHeader, xmlHeaderLen))
  11588.         {
  11589.             TIXMLASSERT(sizeof(XMLDeclaration) == _commentPool.ItemSize());
  11590.             returnNode = new (_commentPool.Alloc()) XMLDeclaration(this);
  11591.             returnNode->_memPool = &_commentPool;
  11592.             p += xmlHeaderLen;
  11593.         }
  11594.         else if (XMLUtil::StringEqual(p, commentHeader, commentHeaderLen))
  11595.         {
  11596.             TIXMLASSERT(sizeof(XMLComment) == _commentPool.ItemSize());
  11597.             returnNode = new (_commentPool.Alloc()) XMLComment(this);
  11598.             returnNode->_memPool = &_commentPool;
  11599.             p += commentHeaderLen;
  11600.         }
  11601.         else if (XMLUtil::StringEqual(p, cdataHeader, cdataHeaderLen))
  11602.         {
  11603.             TIXMLASSERT(sizeof(XMLText) == _textPool.ItemSize());
  11604.             XMLText* text = new (_textPool.Alloc()) XMLText(this);
  11605.             returnNode = text;
  11606.             returnNode->_memPool = &_textPool;
  11607.             p += cdataHeaderLen;
  11608.             text->SetCData(true);
  11609.         }
  11610.         else if (XMLUtil::StringEqual(p, dtdHeader, dtdHeaderLen))
  11611.         {
  11612.             TIXMLASSERT(sizeof(XMLUnknown) == _commentPool.ItemSize());
  11613.             returnNode = new (_commentPool.Alloc()) XMLUnknown(this);
  11614.             returnNode->_memPool = &_commentPool;
  11615.             p += dtdHeaderLen;
  11616.         }
  11617.         else if (XMLUtil::StringEqual(p, elementHeader, elementHeaderLen))
  11618.         {
  11619.             TIXMLASSERT(sizeof(XMLElement) == _elementPool.ItemSize());
  11620.             returnNode = new (_elementPool.Alloc()) XMLElement(this);
  11621.             returnNode->_memPool = &_elementPool;
  11622.             p += elementHeaderLen;
  11623.         }
  11624.         else
  11625.         {
  11626.             TIXMLASSERT(sizeof(XMLText) == _textPool.ItemSize());
  11627.             returnNode = new (_textPool.Alloc()) XMLText(this);
  11628.             returnNode->_memPool = &_textPool;
  11629.             p = start;  // Back it up, all the text counts.
  11630.         }
  11631.  
  11632.         TIXMLASSERT(returnNode);
  11633.         TIXMLASSERT(p);
  11634.         *node = returnNode;
  11635.         return p;
  11636.     }
  11637.  
  11638.  
  11639.     bool XMLDocument::Accept(XMLVisitor* visitor) const
  11640. {
  11641.     TIXMLASSERT(visitor );
  11642.     if ( visitor->VisitEnter( *this ) ) {
  11643.         for ( const XMLNode* node = FirstChild(); node; node=node->NextSibling() ) {
  11644.             if ( !node->Accept(visitor ) ) {
  11645.                 break;
  11646.             }
  11647.         }
  11648.     }
  11649.     return visitor->VisitExit( *this );
  11650. }
  11651.  
  11652.  
  11653. // --------- XMLNode ----------- //
  11654.  
  11655. XMLNode::XMLNode( XMLDocument* doc ) :
  11656.     _document(doc ),
  11657.     _parent( 0 ),
  11658.     _firstChild( 0 ), _lastChild( 0 ),
  11659.     _prev( 0 ), _next( 0 ),
  11660.     _memPool( 0 )
  11661. {
  11662. }
  11663.  
  11664.  
  11665. XMLNode::~XMLNode()
  11666. {
  11667.     DeleteChildren();
  11668.     if (_parent)
  11669.     {
  11670.         _parent->Unlink(this);
  11671.     }
  11672. }
  11673.  
  11674. const char* XMLNode::Value() const
  11675. {
  11676.     // Catch an edge case: XMLDocuments don't have a a Value. Carefully return nullptr.
  11677.     if ( this->ToDocument() )
  11678.         return 0;
  11679.     return _value.GetStr();
  11680. }
  11681.  
  11682. void XMLNode::SetValue( const char* str, bool staticMem)
  11683. {
  11684.     if (staticMem)
  11685.     {
  11686.         _value.SetInternedStr(str);
  11687.     }
  11688.     else
  11689.     {
  11690.         _value.SetStr(str);
  11691.     }
  11692. }
  11693.  
  11694.  
  11695. void XMLNode::DeleteChildren()
  11696. {
  11697.     while (_firstChild)
  11698.     {
  11699.         TIXMLASSERT(_lastChild);
  11700.         TIXMLASSERT(_firstChild->_document == _document);
  11701.         XMLNode* node = _firstChild;
  11702.         Unlink(node);
  11703.  
  11704.         DeleteNode(node);
  11705.     }
  11706.     _firstChild = _lastChild = 0;
  11707. }
  11708.  
  11709.  
  11710. void XMLNode::Unlink(XMLNode* child)
  11711. {
  11712.     TIXMLASSERT(child);
  11713.     TIXMLASSERT(child->_document == _document);
  11714.     TIXMLASSERT(child->_parent == this);
  11715.     if (child == _firstChild)
  11716.     {
  11717.         _firstChild = _firstChild->_next;
  11718.     }
  11719.     if (child == _lastChild)
  11720.     {
  11721.         _lastChild = _lastChild->_prev;
  11722.     }
  11723.  
  11724.     if (child->_prev)
  11725.     {
  11726.         child->_prev->_next = child->_next;
  11727.     }
  11728.     if (child->_next)
  11729.     {
  11730.         child->_next->_prev = child->_prev;
  11731.     }
  11732.     child->_parent = 0;
  11733. }
  11734.  
  11735.  
  11736. void XMLNode::DeleteChild(XMLNode* node)
  11737. {
  11738.     TIXMLASSERT(node);
  11739.     TIXMLASSERT(node->_document == _document);
  11740.     TIXMLASSERT(node->_parent == this);
  11741.     DeleteNode(node);
  11742. }
  11743.  
  11744.  
  11745. XMLNode* XMLNode::InsertEndChild(XMLNode* addThis)
  11746. {
  11747.     TIXMLASSERT(addThis);
  11748.     if (addThis->_document != _document)
  11749.     {
  11750.         TIXMLASSERT(false);
  11751.         return 0;
  11752.     }
  11753.     InsertChildPreamble(addThis);
  11754.  
  11755.     if (_lastChild)
  11756.     {
  11757.         TIXMLASSERT(_firstChild);
  11758.         TIXMLASSERT(_lastChild->_next == 0);
  11759.         _lastChild->_next = addThis;
  11760.         addThis->_prev = _lastChild;
  11761.         _lastChild = addThis;
  11762.  
  11763.         addThis->_next = 0;
  11764.     }
  11765.     else
  11766.     {
  11767.         TIXMLASSERT(_firstChild == 0);
  11768.         _firstChild = _lastChild = addThis;
  11769.  
  11770.         addThis->_prev = 0;
  11771.         addThis->_next = 0;
  11772.     }
  11773.     addThis->_parent = this;
  11774.     return addThis;
  11775. }
  11776.  
  11777.  
  11778. XMLNode* XMLNode::InsertFirstChild(XMLNode* addThis)
  11779. {
  11780.     TIXMLASSERT(addThis);
  11781.     if (addThis->_document != _document)
  11782.     {
  11783.         TIXMLASSERT(false);
  11784.         return 0;
  11785.     }
  11786.     InsertChildPreamble(addThis);
  11787.  
  11788.     if (_firstChild)
  11789.     {
  11790.         TIXMLASSERT(_lastChild);
  11791.         TIXMLASSERT(_firstChild->_prev == 0);
  11792.  
  11793.         _firstChild->_prev = addThis;
  11794.         addThis->_next = _firstChild;
  11795.         _firstChild = addThis;
  11796.  
  11797.         addThis->_prev = 0;
  11798.     }
  11799.     else
  11800.     {
  11801.         TIXMLASSERT(_lastChild == 0);
  11802.         _firstChild = _lastChild = addThis;
  11803.  
  11804.         addThis->_prev = 0;
  11805.         addThis->_next = 0;
  11806.     }
  11807.     addThis->_parent = this;
  11808.     return addThis;
  11809. }
  11810.  
  11811.  
  11812. XMLNode* XMLNode::InsertAfterChild(XMLNode* afterThis, XMLNode* addThis)
  11813. {
  11814.     TIXMLASSERT(addThis);
  11815.     if (addThis->_document != _document)
  11816.     {
  11817.         TIXMLASSERT(false);
  11818.         return 0;
  11819.     }
  11820.  
  11821.     TIXMLASSERT(afterThis);
  11822.  
  11823.     if (afterThis->_parent != this)
  11824.     {
  11825.         TIXMLASSERT(false);
  11826.         return 0;
  11827.     }
  11828.  
  11829.     if (afterThis->_next == 0)
  11830.     {
  11831.         // The last node or the only node.
  11832.         return InsertEndChild(addThis);
  11833.     }
  11834.     InsertChildPreamble(addThis);
  11835.     addThis->_prev = afterThis;
  11836.     addThis->_next = afterThis->_next;
  11837.     afterThis->_next->_prev = addThis;
  11838.     afterThis->_next = addThis;
  11839.     addThis->_parent = this;
  11840.     return addThis;
  11841. }
  11842.  
  11843.  
  11844.  
  11845.  
  11846. const XMLElement* XMLNode::FirstChildElement( const char* name) const
  11847. {
  11848.     for( const XMLNode* node = _firstChild; node; node = node->_next ) {
  11849.         const XMLElement* element = node->ToElement();
  11850.         if ( element ) {
  11851.             if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {
  11852.                 return element;
  11853.             }
  11854.         }
  11855.     }
  11856.     return 0;
  11857. }
  11858.  
  11859.  
  11860. const XMLElement* XMLNode::LastChildElement( const char* name) const
  11861. {
  11862.     for( const XMLNode* node = _lastChild; node; node = node->_prev ) {
  11863.         const XMLElement* element = node->ToElement();
  11864.         if ( element ) {
  11865.             if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {
  11866.                 return element;
  11867.             }
  11868.         }
  11869.     }
  11870.     return 0;
  11871. }
  11872.  
  11873.  
  11874. const XMLElement* XMLNode::NextSiblingElement( const char* name) const
  11875. {
  11876.     for( const XMLNode* node = _next; node; node = node->_next ) {
  11877.         const XMLElement* element = node->ToElement();
  11878.         if ( element
  11879.                 && (!name || XMLUtil::StringEqual( name, element->Name() ))) {
  11880.             return element;
  11881.         }
  11882.     }
  11883.     return 0;
  11884. }
  11885.  
  11886.  
  11887. const XMLElement* XMLNode::PreviousSiblingElement( const char* name) const
  11888. {
  11889.     for( const XMLNode* node = _prev; node; node = node->_prev ) {
  11890.         const XMLElement* element = node->ToElement();
  11891.         if ( element
  11892.                 && (!name || XMLUtil::StringEqual( name, element->Name() ))) {
  11893.             return element;
  11894.         }
  11895.     }
  11896.     return 0;
  11897. }
  11898.  
  11899.  
  11900. char* XMLNode::ParseDeep(char* p, StrPair* parentEnd)
  11901. {
  11902.     // This is a recursive method, but thinking about it "at the current level"
  11903.     // it is a pretty simple flat list:
  11904.     //          <foo/>
  11905.     //          <!-- comment -->
  11906.     //
  11907.     // With a special case:
  11908.     //          <foo>
  11909.     //          </foo>
  11910.     //          <!-- comment -->
  11911.     //
  11912.     // Where the closing element (/foo) *must* be the next thing after the opening
  11913.     // element, and the names must match. BUT the tricky bit is that the closing
  11914.     // element will be read by the child.
  11915.     //
  11916.     // 'endTag' is the end tag for this node, it is returned by a call to a child.
  11917.     // 'parentEnd' is the end tag for the parent, which is filled in and returned.
  11918.  
  11919.     while (p && *p)
  11920.     {
  11921.         XMLNode* node = 0;
  11922.  
  11923.         p = _document->Identify(p, &node);
  11924.         if (node == 0)
  11925.         {
  11926.             break;
  11927.         }
  11928.  
  11929.         StrPair endTag;
  11930.         p = node->ParseDeep(p, &endTag);
  11931.         if (!p)
  11932.         {
  11933.             DeleteNode(node);
  11934.             if (!_document->Error())
  11935.             {
  11936.                 _document->SetError(XML_ERROR_PARSING, 0, 0);
  11937.             }
  11938.             break;
  11939.         }
  11940.  
  11941.         XMLDeclaration* decl = node->ToDeclaration();
  11942.         if (decl)
  11943.         {
  11944.             // A declaration can only be the first child of a document.
  11945.             // Set error, if document already has children.
  11946.             if (!_document->NoChildren())
  11947.             {
  11948.                 _document->SetError(XML_ERROR_PARSING_DECLARATION, decl->Value(), 0);
  11949.                 DeleteNode(decl);
  11950.                 break;
  11951.             }
  11952.         }
  11953.  
  11954.         XMLElement* ele = node->ToElement();
  11955.         if (ele)
  11956.         {
  11957.             // We read the end tag. Return it to the parent.
  11958.             if (ele->ClosingType() == XMLElement::CLOSING)
  11959.             {
  11960.                 if (parentEnd)
  11961.                 {
  11962.                     ele->_value.TransferTo(parentEnd);
  11963.                 }
  11964.                 node->_memPool->SetTracked();   // created and then immediately deleted.
  11965.                 DeleteNode(node);
  11966.                 return p;
  11967.             }
  11968.  
  11969.             // Handle an end tag returned to this level.
  11970.             // And handle a bunch of annoying errors.
  11971.             bool mismatch = false;
  11972.             if (endTag.Empty())
  11973.             {
  11974.                 if (ele->ClosingType() == XMLElement::OPEN)
  11975.                 {
  11976.                     mismatch = true;
  11977.                 }
  11978.             }
  11979.             else
  11980.             {
  11981.                 if (ele->ClosingType() != XMLElement::OPEN)
  11982.                 {
  11983.                     mismatch = true;
  11984.                 }
  11985.                 else if (!XMLUtil::StringEqual(endTag.GetStr(), ele->Name()))
  11986.                 {
  11987.                     mismatch = true;
  11988.                 }
  11989.             }
  11990.             if (mismatch)
  11991.             {
  11992.                 _document->SetError(XML_ERROR_MISMATCHED_ELEMENT, ele->Name(), 0);
  11993.                 DeleteNode(node);
  11994.                 break;
  11995.             }
  11996.         }
  11997.         InsertEndChild(node);
  11998.     }
  11999.     return 0;
  12000. }
  12001.  
  12002. void XMLNode::DeleteNode(XMLNode* node)
  12003. {
  12004.     if (node == 0)
  12005.     {
  12006.         return;
  12007.     }
  12008.     MemPool* pool = node->_memPool;
  12009.     node->~XMLNode();
  12010.     pool->Free(node);
  12011. }
  12012.  
  12013. void XMLNode::InsertChildPreamble(XMLNode* insertThis) const
  12014. {
  12015.     TIXMLASSERT(insertThis );
  12016.     TIXMLASSERT(insertThis->_document == _document );
  12017.  
  12018.     if ( insertThis->_parent )
  12019.         insertThis->_parent->Unlink(insertThis );
  12020.     else
  12021.         insertThis->_memPool->SetTracked();
  12022. }
  12023.  
  12024. // --------- XMLText ---------- //
  12025. char* XMLText::ParseDeep(char* p, StrPair* )
  12026. {
  12027.     const char* start = p;
  12028.     if (this->CData())
  12029.     {
  12030.         p = _value.ParseText(p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION);
  12031.         if (!p)
  12032.         {
  12033.             _document->SetError(XML_ERROR_PARSING_CDATA, start, 0);
  12034.         }
  12035.         return p;
  12036.     }
  12037.     else
  12038.     {
  12039.         int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES;
  12040.         if (_document->WhitespaceMode() == COLLAPSE_WHITESPACE)
  12041.         {
  12042.             flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING;
  12043.         }
  12044.  
  12045.         p = _value.ParseText(p, "<", flags);
  12046.         if (p && *p)
  12047.         {
  12048.             return p - 1;
  12049.         }
  12050.         if (!p)
  12051.         {
  12052.             _document->SetError(XML_ERROR_PARSING_TEXT, start, 0);
  12053.         }
  12054.     }
  12055.     return 0;
  12056. }
  12057.  
  12058.  
  12059. XMLNode* XMLText::ShallowClone(XMLDocument* doc) const
  12060. {
  12061.     if ( !doc ) {
  12062.         doc = _document;
  12063.     }
  12064.     XMLText* text = doc->NewText(Value());  // fixme: this will always allocate memory. Intern?
  12065. text->SetCData(this->CData() );
  12066.     return text;
  12067. }
  12068.  
  12069.  
  12070. bool XMLText::ShallowEqual( const XMLNode* compare) const
  12071. {
  12072.     const XMLText* text = compare->ToText();
  12073.     return ( text && XMLUtil::StringEqual( text->Value(), Value() ) );
  12074. }
  12075.  
  12076.  
  12077. bool XMLText::Accept(XMLVisitor* visitor) const
  12078. {
  12079.     TIXMLASSERT(visitor );
  12080.     return visitor->Visit( *this );
  12081. }
  12082.  
  12083.  
  12084. // --------- XMLComment ---------- //
  12085.  
  12086. XMLComment::XMLComment( XMLDocument* doc ) : XMLNode(doc )
  12087. {
  12088. }
  12089.  
  12090.  
  12091. XMLComment::~XMLComment()
  12092. {
  12093. }
  12094.  
  12095.  
  12096. char* XMLComment::ParseDeep(char* p, StrPair* )
  12097. {
  12098.     // Comment parses as text.
  12099.     const char* start = p;
  12100.     p = _value.ParseText(p, "-->", StrPair::COMMENT);
  12101.     if (p == 0)
  12102.     {
  12103.         _document->SetError(XML_ERROR_PARSING_COMMENT, start, 0);
  12104.     }
  12105.     return p;
  12106. }
  12107.  
  12108.  
  12109. XMLNode* XMLComment::ShallowClone(XMLDocument* doc) const
  12110. {
  12111.     if ( !doc ) {
  12112.         doc = _document;
  12113.     }
  12114.     XMLComment* comment = doc->NewComment(Value());     // fixme: this will always allocate memory. Intern?
  12115.     return comment;
  12116. }
  12117.  
  12118.  
  12119. bool XMLComment::ShallowEqual( const XMLNode* compare) const
  12120. {
  12121.     TIXMLASSERT(compare );
  12122. const XMLComment* comment = compare->ToComment();
  12123.     return ( comment && XMLUtil::StringEqual( comment->Value(), Value() ));
  12124. }
  12125.  
  12126.  
  12127. bool XMLComment::Accept(XMLVisitor* visitor) const
  12128. {
  12129.     TIXMLASSERT(visitor );
  12130.     return visitor->Visit( *this );
  12131. }
  12132.  
  12133.  
  12134. // --------- XMLDeclaration ---------- //
  12135.  
  12136. XMLDeclaration::XMLDeclaration( XMLDocument* doc ) : XMLNode(doc )
  12137. {
  12138. }
  12139.  
  12140.  
  12141. XMLDeclaration::~XMLDeclaration()
  12142. {
  12143.     //printf( "~XMLDeclaration\n" );
  12144. }
  12145.  
  12146.  
  12147. char* XMLDeclaration::ParseDeep(char* p, StrPair* )
  12148. {
  12149.     // Declaration parses as text.
  12150.     const char* start = p;
  12151.     p = _value.ParseText(p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION);
  12152.     if (p == 0)
  12153.     {
  12154.         _document->SetError(XML_ERROR_PARSING_DECLARATION, start, 0);
  12155.     }
  12156.     return p;
  12157. }
  12158.  
  12159.  
  12160. XMLNode* XMLDeclaration::ShallowClone(XMLDocument* doc) const
  12161. {
  12162.     if ( !doc ) {
  12163.         doc = _document;
  12164.     }
  12165.     XMLDeclaration* dec = doc->NewDeclaration(Value()); // fixme: this will always allocate memory. Intern?
  12166.     return dec;
  12167. }
  12168.  
  12169.  
  12170. bool XMLDeclaration::ShallowEqual( const XMLNode* compare) const
  12171. {
  12172.     TIXMLASSERT(compare );
  12173. const XMLDeclaration* declaration = compare->ToDeclaration();
  12174.     return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() ));
  12175. }
  12176.  
  12177.  
  12178.  
  12179. bool XMLDeclaration::Accept(XMLVisitor* visitor) const
  12180. {
  12181.     TIXMLASSERT(visitor );
  12182.     return visitor->Visit( *this );
  12183. }
  12184.  
  12185. // --------- XMLUnknown ---------- //
  12186.  
  12187. XMLUnknown::XMLUnknown( XMLDocument* doc ) : XMLNode(doc )
  12188. {
  12189. }
  12190.  
  12191.  
  12192. XMLUnknown::~XMLUnknown()
  12193. {
  12194. }
  12195.  
  12196.  
  12197. char* XMLUnknown::ParseDeep(char* p, StrPair* )
  12198. {
  12199.     // Unknown parses as text.
  12200.     const char* start = p;
  12201.  
  12202.     p = _value.ParseText(p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION);
  12203.     if (!p)
  12204.     {
  12205.         _document->SetError(XML_ERROR_PARSING_UNKNOWN, start, 0);
  12206.     }
  12207.     return p;
  12208. }
  12209.  
  12210.  
  12211. XMLNode* XMLUnknown::ShallowClone(XMLDocument* doc) const
  12212. {
  12213.     if ( !doc ) {
  12214.         doc = _document;
  12215.     }
  12216.     XMLUnknown* text = doc->NewUnknown(Value());        // fixme: this will always allocate memory. Intern?
  12217.     return text;
  12218. }
  12219.  
  12220.  
  12221. bool XMLUnknown::ShallowEqual( const XMLNode* compare) const
  12222. {
  12223.     TIXMLASSERT(compare );
  12224. const XMLUnknown* unknown = compare->ToUnknown();
  12225.     return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() ));
  12226. }
  12227.  
  12228.  
  12229. bool XMLUnknown::Accept(XMLVisitor* visitor) const
  12230. {
  12231.     TIXMLASSERT(visitor );
  12232.     return visitor->Visit( *this );
  12233. }
  12234.  
  12235. // --------- XMLAttribute ---------- //
  12236.  
  12237. const char* XMLAttribute::Name() const
  12238. {
  12239.     return _name.GetStr();
  12240. }
  12241.  
  12242. const char* XMLAttribute::Value() const
  12243. {
  12244.     return _value.GetStr();
  12245. }
  12246.  
  12247. char* XMLAttribute::ParseDeep(char* p, bool processEntities)
  12248. {
  12249.     // Parse using the name rules: bug fix, was using ParseText before
  12250.     p = _name.ParseName(p);
  12251.     if (!p || !*p)
  12252.     {
  12253.         return 0;
  12254.     }
  12255.  
  12256.     // Skip white space before =
  12257.     p = XMLUtil::SkipWhiteSpace(p);
  12258.     if (*p != '=')
  12259.     {
  12260.         return 0;
  12261.     }
  12262.  
  12263.     ++p;        // move up to opening quote
  12264.     p = XMLUtil::SkipWhiteSpace(p);
  12265.     if (*p != '\"' && *p != '\'')
  12266.     {
  12267.         return 0;
  12268.     }
  12269.  
  12270.     char endTag[2] = { *p, 0 };
  12271.     ++p;        // move past opening quote
  12272.  
  12273.     p = _value.ParseText(p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES);
  12274.     return p;
  12275. }
  12276.  
  12277.  
  12278. void XMLAttribute::SetName( const char* n)
  12279. {
  12280.     _name.SetStr(n);
  12281. }
  12282.  
  12283.  
  12284. XMLError XMLAttribute::QueryIntValue(int* value) const
  12285. {
  12286.     if ( XMLUtil::ToInt( Value(), value )) {
  12287.         return XML_NO_ERROR;
  12288.     }
  12289.     return XML_WRONG_ATTRIBUTE_TYPE;
  12290. }
  12291.  
  12292.  
  12293. XMLError XMLAttribute::QueryUnsignedValue(unsigned int* value) const
  12294. {
  12295.     if ( XMLUtil::ToUnsigned( Value(), value )) {
  12296.         return XML_NO_ERROR;
  12297.     }
  12298.     return XML_WRONG_ATTRIBUTE_TYPE;
  12299. }
  12300.  
  12301.  
  12302. XMLError XMLAttribute::QueryBoolValue(bool* value) const
  12303. {
  12304.     if ( XMLUtil::ToBool( Value(), value )) {
  12305.         return XML_NO_ERROR;
  12306.     }
  12307.     return XML_WRONG_ATTRIBUTE_TYPE;
  12308. }
  12309.  
  12310.  
  12311. XMLError XMLAttribute::QueryFloatValue(float* value) const
  12312. {
  12313.     if ( XMLUtil::ToFloat( Value(), value )) {
  12314.         return XML_NO_ERROR;
  12315.     }
  12316.     return XML_WRONG_ATTRIBUTE_TYPE;
  12317. }
  12318.  
  12319.  
  12320. XMLError XMLAttribute::QueryDoubleValue(double* value) const
  12321. {
  12322.     if ( XMLUtil::ToDouble( Value(), value )) {
  12323.         return XML_NO_ERROR;
  12324.     }
  12325.     return XML_WRONG_ATTRIBUTE_TYPE;
  12326. }
  12327.  
  12328.  
  12329. void XMLAttribute::SetAttribute( const char* v)
  12330. {
  12331.     _value.SetStr(v);
  12332. }
  12333.  
  12334.  
  12335. void XMLAttribute::SetAttribute(int v)
  12336. {
  12337.     char buf[BUF_SIZE];
  12338.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12339.     _value.SetStr(buf);
  12340. }
  12341.  
  12342.  
  12343. void XMLAttribute::SetAttribute(unsigned v)
  12344. {
  12345.     char buf[BUF_SIZE];
  12346.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12347.     _value.SetStr(buf);
  12348. }
  12349.  
  12350.  
  12351. void XMLAttribute::SetAttribute(bool v)
  12352. {
  12353.     char buf[BUF_SIZE];
  12354.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12355.     _value.SetStr(buf);
  12356. }
  12357.  
  12358. void XMLAttribute::SetAttribute(double v)
  12359. {
  12360.     char buf[BUF_SIZE];
  12361.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12362.     _value.SetStr(buf);
  12363. }
  12364.  
  12365. void XMLAttribute::SetAttribute(float v)
  12366. {
  12367.     char buf[BUF_SIZE];
  12368.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12369.     _value.SetStr(buf);
  12370. }
  12371.  
  12372.  
  12373. // --------- XMLElement ---------- //
  12374. XMLElement::XMLElement( XMLDocument* doc ) : XMLNode(doc ),
  12375.     _closingType( 0 ),
  12376.     _rootAttribute( 0 )
  12377. {
  12378. }
  12379.  
  12380.  
  12381. XMLElement::~XMLElement()
  12382. {
  12383.     while (_rootAttribute)
  12384.     {
  12385.         XMLAttribute* next = _rootAttribute->_next;
  12386.         DeleteAttribute(_rootAttribute);
  12387.         _rootAttribute = next;
  12388.     }
  12389. }
  12390.  
  12391.  
  12392. const XMLAttribute* XMLElement::FindAttribute( const char* name) const
  12393. {
  12394.     for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) {
  12395.         if ( XMLUtil::StringEqual( a->Name(), name ) ) {
  12396.             return a;
  12397.         }
  12398.     }
  12399.     return 0;
  12400. }
  12401.  
  12402.  
  12403. const char* XMLElement::Attribute( const char* name, const char* value) const
  12404. {
  12405.     const XMLAttribute* a = FindAttribute(name);
  12406.     if ( !a ) {
  12407.         return 0;
  12408.     }
  12409.     if ( !value || XMLUtil::StringEqual( a->Value(), value )) {
  12410.         return a->Value();
  12411.     }
  12412.     return 0;
  12413. }
  12414.  
  12415.  
  12416. const char* XMLElement::GetText() const
  12417. {
  12418.     if ( FirstChild() && FirstChild()->ToText() ) {
  12419.         return FirstChild()->Value();
  12420.     }
  12421.     return 0;
  12422. }
  12423.  
  12424.  
  12425. void XMLElement::SetText( const char* inText)
  12426. {
  12427.     if (FirstChild() && FirstChild()->ToText())
  12428.         FirstChild()->SetValue(inText);
  12429.     else
  12430.     {
  12431.         XMLText* theText = GetDocument()->NewText(inText);
  12432.         InsertFirstChild(theText);
  12433.     }
  12434. }
  12435.  
  12436.  
  12437. void XMLElement::SetText(int v)
  12438. {
  12439.     char buf[BUF_SIZE];
  12440.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12441.     SetText(buf);
  12442. }
  12443.  
  12444.  
  12445. void XMLElement::SetText(unsigned v)
  12446. {
  12447.     char buf[BUF_SIZE];
  12448.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12449.     SetText(buf);
  12450. }
  12451.  
  12452.  
  12453. void XMLElement::SetText(bool v)
  12454. {
  12455.     char buf[BUF_SIZE];
  12456.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12457.     SetText(buf);
  12458. }
  12459.  
  12460.  
  12461. void XMLElement::SetText(float v)
  12462. {
  12463.     char buf[BUF_SIZE];
  12464.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12465.     SetText(buf);
  12466. }
  12467.  
  12468.  
  12469. void XMLElement::SetText(double v)
  12470. {
  12471.     char buf[BUF_SIZE];
  12472.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  12473.     SetText(buf);
  12474. }
  12475.  
  12476.  
  12477. XMLError XMLElement::QueryIntText(int* ival) const
  12478. {
  12479.     if ( FirstChild() && FirstChild()->ToText() ) {
  12480.         const char* t = FirstChild()->Value();
  12481.         if ( XMLUtil::ToInt( t, ival ) ) {
  12482.             return XML_SUCCESS;
  12483.         }
  12484.         return XML_CAN_NOT_CONVERT_TEXT;
  12485.     }
  12486.     return XML_NO_TEXT_NODE;
  12487. }
  12488.  
  12489.  
  12490. XMLError XMLElement::QueryUnsignedText(unsigned* uval) const
  12491. {
  12492.     if ( FirstChild() && FirstChild()->ToText() ) {
  12493.         const char* t = FirstChild()->Value();
  12494.         if ( XMLUtil::ToUnsigned( t, uval ) ) {
  12495.             return XML_SUCCESS;
  12496.         }
  12497.         return XML_CAN_NOT_CONVERT_TEXT;
  12498.     }
  12499.     return XML_NO_TEXT_NODE;
  12500. }
  12501.  
  12502.  
  12503. XMLError XMLElement::QueryBoolText(bool* bval) const
  12504. {
  12505.     if ( FirstChild() && FirstChild()->ToText() ) {
  12506.         const char* t = FirstChild()->Value();
  12507.         if ( XMLUtil::ToBool( t, bval ) ) {
  12508.             return XML_SUCCESS;
  12509.         }
  12510.         return XML_CAN_NOT_CONVERT_TEXT;
  12511.     }
  12512.     return XML_NO_TEXT_NODE;
  12513. }
  12514.  
  12515.  
  12516. XMLError XMLElement::QueryDoubleText(double* dval) const
  12517. {
  12518.     if ( FirstChild() && FirstChild()->ToText() ) {
  12519.         const char* t = FirstChild()->Value();
  12520.         if ( XMLUtil::ToDouble( t, dval ) ) {
  12521.             return XML_SUCCESS;
  12522.         }
  12523.         return XML_CAN_NOT_CONVERT_TEXT;
  12524.     }
  12525.     return XML_NO_TEXT_NODE;
  12526. }
  12527.  
  12528.  
  12529. XMLError XMLElement::QueryFloatText(float* fval) const
  12530. {
  12531.     if ( FirstChild() && FirstChild()->ToText() ) {
  12532.         const char* t = FirstChild()->Value();
  12533.         if ( XMLUtil::ToFloat( t, fval ) ) {
  12534.             return XML_SUCCESS;
  12535.         }
  12536.         return XML_CAN_NOT_CONVERT_TEXT;
  12537.     }
  12538.     return XML_NO_TEXT_NODE;
  12539. }
  12540.  
  12541.  
  12542.  
  12543. XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name)
  12544. {
  12545.     XMLAttribute* last = 0;
  12546.     XMLAttribute* attrib = 0;
  12547.     for (attrib = _rootAttribute;
  12548.             attrib;
  12549.             last = attrib, attrib = attrib->_next)
  12550.     {
  12551.         if (XMLUtil::StringEqual(attrib->Name(), name))
  12552.         {
  12553.             break;
  12554.         }
  12555.     }
  12556.     if (!attrib)
  12557.     {
  12558.         TIXMLASSERT(sizeof(XMLAttribute) == _document->_attributePool.ItemSize());
  12559.         attrib = new (_document->_attributePool.Alloc()) XMLAttribute();
  12560.         attrib->_memPool = &_document->_attributePool;
  12561.         if (last)
  12562.         {
  12563.             last->_next = attrib;
  12564.         }
  12565.         else
  12566.         {
  12567.             _rootAttribute = attrib;
  12568.         }
  12569.         attrib->SetName(name);
  12570.         attrib->_memPool->SetTracked(); // always created and linked.
  12571.     }
  12572.     return attrib;
  12573. }
  12574.  
  12575.  
  12576. void XMLElement::DeleteAttribute( const char* name)
  12577. {
  12578.     XMLAttribute* prev = 0;
  12579.     for (XMLAttribute* a = _rootAttribute; a; a = a->_next)
  12580.     {
  12581.         if (XMLUtil::StringEqual(name, a->Name()))
  12582.         {
  12583.             if (prev)
  12584.             {
  12585.                 prev->_next = a->_next;
  12586.             }
  12587.             else
  12588.             {
  12589.                 _rootAttribute = a->_next;
  12590.             }
  12591.             DeleteAttribute(a);
  12592.             break;
  12593.         }
  12594.         prev = a;
  12595.     }
  12596. }
  12597.  
  12598.  
  12599. char* XMLElement::ParseAttributes(char* p)
  12600. {
  12601.     const char* start = p;
  12602.     XMLAttribute* prevAttribute = 0;
  12603.  
  12604.     // Read the attributes.
  12605.     while (p)
  12606.     {
  12607.         p = XMLUtil::SkipWhiteSpace(p);
  12608.         if (!(*p))
  12609.         {
  12610.             _document->SetError(XML_ERROR_PARSING_ELEMENT, start, Name());
  12611.             return 0;
  12612.         }
  12613.  
  12614.         // attribute.
  12615.         if (XMLUtil::IsNameStartChar(*p))
  12616.         {
  12617.             TIXMLASSERT(sizeof(XMLAttribute) == _document->_attributePool.ItemSize());
  12618.             XMLAttribute* attrib = new (_document->_attributePool.Alloc()) XMLAttribute();
  12619.             attrib->_memPool = &_document->_attributePool;
  12620.             attrib->_memPool->SetTracked();
  12621.  
  12622.             p = attrib->ParseDeep(p, _document->ProcessEntities());
  12623.             if (!p || Attribute(attrib->Name()))
  12624.             {
  12625.                 DeleteAttribute(attrib);
  12626.                 _document->SetError(XML_ERROR_PARSING_ATTRIBUTE, start, p);
  12627.                 return 0;
  12628.             }
  12629.             // There is a minor bug here: if the attribute in the source xml
  12630.             // document is duplicated, it will not be detected and the
  12631.             // attribute will be doubly added. However, tracking the 'prevAttribute'
  12632.             // avoids re-scanning the attribute list. Preferring performance for
  12633.             // now, may reconsider in the future.
  12634.             if (prevAttribute)
  12635.             {
  12636.                 prevAttribute->_next = attrib;
  12637.             }
  12638.             else
  12639.             {
  12640.                 _rootAttribute = attrib;
  12641.             }
  12642.             prevAttribute = attrib;
  12643.         }
  12644.         // end of the tag
  12645.         else if (*p == '>')
  12646.         {
  12647.             ++p;
  12648.             break;
  12649.         }
  12650.         // end of the tag
  12651.         else if (*p == '/' && *(p + 1) == '>')
  12652.         {
  12653.             _closingType = CLOSED;
  12654.             return p + 2;       // done; sealed element.
  12655.         }
  12656.         else
  12657.         {
  12658.             _document->SetError(XML_ERROR_PARSING_ELEMENT, start, p);
  12659.             return 0;
  12660.         }
  12661.     }
  12662.     return p;
  12663. }
  12664.  
  12665. void XMLElement::DeleteAttribute(XMLAttribute* attribute)
  12666. {
  12667.     if (attribute == 0)
  12668.     {
  12669.         return;
  12670.     }
  12671.     MemPool* pool = attribute->_memPool;
  12672.     attribute->~XMLAttribute();
  12673.     pool->Free(attribute);
  12674. }
  12675.  
  12676. //
  12677. //      <ele></ele>
  12678. //      <ele>foo<b>bar</b></ele>
  12679. //
  12680. char* XMLElement::ParseDeep(char* p, StrPair* strPair)
  12681. {
  12682.     // Read the element name.
  12683.     p = XMLUtil::SkipWhiteSpace(p);
  12684.  
  12685.     // The closing element is the </element> form. It is
  12686.     // parsed just like a regular element then deleted from
  12687.     // the DOM.
  12688.     if (*p == '/')
  12689.     {
  12690.         _closingType = CLOSING;
  12691.         ++p;
  12692.     }
  12693.  
  12694.     p = _value.ParseName(p);
  12695.     if (_value.Empty())
  12696.     {
  12697.         return 0;
  12698.     }
  12699.  
  12700.     p = ParseAttributes(p);
  12701.     if (!p || !*p || _closingType)
  12702.     {
  12703.         return p;
  12704.     }
  12705.  
  12706.     p = XMLNode::ParseDeep(p, strPair);
  12707.     return p;
  12708. }
  12709.  
  12710.  
  12711.  
  12712. XMLNode* XMLElement::ShallowClone(XMLDocument* doc) const
  12713. {
  12714.     if ( !doc ) {
  12715.         doc = _document;
  12716.     }
  12717.     XMLElement* element = doc->NewElement(Value());                                     // fixme: this will always allocate memory. Intern?
  12718.     for( const XMLAttribute* a = FirstAttribute(); a; a=a->Next() ) {
  12719.         element->SetAttribute(a->Name(), a->Value() );                                  // fixme: this will always allocate memory. Intern?
  12720.     }
  12721.     return element;
  12722. }
  12723.  
  12724.  
  12725. bool XMLElement::ShallowEqual( const XMLNode* compare) const
  12726. {
  12727.     TIXMLASSERT(compare );
  12728. const XMLElement* other = compare->ToElement();
  12729.     if ( other && XMLUtil::StringEqual( other->Name(), Name() )) {
  12730.  
  12731.         const XMLAttribute* a = FirstAttribute();
  12732. const XMLAttribute* b = other->FirstAttribute();
  12733.  
  12734.         while ( a && b ) {
  12735.             if ( !XMLUtil::StringEqual( a->Value(), b->Value() ) ) {
  12736.                 return false;
  12737.             }
  12738.             a = a->Next();
  12739. b = b->Next();
  12740.         }
  12741.         if ( a || b ) {
  12742.             // different count
  12743.             return false;
  12744.         }
  12745.         return true;
  12746.     }
  12747.     return false;
  12748. }
  12749.  
  12750.  
  12751. bool XMLElement::Accept(XMLVisitor* visitor) const
  12752. {
  12753.     TIXMLASSERT(visitor );
  12754.     if ( visitor->VisitEnter( *this, _rootAttribute ) ) {
  12755.         for ( const XMLNode* node = FirstChild(); node; node=node->NextSibling() ) {
  12756.             if ( !node->Accept(visitor ) ) {
  12757.                 break;
  12758.             }
  12759.         }
  12760.     }
  12761.     return visitor->VisitExit( *this );
  12762. }
  12763.  
  12764.  
  12765. // --------- XMLDocument ----------- //
  12766.  
  12767. // Warning: List must match 'enum XMLError'
  12768. const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
  12769.     "XML_SUCCESS",
  12770.     "XML_NO_ATTRIBUTE",
  12771.     "XML_WRONG_ATTRIBUTE_TYPE",
  12772.     "XML_ERROR_FILE_NOT_FOUND",
  12773.     "XML_ERROR_FILE_COULD_NOT_BE_OPENED",
  12774.     "XML_ERROR_FILE_READ_ERROR",
  12775.     "XML_ERROR_ELEMENT_MISMATCH",
  12776.     "XML_ERROR_PARSING_ELEMENT",
  12777.     "XML_ERROR_PARSING_ATTRIBUTE",
  12778.     "XML_ERROR_IDENTIFYING_TAG",
  12779.     "XML_ERROR_PARSING_TEXT",
  12780.     "XML_ERROR_PARSING_CDATA",
  12781.     "XML_ERROR_PARSING_COMMENT",
  12782.     "XML_ERROR_PARSING_DECLARATION",
  12783.     "XML_ERROR_PARSING_UNKNOWN",
  12784.     "XML_ERROR_EMPTY_DOCUMENT",
  12785.     "XML_ERROR_MISMATCHED_ELEMENT",
  12786.     "XML_ERROR_PARSING",
  12787.     "XML_CAN_NOT_CONVERT_TEXT",
  12788.     "XML_NO_TEXT_NODE"
  12789. };
  12790.  
  12791.  
  12792. XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
  12793.     XMLNode( 0 ),
  12794.     _writeBOM( false ),
  12795.     _processEntities(processEntities ),
  12796.     _errorID(XML_NO_ERROR ),
  12797.     _whitespace(whitespace ),
  12798.     _errorStr1( 0 ),
  12799.     _errorStr2( 0 ),
  12800.     _charBuffer( 0 )
  12801. {
  12802.     // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)
  12803.     _document = this;
  12804. }
  12805.  
  12806.  
  12807. XMLDocument::~XMLDocument()
  12808. {
  12809.     Clear();
  12810. }
  12811.  
  12812.  
  12813. void XMLDocument::Clear()
  12814. {
  12815.     DeleteChildren();
  12816.  
  12817. #ifdef DEBUG
  12818.     const bool hadError = Error();
  12819. #endif
  12820.     _errorID = XML_NO_ERROR;
  12821.     _errorStr1 = 0;
  12822.     _errorStr2 = 0;
  12823.  
  12824.     delete[] _charBuffer;
  12825.     _charBuffer = 0;
  12826.  
  12827. #if 0
  12828.     _textPool.Trace( "text" );
  12829.     _elementPool.Trace( "element" );
  12830.     _commentPool.Trace( "comment" );
  12831.     _attributePool.Trace( "attribute" );
  12832. #endif
  12833.  
  12834. # ifdef DEBUG
  12835.     if (!hadError)
  12836.     {
  12837.         TIXMLASSERT(_elementPool.CurrentAllocs() == _elementPool.Untracked());
  12838.         TIXMLASSERT(_attributePool.CurrentAllocs() == _attributePool.Untracked());
  12839.         TIXMLASSERT(_textPool.CurrentAllocs() == _textPool.Untracked());
  12840.         TIXMLASSERT(_commentPool.CurrentAllocs() == _commentPool.Untracked());
  12841.     }
  12842. #endif
  12843. }
  12844.  
  12845.  
  12846. XMLElement* XMLDocument::NewElement( const char* name)
  12847. {
  12848.     TIXMLASSERT(sizeof(XMLElement) == _elementPool.ItemSize());
  12849.     XMLElement* ele = new (_elementPool.Alloc()) XMLElement(this);
  12850.     ele->_memPool = &_elementPool;
  12851.     ele->SetName(name);
  12852.     return ele;
  12853. }
  12854.  
  12855.  
  12856. XMLComment* XMLDocument::NewComment( const char* str)
  12857. {
  12858.     TIXMLASSERT(sizeof(XMLComment) == _commentPool.ItemSize());
  12859.     XMLComment* comment = new (_commentPool.Alloc()) XMLComment(this);
  12860.     comment->_memPool = &_commentPool;
  12861.     comment->SetValue(str);
  12862.     return comment;
  12863. }
  12864.  
  12865.  
  12866. XMLText* XMLDocument::NewText( const char* str)
  12867. {
  12868.     TIXMLASSERT(sizeof(XMLText) == _textPool.ItemSize());
  12869.     XMLText* text = new (_textPool.Alloc()) XMLText(this);
  12870.     text->_memPool = &_textPool;
  12871.     text->SetValue(str);
  12872.     return text;
  12873. }
  12874.  
  12875.  
  12876. XMLDeclaration* XMLDocument::NewDeclaration( const char* str)
  12877. {
  12878.     TIXMLASSERT(sizeof(XMLDeclaration) == _commentPool.ItemSize());
  12879.     XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration(this);
  12880.     dec->_memPool = &_commentPool;
  12881.     dec->SetValue(str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"");
  12882.     return dec;
  12883. }
  12884.  
  12885.  
  12886. XMLUnknown* XMLDocument::NewUnknown( const char* str)
  12887. {
  12888.     TIXMLASSERT(sizeof(XMLUnknown) == _commentPool.ItemSize());
  12889.     XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown(this);
  12890.     unk->_memPool = &_commentPool;
  12891.     unk->SetValue(str);
  12892.     return unk;
  12893. }
  12894.  
  12895. static FILE* callfopen( const char* filepath, const char* mode)
  12896. {
  12897.     TIXMLASSERT(filepath);
  12898.     TIXMLASSERT(mode);
  12899. #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
  12900.     FILE* fp = 0;
  12901.     errno_t err = fopen_s( &fp, filepath, mode );
  12902.     if ( err ) {
  12903.         return 0;
  12904.     }
  12905. #else
  12906.     FILE* fp = fopen(filepath, mode);
  12907. #endif
  12908.     return fp;
  12909. }
  12910.  
  12911. void XMLDocument::DeleteNode(XMLNode* node)
  12912. {
  12913.     TIXMLASSERT(node);
  12914.     TIXMLASSERT(node->_document == this);
  12915.     if (node->_parent)
  12916.     {
  12917.         node->_parent->DeleteChild(node);
  12918.     }
  12919.     else
  12920.     {
  12921.         // Isn't in the tree.
  12922.         // Use the parent delete.
  12923.         // Also, we need to mark it tracked: we 'know'
  12924.         // it was never used.
  12925.         node->_memPool->SetTracked();
  12926.         // Call the static XMLNode version:
  12927.         XMLNode::DeleteNode(node);
  12928.     }
  12929. }
  12930.  
  12931.  
  12932. XMLError XMLDocument::LoadFile( const char* filename)
  12933. {
  12934.     Clear();
  12935.     FILE* fp = callfopen(filename, "rb");
  12936.     if (!fp)
  12937.     {
  12938.         SetError(XML_ERROR_FILE_NOT_FOUND, filename, 0);
  12939.         return _errorID;
  12940.     }
  12941.     LoadFile(fp);
  12942.     fclose(fp);
  12943.     return _errorID;
  12944. }
  12945.  
  12946.  
  12947. XMLError XMLDocument::LoadFile(FILE* fp)
  12948. {
  12949.     Clear();
  12950.  
  12951.     fseek(fp, 0, SEEK_SET);
  12952.     if (fgetc(fp) == EOF && ferror(fp) != 0)
  12953.     {
  12954.         SetError(XML_ERROR_FILE_READ_ERROR, 0, 0);
  12955.         return _errorID;
  12956.     }
  12957.  
  12958.     fseek(fp, 0, SEEK_END);
  12959.     const long filelength = ftell(fp);
  12960.     fseek(fp, 0, SEEK_SET);
  12961.     if (filelength == -1L)
  12962.     {
  12963.         SetError(XML_ERROR_FILE_READ_ERROR, 0, 0);
  12964.         return _errorID;
  12965.     }
  12966.  
  12967.     if ((unsigned long)filelength >= (size_t) - 1 ) {
  12968.         // Cannot handle files which won't fit in buffer together with null terminator
  12969.         SetError(XML_ERROR_FILE_READ_ERROR, 0, 0);
  12970.         return _errorID;
  12971.     }
  12972.  
  12973.     if (filelength == 0)
  12974.     {
  12975.         SetError(XML_ERROR_EMPTY_DOCUMENT, 0, 0);
  12976.         return _errorID;
  12977.     }
  12978.  
  12979.     const size_t size = filelength;
  12980.     TIXMLASSERT(_charBuffer == 0);
  12981.     _charBuffer = new char[size + 1];
  12982.     size_t read = fread(_charBuffer, 1, size, fp);
  12983.     if (read != size)
  12984.     {
  12985.         SetError(XML_ERROR_FILE_READ_ERROR, 0, 0);
  12986.         return _errorID;
  12987.     }
  12988.  
  12989.     _charBuffer[size] = 0;
  12990.  
  12991.     Parse();
  12992.     return _errorID;
  12993. }
  12994.  
  12995.  
  12996. XMLError XMLDocument::SaveFile( const char* filename, bool compact)
  12997. {
  12998.     FILE* fp = callfopen(filename, "w");
  12999.     if (!fp)
  13000.     {
  13001.         SetError(XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0);
  13002.         return _errorID;
  13003.     }
  13004.     SaveFile(fp, compact);
  13005.     fclose(fp);
  13006.     return _errorID;
  13007. }
  13008.  
  13009.  
  13010. XMLError XMLDocument::SaveFile(FILE* fp, bool compact)
  13011. {
  13012.     // Clear any error from the last save, otherwise it will get reported
  13013.     // for *this* call.
  13014.     SetError(XML_NO_ERROR, 0, 0);
  13015.     XMLPrinter stream(fp, compact);
  13016.     Print(&stream);
  13017.     return _errorID;
  13018. }
  13019.  
  13020.  
  13021. XMLError XMLDocument::Parse( const char* p, size_t len)
  13022. {
  13023.     Clear();
  13024.  
  13025.     if (len == 0 || !p || !*p)
  13026.     {
  13027.         SetError(XML_ERROR_EMPTY_DOCUMENT, 0, 0);
  13028.         return _errorID;
  13029.     }
  13030.     if (len == (size_t)(-1))
  13031.     {
  13032.         len = strlen(p);
  13033.     }
  13034.     TIXMLASSERT(_charBuffer == 0);
  13035.     _charBuffer = new char[len + 1];
  13036.     memcpy(_charBuffer, p, len);
  13037.     _charBuffer[len] = 0;
  13038.  
  13039.     Parse();
  13040.     if (Error())
  13041.     {
  13042.         // clean up now essentially dangling memory.
  13043.         // and the parse fail can put objects in the
  13044.         // pools that are dead and inaccessible.
  13045.         DeleteChildren();
  13046.         _elementPool.Clear();
  13047.         _attributePool.Clear();
  13048.         _textPool.Clear();
  13049.         _commentPool.Clear();
  13050.     }
  13051.     return _errorID;
  13052. }
  13053.  
  13054.  
  13055. void XMLDocument::Print(XMLPrinter* streamer) const
  13056. {
  13057.     if ( streamer ) {
  13058.         Accept(streamer );
  13059.     }
  13060.     else {
  13061.         XMLPrinter stdoutStreamer(stdout );
  13062.         Accept( &stdoutStreamer );
  13063.     }
  13064. }
  13065.  
  13066.  
  13067. void XMLDocument::SetError(XMLError error, const char* str1, const char* str2)
  13068. {
  13069.     TIXMLASSERT(error >= 0 && error < XML_ERROR_COUNT);
  13070.     _errorID = error;
  13071.     _errorStr1 = str1;
  13072.     _errorStr2 = str2;
  13073. }
  13074.  
  13075. const char* XMLDocument::ErrorName() const
  13076. {
  13077.  
  13078.     TIXMLASSERT(_errorID >= 0 && _errorID<XML_ERROR_COUNT );
  13079. const char* errorName = _errorNames[_errorID];
  13080.     TIXMLASSERT(errorName && errorName[0] );
  13081.     return errorName;
  13082. }
  13083.  
  13084. void XMLDocument::PrintError() const
  13085. {
  13086.     if ( Error() ) {
  13087.         static const int LEN = 20;
  13088. char buf1[LEN] = { 0 };
  13089. char buf2[LEN] = { 0 };
  13090.  
  13091.         if ( _errorStr1 ) {
  13092.             TIXML_SNPRINTF(buf1, LEN, "%s", _errorStr1 );
  13093.         }
  13094.         if ( _errorStr2 ) {
  13095.             TIXML_SNPRINTF(buf2, LEN, "%s", _errorStr2 );
  13096.         }
  13097.  
  13098.         // Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that
  13099.         // causes a clang "always true" -Wtautological-constant-out-of-range-compare warning
  13100.         TIXMLASSERT( 0 <= _errorID && XML_ERROR_COUNT - 1 <= INT_MAX );
  13101.         printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n",
  13102.                 static_cast<int>( _errorID ), ErrorName(), buf1, buf2 );
  13103.     }
  13104. }
  13105.  
  13106. void XMLDocument::Parse()
  13107. {
  13108.     TIXMLASSERT(NoChildren()); // Clear() must have been called previously
  13109.     TIXMLASSERT(_charBuffer);
  13110.     char* p = _charBuffer;
  13111.     p = XMLUtil::SkipWhiteSpace(p);
  13112.     p = const_cast<char*>(XMLUtil::ReadBOM(p, &_writeBOM));
  13113.     if (!*p)
  13114.     {
  13115.         SetError(XML_ERROR_EMPTY_DOCUMENT, 0, 0);
  13116.         return;
  13117.     }
  13118.     ParseDeep(p, 0);
  13119. }
  13120.  
  13121. XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
  13122.     _elementJustOpened( false ),
  13123.     _firstElement( true ),
  13124.     _fp(file ),
  13125.     _depth(depth ),
  13126.     _textDepth( -1 ),
  13127.     _processEntities( true ),
  13128.     _compactMode(compact )
  13129. {
  13130.     for (int i = 0; i < ENTITY_RANGE; ++i)
  13131.     {
  13132.         _entityFlag[i] = false;
  13133.         _restrictedEntityFlag[i] = false;
  13134.     }
  13135.     for (int i = 0; i < NUM_ENTITIES; ++i)
  13136.     {
  13137.         const char entityValue = entities[i].value;
  13138.         TIXMLASSERT(0 <= entityValue && entityValue < ENTITY_RANGE);
  13139.         _entityFlag[(unsigned char)entityValue ] = true;
  13140. }
  13141. _restrictedEntityFlag[(unsigned char)'&'] = true;
  13142.     _restrictedEntityFlag[(unsigned char)'<'] = true;
  13143.     _restrictedEntityFlag[(unsigned char)'>'] = true;   // not required, but consistency is nice
  13144.     _buffer.Push( 0 );
  13145. }
  13146.  
  13147.  
  13148. void XMLPrinter::Print( const char* format, ... )
  13149. {
  13150.     va_list va;
  13151.     va_start(va, format);
  13152.  
  13153.     if (_fp)
  13154.     {
  13155.         vfprintf(_fp, format, va);
  13156.     }
  13157.     else
  13158.     {
  13159.         const int len = TIXML_VSCPRINTF(format, va);
  13160.         // Close out and re-start the va-args
  13161.         va_end(va);
  13162.         TIXMLASSERT(len >= 0);
  13163.         va_start(va, format);
  13164.         TIXMLASSERT(_buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0);
  13165.         char* p = _buffer.PushArr(len) - 1; // back up over the null terminator.
  13166.         TIXML_VSNPRINTF(p, len + 1, format, va);
  13167.     }
  13168.     va_end(va);
  13169. }
  13170.  
  13171.  
  13172. void XMLPrinter::PrintSpace(int depth)
  13173. {
  13174.     for (int i = 0; i < depth; ++i)
  13175.     {
  13176.         Print("    ");
  13177.     }
  13178. }
  13179.  
  13180.  
  13181. void XMLPrinter::PrintString( const char* p, bool restricted)
  13182. {
  13183.     // Look for runs of bytes between entities to print.
  13184.     const char* q = p;
  13185.  
  13186.     if (_processEntities)
  13187.     {
  13188.         const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag;
  13189.         while (*q)
  13190.         {
  13191.             TIXMLASSERT(p <= q);
  13192.             // Remember, char is sometimes signed. (How many times has that bitten me?)
  13193.             if (*q > 0 && *q < ENTITY_RANGE)
  13194.             {
  13195.                 // Check for entities. If one is found, flush
  13196.                 // the stream up until the entity, write the
  13197.                 // entity, and keep looking.
  13198.                 if (flag[(unsigned char) (*q)] ) {
  13199.                     while (p < q)
  13200.                     {
  13201.                         const size_t delta = q - p;
  13202.                         // %.*s accepts type int as "precision"
  13203.                         const int toPrint = (INT_MAX < delta) ? INT_MAX : (int)delta;
  13204.                         Print("%.*s", toPrint, p);
  13205.                         p += toPrint;
  13206.                     }
  13207.                     bool entityPatternPrinted = false;
  13208.                     for (int i = 0; i < NUM_ENTITIES; ++i)
  13209.                     {
  13210.                         if (entities[i].value == *q)
  13211.                         {
  13212.                             Print("&%s;", entities[i].pattern);
  13213.                             entityPatternPrinted = true;
  13214.                             break;
  13215.                         }
  13216.                     }
  13217.                     if (!entityPatternPrinted)
  13218.                     {
  13219.                         // TIXMLASSERT( entityPatternPrinted ) causes gcc -Wunused-but-set-variable in release
  13220.                         TIXMLASSERT(false);
  13221.                     }
  13222.                     ++p;
  13223.                 }
  13224.             }
  13225.             ++q;
  13226.             TIXMLASSERT(p <= q);
  13227.         }
  13228.     }
  13229.     // Flush the remaining string. This will be the entire
  13230.     // string if an entity wasn't found.
  13231.     TIXMLASSERT(p <= q);
  13232.     if (!_processEntities || (p < q))
  13233.     {
  13234.         Print("%s", p);
  13235.     }
  13236. }
  13237.  
  13238.  
  13239. void XMLPrinter::PushHeader(bool writeBOM, bool writeDec)
  13240. {
  13241.     if (writeBOM)
  13242.     {
  13243.         static const unsigned char bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 };
  13244.         Print("%s", bom);
  13245.     }
  13246.     if (writeDec)
  13247.     {
  13248.         PushDeclaration("xml version=\"1.0\"");
  13249.     }
  13250. }
  13251.  
  13252.  
  13253. void XMLPrinter::OpenElement( const char* name, bool compactMode)
  13254. {
  13255.     SealElementIfJustOpened();
  13256.     _stack.Push(name);
  13257.  
  13258.     if (_textDepth < 0 && !_firstElement && !compactMode)
  13259.     {
  13260.         Print("\n");
  13261.     }
  13262.     if (!compactMode)
  13263.     {
  13264.         PrintSpace(_depth);
  13265.     }
  13266.  
  13267.     Print("<%s", name);
  13268.     _elementJustOpened = true;
  13269.     _firstElement = false;
  13270.     ++_depth;
  13271. }
  13272.  
  13273.  
  13274. void XMLPrinter::PushAttribute( const char* name, const char* value)
  13275. {
  13276.     TIXMLASSERT(_elementJustOpened);
  13277.     Print(" %s=\"", name);
  13278.     PrintString(value, false);
  13279.     Print("\"");
  13280. }
  13281.  
  13282.  
  13283. void XMLPrinter::PushAttribute( const char* name, int v)
  13284. {
  13285.     char buf[BUF_SIZE];
  13286.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  13287.     PushAttribute(name, buf);
  13288. }
  13289.  
  13290.  
  13291. void XMLPrinter::PushAttribute( const char* name, unsigned v)
  13292. {
  13293.     char buf[BUF_SIZE];
  13294.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  13295.     PushAttribute(name, buf);
  13296. }
  13297.  
  13298.  
  13299. void XMLPrinter::PushAttribute( const char* name, bool v)
  13300. {
  13301.     char buf[BUF_SIZE];
  13302.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  13303.     PushAttribute(name, buf);
  13304. }
  13305.  
  13306.  
  13307. void XMLPrinter::PushAttribute( const char* name, double v)
  13308. {
  13309.     char buf[BUF_SIZE];
  13310.     XMLUtil::ToStr(v, buf, BUF_SIZE);
  13311.     PushAttribute(name, buf);
  13312. }
  13313.  
  13314.  
  13315. void XMLPrinter::CloseElement(bool compactMode)
  13316. {
  13317.     --_depth;
  13318.     const char* name = _stack.Pop();
  13319.  
  13320.     if (_elementJustOpened)
  13321.     {
  13322.         Print("/>");
  13323.     }
  13324.     else
  13325.     {
  13326.         if (_textDepth < 0 && !compactMode)
  13327.         {
  13328.             Print("\n");
  13329.             PrintSpace(_depth);
  13330.         }
  13331.         Print("</%s>", name);
  13332.     }
  13333.  
  13334.     if (_textDepth == _depth)
  13335.     {
  13336.         _textDepth = -1;
  13337.     }
  13338.     if (_depth == 0 && !compactMode)
  13339.     {
  13340.         Print("\n");
  13341.     }
  13342.     _elementJustOpened = false;
  13343. }
  13344.  
  13345.  
  13346. void XMLPrinter::SealElementIfJustOpened()
  13347. {
  13348.     if (!_elementJustOpened)
  13349.     {
  13350.         return;
  13351.     }
  13352.     _elementJustOpened = false;
  13353.     Print(">");
  13354. }
  13355.  
  13356.  
  13357. void XMLPrinter::PushText( const char* text, bool cdata)
  13358. {
  13359.     _textDepth = _depth - 1;
  13360.  
  13361.     SealElementIfJustOpened();
  13362.     if (cdata)
  13363.     {
  13364.         Print("<![CDATA[%s]]>", text);
  13365.     }
  13366.     else
  13367.     {
  13368.         PrintString(text, true);
  13369.     }
  13370. }
  13371.  
  13372. void XMLPrinter::PushText(int value)
  13373. {
  13374.     char buf[BUF_SIZE];
  13375.     XMLUtil::ToStr(value, buf, BUF_SIZE);
  13376.     PushText(buf, false);
  13377. }
  13378.  
  13379.  
  13380. void XMLPrinter::PushText(unsigned value)
  13381. {
  13382.     char buf[BUF_SIZE];
  13383.     XMLUtil::ToStr(value, buf, BUF_SIZE);
  13384.     PushText(buf, false);
  13385. }
  13386.  
  13387.  
  13388. void XMLPrinter::PushText(bool value)
  13389. {
  13390.     char buf[BUF_SIZE];
  13391.     XMLUtil::ToStr(value, buf, BUF_SIZE);
  13392.     PushText(buf, false);
  13393. }
  13394.  
  13395.  
  13396. void XMLPrinter::PushText(float value)
  13397. {
  13398.     char buf[BUF_SIZE];
  13399.     XMLUtil::ToStr(value, buf, BUF_SIZE);
  13400.     PushText(buf, false);
  13401. }
  13402.  
  13403.  
  13404. void XMLPrinter::PushText(double value)
  13405. {
  13406.     char buf[BUF_SIZE];
  13407.     XMLUtil::ToStr(value, buf, BUF_SIZE);
  13408.     PushText(buf, false);
  13409. }
  13410.  
  13411.  
  13412. void XMLPrinter::PushComment( const char* comment)
  13413. {
  13414.     SealElementIfJustOpened();
  13415.     if (_textDepth < 0 && !_firstElement && !_compactMode)
  13416.     {
  13417.         Print("\n");
  13418.         PrintSpace(_depth);
  13419.     }
  13420.     _firstElement = false;
  13421.     Print("<!--%s-->", comment);
  13422. }
  13423.  
  13424.  
  13425. void XMLPrinter::PushDeclaration( const char* value)
  13426. {
  13427.     SealElementIfJustOpened();
  13428.     if (_textDepth < 0 && !_firstElement && !_compactMode)
  13429.     {
  13430.         Print("\n");
  13431.         PrintSpace(_depth);
  13432.     }
  13433.     _firstElement = false;
  13434.     Print("<?%s?>", value);
  13435. }
  13436.  
  13437.  
  13438. void XMLPrinter::PushUnknown( const char* value)
  13439. {
  13440.     SealElementIfJustOpened();
  13441.     if (_textDepth < 0 && !_firstElement && !_compactMode)
  13442.     {
  13443.         Print("\n");
  13444.         PrintSpace(_depth);
  13445.     }
  13446.     _firstElement = false;
  13447.     Print("<!%s>", value);
  13448. }
  13449.  
  13450.  
  13451. bool XMLPrinter::VisitEnter( const XMLDocument& doc )
  13452. {
  13453.     _processEntities = doc.ProcessEntities();
  13454.     if (doc.HasBOM())
  13455.     {
  13456.         PushHeader(true, false);
  13457.     }
  13458.     return true;
  13459. }
  13460.  
  13461.  
  13462. bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute)
  13463. {
  13464.     const XMLElement* parentElem = 0;
  13465.     if (element.Parent())
  13466.     {
  13467.         parentElem = element.Parent()->ToElement();
  13468.     }
  13469.     const bool compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;
  13470.     OpenElement(element.Name(), compactMode);
  13471.     while (attribute)
  13472.     {
  13473.         PushAttribute(attribute->Name(), attribute->Value());
  13474.         attribute = attribute->Next();
  13475.     }
  13476.     return true;
  13477. }
  13478.  
  13479.  
  13480. bool XMLPrinter::VisitExit( const XMLElement& element )
  13481. {
  13482.     CloseElement(CompactMode(element));
  13483.     return true;
  13484. }
  13485.  
  13486.  
  13487. bool XMLPrinter::Visit( const XMLText& text )
  13488. {
  13489.     PushText(text.Value(), text.CData());
  13490.     return true;
  13491. }
  13492.  
  13493.  
  13494. bool XMLPrinter::Visit( const XMLComment& comment )
  13495. {
  13496.     PushComment(comment.Value());
  13497.     return true;
  13498. }
  13499.  
  13500. bool XMLPrinter::Visit( const XMLDeclaration& declaration )
  13501. {
  13502.     PushDeclaration(declaration.Value());
  13503.     return true;
  13504. }
  13505.  
  13506.  
  13507. bool XMLPrinter::Visit( const XMLUnknown& unknown )
  13508. {
  13509.     PushUnknown(unknown.Value());
  13510.     return true;
  13511. }
  13512.  
  13513. }   // namespace tinyxml2
  13514.  
  13515. /*
  13516. Original code by Lee Thomason (www.grinninglizard.com)
  13517.  
  13518. This software is provided 'as-is', without any express or implied
  13519. warranty. In no event will the authors be held liable for any
  13520. damages arising from the use of this software.
  13521.  
  13522. Permission is granted to anyone to use this software for any
  13523. purpose, including commercial applications, and to alter it and
  13524. redistribute it freely, subject to the following restrictions:
  13525.  
  13526. 1. The origin of this software must not be misrepresented; you must
  13527. not claim that you wrote the original software. If you use this
  13528. software in a product, an acknowledgment in the product documentation
  13529. would be appreciated but is not required.
  13530.  
  13531. 2. Altered source versions must be plainly marked as such, and
  13532. must not be misrepresented as being the original software.
  13533.  
  13534. 3. This notice may not be removed or altered from any source
  13535. distribution.
  13536. */
  13537.  
  13538. #ifndef TINYXML2_INCLUDED
  13539. #define TINYXML2_INCLUDED
  13540.  
  13541. #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
  13542. #   include <ctype.h>
  13543. #   include <limits.h>
  13544. #   include <stdio.h>
  13545. #   include <stdlib.h>
  13546. #   include <string.h>
  13547. #else
  13548. #   include <cctype>
  13549. #   include <climits>
  13550. #   include <cstdio>
  13551. #   include <cstdlib>
  13552. #   include <cstring>
  13553. #endif
  13554.  
  13555. /*
  13556.    TODO: intern strings instead of allocation.
  13557. */
  13558. /*
  13559.         gcc:
  13560.         g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
  13561.  
  13562.     Formatting, Artistic Style:
  13563.         AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
  13564. */
  13565.  
  13566. #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
  13567. #   ifndef DEBUG
  13568. #       define DEBUG
  13569. #   endif
  13570. #endif
  13571.  
  13572. #ifdef _MSC_VER
  13573. #   pragma warning(push)
  13574. #   pragma warning(disable: 4251)
  13575. #endif
  13576.  
  13577. #ifdef _WIN32
  13578. #   ifdef TINYXML2_EXPORT
  13579. #       define TINYXML2_LIB __declspec(dllexport)
  13580. #   elif defined(TINYXML2_IMPORT)
  13581. #       define TINYXML2_LIB __declspec(dllimport)
  13582. #   else
  13583. #       define TINYXML2_LIB
  13584. #   endif
  13585. #else
  13586. #   define TINYXML2_LIB
  13587. #endif
  13588.  
  13589.  
  13590. #if defined(DEBUG)
  13591. #   if defined(_MSC_VER)
  13592. #       // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
  13593. #       define TIXMLASSERT( x )           if ( !((void)0,(x))) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
  13594. #   elif defined (ANDROID_NDK)
  13595. #       include <android/log.h>
  13596. #       define TIXMLASSERT( x )           if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
  13597. #   else
  13598. #       include <assert.h>
  13599. #       define TIXMLASSERT                assert
  13600. #   endif
  13601. #   else
  13602. #       define TIXMLASSERT( x )           {}
  13603. #endif
  13604.  
  13605.  
  13606. /* Versioning, past 1.0.14:
  13607.         http://semver.org/
  13608. */
  13609. static const int TIXML2_MAJOR_VERSION = 3;
  13610. static const int TIXML2_MINOR_VERSION = 0;
  13611. static const int TIXML2_PATCH_VERSION = 0;
  13612.  
  13613. namespace tinyxml2
  13614. {
  13615.     class XMLDocument;
  13616.     class XMLElement;
  13617.     class XMLAttribute;
  13618.     class XMLComment;
  13619.     class XMLText;
  13620.     class XMLDeclaration;
  13621.     class XMLUnknown;
  13622.     class XMLPrinter;
  13623.  
  13624.     /*
  13625.         A class that wraps strings. Normally stores the start and end
  13626.         pointers into the XML file itself, and will apply normalization
  13627.         and entity translation if actually read. Can also store (and memory
  13628.         manage) a traditional char[]
  13629.     */
  13630.     class StrPair
  13631.     {
  13632.         public:
  13633.     enum {
  13634.             NEEDS_ENTITY_PROCESSING = 0x01,
  13635.             NEEDS_NEWLINE_NORMALIZATION = 0x02,
  13636.             NEEDS_WHITESPACE_COLLAPSING = 0x04,
  13637.  
  13638.             TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
  13639.             TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
  13640.             ATTRIBUTE_NAME = 0,
  13641.             ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
  13642.             ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
  13643.             COMMENT = NEEDS_NEWLINE_NORMALIZATION
  13644.         };
  13645.  
  13646.         StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) { }
  13647.         ~StrPair();
  13648.  
  13649.         void Set(char* start, char* end, int flags)
  13650.         {
  13651.             Reset();
  13652.             _start = start;
  13653.             _end = end;
  13654.             _flags = flags | NEEDS_FLUSH;
  13655.         }
  13656.  
  13657.         const char* GetStr();
  13658.  
  13659.         bool Empty() const {
  13660.         return _start == _end;
  13661.     }
  13662.  
  13663.     void SetInternedStr( const char* str)
  13664.     {
  13665.         Reset();
  13666.         _start = const_cast<char*>(str);
  13667.     }
  13668.  
  13669.     void SetStr( const char* str, int flags = 0);
  13670.  
  13671.     char* ParseText(char* in, const char* endTag, int strFlags);
  13672.     char* ParseName(char* in );
  13673.  
  13674.     void TransferTo(StrPair* other);
  13675.  
  13676.     private:
  13677.     void Reset();
  13678.     void CollapseWhitespace();
  13679.  
  13680.     enum {
  13681.         NEEDS_FLUSH = 0x100,
  13682.         NEEDS_DELETE = 0x200
  13683.     };
  13684.  
  13685.     // After parsing, if *_end != 0, it can be set to zero.
  13686.     int _flags;
  13687.     char* _start;
  13688.     char* _end;
  13689.  
  13690.     StrPair( const StrPair& other );    // not supported
  13691.     void operator=(StrPair& other );    // not supported, use TransferTo()
  13692. };
  13693.  
  13694.  
  13695. /*
  13696.         A dynamic array of Plain Old Data. Doesn't support constructors, etc.
  13697.         Has a small initial memory pool, so that low or no usage will not
  13698.         cause a call to new/delete
  13699. */
  13700. template<class T, int INITIAL_SIZE>
  13701. class DynArray
  13702. {
  13703.     public:
  13704.     DynArray()
  13705.     {
  13706.         _mem = _pool;
  13707.         _allocated = INITIAL_SIZE;
  13708.         _size = 0;
  13709.     }
  13710.  
  13711.     ~DynArray()
  13712.     {
  13713.         if (_mem != _pool)
  13714.         {
  13715.             delete[] _mem;
  13716.         }
  13717.     }
  13718.  
  13719.     void Clear()
  13720.     {
  13721.         _size = 0;
  13722.     }
  13723.  
  13724.     void Push(T t)
  13725.     {
  13726.         TIXMLASSERT(_size < INT_MAX);
  13727.         EnsureCapacity(_size + 1);
  13728.         _mem[_size++] = t;
  13729.     }
  13730.  
  13731.     T* PushArr(int count)
  13732.     {
  13733.         TIXMLASSERT(count >= 0);
  13734.         TIXMLASSERT(_size <= INT_MAX - count);
  13735.         EnsureCapacity(_size + count);
  13736.         T* ret = &_mem[_size];
  13737.         _size += count;
  13738.         return ret;
  13739.     }
  13740.  
  13741.     T Pop()
  13742.     {
  13743.         TIXMLASSERT(_size > 0);
  13744.         return _mem[--_size];
  13745.     }
  13746.  
  13747.     void PopArr(int count)
  13748.     {
  13749.         TIXMLASSERT(_size >= count);
  13750.         _size -= count;
  13751.     }
  13752.  
  13753.     bool Empty() const                  {
  13754.         return _size == 0;
  13755.     }
  13756.  
  13757. T& operator[] (int i)
  13758. {
  13759.     TIXMLASSERT(i >= 0 && i < _size);
  13760.     return _mem[i];
  13761. }
  13762.  
  13763. const T& operator[] (int i) const    {
  13764.         TIXMLASSERT(i>= 0 && i<_size );
  13765.         return _mem[i];
  13766.     }
  13767.  
  13768.     const T& PeekTop() const            {
  13769.         TIXMLASSERT(_size > 0 );
  13770.         return _mem[_size - 1];
  13771.     }
  13772.  
  13773.     int Size() const                    {
  13774.         TIXMLASSERT(_size >= 0 );
  13775.         return _size;
  13776.     }
  13777.  
  13778.     int Capacity() const                {
  13779.         TIXMLASSERT(_allocated >= INITIAL_SIZE );
  13780.         return _allocated;
  13781.     }
  13782.  
  13783.     const T* Mem() const                                {
  13784.         TIXMLASSERT(_mem);
  13785.         return _mem;
  13786.     }
  13787.  
  13788.     T* Mem()
  13789. {
  13790.     TIXMLASSERT(_mem);
  13791.     return _mem;
  13792. }
  13793.  
  13794. private:
  13795.     DynArray( const DynArray& ); // not supported
  13796. void operator=( const DynArray& ); // not supported
  13797.  
  13798. void EnsureCapacity(int cap)
  13799. {
  13800.     TIXMLASSERT(cap > 0);
  13801.     if (cap > _allocated)
  13802.     {
  13803.         TIXMLASSERT(cap <= INT_MAX / 2);
  13804.         int newAllocated = cap * 2;
  13805.         T* newMem = new T[newAllocated];
  13806.         memcpy(newMem, _mem, sizeof(T) * _size);    // warning: not using constructors, only works for PODs
  13807.         if (_mem != _pool)
  13808.         {
  13809.             delete[] _mem;
  13810.         }
  13811.         _mem = newMem;
  13812.         _allocated = newAllocated;
  13813.     }
  13814. }
  13815.  
  13816. T* _mem;
  13817. T _pool[INITIAL_SIZE];
  13818. int _allocated;     // objects allocated
  13819. int _size;                      // number objects in use
  13820. };
  13821.  
  13822.  
  13823. /*
  13824.         Parent virtual class of a pool for fast allocation
  13825.         and deallocation of objects.
  13826. */
  13827. class MemPool
  13828. {
  13829.     public:
  13830.     MemPool() { }
  13831.     virtual ~MemPool() { }
  13832.  
  13833.     virtual int ItemSize() const = 0;
  13834.     virtual void* Alloc() = 0;
  13835.     virtual void Free(void* ) = 0;
  13836.     virtual void SetTracked() = 0;
  13837.     virtual void Clear() = 0;
  13838. };
  13839.  
  13840.  
  13841. /*
  13842.         Template child class to create pools of the correct type.
  13843. */
  13844. template<int SIZE>
  13845. class MemPoolT : public MemPool
  13846. {
  13847. public:
  13848.     MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) { }
  13849. ~MemPoolT()
  13850. {
  13851.     Clear();
  13852. }
  13853.  
  13854. void Clear()
  13855. {
  13856.     // Delete the blocks.
  13857.     while (!_blockPtrs.Empty())
  13858.     {
  13859.         Block* b = _blockPtrs.Pop();
  13860.         delete b;
  13861.     }
  13862.     _root = 0;
  13863.     _currentAllocs = 0;
  13864.     _nAllocs = 0;
  13865.     _maxAllocs = 0;
  13866.     _nUntracked = 0;
  13867. }
  13868.  
  13869. virtual int ItemSize() const    {
  13870.         return SIZE;
  13871.     }
  13872.     int CurrentAllocs() const       {
  13873.         return _currentAllocs;
  13874.     }
  13875.  
  13876.     virtual void* Alloc()
  13877. {
  13878.     if (!_root)
  13879.     {
  13880.         // Need a new block.
  13881.         Block* block = new Block();
  13882.         _blockPtrs.Push(block);
  13883.  
  13884.         for (int i = 0; i < COUNT - 1; ++i)
  13885.         {
  13886.             block->chunk[i].next = &block->chunk[i + 1];
  13887.         }
  13888.         block->chunk[COUNT - 1].next = 0;
  13889.         _root = block->chunk;
  13890.     }
  13891.     void* result = _root;
  13892.     _root = _root->next;
  13893.  
  13894.     ++_currentAllocs;
  13895.     if (_currentAllocs > _maxAllocs)
  13896.     {
  13897.         _maxAllocs = _currentAllocs;
  13898.     }
  13899.     _nAllocs++;
  13900.     _nUntracked++;
  13901.     return result;
  13902. }
  13903.  
  13904. virtual void Free(void* mem)
  13905. {
  13906.     if (!mem)
  13907.     {
  13908.         return;
  13909.     }
  13910.     --_currentAllocs;
  13911.     Chunk* chunk = static_cast<Chunk*>(mem);
  13912. # ifdef DEBUG
  13913.     memset(chunk, 0xfe, sizeof(Chunk));
  13914. #endif
  13915.     chunk->next = _root;
  13916.     _root = chunk;
  13917. }
  13918. void Trace( const char* name)
  13919. {
  13920.     printf("Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n",
  13921.             name, _maxAllocs, _maxAllocs * SIZE / 1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size());
  13922. }
  13923.  
  13924. void SetTracked()
  13925. {
  13926.     _nUntracked--;
  13927. }
  13928.  
  13929. int Untracked() const {
  13930.         return _nUntracked;
  13931.     }
  13932.  
  13933.         // This number is perf sensitive. 4k seems like a good tradeoff on my machine.
  13934.         // The test file is large, 170k.
  13935.         // Release:             VS2010 gcc(no opt)
  13936.         //              1k:             4000
  13937.         //              2k:             4000
  13938.         //              4k:             3900    21000
  13939.         //              16k:    5200
  13940.         //              32k:    4300
  13941.         //              64k:    4000    21000
  13942.     enum { COUNT = (4 * 1024) / SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private
  13943.  
  13944. private:
  13945.     MemPoolT( const MemPoolT& ); // not supported
  13946. void operator=( const MemPoolT& ); // not supported
  13947.  
  13948. union Chunk
  13949. {
  13950.     Chunk*  next;
  13951.         char    mem [SIZE];
  13952. };
  13953. struct Block
  13954. {
  13955.     Chunk chunk[COUNT];
  13956. };
  13957. DynArray<Block*, 10 > _blockPtrs;
  13958. Chunk* _root;
  13959.  
  13960. int _currentAllocs;
  13961. int _nAllocs;
  13962. int _maxAllocs;
  13963. int _nUntracked;
  13964. };
  13965.  
  13966.  
  13967.  
  13968. /**
  13969.         Implements the interface to the "Visitor pattern" (see the Accept() method.)
  13970.         If you call the Accept() method, it requires being passed a XMLVisitor
  13971.         class to handle callbacks. For nodes that contain other nodes (Document, Element)
  13972.         you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs
  13973.         are simply called with Visit().
  13974.  
  13975.         If you return 'true' from a Visit method, recursive parsing will continue. If you return
  13976.         false, <b>no children of this node or its siblings</b> will be visited.
  13977.  
  13978.         All flavors of Visit methods have a default implementation that returns 'true' (continue
  13979.         visiting). You need to only override methods that are interesting to you.
  13980.  
  13981.         Generally Accept() is called on the XMLDocument, although all nodes support visiting.
  13982.  
  13983.         You should never change the document from a callback.
  13984.  
  13985.         @sa XMLNode::Accept()
  13986. */
  13987. class TINYXML2_LIB XMLVisitor
  13988. {
  13989. public:
  13990.     virtual ~XMLVisitor() { }
  13991.  
  13992. /// Visit a document.
  13993. virtual bool VisitEnter( const XMLDocument& /*doc*/ )
  13994. {
  13995.     return true;
  13996. }
  13997. /// Visit a document.
  13998. virtual bool VisitExit( const XMLDocument& /*doc*/ )
  13999. {
  14000.     return true;
  14001. }
  14002.  
  14003. /// Visit an element.
  14004. virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ )
  14005. {
  14006.     return true;
  14007. }
  14008. /// Visit an element.
  14009. virtual bool VisitExit( const XMLElement& /*element*/ )
  14010. {
  14011.     return true;
  14012. }
  14013.  
  14014. /// Visit a declaration.
  14015. virtual bool Visit( const XMLDeclaration& /*declaration*/ )
  14016. {
  14017.     return true;
  14018. }
  14019. /// Visit a text node.
  14020. virtual bool Visit( const XMLText& /*text*/ )
  14021. {
  14022.     return true;
  14023. }
  14024. /// Visit a comment node.
  14025. virtual bool Visit( const XMLComment& /*comment*/ )
  14026. {
  14027.     return true;
  14028. }
  14029. /// Visit an unknown node.
  14030. virtual bool Visit( const XMLUnknown& /*unknown*/ )
  14031. {
  14032.     return true;
  14033. }
  14034. };
  14035.  
  14036. // WARNING: must match XMLDocument::_errorNames[]
  14037. enum XMLError
  14038. {
  14039.     XML_SUCCESS = 0,
  14040.     XML_NO_ERROR = 0,
  14041.     XML_NO_ATTRIBUTE,
  14042.     XML_WRONG_ATTRIBUTE_TYPE,
  14043.     XML_ERROR_FILE_NOT_FOUND,
  14044.     XML_ERROR_FILE_COULD_NOT_BE_OPENED,
  14045.     XML_ERROR_FILE_READ_ERROR,
  14046.     XML_ERROR_ELEMENT_MISMATCH,
  14047.     XML_ERROR_PARSING_ELEMENT,
  14048.     XML_ERROR_PARSING_ATTRIBUTE,
  14049.     XML_ERROR_IDENTIFYING_TAG,
  14050.     XML_ERROR_PARSING_TEXT,
  14051.     XML_ERROR_PARSING_CDATA,
  14052.     XML_ERROR_PARSING_COMMENT,
  14053.     XML_ERROR_PARSING_DECLARATION,
  14054.     XML_ERROR_PARSING_UNKNOWN,
  14055.     XML_ERROR_EMPTY_DOCUMENT,
  14056.     XML_ERROR_MISMATCHED_ELEMENT,
  14057.     XML_ERROR_PARSING,
  14058.     XML_CAN_NOT_CONVERT_TEXT,
  14059.     XML_NO_TEXT_NODE,
  14060.  
  14061.     XML_ERROR_COUNT
  14062. };
  14063.  
  14064.  
  14065. /*
  14066.         Utility functionality.
  14067. */
  14068. class XMLUtil
  14069. {
  14070.     public:
  14071.     static const char* SkipWhiteSpace( const char* p )  {
  14072.         TIXMLASSERT(p );
  14073.         while( IsWhiteSpace(*p) ) {
  14074.             ++p;
  14075.         }
  14076.         TIXMLASSERT(p );
  14077.         return p;
  14078.     }
  14079.     static char* SkipWhiteSpace(char* p)
  14080. {
  14081.     return const_cast<char*>(SkipWhiteSpace(const_cast <const char*> (p) ) );
  14082. }
  14083.  
  14084. // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't
  14085. // correct, but simple, and usually works.
  14086. static bool IsWhiteSpace(char p)
  14087. {
  14088.     return !IsUTF8Continuation(p) && isspace(static_cast < unsigned char > (p));
  14089. }
  14090.  
  14091. inline static bool IsNameStartChar(unsigned char ch)
  14092. {
  14093.     if (ch >= 128)
  14094.     {
  14095.         // This is a heuristic guess in attempt to not implement Unicode-aware isalpha()
  14096.         return true;
  14097.     }
  14098.     if (isalpha(ch))
  14099.     {
  14100.         return true;
  14101.     }
  14102.     return ch == ':' || ch == '_';
  14103. }
  14104.  
  14105. inline static bool IsNameChar(unsigned char ch)
  14106. {
  14107.     return IsNameStartChar(ch)
  14108.            || isdigit(ch)
  14109.            || ch == '.'
  14110.            || ch == '-';
  14111. }
  14112.  
  14113. inline static bool StringEqual( const char* p, const char* q, int nChar = INT_MAX)
  14114. {
  14115.     if (p == q)
  14116.     {
  14117.         return true;
  14118.     }
  14119.     int n = 0;
  14120.     while (*p && *q && *p == *q && n < nChar)
  14121.     {
  14122.         ++p;
  14123.         ++q;
  14124.         ++n;
  14125.     }
  14126.     if ((n == nChar) || (*p == 0 && *q == 0))
  14127.     {
  14128.         return true;
  14129.     }
  14130.     return false;
  14131. }
  14132.  
  14133. inline static bool IsUTF8Continuation(char p)
  14134. {
  14135.     return (p & 0x80) != 0;
  14136. }
  14137.  
  14138. static const char* ReadBOM( const char * p, bool * hasBOM );
  14139.     // p is the starting location,
  14140.     // the UTF-8 value of the entity will be placed in value, and length filled in.
  14141.     static const char* GetCharacterRef( const char * p, char * value, int * length );
  14142.     static void ConvertUTF32ToUTF8(unsigned long input, char* output, int* length);
  14143.  
  14144. // converts primitive types to strings
  14145. static void ToStr(int v, char* buffer, int bufferSize);
  14146. static void ToStr(unsigned v, char* buffer, int bufferSize);
  14147. static void ToStr(bool v, char* buffer, int bufferSize);
  14148. static void ToStr(float v, char* buffer, int bufferSize);
  14149. static void ToStr(double v, char* buffer, int bufferSize);
  14150.  
  14151. // converts strings to primitive types
  14152. static bool ToInt( const char* str, int* value);
  14153. static bool ToUnsigned( const char* str, unsigned* value);
  14154. static bool ToBool( const char* str, bool* value);
  14155. static bool ToFloat( const char* str, float* value);
  14156. static bool ToDouble( const char* str, double* value);
  14157. };
  14158.  
  14159.  
  14160. /** XMLNode is a base class for every object that is in the
  14161.         XML Document Object Model (DOM), except XMLAttributes.
  14162.         Nodes have siblings, a parent, and children which can
  14163.         be navigated. A node is always in a XMLDocument.
  14164.         The type of a XMLNode can be queried, and it can
  14165.         be cast to its more defined type.
  14166.  
  14167.         A XMLDocument allocates memory for all its Nodes.
  14168.         When the XMLDocument gets deleted, all its Nodes
  14169.         will also be deleted.
  14170.  
  14171.         @verbatim
  14172.         A Document can contain: Element (container or leaf)
  14173.                                                         Comment (leaf)
  14174.                                                         Unknown (leaf)
  14175.                                                         Declaration( leaf )
  14176.  
  14177.         An Element can contain: Element (container or leaf)
  14178.                                                         Text    (leaf)
  14179.                                                         Attributes (not on tree)
  14180.                                                         Comment (leaf)
  14181.                                                         Unknown (leaf)
  14182.  
  14183.         @endverbatim
  14184. */
  14185. class TINYXML2_LIB XMLNode
  14186. {
  14187.     friend class XMLDocument;
  14188. friend class XMLElement;
  14189. public:
  14190.  
  14191.     /// Get the XMLDocument that owns this XMLNode.
  14192.     const XMLDocument* GetDocument() const      {
  14193.         TIXMLASSERT(_document);
  14194.         return _document;
  14195.     }
  14196.     /// Get the XMLDocument that owns this XMLNode.
  14197.     XMLDocument* GetDocument()
  14198. {
  14199.     TIXMLASSERT(_document);
  14200.     return _document;
  14201. }
  14202.  
  14203. /// Safely cast to an Element, or null.
  14204. virtual XMLElement* ToElement()
  14205. {
  14206.     return 0;
  14207. }
  14208. /// Safely cast to Text, or null.
  14209. virtual XMLText* ToText()
  14210. {
  14211.     return 0;
  14212. }
  14213. /// Safely cast to a Comment, or null.
  14214. virtual XMLComment* ToComment()
  14215. {
  14216.     return 0;
  14217. }
  14218. /// Safely cast to a Document, or null.
  14219. virtual XMLDocument* ToDocument()
  14220. {
  14221.     return 0;
  14222. }
  14223. /// Safely cast to a Declaration, or null.
  14224. virtual XMLDeclaration* ToDeclaration()
  14225. {
  14226.     return 0;
  14227. }
  14228. /// Safely cast to an Unknown, or null.
  14229. virtual XMLUnknown* ToUnknown()
  14230. {
  14231.     return 0;
  14232. }
  14233.  
  14234. virtual const XMLElement* ToElement() const             {
  14235.         return 0;
  14236.     }
  14237.     virtual const XMLText* ToText() const                       {
  14238.         return 0;
  14239.     }
  14240.     virtual const XMLComment* ToComment() const         {
  14241.         return 0;
  14242.     }
  14243.     virtual const XMLDocument* ToDocument() const               {
  14244.         return 0;
  14245.     }
  14246.     virtual const XMLDeclaration* ToDeclaration() const {
  14247.         return 0;
  14248.     }
  14249.     virtual const XMLUnknown* ToUnknown() const         {
  14250.         return 0;
  14251.     }
  14252.  
  14253.     /** The meaning of 'value' changes for the specific type.
  14254.         @verbatim
  14255.         Document:       empty (NULL is returned, not an empty string)
  14256.         Element:        name of the element
  14257.         Comment:        the comment text
  14258.         Unknown:        the tag contents
  14259.         Text:           the text string
  14260.         @endverbatim
  14261.     */
  14262.     const char* Value() const;
  14263.  
  14264. /** Set the Value of an XML node.
  14265.     @sa Value()
  14266. */
  14267. void SetValue( const char* val, bool staticMem = false);
  14268.  
  14269. /// Get the parent of this node on the DOM.
  14270. const XMLNode* Parent() const                   {
  14271.         return _parent;
  14272.     }
  14273.  
  14274.     XMLNode* Parent()
  14275. {
  14276.     return _parent;
  14277. }
  14278.  
  14279. /// Returns true if this node has no children.
  14280. bool NoChildren() const                 {
  14281.         return !_firstChild;
  14282.     }
  14283.  
  14284.     /// Get the first child node, or null if none exists.
  14285.     const XMLNode* FirstChild() const           {
  14286.         return _firstChild;
  14287.     }
  14288.  
  14289.     XMLNode* FirstChild()
  14290. {
  14291.     return _firstChild;
  14292. }
  14293.  
  14294. /** Get the first child element, or optionally the first child
  14295.     element with the specified name.
  14296. */
  14297. const XMLElement* FirstChildElement( const char * name = 0 ) const;
  14298.  
  14299. XMLElement* FirstChildElement( const char* name = 0)
  14300. {
  14301.     return const_cast<XMLElement*>(const_cast <const XMLNode*> (this)->FirstChildElement(name));
  14302. }
  14303.  
  14304. /// Get the last child node, or null if none exists.
  14305. const XMLNode* LastChild() const                                                {
  14306.         return _lastChild;
  14307.     }
  14308.  
  14309.     XMLNode* LastChild()
  14310. {
  14311.     return _lastChild;
  14312. }
  14313.  
  14314. /** Get the last child element or optionally the last child
  14315.     element with the specified name.
  14316. */
  14317. const XMLElement* LastChildElement( const char * name = 0 ) const;
  14318.  
  14319. XMLElement* LastChildElement( const char* name = 0)
  14320. {
  14321.     return const_cast<XMLElement*>(const_cast <const XMLNode*> (this)->LastChildElement(name) );
  14322. }
  14323.  
  14324. /// Get the previous (left) sibling node of this node.
  14325. const XMLNode* PreviousSibling() const                                  {
  14326.         return _prev;
  14327.     }
  14328.  
  14329.     XMLNode* PreviousSibling()
  14330. {
  14331.     return _prev;
  14332. }
  14333.  
  14334. /// Get the previous (left) sibling element of this node, with an optionally supplied name.
  14335. const XMLElement* PreviousSiblingElement( const char * name = 0 ) const ;
  14336.  
  14337. XMLElement* PreviousSiblingElement( const char* name = 0)
  14338. {
  14339.     return const_cast<XMLElement*>(const_cast <const XMLNode*> (this)->PreviousSiblingElement(name) );
  14340. }
  14341.  
  14342. /// Get the next (right) sibling node of this node.
  14343. const XMLNode* NextSibling() const                                              {
  14344.         return _next;
  14345.     }
  14346.  
  14347.     XMLNode* NextSibling()
  14348. {
  14349.     return _next;
  14350. }
  14351.  
  14352. /// Get the next (right) sibling element of this node, with an optionally supplied name.
  14353. const XMLElement* NextSiblingElement( const char * name = 0 ) const;
  14354.  
  14355. XMLElement* NextSiblingElement( const char* name = 0)
  14356. {
  14357.     return const_cast<XMLElement*>(const_cast <const XMLNode*> (this)->NextSiblingElement(name) );
  14358. }
  14359.  
  14360. /**
  14361.     Add a child node as the last (right) child.
  14362.     If the child node is already part of the document,
  14363.     it is moved from its old location to the new location.
  14364.     Returns the addThis argument or 0 if the node does not
  14365.     belong to the same document.
  14366. */
  14367. XMLNode* InsertEndChild(XMLNode* addThis);
  14368.  
  14369. XMLNode* LinkEndChild(XMLNode* addThis)
  14370. {
  14371.     return InsertEndChild(addThis);
  14372. }
  14373. /**
  14374.     Add a child node as the first (left) child.
  14375.     If the child node is already part of the document,
  14376.     it is moved from its old location to the new location.
  14377.     Returns the addThis argument or 0 if the node does not
  14378.     belong to the same document.
  14379. */
  14380. XMLNode* InsertFirstChild(XMLNode* addThis);
  14381. /**
  14382.     Add a node after the specified child node.
  14383.     If the child node is already part of the document,
  14384.     it is moved from its old location to the new location.
  14385.     Returns the addThis argument or 0 if the afterThis node
  14386.     is not a child of this node, or if the node does not
  14387.     belong to the same document.
  14388. */
  14389. XMLNode* InsertAfterChild(XMLNode* afterThis, XMLNode* addThis);
  14390.  
  14391. /**
  14392.     Delete all the children of this node.
  14393. */
  14394. void DeleteChildren();
  14395.  
  14396. /**
  14397.     Delete a child of this node.
  14398. */
  14399. void DeleteChild(XMLNode* node);
  14400.  
  14401. /**
  14402.     Make a copy of this node, but not its children.
  14403.     You may pass in a Document pointer that will be
  14404.     the owner of the new Node. If the 'document' is
  14405.     null, then the node returned will be allocated
  14406.     from the current Document. (this->GetDocument())
  14407.  
  14408.     Note: if called on a XMLDocument, this will return null.
  14409. */
  14410. virtual XMLNode* ShallowClone(XMLDocument* document) const = 0;
  14411.  
  14412. /**
  14413.     Test if 2 nodes are the same, but don't test children.
  14414.     The 2 nodes do not need to be in the same Document.
  14415.  
  14416.     Note: if called on a XMLDocument, this will return false.
  14417. */
  14418. virtual bool ShallowEqual( const XMLNode* compare) const = 0;
  14419.  
  14420. /** Accept a hierarchical visit of the nodes in the TinyXML-2 DOM. Every node in the
  14421.     XML tree will be conditionally visited and the host will be called back
  14422.     via the XMLVisitor interface.
  14423.  
  14424.     This is essentially a SAX interface for TinyXML-2. (Note however it doesn't re-parse
  14425.     the XML for the callbacks, so the performance of TinyXML-2 is unchanged by using this
  14426.     interface versus any other.)
  14427.  
  14428.     The interface has been based on ideas from:
  14429.  
  14430.     - http://www.saxproject.org/
  14431.     - http://c2.com/cgi/wiki?HierarchicalVisitorPattern
  14432.  
  14433.     Which are both good references for "visiting".
  14434.  
  14435.     An example of using Accept():
  14436.     @verbatim
  14437.     XMLPrinter printer;
  14438.     tinyxmlDoc.Accept( &printer );
  14439.     const char* xmlcstr = printer.CStr();
  14440.     @endverbatim
  14441. */
  14442. virtual bool Accept(XMLVisitor* visitor) const = 0;
  14443.  
  14444. protected:
  14445.     XMLNode(XMLDocument* );
  14446. virtual ~XMLNode();
  14447.  
  14448. virtual char* ParseDeep(char*, StrPair* );
  14449.  
  14450. XMLDocument* _document;
  14451. XMLNode* _parent;
  14452. mutable StrPair _value;
  14453.  
  14454.     XMLNode* _firstChild;
  14455. XMLNode* _lastChild;
  14456.  
  14457. XMLNode* _prev;
  14458. XMLNode* _next;
  14459.  
  14460. private:
  14461.     MemPool* _memPool;
  14462. void Unlink(XMLNode* child);
  14463. static void DeleteNode(XMLNode* node);
  14464. void InsertChildPreamble(XMLNode* insertThis) const;
  14465.  
  14466.     XMLNode( const XMLNode& );  // not supported
  14467. XMLNode& operator=( const XMLNode& );   // not supported
  14468. };
  14469.  
  14470.  
  14471. /** XML text.
  14472.  
  14473.         Note that a text node can have child element nodes, for example:
  14474.         @verbatim
  14475.         <root>This is <b>bold</b></root>
  14476.         @endverbatim
  14477.  
  14478.         A text node can have 2 ways to output the next. "normal" output
  14479.         and CDATA. It will default to the mode it was parsed from the XML file and
  14480.         you generally want to leave it alone, but you can change the output mode with
  14481.         SetCData() and query it with CData().
  14482. */
  14483. class TINYXML2_LIB XMLText : public XMLNode
  14484. {
  14485.     friend class XMLBase;
  14486. friend class XMLDocument;
  14487. public:
  14488.     virtual bool Accept(XMLVisitor* visitor) const;
  14489.  
  14490. virtual XMLText* ToText()
  14491. {
  14492.     return this;
  14493. }
  14494. virtual const XMLText* ToText() const   {
  14495.         return this;
  14496.     }
  14497.  
  14498.     /// Declare whether this should be CDATA or standard text.
  14499.     void SetCData(bool isCData)
  14500. {
  14501.     _isCData = isCData;
  14502. }
  14503. /// Returns true if this is a CDATA text element.
  14504. bool CData() const                      {
  14505.         return _isCData;
  14506.     }
  14507.  
  14508.     virtual XMLNode* ShallowClone(XMLDocument* document) const;
  14509. virtual bool ShallowEqual( const XMLNode* compare) const;
  14510.  
  14511. protected:
  14512.     XMLText(XMLDocument* doc)   : XMLNode(doc ), _isCData( false ) { }
  14513. virtual ~XMLText() { }
  14514.  
  14515. char* ParseDeep(char*, StrPair* endTag);
  14516.  
  14517. private:
  14518.     bool _isCData;
  14519.  
  14520.     XMLText( const XMLText& );  // not supported
  14521. XMLText& operator=( const XMLText& );   // not supported
  14522. };
  14523.  
  14524.  
  14525. /** An XML Comment. */
  14526. class TINYXML2_LIB XMLComment : public XMLNode
  14527. {
  14528.     friend class XMLDocument;
  14529. public:
  14530.     virtual XMLComment* ToComment()
  14531. {
  14532.     return this;
  14533. }
  14534. virtual const XMLComment* ToComment() const             {
  14535.         return this;
  14536.     }
  14537.  
  14538.     virtual bool Accept(XMLVisitor* visitor) const;
  14539.  
  14540. virtual XMLNode* ShallowClone(XMLDocument* document) const;
  14541. virtual bool ShallowEqual( const XMLNode* compare) const;
  14542.  
  14543. protected:
  14544.     XMLComment(XMLDocument* doc);
  14545. virtual ~XMLComment();
  14546.  
  14547. char* ParseDeep(char*, StrPair* endTag);
  14548.  
  14549. private:
  14550.     XMLComment( const XMLComment& );    // not supported
  14551. XMLComment& operator=( const XMLComment& );     // not supported
  14552. };
  14553.  
  14554.  
  14555. /** In correct XML the declaration is the first entry in the file.
  14556.         @verbatim
  14557.                 <?xml version="1.0" standalone="yes"?>
  14558.         @endverbatim
  14559.  
  14560.         TinyXML-2 will happily read or write files without a declaration,
  14561.         however.
  14562.  
  14563.         The text of the declaration isn't interpreted. It is parsed
  14564.         and written as a string.
  14565. */
  14566. class TINYXML2_LIB XMLDeclaration : public XMLNode
  14567. {
  14568.     friend class XMLDocument;
  14569. public:
  14570.     virtual XMLDeclaration* ToDeclaration()
  14571. {
  14572.     return this;
  14573. }
  14574. virtual const XMLDeclaration* ToDeclaration() const             {
  14575.         return this;
  14576.     }
  14577.  
  14578.     virtual bool Accept(XMLVisitor* visitor) const;
  14579.  
  14580. virtual XMLNode* ShallowClone(XMLDocument* document) const;
  14581. virtual bool ShallowEqual( const XMLNode* compare) const;
  14582.  
  14583. protected:
  14584.     XMLDeclaration(XMLDocument* doc);
  14585. virtual ~XMLDeclaration();
  14586.  
  14587. char* ParseDeep(char*, StrPair* endTag);
  14588.  
  14589. private:
  14590.     XMLDeclaration( const XMLDeclaration& );    // not supported
  14591. XMLDeclaration& operator=( const XMLDeclaration& );     // not supported
  14592. };
  14593.  
  14594.  
  14595. /** Any tag that TinyXML-2 doesn't recognize is saved as an
  14596.         unknown. It is a tag of text, but should not be modified.
  14597.         It will be written back to the XML, unchanged, when the file
  14598.         is saved.
  14599.  
  14600.         DTD tags get thrown into XMLUnknowns.
  14601. */
  14602. class TINYXML2_LIB XMLUnknown : public XMLNode
  14603. {
  14604.     friend class XMLDocument;
  14605. public:
  14606.     virtual XMLUnknown* ToUnknown()
  14607. {
  14608.     return this;
  14609. }
  14610. virtual const XMLUnknown* ToUnknown() const             {
  14611.         return this;
  14612.     }
  14613.  
  14614.     virtual bool Accept(XMLVisitor* visitor) const;
  14615.  
  14616. virtual XMLNode* ShallowClone(XMLDocument* document) const;
  14617. virtual bool ShallowEqual( const XMLNode* compare) const;
  14618.  
  14619. protected:
  14620.     XMLUnknown(XMLDocument* doc);
  14621. virtual ~XMLUnknown();
  14622.  
  14623. char* ParseDeep(char*, StrPair* endTag);
  14624.  
  14625. private:
  14626.     XMLUnknown( const XMLUnknown& );    // not supported
  14627. XMLUnknown& operator=( const XMLUnknown& );     // not supported
  14628. };
  14629.  
  14630.  
  14631.  
  14632. /** An attribute is a name-value pair. Elements have an arbitrary
  14633.         number of attributes, each with a unique name.
  14634.  
  14635.         @note The attributes are not XMLNodes. You may only query the
  14636.         Next() attribute in a list.
  14637. */
  14638. class TINYXML2_LIB XMLAttribute
  14639. {
  14640.     friend class XMLElement;
  14641. public:
  14642.     /// The name of the attribute.
  14643.     const char* Name() const;
  14644.  
  14645. /// The value of the attribute.
  14646. const char* Value() const;
  14647.  
  14648. /// The next attribute in the list.
  14649. const XMLAttribute* Next() const {
  14650.         return _next;
  14651.     }
  14652.  
  14653.     /** IntValue interprets the attribute as an integer, and returns the value.
  14654.         If the value isn't an integer, 0 will be returned. There is no error checking;
  14655.         use QueryIntValue() if you need error checking.
  14656.     */
  14657.     int IntValue() const               {
  14658.         int i = 0;
  14659.         QueryIntValue( &i );
  14660.         return i;
  14661.     }
  14662.     /// Query as an unsigned integer. See IntValue()
  14663.     unsigned UnsignedValue() const          {
  14664.         unsigned i = 0;
  14665.         QueryUnsignedValue( &i );
  14666.         return i;
  14667.     }
  14668.     /// Query as a boolean. See IntValue()
  14669.     bool BoolValue() const              {
  14670.         bool b = false;
  14671.         QueryBoolValue( &b );
  14672.         return b;
  14673.     }
  14674.     /// Query as a double. See IntValue()
  14675.     double DoubleValue() const            {
  14676.         double d = 0;
  14677.         QueryDoubleValue( &d );
  14678.         return d;
  14679.     }
  14680.     /// Query as a float. See IntValue()
  14681.     float FloatValue() const             {
  14682.         float f = 0;
  14683.         QueryFloatValue( &f );
  14684.         return f;
  14685.     }
  14686.  
  14687.     /** QueryIntValue interprets the attribute as an integer, and returns the value
  14688.         in the provided parameter. The function will return XML_NO_ERROR on success,
  14689.         and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful.
  14690.     */
  14691.     XMLError QueryIntValue(int* value) const;
  14692. /// See QueryIntValue
  14693. XMLError QueryUnsignedValue(unsigned int* value) const;
  14694. /// See QueryIntValue
  14695. XMLError QueryBoolValue(bool* value) const;
  14696. /// See QueryIntValue
  14697. XMLError QueryDoubleValue(double* value) const;
  14698. /// See QueryIntValue
  14699. XMLError QueryFloatValue(float* value) const;
  14700.  
  14701. /// Set the attribute to a string value.
  14702. void SetAttribute( const char* value);
  14703. /// Set the attribute to value.
  14704. void SetAttribute(int value);
  14705. /// Set the attribute to value.
  14706. void SetAttribute(unsigned value);
  14707. /// Set the attribute to value.
  14708. void SetAttribute(bool value);
  14709. /// Set the attribute to value.
  14710. void SetAttribute(double value);
  14711. /// Set the attribute to value.
  14712. void SetAttribute(float value);
  14713.  
  14714. private:
  14715.     enum { BUF_SIZE = 200 };
  14716.  
  14717.     XMLAttribute() : _next( 0 ), _memPool( 0 ) { }
  14718. virtual ~XMLAttribute() { }
  14719.  
  14720.     XMLAttribute( const XMLAttribute& );    // not supported
  14721. void operator=( const XMLAttribute& );  // not supported
  14722. void SetName( const char* name);
  14723.  
  14724. char* ParseDeep(char* p, bool processEntities);
  14725.  
  14726. mutable StrPair _name;
  14727.     mutable StrPair _value;
  14728.     XMLAttribute* _next;
  14729. MemPool* _memPool;
  14730. };
  14731.  
  14732.  
  14733. /** The element is a container class. It has a value, the element name,
  14734.         and can contain other elements, text, comments, and unknowns.
  14735.         Elements also contain an arbitrary number of attributes.
  14736. */
  14737. class TINYXML2_LIB XMLElement : public XMLNode
  14738. {
  14739.     friend class XMLBase;
  14740. friend class XMLDocument;
  14741. public:
  14742.     /// Get the name of an element (which is the Value() of the node.)
  14743.     const char* Name() const            {
  14744.         return Value();
  14745.     }
  14746.     /// Set the name of the element.
  14747.     void SetName( const char* str, bool staticMem = false)
  14748. {
  14749.     SetValue(str, staticMem);
  14750. }
  14751.  
  14752. virtual XMLElement* ToElement()
  14753. {
  14754.     return this;
  14755. }
  14756. virtual const XMLElement* ToElement() const {
  14757.         return this;
  14758.     }
  14759.     virtual bool Accept(XMLVisitor* visitor) const;
  14760.  
  14761. /** Given an attribute name, Attribute() returns the value
  14762.     for the attribute of that name, or null if none
  14763.     exists. For example:
  14764.  
  14765.     @verbatim
  14766.     const char* value = ele->Attribute( "foo" );
  14767.     @endverbatim
  14768.  
  14769.     The 'value' parameter is normally null. However, if specified,
  14770.     the attribute will only be returned if the 'name' and 'value'
  14771.     match. This allow you to write code:
  14772.  
  14773.     @verbatim
  14774.     if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar();
  14775.     @endverbatim
  14776.  
  14777.     rather than:
  14778.     @verbatim
  14779.     if ( ele->Attribute( "foo" ) ) {
  14780.         if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar();
  14781.     }
  14782.     @endverbatim
  14783. */
  14784. const char* Attribute( const char * name, const char * value = 0 ) const;
  14785.  
  14786. /** Given an attribute name, IntAttribute() returns the value
  14787.     of the attribute interpreted as an integer. 0 will be
  14788.     returned if there is an error. For a method with error
  14789.     checking, see QueryIntAttribute()
  14790. */
  14791. int IntAttribute( const char* name) const     {
  14792.         int i = 0;
  14793.         QueryIntAttribute(name, &i );
  14794.         return i;
  14795.     }
  14796.     /// See IntAttribute()
  14797.     unsigned UnsignedAttribute( const char* name) const {
  14798.         unsigned i = 0;
  14799.         QueryUnsignedAttribute(name, &i );
  14800.         return i;
  14801.     }
  14802.     /// See IntAttribute()
  14803.     bool BoolAttribute( const char* name) const    {
  14804.         bool b = false;
  14805.         QueryBoolAttribute(name, &b );
  14806.         return b;
  14807.     }
  14808.     /// See IntAttribute()
  14809.     double DoubleAttribute( const char* name) const  {
  14810.         double d = 0;
  14811.         QueryDoubleAttribute(name, &d );
  14812.         return d;
  14813.     }
  14814.     /// See IntAttribute()
  14815.     float FloatAttribute( const char* name) const   {
  14816.         float f = 0;
  14817.         QueryFloatAttribute(name, &f );
  14818.         return f;
  14819.     }
  14820.  
  14821.     /** Given an attribute name, QueryIntAttribute() returns
  14822.         XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion
  14823.         can't be performed, or XML_NO_ATTRIBUTE if the attribute
  14824.         doesn't exist. If successful, the result of the conversion
  14825.         will be written to 'value'. If not successful, nothing will
  14826.         be written to 'value'. This allows you to provide default
  14827.         value:
  14828.  
  14829.         @verbatim
  14830.         int value = 10;
  14831.         QueryIntAttribute( "foo", &value );             // if "foo" isn't found, value will still be 10
  14832.         @endverbatim
  14833.     */
  14834.     XMLError QueryIntAttribute( const char* name, int* value) const                {
  14835.         const XMLAttribute* a = FindAttribute(name);
  14836.         if ( !a ) {
  14837.             return XML_NO_ATTRIBUTE;
  14838.         }
  14839.         return a->QueryIntValue(value );
  14840.     }
  14841.     /// See QueryIntAttribute()
  14842.     XMLError QueryUnsignedAttribute( const char* name, unsigned int* value) const  {
  14843.         const XMLAttribute* a = FindAttribute(name);
  14844.         if ( !a ) {
  14845.             return XML_NO_ATTRIBUTE;
  14846.         }
  14847.         return a->QueryUnsignedValue(value );
  14848.     }
  14849.     /// See QueryIntAttribute()
  14850.     XMLError QueryBoolAttribute( const char* name, bool* value) const              {
  14851.         const XMLAttribute* a = FindAttribute(name);
  14852.         if ( !a ) {
  14853.             return XML_NO_ATTRIBUTE;
  14854.         }
  14855.         return a->QueryBoolValue(value );
  14856.     }
  14857.     /// See QueryIntAttribute()
  14858.     XMLError QueryDoubleAttribute( const char* name, double* value) const          {
  14859.         const XMLAttribute* a = FindAttribute(name);
  14860.         if ( !a ) {
  14861.             return XML_NO_ATTRIBUTE;
  14862.         }
  14863.         return a->QueryDoubleValue(value );
  14864.     }
  14865.     /// See QueryIntAttribute()
  14866.     XMLError QueryFloatAttribute( const char* name, float* value) const            {
  14867.         const XMLAttribute* a = FindAttribute(name);
  14868.         if ( !a ) {
  14869.             return XML_NO_ATTRIBUTE;
  14870.         }
  14871.         return a->QueryFloatValue(value );
  14872.     }
  14873.  
  14874.        
  14875.     /** Given an attribute name, QueryAttribute() returns
  14876.         XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion
  14877.         can't be performed, or XML_NO_ATTRIBUTE if the attribute
  14878.         doesn't exist. It is overloaded for the primitive types,
  14879.                 and is a generally more convenient replacement of
  14880.                 QueryIntAttribute() and related functions.
  14881.                
  14882.                 If successful, the result of the conversion
  14883.         will be written to 'value'. If not successful, nothing will
  14884.         be written to 'value'. This allows you to provide default
  14885.         value:
  14886.  
  14887.         @verbatim
  14888.         int value = 10;
  14889.         QueryAttribute( "foo", &value );                // if "foo" isn't found, value will still be 10
  14890.         @endverbatim
  14891.     */
  14892.         int QueryAttribute( const char* name, int* value) const {
  14893.                 return QueryIntAttribute(name, value );
  14894.         }
  14895.  
  14896.         int QueryAttribute( const char* name, unsigned int* value) const {
  14897.                 return QueryUnsignedAttribute(name, value );
  14898.         }
  14899.  
  14900.         int QueryAttribute( const char* name, bool* value) const {
  14901.                 return QueryBoolAttribute(name, value );
  14902.         }
  14903.  
  14904.         int QueryAttribute( const char* name, double* value) const {
  14905.                 return QueryDoubleAttribute(name, value );
  14906.         }
  14907.  
  14908.         int QueryAttribute( const char* name, float* value) const {
  14909.                 return QueryFloatAttribute(name, value );
  14910.         }
  14911.  
  14912.         /// Sets the named attribute to value.
  14913.     void SetAttribute( const char* name, const char* value)
  14914. {
  14915.     XMLAttribute* a = FindOrCreateAttribute(name);
  14916.     a->SetAttribute(value);
  14917. }
  14918. /// Sets the named attribute to value.
  14919. void SetAttribute( const char* name, int value)
  14920. {
  14921.     XMLAttribute* a = FindOrCreateAttribute(name);
  14922.     a->SetAttribute(value);
  14923. }
  14924. /// Sets the named attribute to value.
  14925. void SetAttribute( const char* name, unsigned value)
  14926. {
  14927.     XMLAttribute* a = FindOrCreateAttribute(name);
  14928.     a->SetAttribute(value);
  14929. }
  14930. /// Sets the named attribute to value.
  14931. void SetAttribute( const char* name, bool value)
  14932. {
  14933.     XMLAttribute* a = FindOrCreateAttribute(name);
  14934.     a->SetAttribute(value);
  14935. }
  14936. /// Sets the named attribute to value.
  14937. void SetAttribute( const char* name, double value)
  14938. {
  14939.     XMLAttribute* a = FindOrCreateAttribute(name);
  14940.     a->SetAttribute(value);
  14941. }
  14942. /// Sets the named attribute to value.
  14943. void SetAttribute( const char* name, float value)
  14944. {
  14945.     XMLAttribute* a = FindOrCreateAttribute(name);
  14946.     a->SetAttribute(value);
  14947. }
  14948.  
  14949. /**
  14950.     Delete an attribute.
  14951. */
  14952. void DeleteAttribute( const char* name);
  14953.  
  14954. /// Return the first attribute in the list.
  14955. const XMLAttribute* FirstAttribute() const {
  14956.         return _rootAttribute;
  14957.     }
  14958.     /// Query a specific attribute in the list.
  14959.     const XMLAttribute* FindAttribute( const char * name ) const;
  14960.  
  14961. /** Convenience function for easy access to the text inside an element. Although easy
  14962.     and concise, GetText() is limited compared to getting the XMLText child
  14963.     and accessing it directly.
  14964.  
  14965.     If the first child of 'this' is a XMLText, the GetText()
  14966.     returns the character string of the Text node, else null is returned.
  14967.  
  14968.     This is a convenient method for getting the text of simple contained text:
  14969.     @verbatim
  14970.     <foo>This is text</foo>
  14971.         const char* str = fooElement->GetText();
  14972.     @endverbatim
  14973.  
  14974.     'str' will be a pointer to "This is text".
  14975.  
  14976.     Note that this function can be misleading. If the element foo was created from
  14977.     this XML:
  14978.     @verbatim
  14979.         <foo><b>This is text</b></foo>
  14980.     @endverbatim
  14981.  
  14982.     then the value of str would be null. The first child node isn't a text node, it is
  14983.     another element. From this XML:
  14984.     @verbatim
  14985.         <foo>This is <b>text</b></foo>
  14986.     @endverbatim
  14987.     GetText() will return "This is ".
  14988. */
  14989. const char* GetText() const;
  14990.  
  14991. /** Convenience function for easy access to the text inside an element. Although easy
  14992.     and concise, SetText() is limited compared to creating an XMLText child
  14993.     and mutating it directly.
  14994.  
  14995.     If the first child of 'this' is a XMLText, SetText() sets its value to
  14996.     the given string, otherwise it will create a first child that is an XMLText.
  14997.  
  14998.     This is a convenient method for setting the text of simple contained text:
  14999.     @verbatim
  15000.     <foo>This is text</foo>
  15001.         fooElement->SetText( "Hullaballoo!" );
  15002.     <foo>Hullaballoo!</foo>
  15003.     @endverbatim
  15004.  
  15005.     Note that this function can be misleading. If the element foo was created from
  15006.     this XML:
  15007.     @verbatim
  15008.         <foo><b>This is text</b></foo>
  15009.     @endverbatim
  15010.  
  15011.     then it will not change "This is text", but rather prefix it with a text element:
  15012.     @verbatim
  15013.         <foo>Hullaballoo!<b>This is text</b></foo>
  15014.     @endverbatim
  15015.    
  15016.     For this XML:
  15017.     @verbatim
  15018.         <foo />
  15019.     @endverbatim
  15020.     SetText() will generate
  15021.     @verbatim
  15022.         <foo>Hullaballoo!</foo>
  15023.     @endverbatim
  15024. */
  15025. void SetText( const char* inText);
  15026. /// Convenience method for setting text inside and element. See SetText() for important limitations.
  15027. void SetText(int value);
  15028. /// Convenience method for setting text inside and element. See SetText() for important limitations.
  15029. void SetText(unsigned value);
  15030. /// Convenience method for setting text inside and element. See SetText() for important limitations.
  15031. void SetText(bool value);
  15032. /// Convenience method for setting text inside and element. See SetText() for important limitations.
  15033. void SetText(double value);
  15034. /// Convenience method for setting text inside and element. See SetText() for important limitations.
  15035. void SetText(float value);
  15036.  
  15037. /**
  15038.     Convenience method to query the value of a child text node. This is probably best
  15039.     shown by example. Given you have a document is this form:
  15040.     @verbatim
  15041.         <point>
  15042.             <x>1</x>
  15043.             <y>1.4</y>
  15044.         </point>
  15045.     @endverbatim
  15046.  
  15047.     The QueryIntText() and similar functions provide a safe and easier way to get to the
  15048.     "value" of x and y.
  15049.  
  15050.     @verbatim
  15051.         int x = 0;
  15052.         float y = 0;    // types of x and y are contrived for example
  15053.         const XMLElement* xElement = pointElement->FirstChildElement( "x" );
  15054.         const XMLElement* yElement = pointElement->FirstChildElement( "y" );
  15055.         xElement->QueryIntText( &x );
  15056.         yElement->QueryFloatText( &y );
  15057.     @endverbatim
  15058.  
  15059.     @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted
  15060.              to the requested type, and XML_NO_TEXT_NODE if there is no child text to query.
  15061.  
  15062. */
  15063. XMLError QueryIntText(int* ival) const;
  15064. /// See QueryIntText()
  15065. XMLError QueryUnsignedText(unsigned* uval) const;
  15066. /// See QueryIntText()
  15067. XMLError QueryBoolText(bool* bval) const;
  15068. /// See QueryIntText()
  15069. XMLError QueryDoubleText(double* dval) const;
  15070. /// See QueryIntText()
  15071. XMLError QueryFloatText(float* fval) const;
  15072.  
  15073. // internal:
  15074. enum {
  15075.     OPEN,       // <foo>
  15076.     CLOSED,     // <foo/>
  15077.     CLOSING     // </foo>
  15078. };
  15079. int ClosingType() const {
  15080.         return _closingType;
  15081.     }
  15082.     virtual XMLNode* ShallowClone(XMLDocument* document) const;
  15083. virtual bool ShallowEqual( const XMLNode* compare) const;
  15084.  
  15085. protected:
  15086.     char* ParseDeep(char* p, StrPair* endTag);
  15087.  
  15088. private:
  15089.     XMLElement(XMLDocument* doc);
  15090. virtual ~XMLElement();
  15091.     XMLElement( const XMLElement& );    // not supported
  15092. void operator=( const XMLElement& );    // not supported
  15093.  
  15094. XMLAttribute* FindAttribute( const char* name)
  15095. {
  15096.     return const_cast<XMLAttribute*>(const_cast <const XMLElement*> (this)->FindAttribute(name));
  15097. }
  15098. XMLAttribute* FindOrCreateAttribute( const char* name);
  15099. //void LinkAttribute( XMLAttribute* attrib );
  15100. char* ParseAttributes(char* p);
  15101. static void DeleteAttribute(XMLAttribute* attribute);
  15102.  
  15103. enum { BUF_SIZE = 200 };
  15104. int _closingType;
  15105. // The attribute list is ordered; there is no 'lastAttribute'
  15106. // because the list needs to be scanned for dupes before adding
  15107. // a new attribute.
  15108. XMLAttribute* _rootAttribute;
  15109. };
  15110.  
  15111.  
  15112. enum Whitespace
  15113. {
  15114.     PRESERVE_WHITESPACE,
  15115.     COLLAPSE_WHITESPACE
  15116. };
  15117.  
  15118.  
  15119. /** A Document binds together all the functionality.
  15120.         It can be saved, loaded, and printed to the screen.
  15121.         All Nodes are connected and allocated to a Document.
  15122.         If the Document is deleted, all its Nodes are also deleted.
  15123. */
  15124. class TINYXML2_LIB XMLDocument : public XMLNode
  15125. {
  15126.     friend class XMLElement;
  15127. public:
  15128.     /// constructor
  15129.     XMLDocument(bool processEntities = true, Whitespace = PRESERVE_WHITESPACE);
  15130. ~XMLDocument();
  15131.  
  15132. virtual XMLDocument* ToDocument()
  15133. {
  15134.     TIXMLASSERT(this == _document);
  15135.     return this;
  15136. }
  15137. virtual const XMLDocument* ToDocument() const   {
  15138.  
  15139.     TIXMLASSERT(this == _document);
  15140.         return this;
  15141.     }
  15142.  
  15143. /**
  15144.     Parse an XML file from a character string.
  15145.     Returns XML_NO_ERROR (0) on success, or
  15146.     an errorID.
  15147.  
  15148.     You may optionally pass in the 'nBytes', which is
  15149.     the number of bytes which will be parsed. If not
  15150.     specified, TinyXML-2 will assume 'xml' points to a
  15151.     null terminated string.
  15152. */
  15153. XMLError Parse( const char* xml, size_t nBytes = (size_t)(-1));
  15154.  
  15155. /**
  15156.     Load an XML file from disk.
  15157.     Returns XML_NO_ERROR (0) on success, or
  15158.     an errorID.
  15159. */
  15160. XMLError LoadFile( const char* filename);
  15161.  
  15162. /**
  15163.     Load an XML file from disk. You are responsible
  15164.     for providing and closing the FILE*.
  15165.  
  15166.     NOTE: The file should be opened as binary ("rb")
  15167.     not text in order for TinyXML-2 to correctly
  15168.     do newline normalization.
  15169.  
  15170.     Returns XML_NO_ERROR (0) on success, or
  15171.     an errorID.
  15172. */
  15173. XMLError LoadFile(FILE* );
  15174.  
  15175. /**
  15176.     Save the XML file to disk.
  15177.     Returns XML_NO_ERROR (0) on success, or
  15178.     an errorID.
  15179. */
  15180. XMLError SaveFile( const char* filename, bool compact = false);
  15181.  
  15182. /**
  15183.     Save the XML file to disk. You are responsible
  15184.     for providing and closing the FILE*.
  15185.  
  15186.     Returns XML_NO_ERROR (0) on success, or
  15187.     an errorID.
  15188. */
  15189. XMLError SaveFile(FILE* fp, bool compact = false);
  15190.  
  15191. bool ProcessEntities() const        {
  15192.         return _processEntities;
  15193.     }
  15194.     Whitespace WhitespaceMode() const   {
  15195.         return _whitespace;
  15196.     }
  15197.  
  15198.     /**
  15199.         Returns true if this document has a leading Byte Order Mark of UTF8.
  15200.     */
  15201.     bool HasBOM() const {
  15202.         return _writeBOM;
  15203.     }
  15204.     /** Sets whether to write the BOM when writing the file.
  15205.     */
  15206.     void SetBOM(bool useBOM)
  15207. {
  15208.     _writeBOM = useBOM;
  15209. }
  15210.  
  15211. /** Return the root element of DOM. Equivalent to FirstChildElement().
  15212.     To get the first node, use FirstChild().
  15213. */
  15214. XMLElement* RootElement()
  15215. {
  15216.     return FirstChildElement();
  15217. }
  15218. const XMLElement* RootElement() const   {
  15219.         return FirstChildElement();
  15220.     }
  15221.  
  15222.     /** Print the Document. If the Printer is not provided, it will
  15223.         print to stdout. If you provide Printer, this can print to a file:
  15224.         @verbatim
  15225.         XMLPrinter printer( fp );
  15226.         doc.Print( &printer );
  15227.         @endverbatim
  15228.  
  15229.         Or you can use a printer to print to memory:
  15230.         @verbatim
  15231.         XMLPrinter printer;
  15232.         doc.Print( &printer );
  15233.         // printer.CStr() has a const char* to the XML
  15234.         @endverbatim
  15235.     */
  15236.     void Print(XMLPrinter* streamer = 0) const;
  15237. virtual bool Accept(XMLVisitor* visitor) const;
  15238.  
  15239. /**
  15240.     Create a new Element associated with
  15241.     this Document. The memory for the Element
  15242.     is managed by the Document.
  15243. */
  15244. XMLElement* NewElement( const char* name);
  15245. /**
  15246.     Create a new Comment associated with
  15247.     this Document. The memory for the Comment
  15248.     is managed by the Document.
  15249. */
  15250. XMLComment* NewComment( const char* comment);
  15251. /**
  15252.     Create a new Text associated with
  15253.     this Document. The memory for the Text
  15254.     is managed by the Document.
  15255. */
  15256. XMLText* NewText( const char* text);
  15257. /**
  15258.     Create a new Declaration associated with
  15259.     this Document. The memory for the object
  15260.     is managed by the Document.
  15261.  
  15262.     If the 'text' param is null, the standard
  15263.     declaration is used.:
  15264.     @verbatim
  15265.         <?xml version="1.0" encoding="UTF-8"?>
  15266.     @endverbatim
  15267. */
  15268. XMLDeclaration* NewDeclaration( const char* text = 0);
  15269. /**
  15270.     Create a new Unknown associated with
  15271.     this Document. The memory for the object
  15272.     is managed by the Document.
  15273. */
  15274. XMLUnknown* NewUnknown( const char* text);
  15275.  
  15276. /**
  15277.     Delete a node associated with this document.
  15278.     It will be unlinked from the DOM.
  15279. */
  15280. void DeleteNode(XMLNode* node);
  15281.  
  15282. void SetError(XMLError error, const char* str1, const char* str2);
  15283.  
  15284. /// Return true if there was an error parsing the document.
  15285. bool Error() const {
  15286.         return _errorID != XML_NO_ERROR;
  15287.     }
  15288.     /// Return the errorID.
  15289.     XMLError ErrorID() const {
  15290.         return _errorID;
  15291.     }
  15292.         const char* ErrorName() const;
  15293.  
  15294. /// Return a possibly helpful diagnostic location or string.
  15295. const char* GetErrorStr1() const {
  15296.         return _errorStr1;
  15297.     }
  15298.     /// Return a possibly helpful secondary diagnostic location or string.
  15299.     const char* GetErrorStr2() const {
  15300.         return _errorStr2;
  15301.     }
  15302.     /// If there is an error, print it to stdout.
  15303.     void PrintError() const;
  15304.  
  15305. /// Clear the document, resetting it to the initial state.
  15306. void Clear();
  15307.  
  15308. // internal
  15309. char* Identify(char* p, XMLNode** node);
  15310.  
  15311. virtual XMLNode* ShallowClone(XMLDocument* /*document*/ ) const    {
  15312.         return 0;
  15313.     }
  15314.     virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const   {
  15315.         return false;
  15316.     }
  15317.  
  15318. private:
  15319.     XMLDocument( const XMLDocument& );  // not supported
  15320. void operator=( const XMLDocument& );   // not supported
  15321.  
  15322. bool _writeBOM;
  15323. bool _processEntities;
  15324. XMLError _errorID;
  15325. Whitespace _whitespace;
  15326. const char* _errorStr1;
  15327. const char* _errorStr2;
  15328. char* _charBuffer;
  15329.  
  15330. MemPoolT< sizeof(XMLElement) >   _elementPool;
  15331.     MemPoolT< sizeof(XMLAttribute) > _attributePool;
  15332.     MemPoolT< sizeof(XMLText) >          _textPool;
  15333.     MemPoolT< sizeof(XMLComment) >       _commentPool;
  15334.  
  15335.         static const char* _errorNames[XML_ERROR_COUNT];
  15336.  
  15337. void Parse();
  15338. };
  15339.  
  15340.  
  15341. /**
  15342.         A XMLHandle is a class that wraps a node pointer with null checks; this is
  15343.         an incredibly useful thing. Note that XMLHandle is not part of the TinyXML-2
  15344.         DOM structure. It is a separate utility class.
  15345.  
  15346.         Take an example:
  15347.         @verbatim
  15348.         <Document>
  15349.                 <Element attributeA = "valueA">
  15350.                         <Child attributeB = "value1" />
  15351.                         <Child attributeB = "value2" />
  15352.                 </Element>
  15353.         </Document>
  15354.         @endverbatim
  15355.  
  15356.         Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
  15357.         easy to write a *lot* of code that looks like:
  15358.  
  15359.         @verbatim
  15360.         XMLElement* root = document.FirstChildElement( "Document" );
  15361.         if ( root )
  15362.         {
  15363.                 XMLElement* element = root->FirstChildElement( "Element" );
  15364.                 if ( element )
  15365.                 {
  15366.                         XMLElement* child = element->FirstChildElement( "Child" );
  15367.                         if ( child )
  15368.                         {
  15369.                                 XMLElement* child2 = child->NextSiblingElement( "Child" );
  15370.                                 if ( child2 )
  15371.                                 {
  15372.                                         // Finally do something useful.
  15373.         @endverbatim
  15374.  
  15375.         And that doesn't even cover "else" cases. XMLHandle addresses the verbosity
  15376.         of such code. A XMLHandle checks for null pointers so it is perfectly safe
  15377.         and correct to use:
  15378.  
  15379.         @verbatim
  15380.         XMLHandle docHandle( &document );
  15381.         XMLElement* child2 = docHandle.FirstChildElement( "Document" ).FirstChildElement( "Element" ).FirstChildElement().NextSiblingElement();
  15382.         if ( child2 )
  15383.         {
  15384.                 // do something useful
  15385.         @endverbatim
  15386.  
  15387.         Which is MUCH more concise and useful.
  15388.  
  15389.         It is also safe to copy handles - internally they are nothing more than node pointers.
  15390.         @verbatim
  15391.         XMLHandle handleCopy = handle;
  15392.         @endverbatim
  15393.  
  15394.         See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects.
  15395. */
  15396. class TINYXML2_LIB XMLHandle
  15397. {
  15398. public:
  15399.     /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
  15400.     XMLHandle(XMLNode* node)
  15401. {
  15402.     _node = node;
  15403. }
  15404.     /// Create a handle from a node.
  15405.     XMLHandle(XMLNode& node )
  15406. {
  15407.     _node = &node;
  15408. }
  15409.     /// Copy constructor
  15410.     XMLHandle( const XMLHandle& ref )
  15411. {
  15412.     _node = ref._node;
  15413. }
  15414. /// Assignment
  15415. XMLHandle& operator=( const XMLHandle& ref )
  15416. {
  15417.     _node = ref._node;
  15418.     return *this;
  15419. }
  15420.  
  15421. /// Get the first child of this handle.
  15422. XMLHandle FirstChild()
  15423. {
  15424.     return XMLHandle(_node ? _node->FirstChild() : 0);
  15425. }
  15426. /// Get the first child element of this handle.
  15427. XMLHandle FirstChildElement( const char* name = 0)
  15428. {
  15429.     return XMLHandle(_node ? _node->FirstChildElement(name) : 0);
  15430. }
  15431. /// Get the last child of this handle.
  15432. XMLHandle LastChild()
  15433. {
  15434.     return XMLHandle(_node ? _node->LastChild() : 0);
  15435. }
  15436. /// Get the last child element of this handle.
  15437. XMLHandle LastChildElement( const char* name = 0)
  15438. {
  15439.     return XMLHandle(_node ? _node->LastChildElement(name) : 0);
  15440. }
  15441. /// Get the previous sibling of this handle.
  15442. XMLHandle PreviousSibling()
  15443. {
  15444.     return XMLHandle(_node ? _node->PreviousSibling() : 0);
  15445. }
  15446. /// Get the previous sibling element of this handle.
  15447. XMLHandle PreviousSiblingElement( const char* name = 0)
  15448. {
  15449.     return XMLHandle(_node ? _node->PreviousSiblingElement(name) : 0);
  15450. }
  15451. /// Get the next sibling of this handle.
  15452. XMLHandle NextSibling()
  15453. {
  15454.     return XMLHandle(_node ? _node->NextSibling() : 0);
  15455. }
  15456. /// Get the next sibling element of this handle.
  15457. XMLHandle NextSiblingElement( const char* name = 0)
  15458. {
  15459.     return XMLHandle(_node ? _node->NextSiblingElement(name) : 0);
  15460. }
  15461.  
  15462. /// Safe cast to XMLNode. This can return null.
  15463. XMLNode* ToNode()
  15464. {
  15465.     return _node;
  15466. }
  15467. /// Safe cast to XMLElement. This can return null.
  15468. XMLElement* ToElement()
  15469. {
  15470.     return ((_node == 0) ? 0 : _node->ToElement());
  15471. }
  15472. /// Safe cast to XMLText. This can return null.
  15473. XMLText* ToText()
  15474. {
  15475.     return ((_node == 0) ? 0 : _node->ToText());
  15476. }
  15477. /// Safe cast to XMLUnknown. This can return null.
  15478. XMLUnknown* ToUnknown()
  15479. {
  15480.     return ((_node == 0) ? 0 : _node->ToUnknown());
  15481. }
  15482. /// Safe cast to XMLDeclaration. This can return null.
  15483. XMLDeclaration* ToDeclaration()
  15484. {
  15485.     return ((_node == 0) ? 0 : _node->ToDeclaration());
  15486. }
  15487.  
  15488. private:
  15489.     XMLNode* _node;
  15490. };
  15491.  
  15492.  
  15493. /**
  15494.         A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the
  15495.         same in all regards, except for the 'const' qualifiers. See XMLHandle for API.
  15496. */
  15497. class TINYXML2_LIB XMLConstHandle
  15498. {
  15499. public:
  15500.     XMLConstHandle( const XMLNode* node)
  15501. {
  15502.     _node = node;
  15503. }
  15504.     XMLConstHandle( const XMLNode& node )
  15505. {
  15506.     _node = &node;
  15507. }
  15508.     XMLConstHandle( const XMLConstHandle& ref )
  15509. {
  15510.     _node = ref._node;
  15511. }
  15512.  
  15513. XMLConstHandle& operator=( const XMLConstHandle& ref )
  15514. {
  15515.     _node = ref._node;
  15516.     return *this;
  15517. }
  15518.  
  15519. const XMLConstHandle FirstChild() const                                                                                 {
  15520.         return XMLConstHandle(_node ? _node->FirstChild() : 0);
  15521.     }
  15522.     const XMLConstHandle FirstChildElement( const char * name = 0 ) const                {
  15523.         return XMLConstHandle(_node? _node->FirstChildElement( name ) : 0 );
  15524.     }
  15525.     const XMLConstHandle LastChild()    const                                                                           {
  15526.         return XMLConstHandle(_node ? _node->LastChild() : 0);
  15527.     }
  15528.     const XMLConstHandle LastChildElement( const char * name = 0 ) const             {
  15529.         return XMLConstHandle(_node? _node->LastChildElement( name ) : 0 );
  15530.     }
  15531.     const XMLConstHandle PreviousSibling() const                                                                        {
  15532.         return XMLConstHandle(_node ? _node->PreviousSibling() : 0);
  15533.     }
  15534.     const XMLConstHandle PreviousSiblingElement( const char * name = 0 ) const       {
  15535.         return XMLConstHandle(_node? _node->PreviousSiblingElement( name ) : 0 );
  15536.     }
  15537.     const XMLConstHandle NextSibling() const                                                                            {
  15538.         return XMLConstHandle(_node ? _node->NextSibling() : 0);
  15539.     }
  15540.     const XMLConstHandle NextSiblingElement( const char * name = 0 ) const           {
  15541.         return XMLConstHandle(_node? _node->NextSiblingElement( name ) : 0 );
  15542.     }
  15543.  
  15544.  
  15545.     const XMLNode* ToNode() const                               {
  15546.         return _node;
  15547.     }
  15548.     const XMLElement* ToElement() const                 {
  15549.         return ((_node == 0) ? 0 : _node->ToElement());
  15550.     }
  15551.     const XMLText* ToText() const                               {
  15552.         return ((_node == 0) ? 0 : _node->ToText());
  15553.     }
  15554.     const XMLUnknown* ToUnknown() const                 {
  15555.         return ((_node == 0) ? 0 : _node->ToUnknown());
  15556.     }
  15557.     const XMLDeclaration* ToDeclaration() const {
  15558.         return ((_node == 0) ? 0 : _node->ToDeclaration());
  15559.     }
  15560.  
  15561. private:
  15562.     const XMLNode* _node;
  15563. };
  15564.  
  15565.  
  15566. /**
  15567.         Printing functionality. The XMLPrinter gives you more
  15568.         options than the XMLDocument::Print() method.
  15569.  
  15570.         It can:
  15571.         -# Print to memory.
  15572.         -# Print to a file you provide.
  15573.         -# Print XML without a XMLDocument.
  15574.  
  15575.         Print to Memory
  15576.  
  15577.         @verbatim
  15578.         XMLPrinter printer;
  15579.         doc.Print( &printer );
  15580.         SomeFunction( printer.CStr() );
  15581.         @endverbatim
  15582.  
  15583.         Print to a File
  15584.  
  15585.         You provide the file pointer.
  15586.         @verbatim
  15587.         XMLPrinter printer( fp );
  15588.         doc.Print( &printer );
  15589.         @endverbatim
  15590.  
  15591.         Print without a XMLDocument
  15592.  
  15593.         When loading, an XML parser is very useful. However, sometimes
  15594.         when saving, it just gets in the way. The code is often set up
  15595.         for streaming, and constructing the DOM is just overhead.
  15596.  
  15597.         The Printer supports the streaming case. The following code
  15598.         prints out a trivially simple XML file without ever creating
  15599.         an XML document.
  15600.  
  15601.         @verbatim
  15602.         XMLPrinter printer( fp );
  15603.         printer.OpenElement( "foo" );
  15604.         printer.PushAttribute( "foo", "bar" );
  15605.         printer.CloseElement();
  15606.         @endverbatim
  15607. */
  15608. class TINYXML2_LIB XMLPrinter : public XMLVisitor
  15609. {
  15610. public:
  15611.     /** Construct the printer. If the FILE* is specified,
  15612.         this will print to the FILE. Else it will print
  15613.         to memory, and the result is available in CStr().
  15614.         If 'compact' is set to true, then output is created
  15615.         with only required whitespace and newlines.
  15616.     */
  15617.     XMLPrinter(FILE* file = 0, bool compact = false, int depth = 0);
  15618. virtual ~XMLPrinter() { }
  15619.  
  15620. /** If streaming, write the BOM and declaration. */
  15621. void PushHeader(bool writeBOM, bool writeDeclaration);
  15622. /** If streaming, start writing an element.
  15623.     The element must be closed with CloseElement()
  15624. */
  15625. void OpenElement( const char* name, bool compactMode = false);
  15626. /// If streaming, add an attribute to an open element.
  15627. void PushAttribute( const char* name, const char* value);
  15628. void PushAttribute( const char* name, int value);
  15629. void PushAttribute( const char* name, unsigned value);
  15630. void PushAttribute( const char* name, bool value);
  15631. void PushAttribute( const char* name, double value);
  15632. /// If streaming, close the Element.
  15633. virtual void CloseElement(bool compactMode = false);
  15634.  
  15635. /// Add a text node.
  15636. void PushText( const char* text, bool cdata = false);
  15637. /// Add a text node from an integer.
  15638. void PushText(int value);
  15639. /// Add a text node from an unsigned.
  15640. void PushText(unsigned value);
  15641. /// Add a text node from a bool.
  15642. void PushText(bool value);
  15643. /// Add a text node from a float.
  15644. void PushText(float value);
  15645. /// Add a text node from a double.
  15646. void PushText(double value);
  15647.  
  15648. /// Add a comment
  15649. void PushComment( const char* comment);
  15650.  
  15651. void PushDeclaration( const char* value);
  15652. void PushUnknown( const char* value);
  15653.  
  15654. virtual bool VisitEnter( const XMLDocument& /*doc*/ );
  15655. virtual bool VisitExit( const XMLDocument& /*doc*/ )
  15656. {
  15657.     return true;
  15658. }
  15659.  
  15660. virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute);
  15661. virtual bool VisitExit( const XMLElement& element );
  15662.  
  15663. virtual bool Visit( const XMLText& text );
  15664. virtual bool Visit( const XMLComment& comment );
  15665. virtual bool Visit( const XMLDeclaration& declaration );
  15666. virtual bool Visit( const XMLUnknown& unknown );
  15667.  
  15668. /**
  15669.     If in print to memory mode, return a pointer to
  15670.     the XML file in memory.
  15671. */
  15672. const char* CStr() const {
  15673.         return _buffer.Mem();
  15674.     }
  15675.     /**
  15676.         If in print to memory mode, return the size
  15677.         of the XML file in memory. (Note the size returned
  15678.         includes the terminating null.)
  15679.     */
  15680.     int CStrSize() const {
  15681.         return _buffer.Size();
  15682.     }
  15683.     /**
  15684.         If in print to memory mode, reset the buffer to the
  15685.         beginning.
  15686.     */
  15687.     void ClearBuffer()
  15688. {
  15689.     _buffer.Clear();
  15690.     _buffer.Push(0);
  15691. }
  15692.  
  15693. protected:
  15694.         virtual bool CompactMode( const XMLElement& ) { return _compactMode; }
  15695.  
  15696. /** Prints out the space before an element. You may override to change
  15697.     the space and tabs used. A PrintSpace() override should call Print().
  15698. */
  15699. virtual void PrintSpace(int depth);
  15700. void Print( const char* format, ... );
  15701.  
  15702. void SealElementIfJustOpened();
  15703. bool _elementJustOpened;
  15704. DynArray< const char*, 10 > _stack;
  15705.  
  15706. private:
  15707.     void PrintString( const char*, bool restrictedEntitySet);   // prints out, after detecting entities.
  15708.  
  15709. bool _firstElement;
  15710. FILE* _fp;
  15711. int _depth;
  15712. int _textDepth;
  15713. bool _processEntities;
  15714. bool _compactMode;
  15715.  
  15716. enum {
  15717.     ENTITY_RANGE = 64,
  15718.     BUF_SIZE = 200
  15719. };
  15720. bool _entityFlag[ENTITY_RANGE];
  15721. bool _restrictedEntityFlag[ENTITY_RANGE];
  15722.  
  15723. DynArray<char, 20 > _buffer;
  15724. };
  15725.  
  15726.  
  15727. }       // tinyxml2
  15728.  
  15729. #if defined(_MSC_VER)
  15730. #   pragma warning(pop)
  15731. #endif
  15732.  
  15733. #endif TINYXML2_INCLUDED
  15734. /*
  15735. Syn's AYYWAREFramework 2015
  15736. */
  15737.  
  15738. #include "UTIL Functions.h"
  15739. #include "Utilities.h"
  15740.  
  15741. #include "RenderManager.h"
  15742.  
  15743. void UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask,
  15744.         const IClientEntity* ignore, int collisionGroup, trace_t* ptr)
  15745. {
  15746.     typedef int(__fastcall * UTIL_TraceLine_t)(const Vector&, const Vector&, unsigned int, const IClientEntity*, int, trace_t*);
  15747.     static UTIL_TraceLine_t TraceLine = (UTIL_TraceLine_t)Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x55\x8B\xEC\x83\xE4\xF0\x83\xEC\x7C\x56\x52", "xxxxxxxxxxx");
  15748.     TraceLine(vecAbsStart, vecAbsEnd, mask, ignore, collisionGroup, ptr);
  15749. }
  15750.  
  15751. void UTIL_ClipTraceToPlayers(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, ITraceFilter* filter, trace_t* tr)
  15752. {
  15753.     static DWORD dwAddress = Utilities::Memory::FindPattern("client.dll", (BYTE*)"\x53\x8B\xDC\x83\xEC\x08\x83\xE4\xF0\x83\xC4\x04\x55\x8B\x6B\x04\x89\x6C\x24\x04\x8B\xEC\x81\xEC\x00\x00\x00\x00\x8B\x43\x10", "xxxxxxxxxxxxxxxxxxxxxxxx????xxx");
  15754.  
  15755.     if (!dwAddress)
  15756.         return;
  15757.  
  15758.     _asm
  15759.  
  15760.     {
  15761.         MOV EAX, filter
  15762.  
  15763.             LEA ECX, tr
  15764.  
  15765.             PUSH ECX
  15766.  
  15767.             PUSH EAX
  15768.  
  15769.             PUSH mask
  15770.  
  15771.             LEA EDX, vecAbsEnd
  15772.  
  15773.             LEA ECX, vecAbsStart
  15774.  
  15775.             CALL dwAddress
  15776.  
  15777.             ADD ESP, 0xC
  15778.  
  15779.     }
  15780. }
  15781.  
  15782. bool IsBreakableEntity(IClientEntity* ent)
  15783. {
  15784.     typedef bool(__thiscall * IsBreakbaleEntity_t)(IClientEntity *);
  15785.     IsBreakbaleEntity_t IsBreakbaleEntityFn = (IsBreakbaleEntity_t)Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x55\x8B\xEC\x51\x56\x8B\xF1\x85\xF6\x74\x68", "xxxxxxxxxxx");
  15786.     if (IsBreakbaleEntityFn)
  15787.         return IsBreakbaleEntityFn(ent);
  15788.     else
  15789.         return false;
  15790. }
  15791.  
  15792. bool TraceToExit(Vector& end, trace_t& tr, Vector start, Vector vEnd, trace_t* trace)
  15793. {
  15794.     typedef bool(__fastcall * TraceToExitFn)(Vector &, trace_t &, float, float, float, float, float, float, trace_t *);
  15795.     static TraceToExitFn TraceToExit = (TraceToExitFn)Utilities::Memory::FindPattern("client.dll", (BYTE*)"\x55\x8B\xEC\x83\xEC\x2C\xF3\x0F\x10\x75\x00\x33\xC0", "xxxxxxxxxx?xx");
  15796.  
  15797.     if (!TraceToExit)
  15798.         return false;
  15799.  
  15800.     return TraceToExit(end, tr, start.x, start.y, start.z, vEnd.x, vEnd.y, vEnd.z, trace);
  15801. }
  15802.  
  15803. void GameUtils::NormaliseViewAngle(Vector &angle)
  15804. {
  15805.     while (angle.y <= -180) angle.y += 360;
  15806.     while (angle.y > 180) angle.y -= 360;
  15807.     while (angle.x <= -180) angle.x += 360;
  15808.     while (angle.x > 180) angle.x -= 360;
  15809.  
  15810.  
  15811.     if (angle.x > 89.0) angle.x = 89;
  15812.     if (angle.x < -89.0) angle.x = -89;
  15813.     if (angle.y < -180) angle.y = -179.999;
  15814.     if (angle.y > 180) angle.y = 179.999;
  15815.  
  15816.     angle.z = 0;
  15817. }
  15818.  
  15819. void GameUtils::CL_FixMove(CUserCmd* pCmd, Vector viewangles)
  15820. {
  15821.     /*pCmd->forwardmove = DotProduct(forward * vForwardNorm, aimforward) + DotProduct(right * vRightNorm, aimforward) + DotProduct(up * vUpNorm, aimforward);
  15822.         pCmd->sidemove = DotProduct(forward * vForwardNorm, aimright) + DotProduct(right * vRightNorm, aimright) + DotProduct(up * vUpNorm, aimright);
  15823.         pCmd->upmove = DotProduct(forward * vForwardNorm, aimup) + DotProduct(right * vRightNorm, aimup) + DotProduct(up * vUpNorm, aimup);*/
  15824. }
  15825.  
  15826. char shit[16];
  15827. trace_t Trace;
  15828. char shit2[16];
  15829. IClientEntity* entCopy;
  15830.  
  15831. bool GameUtils::IsVisible(IClientEntity* pLocal, IClientEntity* pEntity, int BoneID)
  15832. {
  15833.     if (BoneID < 0) return false;
  15834.  
  15835.     entCopy = pEntity;
  15836.     Vector start = pLocal->GetOrigin() + pLocal->GetViewOffset();
  15837.     Vector end = GetHitboxPosition(pEntity, BoneID);//pEntity->GetBonePos(BoneID);
  15838.     char shit3[32];
  15839.  
  15840.     //Interfaces::Trace->TraceRay(Ray,MASK_SOLID, NULL/*&filter*/, &Trace);
  15841.     UTIL_TraceLine(start, end, MASK_SOLID, pLocal, 0, &Trace);
  15842.  
  15843.     if (Trace.m_pEnt == entCopy)
  15844.     {
  15845.         return true;
  15846.     }
  15847.  
  15848.     if (Trace.fraction == 1.0f)
  15849.     {
  15850.         return true;
  15851.     }
  15852.  
  15853.     return false;
  15854.  
  15855. }
  15856.  
  15857. bool GameUtils::IsBallisticWeapon(void* weapon)
  15858. {
  15859.     if (weapon == nullptr) return false;
  15860.     IClientEntity* weaponEnt = (IClientEntity*)weapon;
  15861.     ClientClass* pWeaponClass = weaponEnt->GetClientClass();
  15862.  
  15863.     if (pWeaponClass->m_ClassID == (int)CSGOClassID::CKnife || pWeaponClass->m_ClassID == (int)CSGOClassID::CHEGrenade || pWeaponClass->m_ClassID == (int)CSGOClassID::CDecoyGrenade || pWeaponClass->m_ClassID == (int)CSGOClassID::CIncendiaryGrenade || pWeaponClass->m_ClassID == (int)CSGOClassID::CSmokeGrenade || pWeaponClass->m_ClassID == (int)CSGOClassID::CC4)
  15864.         return false;
  15865.     else
  15866.         return true;
  15867. }
  15868.  
  15869. bool GameUtils::IsPistol(void* weapon)
  15870. {
  15871.     if (weapon == nullptr) return false;
  15872.     IClientEntity* weaponEnt = (IClientEntity*)weapon;
  15873.     ClientClass* pWeaponClass = weaponEnt->GetClientClass();
  15874.  
  15875.     if (pWeaponClass->m_ClassID == (int)CSGOClassID::CDEagle || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponElite || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponFiveSeven || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponGlock || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponHKP2000 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponP250 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponP228 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponTec9 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponUSP)
  15876.         return true;
  15877.     else
  15878.         return false;
  15879. }
  15880.  
  15881. bool GameUtils::IsSniper(void* weapon)
  15882. {
  15883.     if (weapon == nullptr) return false;
  15884.     IClientEntity* weaponEnt = (IClientEntity*)weapon;
  15885.     ClientClass* pWeaponClass = weaponEnt->GetClientClass();
  15886.  
  15887.     if (pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponAWP || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponSSG08 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponSCAR20 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponG3SG1)
  15888.         return true;
  15889.     else
  15890.         return false;
  15891. }
  15892.  
  15893. void SayInChat(const char* text)
  15894. {
  15895.     char buffer[250];
  15896.     sprintf_s(buffer, "say \"%s\"", text);
  15897.     Interfaces::Engine->ClientCmd_Unrestricted(buffer);
  15898. }
  15899.  
  15900. Vector GetHitboxPosition(IClientEntity* pEntity, int Hitbox)
  15901. {
  15902.     matrix3x4 matrix[128];
  15903.  
  15904.     if (!pEntity->SetupBones(matrix, 128, 0x00000100, GetTickCount64()))
  15905.         return Vector(0, 0, 0);
  15906.  
  15907.     studiohdr_t* hdr = Interfaces::ModelInfo->GetStudiomodel(pEntity->GetModel());
  15908.     mstudiohitboxset_t* set = hdr->GetHitboxSet(0);
  15909.  
  15910.     mstudiobbox_t* hitbox = set->GetHitbox(Hitbox);
  15911.  
  15912.     if (!hitbox)
  15913.         return Vector(0, 0, 0);
  15914.  
  15915.     Vector vMin, vMax, vCenter, sCenter;
  15916.     VectorTransform(hitbox->bbmin, matrix[hitbox->bone], vMin);
  15917.     VectorTransform(hitbox->bbmax, matrix[hitbox->bone], vMax);
  15918.     vCenter = (vMin + vMax) * 0.5f;
  15919.     return vCenter;
  15920. }
  15921.  
  15922. int GameUtils::GetPlayerCompRank(IClientEntity* pEntity)
  15923. {
  15924.     static DWORD m_iCompetitiveRanking = NetVar.GetNetVar(0x75671F7F);
  15925.     static DWORD GameResources = *(DWORD*)(Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x8B\x3D\x00\x00\x00\x00\x85\xFF\x0F\x84\x00\x00\x00\x00\x81\xC7", "xx????xxxx????xx") + 0x2);
  15926.  
  15927.     return *(int*)((DWORD)GameResources + m_iCompetitiveRanking + (int)pEntity->GetIndex() * 4);
  15928. }
  15929.  
  15930. void ForceUpdate()
  15931. {
  15932.     // Shh
  15933.     static DWORD clientstateaddr = Utilities::Memory::FindPattern("engine.dll", (PBYTE)"\x8B\x3D\x00\x00\x00\x00\x8A\xF9\xF3\x0F\x11\x45\xF8\x83\xBF\xE8\x00\x00\x00\x02", "xx????xxxxxxxxxxxxxx");
  15934.     static uintptr_t pEngineBase = (uintptr_t)GetModuleHandleA("engine.dll");
  15935.  
  15936.     static uintptr_t pClientState = **(uintptr_t**)(Utilities::Memory::FindPattern("engine.dll", (PBYTE)"\x8B\x3D\x00\x00\x00\x00\x8A\xF9", "xx????xx") + 2);
  15937.  
  15938.     static uintptr_t dwAddr1 = Utilities::Memory::FindPattern("engine.dll", (PBYTE)"\xE8\x00\x00\x00\x00\x68\x00\x00\x00\x00\x68\x00\x00\x00\x00\xC7\x87\x00\x00\x00\x00\x00\x00\x00\x00", "x????x????x????xx????????");
  15939.  
  15940.     //E8 call is being used here
  15941.     static uintptr_t dwRelAddr = *(uintptr_t*)(dwAddr1 + 1);
  15942.     static uintptr_t sub_B5E60 = ((dwAddr1 + 5) + dwRelAddr);
  15943.  
  15944.     __asm
  15945.  
  15946.     {
  15947.         pushad
  15948.         mov edi, pClientState
  15949.         lea ecx, dword ptr[edi + 0x8]
  15950.  
  15951.         call sub_B5E60
  15952.  
  15953.         mov dword ptr[edi + 0x154], 0xFFFFFFFF
  15954.  
  15955.         popad
  15956.  
  15957.     }
  15958. }/*
  15959. Syn's AYYWAREFramework 2015
  15960. */
  15961.  
  15962. #include "UTIL Functions.h"
  15963. #include "Utilities.h"
  15964.  
  15965. #include "RenderManager.h"
  15966.  
  15967. void UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask,
  15968.         const IClientEntity* ignore, int collisionGroup, trace_t* ptr)
  15969. {
  15970.     typedef int(__fastcall * UTIL_TraceLine_t)(const Vector&, const Vector&, unsigned int, const IClientEntity*, int, trace_t*);
  15971.     static UTIL_TraceLine_t TraceLine = (UTIL_TraceLine_t)Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x55\x8B\xEC\x83\xE4\xF0\x83\xEC\x7C\x56\x52", "xxxxxxxxxxx");
  15972.     TraceLine(vecAbsStart, vecAbsEnd, mask, ignore, collisionGroup, ptr);
  15973. }
  15974.  
  15975. void UTIL_ClipTraceToPlayers(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, ITraceFilter* filter, trace_t* tr)
  15976. {
  15977.     static DWORD dwAddress = Utilities::Memory::FindPattern("client.dll", (BYTE*)"\x53\x8B\xDC\x83\xEC\x08\x83\xE4\xF0\x83\xC4\x04\x55\x8B\x6B\x04\x89\x6C\x24\x04\x8B\xEC\x81\xEC\x00\x00\x00\x00\x8B\x43\x10", "xxxxxxxxxxxxxxxxxxxxxxxx????xxx");
  15978.  
  15979.     if (!dwAddress)
  15980.         return;
  15981.  
  15982.     _asm
  15983.  
  15984.     {
  15985.         MOV EAX, filter
  15986.  
  15987.             LEA ECX, tr
  15988.  
  15989.             PUSH ECX
  15990.  
  15991.             PUSH EAX
  15992.  
  15993.             PUSH mask
  15994.  
  15995.             LEA EDX, vecAbsEnd
  15996.  
  15997.             LEA ECX, vecAbsStart
  15998.  
  15999.             CALL dwAddress
  16000.  
  16001.             ADD ESP, 0xC
  16002.  
  16003.     }
  16004. }
  16005.  
  16006. bool IsBreakableEntity(IClientEntity* ent)
  16007. {
  16008.     typedef bool(__thiscall * IsBreakbaleEntity_t)(IClientEntity *);
  16009.     IsBreakbaleEntity_t IsBreakbaleEntityFn = (IsBreakbaleEntity_t)Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x55\x8B\xEC\x51\x56\x8B\xF1\x85\xF6\x74\x68", "xxxxxxxxxxx");
  16010.     if (IsBreakbaleEntityFn)
  16011.         return IsBreakbaleEntityFn(ent);
  16012.     else
  16013.         return false;
  16014. }
  16015.  
  16016. bool TraceToExit(Vector& end, trace_t& tr, Vector start, Vector vEnd, trace_t* trace)
  16017. {
  16018.     typedef bool(__fastcall * TraceToExitFn)(Vector &, trace_t &, float, float, float, float, float, float, trace_t *);
  16019.     static TraceToExitFn TraceToExit = (TraceToExitFn)Utilities::Memory::FindPattern("client.dll", (BYTE*)"\x55\x8B\xEC\x83\xEC\x2C\xF3\x0F\x10\x75\x00\x33\xC0", "xxxxxxxxxx?xx");
  16020.  
  16021.     if (!TraceToExit)
  16022.         return false;
  16023.  
  16024.     return TraceToExit(end, tr, start.x, start.y, start.z, vEnd.x, vEnd.y, vEnd.z, trace);
  16025. }
  16026.  
  16027. void GameUtils::NormaliseViewAngle(Vector &angle)
  16028. {
  16029.     while (angle.y <= -180) angle.y += 360;
  16030.     while (angle.y > 180) angle.y -= 360;
  16031.     while (angle.x <= -180) angle.x += 360;
  16032.     while (angle.x > 180) angle.x -= 360;
  16033.  
  16034.  
  16035.     if (angle.x > 89.0) angle.x = 89;
  16036.     if (angle.x < -89.0) angle.x = -89;
  16037.     if (angle.y < -180) angle.y = -179.999;
  16038.     if (angle.y > 180) angle.y = 179.999;
  16039.  
  16040.     angle.z = 0;
  16041. }
  16042.  
  16043. void GameUtils::CL_FixMove(CUserCmd* pCmd, Vector viewangles)
  16044. {
  16045.     /*pCmd->forwardmove = DotProduct(forward * vForwardNorm, aimforward) + DotProduct(right * vRightNorm, aimforward) + DotProduct(up * vUpNorm, aimforward);
  16046.         pCmd->sidemove = DotProduct(forward * vForwardNorm, aimright) + DotProduct(right * vRightNorm, aimright) + DotProduct(up * vUpNorm, aimright);
  16047.         pCmd->upmove = DotProduct(forward * vForwardNorm, aimup) + DotProduct(right * vRightNorm, aimup) + DotProduct(up * vUpNorm, aimup);*/
  16048. }
  16049.  
  16050. char shit[16];
  16051. trace_t Trace;
  16052. char shit2[16];
  16053. IClientEntity* entCopy;
  16054.  
  16055. bool GameUtils::IsVisible(IClientEntity* pLocal, IClientEntity* pEntity, int BoneID)
  16056. {
  16057.     if (BoneID < 0) return false;
  16058.  
  16059.     entCopy = pEntity;
  16060.     Vector start = pLocal->GetOrigin() + pLocal->GetViewOffset();
  16061.     Vector end = GetHitboxPosition(pEntity, BoneID);//pEntity->GetBonePos(BoneID);
  16062.     char shit3[32];
  16063.  
  16064.     //Interfaces::Trace->TraceRay(Ray,MASK_SOLID, NULL/*&filter*/, &Trace);
  16065.     UTIL_TraceLine(start, end, MASK_SOLID, pLocal, 0, &Trace);
  16066.  
  16067.     if (Trace.m_pEnt == entCopy)
  16068.     {
  16069.         return true;
  16070.     }
  16071.  
  16072.     if (Trace.fraction == 1.0f)
  16073.     {
  16074.         return true;
  16075.     }
  16076.  
  16077.     return false;
  16078.  
  16079. }
  16080.  
  16081. bool GameUtils::IsBallisticWeapon(void* weapon)
  16082. {
  16083.     if (weapon == nullptr) return false;
  16084.     IClientEntity* weaponEnt = (IClientEntity*)weapon;
  16085.     ClientClass* pWeaponClass = weaponEnt->GetClientClass();
  16086.  
  16087.     if (pWeaponClass->m_ClassID == (int)CSGOClassID::CKnife || pWeaponClass->m_ClassID == (int)CSGOClassID::CHEGrenade || pWeaponClass->m_ClassID == (int)CSGOClassID::CDecoyGrenade || pWeaponClass->m_ClassID == (int)CSGOClassID::CIncendiaryGrenade || pWeaponClass->m_ClassID == (int)CSGOClassID::CSmokeGrenade || pWeaponClass->m_ClassID == (int)CSGOClassID::CC4)
  16088.         return false;
  16089.     else
  16090.         return true;
  16091. }
  16092.  
  16093. bool GameUtils::IsPistol(void* weapon)
  16094. {
  16095.     if (weapon == nullptr) return false;
  16096.     IClientEntity* weaponEnt = (IClientEntity*)weapon;
  16097.     ClientClass* pWeaponClass = weaponEnt->GetClientClass();
  16098.  
  16099.     if (pWeaponClass->m_ClassID == (int)CSGOClassID::CDEagle || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponElite || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponFiveSeven || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponGlock || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponHKP2000 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponP250 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponP228 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponTec9 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponUSP)
  16100.         return true;
  16101.     else
  16102.         return false;
  16103. }
  16104.  
  16105. bool GameUtils::IsSniper(void* weapon)
  16106. {
  16107.     if (weapon == nullptr) return false;
  16108.     IClientEntity* weaponEnt = (IClientEntity*)weapon;
  16109.     ClientClass* pWeaponClass = weaponEnt->GetClientClass();
  16110.  
  16111.     if (pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponAWP || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponSSG08 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponSCAR20 || pWeaponClass->m_ClassID == (int)CSGOClassID::CWeaponG3SG1)
  16112.         return true;
  16113.     else
  16114.         return false;
  16115. }
  16116.  
  16117. void SayInChat(const char* text)
  16118. {
  16119.     char buffer[250];
  16120.     sprintf_s(buffer, "say \"%s\"", text);
  16121.     Interfaces::Engine->ClientCmd_Unrestricted(buffer);
  16122. }
  16123.  
  16124. Vector GetHitboxPosition(IClientEntity* pEntity, int Hitbox)
  16125. {
  16126.     matrix3x4 matrix[128];
  16127.  
  16128.     if (!pEntity->SetupBones(matrix, 128, 0x00000100, GetTickCount64()))
  16129.         return Vector(0, 0, 0);
  16130.  
  16131.     studiohdr_t* hdr = Interfaces::ModelInfo->GetStudiomodel(pEntity->GetModel());
  16132.     mstudiohitboxset_t* set = hdr->GetHitboxSet(0);
  16133.  
  16134.     mstudiobbox_t* hitbox = set->GetHitbox(Hitbox);
  16135.  
  16136.     if (!hitbox)
  16137.         return Vector(0, 0, 0);
  16138.  
  16139.     Vector vMin, vMax, vCenter, sCenter;
  16140.     VectorTransform(hitbox->bbmin, matrix[hitbox->bone], vMin);
  16141.     VectorTransform(hitbox->bbmax, matrix[hitbox->bone], vMax);
  16142.     vCenter = (vMin + vMax) * 0.5f;
  16143.     return vCenter;
  16144. }
  16145.  
  16146. int GameUtils::GetPlayerCompRank(IClientEntity* pEntity)
  16147. {
  16148.     static DWORD m_iCompetitiveRanking = NetVar.GetNetVar(0x75671F7F);
  16149.     static DWORD GameResources = *(DWORD*)(Utilities::Memory::FindPattern("client.dll", (PBYTE)"\x8B\x3D\x00\x00\x00\x00\x85\xFF\x0F\x84\x00\x00\x00\x00\x81\xC7", "xx????xxxx????xx") + 0x2);
  16150.  
  16151.     return *(int*)((DWORD)GameResources + m_iCompetitiveRanking + (int)pEntity->GetIndex() * 4);
  16152. }
  16153.  
  16154. void ForceUpdate()
  16155. {
  16156.     // Shh
  16157.     static DWORD clientstateaddr = Utilities::Memory::FindPattern("engine.dll", (PBYTE)"\x8B\x3D\x00\x00\x00\x00\x8A\xF9\xF3\x0F\x11\x45\xF8\x83\xBF\xE8\x00\x00\x00\x02", "xx????xxxxxxxxxxxxxx");
  16158.     static uintptr_t pEngineBase = (uintptr_t)GetModuleHandleA("engine.dll");
  16159.  
  16160.     static uintptr_t pClientState = **(uintptr_t**)(Utilities::Memory::FindPattern("engine.dll", (PBYTE)"\x8B\x3D\x00\x00\x00\x00\x8A\xF9", "xx????xx") + 2);
  16161.  
  16162.     static uintptr_t dwAddr1 = Utilities::Memory::FindPattern("engine.dll", (PBYTE)"\xE8\x00\x00\x00\x00\x68\x00\x00\x00\x00\x68\x00\x00\x00\x00\xC7\x87\x00\x00\x00\x00\x00\x00\x00\x00", "x????x????x????xx????????");
  16163.  
  16164.     //E8 call is being used here
  16165.     static uintptr_t dwRelAddr = *(uintptr_t*)(dwAddr1 + 1);
  16166.     static uintptr_t sub_B5E60 = ((dwAddr1 + 5) + dwRelAddr);
  16167.  
  16168.     __asm
  16169.  
  16170.     {
  16171.         pushad
  16172.         mov edi, pClientState
  16173.         lea ecx, dword ptr[edi + 0x8]
  16174.  
  16175.         call sub_B5E60
  16176.  
  16177.         mov dword ptr[edi + 0x154], 0xFFFFFFFF
  16178.  
  16179.         popad
  16180.  
  16181.     }
  16182. }/*
  16183. Syn's AYYWAREFramework 2015
  16184. */
  16185.  
  16186. #pragma once
  16187.  
  16188. #include "SDK.h"
  16189.  
  16190. namespace GameUtils
  16191. {
  16192.     void NormaliseViewAngle(Vector &angle);
  16193.     void CL_FixMove(CUserCmd* cmd, Vector viewangles);
  16194.     bool IsVisible(IClientEntity* pLocal, IClientEntity* pEntity, int BoneID);
  16195.     bool IsBallisticWeapon(void* weapon);
  16196.     bool IsPistol(void* weapon);
  16197.     bool IsSniper(void* weapon);
  16198.     int GetPlayerCompRank(IClientEntity* pEntity);
  16199. };
  16200.  
  16201. // Trace Line Memes
  16202. void UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask,
  16203.  
  16204. const IClientEntity* ignore, int collisionGroup, trace_t* ptr);
  16205.  
  16206. void UTIL_ClipTraceToPlayers(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, ITraceFilter* filter, trace_t* tr);
  16207.  
  16208. bool IsBreakableEntity(IClientEntity* ent);
  16209.  
  16210. bool TraceToExit(Vector& end, trace_t& tr, Vector start, Vector vEnd, trace_t* trace);
  16211.  
  16212. void SayInChat(const char* text);
  16213.  
  16214. Vector GetHitboxPosition(IClientEntity* pEntity, int Hitbox);
  16215.  
  16216. void ForceUpdate();
  16217. /*
  16218. Syn's AYYWAREFramework
  16219. */
  16220. #pragma once
  16221. #define _CRT_SECURE_NO_WARNINGS
  16222.  
  16223. // Includes
  16224. #include "Utilities.h"
  16225. #include <fstream>
  16226. #include <Psapi.h>
  16227.  
  16228. bool FileLog = false;
  16229. std::ofstream logFile;
  16230.  
  16231. // --------         Utilities Core           ------------ //
  16232. // Opens a debug console
  16233. void Utilities::OpenConsole(std::string Title)
  16234. {
  16235.     AllocConsole();
  16236.     freopen("CONIN$", "r", stdin);
  16237.     freopen("CONOUT$", "w", stdout);
  16238.     freopen("CONOUT$", "w", stderr);
  16239.  
  16240.     SetConsoleTitle(Title.c_str());
  16241. }
  16242.  
  16243. // Closes the debug console
  16244. void Utilities::CloseConsole()
  16245. {
  16246.     FreeConsole();
  16247. }
  16248.  
  16249. // Outputs text to the console
  16250. void Utilities::Log(const char* fmt, ...)
  16251. {
  16252.     if (!fmt) return; //if the passed string is null return
  16253.     if (strlen(fmt) < 2) return;
  16254.  
  16255.     //Set up va_list and buffer to hold the params
  16256.     va_list va_alist;
  16257.     char logBuf[256] = { 0 };
  16258.  
  16259.     //Do sprintf with the parameters
  16260.     va_start(va_alist, fmt);
  16261.     _vsnprintf(logBuf + strlen(logBuf), sizeof(logBuf) - strlen(logBuf), fmt, va_alist);
  16262.     va_end(va_alist);
  16263.  
  16264.     //Output to console
  16265.     if (logBuf[0] != '\0')
  16266.     {
  16267.         SetConsoleColor(FOREGROUND_INTENSE_GREEN);
  16268.         printf("[%s]", GetTimeString().c_str());
  16269.         SetConsoleColor(FOREGROUND_WHITE);
  16270.         printf(": %s\n", logBuf);
  16271.     }
  16272.  
  16273.     if (FileLog)
  16274.     {
  16275.         logFile << logBuf << std::endl;
  16276.     }
  16277. }
  16278.  
  16279. // Gets the current time as a string
  16280. std::string Utilities::GetTimeString()
  16281. {
  16282.     //Time related variables
  16283.     time_t current_time;
  16284.  
  16285.     struct tm * time_info;
  16286. static char timeString[10];
  16287.  
  16288.     //Get current time
  16289.     time(&current_time);
  16290. time_info = localtime(&current_time);
  16291.  
  16292.     //Get current time as string
  16293.     strftime(timeString, sizeof(timeString), "%I:%M%p", time_info);
  16294.         return timeString;
  16295. }
  16296.  
  16297. // Sets the console color for upcoming text
  16298. void Utilities::SetConsoleColor(WORD color)
  16299. {
  16300.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
  16301. }
  16302.  
  16303. // Enables writing all log calls to a file
  16304. void Utilities::EnableLogFile(std::string filename)
  16305. {
  16306.     logFile.open(filename.c_str());
  16307.     if (logFile.is_open())
  16308.         FileLog = true;
  16309. }
  16310.  
  16311.  
  16312. // --------         Utilities Memory           ------------ //
  16313.  
  16314. DWORD Utilities::Memory::WaitOnModuleHandle(std::string moduleName)
  16315. {
  16316.     DWORD ModuleHandle = NULL;
  16317.     while (!ModuleHandle)
  16318.     {
  16319.         ModuleHandle = (DWORD)GetModuleHandle(moduleName.c_str());
  16320.         if (!ModuleHandle)
  16321.             Sleep(50);
  16322.     }
  16323.     return ModuleHandle;
  16324. }
  16325.  
  16326. bool bCompare(const BYTE* Data, const BYTE* Mask, const char* szMask)
  16327. {
  16328.     for (; *szMask; ++szMask, ++Mask, ++Data)
  16329.     {
  16330.         if (*szMask == 'x' && *Mask != *Data)
  16331.         {
  16332.             return false;
  16333.         }
  16334.     }
  16335.     return (*szMask) == 0;
  16336. }
  16337.  
  16338. DWORD Utilities::Memory::FindPattern(std::string moduleName, BYTE* Mask, char* szMask)
  16339. {
  16340.     DWORD Address = WaitOnModuleHandle(moduleName.c_str());
  16341.     MODULEINFO ModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)Address, &ModInfo, sizeof(MODULEINFO));
  16342.     DWORD Length = ModInfo.SizeOfImage;
  16343.     for (DWORD c = 0; c < Length; c += 1)
  16344.     {
  16345.         if (bCompare((BYTE*)(Address + c), Mask, szMask))
  16346.         {
  16347.             return (DWORD)(Address + c);
  16348.         }
  16349.     }
  16350.     return 0;
  16351. }
  16352.  
  16353. DWORD Utilities::Memory::FindTextPattern(std::string moduleName, char* string)
  16354. {
  16355.     DWORD Address = WaitOnModuleHandle(moduleName.c_str());
  16356.     MODULEINFO ModInfo; GetModuleInformation(GetCurrentProcess(), (HMODULE)Address, &ModInfo, sizeof(MODULEINFO));
  16357.     DWORD Length = ModInfo.SizeOfImage;
  16358.  
  16359.     int len = strlen(string);
  16360.     char* szMask = new char[len + 1];
  16361.     for (int i = 0; i < len; i++)
  16362.     {
  16363.         szMask[i] = 'x';
  16364.     }
  16365.     szMask[len] = '\0';
  16366.  
  16367.     for (DWORD c = 0; c < Length; c += 1)
  16368.     {
  16369.         if (bCompare((BYTE*)(Address + c), (BYTE*)string, szMask))
  16370.         {
  16371.             return (DWORD)(Address + c);
  16372.         }
  16373.     }
  16374.     return 0;
  16375. }
  16376.  
  16377. // --------         Utilities Memory VMT Manager       ------------ //
  16378.  
  16379. bool Utilities::Memory::VMTManager::Initialise(DWORD* InstancePointer)
  16380. {
  16381.     // Store the instance pointers and such, and work out how big the table is
  16382.     Instance = InstancePointer;
  16383.     OriginalTable = (DWORD*)*InstancePointer;
  16384.     int VMTSize = MethodCount(InstancePointer);
  16385.     size_t TableBytes = VMTSize * 4;
  16386.  
  16387.     // Allocate some memory and copy the table
  16388.     CustomTable = (DWORD*)malloc(TableBytes + 8);
  16389.     if (!CustomTable) return false;
  16390.     memcpy((void*)CustomTable, (void*)OriginalTable, VMTSize * 4);
  16391.  
  16392.     // Change the pointer
  16393.     *InstancePointer = (DWORD)CustomTable;
  16394.  
  16395.     initComplete = true;
  16396.     return true;
  16397. }
  16398.  
  16399. int Utilities::Memory::VMTManager::MethodCount(DWORD* InstancePointer)
  16400. {
  16401.     DWORD* VMT = (DWORD*)*InstancePointer;
  16402.     int Index = 0;
  16403.     int Amount = 0;
  16404.     while (!IsBadCodePtr((FARPROC)VMT[Index]))
  16405.     {
  16406.         if (!IsBadCodePtr((FARPROC)VMT[Index]))
  16407.         {
  16408.             Amount++;
  16409.             Index++;
  16410.         }
  16411.     }
  16412.  
  16413.     return Amount;
  16414. }
  16415.  
  16416. DWORD Utilities::Memory::VMTManager::HookMethod(DWORD NewFunction, int Index)
  16417. {
  16418.     if (initComplete)
  16419.     {
  16420.         CustomTable[Index] = NewFunction;
  16421.         return OriginalTable[Index];
  16422.     }
  16423.     else
  16424.         return NULL;
  16425. }
  16426.  
  16427. void Utilities::Memory::VMTManager::UnhookMethod(int Index)
  16428. {
  16429.     if (initComplete)
  16430.         CustomTable[Index] = OriginalTable[Index];
  16431.     return;
  16432. }
  16433.  
  16434. void Utilities::Memory::VMTManager::RestoreOriginal()
  16435. {
  16436.     if (initComplete)
  16437.     {
  16438.         *Instance = (DWORD)OriginalTable;
  16439.     }
  16440.     return;
  16441. }
  16442.  
  16443. void Utilities::Memory::VMTManager::RestoreCustom()
  16444. {
  16445.     if (initComplete)
  16446.     {
  16447.         *Instance = (DWORD)CustomTable;
  16448.     }
  16449.     return;
  16450. }
  16451.  
  16452. DWORD Utilities::Memory::VMTManager::GetOriginalFunction(int Index)
  16453. {
  16454.     return OriginalTable[Index];
  16455. }
  16456. /*
  16457. Syn's AYYWAREFramework
  16458. */
  16459.  
  16460. #pragma once
  16461.  
  16462. // Includes
  16463. #include "CommonIncludes.h"
  16464. #include <time.h>
  16465.  
  16466. // Colors for the console
  16467. //Define extra colours
  16468. #define FOREGROUND_WHITE                    (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN)
  16469. #define FOREGROUND_YELLOW               (FOREGROUND_RED | FOREGROUND_GREEN)
  16470. #define FOREGROUND_CYAN                 (FOREGROUND_BLUE | FOREGROUND_GREEN)
  16471. #define FOREGROUND_MAGENTA              (FOREGROUND_RED | FOREGROUND_BLUE)
  16472. #define FOREGROUND_BLACK                    0
  16473.  
  16474. #define FOREGROUND_INTENSE_RED          (FOREGROUND_RED | FOREGROUND_INTENSITY)
  16475. #define FOREGROUND_INTENSE_GREEN        (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
  16476. #define FOREGROUND_INTENSE_BLUE         (FOREGROUND_BLUE | FOREGROUND_INTENSITY)
  16477. #define FOREGROUND_INTENSE_WHITE        (FOREGROUND_WHITE | FOREGROUND_INTENSITY)
  16478. #define FOREGROUND_INTENSE_YELLOW       (FOREGROUND_YELLOW | FOREGROUND_INTENSITY)
  16479. #define FOREGROUND_INTENSE_CYAN         (FOREGROUND_CYAN | FOREGROUND_INTENSITY)
  16480. #define FOREGROUND_INTENSE_MAGENTA      (FOREGROUND_MAGENTA | FOREGROUND_INTENSITY)
  16481.  
  16482. // Utilities Namespace
  16483. // Purpose: Contains misc functionality for memory related functionality
  16484. namespace Utilities
  16485. {
  16486.     // Debug console controls
  16487.     void OpenConsole(std::string Title);
  16488.     void CloseConsole();
  16489.     void Log(const char* fmt, ...);
  16490.  
  16491.     void EnableLogFile(std::string filename);
  16492.  
  16493.     void SetConsoleColor(WORD color);
  16494.  
  16495.     // Misc Shizz
  16496.     std::string GetTimeString();
  16497.  
  16498.     // Memory utils
  16499.     // Purpose: Provides memeory related functionality (pattern scanning ect)
  16500.     namespace Memory
  16501.     {
  16502.         // Waits for a module to be available, before returning it's base address
  16503.         DWORD WaitOnModuleHandle(std::string moduleName);
  16504.  
  16505.         // Attempts to locate the given signature and mask in a memory range
  16506.         // Returns the address at which it has been found
  16507.         DWORD FindPattern(std::string moduleName, BYTE* Mask, char* szMask);
  16508.  
  16509.         // Attempts to locate the given text in a memory range
  16510.         // Returns the address at which it has been found
  16511.         DWORD FindTextPattern(std::string moduleName, char* string);
  16512.  
  16513.         class VMTManager
  16514.         {
  16515.             private:
  16516.                         DWORD* CustomTable;
  16517.             bool initComplete;
  16518.             DWORD* OriginalTable;
  16519.             DWORD* Instance;
  16520.  
  16521.             int MethodCount(DWORD* InstancePointer);
  16522.  
  16523.             public:
  16524.                         bool Initialise(DWORD* InstancePointer); // Pass a &class
  16525.  
  16526.             DWORD HookMethod(DWORD NewFunction, int Index);
  16527.             void UnhookMethod(int Index);
  16528.  
  16529.             void RestoreOriginal();
  16530.             void RestoreCustom();
  16531.  
  16532.             DWORD GetOriginalFunction(int Index);
  16533.         };
  16534.     };
  16535. };
  16536.  
  16537. /*
  16538. Syn's AYYWAREFramework
  16539. */
  16540.  
  16541. #pragma once
  16542.  
  16543. // Includes
  16544. #include "CommonIncludes.h"
  16545. #include <time.h>
  16546.  
  16547. // Colors for the console
  16548. //Define extra colours
  16549. #define FOREGROUND_WHITE                    (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN)
  16550. #define FOREGROUND_YELLOW               (FOREGROUND_RED | FOREGROUND_GREEN)
  16551. #define FOREGROUND_CYAN                 (FOREGROUND_BLUE | FOREGROUND_GREEN)
  16552. #define FOREGROUND_MAGENTA              (FOREGROUND_RED | FOREGROUND_BLUE)
  16553. #define FOREGROUND_BLACK                    0
  16554.  
  16555. #define FOREGROUND_INTENSE_RED          (FOREGROUND_RED | FOREGROUND_INTENSITY)
  16556. #define FOREGROUND_INTENSE_GREEN        (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
  16557. #define FOREGROUND_INTENSE_BLUE         (FOREGROUND_BLUE | FOREGROUND_INTENSITY)
  16558. #define FOREGROUND_INTENSE_WHITE        (FOREGROUND_WHITE | FOREGROUND_INTENSITY)
  16559. #define FOREGROUND_INTENSE_YELLOW       (FOREGROUND_YELLOW | FOREGROUND_INTENSITY)
  16560. #define FOREGROUND_INTENSE_CYAN         (FOREGROUND_CYAN | FOREGROUND_INTENSITY)
  16561. #define FOREGROUND_INTENSE_MAGENTA      (FOREGROUND_MAGENTA | FOREGROUND_INTENSITY)
  16562.  
  16563. // Utilities Namespace
  16564. // Purpose: Contains misc functionality for memory related functionality
  16565. namespace Utilities
  16566. {
  16567.         // Debug console controls
  16568.         void OpenConsole(std::string Title);
  16569.         void CloseConsole();
  16570.         void Log(const char *fmt, ...);
  16571.  
  16572.         void EnableLogFile(std::string filename);
  16573.  
  16574.         void SetConsoleColor(WORD color);  
  16575.  
  16576.         // Misc Shizz
  16577.         std::string GetTimeString();
  16578.        
  16579.         // Memory utils
  16580.         // Purpose: Provides memeory related functionality (pattern scanning ect)
  16581.         namespace Memory
  16582.         {
  16583.                 // Waits for a module to be available, before returning it's base address
  16584.                 DWORD WaitOnModuleHandle(std::string moduleName);
  16585.  
  16586.                 // Attempts to locate the given signature and mask in a memory range
  16587.                 // Returns the address at which it has been found
  16588.                 DWORD FindPattern(std::string moduleName, BYTE* Mask, char* szMask);
  16589.  
  16590.                 // Attempts to locate the given text in a memory range
  16591.                 // Returns the address at which it has been found
  16592.                 DWORD FindTextPattern(std::string moduleName, char* string);
  16593.  
  16594.                 class VMTManager
  16595.                 {
  16596.                 private:
  16597.                         DWORD   *CustomTable;
  16598.                         bool    initComplete;
  16599.                         DWORD   *OriginalTable;
  16600.                         DWORD   *Instance;
  16601.  
  16602.                         int             MethodCount(DWORD* InstancePointer);
  16603.                        
  16604.                 public:
  16605.                         bool    Initialise(DWORD* InstancePointer); // Pass a &class
  16606.  
  16607.                         DWORD   HookMethod(DWORD NewFunction, int Index);
  16608.                         void    UnhookMethod(int Index);
  16609.  
  16610.                         void    RestoreOriginal();
  16611.                         void    RestoreCustom();
  16612.  
  16613.                         DWORD   GetOriginalFunction(int Index);
  16614.                 };
  16615.         };
  16616. };
  16617.  
  16618. #ifndef _VECTORZ_H
  16619. #define _VECTORZ_H
  16620.  
  16621. #define CHECK_VALID( _v ) 0
  16622. #define Assert( _exp ) ((void)0)
  16623.  
  16624. #include <Windows.h>
  16625. #include <math.h>
  16626.  
  16627. // from the leaked sdk
  16628.  
  16629. #define  FORCEINLINE                    __forceinline
  16630.  
  16631. typedef float vec_t;
  16632.  
  16633. inline vec_t BitsToFloat(unsigned long i)
  16634. {
  16635. return *reinterpret_cast<vec_t*>(&i);
  16636. }
  16637.  
  16638. #define FLOAT32_NAN_BITS     (unsigned long)0x7FC00000
  16639. #define FLOAT32_NAN          BitsToFloat( FLOAT32_NAN_BITS )
  16640.  
  16641. #define VEC_T_NAN FLOAT32_NAN
  16642.  
  16643. class Vector
  16644. {
  16645.     public:
  16646.         vec_t x, y, z;
  16647.  
  16648.     Vector(void);
  16649.     Vector(vec_t X, vec_t Y, vec_t Z);
  16650.     explicit Vector(vec_t XYZ);
  16651.  
  16652.     void Init(vec_t ix = 0.0f, vec_t iy = 0.0f, vec_t iz = 0.0f);
  16653.  
  16654.     bool IsValid() const;
  16655.     void Invalidate();
  16656.  
  16657.     vec_t operator[](int i) const;
  16658.     vec_t&  operator[](int i);
  16659.  
  16660.     vec_t* Base();
  16661.     vec_t const* Base() const;
  16662.  
  16663.     inline void Zero();
  16664.  
  16665.     bool operator ==(const Vector& v) const;
  16666.     bool operator !=(const Vector& v) const;
  16667.  
  16668.     FORCEINLINE Vector& operator+=(const Vector& v);
  16669.         FORCEINLINE Vector& operator-=(const Vector& v);
  16670.         FORCEINLINE Vector& operator*=(const Vector& v);
  16671.         FORCEINLINE Vector& operator*=(float s);
  16672.     FORCEINLINE Vector& operator/=(const Vector& v);
  16673.         FORCEINLINE Vector& operator/=(float s);
  16674.     FORCEINLINE Vector& operator+=(float fl);
  16675.     FORCEINLINE Vector& operator-=(float fl);
  16676.  
  16677.     void Negate();
  16678.  
  16679.     inline vec_t Length() const;
  16680.  
  16681.     FORCEINLINE vec_t LengthSqr(void) const
  16682.         {
  16683.                 return (x* x + y* y + z* z);
  16684. }
  16685.  
  16686. bool IsZero(float tolerance = 0.01f) const
  16687.         {
  16688.                 return (x > -tolerance && x<tolerance &&
  16689.  
  16690.             y> -tolerance && y<tolerance &&
  16691.  
  16692.            z> -tolerance && z<tolerance);
  16693.         }
  16694.  
  16695.         vec_t NormalizeInPlace();
  16696. Vector Normalized() const;
  16697.  
  16698. bool IsLengthGreaterThan(float val) const;
  16699. bool IsLengthLessThan(float val) const;
  16700.  
  16701. FORCEINLINE bool WithinAABox(Vector const &boxmin, Vector const &boxmax);
  16702.  
  16703. vec_t DistTo(const Vector& vOther) const;
  16704.  
  16705. FORCEINLINE vec_t DistToSqr(const Vector& vOther) const
  16706.         {
  16707.                 Vector delta;
  16708.  
  16709. delta.x = x - vOther.x;
  16710.                 delta.y = y - vOther.y;
  16711.                 delta.z = z - vOther.z;
  16712.  
  16713.                 return delta.LengthSqr();
  16714.         }
  16715.  
  16716.         void CopyToArray(float* rgfl) const;
  16717. void MulAdd(const Vector& a, const Vector& b, float scalar);
  16718.  
  16719. vec_t Dot(const Vector& vOther) const;
  16720.  
  16721. Vector& operator=(const Vector& vOther);
  16722.  
  16723. vec_t Length2D(void) const;
  16724. vec_t Length2DSqr(void) const;
  16725.  
  16726. Vector operator -(void) const;
  16727. Vector operator +(const Vector& v) const;
  16728. Vector operator -(const Vector& v) const;
  16729. Vector operator *(const Vector& v) const;
  16730. Vector operator /(const Vector& v) const;
  16731. Vector operator *(float fl) const;
  16732. Vector operator /(float fl) const;
  16733.  
  16734. Vector Cross(const Vector& vOther) const;
  16735.  
  16736. Vector Min(const Vector& vOther) const;
  16737. Vector Max(const Vector& vOther) const;
  16738. };
  16739.  
  16740. FORCEINLINE Vector ReplicateToVector(float x)
  16741. {
  16742.     return Vector(x, x, x);
  16743. }
  16744.  
  16745. inline Vector::Vector(void)
  16746. {
  16747.  
  16748. }
  16749.  
  16750.  
  16751.  
  16752. inline Vector::Vector(vec_t X, vec_t Y, vec_t Z)
  16753. {
  16754.     x = X; y = Y; z = Z;
  16755. }
  16756.  
  16757. inline Vector::Vector(vec_t XYZ)
  16758. {
  16759.     x = y = z = XYZ;
  16760. }
  16761.  
  16762. inline void Vector::Init(vec_t ix, vec_t iy, vec_t iz)
  16763. {
  16764.     x = ix; y = iy; z = iz;
  16765. }
  16766.  
  16767. inline void Vector::Zero()
  16768. {
  16769.     x = y = z = 0.0f;
  16770. }
  16771.  
  16772. inline void VectorClear(Vector& a)
  16773. {
  16774.     a.x = a.y = a.z = 0.0f;
  16775. }
  16776.  
  16777. inline Vector& Vector::operator=(const Vector& vOther)
  16778. {
  16779.     x = vOther.x; y = vOther.y; z = vOther.z;
  16780.     return *this;
  16781. }
  16782.  
  16783. inline vec_t& Vector::operator[](int i)
  16784. {
  16785.         return ((vec_t*)this)[i];
  16786. }
  16787.  
  16788. inline vec_t Vector::operator[](int i) const
  16789. {
  16790.         return ((vec_t*)this)[i];
  16791. }
  16792.  
  16793.  
  16794.  
  16795. inline vec_t* Vector::Base()
  16796. {
  16797.     return (vec_t*)this;
  16798. }
  16799.  
  16800. inline vec_t const* Vector::Base() const
  16801. {
  16802.         return (vec_t const*)this;
  16803. }
  16804.  
  16805. inline bool Vector::IsValid() const
  16806. {
  16807.         return (x == x && y == y && z == z);
  16808. }
  16809.  
  16810. inline void Vector::Invalidate()
  16811. {
  16812.     x = y = z = VEC_T_NAN;
  16813. }
  16814.  
  16815. inline bool Vector::operator==(const Vector& src) const
  16816. {
  16817.         return (src.x == x) && (src.y == y) && (src.z == z);
  16818. }
  16819.  
  16820. inline bool Vector::operator!=(const Vector& src) const
  16821. {
  16822.         return (src.x != x) || (src.y != y) || (src.z != z);
  16823. }
  16824.  
  16825. FORCEINLINE void VectorCopy(const Vector& src, Vector& dst)
  16826. {
  16827.     dst.x = src.x;
  16828.     dst.y = src.y;
  16829.     dst.z = src.z;
  16830. }
  16831.  
  16832. inline void Vector::CopyToArray(float* rgfl) const
  16833. {
  16834.         rgfl[0] = x; rgfl[1] = y; rgfl[2] = z;
  16835. }
  16836.  
  16837. inline void Vector::Negate()
  16838. {
  16839.     x = -x; y = -y; z = -z;
  16840. }
  16841.  
  16842. FORCEINLINE Vector& Vector::operator+=(const Vector& v)
  16843. {
  16844.     x += v.x; y += v.y; z += v.z;
  16845.     return *this;
  16846. }
  16847.  
  16848. FORCEINLINE Vector& Vector::operator-=(const Vector& v)
  16849. {
  16850.     x -= v.x; y -= v.y; z -= v.z;
  16851.     return *this;
  16852. }
  16853.  
  16854. FORCEINLINE Vector& Vector::operator*=(float fl)
  16855. {
  16856.     x *= fl;
  16857.     y *= fl;
  16858.     z *= fl;
  16859.     return *this;
  16860. }
  16861.  
  16862. FORCEINLINE Vector& Vector::operator*=(const Vector& v)
  16863. {
  16864.     x *= v.x;
  16865.     y *= v.y;
  16866.     z *= v.z;
  16867.     return *this;
  16868. }
  16869.  
  16870. FORCEINLINE Vector& Vector::operator+=(float fl)
  16871. {
  16872.     x += fl;
  16873.     y += fl;
  16874.     z += fl;
  16875.     return *this;
  16876. }
  16877.  
  16878. FORCEINLINE Vector& Vector::operator-=(float fl)
  16879. {
  16880.     x -= fl;
  16881.     y -= fl;
  16882.     z -= fl;
  16883.     return *this;
  16884. }
  16885.  
  16886. FORCEINLINE Vector& Vector::operator/=(float fl)
  16887. {
  16888.     float oofl = 1.0f / fl;
  16889.     x *= oofl;
  16890.     y *= oofl;
  16891.     z *= oofl;
  16892.     return *this;
  16893. }
  16894.  
  16895. FORCEINLINE Vector& Vector::operator/=(const Vector& v)
  16896. {
  16897.     x /= v.x;
  16898.     y /= v.y;
  16899.     z /= v.z;
  16900.     return *this;
  16901. }
  16902.  
  16903. FORCEINLINE void VectorAdd(const Vector& a, const Vector& b, Vector& c)
  16904. {
  16905.     c.x = a.x + b.x;
  16906.     c.y = a.y + b.y;
  16907.     c.z = a.z + b.z;
  16908. }
  16909.  
  16910. FORCEINLINE void VectorSubtract(const Vector& a, const Vector& b, Vector& c)
  16911. {
  16912.     c.x = a.x - b.x;
  16913.     c.y = a.y - b.y;
  16914.     c.z = a.z - b.z;
  16915. }
  16916.  
  16917. FORCEINLINE void VectorMultiply(const Vector& a, vec_t b, Vector& c)
  16918. {
  16919.     c.x = a.x * b;
  16920.     c.y = a.y * b;
  16921.     c.z = a.z * b;
  16922. }
  16923.  
  16924. FORCEINLINE void VectorMultiply(const Vector& a, const Vector& b, Vector& c)
  16925. {
  16926.     c.x = a.x * b.x;
  16927.     c.y = a.y * b.y;
  16928.     c.z = a.z * b.z;
  16929. }
  16930.  
  16931. inline void VectorScale(const Vector& in, vec_t scale, Vector& result)
  16932. {
  16933.     VectorMultiply(in, scale, result);
  16934. }
  16935.  
  16936. FORCEINLINE void VectorDivide(const Vector& a, vec_t b, Vector& c)
  16937. {
  16938.     vec_t oob = 1.0f / b;
  16939.     c.x = a.x * oob;
  16940.     c.y = a.y * oob;
  16941.     c.z = a.z * oob;
  16942. }
  16943.  
  16944. FORCEINLINE void VectorDivide(const Vector& a, const Vector& b, Vector& c)
  16945. {
  16946.     c.x = a.x / b.x;
  16947.     c.y = a.y / b.y;
  16948.     c.z = a.z / b.z;
  16949. }
  16950.  
  16951. inline void Vector::MulAdd(const Vector& a, const Vector& b, float scalar)
  16952. {
  16953.     x = a.x + b.x * scalar;
  16954.     y = a.y + b.y * scalar;
  16955.     z = a.z + b.z * scalar;
  16956. }
  16957.  
  16958. inline void VectorLerp(const Vector& src1, const Vector& src2, vec_t t, Vector& dest)
  16959. {
  16960.     dest.x = src1.x + (src2.x - src1.x) * t;
  16961.     dest.y = src1.y + (src2.y - src1.y) * t;
  16962.     dest.z = src1.z + (src2.z - src1.z) * t;
  16963. }
  16964.  
  16965. FORCEINLINE vec_t DotProduct(const Vector& a, const Vector& b)
  16966. {
  16967.     return (a.x * b.x + a.y * b.y + a.z * b.z);
  16968. }
  16969.  
  16970. inline vec_t Vector::Dot(const Vector& vOther) const
  16971. {
  16972.         return DotProduct(*this, vOther);
  16973. }
  16974.  
  16975. inline void CrossProduct(const Vector& a, const Vector& b, Vector& result)
  16976. {
  16977.     result.x = a.y * b.z - a.z * b.y;
  16978.     result.y = a.z * b.x - a.x * b.z;
  16979.     result.z = a.x * b.y - a.y * b.x;
  16980. }
  16981.  
  16982. //inline vec_t DotProductAbs(const Vector& v0, const Vector& v1)
  16983. //{
  16984. //      return abs(v0.x * v1.x) + abs(v0.y * v1.y) + abs(v0.z * v1.z);
  16985. //}
  16986.  
  16987. inline vec_t VectorLength(const Vector& v)
  16988. {
  16989.     return (vec_t)sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
  16990. }
  16991.  
  16992. inline vec_t Vector::Length(void) const
  16993. {
  16994.         return VectorLength(*this);
  16995. }
  16996.  
  16997. inline vec_t VectorNormalize(Vector& v)
  16998. {
  16999.     vec_t l = v.Length();
  17000.  
  17001.     if (l != 0.0f)
  17002.     {
  17003.         v /= l;
  17004.     }
  17005.     else
  17006.     {
  17007.         v.x = v.y = 0.0f; v.z = 1.0f;
  17008.     }
  17009.  
  17010.     return l;
  17011. }
  17012.  
  17013. FORCEINLINE float VectorNormalizer(float* v)
  17014. {
  17015.     return VectorNormalize(*(reinterpret_cast<Vector*>(v)));
  17016. }
  17017. inline vec_t Vector::NormalizeInPlace()
  17018. {
  17019.         return VectorNormalize(*this);
  17020. }
  17021.  
  17022. bool Vector::WithinAABox(Vector const &boxmin, Vector const &boxmax)
  17023. {
  17024.     return (
  17025.         (x >= boxmin.x) && (x <= boxmax.x) &&
  17026.         (y >= boxmin.y) && (y <= boxmax.y) &&
  17027.         (z >= boxmin.z) && (z <= boxmax.z)
  17028.         );
  17029. }
  17030.  
  17031. inline vec_t Vector::DistTo(const Vector& vOther) const
  17032. {
  17033.         Vector delta;
  17034.  
  17035.     VectorSubtract(*this, vOther, delta);
  17036.         return delta.Length();
  17037. }
  17038.  
  17039. inline Vector Vector::Min(const Vector& vOther) const
  17040. {
  17041.         return Vector(x<vOther.x? x : vOther.x,
  17042.         y<vOther.y? y : vOther.y,
  17043.         z<vOther.z? z : vOther.z);
  17044. }
  17045.  
  17046. inline Vector Vector::Max(const Vector& vOther) const
  17047. {
  17048.         return Vector(x > vOther.x? x : vOther.x,
  17049.         y > vOther.y? y : vOther.y,
  17050.         z > vOther.z? z : vOther.z);
  17051. }
  17052.  
  17053. inline Vector Vector::operator -(void) const
  17054. {
  17055.         return Vector(-x, -y, -z);
  17056. }
  17057.  
  17058. inline Vector Vector::operator +(const Vector& v) const
  17059. {
  17060.         Vector res;
  17061.  
  17062.     VectorAdd(*this, v, res);
  17063.         return res;
  17064. }
  17065.  
  17066. inline Vector Vector::operator -(const Vector& v) const
  17067. {
  17068.         Vector res;
  17069.  
  17070.     VectorSubtract(*this, v, res);
  17071.         return res;
  17072. }
  17073.  
  17074. inline Vector Vector::operator *(float fl) const
  17075. {
  17076.         Vector res;
  17077.  
  17078.     VectorMultiply(*this, fl, res);
  17079.         return res;
  17080. }
  17081.  
  17082. inline Vector Vector::operator *(const Vector& v) const
  17083. {
  17084.         Vector res;
  17085.  
  17086.     VectorMultiply(*this, v, res);
  17087.         return res;
  17088. }
  17089.  
  17090. inline Vector Vector::operator /(float fl) const
  17091. {
  17092.         Vector res;
  17093.  
  17094.     VectorDivide(*this, fl, res);
  17095.         return res;
  17096. }
  17097.  
  17098. inline Vector Vector::operator /(const Vector& v) const
  17099. {
  17100.         Vector res;
  17101.  
  17102.     VectorDivide(*this, v, res);
  17103.         return res;
  17104. }
  17105.  
  17106. inline Vector operator *(float fl, const Vector& v)
  17107. {
  17108.     return v * fl;
  17109. }
  17110.  
  17111. inline Vector Vector::Cross(const Vector& vOther) const
  17112. {
  17113.         Vector res;
  17114.  
  17115.     CrossProduct(*this, vOther, res);
  17116.         return res;
  17117. }
  17118.  
  17119. inline vec_t Vector::Length2D(void) const
  17120. {
  17121.         return (vec_t)::sqrtf(x* x + y* y);
  17122. }
  17123.  
  17124. inline vec_t Vector::Length2DSqr(void) const
  17125. {
  17126.         return (x* x + y* y);
  17127. }
  17128.  
  17129. inline Vector CrossProduct(const Vector& a, const Vector& b)
  17130. {
  17131.     return Vector(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
  17132. }
  17133.  
  17134. inline void VectorMin(const Vector& a, const Vector& b, Vector& result)
  17135. {
  17136.     result.x = min(a.x, b.x);
  17137.     result.y = min(a.y, b.y);
  17138.     result.z = min(a.z, b.z);
  17139. }
  17140.  
  17141. inline void VectorMax(const Vector& a, const Vector& b, Vector& result)
  17142. {
  17143.     result.x = max(a.x, b.x);
  17144.     result.y = max(a.y, b.y);
  17145.     result.z = max(a.z, b.z);
  17146. }
  17147.  
  17148.  
  17149. class VectorAligned : public Vector
  17150. {
  17151. public:
  17152.  
  17153.     VectorAligned()
  17154. {
  17155.     x = y = z = 0.0f;
  17156. }
  17157.  
  17158.  
  17159.     VectorAligned(const Vector& v)
  17160. {
  17161.     x = v.x; y = v.y; z = v.z;
  17162. }
  17163.  
  17164. float w;
  17165. };
  17166.  
  17167.  
  17168.  
  17169. #endif // VECTOR_H
  17170. //========= Copyright Valve Corporation, All rights reserved. ============//
  17171. //
  17172. // Purpose:
  17173. //
  17174. // $NoKeywords: $
  17175. //
  17176. //=============================================================================//
  17177.  
  17178. #ifndef VECTOR2D_H
  17179. #define VECTOR2D_H
  17180.  
  17181. #ifdef _WIN32
  17182. #pragma once
  17183. #endif
  17184.  
  17185. #include "MiscDefinitions.h"
  17186.  
  17187. #include <math.h>
  17188. #include <float.h>
  17189.  
  17190. // For rand(). We really need a library!
  17191. #include <stdlib.h>
  17192.  
  17193. #define CHECK_VALID( _v ) 0
  17194. #define Assert( _exp ) ((void)0)
  17195.  
  17196. #define VALVE_RAND_MAX 0x7fff
  17197.  
  17198. //=========================================================
  17199. // 2D Vector2D
  17200. //=========================================================
  17201.  
  17202. class Vector2D
  17203. {
  17204.     public:
  17205.         // Members
  17206.         vec_t x, y;
  17207.  
  17208.     // Construction/destruction
  17209.     Vector2D(void);
  17210.     Vector2D(vec_t X, vec_t Y);
  17211.     Vector2D(const float* pFloat);
  17212.  
  17213.     // Initialization
  17214.     void Init(vec_t ix = 0.0f, vec_t iy = 0.0f);
  17215.  
  17216.     // Got any nasty NAN's?
  17217.     bool IsValid() const;
  17218.  
  17219.     // array access...
  17220.     vec_t operator[](int i) const;
  17221.     vec_t& operator[](int i);
  17222.  
  17223.     // Base address...
  17224.     vec_t* Base();
  17225.     vec_t const* Base() const;
  17226.  
  17227.     // Initialization methods
  17228.     void Random(float minVal, float maxVal);
  17229.  
  17230.     // equality
  17231.     bool operator ==(const Vector2D& v) const;
  17232.     bool operator !=(const Vector2D& v) const;
  17233.  
  17234.     // arithmetic operations
  17235.     Vector2D&   operator+=(const Vector2D &v);
  17236.         Vector2D&       operator-=(const Vector2D &v);
  17237.         Vector2D&       operator*=(const Vector2D &v);
  17238.         Vector2D&       operator*=(float s);
  17239.     Vector2D&   operator/=(const Vector2D &v);
  17240.         Vector2D&       operator/=(float s);
  17241.  
  17242.     // negate the Vector2D components
  17243.     void Negate();
  17244.  
  17245.     // Get the Vector2D's magnitude.
  17246.     vec_t Length() const;
  17247.  
  17248.     // Get the Vector2D's magnitude squared.
  17249.     vec_t LengthSqr(void) const;
  17250.  
  17251.     // return true if this vector is (0,0) within tolerance
  17252.     bool IsZero(float tolerance = 0.01f) const
  17253.         {
  17254.                 return (x > -tolerance && x<tolerance &&
  17255.  
  17256.             y> -tolerance && y<tolerance);
  17257.         }
  17258.  
  17259. // Normalize in place and return the old length.
  17260. vec_t NormalizeInPlace();
  17261.  
  17262. // Compare length.
  17263. bool IsLengthGreaterThan(float val) const;
  17264. bool IsLengthLessThan(float val) const;
  17265.  
  17266. // Get the distance from this Vector2D to the other one.
  17267. vec_t DistTo(const Vector2D &vOther) const;
  17268.  
  17269. // Get the distance from this Vector2D to the other one squared.
  17270. vec_t DistToSqr(const Vector2D &vOther) const;
  17271.  
  17272. // Copy
  17273. void CopyToArray(float* rgfl) const;
  17274.  
  17275. // Multiply, add, and assign to this (ie: *this = a + b * scalar). This
  17276. // is about 12% faster than the actual Vector2D equation (because it's done per-component
  17277. // rather than per-Vector2D).
  17278. void MulAdd(const Vector2D& a, const Vector2D& b, float scalar);
  17279.  
  17280. // Dot product.
  17281. vec_t Dot(const Vector2D& vOther) const;
  17282.  
  17283. // assignment
  17284. Vector2D& operator=(const Vector2D &vOther);
  17285.  
  17286. # ifndef VECTOR_NO_SLOW_OPERATIONS
  17287.     // copy constructors
  17288.     Vector2D(const Vector2D &vOther);
  17289.  
  17290. // arithmetic operations
  17291. Vector2D operator -(void) const;
  17292.  
  17293. Vector2D operator +(const Vector2D& v) const;
  17294. Vector2D operator -(const Vector2D& v) const;
  17295. Vector2D operator *(const Vector2D& v) const;
  17296. Vector2D operator /(const Vector2D& v) const;
  17297. Vector2D operator *(float fl) const;
  17298. Vector2D operator /(float fl) const;
  17299.  
  17300. // Cross product between two vectors.
  17301. Vector2D Cross(const Vector2D &vOther) const;
  17302.  
  17303. // Returns a Vector2D with the min or max in X, Y, and Z.
  17304. Vector2D Min(const Vector2D &vOther) const;
  17305. Vector2D Max(const Vector2D &vOther) const;
  17306.  
  17307. #else
  17308.  
  17309. private:
  17310.     // No copy constructors allowed if we're in optimal mode
  17311.     Vector2D(const Vector2D& vOther);
  17312. #endif
  17313. };
  17314.  
  17315. //-----------------------------------------------------------------------------
  17316.  
  17317. const Vector2D vec2_origin(0, 0);
  17318. const Vector2D vec2_invalid(FLT_MAX, FLT_MAX);
  17319.  
  17320. //-----------------------------------------------------------------------------
  17321. // Vector2D related operations
  17322. //-----------------------------------------------------------------------------
  17323.  
  17324. // Vector2D clear
  17325. void Vector2DClear(Vector2D& a);
  17326.  
  17327. // Copy
  17328. void Vector2DCopy(const Vector2D& src, Vector2D& dst);
  17329.  
  17330. // Vector2D arithmetic
  17331. void Vector2DAdd(const Vector2D& a, const Vector2D& b, Vector2D& result);
  17332. void Vector2DSubtract(const Vector2D& a, const Vector2D& b, Vector2D& result);
  17333. void Vector2DMultiply(const Vector2D& a, vec_t b, Vector2D& result);
  17334. void Vector2DMultiply(const Vector2D& a, const Vector2D& b, Vector2D& result);
  17335. void Vector2DDivide(const Vector2D& a, vec_t b, Vector2D& result);
  17336. void Vector2DDivide(const Vector2D& a, const Vector2D& b, Vector2D& result);
  17337. void Vector2DMA(const Vector2D& start, float s, const Vector2D& dir, Vector2D& result);
  17338.  
  17339. // Store the min or max of each of x, y, and z into the result.
  17340. void Vector2DMin(const Vector2D &a, const Vector2D &b, Vector2D &result);
  17341. void Vector2DMax(const Vector2D &a, const Vector2D &b, Vector2D &result);
  17342.  
  17343. #define Vector2DExpand( v ) (v).x, (v).y
  17344.  
  17345. // Normalization
  17346. vec_t Vector2DNormalize(Vector2D& v);
  17347.  
  17348. // Length
  17349. vec_t Vector2DLength(const Vector2D& v);
  17350.  
  17351. // Dot Product
  17352. vec_t DotProduct2D(const Vector2D& a, const Vector2D& b);
  17353.  
  17354. // Linearly interpolate between two vectors
  17355. void Vector2DLerp(const Vector2D& src1, const Vector2D& src2, vec_t t, Vector2D& dest);
  17356.  
  17357.  
  17358. //-----------------------------------------------------------------------------
  17359. //
  17360. // Inlined Vector2D methods
  17361. //
  17362. //-----------------------------------------------------------------------------
  17363.  
  17364.  
  17365. //-----------------------------------------------------------------------------
  17366. // constructors
  17367. //-----------------------------------------------------------------------------
  17368.  
  17369. inline Vector2D::Vector2D(void)
  17370. {
  17371. # ifdef _DEBUG
  17372.     // Initialize to NAN to catch errors
  17373.     x = y = VEC_T_NAN;
  17374. #endif
  17375. }
  17376.  
  17377. inline Vector2D::Vector2D(vec_t X, vec_t Y)
  17378. {
  17379.     x = X; y = Y;
  17380.     Assert(IsValid());
  17381. }
  17382.  
  17383. inline Vector2D::Vector2D(const float* pFloat)
  17384. {
  17385.     Assert(pFloat);
  17386.     x = pFloat[0]; y = pFloat[1];
  17387.     Assert(IsValid());
  17388. }
  17389.  
  17390.  
  17391. //-----------------------------------------------------------------------------
  17392. // copy constructor
  17393. //-----------------------------------------------------------------------------
  17394.  
  17395. inline Vector2D::Vector2D(const Vector2D &vOther)
  17396. {
  17397.     Assert(vOther.IsValid());
  17398.     x = vOther.x; y = vOther.y;
  17399. }
  17400.  
  17401. //-----------------------------------------------------------------------------
  17402. // initialization
  17403. //-----------------------------------------------------------------------------
  17404.  
  17405. inline void Vector2D::Init(vec_t ix, vec_t iy)
  17406. {
  17407.     x = ix; y = iy;
  17408.     Assert(IsValid());
  17409. }
  17410.  
  17411. inline void Vector2D::Random(float minVal, float maxVal)
  17412. {
  17413.     x = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal);
  17414.     y = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal);
  17415. }
  17416.  
  17417. inline void Vector2DClear(Vector2D& a)
  17418. {
  17419.     a.x = a.y = 0.0f;
  17420. }
  17421.  
  17422. //-----------------------------------------------------------------------------
  17423. // assignment
  17424. //-----------------------------------------------------------------------------
  17425.  
  17426. inline Vector2D& Vector2D::operator=(const Vector2D &vOther)
  17427. {
  17428.     Assert(vOther.IsValid());
  17429.     x = vOther.x; y = vOther.y;
  17430.     return *this;
  17431. }
  17432.  
  17433. //-----------------------------------------------------------------------------
  17434. // Array access
  17435. //-----------------------------------------------------------------------------
  17436.  
  17437. inline vec_t& Vector2D::operator[](int i)
  17438. {
  17439.  
  17440.     Assert((i >= 0) && (i< 2));
  17441.         return ((vec_t*)this)[i];
  17442. }
  17443.  
  17444. inline vec_t Vector2D::operator[](int i) const
  17445. {
  17446.  
  17447.     Assert((i >= 0) && (i< 2));
  17448.         return ((vec_t*)this)[i];
  17449. }
  17450.  
  17451. //-----------------------------------------------------------------------------
  17452. // Base address...
  17453. //-----------------------------------------------------------------------------
  17454.  
  17455. inline vec_t* Vector2D::Base()
  17456. {
  17457.     return (vec_t*)this;
  17458. }
  17459.  
  17460. inline vec_t const* Vector2D::Base() const
  17461. {
  17462.         return (vec_t const*)this;
  17463. }
  17464.  
  17465. //-----------------------------------------------------------------------------
  17466. // IsValid?
  17467. //-----------------------------------------------------------------------------
  17468.  
  17469. inline bool Vector2D::IsValid() const
  17470. {
  17471.         return IsFinite(x) && IsFinite(y);
  17472. }
  17473.  
  17474. //-----------------------------------------------------------------------------
  17475. // comparison
  17476. //-----------------------------------------------------------------------------
  17477.  
  17478. inline bool Vector2D::operator==(const Vector2D& src) const
  17479. {
  17480.  
  17481.     Assert(src.IsValid() && IsValid());
  17482.         return (src.x == x) && (src.y == y);
  17483. }
  17484.  
  17485. inline bool Vector2D::operator!=(const Vector2D& src) const
  17486. {
  17487.  
  17488.     Assert(src.IsValid() && IsValid());
  17489.         return (src.x != x) || (src.y != y);
  17490. }
  17491.  
  17492.  
  17493. //-----------------------------------------------------------------------------
  17494. // Copy
  17495. //-----------------------------------------------------------------------------
  17496.  
  17497. inline void Vector2DCopy(const Vector2D& src, Vector2D& dst)
  17498. {
  17499.     Assert(src.IsValid());
  17500.     dst.x = src.x;
  17501.     dst.y = src.y;
  17502. }
  17503.  
  17504. inline void Vector2D::CopyToArray(float* rgfl) const
  17505. {
  17506.  
  17507.     Assert(IsValid());
  17508.  
  17509.     Assert(rgfl);
  17510. rgfl[0] = x; rgfl[1] = y;
  17511. }
  17512.  
  17513. //-----------------------------------------------------------------------------
  17514. // standard math operations
  17515. //-----------------------------------------------------------------------------
  17516.  
  17517. inline void Vector2D::Negate()
  17518. {
  17519.     Assert(IsValid());
  17520.     x = -x; y = -y;
  17521. }
  17522.  
  17523. inline Vector2D& Vector2D::operator+=(const Vector2D& v)
  17524. {
  17525.     Assert(IsValid() && v.IsValid());
  17526.     x += v.x; y += v.y;
  17527.     return *this;
  17528. }
  17529.  
  17530. inline Vector2D& Vector2D::operator-=(const Vector2D& v)
  17531. {
  17532.     Assert(IsValid() && v.IsValid());
  17533.     x -= v.x; y -= v.y;
  17534.     return *this;
  17535. }
  17536.  
  17537. inline Vector2D& Vector2D::operator*=(float fl)
  17538. {
  17539.     x *= fl;
  17540.     y *= fl;
  17541.     Assert(IsValid());
  17542.     return *this;
  17543. }
  17544.  
  17545. inline Vector2D& Vector2D::operator*=(const Vector2D& v)
  17546. {
  17547.     x *= v.x;
  17548.     y *= v.y;
  17549.     Assert(IsValid());
  17550.     return *this;
  17551. }
  17552.  
  17553. inline Vector2D& Vector2D::operator/=(float fl)
  17554. {
  17555.     Assert(fl != 0.0f);
  17556.     float oofl = 1.0f / fl;
  17557.     x *= oofl;
  17558.     y *= oofl;
  17559.     Assert(IsValid());
  17560.     return *this;
  17561. }
  17562.  
  17563. inline Vector2D& Vector2D::operator/=(const Vector2D& v)
  17564. {
  17565.     Assert(v.x != 0.0f && v.y != 0.0f);
  17566.     x /= v.x;
  17567.     y /= v.y;
  17568.     Assert(IsValid());
  17569.     return *this;
  17570. }
  17571.  
  17572. inline void Vector2DAdd(const Vector2D& a, const Vector2D& b, Vector2D& c)
  17573. {
  17574.     Assert(a.IsValid() && b.IsValid());
  17575.     c.x = a.x + b.x;
  17576.     c.y = a.y + b.y;
  17577. }
  17578.  
  17579. inline void Vector2DSubtract(const Vector2D& a, const Vector2D& b, Vector2D& c)
  17580. {
  17581.     Assert(a.IsValid() && b.IsValid());
  17582.     c.x = a.x - b.x;
  17583.     c.y = a.y - b.y;
  17584. }
  17585.  
  17586. inline void Vector2DMultiply(const Vector2D& a, vec_t b, Vector2D& c)
  17587. {
  17588.     Assert(a.IsValid() && IsFinite(b));
  17589.     c.x = a.x * b;
  17590.     c.y = a.y * b;
  17591. }
  17592.  
  17593. inline void Vector2DMultiply(const Vector2D& a, const Vector2D& b, Vector2D& c)
  17594. {
  17595.     Assert(a.IsValid() && b.IsValid());
  17596.     c.x = a.x * b.x;
  17597.     c.y = a.y * b.y;
  17598. }
  17599.  
  17600.  
  17601. inline void Vector2DDivide(const Vector2D& a, vec_t b, Vector2D& c)
  17602. {
  17603.     Assert(a.IsValid());
  17604.     Assert(b != 0.0f);
  17605.     vec_t oob = 1.0f / b;
  17606.     c.x = a.x * oob;
  17607.     c.y = a.y * oob;
  17608. }
  17609.  
  17610. inline void Vector2DDivide(const Vector2D& a, const Vector2D& b, Vector2D& c)
  17611. {
  17612.     Assert(a.IsValid());
  17613.     Assert((b.x != 0.0f) && (b.y != 0.0f));
  17614.     c.x = a.x / b.x;
  17615.     c.y = a.y / b.y;
  17616. }
  17617.  
  17618. inline void Vector2DMA(const Vector2D& start, float s, const Vector2D& dir, Vector2D& result)
  17619. {
  17620.     Assert(start.IsValid() && IsFinite(s) && dir.IsValid());
  17621.     result.x = start.x + s * dir.x;
  17622.     result.y = start.y + s * dir.y;
  17623. }
  17624.  
  17625. // FIXME: Remove
  17626. // For backwards compatability
  17627. inline void Vector2D::MulAdd(const Vector2D& a, const Vector2D& b, float scalar)
  17628. {
  17629.     x = a.x + b.x * scalar;
  17630.     y = a.y + b.y * scalar;
  17631. }
  17632.  
  17633. inline void Vector2DLerp(const Vector2D& src1, const Vector2D& src2, vec_t t, Vector2D& dest)
  17634. {
  17635.     dest[0] = src1[0] + (src2[0] - src1[0]) * t;
  17636.     dest[1] = src1[1] + (src2[1] - src1[1]) * t;
  17637. }
  17638.  
  17639. //-----------------------------------------------------------------------------
  17640. // dot, cross
  17641. //-----------------------------------------------------------------------------
  17642. inline vec_t DotProduct2D(const Vector2D& a, const Vector2D& b)
  17643. {
  17644.     Assert(a.IsValid() && b.IsValid());
  17645.     return (a.x * b.x + a.y * b.y);
  17646. }
  17647.  
  17648. // for backwards compatability
  17649. inline vec_t Vector2D::Dot(const Vector2D& vOther) const
  17650. {
  17651.         return DotProduct2D(*this, vOther);
  17652. }
  17653.  
  17654.  
  17655. //-----------------------------------------------------------------------------
  17656. // length
  17657. //-----------------------------------------------------------------------------
  17658. inline vec_t Vector2DLength(const Vector2D& v)
  17659. {
  17660.     Assert(v.IsValid());
  17661.     return (vec_t)sqrt(v.x * v.x + v.y * v.y);
  17662. }
  17663.  
  17664. inline vec_t Vector2D::LengthSqr(void) const
  17665. {
  17666.  
  17667.     Assert(IsValid());
  17668.         return (x* x + y* y);
  17669. }
  17670.  
  17671. inline vec_t Vector2D::NormalizeInPlace()
  17672. {
  17673.         return Vector2DNormalize(*this);
  17674. }
  17675.  
  17676. inline bool Vector2D::IsLengthGreaterThan(float val) const
  17677. {
  17678.         return LengthSqr() > val* val;
  17679. }
  17680.  
  17681. inline bool Vector2D::IsLengthLessThan(float val) const
  17682. {
  17683.         return LengthSqr() < val* val;
  17684. }
  17685.  
  17686. inline vec_t Vector2D::Length(void) const
  17687. {
  17688.         return Vector2DLength(*this);
  17689. }
  17690.  
  17691.  
  17692. inline void Vector2DMin(const Vector2D &a, const Vector2D &b, Vector2D &result)
  17693. {
  17694.     result.x = (a.x < b.x) ? a.x : b.x;
  17695.     result.y = (a.y < b.y) ? a.y : b.y;
  17696. }
  17697.  
  17698.  
  17699. inline void Vector2DMax(const Vector2D &a, const Vector2D &b, Vector2D &result)
  17700. {
  17701.     result.x = (a.x > b.x) ? a.x : b.x;
  17702.     result.y = (a.y > b.y) ? a.y : b.y;
  17703. }
  17704.  
  17705.  
  17706. //-----------------------------------------------------------------------------
  17707. // Normalization
  17708. //-----------------------------------------------------------------------------
  17709. inline vec_t Vector2DNormalize(Vector2D& v)
  17710. {
  17711.     Assert(v.IsValid());
  17712.     vec_t l = v.Length();
  17713.     if (l != 0.0f)
  17714.     {
  17715.         v /= l;
  17716.     }
  17717.     else
  17718.     {
  17719.         v.x = v.y = 0.0f;
  17720.     }
  17721.     return l;
  17722. }
  17723.  
  17724.  
  17725. //-----------------------------------------------------------------------------
  17726. // Get the distance from this Vector2D to the other one
  17727. //-----------------------------------------------------------------------------
  17728. inline vec_t Vector2D::DistTo(const Vector2D &vOther) const
  17729. {
  17730.         Vector2D delta;
  17731.  
  17732.     Vector2DSubtract(*this, vOther, delta);
  17733.         return delta.Length();
  17734. }
  17735.  
  17736. inline vec_t Vector2D::DistToSqr(const Vector2D &vOther) const
  17737. {
  17738.         Vector2D delta;
  17739.  
  17740.     Vector2DSubtract(*this, vOther, delta);
  17741.         return delta.LengthSqr();
  17742. }
  17743.  
  17744.  
  17745. //-----------------------------------------------------------------------------
  17746. // Computes the closest point to vecTarget no farther than flMaxDist from vecStart
  17747. //-----------------------------------------------------------------------------
  17748. inline void ComputeClosestPoint2D(const Vector2D& vecStart, float flMaxDist, const Vector2D& vecTarget, Vector2D* pResult)
  17749. {
  17750.     Vector2D vecDelta;
  17751.     Vector2DSubtract(vecTarget, vecStart, vecDelta);
  17752.     float flDistSqr = vecDelta.LengthSqr();
  17753.     if (flDistSqr <= flMaxDist * flMaxDist)
  17754.     {
  17755.         *pResult = vecTarget;
  17756.     }
  17757.     else
  17758.     {
  17759.         vecDelta /= sqrt(flDistSqr);
  17760.         Vector2DMA(vecStart, flMaxDist, vecDelta, *pResult);
  17761.     }
  17762. }
  17763.  
  17764.  
  17765.  
  17766. //-----------------------------------------------------------------------------
  17767. //
  17768. // Slow methods
  17769. //
  17770. //-----------------------------------------------------------------------------
  17771.  
  17772. #ifndef VECTOR_NO_SLOW_OPERATIONS
  17773.  
  17774. //-----------------------------------------------------------------------------
  17775. // Returns a Vector2D with the min or max in X, Y, and Z.
  17776. //-----------------------------------------------------------------------------
  17777.  
  17778. inline Vector2D Vector2D::Min(const Vector2D &vOther) const
  17779. {
  17780.         return Vector2D(x<vOther.x? x : vOther.x,
  17781.         y<vOther.y? y : vOther.y);
  17782. }
  17783.  
  17784. inline Vector2D Vector2D::Max(const Vector2D &vOther) const
  17785. {
  17786.         return Vector2D(x > vOther.x? x : vOther.x,
  17787.         y > vOther.y? y : vOther.y);
  17788. }
  17789.  
  17790.  
  17791. //-----------------------------------------------------------------------------
  17792. // arithmetic operations
  17793. //-----------------------------------------------------------------------------
  17794.  
  17795. inline Vector2D Vector2D::operator -(void) const
  17796. {
  17797.         return Vector2D(-x, -y);
  17798. }
  17799.  
  17800. inline Vector2D Vector2D::operator +(const Vector2D& v) const
  17801. {
  17802.         Vector2D res;
  17803.  
  17804.     Vector2DAdd(*this, v, res);
  17805.         return res;
  17806. }
  17807.  
  17808. inline Vector2D Vector2D::operator -(const Vector2D& v) const
  17809. {
  17810.         Vector2D res;
  17811.  
  17812.     Vector2DSubtract(*this, v, res);
  17813.         return res;
  17814. }
  17815.  
  17816. inline Vector2D Vector2D::operator *(float fl) const
  17817. {
  17818.         Vector2D res;
  17819.  
  17820.     Vector2DMultiply(*this, fl, res);
  17821.         return res;
  17822. }
  17823.  
  17824. inline Vector2D Vector2D::operator *(const Vector2D& v) const
  17825. {
  17826.         Vector2D res;
  17827.  
  17828.     Vector2DMultiply(*this, v, res);
  17829.         return res;
  17830. }
  17831.  
  17832. inline Vector2D Vector2D::operator /(float fl) const
  17833. {
  17834.         Vector2D res;
  17835.  
  17836.     Vector2DDivide(*this, fl, res);
  17837.         return res;
  17838. }
  17839.  
  17840. inline Vector2D Vector2D::operator /(const Vector2D& v) const
  17841. {
  17842.         Vector2D res;
  17843.  
  17844.     Vector2DDivide(*this, v, res);
  17845.         return res;
  17846. }
  17847.  
  17848. inline Vector2D operator *(float fl, const Vector2D& v)
  17849. {
  17850.     return v * fl;
  17851. }
  17852.  
  17853. #endif //slow
  17854.  
  17855. #endif // VECTOR2D_H
  17856. /*
  17857. Syn's AYYWAREFramework 2015
  17858. */
  17859.  
  17860. #include "Visuals.h"
  17861. #include "Interfaces.h"
  17862. #include "RenderManager.h"
  17863.  
  17864. // Any init here
  17865. void CVisuals::Init()
  17866. {
  17867.     // Idk
  17868. }
  17869.  
  17870. // Don't really need to do anything in here
  17871. void CVisuals::Move(CUserCmd* pCmd) { }
  17872.  
  17873. // Main ESP Drawing loop
  17874. void CVisuals::Draw()
  17875. {
  17876.     // Crosshair
  17877.     if (Menu::Window.VisualsTab.OtherCrosshair.GetState())
  17878.         DrawCrosshair();
  17879.  
  17880.     // Recoil Crosshair
  17881.     if (Menu::Window.VisualsTab.OtherRecoilCrosshair.GetIndex())
  17882.         DrawRecoilCrosshair();
  17883.  
  17884.  
  17885. }
  17886.  
  17887. // Draw a basic crosshair
  17888. void CVisuals::DrawCrosshair()
  17889. {
  17890.     // Crosshair
  17891.     RECT View = Render::GetViewport();
  17892.     int MidX = View.right / 2;
  17893.     int MidY = View.bottom / 2;
  17894.     Render::Line(MidX - 8, MidY - 8, MidX + 8, MidY + 8, Color(0, 0, 0, 200));
  17895.     Render::Line(MidX + 8, MidY - 8, MidX - 8, MidY + 8, Color(0, 0, 0, 200));
  17896.     Render::Line(MidX - 4, MidY - 4, MidX + 4, MidY + 4, Color(0, 255, 0, 255));
  17897.     Render::Line(MidX + 4, MidY - 4, MidX - 4, MidY + 4, Color(0, 255, 0, 255));
  17898. }
  17899.  
  17900. // Recoil crosshair
  17901. void CVisuals::DrawRecoilCrosshair()
  17902. {
  17903.     if (Menu::Window.RageBotTab.AccuracyRecoil.GetState())
  17904.         return;
  17905.  
  17906.     IClientEntity* pLocal = hackManager.pLocal();
  17907.  
  17908.     // Get the view with the recoil
  17909.     Vector ViewAngles;
  17910.     Interfaces::Engine->GetViewAngles(ViewAngles);
  17911.     ViewAngles += pLocal->localPlayerExclusive()->GetAimPunchAngle() * 2.f;
  17912.  
  17913.     // Build a ray going fowards at that angle
  17914.     Vector fowardVec;
  17915.     AngleVectors(ViewAngles, &fowardVec);
  17916.     fowardVec *= 10000;
  17917.  
  17918.     // Get ray start / end
  17919.     Vector start = pLocal->GetOrigin() + pLocal->GetViewOffset();
  17920.     Vector end = start + fowardVec, endScreen;
  17921.  
  17922.     if (Render::WorldToScreen(end, endScreen) && pLocal->IsAlive())
  17923.     {
  17924.         Render::Line(endScreen.x - 4, endScreen.y - 4, endScreen.x + 4, endScreen.y + 4, Color(0, 255, 0, 255));
  17925.         Render::Line(endScreen.x + 4, endScreen.y - 4, endScreen.x - 4, endScreen.y + 4, Color(0, 255, 0, 255));
  17926.         Render::Line(endScreen.x - 2, endScreen.y - 2, endScreen.x + 2, endScreen.y + 2, Color(0, 0, 0, 200));
  17927.         Render::Line(endScreen.x + 2, endScreen.y - 2, endScreen.x - 2, endScreen.y + 2, Color(0, 0, 0, 200));
  17928.     }
  17929. }/*
  17930. Syn's AYYWAREFramework 2015
  17931. */
  17932.  
  17933. #pragma once
  17934.  
  17935. #include "Hacks.h"
  17936.  
  17937. // All misc visuals (Crosshairs etc) go in this class
  17938.  
  17939. class CVisuals : public CHack
  17940. {
  17941. public:
  17942.         void Init();
  17943. void Draw();
  17944. void Move(CUserCmd* pCmd);
  17945. private:
  17946.         void DrawCrosshair();
  17947. void DrawRecoilCrosshair();
  17948. void DrawCenterRadar();
  17949. };/*
  17950. Syn's AYYWAREFramework 2015
  17951. */
  17952.  
  17953. #pragma once
  17954.  
  17955. #include "Hacks.h"
  17956.  
  17957. // All misc visuals (Crosshairs etc) go in this class
  17958.  
  17959. class CVisuals : public CHack
  17960. {
  17961. public:
  17962.         void Init();
  17963.         void Draw();
  17964.         void Move(CUserCmd *pCmd);
  17965. private:
  17966.         void DrawCrosshair();
  17967.         void DrawRecoilCrosshair();
  17968.         void DrawCenterRadar();
  17969. };/*
  17970. Syn's AYYWAREFramework 2015
  17971. */
  17972.  
  17973. #pragma once
  17974.  
  17975. #include "GUI.h"
  17976.  
  17977. #include "Interfaces.h"
  17978.  
  17979. void CWindow::SetPosition(int x, int y)
  17980. {
  17981.     m_x = x; m_y = y;
  17982. }
  17983.  
  17984. void CWindow::SetSize(int w, int h)
  17985. {
  17986.     m_iWidth = w;
  17987.     m_iHeight = h;
  17988. }
  17989.  
  17990. void CWindow::SetTitle(std::string title)
  17991. {
  17992.     Title = title;
  17993. }
  17994.  
  17995. void CWindow::RegisterTab(CTab* Tab)
  17996. {
  17997.     if (Tabs.size() == 0)
  17998.     {
  17999.         SelectedTab = Tab;
  18000.     }
  18001.     Tab->parent = this;
  18002.     Tabs.push_back(Tab);
  18003. }
  18004.  
  18005. RECT CWindow::GetClientArea()
  18006. {
  18007.     RECT client;
  18008.     client.left = m_x + 8;
  18009.     client.top = m_y + 1 + 27;
  18010.     client.right = m_iWidth - 4 - 12;
  18011.     client.bottom = m_iHeight - 2 - 8 - 26;
  18012.     return client;
  18013. }
  18014.  
  18015. RECT CWindow::GetTabArea()
  18016. {
  18017.     RECT client;
  18018.     client.left = m_x + 8;
  18019.     client.top = m_y + 1 + 27;
  18020.     client.right = m_iWidth - 4 - 12;
  18021.     client.bottom = 29;
  18022.     return client;
  18023. }
  18024.  
  18025. void CWindow::Open()
  18026. {
  18027.     m_bIsOpen = true;
  18028. }
  18029.  
  18030. void CWindow::Close()
  18031. {
  18032.     m_bIsOpen = false;
  18033. }
  18034.  
  18035. void CWindow::Toggle()
  18036. {
  18037.     m_bIsOpen = !m_bIsOpen;
  18038.     if (m_bIsOpen)
  18039.         Interfaces::Engine->ClientCmd_Unrestricted("cl_mouseenable 0");
  18040.     else
  18041.         Interfaces::Engine->ClientCmd_Unrestricted("cl_mouseenable 1");
  18042. }
  18043.  
  18044. CControl* CWindow::GetFocus()
  18045. {
  18046.     return FocusedControl;
  18047. }
  18048.  
  18049. // TABS ---------------------------------------------------------------------------------------------------
  18050.  
  18051. void CTab::SetTitle(std::string name)
  18052. {
  18053.     Title = name;
  18054. }
  18055.  
  18056. void CTab::RegisterControl(CControl* control)
  18057. {
  18058.     control->parent = parent;
  18059.     Controls.push_back(control);
  18060. }

Replies to src rss

Title Name Language When
Re: src Torrid Moth text 5 Years ago.