Optimize Auto Databank code

This commit is contained in:
nastys
2025-03-05 21:49:41 +01:00
parent cf26061123
commit b20fc255dc
3 changed files with 35 additions and 52 deletions
+29 -34
View File
@@ -1,6 +1,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include "databank.h"
#include "urlutil.h"
@@ -33,14 +34,14 @@ namespace Databank
try
{
PvEntry entry;
entry.id = std::stoi(tokens[i]);
int id = std::stoi(tokens[i]);
entry.unk1 = std::stoi(tokens[i + 1]);
entry.unk2 = std::stoi(tokens[i + 2]);
entry.advStart = tokens[i + 3];
entry.advEnd = tokens[i + 4];
entry.start = tokens[i + 5];
entry.end = tokens[i + 6];
entries.insert(entry);
entries.insert({ id, entry });
}
catch (const std::exception& e)
{
@@ -73,19 +74,39 @@ namespace Databank
}
}
bool PvList::finalize()
void PvList::addEntry(int id, PvEntry& entry)
{
entries.insert({ id, entry });
}
void PvList::generateMissingEntries()
{
PvEntry entry = PvEntry();
for (int i = 0; i <= 999; i++)
{
entry.advStart = "2000-01-01";
entry.advEnd = "2029-01-01";
entry.start = "2000-01-01";
entry.end = "2029-01-01";
entries.insert({ i, entry });
}
}
std::string PvList::finalize()
{
std::ostringstream csvStream;
if (entries.empty())
{
finalString = "%2A%2A%2A"; // ***
return "%2A%2A%2A"; // ***
//checksum = "5341";
}
else
{
bool first = true;
for (const auto& entry : entries)
for (const auto& entryMap : entries)
{
std::ostringstream entryStream;
if (!first)
@@ -93,7 +114,8 @@ namespace Databank
csvStream << ",";
}
first = false;
entryStream << entry.id << ","
const PvEntry& entry = entryMap.second;
entryStream << entryMap.first << ","
<< entry.unk1 << ","
<< entry.unk2 << ","
<< entry.advStart << ","
@@ -103,35 +125,8 @@ namespace Databank
csvStream << urlEncode(entryStream.str());
}
finalString = urlEncode(csvStream.str());
return urlEncode(csvStream.str());
//checksum = std::to_string(crc16_ccitt(finalString));
}
return true;
}
void PvList::copyCstrData(char* dst)
{
strcpy_s((char*)dst, finalString.size(), finalString.c_str());
}
void PvList::addEntry(PvEntry& entry)
{
entries.insert(entry);
}
void PvList::generateMissingEntries()
{
PvEntry entry = PvEntry();
for (int i = 0; i <= 999; i++)
{
entry.id = i;
entry.advStart = "2000-01-01";
entry.advEnd = "2029-01-01";
entry.start = "2000-01-01";
entry.end = "2029-01-01";
entries.insert(entry);
}
}
}
+4 -16
View File
@@ -1,7 +1,5 @@
#pragma once
#include <chrono>
#include <set>
#include <vector>
#include <map>
#include "databank.h"
@@ -9,31 +7,21 @@ namespace Databank
{
struct PvEntry
{
int id = -1;
int unk1 = 1;
int unk2 = 0;
std::string advStart, advEnd, start, end;
bool operator<(const PvEntry& other) const
{
return id < other.id;
}
};
class PvList
{
protected:
std::set<PvEntry> entries;
std::map<int, PvEntry> entries;
public:
std::string finalString = std::string();
//std::string checksum = std::string();
bool readFromStr(std::string& str);
bool readFromFile(const std::string& filename);
bool finalize();
void copyCstrData(char* dst);
void addEntry(PvEntry& entry);
void addEntry(int id, PvEntry& entry);
void generateMissingEntries();
std::string finalize();
};
}
@@ -290,9 +290,9 @@ void hookedPvListInitializer(void* pvListContainer)
}
if (i != 4) lists[i].generateMissingEntries();
lists[i].finalize();
std::string finalString = lists[i].finalize();
Storage::customAddStringContainer(&records[i], lists[i].finalString.c_str());
Storage::customAddStringContainer(&records[i], finalString.c_str());
}
*(uint8_t*)(0x140CDB1D9) = 0x01; // enables databank