addressablestools 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. addressablestools-0.1.0/LICENSE +19 -0
  2. addressablestools-0.1.0/PKG-INFO +72 -0
  3. addressablestools-0.1.0/README.md +39 -0
  4. addressablestools-0.1.0/pyproject.toml +18 -0
  5. addressablestools-0.1.0/setup.cfg +4 -0
  6. addressablestools-0.1.0/src/AddressablesTools/AddressablesCatalogFileParser.py +104 -0
  7. addressablestools-0.1.0/src/AddressablesTools/Binary/ContentCatalogDataBinaryHeader.py +45 -0
  8. addressablestools-0.1.0/src/AddressablesTools/Binary/__init__.py +0 -0
  9. addressablestools-0.1.0/src/AddressablesTools/Catalog/ClassJsonObject.py +18 -0
  10. addressablestools-0.1.0/src/AddressablesTools/Catalog/ContentCatalogData.py +255 -0
  11. addressablestools-0.1.0/src/AddressablesTools/Catalog/ObjectInitializationData.py +39 -0
  12. addressablestools-0.1.0/src/AddressablesTools/Catalog/ResourceLocation.py +121 -0
  13. addressablestools-0.1.0/src/AddressablesTools/Catalog/SerializedObjectDecoder.py +151 -0
  14. addressablestools-0.1.0/src/AddressablesTools/Catalog/SerializedType.py +46 -0
  15. addressablestools-0.1.0/src/AddressablesTools/Catalog/WrappedSerializedObject.py +20 -0
  16. addressablestools-0.1.0/src/AddressablesTools/Catalog/__init__.py +0 -0
  17. addressablestools-0.1.0/src/AddressablesTools/CatalogFileType.py +10 -0
  18. addressablestools-0.1.0/src/AddressablesTools/Classes/AssetBundleRequestOptions.py +154 -0
  19. addressablestools-0.1.0/src/AddressablesTools/Classes/Hash128.py +16 -0
  20. addressablestools-0.1.0/src/AddressablesTools/Classes/TypeReference.py +11 -0
  21. addressablestools-0.1.0/src/AddressablesTools/Classes/__init__.py +0 -0
  22. addressablestools-0.1.0/src/AddressablesTools/Const.py +5 -0
  23. addressablestools-0.1.0/src/AddressablesTools/JSON/ContentCatalogDataJson.py +69 -0
  24. addressablestools-0.1.0/src/AddressablesTools/JSON/ObjectInitializationDataJson.py +20 -0
  25. addressablestools-0.1.0/src/AddressablesTools/JSON/SerializedTypeJson.py +14 -0
  26. addressablestools-0.1.0/src/AddressablesTools/JSON/__init__.py +0 -0
  27. addressablestools-0.1.0/src/AddressablesTools/Reader/BinaryReader.py +40 -0
  28. addressablestools-0.1.0/src/AddressablesTools/Reader/CatalogBinaryReader.py +86 -0
  29. addressablestools-0.1.0/src/AddressablesTools/Reader/__init__.py +0 -0
  30. addressablestools-0.1.0/src/AddressablesTools/__init__.py +23 -0
  31. addressablestools-0.1.0/src/AddressablesTools/classes.py +23 -0
  32. addressablestools-0.1.0/src/addressablestools.egg-info/PKG-INFO +72 -0
  33. addressablestools-0.1.0/src/addressablestools.egg-info/SOURCES.txt +34 -0
  34. addressablestools-0.1.0/src/addressablestools.egg-info/dependency_links.txt +1 -0
  35. addressablestools-0.1.0/src/addressablestools.egg-info/top_level.txt +1 -0
  36. addressablestools-0.1.0/tests/test_parse.py +42 -0
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: addressablestools
3
+ Version: 0.1.0
4
+ Summary: Python copy of AddressablesTools
5
+ Author-email: Jitsu <jitsu233@gmail.com>
6
+ License: Copyright (c) 2018 The Python Packaging Authority
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+ Project-URL: Homepage, https://github.com/anosu/AddressablesToolsPy
26
+ Project-URL: Bug Reports, https://github.com/anosu/AddressablesToolsPy/issues
27
+ Project-URL: Funding, https://donate.pypi.org
28
+ Project-URL: Source, https://github.com/anosu/AddressablesToolsPy
29
+ Requires-Python: >=3.12
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Dynamic: license-file
33
+
34
+ # AddressablesToolsPy
35
+
36
+ Python copy of AddressablesTools
37
+
38
+ ### Usage
39
+
40
+ ```python
41
+ from pathlib import Path
42
+ from AddressablesTools import parse
43
+
44
+
45
+ def main():
46
+ data = Path("tests/samples/catalog.json").read_text("utf-8")
47
+ catalog = parse(data)
48
+ for key, locs in catalog.Resources.items():
49
+ if not isinstance(key, str):
50
+ continue
51
+ if not key.endswith(".bundle"):
52
+ continue
53
+ res_loc = locs[0]
54
+ print(
55
+ f"Bundle {key}, Crc: {res_loc.Data.Object.Crc}, Hash: {res_loc.Data.Object.Hash}"
56
+ )
57
+
58
+ print("-" * 50)
59
+
60
+ asset_locs = catalog.Resources[
61
+ "Assets/Paripari/AddressableAssets/VFX Texture Assets/ParticleTextures/sparkle.png"
62
+ ]
63
+ dep_key = asset_locs[0].DependencyKey
64
+ print(f"Dependency of {asset_locs[0].PrimaryKey}: {dep_key}")
65
+ dep_bundle = catalog.Resources[dep_key][0]
66
+ print(f"ProviderId of {dep_bundle.PrimaryKey}: {dep_bundle.ProviderId}")
67
+ print(f"InternalId of {dep_bundle.PrimaryKey}: {dep_bundle.InternalId}")
68
+
69
+
70
+ if __name__ == "__main__":
71
+ main()
72
+ ```
@@ -0,0 +1,39 @@
1
+ # AddressablesToolsPy
2
+
3
+ Python copy of AddressablesTools
4
+
5
+ ### Usage
6
+
7
+ ```python
8
+ from pathlib import Path
9
+ from AddressablesTools import parse
10
+
11
+
12
+ def main():
13
+ data = Path("tests/samples/catalog.json").read_text("utf-8")
14
+ catalog = parse(data)
15
+ for key, locs in catalog.Resources.items():
16
+ if not isinstance(key, str):
17
+ continue
18
+ if not key.endswith(".bundle"):
19
+ continue
20
+ res_loc = locs[0]
21
+ print(
22
+ f"Bundle {key}, Crc: {res_loc.Data.Object.Crc}, Hash: {res_loc.Data.Object.Hash}"
23
+ )
24
+
25
+ print("-" * 50)
26
+
27
+ asset_locs = catalog.Resources[
28
+ "Assets/Paripari/AddressableAssets/VFX Texture Assets/ParticleTextures/sparkle.png"
29
+ ]
30
+ dep_key = asset_locs[0].DependencyKey
31
+ print(f"Dependency of {asset_locs[0].PrimaryKey}: {dep_key}")
32
+ dep_bundle = catalog.Resources[dep_key][0]
33
+ print(f"ProviderId of {dep_bundle.PrimaryKey}: {dep_bundle.ProviderId}")
34
+ print(f"InternalId of {dep_bundle.PrimaryKey}: {dep_bundle.InternalId}")
35
+
36
+
37
+ if __name__ == "__main__":
38
+ main()
39
+ ```
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "addressablestools"
3
+ version = "0.1.0"
4
+ authors = [{ name = "Jitsu", email = "jitsu233@gmail.com" }]
5
+ description = "Python copy of AddressablesTools"
6
+ readme = "README.md"
7
+ license = { file = "LICENSE" }
8
+ requires-python = ">=3.12"
9
+ dependencies = []
10
+
11
+ [project.urls]
12
+ "Homepage" = "https://github.com/anosu/AddressablesToolsPy"
13
+ "Bug Reports" = "https://github.com/anosu/AddressablesToolsPy/issues"
14
+ "Funding" = "https://donate.pypi.org"
15
+ "Source" = "https://github.com/anosu/AddressablesToolsPy"
16
+
17
+ [dependency-groups]
18
+ dev = ["pytest>=8.3.5", "ruff>=0.11.7"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,104 @@
1
+ import json
2
+ from io import BytesIO
3
+
4
+ from .CatalogFileType import CatalogFileType
5
+ from .JSON.ContentCatalogDataJson import ContentCatalogDataJson
6
+ from .JSON.ObjectInitializationDataJson import ObjectInitializationDataJson
7
+ from .JSON.SerializedTypeJson import SerializedTypeJson
8
+ from .Catalog.ContentCatalogData import ContentCatalogData
9
+ from .Reader.CatalogBinaryReader import CatalogBinaryReader
10
+
11
+
12
+ def serializedTypeDecoder(obj: dict):
13
+ return SerializedTypeJson.New(obj["m_AssemblyName"], obj["m_ClassName"])
14
+
15
+
16
+ def objectInitializationDataDecoder(obj: dict):
17
+ _m_ObjectType = obj["m_ObjectType"]
18
+ m_ObjectType = SerializedTypeJson.New(
19
+ _m_ObjectType["m_AssemblyName"], _m_ObjectType["m_ClassName"]
20
+ )
21
+ return ObjectInitializationDataJson.New(obj["m_Id"], m_ObjectType, obj["m_Data"])
22
+
23
+
24
+ def contentCatalogDataDecoder(obj: dict):
25
+ _m_InstanceProviderData = obj["m_InstanceProviderData"]
26
+ _m_SceneProviderData = obj["m_SceneProviderData"]
27
+ _m_ResourceProviderData = obj["m_ResourceProviderData"]
28
+
29
+ m_InstanceProviderData = ObjectInitializationDataJson.New(
30
+ _m_InstanceProviderData["m_Id"],
31
+ SerializedTypeJson.New(
32
+ _m_InstanceProviderData["m_ObjectType"]["m_AssemblyName"],
33
+ _m_InstanceProviderData["m_ObjectType"]["m_ClassName"],
34
+ ),
35
+ _m_InstanceProviderData["m_Data"],
36
+ )
37
+
38
+ m_SceneProviderData = ObjectInitializationDataJson.New(
39
+ _m_SceneProviderData["m_Id"],
40
+ SerializedTypeJson.New(
41
+ _m_SceneProviderData["m_ObjectType"]["m_AssemblyName"],
42
+ _m_SceneProviderData["m_ObjectType"]["m_ClassName"],
43
+ ),
44
+ _m_SceneProviderData["m_Data"],
45
+ )
46
+
47
+ m_ResourceProviderData = [
48
+ ObjectInitializationDataJson.New(
49
+ o["m_Id"],
50
+ SerializedTypeJson.New(
51
+ o["m_ObjectType"]["m_AssemblyName"], o["m_ObjectType"]["m_ClassName"]
52
+ ),
53
+ o["m_Data"],
54
+ )
55
+ for o in _m_ResourceProviderData
56
+ ]
57
+
58
+ return ContentCatalogDataJson.New(
59
+ obj["m_LocatorId"],
60
+ obj.get("m_BuildResultHash"),
61
+ m_InstanceProviderData,
62
+ m_SceneProviderData,
63
+ m_ResourceProviderData,
64
+ obj["m_ProviderIds"],
65
+ obj["m_InternalIds"],
66
+ obj["m_KeyDataString"],
67
+ obj["m_BucketDataString"],
68
+ obj["m_EntryDataString"],
69
+ obj["m_ExtraDataString"],
70
+ obj.get("m_Keys"),
71
+ [
72
+ SerializedTypeJson.New(o["m_AssemblyName"], o["m_ClassName"])
73
+ for o in obj["m_resourceTypes"]
74
+ ],
75
+ obj.get("m_InternalIdPrefixes"),
76
+ )
77
+
78
+
79
+ class AddressablesCatalogFileParser:
80
+ @staticmethod
81
+ def CCDJsonFromString(data: str) -> ContentCatalogDataJson:
82
+ return contentCatalogDataDecoder(json.loads(data))
83
+
84
+ @staticmethod
85
+ def FromBinaryData(data: bytes) -> ContentCatalogData:
86
+ ms = BytesIO(data)
87
+ reader = CatalogBinaryReader(ms)
88
+ catalogData = ContentCatalogData()
89
+ catalogData.ReadBinary(reader)
90
+ return catalogData
91
+
92
+ @staticmethod
93
+ def FromJsonString(data: str) -> ContentCatalogData:
94
+ ccdJson = AddressablesCatalogFileParser.CCDJsonFromString(data)
95
+ catalogData = ContentCatalogData()
96
+ catalogData.ReadJson(ccdJson)
97
+ return catalogData
98
+
99
+ @staticmethod
100
+ def GetCatalogFileType() -> CatalogFileType:
101
+ return CatalogFileType.Null
102
+
103
+
104
+ __all__ = ["AddressablesCatalogFileParser"]
@@ -0,0 +1,45 @@
1
+ from ..Reader import CatalogBinaryReader
2
+ from ..Const import uint
3
+
4
+
5
+ class ContentCatalogDataBinaryHeader:
6
+ Magic: int
7
+ Version: int
8
+ KeysOffset: int
9
+ IdOffset: int
10
+ InstanceProviderOffset: int
11
+ SceneProviderOffset: int
12
+ InitObjectsArrayOffset: int
13
+ BuildResultHashOffset: int
14
+
15
+ def __repr__(self):
16
+ return (
17
+ f"<{self.__class__.__name__}(Magic={self.Magic}, Version={self.Version})>"
18
+ )
19
+
20
+ def __init__(self):
21
+ self.Magic = 0
22
+ self.Version = 0
23
+ self.KeysOffset = 0
24
+ self.IdOffset = 0
25
+ self.InstanceProviderOffset = 0
26
+ self.SceneProviderOffset = 0
27
+ self.InitObjectsArrayOffset = 0
28
+ self.BuildResultHashOffset = 0
29
+
30
+ def Read(self, reader: CatalogBinaryReader):
31
+ self.Magic = reader.ReadInt32()
32
+ self.Version = reader.ReadInt32()
33
+ if self.Version not in [1, 2]:
34
+ raise Exception("Only versions 1 and 2 are supported")
35
+ reader.Version = self.Version
36
+
37
+ self.KeysOffset = reader.ReadUInt32()
38
+ self.IdOffset = reader.ReadUInt32()
39
+ self.InstanceProviderOffset = reader.ReadUInt32()
40
+ self.SceneProviderOffset = reader.ReadUInt32()
41
+ self.InitObjectsArrayOffset = reader.ReadUInt32()
42
+ if self.Version == 1 and self.KeysOffset == 0x20:
43
+ self.BuildResultHashOffset = uint.MaxValue
44
+ else:
45
+ self.BuildResultHashOffset = reader.ReadUInt32()
@@ -0,0 +1,18 @@
1
+ from .SerializedType import SerializedType
2
+
3
+
4
+ class ClassJsonObject:
5
+ Type: SerializedType
6
+ JsonText: str | None
7
+
8
+ def __repr__(self):
9
+ return f"<{self.__class__.__name__}(Type={self.Type})>"
10
+
11
+ def __init__(self, assemblyName: str, className: str, jsonText: str):
12
+ self.Type = SerializedType()
13
+ self.Type.AssemblyName = assemblyName
14
+ self.Type.ClassName = className
15
+ self.JsonText = className
16
+
17
+
18
+ __all__ = ["ClassJsonObject"]
@@ -0,0 +1,255 @@
1
+ from io import BytesIO
2
+ from base64 import b64decode
3
+
4
+ from .ObjectInitializationData import ObjectInitializationData
5
+ from .ResourceLocation import ResourceLocation
6
+ from .SerializedObjectDecoder import SerializedObjectDecoder
7
+ from .SerializedType import SerializedType
8
+ from ..Binary.ContentCatalogDataBinaryHeader import ContentCatalogDataBinaryHeader
9
+ from ..JSON.ContentCatalogDataJson import ContentCatalogDataJson
10
+ from ..Reader.CatalogBinaryReader import CatalogBinaryReader
11
+ from ..Reader.BinaryReader import BinaryReader
12
+ from ..Catalog.ClassJsonObject import ClassJsonObject
13
+ from ..Classes.TypeReference import TypeReference
14
+ from ..Classes.Hash128 import Hash128
15
+ from ..Catalog.WrappedSerializedObject import WrappedSerializedObject
16
+ from ..Classes.AssetBundleRequestOptions import AssetBundleRequestOptions
17
+
18
+
19
+ class ContentCatalogData:
20
+ Version: int
21
+
22
+ LocatorId: str | None
23
+ BuildResultHash: str | None
24
+ InstanceProviderData: ObjectInitializationData | None
25
+ SceneProviderData: ObjectInitializationData | None
26
+ ResourceProviderData: list[ObjectInitializationData] | None
27
+ ProviderIds: list[str] | None
28
+ InternalIds: list[str] | None
29
+ Keys: list[str] | None
30
+ ResourceTypes: list[SerializedType] | None
31
+ InternalIdPrefixes: list[str] | None
32
+ Resources: dict[object, list[ResourceLocation]] | None
33
+
34
+ Header: ContentCatalogDataBinaryHeader | None
35
+
36
+ class Bucket:
37
+ offset: int
38
+ entries: list[int]
39
+
40
+ def __repr__(self):
41
+ return f"<{self.__class__.__name__}>"
42
+
43
+ def __init__(self, offset: int, entries: list[int]):
44
+ self.offset = offset
45
+ self.entries = entries
46
+
47
+ def __repr__(self):
48
+ return f"<{self.__class__.__name__}(LocatorId={self.LocatorId}, BuildResultHash={self.BuildResultHash})>"
49
+
50
+ def __init__(self):
51
+ self.LocatorId = None
52
+ self.BuildResultHash = None
53
+ self.InstanceProviderData = None
54
+ self.SceneProviderData = None
55
+ self.ResourceProviderData = None
56
+ self.ProviderIds = None
57
+ self.InternalIds = None
58
+ self.Keys = None
59
+ self.ResourceTypes = None
60
+ self.InternalIdPrefixes = None
61
+ self.Resources = None
62
+
63
+ self.Header = None
64
+
65
+ def ReadJson(self, data: ContentCatalogDataJson):
66
+ self.LocatorId = data.m_LocatorId
67
+ self.BuildResultHash = data.m_BuildResultHash
68
+
69
+ self.InstanceProviderData = ObjectInitializationData()
70
+ self.InstanceProviderData.ReadJson(data.m_InstanceProviderData)
71
+
72
+ self.SceneProviderData = ObjectInitializationData()
73
+ self.SceneProviderData.ReadJson(data.m_SceneProviderData)
74
+
75
+ self.ResourceProviderData = []
76
+ for i in range(len(data.m_ResourceProviderData)):
77
+ o = ObjectInitializationData()
78
+ o.ReadJson(data.m_ResourceProviderData[i])
79
+ self.ResourceProviderData.append(o)
80
+
81
+ self.ProviderIds = []
82
+ for i in range(len(data.m_ProviderIds)):
83
+ self.ProviderIds.append(data.m_ProviderIds[i])
84
+
85
+ self.InternalIds = []
86
+ for i in range(len(data.m_InternalIds)):
87
+ self.InternalIds.append(data.m_InternalIds[i])
88
+
89
+ if data.m_Keys is not None:
90
+ self.Keys = []
91
+ for i in range(len(data.m_Keys)):
92
+ self.Keys.append(data.m_Keys[i])
93
+ else:
94
+ self.Keys = None
95
+
96
+ self.ResourceTypes = []
97
+ for i in range(len(data.m_resourceTypes)):
98
+ o = SerializedType()
99
+ o.ReadJson(data.m_resourceTypes[i])
100
+ self.ResourceTypes.append(o)
101
+
102
+ if data.m_InternalIdPrefixes is not None:
103
+ self.InternalIdPrefixes = []
104
+ for i in range(len(data.m_InternalIdPrefixes)):
105
+ self.InternalIdPrefixes.append(data.m_InternalIdPrefixes[i])
106
+ else:
107
+ self.InternalIdPrefixes = None
108
+
109
+ self.ReadResourcesJson(data)
110
+
111
+ def ReadBinary(self, reader: CatalogBinaryReader):
112
+ header = ContentCatalogDataBinaryHeader()
113
+ header.Read(reader)
114
+
115
+ self.Version = reader.Version
116
+ self.Header = header
117
+
118
+ self.LocatorId = reader.ReadEncodedString(header.IdOffset)
119
+ self.BuildResultHash = reader.ReadEncodedString(header.BuildResultHashOffset)
120
+
121
+ self.InstanceProviderData = ObjectInitializationData()
122
+ self.InstanceProviderData.ReadBinary(reader, header.InstanceProviderOffset)
123
+
124
+ self.SceneProviderData = ObjectInitializationData()
125
+ self.SceneProviderData.ReadBinary(reader, header.SceneProviderOffset)
126
+
127
+ resourceProviderDataOffsets = reader.ReadOffsetArray(
128
+ header.InitObjectsArrayOffset
129
+ )
130
+ self.ResourceProviderData = []
131
+ for i in range(len(resourceProviderDataOffsets)):
132
+ o = ObjectInitializationData()
133
+ o.ReadBinary(reader, resourceProviderDataOffsets[i])
134
+ self.ResourceProviderData.append(o)
135
+
136
+ self.ReadResourcesBinary(reader, header)
137
+
138
+ def ReadResourcesJson(self, data: ContentCatalogDataJson):
139
+ buckets: list[ContentCatalogData.Bucket] = []
140
+
141
+ bucketStream = BytesIO(b64decode(data.m_BucketDataString))
142
+ bucketReader = BinaryReader(bucketStream)
143
+ bucketCount = bucketReader.ReadInt32()
144
+ for i in range(bucketCount):
145
+ offset = bucketReader.ReadInt32()
146
+ entryCount = bucketReader.ReadInt32()
147
+ entries: list[int] = []
148
+ for j in range(entryCount):
149
+ entries.append(bucketReader.ReadInt32())
150
+ buckets.append(ContentCatalogData.Bucket(offset, entries))
151
+
152
+ keys: list[
153
+ ClassJsonObject
154
+ | TypeReference
155
+ | Hash128
156
+ | int
157
+ | str
158
+ | WrappedSerializedObject[AssetBundleRequestOptions]
159
+ ] = []
160
+
161
+ keyDataStream = BytesIO(b64decode(data.m_KeyDataString))
162
+ keyReader = BinaryReader(keyDataStream)
163
+ keyCount = keyReader.ReadInt32()
164
+ for i in range(keyCount):
165
+ keyDataStream.seek(buckets[i].offset)
166
+ keys.append(SerializedObjectDecoder.DecodeV1(keyReader))
167
+
168
+ locations: list[ResourceLocation] = []
169
+
170
+ entryDataStream = BytesIO(b64decode(data.m_EntryDataString))
171
+ extraDataStream = BytesIO(b64decode(data.m_ExtraDataString))
172
+ entryReader = BinaryReader(entryDataStream)
173
+ extraReader = BinaryReader(extraDataStream)
174
+ entryCount = entryReader.ReadInt32()
175
+ for i in range(entryCount):
176
+ internalIdIndex = entryReader.ReadInt32()
177
+ providerIndex = entryReader.ReadInt32()
178
+ dependencyKeyIndex = entryReader.ReadInt32()
179
+ depHash = entryReader.ReadInt32()
180
+ dataIndex = entryReader.ReadInt32()
181
+ primaryKeyIndex = entryReader.ReadInt32()
182
+ resourceTypeIndex = entryReader.ReadInt32()
183
+
184
+ internalId = self.InternalIds[internalIdIndex]
185
+ splitIndex = internalId.find("#")
186
+ if splitIndex != -1:
187
+ try:
188
+ prefixIndex = int(internalId[:splitIndex])
189
+ internalId = (
190
+ self.InternalIdPrefixes[prefixIndex]
191
+ + internalId[splitIndex + 1 :]
192
+ )
193
+ except ValueError:
194
+ pass
195
+
196
+ providerId = self.ProviderIds[providerIndex]
197
+
198
+ dependencyKey = (
199
+ keys[dependencyKeyIndex] if dependencyKeyIndex >= 0 else None
200
+ )
201
+
202
+ if dataIndex >= 0:
203
+ extraDataStream.seek(dataIndex)
204
+ objData = SerializedObjectDecoder.DecodeV1(extraReader)
205
+ else:
206
+ objData = None
207
+
208
+ if self.Keys is None:
209
+ primaryKey = keys[primaryKeyIndex]
210
+ else:
211
+ primaryKey = self.Keys[primaryKeyIndex]
212
+
213
+ resourceType = self.ResourceTypes[resourceTypeIndex]
214
+
215
+ loc = ResourceLocation()
216
+ loc.ReadJson(
217
+ internalId,
218
+ providerId,
219
+ dependencyKey,
220
+ objData,
221
+ depHash,
222
+ primaryKey,
223
+ resourceType,
224
+ )
225
+ locations.append(loc)
226
+
227
+ self.Resources = {}
228
+ for i in range(len(buckets)):
229
+ bucketEntries = buckets[i].entries
230
+ locs = []
231
+ for j in range(len(bucketEntries)):
232
+ locs.append(locations[bucketEntries[j]])
233
+ self.Resources[keys[i]] = locs
234
+
235
+ def ReadResourcesBinary(
236
+ self, reader: CatalogBinaryReader, header: ContentCatalogDataBinaryHeader
237
+ ):
238
+ keyLocationOffsets = reader.ReadOffsetArray(header.KeysOffset)
239
+ self.Resources = {}
240
+ for i in range(0, len(keyLocationOffsets), 2):
241
+ keyOffset = keyLocationOffsets[i]
242
+ locationListOffset = keyLocationOffsets[i + 1]
243
+ key = SerializedObjectDecoder.DecodeV2(reader, keyOffset)
244
+
245
+ locationOffsets = reader.ReadOffsetArray(locationListOffset)
246
+ locations = []
247
+ for j in range(len(locationOffsets)):
248
+ location = ResourceLocation()
249
+ location.ReadBinary(reader, locationOffsets[j])
250
+ locations.append(location)
251
+
252
+ self.Resources[key] = locations
253
+
254
+
255
+ __all__ = ["ContentCatalogData"]
@@ -0,0 +1,39 @@
1
+ from .SerializedType import SerializedType
2
+ from ..JSON.ObjectInitializationDataJson import ObjectInitializationDataJson
3
+ from ..Reader.CatalogBinaryReader import CatalogBinaryReader
4
+
5
+
6
+ class ObjectInitializationData:
7
+ Id: str | None
8
+ ObjectType: SerializedType | None
9
+ Data: str | None
10
+
11
+ def __repr__(self):
12
+ return (
13
+ f"<{self.__class__.__name__}(Id={self.Id}, ObjectType={self.ObjectType})>"
14
+ )
15
+
16
+ def __init__(self):
17
+ self.Id = None
18
+ self.ObjectType = None
19
+ self.Data = None
20
+
21
+ def ReadJson(self, obj: ObjectInitializationDataJson):
22
+ self.Id = obj.m_Id
23
+ self.ObjectType = SerializedType()
24
+ self.ObjectType.ReadJson(obj.m_ObjectType)
25
+ self.Data = obj.m_Data
26
+
27
+ def ReadBinary(self, reader: CatalogBinaryReader, offset: int):
28
+ reader.BaseStream.seek(offset)
29
+ idOffset = reader.ReadUInt32()
30
+ objectTypeOffset = reader.ReadUInt32()
31
+ dataOffset = reader.ReadUInt32()
32
+
33
+ self.Id = reader.ReadEncodedString(idOffset)
34
+ self.ObjectType = SerializedType()
35
+ self.ObjectType.ReadBinary(reader, objectTypeOffset)
36
+ self.Data = reader.ReadEncodedString(dataOffset)
37
+
38
+
39
+ __all__ = ["ObjectInitializationData"]