발로란트 맵 3D: 모든 맵을 Riot CDN 에서 바로 추출해 3D 리플레이에 붙임 · 매핑 업데이트 자동 적용
- tools/map-extract (C#, CUE4Parse 고정 커밋): 게임 파일을 받지 않고 매니페스트 조각만 HTTP Range 로 읽어 맵 22개(일반 13 · 팀 데스매치 5 · 스커미시 3 · 어빌리티 드래프트)를 월드 좌표 glb 로. 3.1분 · 587MB 받음 - scripts/pack.py (gltfpack -cc + gzip, 맵당 0.5~4.6MB) · update.sh (uedb 매핑 · 라이브 패치 확인 → 매핑 보관 → 추출 → .5 data/maps3d 반영) · install.sh (systemd 사용자 타이머 30분, 메모리 6GB 상한) - 사이트 서버: GET /site/maps3d* (로그인 필요, gzip 그대로). CSP 에 'wasm-unsafe-eval' (meshopt 압축 풀기만) - 3D 재생기: 맵 3D 위에 선수 표시, 천장 자르기(자동 · 없음 · 직접), 높이 색칠. 맵이 없거나 실패하면 미니맵 - 리플레이 칸: 리플레이를 아직 안 보내는 앱 버전이면 그렇게 안내 - 테스트: maps3d.test.ts 2개, CSP 테스트 갱신 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
62
tools/map-extract/scripts/install.sh
Executable file
62
tools/map-extract/scripts/install.sh
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
# 맵 3D 자동 갱신을 이 리눅스 서버(.9)에 설치한다. 저장소에서: tools/map-extract/scripts/install.sh
|
||||
# - gvr-map-extract 를 빌드해 $GVR_MAPS_HOME/bin 에 둔다 (저장소 작업 폴더가 바뀌어도 타이머는 그대로 돈다)
|
||||
# - systemd 사용자 타이머 gvr-maps-update.timer (30분마다 update.sh). 메모리 6GB · CPU 3코어 상한, 봇과 다른 cgroup
|
||||
# 코드를 고쳤으면 다시 실행하면 된다. 지금 바로 한 번 돌리기: systemctl --user start gvr-maps-update
|
||||
set -euo pipefail
|
||||
here="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
GVR_MAPS_HOME="${GVR_MAPS_HOME:-$HOME/gvr-maps}"
|
||||
export PATH="$HOME/.dotnet:$PATH" DOTNET_ROOT="${DOTNET_ROOT:-$HOME/.dotnet}" DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||
"$here/fetch-cue4parse.sh"
|
||||
rm -rf "$GVR_MAPS_HOME/bin.new"
|
||||
CUE4PARSE_SKIP_NATIVE=1 dotnet build "$here/MapExtract.csproj" -c Release -o "$GVR_MAPS_HOME/bin.new" -v quiet -nologo -clp:ErrorsOnly
|
||||
rm -rf "$GVR_MAPS_HOME/bin.old"
|
||||
[ -d "$GVR_MAPS_HOME/bin" ] && mv "$GVR_MAPS_HOME/bin" "$GVR_MAPS_HOME/bin.old"
|
||||
mv "$GVR_MAPS_HOME/bin.new" "$GVR_MAPS_HOME/bin"
|
||||
# Oodle 압축 풀기 라이브러리: 처음 실행 때 받는다. 이전 설치에 있으면 옮겨 둔다
|
||||
[ -f "$GVR_MAPS_HOME/bin.old/liboodle-data-shared.so" ] && cp "$GVR_MAPS_HOME/bin.old/liboodle-data-shared.so" "$GVR_MAPS_HOME/bin/"
|
||||
rm -rf "$GVR_MAPS_HOME/bin.old"
|
||||
mkdir -p "$GVR_MAPS_HOME/scripts"
|
||||
cp "$here/scripts/update.sh" "$here/scripts/pack.py" "$here/scripts/preview.py" "$GVR_MAPS_HOME/scripts/"
|
||||
chmod +x "$GVR_MAPS_HOME/scripts/update.sh"
|
||||
|
||||
unit="$HOME/.config/systemd/user"
|
||||
mkdir -p "$unit"
|
||||
node_dir="$(dirname "$(command -v node)")"
|
||||
cat > "$unit/gvr-maps-update.service" <<EOF
|
||||
[Unit]
|
||||
Description=겜녹이: 발로란트 맵 3D 자동 갱신 (uedb 매핑 · 라이브 패치 확인 → 추출 → 사이트 반영)
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
Environment=GVR_MAPS_HOME=$GVR_MAPS_HOME
|
||||
Environment=DOTNET_ROOT=$DOTNET_ROOT
|
||||
Environment=PATH=$node_dir:$HOME/.dotnet:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=TMPDIR=$HOME/.tmp
|
||||
Environment=NOTIFY_CHANNEL=${NOTIFY_CHANNEL:-}
|
||||
Environment=NOTIFY_ENV=${NOTIFY_ENV:-}
|
||||
ExecStart=$GVR_MAPS_HOME/scripts/update.sh
|
||||
MemoryMax=6G
|
||||
MemorySwapMax=0
|
||||
CPUQuota=300%
|
||||
CPUWeight=50
|
||||
Nice=10
|
||||
TimeoutStartSec=2h
|
||||
EOF
|
||||
cat > "$unit/gvr-maps-update.timer" <<EOF
|
||||
[Unit]
|
||||
Description=겜녹이: 발로란트 맵 3D 자동 갱신 (30분마다)
|
||||
|
||||
[Timer]
|
||||
OnBootSec=5min
|
||||
OnUnitActiveSec=30min
|
||||
RandomizedDelaySec=2min
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
EOF
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now gvr-maps-update.timer
|
||||
echo "설치 완료: $GVR_MAPS_HOME · $(systemctl --user list-timers gvr-maps-update.timer --no-legend | head -1)"
|
||||
33
tools/map-extract/scripts/pack.py
Executable file
33
tools/map-extract/scripts/pack.py
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
"""gvr-map-extract 결과(<코드>.glb + <코드>.json)를 사이트용으로 압축한다.
|
||||
pack.py <추출 폴더> <출력 폴더> <버전(예: VALORANT_13.08)>
|
||||
출력: <출력>/<dir>/<코드>.glb.gz (gltfpack -cc 로 meshopt 압축 · 위치 양자화 → gzip) + <출력>/index.json
|
||||
사이트 서버 data/maps3d 에 그대로 올리면 된다 (site/server/src/maps3d.ts)."""
|
||||
import datetime, gzip, json, os, re, shutil, subprocess, sys
|
||||
|
||||
src, out, version = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
stamp = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%d%H%M')
|
||||
d = re.sub(r'[^\w.-]', '_', f'{version}-{stamp}')
|
||||
os.makedirs(os.path.join(out, d), exist_ok=True)
|
||||
maps = {}
|
||||
for name in sorted(os.listdir(src)):
|
||||
if not name.endswith('.json'):
|
||||
continue
|
||||
info = json.load(open(os.path.join(src, name)))
|
||||
code = info['code']
|
||||
glb = os.path.join(src, code + '.glb')
|
||||
if not os.path.exists(glb) or info.get('triangles', 0) == 0:
|
||||
continue
|
||||
packed = os.path.join(out, d, code + '.glb')
|
||||
subprocess.run(['npx', '-y', 'gltfpack@1.3.0', '-i', glb, '-o', packed, '-cc'], check=True, stdout=subprocess.DEVNULL)
|
||||
with open(packed, 'rb') as f, gzip.open(packed + '.gz', 'wb', 9) as g:
|
||||
shutil.copyfileobj(f, g)
|
||||
os.remove(packed)
|
||||
size = os.path.getsize(packed + '.gz')
|
||||
maps[info['mapUrl']] = {'code': code, 'file': code + '.glb', 'bytes': size, 'triangles': info['triangles']}
|
||||
print(f"{code}: {info['triangles']} 삼각형 → {size / 1e6:.1f}MB")
|
||||
idx = {'version': version, 'dir': d, 'updatedAt': datetime.datetime.now(datetime.timezone.utc).isoformat(), 'maps': maps}
|
||||
tmp = os.path.join(out, 'index.json.tmp')
|
||||
json.dump(idx, open(tmp, 'w'), ensure_ascii=False, indent=1)
|
||||
os.replace(tmp, os.path.join(out, 'index.json'))
|
||||
print(f'index.json: 맵 {len(maps)}개 · 폴더 {d}')
|
||||
43
tools/map-extract/scripts/preview.py
Executable file
43
tools/map-extract/scripts/preview.py
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
"""추출한 맵 glb 를 위에서 본 그림(PNG)으로 그린다. 확인용.
|
||||
preview.py <맵.glb> <출력.png> [천장 cm (이보다 높은 삼각형 제외)]
|
||||
삼각형마다 무게중심 · 꼭짓점을 찍고 높은 것이 위에 오게 칠한다 (빠른 근사)."""
|
||||
import json, struct, sys
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
src, dst = sys.argv[1], sys.argv[2]
|
||||
zmax = float(sys.argv[3]) if len(sys.argv) > 3 else None
|
||||
b = open(src, 'rb').read()
|
||||
jl = struct.unpack('<I', b[12:16])[0]
|
||||
j = json.loads(b[20:20 + jl])
|
||||
bin_ = b[20 + jl + 8:]
|
||||
pa, ia = j['accessors'][0], j['accessors'][1]
|
||||
pv, iv = j['bufferViews'][pa['bufferView']], j['bufferViews'][ia['bufferView']]
|
||||
P = np.frombuffer(bin_, '<f4', pa['count'] * 3, pv.get('byteOffset', 0)).reshape(-1, 3)
|
||||
I = np.frombuffer(bin_, '<u4', ia['count'], iv.get('byteOffset', 0)).reshape(-1, 3)
|
||||
T = P[I] # (n,3,3)
|
||||
if zmax is not None:
|
||||
T = T[T[:, :, 2].max(1) < zmax]
|
||||
# 면 방향 음영
|
||||
n = np.cross(T[:, 1] - T[:, 0], T[:, 2] - T[:, 0])
|
||||
n /= np.linalg.norm(n, axis=1, keepdims=True) + 1e-9
|
||||
lum = 0.35 + 0.65 * np.abs(n @ np.array([0.3, 0.5, 0.81]))
|
||||
pts = np.concatenate([T.mean(1), T[:, 0], T[:, 1], T[:, 2], (T[:, 0] + T[:, 1]) / 2, (T[:, 1] + T[:, 2]) / 2, (T[:, 0] + T[:, 2]) / 2])
|
||||
L = np.tile(lum, 7)
|
||||
lo, hi = np.percentile(pts, 0.5, axis=0), np.percentile(pts, 99.5, axis=0)
|
||||
size = 1400
|
||||
s = (size - 20) / max(hi[0] - lo[0], hi[1] - lo[1])
|
||||
# 미니맵과 같은 방향: 화면 x = 월드 y, 화면 아래 = 월드 x 감소
|
||||
x = ((pts[:, 1] - lo[1]) * s + 10).astype(int)
|
||||
y = ((hi[0] - pts[:, 0]) * s + 10).astype(int)
|
||||
W, H = int((hi[1] - lo[1]) * s + 20), int((hi[0] - lo[0]) * s + 20)
|
||||
ok = (x >= 0) & (x < W) & (y >= 0) & (y < H)
|
||||
x, y, z, L = x[ok], y[ok], pts[ok, 2], L[ok]
|
||||
order = np.argsort(z) # 낮은 것 먼저, 높은 것이 덮는다
|
||||
img = np.zeros((H, W, 3), np.float32) + np.array([18, 20, 26], np.float32) / 255
|
||||
zn = np.clip((z - lo[2]) / (hi[2] - lo[2] + 1e-9), 0, 1)
|
||||
col = np.stack([0.35 + 0.45 * zn, 0.40 + 0.35 * zn, 0.55 - 0.15 * zn], 1) * L[:, None]
|
||||
img[y[order], x[order]] = col[order]
|
||||
Image.fromarray((np.clip(img, 0, 1) * 255).astype(np.uint8)).save(dst)
|
||||
print(dst, W, H, 'triangles', len(T), 'z', lo[2].round(), hi[2].round())
|
||||
107
tools/map-extract/scripts/update.sh
Executable file
107
tools/map-extract/scripts/update.sh
Executable file
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env bash
|
||||
# 발로란트 맵 3D 자동 갱신 (systemd 타이머가 30분마다 실행, install.sh 참고)
|
||||
#
|
||||
# 1. uedb.dev 발로란트 매핑(.usmap) 버전 · 라이브 패치 매니페스트를 본다. 지난번에 올린 것과 같으면 끝
|
||||
# 2. 새 매핑이면 받아서 보관한다: $GVR_MAPS_HOME/mappings/ + nextcloud claude/game-voice-recorder/valorant/mappings/
|
||||
# 3. 모든 맵을 Riot CDN 에서 바로 뽑고(gvr-map-extract, 필요한 조각만 받음 · 디스크 거의 안 씀) 압축한다 (pack.py)
|
||||
# 4. 사이트 서버(.5) data/maps3d 에 올리고 index.json 을 바꿔 끼운다 → 사이트가 바로 새 맵을 쓴다
|
||||
#
|
||||
# 실패하면 사이트는 이전 맵을 그대로 쓴다. 같은 (매핑, 패치) 조합은 한 번 실패하면 다음 변경 때까지 다시 하지 않는다.
|
||||
# 강제로 다시: update.sh --force
|
||||
set -euo pipefail
|
||||
GVR_MAPS_HOME="${GVR_MAPS_HOME:-$HOME/gvr-maps}"
|
||||
SITE_HOST="${SITE_HOST:-root@192.168.10.5}"
|
||||
SITE_DATA="${SITE_DATA:-/root/other/game-voice-recorder/data}"
|
||||
UEDB="https://uedb.dev/svc/api/v1/valorant/mappings"
|
||||
SECRETS="${SECRETS:-$HOME/.config/ejclaw/secrets.json}"
|
||||
export DOTNET_ROOT="${DOTNET_ROOT:-$HOME/.dotnet}"
|
||||
BIN="$GVR_MAPS_HOME/bin/gvr-map-extract"
|
||||
STATE="$GVR_MAPS_HOME/state.json"
|
||||
mkdir -p "$GVR_MAPS_HOME/mappings" "$GVR_MAPS_HOME/work"
|
||||
exec 9>"$GVR_MAPS_HOME/.lock"
|
||||
flock -n 9 || { echo "이미 실행 중"; exit 0; }
|
||||
log() { echo "[$(date '+%F %T')] $*"; }
|
||||
# 결과 알림 (선택): NOTIFY_CHANNEL=<디스코드 채널 id>, NOTIFY_ENV=<DISCORD_OWNER_BOT_TOKEN 이 든 .env>
|
||||
notify() {
|
||||
[ -n "${NOTIFY_CHANNEL:-}" ] && [ -f "${NOTIFY_ENV:-}" ] || return 0
|
||||
local token
|
||||
token="$(grep -E '^DISCORD_OWNER_BOT_TOKEN=' "$NOTIFY_ENV" | head -1 | sed -E 's/^[^=]+=//' | tr -d '"'\''\r')"
|
||||
[ -n "$token" ] || return 0
|
||||
curl -sS -o /dev/null --max-time 20 -X POST "https://discord.com/api/v10/channels/$NOTIFY_CHANNEL/messages" \
|
||||
-H "Authorization: Bot $token" -H 'Content-Type: application/json' \
|
||||
-d "$(jq -nc --arg c "$1" '{content:$c, allowed_mentions:{parse:[]}}')" || true
|
||||
}
|
||||
st() { python3 -c 'import json,sys; d=json.load(open(sys.argv[1])) if __import__("os").path.exists(sys.argv[1]) else {}; print(d.get(sys.argv[2],""))' "$STATE" "$1"; }
|
||||
set_state() { python3 - "$STATE" "$@" <<'P'
|
||||
import json, os, sys
|
||||
f = sys.argv[1]
|
||||
d = json.load(open(f)) if os.path.exists(f) else {}
|
||||
for kv in sys.argv[2:]:
|
||||
k, v = kv.split('=', 1)
|
||||
d[k] = v
|
||||
json.dump(d, open(f + '.tmp', 'w'), indent=1)
|
||||
os.replace(f + '.tmp', f)
|
||||
P
|
||||
}
|
||||
|
||||
# 1. 바뀐 것이 있나
|
||||
meta="$(curl -fsS --max-time 30 "$UEDB")"
|
||||
version="$(jq -r .version <<<"$meta")"
|
||||
updated="$(jq -r .updated <<<"$meta")"
|
||||
usmap_url="$(jq -r '.mappings.Brotli // .mappings.ZStandard' <<<"$meta")"
|
||||
[ -n "$version" ] && [ "$version" != null ] && [ -n "$usmap_url" ] && [ "$usmap_url" != null ] || { log "uedb 응답 이상: $meta"; exit 1; }
|
||||
manifest="$("$BIN" manifest)"
|
||||
key="$version|$updated|$manifest"
|
||||
if [ "${1:-}" != "--force" ]; then
|
||||
[ "$key" = "$(st published)" ] && { log "변경 없음 ($version, $(basename "$manifest"))"; exit 0; }
|
||||
[ "$key" = "$(st failed)" ] && { log "이 조합은 이미 실패함, 다음 변경까지 대기 ($version, $(basename "$manifest"))"; exit 0; }
|
||||
fi
|
||||
log "새로 뽑기: 매핑 $version ($updated) · 패치 $(basename "$manifest")"
|
||||
|
||||
# 2. 매핑 받기 · 보관
|
||||
stamp="$(date -u -d "$updated" +%Y%m%d%H%M 2>/dev/null || date -u +%Y%m%d%H%M)"
|
||||
usmap="$GVR_MAPS_HOME/mappings/${version}_${stamp}_$(basename "$usmap_url" | sed 's/^.*_\(br\|zs\)\.usmap$/\1/').usmap"
|
||||
if [ ! -s "$usmap" ]; then
|
||||
curl -fsS --max-time 300 -o "$usmap.part" "$usmap_url"
|
||||
mv "$usmap.part" "$usmap"
|
||||
log "매핑 저장 $usmap ($(stat -c %s "$usmap") 바이트)"
|
||||
# nextcloud 보관 (claude/ 폴더 안만 쓴다, 사용자 규칙)
|
||||
if [ -f "$SECRETS" ]; then
|
||||
read -r nc_host nc_user nc_token < <(python3 -c 'import json,sys; c=json.load(open(sys.argv[1]))["credentials"]["nextcloud.192.168.10.10"]; print(c["host"], c["username"], c["token"])' "$SECRETS") || true
|
||||
if [ -n "${nc_token:-}" ]; then
|
||||
dav="$nc_host/remote.php/dav/files/$nc_user/claude/game-voice-recorder/valorant/mappings"
|
||||
curl -fsS -u "$nc_user:$nc_token" -X MKCOL "$nc_host/remote.php/dav/files/$nc_user/claude/game-voice-recorder/valorant" >/dev/null 2>&1 || true
|
||||
curl -fsS -u "$nc_user:$nc_token" -X MKCOL "$dav" >/dev/null 2>&1 || true
|
||||
if curl -fsS -u "$nc_user:$nc_token" -T "$usmap" "$dav/$(basename "$usmap")" >/dev/null; then log "nextcloud 보관 완료"; else log "nextcloud 보관 실패 (계속 진행)"; fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# 3. 뽑기 · 압축
|
||||
raw="$GVR_MAPS_HOME/work/raw"
|
||||
out="$GVR_MAPS_HOME/work/out"
|
||||
rm -rf "$raw" "$out"
|
||||
mkdir -p "$raw" "$out"
|
||||
if ! GVR_USMAP="$usmap" GVR_MANIFEST="$manifest" "$BIN" extract "$raw"; then
|
||||
set_state "failed=$key" "failedAt=$(date -Is)"
|
||||
log "추출 실패 → 사이트는 이전 맵 유지"
|
||||
notify "⚠️ 발로란트 맵 3D 자동 갱신 실패 (매핑 $version · 패치 $(basename "$manifest" .manifest)). 사이트는 이전 맵을 그대로 씁니다. 로그: journalctl --user -u gvr-maps-update"
|
||||
exit 1
|
||||
fi
|
||||
python3 "$GVR_MAPS_HOME/scripts/pack.py" "$raw" "$out" "$version"
|
||||
dir="$(jq -r .dir "$out/index.json")"
|
||||
count="$(jq '.maps | length' "$out/index.json")"
|
||||
[ "$count" -gt 0 ] || { set_state "failed=$key"; log "맵 0개 → 올리지 않음"; exit 1; }
|
||||
|
||||
# 4. 사이트 서버에 올리기 (폴더 먼저, index.json 은 마지막에 바꿔 끼움)
|
||||
ssh -o BatchMode=yes "$SITE_HOST" "mkdir -p '$SITE_DATA/maps3d'"
|
||||
tar -C "$out" -cf - "$dir" | ssh -o BatchMode=yes "$SITE_HOST" "tar -xf - -C '$SITE_DATA/maps3d'"
|
||||
scp -q -o BatchMode=yes "$out/index.json" "$SITE_HOST:$SITE_DATA/maps3d/index.json.tmp"
|
||||
prev="$(ssh -o BatchMode=yes "$SITE_HOST" "cat '$SITE_DATA/maps3d/index.json' 2>/dev/null" | jq -r '.dir // empty' 2>/dev/null || true)"
|
||||
ssh -o BatchMode=yes "$SITE_HOST" "mv '$SITE_DATA/maps3d/index.json.tmp' '$SITE_DATA/maps3d/index.json'"
|
||||
# 지금 것과 바로 전 것(이미 열어 둔 화면용)만 남긴다
|
||||
ssh -o BatchMode=yes "$SITE_HOST" "cd '$SITE_DATA/maps3d' && for d in */; do d=\${d%/}; [ \"\$d\" = '$dir' ] || [ \"\$d\" = '$prev' ] || rm -rf -- \"\$d\"; done"
|
||||
set_state "published=$key" "publishedAt=$(date -Is)" "dir=$dir" "failed="
|
||||
rm -rf "$raw" "$out"
|
||||
log "사이트 반영 완료: 맵 $count 개 · $dir"
|
||||
notify "🗺️ 발로란트 맵 3D 자동 갱신: 매핑 $version · 맵 ${count}개를 사이트에 반영했습니다"
|
||||
Reference in New Issue
Block a user