- 변환기 Crosshair.cs: BombPlayerState 에 복제된 선수 조준점 프로필(주 · 정조준 · 저격 점 · 이름)을 두 번째 읽기로 읽어 players[].crosshair (바뀐 시각마다 전체 설정). 첫 읽기 필드 목록으로 번호를 찾고 패치로 밀려도 이름이 맞는 자리를 찾는다. --fields 디버그, --self-test 에 자리 찾기 · 기본색 검사 - 사이트 lib/crosshair.ts 그리기 · 발로란트 조준점 코드 읽기, CrosshairPanel: 선수 조준점(없으면 내 조준점) / 모든 선수에 내 조준점, 직접 고치기 · 코드 가져오기 · 선수 조준점 복사 - 1인칭: 정조준 조준점 · 저격 조준경 가운데 점 · 사격/이동 오차로 벌어짐 - 앱 1.8.2 (버전이 바뀌면 리플레이를 다시 변환해 조준점이 생긴다) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
147 lines
7.2 KiB
C#
147 lines
7.2 KiB
C#
// gvr-replay: 발로란트 리플레이(.vrf) → 사이트 재생기용 JSON (형식 gvr-replay v2)
|
|
// gvr-replay <file.vrf> <out.json> [--hz 10]
|
|
// gvr-replay <file.vrf> --stats (디버그: 액터 종류별 개수)
|
|
// gvr-replay <file.vrf> --fields (디버그: 복제 필드 목록 <경로\t이름>, 번호 순)
|
|
// gvr-replay --self-test (회귀 검사: 무기 주인 시간표 · 조준점 필드 자리)
|
|
// 성공하면 종료 코드 0 과 함께 stdout 마지막 줄에 {"ok":true,...} 요약을 쓴다. 실패는 1 과 {"ok":false,"error":...}
|
|
using System.Diagnostics;
|
|
using System.Text.Json;
|
|
using Replay.Encoding.Archives;
|
|
using Replay.Models.Descriptors;
|
|
using Replay.Valorant;
|
|
using Replay.Valorant.Events;
|
|
|
|
namespace GvrReplay;
|
|
|
|
public static class Program
|
|
{
|
|
/// <summary>회귀 검사 (리플레이 파일 없이): 무기를 넘겨받아도 넘기기 전 상태는 이전 주인 것</summary>
|
|
private static int SelfTest()
|
|
{
|
|
var fails = new List<string>();
|
|
void Eq(string name, int got, int want)
|
|
{
|
|
if (got != want) fails.Add($"{name}: {got} (기대 {want})");
|
|
}
|
|
// 선수 0 이 1초에 들고 2초에 재장전, 10초에 선수 1 이 주움
|
|
var o = EquipOwners.Build([(1000, 7u, 0), (10000, 7u, 1)]);
|
|
Eq("주기 전 재장전(2초)", EquipOwners.At(o, 7, 2000), 0);
|
|
Eq("주운 순간(10초)", EquipOwners.At(o, 7, 10000), 1);
|
|
Eq("주운 뒤(12초)", EquipOwners.At(o, 7, 12000), 1);
|
|
Eq("첫 기록 전(0.5초)", EquipOwners.At(o, 7, 500), 0);
|
|
Eq("기록 없는 장비", EquipOwners.At(o, 8, 2000), -1);
|
|
// 같은 시각 순서가 뒤섞여 들어와도 시간 순으로
|
|
var o2 = EquipOwners.Build([(5000, 9u, 2), (1000, 9u, 3)]);
|
|
Eq("순서 섞임(3초)", EquipOwners.At(o2, 9, 3000), 3);
|
|
Eq("순서 섞임(6초)", EquipOwners.At(o2, 9, 6000), 2);
|
|
// 선수를 모르는 기록(-1)은 건너뛴다
|
|
var o3 = EquipOwners.Build([(1000, 4u, 5), (2000, 4u, -1)]);
|
|
Eq("모르는 선수 건너뜀", EquipOwners.At(o3, 4, 3000), 5);
|
|
// 조준점 필드 자리: 13.08 번호 그대로 · 앞에 필드가 2개 늘어난 패치 · 이름이 어긋나면 못 찾음
|
|
Dictionary<int, string> Names(int b) => new()
|
|
{
|
|
[b] = "B", [b + 8] = "bUseCustomColor", [b + 23] = "LineThickness", [b + 35] = "LineThickness",
|
|
[b + 70] = "LineThickness", [b + 153] = "bUsePrimaryCrosshairForADS", [b + 158] = "ProfileName", [b - 13] = "AssignedTeamState",
|
|
};
|
|
Eq("조준점 자리 13.08", Crosshair.FindBase(Names(39)) ?? -1, 39);
|
|
Eq("조준점 자리 +2", Crosshair.FindBase(Names(41)) ?? -1, 41);
|
|
var wrong = Names(39);
|
|
wrong[39 + 23] = "LineOffset";
|
|
Eq("조준점 이름 어긋남", Crosshair.FindBase(wrong) ?? -1, -1);
|
|
// 기본값: 오지 않은 색은 흰색, 사용자 지정 색을 쓰면 그 색
|
|
var cs = Crosshair.Snapshot(0, new Dictionary<string, object> { ["p.cb"] = 0, ["p.cg"] = 0, ["a.useCustom"] = true, ["a.ur"] = 0 });
|
|
if (cs.Primary.Color != "#ff0000") fails.Add($"주 조준점 색: {cs.Primary.Color} (기대 #ff0000)");
|
|
if (cs.Ads.Color != "#00ffff") fails.Add($"정조준 사용자 지정 색: {cs.Ads.Color} (기대 #00ffff)");
|
|
foreach (var f in fails) Console.Error.WriteLine("FAIL " + f);
|
|
Console.WriteLine(JsonSerializer.Serialize(new { ok = fails.Count == 0, selfTest = true, failed = fails.Count }));
|
|
return fails.Count == 0 ? 0 : 1;
|
|
}
|
|
|
|
public static int Main(string[] args)
|
|
{
|
|
if (args.Length == 1 && args[0] == "--self-test") return SelfTest();
|
|
if (args.Length < 2)
|
|
{
|
|
Console.Error.WriteLine("사용법: gvr-replay <file.vrf> <out.json> [--hz 10] | gvr-replay <file.vrf> --stats");
|
|
return 2;
|
|
}
|
|
var input = args[0];
|
|
var stats = args[1] == "--stats";
|
|
var hz = 10;
|
|
for (var i = 2; i < args.Length - 1; i++)
|
|
if (args[i] == "--hz") hz = Math.Clamp(int.Parse(args[i + 1]), 1, 60);
|
|
try
|
|
{
|
|
var sw = Stopwatch.StartNew();
|
|
var collector = new Collector(1000 / hz);
|
|
using var file = File.OpenRead(input);
|
|
using var archive = new FBinaryArchive(file);
|
|
var enricher = new ValorantEventEnricher(collector);
|
|
// 진단 필드: 스킬 주인(Instigator) · 투사체 비행(ReplicatedMovement) · 무기 상태(CurrentState)를 페이로드 종류와 상관없이 읽는다
|
|
var profile = new ParseProfile { EnabledCategories = ExportCategory.All, CaptureDiagnosticFields = true };
|
|
var result = ValorantReplayReader.CreateDefault(null, enricher, profile).Read(archive);
|
|
enricher.Complete();
|
|
var info = result.Metadata.ReplayInfo;
|
|
if (args[1] == "--fields")
|
|
{
|
|
foreach (var g in result.ExportGroups)
|
|
foreach (var f in g.Fields)
|
|
Console.WriteLine(g.PathName + "\t" + f.Name);
|
|
return 0;
|
|
}
|
|
if (stats)
|
|
{
|
|
collector.PrintStats();
|
|
return 0;
|
|
}
|
|
var replay = collector.Build(
|
|
result.Metadata.ReplayVersion.Branch,
|
|
FDateTimeToUnixMs(info.Timestamp),
|
|
info.LengthInMs,
|
|
hz);
|
|
// 선수 조준점 (두 번째 읽기). 못 읽어도 나머지 변환은 그대로 쓴다
|
|
var crosshairs = 0;
|
|
try
|
|
{
|
|
foreach (var (state, list) in Crosshair.Read(input, result))
|
|
if (collector.SubjectOfState(state) is { } subject && replay.Players.FirstOrDefault(p => p.Puuid == subject) is { } pl)
|
|
{
|
|
pl.Crosshair = list;
|
|
crosshairs++;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.Error.WriteLine("조준점 읽기 실패: " + e.Message);
|
|
}
|
|
var tmp = args[1] + ".tmp";
|
|
using (var fs = File.Create(tmp))
|
|
JsonSerializer.Serialize(fs, replay, ReplayJson.Options);
|
|
File.Move(tmp, args[1], true);
|
|
Console.WriteLine(JsonSerializer.Serialize(new
|
|
{
|
|
ok = true,
|
|
matchId = replay.MatchId,
|
|
map = replay.Map,
|
|
build = replay.Build,
|
|
players = replay.Players.Count,
|
|
rounds = replay.Rounds.Count,
|
|
kills = replay.Kills.Count,
|
|
crosshairs,
|
|
elapsedMs = sw.ElapsedMilliseconds,
|
|
status = result.Status.ToString(),
|
|
warnings = result.TotalDiagnosticCount,
|
|
}));
|
|
return 0;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(JsonSerializer.Serialize(new { ok = false, error = e.GetType().Name + ": " + e.Message }));
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
/// UE FDateTime ticks (100ns, 0001-01-01 기준, UTC) → 유닉스 ms
|
|
public static long FDateTimeToUnixMs(long ticks) => ticks <= 0 ? 0 : (ticks - 621355968000000000L) / 10000L;
|
|
}
|