1인칭 조준점: 리플레이의 선수 조준점 · 사이트 전체 내 조준점 설정 · v1.8.2
- 변환기 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>
This commit is contained in:
@@ -62,6 +62,9 @@ public sealed partial class Collector(int sampleMs) : IReplayEventSink
|
||||
[GeneratedRegex(@"^Default__(GameObject_|Patch_|Pawn_|Projectile_|TimedBomb_C$)")]
|
||||
private static partial Regex ObjectClass();
|
||||
|
||||
/// PlayerState 액터 → 선수 puuid
|
||||
public string? SubjectOfState(uint state) => _subjectByState.GetValueOrDefault(state);
|
||||
|
||||
public void Emit(ReplayEvent e)
|
||||
{
|
||||
switch (e)
|
||||
|
||||
195
tools/replay-extract/src/Crosshair.cs
Normal file
195
tools/replay-extract/src/Crosshair.cs
Normal file
@@ -0,0 +1,195 @@
|
||||
using System.Text.Json;
|
||||
using Replay.Encoding.Archives;
|
||||
using Replay.Models.Descriptors;
|
||||
using Replay.Models.Events;
|
||||
using Replay.Unreal.Parsing;
|
||||
using Replay.Valorant;
|
||||
using Replay.Valorant.Descriptors;
|
||||
|
||||
namespace GvrReplay;
|
||||
|
||||
/// <summary>
|
||||
/// 선수 조준점 설정. BombPlayerState 에 선수마다 조준점 프로필(주 조준점 · 정조준 · 저격 조준경 · 프로필 이름)이 복제된다
|
||||
/// (관전자에게 보이는 조준점). 파서의 BombPlayerState 형식에는 이 필드가 없어서, 첫 번째 읽기에서 받은 필드 목록으로
|
||||
/// 번호(handle)를 찾고 이 필드만 읽는 두 번째 읽기를 한다.
|
||||
/// 필드는 기본값(색 흰색 255 · 숫자 0 · 끔)과 다를 때만 오고, 바뀐 필드만 다시 온다.
|
||||
/// </summary>
|
||||
public static class Crosshair
|
||||
{
|
||||
public const string StatePath = "/Game/GameModes/Bomb/BombPlayerState.BombPlayerState_C";
|
||||
// 13.08 · 13.09 에서 주 조준점 색(B)의 번호. 패치로 앞에 필드가 늘면 이름이 맞는 곳으로 옮겨 찾는다
|
||||
private const int KnownBase = 39;
|
||||
|
||||
private static readonly string[] Lines =
|
||||
[
|
||||
"LineThickness", "LineLength", "LineLengthVertical", "LineOffset", "bAllowVertScaling", "bShowMovementError",
|
||||
"bShowShootingError", "bShowMinError", "Opacity", "bShowLines", "FiringErrorScale", "MovementErrorScale",
|
||||
];
|
||||
private static readonly string?[] Cross =
|
||||
[
|
||||
"B", "G", "R", "A", "B", "G", "R", "A", "bUseCustomColor", "bHasOutline", "OutlineThickness", "B", "G", "R", "A",
|
||||
"OutlineOpacity", "CenterDotSize", "CenterDotOpacity", "bDisplayCenterDot", "bFadeCrosshairWithFiringError",
|
||||
"bShowSpectatedPlayerCrosshair", null, "bFixMinErrorAcrossWeapons", .. Lines, .. Lines,
|
||||
];
|
||||
private static readonly string?[] Sniper =
|
||||
[
|
||||
"B", "G", "R", "A", "B", "G", "R", "A", "CenterDotSize", "CenterDotOpacity", "bDisplayCenterDot", null,
|
||||
"bUsePrimaryCrosshairForADS", null, null, "bUseAdvancedOptions", null, "ProfileName",
|
||||
];
|
||||
|
||||
/// 기준 번호부터의 (이름, 열쇠). 세 번째 조준점 묶음(번호 94~140)은 값이 오는 것을 본 적이 없어 읽지 않는다
|
||||
private static readonly (string? Name, string? Key)[] Layout = BuildLayout();
|
||||
|
||||
private static (string?, string?)[] BuildLayout()
|
||||
{
|
||||
var o = new List<(string?, string?)>();
|
||||
string?[] lineKeys = ["thickness", "length", "vLength", "offset", "allowVert", "moveError", "fireError", "minError", "opacity", "on", "fireScale", "moveScale"];
|
||||
string?[] crossKeys =
|
||||
[
|
||||
"cb", "cg", "cr", null, "ub", "ug", "ur", null, "useCustom", "outline", "outlineThickness", null, null, null, null,
|
||||
"outlineOpacity", "dotSize", "dotOpacity", "dot", null, null, null, null,
|
||||
.. lineKeys.Select(k => "i." + k), .. lineKeys.Select(k => "o." + k),
|
||||
];
|
||||
foreach (var prefix in new[] { "p.", "a.", null })
|
||||
for (var i = 0; i < Cross.Length; i++)
|
||||
o.Add(prefix is null ? (null, null) : (Cross[i], crossKeys[i] is { } k ? prefix + k : null));
|
||||
string?[] sniperKeys = ["s.cb", "s.cg", "s.cr", null, null, null, null, null, "s.dotSize", "s.dotOpacity", "s.dot", null, "adsFromPrimary", null, null, "advanced", null, "name"];
|
||||
for (var i = 0; i < Sniper.Length; i++) o.Add((Sniper[i], sniperKeys[i]));
|
||||
return [.. o];
|
||||
}
|
||||
|
||||
/// <summary>필드 목록(번호 → 이름)에서 조준점 기준 번호. 이름이 하나라도 어긋나면 그 자리는 아니다. 못 찾으면 null</summary>
|
||||
public static int? FindBase(IReadOnlyDictionary<int, string> names)
|
||||
{
|
||||
int? best = null;
|
||||
var bestHits = 0;
|
||||
for (var d = 0; d <= 80; d++)
|
||||
foreach (var b in d == 0 ? new[] { KnownBase } : new[] { KnownBase + d, KnownBase - d })
|
||||
{
|
||||
if (b < 0) continue;
|
||||
var hits = 0;
|
||||
var bad = false;
|
||||
foreach (var (h, name) in names)
|
||||
{
|
||||
var i = h - b;
|
||||
if (i < 0 || i >= Layout.Length || Layout[i].Name is not { } want) continue;
|
||||
if (want != name) { bad = true; break; }
|
||||
hits++;
|
||||
}
|
||||
// 프로필 이름 + 몇 개 이상 맞아야 한다 (조준점을 하나도 안 바꾼 경기면 필드가 거의 안 온다)
|
||||
if (!bad && hits > bestHits && names.GetValueOrDefault(b + Layout.Length - 1) == "ProfileName")
|
||||
{
|
||||
best = b;
|
||||
bestHits = hits;
|
||||
}
|
||||
}
|
||||
return bestHits >= 3 ? best : null;
|
||||
}
|
||||
|
||||
/// <summary>두 번째 읽기: PlayerState 액터 → 조준점이 바뀐 시각마다 전체 설정</summary>
|
||||
public static Dictionary<uint, List<CrosshairAt>> Read(string path, ValorantReplayReadResult first)
|
||||
{
|
||||
var group = first.ExportGroups.FirstOrDefault(g => g.PathName == StatePath);
|
||||
if (group is null) return [];
|
||||
var names = new Dictionary<int, string>();
|
||||
foreach (var f in group.Fields)
|
||||
if (f.Name is { } n) names[(int)f.Handle] = n;
|
||||
if (FindBase(names) is not { } b) return [];
|
||||
|
||||
var keyByHandle = new Dictionary<int, string>();
|
||||
var fields = new List<FieldDescriptor>();
|
||||
for (var i = 0; i < Layout.Length; i++)
|
||||
{
|
||||
if (Layout[i] is not { Name: { } name, Key: { } key }) continue;
|
||||
var h = b + i;
|
||||
keyByHandle[h] = key;
|
||||
fields.Add(new FieldDescriptor
|
||||
{
|
||||
Handle = (uint)h,
|
||||
ExportName = name,
|
||||
PropertyName = key,
|
||||
Categories = ExportCategory.GameState,
|
||||
Decoder = name == "ProfileName" ? PrimitiveDecoders.FString
|
||||
: name.Length == 1 ? PrimitiveDecoders.Byte
|
||||
: name.StartsWith('b') ? PrimitiveDecoders.Bool
|
||||
: PrimitiveDecoders.Float,
|
||||
});
|
||||
}
|
||||
// 기본 목록(경로 별칭 · 하위 객체 등 읽기에 필요)에서 BombPlayerState 만 조준점 필드로 바꾼다 (같은 경로는 나중 것이 쓰인다)
|
||||
var catalog = ValorantDescriptors.CreateCatalog();
|
||||
catalog.Add(new ExportGroupDescriptor(StatePath, ExportCategory.GameState, ExportGroupKind.Actor, fields: fields));
|
||||
var sink = new Sink(keyByHandle);
|
||||
var profile = new ParseProfile
|
||||
{
|
||||
EnabledCategories = ExportCategory.All,
|
||||
CaptureDiagnosticFields = true,
|
||||
IncludedPaths = [StatePath],
|
||||
};
|
||||
using var file = File.OpenRead(path);
|
||||
using var archive = new FBinaryArchive(file);
|
||||
new ValorantReplayReader(null, sink, profile, catalog).Read(archive);
|
||||
return sink.Result;
|
||||
}
|
||||
|
||||
private sealed class Sink(Dictionary<int, string> keyByHandle) : IReplayEventSink
|
||||
{
|
||||
private readonly Dictionary<uint, Dictionary<string, object>> _now = [];
|
||||
public Dictionary<uint, List<CrosshairAt>> Result { get; } = [];
|
||||
|
||||
public void Emit(ReplayEvent e)
|
||||
{
|
||||
if (e is not ExportGroupReceived x || x.ExportGroupPath != StatePath || x.DiagnosticFields.Count == 0) return;
|
||||
if (!_now.TryGetValue(x.ActorNetGuid, out var v)) _now[x.ActorNetGuid] = v = [];
|
||||
var changed = false;
|
||||
foreach (var f in x.DiagnosticFields)
|
||||
{
|
||||
if (!keyByHandle.TryGetValue(f.Handle, out var key)) continue;
|
||||
object val = f.Value.Kind switch
|
||||
{
|
||||
DecodedFieldValueKind.Bool => f.Value.BoolValue,
|
||||
DecodedFieldValueKind.Byte => (int)f.Value.ByteValue,
|
||||
DecodedFieldValueKind.Float => Math.Round(f.Value.FloatValue, 3),
|
||||
DecodedFieldValueKind.String => (f.Value.StringValue ?? "").TrimEnd('\0'),
|
||||
_ => null!,
|
||||
};
|
||||
if (val is null) continue;
|
||||
v[key] = val;
|
||||
changed = true;
|
||||
}
|
||||
if (!changed) return;
|
||||
var t = (int)Math.Round(x.TimeSeconds * 1000.0);
|
||||
var at = Snapshot(t, v);
|
||||
if (!Result.TryGetValue(x.ActorNetGuid, out var list)) Result[x.ActorNetGuid] = list = [];
|
||||
// 같은 시각에 나눠 온 것은 하나로, 바뀐 것이 없으면 넣지 않는다
|
||||
if (list.Count > 0 && list[^1].T == t) list.RemoveAt(list.Count - 1);
|
||||
if (list.Count > 0 && Same(list[^1], at)) return;
|
||||
list.Add(at);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool Same(CrosshairAt a, CrosshairAt b) =>
|
||||
JsonSerializer.Serialize(a with { T = 0 }, ReplayJson.Options) == JsonSerializer.Serialize(b with { T = 0 }, ReplayJson.Options);
|
||||
|
||||
public static CrosshairAt Snapshot(int t, IReadOnlyDictionary<string, object> v)
|
||||
{
|
||||
// 오지 않은 필드는 기본값: 색 255 · 숫자 0 · 끔
|
||||
int C(string k) => v.TryGetValue(k, out var o) ? (int)o : 255;
|
||||
double F(string k) => v.TryGetValue(k, out var o) ? (double)o : 0;
|
||||
bool B(string k) => v.TryGetValue(k, out var o) && (bool)o;
|
||||
string Hex(string p) => $"#{C(p + "r"):x2}{C(p + "g"):x2}{C(p + "b"):x2}";
|
||||
CrossLines L(string p) => new(B(p + "on"), F(p + "length"), B(p + "allowVert") ? F(p + "vLength") : F(p + "length"),
|
||||
F(p + "thickness"), F(p + "offset"), F(p + "opacity"), B(p + "moveError"), B(p + "fireError"), F(p + "moveScale"), F(p + "fireScale"));
|
||||
CrossSet S(string p) => new(Hex(p + (B(p + "useCustom") ? "u" : "c")), B(p + "outline"), F(p + "outlineThickness"), F(p + "outlineOpacity"),
|
||||
B(p + "dot"), F(p + "dotSize"), F(p + "dotOpacity"), L(p + "i."), L(p + "o."));
|
||||
return new CrosshairAt(t, v.TryGetValue("name", out var n) ? (string)n : "", S("p."), S("a."),
|
||||
new SniperDot(Hex("s.c"), B("s.dot"), F("s.dotSize"), F("s.dotOpacity")), B("adsFromPrimary"), B("advanced"));
|
||||
}
|
||||
}
|
||||
|
||||
/// 조준점 설정 (t 부터). ads 는 adsFromPrimary 가 꺼져 있을 때 정조준에 쓴다. 크기는 발로란트 설정 값 그대로 (화면 픽셀)
|
||||
public sealed record CrosshairAt(int T, string Name, CrossSet Primary, CrossSet Ads, SniperDot Sniper, bool AdsFromPrimary, bool Advanced);
|
||||
/// color 는 실제로 보이는 색 (사용자 지정 색을 쓰면 그 색)
|
||||
public sealed record CrossSet(string Color, bool Outline, double OutlineThickness, double OutlineOpacity, bool Dot, double DotSize, double DotOpacity, CrossLines Inner, CrossLines Outer);
|
||||
/// vLength 는 세로 길이를 따로 쓰지 않으면 length 와 같다
|
||||
public sealed record CrossLines(bool On, double Length, double VLength, double Thickness, double Offset, double Opacity, bool MoveError, bool FireError, double MoveScale, double FireScale);
|
||||
public sealed record SniperDot(string Color, bool Dot, double DotSize, double DotOpacity);
|
||||
@@ -53,6 +53,8 @@ public sealed class ReplayPlayer
|
||||
public string? Character { get; set; }
|
||||
/// 이동 기록. 열 별 배열 (같은 길이): t, x, y, z, yaw(도), pitch(도)
|
||||
public PlayerTrack Track { get; set; } = new();
|
||||
/// 조준점 설정이 바뀐 시각마다 전체 설정 (시간 순). 리플레이에 없으면 null
|
||||
public List<CrosshairAt>? Crosshair { get; set; }
|
||||
}
|
||||
|
||||
public sealed class PlayerTrack
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// gvr-replay: 발로란트 리플레이(.vrf) → 사이트 재생기용 JSON (형식 gvr-replay v2)
|
||||
// gvr-replay <file.vrf> <out.json> [--hz 10]
|
||||
// gvr-replay <file.vrf> --stats (디버그: 액터 종류별 개수)
|
||||
// gvr-replay --self-test (회귀 검사: 무기 주인 시간표)
|
||||
// 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;
|
||||
@@ -36,6 +37,21 @@ public static class Program
|
||||
// 선수를 모르는 기록(-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;
|
||||
@@ -66,6 +82,13 @@ public static class Program
|
||||
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();
|
||||
@@ -76,6 +99,21 @@ public static class Program
|
||||
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);
|
||||
@@ -89,6 +127,7 @@ public static class Program
|
||||
players = replay.Players.Count,
|
||||
rounds = replay.Rounds.Count,
|
||||
kills = replay.Kills.Count,
|
||||
crosshairs,
|
||||
elapsedMs = sw.ElapsedMilliseconds,
|
||||
status = result.Status.ToString(),
|
||||
warnings = result.TotalDiagnosticCount,
|
||||
|
||||
Reference in New Issue
Block a user