Last active
August 29, 2015 14:23
-
-
Save YaLTeR/b07e3d0afcda3556c1a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iomanip> | |
#include <iostream> | |
#include <cstdint> | |
#include <vector> | |
#include <intrin.h> | |
const double M_PI = 3.14159265358979323846; | |
// Stolen from HLSDK, added the roll calculation. | |
void VectorAngles(const float forward[3], const float right[3], double angles[3]) | |
{ | |
double tmp, yaw, pitch, roll; | |
if (forward[1] == 0 && forward[0] == 0) { | |
yaw = 0; | |
if (forward[2] > 0) | |
pitch = 90; | |
else | |
pitch = 270; | |
} else { | |
yaw = (std::atan2(forward[1], forward[0]) * 180 / M_PI); | |
if (yaw < 0) | |
yaw += 360; | |
tmp = std::sqrt(forward[0] * forward[0] + forward[1] * forward[1]); | |
pitch = (std::atan2(-forward[2], tmp) * 180 / M_PI); | |
if (pitch < 0) | |
pitch += 360; | |
tmp = std::sqrt(right[0] * right[0] + right[1] * right[1]); | |
roll = (std::atan2(right[2], tmp) * 180 / M_PI); | |
if (roll < 0) | |
roll += 360; | |
} | |
angles[0] = pitch; | |
angles[1] = yaw; | |
angles[2] = roll; | |
} | |
void ScanFrame(const unsigned char frame[147]) | |
{ | |
uint32_t fOrigin[3]; | |
std::memcpy(fOrigin, frame + 0x62, sizeof(fOrigin)); | |
fOrigin[0] = _byteswap_ulong(fOrigin[0]); | |
fOrigin[1] = _byteswap_ulong(fOrigin[1]); | |
fOrigin[2] = _byteswap_ulong(fOrigin[2]); | |
float *origin = reinterpret_cast<float*>(fOrigin); | |
std::cout << "Origin: " << origin[0] << " " << origin[1] << " " << origin[2] << "\t"; | |
uint32_t fFOV[2]; | |
std::memcpy(fFOV, frame + 0x18, sizeof(fFOV)); | |
fFOV[0] = _byteswap_ulong(fFOV[0]); | |
fFOV[1] = _byteswap_ulong(fFOV[1]); | |
float *FOV = reinterpret_cast<float*>(fFOV); | |
std::cout << "FOV: " << FOV[0] << " " << FOV[1] << "\t"; | |
uint32_t fVectors[9]; | |
std::memcpy(fVectors, frame + 0x6e, sizeof(fVectors)); | |
for (int i = 0; i < 9; ++i) fVectors[i] = _byteswap_ulong(fVectors[i]); | |
float *forward = reinterpret_cast<float*>(fVectors), | |
*right = reinterpret_cast<float*>(&fVectors[3]), | |
*up = reinterpret_cast<float*>(&fVectors[6]); | |
double angles[3]; | |
VectorAngles(forward, right, angles); | |
std::cout << "Angles: " << angles[0] << " " << angles[1] << " " << angles[2]; | |
std::cout << "\n"; | |
} | |
int main(int argc, char *argv[]) { | |
if (argc != 2) { | |
std::cerr << "Usage: tool.exe <filename>\n"; | |
return 1; | |
} | |
std::ifstream in(argv[1], std::ios::binary); | |
if (!in.is_open()) { | |
std::cerr << "Error opening the input file.\n"; | |
return 1; | |
} | |
in.seekg(0, std::ios::end); | |
std::size_t size = in.tellg(); | |
if (size <= 4 || (size - 4) % 147) { | |
std::cout << "Wrong file size: size <= 4 or (size - 4) not divisible by 147!\n"; | |
return 1; | |
} | |
in.seekg(0, std::ios::beg); | |
std::vector<char> buf(size); | |
std::copy(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>(), buf.begin()); | |
uint32_t unk; | |
std::memcpy(&unk, buf.data(), 4); | |
std::cout << "First 4 bytes: " << std::hex << unk << std::dec << std::fixed << std::setprecision(6) << "\n"; | |
int lines = 0; | |
std::size_t bytesread = 4; | |
while (bytesread < size) { | |
char frame[147]; | |
std::memcpy(frame, buf.data() + bytesread, 147); | |
std::cout << "Frame " << lines << ":\t"; | |
ScanFrame(reinterpret_cast<const unsigned char*>(frame)); | |
bytesread += 147; | |
lines++; | |
} | |
std::system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment