Skip to content

Commit

Permalink
add support for double value type
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomGamers committed May 24, 2022
1 parent 42e90c4 commit cf8e194
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion SUWSF.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Pattern="39 8E E3 3F"
Offset=0
; Value to write. Numbers or variables (aspectratio, width, height) are accepted. Bytes are accepted if ValueType="byte"
Value="aspectratio"
; Type of value. Accepted values are: "float", "int", "byte" (default: "float")
; Type of value. Accepted values are: "float", "double", "int", "byte" (default: "float")
ValueType="float"
; Which match to write to. Accepted values are: number of match (starting from 1), last, all. (default: "all")
Match="all"
Expand Down
13 changes: 9 additions & 4 deletions SUWSF/GenericPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::vector<GenericPatch::Config> GenericPatch::GetConfigs()
{
DBOUT("ValueType=" << params.second);
config.valType = params.second;
if (config.valType != "float" && config.valType != "byte" && config.valType != "int")
if (config.valType != "float" && config.valType != "byte" && config.valType != "int" && config.valType != "double")
{
DBOUT("ValueType unsupported. Supported types are: float, byte...Skipping patch...");
goto CONTINUE;
Expand Down Expand Up @@ -104,15 +104,15 @@ std::vector<GenericPatch::Config> GenericPatch::GetConfigs()
DBOUT("No pattern found, skipping patch...");
goto CONTINUE;
}
if (config.valType == "float" || config.valType == "int")
if (config.valType == "float" || config.valType == "int" || config.valType == "double")
{
try
{
boost::replace_all(config.val, "width", std::to_string(UserSettings::config.width));
boost::replace_all(config.val, "height", std::to_string(UserSettings::config.height));
boost::replace_all(config.val, "aspectratio", std::to_string(UserSettings::config.aspectratio));
int error = -1;
float f = te_interp(config.val.c_str(), &error);
double d = te_interp(config.val.c_str(), &error);

if (error != 0)
{
Expand All @@ -122,13 +122,18 @@ std::vector<GenericPatch::Config> GenericPatch::GetConfigs()

if (config.valType == "float")
{
float f = static_cast<float>(d);
config.val = hexStr(reinterpret_cast<BYTE*>(&f), sizeof(float));
}
else if (config.valType == "int")
{
int i = static_cast<int>(f);
int i = static_cast<int>(d);
config.val = hexStr(reinterpret_cast<BYTE*>(&i), sizeof(int));
}
else if (config.valType == "double")
{
config.val = hexStr(reinterpret_cast<BYTE*>(&d), sizeof(double));
}
}
catch (std::exception const& e)
{
Expand Down
2 changes: 1 addition & 1 deletion SUWSF/UserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void UserSettings::SetConfig()
config.width = std::stoi(resStrings.at(0));
config.height = std::stoi(resStrings.at(1));
}
config.aspectratio = (float)config.width / config.height;
config.aspectratio = (double)config.width / config.height;
DBOUT("Detected width is " << config.width);
DBOUT("Detected height is " << config.height);
DBOUT("Detected aspect ratio is " << config.aspectratio);
Expand Down
2 changes: 1 addition & 1 deletion SUWSF/UserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UserSettings
struct Config
{
int width, height;
float aspectratio;
double aspectratio;
bool enabled = true;
};
static Config config;
Expand Down

0 comments on commit cf8e194

Please sign in to comment.