CheatMenuSA/src/filehandler.cpp

183 lines
6.1 KiB
C++
Raw Normal View History

2021-10-24 18:08:00 -04:00
#include "pch.h"
2021-10-25 10:03:27 -04:00
#include "filehandler.h"
// TODO: Clean up this mess, use structures instead?
void FileHandler::GenerateHandlingFile(tHandlingData *pHandling, std::map<int, std::string>& storeMap)
{
2022-01-07 03:18:00 -05:00
FILE* fp = fopen("handling.txt", "w");
std::string handlingId = storeMap[FindPlayerPed()->m_pVehicle->m_nModelIndex];
float mass = pHandling->m_fMass;
float turnMass = pHandling->m_fTurnMass;
float dragMult = pHandling->m_fDragMult;
CVector centreOfMass = pHandling->m_vecCentreOfMass;
int percentSubmerged = pHandling->m_nPercentSubmerged;
float tractionMultiplier = pHandling->m_fTractionMultiplier;
float tractionLoss = pHandling->m_fTractionLoss;
float tractionBias = pHandling->m_fTractionBias;
float engineAcceleration = pHandling->m_transmissionData.m_fEngineAcceleration * 12500;
float engineInertia = pHandling->m_transmissionData.m_fEngineInertia;
int driveType = pHandling->m_transmissionData.m_nDriveType;
int engineType = pHandling->m_transmissionData.m_nEngineType;
float brakeDeceleration = pHandling->m_fBrakeDeceleration * 2500;
float brakeBias = pHandling->m_fBrakeBias;
int abs = pHandling->m_bABS;
float steeringLock = pHandling->m_fSteeringLock;
float susForceLevel = pHandling->m_fSuspensionForceLevel;
float susDampingLevel = pHandling->m_fSuspensionDampingLevel;
float susHighSpdComDamp = pHandling->m_fSuspensionHighSpdComDamp;
float susUpperLimit = pHandling->m_fSuspensionUpperLimit;
float susLowerLimit = pHandling->m_fSuspensionLowerLimit;
float susBias = pHandling->m_fSuspensionBiasBetweenFrontAndRear;
float antiDiveMul = pHandling->m_fSuspensionAntiDiveMultiplier;
float cdm = pHandling->m_fCollisionDamageMultiplier / (2000.0f * (1.0 / mass));
int monetaryValue = pHandling->m_nMonetaryValue;
int maxVelocity = pHandling->m_transmissionData.m_fMaxGearVelocity / *(float*)0xC2B9BC;
int modelFlags = pHandling->m_nModelFlags;
int handlingFlags = pHandling->m_nHandlingFlags;
int frontLight = pHandling->m_nFrontLights;
int rearLight = pHandling->m_nRearLights;
int animGrp = pHandling->m_nAnimGroup;
int numGears = pHandling->m_transmissionData.m_nNumberOfGears;
float seatOffsetDistance = pHandling->m_fSeatOffsetDistance;
2022-01-07 03:18:00 -05:00
// TODO: make this more readable
fprintf(
fp,
"\n%s\t%.5g\t%.5g\t%.5g\t%.5g\t%.5g\t%.5g\t%d\t%.5g\t%.5g\t%.5g\t%d\t%d\t%.5g\t%.5g\t%c\t%c\t%.5g\t%.5g\t%d\t%.5g\t%.5g\t%.5g\t%.5g\t%.5g\t%.5g\t%.5g\t%.5g\t%.5g\t%.5g\t%d\t%x\t%x\t%d\t%d\t%d",
handlingId.c_str(), mass, turnMass, dragMult, centreOfMass.x, centreOfMass.y, centreOfMass.z, percentSubmerged,
tractionMultiplier, tractionLoss, tractionBias, numGears,
maxVelocity, engineAcceleration, engineInertia, driveType, engineType, brakeDeceleration, brakeBias, abs,
steeringLock, susForceLevel, susDampingLevel,
susHighSpdComDamp, susUpperLimit, susLowerLimit, susBias,
antiDiveMul, seatOffsetDistance,
cdm, monetaryValue, modelFlags, handlingFlags, frontLight, rearLight,
animGrp);
2022-01-07 03:18:00 -05:00
fclose(fp);
}
2021-10-25 10:03:27 -04:00
void FileHandler::FetchColorData(std::vector<std::vector<float>>& storeVec)
{
2022-01-07 03:18:00 -05:00
std::string m_FilePath = GAME_PATH((char*)"/data/carcols.dat");
if (!std::filesystem::exists(m_FilePath))
{
gLog << "Carcols.dat not found";
return;
}
std::ifstream file(m_FilePath);
std::string line;
bool isCar, isCol;
int count = 0;
while (getline(file, line))
{
// skip commented & empty lines
if (line[0] == '#' || line == "")
{
continue;
}
// section blocks
if (line[0] == 'c' && line[1] == 'a' && line[2] == 'r')
{
isCar = true;
continue;
}
if (line[0] == 'c' && line[1] == 'o' && line[2] == 'l')
{
isCol = true;
continue;
}
if (line[0] == 'e' && line[1] == 'n' && line[2] == 'd')
{
isCar = false;
isCol = false;
continue;
}
if (isCol)
{
try
{
std::string temp;
std::stringstream ss(line);
// fix one instance where . is used instead of ,
std::replace(temp.begin(), temp.end(), '.', ',');
// Format: red, green, blue
int r,g,b;
getline(ss, temp, ',');
r = std::stoi(temp);
getline(ss, temp, ',');
g = std::stoi(temp);
getline(ss, temp, ',');
b = std::stoi(temp);
storeVec.push_back({r / 255.0f, g / 255.0f, b / 255.0f});
++count;
}
catch (...)
{
gLog << "Error parsing carcols.dat, " << line << std::endl;
}
}
}
file.close();
2021-12-24 05:36:07 -05:00
}
void FileHandler::FetchHandlingID(std::map<int, std::string>& storeMap)
{
2022-01-07 03:18:00 -05:00
std::string m_FilePath = GAME_PATH((char*)"/data/vehicles.ide");
if (!std::filesystem::exists(m_FilePath))
{
2021-09-20 08:41:40 -04:00
gLog << "Vehicle.ide not found";
2022-01-07 03:18:00 -05:00
return;
}
std::ifstream file(m_FilePath);
std::string line;
while (getline(file, line))
{
/*
Format: model, modelname, txdname, type, handlingId, ...
Skip if first thing isn't model id
*/
if (line[0] <= '0' || line[0] >= '9')
{
continue;
}
// running inside try block to handle user errors, mostly commas
try
{
std::string temp;
std::stringstream ss(line);
// get model
getline(ss, temp, ',');
int model = std::stoi(temp);
// get modelname, txd, type, handlingId
getline(ss, temp, ',');
getline(ss, temp, ',');
getline(ss, temp, ',');
getline(ss, temp, ',');
temp.erase(std::remove_if(temp.begin(), temp.end(), isspace), temp.end());
storeMap[model] = temp;
}
catch (...)
{
gLog << "Error parsing vehicles.ide, " << line << std::endl;
}
}
2021-12-24 05:36:07 -05:00
2022-01-07 03:18:00 -05:00
file.close();
}