/*Well, this is my tutorial on Counter-Strike coding.. Ive only been coding for Counter-Strike for two day's but already I have a good feel in it.. This is basically going to cover setting up your own cvar system, a basic menu w/ glowing string's, and quite a few different hack option's... I used panzer's 1.20 pGL Basehook to learn off of... I decided not to use a hook source because then it would feel more like taking away from the base to make it personal rather than making one from scratch.. I hope everyone enjoy's this, and since it's only my 2nd day into coding for Counter- Strike, I will be sure to go over everything and what everything does from what I understand personally this soon on..*/ // Creating your own cvar system // This is actually quite simple believe it or not... // My own CVAR struct, adjust to taste =P struct basehookcvar_s // Once the struct is setup, you can name it w/e you want, i.e basehookcvar_s?! { float wallhack; // the float's are for the cvar's of the hack's... float whitewalls; float wireframe; float thirdperson; float bunnyhop; float spinhack; float nosky; float nightmode; float wiremodels; float nigger; float duckjump; float menu; }; basehookcvar_s cvar; //Now, since we have built our own cvar system, we are all ready to make our Menu System... //Menu Structure struct basehookmenu_s// Look under InitMenu(){ for more information on how this is working... { char title[16]; float* value; float min; float max; float step; }; int menuIndex = 0; int menuItems = 11;// When adding more thing's/feat's, always make sure to update this basehookmenu_s menu[11];// Along w/ this also =P // Menu Drawing void InitMenu() { strcpy( menu[0].title, "WHack" );// Title is what is displayed on your screen menu[0].value = &cvar.wallhack;// Place the value of the cvar.w/e here... menu[0].min = 0;// Min is for the minumum possible setting, which would be 0 for off menu[0].max = 1;// Max is for the Max amount of changes allowed before reseting back to 0/off menu[0].step = 1;// Step is for the ammount it goes up... Of course we use 1... strcpy( menu[1].title, "WWalls" ); menu[1].value = &cvar.whitewalls; menu[1].min = 0; menu[1].max = 1; menu[1].step = 1; strcpy( menu[2].title, "WFrame" ); menu[2].value = &cvar.wireframe; menu[2].min = 0; menu[2].max = 3; menu[2].step = 1; strcpy( menu[3].title, "CCam" ); menu[3].value = &cvar.thirdperson; menu[3].min = 0; menu[3].max = 1; menu[3].step = 1; strcpy( menu[4].title, "BHop" ); menu[4].value = &cvar.bunnyhop; menu[4].min = 0; menu[4].max = 1; menu[4].step = 1; strcpy( menu[5].title, "Spin" ); menu[5].value = &cvar.spinhack; menu[5].min = 0; menu[5].max = 1; menu[5].step = 1; strcpy( menu[6].title, "NoSky"); menu[6].value = &cvar.nosky; menu[6].min = 0; menu[6].max = 1; menu[6].step = 1; strcpy( menu[7].title, "NMode"); menu[7].value = &cvar.nightmode; menu[7].min = 0; menu[7].max = 1; menu[7].step = 1; strcpy( menu[8].title, "WModel"); menu[8].value = &cvar.wiremodels; menu[8].min = 0; menu[8].max = 3; menu[8].step = 1; strcpy( menu[9].title, "NigMode"); menu[9].value = &cvar.nigger; menu[9].min = 0; menu[9].max = 1; menu[9].step = 1; strcpy( menu[10].title, "DJump"); menu[10].value = &cvar.duckjump; menu[10].min = 0; menu[10].max = 1; menu[10].step = 1; } // Now that the Menu is all done, let's go ahead and draw it... Head down to HUD_Redraw... // Menu if(cvar.menu) { gEngfuncs.pfnClientCmd("unbind mouse1"); gEngfuncs.pfnClientCmd("unbind mwheelup"); gEngfuncs.pfnClientCmd("unbind mwheeldown"); } if(!cvar.menu) { gEngfuncs.pfnClientCmd("bind mouse1 +attack"); gEngfuncs.pfnClientCmd("bind mwheelup invprev"); gEngfuncs.pfnClientCmd("bind mwheeldown invnext"); } if( cvar.menu ) { int x = 200; int xx = 220; int y = 100; int yy = 200; int yyy = 316; InitMenu(); // Draw's Glowing Hud Text DrawGlowHudString( x - 130, 84, 0, 0, 128, "Title of Hack Here =P" ); for(int i=0;i<menuItems;i++) { if( i!=menuIndex ) { DrawHudString( x - 130, 100 + (16*i), 255, 255, 255, menu[i].title ); DrawHudString( x - 60, 100 + (16*i), 255, 255, 255, "%2.2f", menu[i].value[0] ); } else { static int b = 0; static bool mode = 1; if( mode ) b+=10; else b-=10; if( b<0 ) { b=0;mode=1; } if( b>255 ) { b=255;mode=0; } DrawGlowHudString( x - 130, 100 + (16*i), 0, 0, b, menu[i].title ); DrawGlowHudString( x - 60, 100 + (16*i), 0, 0, b, "%2.2f", menu[i].value[0] ); } } } } // Now that we have placed it in HUD_Redraw, there's one more section we have to cover before // it will actually be able to toggle on and off.. Head down to HUD_Key_Event for this... // Setup Hotkey for toggleing of Menu if( keynum == 147 ) // Insert { if( eventcode == 1 ) cvar.menu=!cvar.menu; } if( cvar.menu && (eventcode==1) ) { if( keynum == 128 ) { if( menuIndex>0 ) menuIndex--; } if( keynum == 129 ) // downarrow { if( menuIndex<menuItems-1 ) menuIndex++; } if( keynum == 130 ) // leftarrow { if( menu[menuIndex].value ) { menu[menuIndex].value[0] -= menu[menuIndex].step; if( menu[menuIndex].value[0] < menu[menuIndex].min ) menu[menuIndex].value[0] = menu[menuIndex].max; } } if( keynum == 131 ) // rightarrow { if( menu[menuIndex].value ) { menu[menuIndex].value[0] += menu[menuIndex].step; if( menu[menuIndex].value[0] > menu[menuIndex].max ) menu[menuIndex].value[0] = menu[menuIndex].min; } } if( keynum == 239 ) { if( menuIndex<menuItems-1 ) menuIndex++; } if( keynum == 240 ) { if( menuIndex>0 ) menuIndex--; } if( keynum == 241 ) { if( eventcode ) { menu[menuIndex].value[0] += menu[menuIndex].step; if( menu[menuIndex].value[0] > menu[menuIndex].max ) menu[menuIndex].value[0] = menu[menuIndex].min; } } if( keynum == 242 ) { if( eventcode ) { menu[menuIndex].value[0] -= menu[menuIndex].step; if( menu[menuIndex].value[0] < menu[menuIndex].min ) menu[menuIndex].value[0] = menu[menuIndex].max; } } } } // Well, congrat's, you have successfully made your own cvar system and menu... Now let's start // adding some hook feature's =D // Right above the 1st hooked client function, CL_CreateMove, place this copy/paste code for a // spinbot... Credit's of course goto Tetsuo for this, thank's man! #define SPIN_REVS_PER_SECOND 5.0f // adjust to taste, I use 5 b/c it doesnt make me lag.. //Tetsuo's copy/paste Spinhack code, thanks alot =D void Spinhack(usercmd_t *cmd) { // thanks tetsuo for this copy/paste cl_entity_t *pLocal; Vector viewforward, viewright, viewup, aimforward, aimright, aimup, vTemp; float newforward, newright, newup, fTime; float forward = g_Originalcmd.forwardmove; float right = g_Originalcmd.sidemove; float up = g_Originalcmd.upmove; pLocal = gEngfuncs.GetLocalPlayer(); if(!pLocal) return; // this branch makes sure your horizontal velocity is not affected when fixing up the movement angles -- it isn't specific to spinning and you can use it with the source tetsuo posted in his forum too if(pLocal->curstate.movetype == MOVETYPE_WALK) { gEngfuncs.pfnAngleVectors(Vector(0.0f, g_Originalcmd.viewangles.y, 0.0f), viewforward, viewright, viewup); } else { gEngfuncs.pfnAngleVectors(g_Originalcmd.viewangles , viewforward, viewright, viewup); } // SPIN!!! int iHasShiftHeld = GetAsyncKeyState(VK_LSHIFT); if(pLocal->curstate.movetype == MOVETYPE_WALK && !iHasShiftHeld && !(cmd->buttons & IN_ATTACK) && !(cmd->buttons & IN_USE)) { fTime = gEngfuncs.GetClientTime(); cmd->viewangles.y = fmod(fTime * SPIN_REVS_PER_SECOND * 360.0f, 360.0f); } // this branch makes sure your horizontal velocity is not affected when fixing up the movement angles -- it isn't specific to spinning and you can use it with the source tetsuo posted in his forum too if(pLocal->curstate.movetype == MOVETYPE_WALK) { gEngfuncs.pfnAngleVectors(Vector(0.0f, cmd->viewangles.y, 0.0f), aimforward, aimright, aimup); } else { gEngfuncs.pfnAngleVectors(cmd->viewangles, aimforward, aimright, aimup); } newforward = DotProduct(forward * viewforward.Normalize(), aimforward) + DotProduct(right * viewright.Normalize(), aimforward) + DotProduct(up * viewup.Normalize(), aimforward); newright = DotProduct(forward * viewforward.Normalize(), aimright) + DotProduct(right * viewright.Normalize(), aimright) + DotProduct(up * viewup.Normalize(), aimright); newup = DotProduct(forward * viewforward.Normalize(), aimup) + DotProduct(right * viewright.Normalize(), aimup) + DotProduct(up * viewup.Normalize(), aimup); cmd->forwardmove = newforward; cmd->sidemove = newright; cmd->upmove = newup; } //Now that we have that, we are going to have to add the cvar for it to actually work.. Goto CL_ // CreateMove and add this under memcpy(&g_Originalcmd, cmd, sizeof(usercmd_t)); //Spinhack if(cvar.spinhack) Spinhack(cmd); // Now the Spinhack is successfully done.. Let's move on to something else.. Persay Bunnyhop/Duck // jump now =D This is were it tend's to get a little tricky.. We are going to have to hook 2 part's // along with the CL_CreateMove... Those 2 part's would include local.h along w/ HUD_PlayerMove.. // Now, to add the code for bunnyhop and duckjump... Goto CL_CreateMove above the memcpy(&g_Originalcmd, cmd, sizeof(usercmd_t)); // part... // Add this there: // Bunnyhop/Duckjump if (cvar.bunnyhop && (cmd->buttons & IN_JUMP) && !(me.pmFlags & FL_ONGROUND)) cmd->buttons &= ~IN_JUMP; if (cvar.duckjump && !(me.pmFlags & FL_ONGROUND) && me.pmVelocity[2]>0) cmd->buttons |= IN_DUCK; // Now that that is done, we have to setup our int and float for these to work in local.h... Add // this above the current functions listed... int pmFlags; // Bunnyhop float pmVelocity[3]; // Duckjump // Now that local.h is hooked, we still have one thing we have to do... Go down to HUD_PlayerMove // and add this: me.pmFlags = a->flags; // Flags // Now that we have successfully completed a Spinhack, Bunnyhop, and Duckjump, let's start adding // real hack function's... Everyone ready?! It can't possibly get harder than the above, so no // worries =D // But before we get to ahead of ourselve's, let's be sure to add 3rdPerson while we are still in // the hooked client function's instead of going to the OpenGL part and back up.. Go down to HUD_Redraw // and add this above the Menu: //3rd Person if(cvar.thirdperson) { gEngfuncs.pfnGetCvarPointer("chase_active")->value = 1; gEngfuncs.pfnGetCvarPointer("r_drawviewmodel")->value = 0; } if(!cvar.thirdperson) { gEngfuncs.pfnGetCvarPointer("chase_active")->value = 0; gEngfuncs.pfnGetCvarPointer("r_drawviewmodel")->value = 1; } // Okay, now we are ready to head down to the OpenGL section.. Go down to glBegin.. This is where // the fun really begin's =D... // We will start with a simple wallhack: //Wallhack if(cvar.wallhack == 1) { if(!(mode==GL_TRIANGLES||mode==GL_TRIANGLE_STRIP|| mode==GL_TRIANGLE_FAN||mode==GL_QUADS)) { GLfloat curcol[4]; glGetFloatv(GL_CURRENT_COLOR, curcol); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glColor4f(curcol[0],curcol[1],curcol[2],0.5f); glClearColor(0.0f,0.0f,0.0f,0.0f); } } // Now let's add a simple Whitewall's: //Whitewalls if(cvar.whitewalls == 1) { if(!(mode==GL_TRIANGLES||mode==GL_TRIANGLE_STRIP|| mode==GL_TRIANGLE_FAN||mode==GL_QUADS)) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); } } // Let's add nigger mode also =P //Nigger Mode if(cvar.nigger) { if(mode == GL_TRIANGLE_STRIP) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); } } // Now, this is where it kinda get's a bit hard... Let's add 3 different wireframe mode's, all with // the same wireframe code, just different thickness... You can adjust the width yourself, there // currently at the width's i prefer: // Wireframe-> Not all that was changed was the LineWidth, give's it a thicker look.. Skinny lines->1, Thich lines->3, Thickest->5.. if (cvar.wireframe==1) // moce 1 { if (mode == GL_POLYGON) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(1.0); glColor3f(255,255,255); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } } if (cvar.wireframe==2) // mode 2 { if (mode == GL_POLYGON) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(3.0); glColor3f(255,255,255); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } } if (cvar.wireframe==3) // mode 3 { if (mode == GL_POLYGON) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(5.0); glColor3f(255,255,255); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } } // Now that we have added wireframe for the wall's, let's do it for the players.. Please note, you // can only have one wireframe mode on at once.. So you cant have wiremodel's and walls on at same // time... //Wireframe Models if(cvar.wiremodels==1) //mode 1 { if(mode==GL_TRIANGLE_STRIP || mode==GL_TRIANGLE_FAN) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(1.0); } else { glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); } } if(cvar.wiremodels==2) //mode 2 { if(mode==GL_TRIANGLE_STRIP || mode==GL_TRIANGLE_FAN) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(3.0); } else { glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); } } if(cvar.wiremodels==3) //mode 3 { if(mode==GL_TRIANGLE_STRIP || mode==GL_TRIANGLE_FAN) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(5.0); } else { glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); } } // Now, let's add our nosky... To do this, we must 1st go back to the top and add this: //Bool for NoSKy bool bnosky = false; // Now, since we have our bool setup, we are ready to add the code for it work.. Go back to glBegin // NoSky if (mode == GL_QUADS && cvar.nosky) bnosky = true; else bnosky = false; // Now that is done, let's head down to glClear... This way, our wallhack doesnt fux0r up and the // wireframe doesnt blend on screen and make it to were u cant see shit =P //Used to make sure our wireframe/wallhack doesnt blend other textures.. if(mask==GL_DEPTH_BUFFER_BIT) { mask+=GL_COLOR_BUFFER_BIT; glClearColor(0.0f, 0.0f, 0.0f, 0.0f); } // Once that is done, we are all ready to add our last function and probably my favorite... Night // mode... So, once again, we must go back to glBegin.... // Nightmode if(cvar.nightmode) { if(mode != GL_TRIANGLES && mode != GL_TRIANGLE_STRIP && mode != GL_TRIANGLE_FAN && mode != GL_QUADS) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); } } // Well, I am pretty sure that cover's everything I have learned thus far in the 2 day's I have // coding for Counter-Strike... I was going to do this in a word doc but I relized it would be ugly // and alot of people would probably be confused... Well, I hope this help's everyone out there who // was just as dazed and confused as I was 2 day's ago...
added formatting & code tags!
Comment