#include #include #include #include #include #include #include #include "gk/structs/manager.h" #include "gk/structs/validity.h" #include "game/validity.h" #include "game/nui_elevation.h" using gk::LiveManager; using gk::SkeletonData; using gk::SkeletonTrackingState; using gk::Vec3; using gk::game::BoxDistanceSquared; using gk::game::ElevationThread; using gk::game::ICameraElevation; using gk::game::UpdateCameraElevation; using gk::game::UpdateValidityCandidates; using gk::game::ValidityState; namespace { std::vector ReadHex() { std::vector out; std::string digits; int c = 0; while ((c = std::getchar()) != EOF) { if (std::isxdigit(c) != 0) { digits.push_back(static_cast(c)); } } for (std::size_t i = 0; i + 1 < digits.size(); i += 2) { out.push_back(static_cast( std::strtol(digits.substr(i, 2).c_str(), nullptr, 16))); } return out; } void PutHex(const void* data, std::size_t size) { const auto* bytes = static_cast(data); for (std::size_t i = 0; i < size; ++i) { std::printf("%02x", bytes[i]); } std::printf("\n"); } class ScriptedSensor final : public ICameraElevation { public: ScriptedSensor(std::int32_t angle, std::int32_t status) : angle_(angle), status_(status) {} std::int32_t GK_STDCALL GetAngle(std::int32_t* out_degrees) override { ++get_calls_; *out_degrees = angle_; return status_; } std::int32_t GK_STDCALL SetAngle(std::int32_t degrees) override { ++set_calls_; set_arg_ = degrees; return 0; } std::int32_t get_calls_ = 0; std::int32_t set_calls_ = 0; std::int32_t set_arg_ = 0; private: std::int32_t angle_; std::int32_t status_; }; float ReadFloat(const std::uint8_t* p) { float v = 0.0F; std::memcpy(&v, p, 4); return v; } std::uint32_t ReadU32(const std::uint8_t* p) { std::uint32_t v = 0; std::memcpy(&v, p, 4); return v; } int RunBox(const std::vector& in) { gk::ValidityBox box{}; Vec3 point{}; std::memcpy(&box, in.data(), sizeof(box)); std::memcpy(&point, in.data() + sizeof(box), sizeof(point)); const float result = BoxDistanceSquared(box, point); PutHex(&result, sizeof(result)); return 0; } int RunElev(const std::vector& in) { const auto* p = in.data(); ElevationThread thread{}; thread.desired_angle = static_cast(ReadU32(p + 0)); thread.applied_angle = static_cast(ReadU32(p + 4)); thread.smoothed_angle = static_cast(ReadU32(p + 8)); thread.accumulator = static_cast(ReadU32(p + 12)); const auto angle = static_cast(ReadU32(p + 16)); const auto status = static_cast(ReadU32(p + 20)); ScriptedSensor sensor(angle, status); thread.sensor = &sensor; UpdateCameraElevation(thread); std::uint8_t out[28]; std::memcpy(out + 0, &thread.desired_angle, 4); std::memcpy(out + 4, &thread.applied_angle, 4); std::memcpy(out + 8, &thread.smoothed_angle, 4); std::memcpy(out + 12, &thread.accumulator, 4); std::memcpy(out + 16, &sensor.set_calls_, 4); std::memcpy(out + 20, &sensor.set_arg_, 4); std::memcpy(out + 24, &sensor.get_calls_, 4); PutHex(out, sizeof(out)); return 0; } int RunGate(const std::vector& in) { const auto* p = in.data(); std::size_t off = 0; ValidityState state{}; std::memcpy(&state.transform, p + off, sizeof(state.transform)); off += sizeof(state.transform); std::memcpy(&state.box, p + off, sizeof(state.box)); off += sizeof(state.box); std::memcpy(&state.missing_position, p + off, sizeof(state.missing_position)); off += sizeof(state.missing_position); state.entry_tolerance = ReadFloat(p + off); off += 4; state.retained_tolerance = ReadFloat(p + off); off += 4; const std::uint8_t synthetic = p[off]; off += 1; LiveManager manager{}; std::memset(&manager, 0, sizeof(LiveManager)); manager.synthetic_tracking_mode = synthetic; for (std::size_t i = 0; i < gk::kSkeletonCount; ++i) { SkeletonData& skel = manager.skeleton_frame.skeletons[i]; skel.tracking_state = static_cast(ReadU32(p + off)); off += 4; skel.tracking_id = ReadU32(p + off); off += 4; skel.position.x = ReadFloat(p + off); off += 4; skel.position.y = ReadFloat(p + off); off += 4; skel.position.z = ReadFloat(p + off); off += 4; } for (std::size_t i = 0; i < gk::kSkeletonCount; ++i) { std::uint32_t id = ReadU32(p + off); off += 4; std::memcpy(&state.candidates[i].tracking_id, &id, 4); state.candidates[i].valid = p[off]; off += 1; } UpdateValidityCandidates(manager, state); PutHex(state.candidates, sizeof(state.candidates)); return 0; } } int main(int argc, char** argv) { if (argc < 2) { std::fprintf(stderr, "usage: recon \n"); return 2; } const std::vector in = ReadHex(); const std::string mode = argv[1]; if (mode == "box") { return RunBox(in); } if (mode == "elev") { return RunElev(in); } if (mode == "gate") { return RunGate(in); } std::fprintf(stderr, "unknown mode %s\n", argv[1]); return 2; }