• Use [hide] Content [/hide] to prevent leeching of your content.

HL2 Cvar Controller

Jimster480

Administrator
Staff member
[syntax="cpp"]
#include "CvarSys.h"
#include <fstream>
#include <string>
using namespace std;
// HL2 Cvar Control System (Class) By: Jimster480
// Thx to P47R1CK for teaching/helping me about/with the source engine <3
// Plz Credit me if you use this....
// char dlldir[512]; // You need this.

//----------------------------------------------------------------
bool FileExist(const char* filename)
{
WIN32_FIND_DATA finddata;
HANDLE handle = FindFirstFile(filename,&finddata);
return (handle!=INVALID_HANDLE_VALUE);
}
//----------------------------------------------------------------
inline std::string DirFile(const char* basename) // Credits: Unknown. I don't think I wrote this.
{
if(strstr(basename,"..")){ return ":*?\\/<>\""; }
string ret = dlldir;
return (ret+basename);
}
//----------------------------------------------------------------
struct mcvar
{
char name[128];
float value;
float max;
float min;
float change;
float origvalue;
ConVar *ptr;
bool reset;
};
mcvar pc[128];
int cvarnum;
int cnum;
//----------------------------------------------------------------
void CvarSys::AddCvar(char nme[128],float valu,float chg,float mn,float mx,float orig)
{
cnum++;
cvarnum = cnum;
strcpy(pc[cnum].name,nme);
pc[cnum].value = valu;
pc[cnum].ptr = pCvar->FindVar(pc[cnum].name);
pc[cnum].max = mx;
pc[cnum].min = mn;
pc[cnum].change = chg;
pc[cnum].origvalue = orig;
}
void CvarSys::SetCvars(void)
{
for(int i = 1;i<=cvarnum;i++)
{
ConVar * ptr = pCvar->FindVar(pc.name);
if(ptr == NULL) continue;
/*pc.*/ptr->SetValue(pc.value);
pc.reset = false;
}
}
void CvarSys::SetCvar(int i)
{
{
ConVar * ptr = pCvar->FindVar(pc.name);
if(ptr == NULL) return;
/*pc.*/ptr->SetValue(pc.value);
pc.reset = false;
}
}
void CvarSys::ResetCvar(int i)
{
{
if(pc.reset == true) return;
ConVar * ptr = pCvar->FindVar(pc.name);
if(ptr == NULL) return;
/*pc.*/ptr->SetValue(pc.origvalue);
pc.reset = true;
}
}
void CvarSys::ResetCvars(void)
{
for(int i = 1;i<=cvarnum;i++)
{
if(pc.reset == true) continue;
ConVar * ptr = pCvar->FindVar(pc.name);
if(ptr == NULL) continue;
/*pc.*/ptr->SetValue(pc.origvalue);
pc.reset = true;
}
}
void CvarSys::AddCvarsToMenu(void)
{
for(int i = 1;i<=cvarnum; i++)
{
pMisc->AddMenuOption(pc.name,&pc.value,pc.max,pc.min,pc.change,0); // Z0MG MENU FUNC?! Yes, Use/Make/Get Your Own.
}
}
void CvarSys::AddCvarToMenu(int i)
{
{
pMisc->AddMenuOption(pc.name,&pc.value,pc.max,pc.min,pc.change,0); // Z0MG MENU FUNC?! Yes, Use/Make/Get Your Own.
}
}
void CvarSys::SetupCvars(void)
{
for(int i = 0;i<128;i++)
{
pc.value = 0.0f;
pc.min = 0.0f;
pc.max = 0.0f;
pc.change = 0.0f;
pc.name[0] = 0;
pc.reset = true;
}
cvarnum = 0;

}
void CvarSys::LoadCvars(void)
{
float value,change,min,max,org;
char name[128];
if(FileExist(DirFile( "cvarsys.ini" ).c_str()))
{
char data[16];
GetPrivateProfileString( "CVARSYS", "cvarnum", "0", data, 16, DirFile( "cvarsys.ini" ).c_str() );
int num = atof(data);
char buf[128] = {'\0'};
for(int i = 1;i<=num;i++)
{
sprintf(buf, "name%i",i);
GetPrivateProfileString( "CVARSYS", buf, "missing", name, 128, DirFile( "cvarsys.ini" ).c_str());
sprintf(buf, "value%i",i);
GetPrivateProfileString( "CVARSYS", buf, "1", data, 16, DirFile( "cvarsys.ini" ).c_str());
value = atof(data);
sprintf(buf, "change%i",i);
GetPrivateProfileString( "CVARSYS", buf, "1", data, 16, DirFile( "cvarsys.ini" ).c_str());
change = atof(data);
sprintf(buf, "min%i",i);
GetPrivateProfileString( "CVARSYS", buf, "0", data, 16, DirFile( "cvarsys.ini" ).c_str());
min = atof(data);
sprintf(buf, "max%i",i);
GetPrivateProfileString( "CVARSYS", buf, "50", data, 16, DirFile( "cvarsys.ini" ).c_str());
max = atof(data);
sprintf(buf, "orig%i",i);
GetPrivateProfileString( "CVARSYS", buf, "0", data, 16, DirFile( "cvarsys.ini" ).c_str());
org = atof(data);
AddCvar(name,value,change,min,max,org);
}
}
else { MessageBoxW(NULL,L"cvarsys.ini not found",0,0);}
}[/color]

#ifndef __CvarSys_H__
#define __CvarSys_H__

#include "sdk.h" // Link It Up :p

// HL2 Cvar Control System (Class) By: Jimster480
// Thx to P47R1CK for teaching/helping me about/with the source engine <3
// Plz Credit me if you use this....
// extern char dlldir[512]; // You need this.
class CvarSys
{
public:
void AddCvar(char nme[128],float valu,float chg,float mn,float mx,float orig);
void SetCvars(void);
void SetCvar(int i);
void ResetCvars(void);
void ResetCvar(int i);
void AddCvarsToMenu(void);
void AddCvarToMenu(int i);
void SetupCvars(void);
void LoadCvars(void);
};

#endif
[/syntax]

Links: <!-- m --><a class="postlink" href="http://jimster480.com/CvarSys.rar">http://jimster480.com/CvarSys.rar</a><!-- m -->
 
Top Bottom