Cnass commited on
Commit
dc9096f
·
verified ·
1 Parent(s): 113e464

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. godot_gdc.py +13 -4
godot_gdc.py CHANGED
@@ -1,8 +1,9 @@
1
  """Godot 4 derlenmiş GDScript (`.gdc`, ikili belirteç tamponu) okuyucu.
2
 
3
  Biçim (modules/gdscript/gdscript_tokenizer_buffer.cpp, 4.3+): "GDSC", uint32
4
- sürüm (100 ya da 101), uint32 açılmış boyut (0 → sıkıştırılmamış, değilse
5
- zstd), ardından tanımlayıcı/sabit/satır/belirteç sayıları, tanımlayıcılar
 
6
  (UTF-32, her bayt 0xb6 ile XOR'lu) ve sabitler (marshalls encode_variant).
7
  Yalnız okunur; oyunun betiklerine hiç dokunulmaz.
8
  """
@@ -12,8 +13,12 @@ import struct
12
  from dataclasses import dataclass, field
13
 
14
  VT_NIL, VT_BOOL, VT_INT, VT_FLOAT, VT_STRING = 0, 1, 2, 3, 4
15
- VT_STRING_NAME, VT_NODE_PATH = 21, 22
16
  FLAG_64 = 1 << 16
 
 
 
 
17
 
18
 
19
  class GdcError(Exception):
@@ -60,6 +65,10 @@ def _constant(buf: bytes, pos: int) -> tuple[object, int]:
60
  if header & FLAG_64:
61
  return struct.unpack_from("<d", buf, pos)[0], pos + 8
62
  return struct.unpack_from("<f", buf, pos)[0], pos + 4
 
 
 
 
63
  if kind in (VT_STRING, VT_STRING_NAME):
64
  return _string(buf, pos)
65
  if kind == VT_NODE_PATH:
@@ -83,7 +92,7 @@ def read_gdc(data: bytes) -> GdcScript:
83
  body = data[12:] if size == 0 else _zstd_decompress(data[12:], size)
84
  try:
85
  id_count, const_count = struct.unpack_from("<II", body, 0)
86
- pos = 16
87
  out = GdcScript()
88
  for _ in range(id_count):
89
  n = struct.unpack_from("<I", body, pos)[0]
 
1
  """Godot 4 derlenmiş GDScript (`.gdc`, ikili belirteç tamponu) okuyucu.
2
 
3
  Biçim (modules/gdscript/gdscript_tokenizer_buffer.cpp, 4.3+): "GDSC", uint32
4
+ sürüm (100: 4.3/4.4, 101: 4.5+), uint32 açılmış boyut (0 → sıkıştırılmamış,
5
+ değilse zstd), ardından tanımlayıcı/sabit/satır/belirteç sayıları (100'de
6
+ 20, 101'de 16 bayt), tanımlayıcılar
7
  (UTF-32, her bayt 0xb6 ile XOR'lu) ve sabitler (marshalls encode_variant).
8
  Yalnız okunur; oyunun betiklerine hiç dokunulmaz.
9
  """
 
13
  from dataclasses import dataclass, field
14
 
15
  VT_NIL, VT_BOOL, VT_INT, VT_FLOAT, VT_STRING = 0, 1, 2, 3, 4
16
+ VT_COLOR, VT_STRING_NAME, VT_NODE_PATH = 20, 21, 22
17
  FLAG_64 = 1 << 16
18
+ # Sabit boyutlu türler: Variant türü → bileşen sayısı. Gerçek sayılı olanlar
19
+ # FLAG_64 ile 8 bayt; tamsayılılar (Vector2i…) ve Color her zaman 4 bayt.
20
+ _REAL_PARTS = {5: 2, 7: 4, 9: 3, 11: 6, 12: 4, 14: 4, 15: 4, 16: 6, 17: 9, 18: 12, 19: 16}
21
+ _INT_PARTS = {6: 2, 8: 4, 10: 3, 13: 4, VT_COLOR: 4}
22
 
23
 
24
  class GdcError(Exception):
 
65
  if header & FLAG_64:
66
  return struct.unpack_from("<d", buf, pos)[0], pos + 8
67
  return struct.unpack_from("<f", buf, pos)[0], pos + 4
68
+ if kind in _REAL_PARTS:
69
+ return None, pos + _REAL_PARTS[kind] * (8 if header & FLAG_64 else 4)
70
+ if kind in _INT_PARTS:
71
+ return None, pos + _INT_PARTS[kind] * 4
72
  if kind in (VT_STRING, VT_STRING_NAME):
73
  return _string(buf, pos)
74
  if kind == VT_NODE_PATH:
 
92
  body = data[12:] if size == 0 else _zstd_decompress(data[12:], size)
93
  try:
94
  id_count, const_count = struct.unpack_from("<II", body, 0)
95
+ pos = 20 if version == 100 else 16 # 4.3/4.4 başlığında fazladan bir alan var
96
  out = GdcScript()
97
  for _ in range(id_count):
98
  n = struct.unpack_from("<I", body, pos)[0]