CheatMenuSA/src/filehandler.cpp

203 lines
6.8 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"
#ifdef GTASA
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);
}
void FileHandler::FetchHandlingID(std::map<int, std::string>& storeMap)
{
2022-06-16 16:42:57 -04:00
const char* path = GAME_PATH((char*)"/data/vehicles.ide");
if (!std::filesystem::exists(path))
{
2022-06-15 06:45:43 -04:00
Log::Print<eLogLevel::Warn>("Vehicle.ide not found");
return;
}
2022-06-16 16:42:57 -04:00
FILE *pFile= fopen(path, "r");
if (pFile != NULL)
{
2022-06-16 16:42:57 -04:00
static const uint8_t bufSize = 128;
char buf[bufSize];
while (fgets(buf, bufSize, pFile) != NULL)
{
2022-06-16 16:42:57 -04:00
if (buf[0] == 'e' && buf[1] == 'n' && buf[2] == 'd')
{
break;
}
2022-06-16 16:42:57 -04:00
if (buf[0] < '0' || buf[0] > '9')
{
continue;
}
// replace comma and remove tabs
uint8_t sz = bufSize;
for(uint8_t i = 0; i < sz; ++i)
{
if (buf[i] == ',')
{
buf[i] = ' ';
continue;
}
if (buf[i] == ' ' || buf[i] == '\t' )
{
for(uint8_t j = i; j < sz; ++j)
{
buf[j] = buf[j+1];
}
--sz;
}
}
2022-06-16 16:42:57 -04:00
int id;
char model[32], txd[32], type[32], handling[32];
if (sscanf(buf, "%d %s %s %s %s", &id, model, txd, type, handling) == 5)
{
// storeMap[id] = std::string(handling);
}
}
2022-06-16 16:42:57 -04:00
fclose(pFile);
}
2022-06-16 16:42:57 -04:00
// 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 (...)
// {
// Log::Print<eLogLevel::Warn>("Failed parsing vehicles.ide, {}", line);
// }
// }
// file.close();
}
#endif
2021-10-25 10:03:27 -04:00
void FileHandler::FetchColorData(std::vector<std::vector<float>>& storeVec)
{
2022-06-16 16:42:57 -04:00
const char* path = GAME_PATH((char*)"/data/carcols.dat");
if (!std::filesystem::exists(path))
2022-01-07 03:18:00 -05:00
{
2022-06-15 06:45:43 -04:00
Log::Print<eLogLevel::Warn>("Carcols.dat not found");
2022-01-07 03:18:00 -05:00
return;
}
2022-06-16 16:42:57 -04:00
FILE *pFile= fopen(path, "r");
if (pFile != NULL)
2022-01-07 03:18:00 -05:00
{
2022-06-16 16:42:57 -04:00
static const uint8_t bufSize = 16;
char buf[bufSize];
while (fgets(buf, bufSize, pFile) != NULL)
2022-01-07 03:18:00 -05:00
{
2022-06-16 16:42:57 -04:00
if (buf[0] == '#' || buf[0] == '\n')
2022-01-07 03:18:00 -05:00
{
2022-06-16 16:42:57 -04:00
continue;
}
2022-01-07 03:18:00 -05:00
2022-06-16 16:42:57 -04:00
if (buf[0] == 'e' && buf[1] == 'n' && buf[2] == 'd')
{
break;
}
2022-01-07 03:18:00 -05:00
2022-06-16 16:42:57 -04:00
// replace comma and dots with spaces
for(uint8_t i = 0; i < bufSize; ++i)
{
if (buf[i] == ',' || buf[i] == '.')
{
buf[i] = ' ';
}
2022-01-07 03:18:00 -05:00
}
2022-06-16 16:42:57 -04:00
int r = 0, g = 0, b = 0;
if (sscanf(buf, "%d %d %d", &r, &g, &b) == 3)
2022-01-07 03:18:00 -05:00
{
2022-06-16 16:42:57 -04:00
storeVec.push_back({r / 255.0f, g / 255.0f, b / 255.0f});
2022-01-07 03:18:00 -05:00
}
}
2022-06-16 16:42:57 -04:00
fclose(pFile);
2022-01-07 03:18:00 -05:00
}
2021-12-24 05:36:07 -05:00
}