2022-06-30 15:37:47 -04:00
|
|
|
#include <STDInclude.hpp>
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
2022-07-23 16:16:26 -04:00
|
|
|
std::vector<std::string> VisionFile::DvarExceptions =
|
2022-06-30 15:37:47 -04:00
|
|
|
{
|
|
|
|
"r_pretess",
|
|
|
|
};
|
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
std::unordered_map<std::string, std::string> VisionFile::VisionReplacements
|
2022-06-30 15:37:47 -04:00
|
|
|
{
|
2022-07-23 16:16:26 -04:00
|
|
|
{"511", "r_glow"},
|
|
|
|
{"516", "r_glowRadius0"},
|
|
|
|
{"512", "r_glowBloomCutoff"},
|
|
|
|
{"513", "r_glowBloomDesaturation"},
|
|
|
|
{"514", "r_glowBloomIntensity0"},
|
|
|
|
{"520", "r_filmEnable"},
|
|
|
|
{"522", "r_filmContrast"},
|
|
|
|
{"521", "r_filmBrightness"},
|
|
|
|
{"523", "r_filmDesaturation"},
|
|
|
|
{"524", "r_filmDesaturationDark"},
|
|
|
|
{"525", "r_filmInvert"},
|
|
|
|
{"526", "r_filmLightTint"},
|
|
|
|
{"527", "r_filmMediumTint"},
|
|
|
|
{"528", "r_filmDarkTint"},
|
|
|
|
{"529", "r_primaryLightUseTweaks"},
|
|
|
|
{"530", "r_primaryLightTweakDiffuseStrength"},
|
|
|
|
{"531", "r_primaryLightTweakSpecularStrength"},
|
|
|
|
};
|
|
|
|
|
|
|
|
bool VisionFile::ApplyExemptDvar(const char* dvarName, const char** buffer, const char* filename)
|
|
|
|
{
|
|
|
|
for (auto& exceptions : DvarExceptions)
|
2022-06-30 15:37:47 -04:00
|
|
|
{
|
2022-07-23 16:16:26 -04:00
|
|
|
if (!_stricmp(dvarName, exceptions.data()))
|
2022-06-30 15:37:47 -04:00
|
|
|
{
|
2022-07-23 16:16:26 -04:00
|
|
|
const auto* dvar = Game::Dvar_FindVar(dvarName);
|
|
|
|
const auto* parsedValue = Game::Com_ParseOnLine(buffer);
|
2022-06-30 15:37:47 -04:00
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
assert(dvar);
|
|
|
|
assert(parsedValue);
|
2022-06-30 15:37:47 -04:00
|
|
|
|
2022-08-11 06:44:03 -04:00
|
|
|
Game::Dvar_SetFromStringFromSource(dvar, parsedValue, Game::DVAR_SOURCE_INTERNAL);
|
2022-07-23 16:16:26 -04:00
|
|
|
Logger::Print("Overriding '{}' from '{}'\n", dvar->name, filename);
|
2022-06-30 15:37:47 -04:00
|
|
|
|
|
|
|
// Successfully found and tried to apply the string value to the dvar
|
2022-07-23 16:16:26 -04:00
|
|
|
return true;
|
2022-06-30 15:37:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
return false;
|
2022-06-30 15:37:47 -04:00
|
|
|
}
|
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
bool VisionFile::LoadVisionSettingsFromBuffer(const char* buffer, const char* filename, Game::visionSetVars_t* settings)
|
2022-06-30 15:37:47 -04:00
|
|
|
{
|
2022-07-23 16:16:26 -04:00
|
|
|
assert(settings);
|
2022-06-30 15:37:47 -04:00
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
bool wasRead[21]{};
|
|
|
|
Game::Com_BeginParseSession(filename);
|
2022-06-30 15:37:47 -04:00
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
auto* token = Game::Com_Parse(&buffer);
|
2022-06-30 15:37:47 -04:00
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
if (!*token)
|
|
|
|
{
|
|
|
|
break;
|
2022-06-30 15:37:47 -04:00
|
|
|
}
|
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
auto found = false;
|
|
|
|
auto fieldNum = 0;
|
2022-06-30 15:37:47 -04:00
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
const auto it = VisionReplacements.find(token);
|
|
|
|
for (fieldNum = 0; fieldNum < 21; ++fieldNum)
|
|
|
|
{
|
|
|
|
if (!wasRead[fieldNum] && !_stricmp((it == VisionReplacements.end()) ? token : it->second.data(), Game::visionDefFields[fieldNum].name))
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-30 15:37:47 -04:00
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
if (!ApplyExemptDvar(token, &buffer, filename))
|
|
|
|
{
|
|
|
|
Logger::Warning(Game::CON_CHANNEL_SYSTEM, "WARNING: unknown dvar '{}' in file '{}'\n", token, filename);
|
|
|
|
Game::Com_SkipRestOfLine(&buffer);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-30 15:37:47 -04:00
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
token = Game::Com_ParseOnLine(&buffer);
|
|
|
|
if (ApplyTokenToField(fieldNum, token, settings))
|
|
|
|
{
|
|
|
|
wasRead[fieldNum] = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Logger::Warning(Game::CON_CHANNEL_SYSTEM, "WARNING: malformed dvar '{}' in file '{}'\n", token, filename);
|
|
|
|
Game::Com_SkipRestOfLine(&buffer);
|
|
|
|
}
|
2022-06-30 15:37:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Game::Com_EndParseSession();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
__declspec(naked) bool VisionFile::LoadVisionSettingsFromBuffer_Stub()
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
2022-07-23 16:16:26 -04:00
|
|
|
push eax
|
|
|
|
pushad
|
|
|
|
|
|
|
|
push [esp + 0x24 + 0x8] // settings
|
2022-06-30 15:37:47 -04:00
|
|
|
push ebx // filename
|
2022-07-23 16:16:26 -04:00
|
|
|
push [esp + 0x24 + 0xC] // buffer
|
|
|
|
call LoadVisionSettingsFromBuffer
|
2022-06-30 15:37:47 -04:00
|
|
|
add esp, 0xC
|
|
|
|
|
2022-07-23 16:16:26 -04:00
|
|
|
mov [esp + 0x20], eax
|
|
|
|
popad
|
|
|
|
pop eax
|
|
|
|
|
2022-06-30 15:37:47 -04:00
|
|
|
ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VisionFile::VisionFile()
|
|
|
|
{
|
|
|
|
AssertSize(Game::visField_t, 12);
|
|
|
|
|
|
|
|
// Place hook in LoadVisionFile function
|
|
|
|
Utils::Hook(0x59A98A, LoadVisionSettingsFromBuffer_Stub, HOOK_CALL).install()->quick();
|
|
|
|
}
|
|
|
|
}
|