/
VehicleRecordingTool.cpp
143 lines (105 loc) · 3.03 KB
/
VehicleRecordingTool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/
#include "StdInc.h"
#include "ToolComponentHelpers.h"
#include "IteratorView.h"
#include <boost/filesystem.hpp>
#define RAGE_FORMATS_GAME five
#define RAGE_FORMATS_GAME_FIVE
#include <pgBase.h>
#include <pgContainers.h>
struct VehicleRecordingEntry : public rage::five::pgStreamableBase
{
uint32_t time;
uint16_t vel[3];
uint8_t right[3];
uint8_t up[3];
uint8_t steeringAngle;
uint8_t gasPower;
uint8_t brakePower;
uint8_t handbrake;
float pos[3];
};
class VehicleRecordingFile : public rage::five::pgBase
{
private:
rage::five::pgArray<VehicleRecordingEntry> m_entries;
public:
inline void SetEntries(uint16_t count, VehicleRecordingEntry* entries)
{
m_entries.SetFrom(entries, count);
}
};
static void DoFile(const boost::filesystem::path& path)
{
static_assert(sizeof(VehicleRecordingEntry) == 32, "size");
std::wstring fileNameStr = path.wstring();
const wchar_t* fileName = fileNameStr.c_str();
FILE* f = _wfopen(fileName, L"rb");
if (!f)
{
wprintf(L"couldn't open input file %s...\n", path.filename().c_str());
return;
}
std::vector<VehicleRecordingEntry> entries;
fseek(f, 0, SEEK_END);
entries.resize(ftell(f) / sizeof(VehicleRecordingEntry));
fseek(f, 0, SEEK_SET);
fread(&entries[0], sizeof(VehicleRecordingEntry), entries.size(), f);
fclose(f);
auto bm = rage::five::pgStreamManager::BeginPacking();
auto file = new(false) VehicleRecordingFile();
file->SetBlockMap();
file->SetEntries(entries.size(), &entries[0]);
rage::five::pgStreamManager::EndPacking();
std::wstring outFileName(fileName);
outFileName = outFileName.substr(0, outFileName.length() - 3) + L"yvr";
f = _wfopen(outFileName.c_str(), L"wb");
if (!f)
{
printf("... couldn't open output file for writing.\n");
return;
}
size_t outputSize = 0;
bm->Save(1, [&](const void* d, size_t s)
{
fwrite(d, 1, s, f);
outputSize += s;
});
printf("written successfully - compressed size %zu\n", outputSize);
fclose(f);
for (int i = 0; i < bm->physicalLen + bm->virtualLen; i++)
{
delete bm->blocks[i].data;
}
delete bm;
}
static void HandleArguments(boost::program_options::wcommand_line_parser& parser, std::function<void()> cb)
{
boost::program_options::options_description desc;
desc.add_options()
("filename", boost::program_options::value<std::vector<boost::filesystem::path>>()->required(), "The path of the file to convert.");
boost::program_options::positional_options_description positional;
positional.add("filename", -1);
parser.options(desc).
positional(positional);
cb();
}
static void Run(const boost::program_options::variables_map& map)
{
if (map.count("filename") == 0)
{
printf("Usage:\n\n fivem tool:vehrec *.rrr...\n");
return;
}
auto& entries = map["filename"].as<std::vector<boost::filesystem::path>>();
for (auto& filePath : entries)
{
DoFile(filePath);
}
}
static FxToolCommand command("tool:vehrec", HandleArguments, Run);