Some better dvar handling.

This commit is contained in:
momo5502 2015-12-23 17:12:15 +01:00
parent 602d4ac61d
commit f174fd77ef
7 changed files with 34 additions and 13 deletions

View File

@ -12,6 +12,10 @@ namespace Components
} }
} }
template <> Game::dvar_t* Dvar::Var::Get()
{
return this->dvar;
}
template <> char* Dvar::Var::Get() template <> char* Dvar::Var::Get()
{ {
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING && this->dvar->current.string) if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_STRING && this->dvar->current.string)
@ -21,12 +25,10 @@ namespace Components
return ""; return "";
} }
template <> const char* Dvar::Var::Get() template <> const char* Dvar::Var::Get()
{ {
return this->Get<char*>(); return this->Get<char*>();
} }
template <> int Dvar::Var::Get() template <> int Dvar::Var::Get()
{ {
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT) if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_INT)
@ -36,7 +38,6 @@ namespace Components
return 0; return 0;
} }
template <> float Dvar::Var::Get() template <> float Dvar::Var::Get()
{ {
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT) if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
@ -46,7 +47,6 @@ namespace Components
return 0; return 0;
} }
template <> float* Dvar::Var::Get() template <> float* Dvar::Var::Get()
{ {
static float val[4] = { 0 }; static float val[4] = { 0 };
@ -58,7 +58,6 @@ namespace Components
return val; return val;
} }
template <> bool Dvar::Var::Get() template <> bool Dvar::Var::Get()
{ {
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL) if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_BOOL)
@ -73,7 +72,6 @@ namespace Components
{ {
this->Set(reinterpret_cast<const char*>(string)); this->Set(reinterpret_cast<const char*>(string));
} }
void Dvar::Var::Set(const char* string) void Dvar::Var::Set(const char* string)
{ {
if (this->dvar && this->dvar->name) if (this->dvar && this->dvar->name)
@ -81,12 +79,10 @@ namespace Components
Game::Dvar_SetCommand(this->dvar->name, string); Game::Dvar_SetCommand(this->dvar->name, string);
} }
} }
void Dvar::Var::Set(std::string string) void Dvar::Var::Set(std::string string)
{ {
this->Set(string.data()); this->Set(string.data());
} }
void Dvar::Var::Set(int integer) void Dvar::Var::Set(int integer)
{ {
if (this->dvar && this->dvar->name) if (this->dvar && this->dvar->name)
@ -94,7 +90,6 @@ namespace Components
Game::Dvar_SetCommand(this->dvar->name, Utils::VA("%i", integer)); Game::Dvar_SetCommand(this->dvar->name, Utils::VA("%i", integer));
} }
} }
void Dvar::Var::Set(float value) void Dvar::Var::Set(float value)
{ {
if (this->dvar && this->dvar->name) if (this->dvar && this->dvar->name)
@ -107,12 +102,18 @@ namespace Components
{ {
return Game::Dvar_RegisterBool(name, value, flag, description); return Game::Dvar_RegisterBool(name, value, flag, description);
} }
template<> static Dvar::Var Dvar::Var::Register(const char* name, const char* value, Game::dvar_flag flag, const char* description) template<> static Dvar::Var Dvar::Var::Register(const char* name, const char* value, Game::dvar_flag flag, const char* description)
{ {
return Game::Dvar_RegisterString(name, value, flag, description); return Game::Dvar_RegisterString(name, value, flag, description);
} }
Game::dvar_t* Dvar::RegisterName(const char* name, const char* default, Game::dvar_flag flag, const char* description)
{
// TODO: Register string dvars here
return Dvar::Var::Register<const char*>(name, "Unknown Soldier", (Game::dvar_flag)(flag | Game::dvar_flag::DVAR_FLAG_SAVED), description).Get<Game::dvar_t*>();
}
Dvar::Dvar() Dvar::Dvar()
{ {
// set flags of cg_drawFPS to archive // set flags of cg_drawFPS to archive
@ -125,7 +126,7 @@ namespace Components
static float cgFov90 = 90.0f; static float cgFov90 = 90.0f;
Utils::Hook::Set<float*>(0x4F8E28, &cgFov90); Utils::Hook::Set<float*>(0x4F8E28, &cgFov90);
//Dvar::Var::Register<bool>("zob", true, Game::dvar_flag::DVAR_FLAG_NONE, "test dvar"); // Hook dvar 'name' registration
//Dvar::Var::Register<const char*>("zob2", "test", Game::dvar_flag::DVAR_FLAG_NONE, "test dvar3"); Utils::Hook(0x40531C, Dvar::RegisterName, HOOK_CALL).Install()->Quick();
} }
} }

View File

@ -31,6 +31,6 @@ namespace Components
const char* GetName() { return "Dvar"; }; const char* GetName() { return "Dvar"; };
private: private:
static Game::dvar_t* RegisterName(const char* name, const char* default, Game::dvar_flag flag, const char* description);
}; };
} }

View File

@ -4,6 +4,7 @@
#include <windows.h> #include <windows.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <map> #include <map>
#include <mutex> #include <mutex>

View File

@ -24,6 +24,8 @@ namespace Utils
Hook::Place = place; Hook::Place = place;
Hook::Stub = stub; Hook::Stub = stub;
Hook::Original = (char*)Hook::Place + 5 + *(DWORD*)((DWORD)Hook::Place + 1);
return this; return this;
} }

View File

@ -85,6 +85,7 @@ namespace Utils
void* Place; void* Place;
void* Stub; void* Stub;
void* Original;
char Buffer[5]; char Buffer[5];
bool UseJump; bool UseJump;

View File

@ -56,8 +56,10 @@
<ClInclude Include="Components\Console.hpp" /> <ClInclude Include="Components\Console.hpp" />
<ClInclude Include="Components\Dvar.hpp" /> <ClInclude Include="Components\Dvar.hpp" />
<ClInclude Include="Components\Loader.hpp" /> <ClInclude Include="Components\Loader.hpp" />
<ClInclude Include="Components\Materials.hpp" />
<ClInclude Include="Components\QuickPatch.hpp" /> <ClInclude Include="Components\QuickPatch.hpp" />
<ClInclude Include="Components\RawFiles.hpp" /> <ClInclude Include="Components\RawFiles.hpp" />
<ClInclude Include="Components\Renderer.hpp" />
<ClInclude Include="Components\Window.hpp" /> <ClInclude Include="Components\Window.hpp" />
<ClInclude Include="Game\Functions.hpp" /> <ClInclude Include="Game\Functions.hpp" />
<ClInclude Include="Game\Structs.hpp" /> <ClInclude Include="Game\Structs.hpp" />
@ -80,8 +82,10 @@
<ClCompile Include="Components\Console.cpp" /> <ClCompile Include="Components\Console.cpp" />
<ClCompile Include="Components\Dvar.cpp" /> <ClCompile Include="Components\Dvar.cpp" />
<ClCompile Include="Components\Loader.cpp" /> <ClCompile Include="Components\Loader.cpp" />
<ClCompile Include="Components\Materials.cpp" />
<ClCompile Include="Components\QuickPatch.cpp" /> <ClCompile Include="Components\QuickPatch.cpp" />
<ClCompile Include="Components\RawFiles.cpp" /> <ClCompile Include="Components\RawFiles.cpp" />
<ClCompile Include="Components\Renderer.cpp" />
<ClCompile Include="Components\Window.cpp" /> <ClCompile Include="Components\Window.cpp" />
<ClCompile Include="Game\Functions.cpp" /> <ClCompile Include="Game\Functions.cpp" />
<ClCompile Include="Steam\Interfaces\SteamFriends.cpp" /> <ClCompile Include="Steam\Interfaces\SteamFriends.cpp" />

View File

@ -92,6 +92,12 @@
<ClCompile Include="Components\RawFiles.cpp"> <ClCompile Include="Components\RawFiles.cpp">
<Filter>Source\Components\Modules</Filter> <Filter>Source\Components\Modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Components\Materials.cpp">
<Filter>Source\Components\Modules</Filter>
</ClCompile>
<ClCompile Include="Components\Renderer.cpp">
<Filter>Source\Components\Modules</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Steam\Interfaces\SteamUser.hpp"> <ClInclude Include="Steam\Interfaces\SteamUser.hpp">
@ -160,5 +166,11 @@
<ClInclude Include="Components\RawFiles.hpp"> <ClInclude Include="Components\RawFiles.hpp">
<Filter>Source\Components\Modules</Filter> <Filter>Source\Components\Modules</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Components\Materials.hpp">
<Filter>Source\Components\Modules</Filter>
</ClInclude>
<ClInclude Include="Components\Renderer.hpp">
<Filter>Source\Components\Modules</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>