private void AudioFieldsGUI(ref VerticalGUIRect guiRect, BlockData block) { block.DigAudio = EditorAssetUtility.AssetPtrField(guiRect.Next, s_DigAudioContent, block.DigAudio, typeof(AudioClip)); block.PlaceAudio = EditorAssetUtility.AssetPtrField(guiRect.Next, s_PlaceAudioContent, block.PlaceAudio, typeof(AudioClip)); guiRect.Space(10); m_StepAudioList ??= new ReorderableList(null, typeof(AssetPtr), true, true, true, true) { elementHeight = EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.singleLineHeight, drawHeaderCallback = (Rect pos) => { EditorGUI.LabelField(pos, s_StepAudiosContent); }, drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { rect.y += EditorGUIUtility.standardVerticalSpacing; rect.height = EditorGUIUtility.singleLineHeight; AssetPtr asset = m_StepAudioList.list[index] as AssetPtr; m_StepAudioList.list[index] = EditorAssetUtility.AssetPtrField(rect, GUIContent.none, asset, typeof(AudioClip)); } }; m_StepAudioList.list = block.StepAudios ??= new List <AssetPtr>(); m_StepAudioList.DoList(guiRect.GetNext(m_StepAudioList.GetHeight(), true, true)); }
static void Install( Apk apk, SerializedAssets assets, HashSet <string> toInstall, InvocationResult res, Dictionary <string, string> levels ) { foreach (string levelID in toInstall) { string levelFolder = levels[levelID]; try { JsonLevel level = JsonLevel.LoadFromFolder(levelFolder); // We use transactions here so if these throw // an exception, which happens when levels are // invalid, then it doesn't modify the APK in // any way that might screw things up later. var assetsTxn = new SerializedAssets.Transaction(assets); var apkTxn = new Apk.Transaction(); AssetPtr levelPtr = level.AddToAssets(assetsTxn, apkTxn, levelID); // Danger should be over, nothing here should fail assetsTxn.ApplyTo(assets); apkTxn.ApplyTo(apk); res.installedLevels.Add(levelID); } catch (FileNotFoundException e) { res.installSkipped.Add(levelID, $"Missing file referenced by level: {e.FileName}"); } catch (JsonReaderException e) { res.installSkipped.Add(levelID, $"Invalid level JSON: {e.Message}"); } } }
void ResourceListener(AssetPtr ptr) { if (ptr == null || ptr.Data == null) { return; } if (!ptr.Data.url.Contains(mCurnAnimatorame)) { return; } GameObject cameraanimator = new GameObject(mCurnAnimatorame); CameraPath cPath = cameraanimator.AddComponent <CameraPath>(); CameraPathAnimator animator = cameraanimator.AddComponent <CameraPathAnimator>(); XmlDocument xml = new XmlDocument(); xml.LoadXml(ptr.Data.text); cPath.FromXML(xml); if (Camera.main != null) { animator.animationObject = Camera.main.transform; } BaseScene scene = SceneManager.Instance.GetCurScene(); if (scene != null) { animator.AnimationCustomEvent += scene.GetCameraPathManager().OnCustomEvent; animator.AnimationFinishedEvent += animator_AnimationFinishedEvent; } FollowAnimator = animator; animator.Play(); }
public LocalizedTextMeshProUGUI(BinaryReader reader, int _length) { text = new AssetPtr(reader); maintainTextAlignment = reader.ReadByte(); reader.AlignStream(); key = reader.ReadAlignedString(); }
public static SpriteAssetData CreateCoverSprite( SerializedAssets.Transaction assets, AssetPtr customTexture, string name ) { // Default Sprite ulong pd = 45; var sp = assets.GetAssetAt(pd); if (!sp.data.GetType().Equals(typeof(SpriteAssetData))) { throw new ApplicationException($"Default Sprite data does not exist at PathID: {pd} instead it has Type {sp.data.GetType()} with TypeID: {sp.typeID}"); } var sprite = sp.data as SpriteAssetData; return(new SpriteAssetData() { name = name + "CoverSprite", texture = customTexture, atlasTags = sprite.atlasTags, extrude = sprite.extrude, floats = sprite.floats, guid = sprite.guid, isPolygon = sprite.isPolygon, second = sprite.second, spriteAtlas = sprite.spriteAtlas, bytesAfterTexture = sprite.bytesAfterTexture }); }
// Here is the list of components of the Saber's GameObject: // Transform, VRController, BoxCollider, Rigidbody, Saber (this), SaberTypeObject, SaberModelContainer // MeshFilters of importance: no idea // Children: 2 // Transforms: (142, 77), (142, 76) // GameObjects: (142, 34): Top, (142, 38): Bottom // To insert custom saber, should just need to add new gameobject, set that object's parent to saber, disable all old mesh filters in top/bottom public Saber(BinaryReader reader, int _length) { topPos = new AssetPtr(reader); bottomPos = new AssetPtr(reader); handlePos = new AssetPtr(reader); vrController = new AssetPtr(reader); saberTypeObject = new AssetPtr(reader); }
public BeatmapDifficulty(BinaryReader reader) { difficulty = reader.ReadInt32(); difficultyRank = reader.ReadInt32(); noteJumpMovementSpeed = reader.ReadSingle(); noteJumpStartBeatOffset = reader.ReadInt32(); beatmapData = new AssetPtr(reader); }
public LevelPackBehaviorData(BinaryReader reader, int length) { packID = reader.ReadAlignedString(); packName = reader.ReadAlignedString(); coverImage = new AssetPtr(reader); isPackAlwaysOwned = Convert.ToBoolean(reader.ReadByte()); reader.AlignStream(); beatmapLevelCollection = new AssetPtr(reader); }
public static AssetPtr AssetPtrField(Rect rect, GUIContent label, AssetPtr value, Type assetType, out bool changed) { value ??= AssetPtr.NullPtr; Object asset = LoadAssetByGUID(value.AssetGUID, assetType); Object newAsset = EditorGUI.ObjectField(rect, label, asset, assetType, false); changed = newAsset != asset; return(changed ? newAsset.GetAssetPtr() : value); }
public LocalizationDocument(BinaryReader reader) { docsID = reader.ReadAlignedString(); sheetID = reader.ReadAlignedString(); format = reader.ReadInt32(); textAsset = new AssetPtr(reader); downloadOnStart = reader.ReadBoolean(); reader.AlignStream(); }
public TransformAssetData(BinaryReader reader, int _length) { gameObject = new AssetPtr(reader); localRotation = new AssetVector4(reader, 16); localPosition = new AssetVector3(reader, 12); localScale = new AssetVector3(reader, 12); children = reader.ReadPrefixedList(r => new AssetPtr(r)); parent = new AssetPtr(reader); }
public void ElementGUI(Rect rect, GUIContent label, ref int?location) { AssetPtr asset = location == null ? AssetPtr.NullPtr : Elements[location.Value].Asset; AssetPtr newAsset = EditorAssetUtility.AssetPtrField(rect, label, asset, typeof(T), out bool changed); if (changed) { SetAssetToLocation(ref location, newAsset); } }
public AssetPtr[] ToArray() { AssetPtr[] result = new AssetPtr[Elements.Count]; for (int i = 0; i < Elements.Count; i++) { result[i] = Elements[i].Asset; } return(result); }
public GameObjectAssetData(BinaryReader reader, int _length) { int size = reader.ReadInt32(); components = new AssetPtr[size]; for (int i = 0; i < size; i++) { components[i] = new AssetPtr(reader); } layer = reader.ReadUInt32(); name = reader.ReadAlignedString(); tag = reader.ReadUInt16(); isActive = reader.ReadBoolean(); }
public TextMeshPro(BinaryReader reader, int length) { long start = reader.BaseStream.Position; material = new AssetPtr(reader); color = new SimpleColor(reader, 16); raycastTarget = reader.ReadByte(); reader.AlignStream(); cullState = new PersistentCalls(reader); text = reader.ReadAlignedString(); rightToLeft = reader.ReadByte(); reader.AlignStream(); fontAsset = new AssetPtr(reader); remainingData = reader.ReadBytes(length - (int)(reader.BaseStream.Position - start)); }
private void OnAssetComplete(AssetPtr asset) { mMaterialAssetPtr = asset; UnityEngine.Object[] objs = asset.Data.LoadAll(); foreach (UnityEngine.Object obj in objs) { if (obj is Material) { materials.Add(obj.name, obj as Material); } } asset.Data.UnloadWebStream(); }
public void SetAssetToLocation(ref int?location, AssetPtr asset) { if (location != null) { int index = location.Value; Element element = Elements[index]; Assert.AreNotEqual(element.Asset, AssetPtr.NullPtr); if (element.Asset == asset) { return; } if (--element.RefCount == 0) { Elements.RemoveAt(index); IndexMap.Remove(element.Asset.AssetGUID); for (int i = index; i < Elements.Count; i++) { IndexMap[Elements[i].Asset.AssetGUID] = i; } OnElementRemoved?.Invoke(index); } } if (asset == AssetPtr.NullPtr) { location = null; } else if (IndexMap.TryGetValue(asset.AssetGUID, out int index)) { location = index; Elements[index].RefCount++; } else { location = index = Elements.Count; Elements.Add(new Element { Asset = asset, RefCount = 1 }); IndexMap.Add(asset.AssetGUID, index); } }
static void EnsureInstalled( Apk apk, SerializedAssets assets, HashSet <string> existingLevels, InvocationResult res, Dictionary <string, string> ensureInstalled ) { LevelCollectionBehaviorData extrasCollection = assets.FindExtrasLevelCollection(); foreach (KeyValuePair <string, string> entry in ensureInstalled) { string levelID = entry.Key; string levelFolder = entry.Value; try { JsonLevel level = JsonLevel.LoadFromFolder(levelFolder); if (existingLevels.Contains(levelID)) { res.installSkipped.Add(levelID, "Present"); } else { // We use transactions here so if these throw // an exception, which happens when levels are // invalid, then it doesn't modify the APK in // any way that might screw things up later. var assetsTxn = new SerializedAssets.Transaction(assets); var apkTxn = new Apk.Transaction(); AssetPtr levelPtr = level.AddToAssets(assetsTxn, apkTxn, levelID); // Danger should be over, nothing here should fail assetsTxn.ApplyTo(assets); extrasCollection.levels.Add(levelPtr); apkTxn.ApplyTo(apk); existingLevels.Add(levelID); res.installedLevels.Add(levelID); } } catch (FileNotFoundException e) { res.installSkipped.Add(levelID, $"Missing file referenced by level: {e.FileName}"); } catch (JsonReaderException e) { res.installSkipped.Add(levelID, $"Invalid level JSON: {e.Message}"); } } }
public LevelBehaviorData(BinaryReader reader, int length) { levelID = reader.ReadAlignedString(); songName = reader.ReadAlignedString(); songSubName = reader.ReadAlignedString(); songAuthorName = reader.ReadAlignedString(); levelAuthorName = reader.ReadAlignedString(); audioClip = new AssetPtr(reader); beatsPerMinute = reader.ReadSingle(); songTimeOffset = reader.ReadSingle(); shuffle = reader.ReadSingle(); shufflePeriod = reader.ReadSingle(); previewStartTime = reader.ReadSingle(); previewDuration = reader.ReadSingle(); coverImage = new AssetPtr(reader); environment = new AssetPtr(reader); difficultyBeatmapSets = reader.ReadPrefixedList(r => new BeatmapSet(r)); }
public void TestBigFile() { using (Apk apk = new Apk(baseAPKPath)) { byte[] data = apk.ReadEntireEntry(Apk.MainAssetsFile); var assets = TestRoundTrips(data, "big"); var existing = assets.ExistingLevelIDs(); Assert.NotEmpty(existing); Assert.False(existing.Contains("BUBBLETEA"), "Run tests on a non-patched APK"); JsonLevel level = JsonLevel.LoadFromFolder(repoPath("testdata/bubble_tea_song/")); // pass null as the apk so it doesn't get modified AssetPtr levelPtr = level.AddToAssets(assets, null); LevelCollectionBehaviorData extrasCollection = assets.FindExtrasLevelCollection(); extrasCollection.levels.Add(levelPtr); byte[] outData = assets.ToBytes(); File.WriteAllBytes($"../../../../testoutput/bubble_tea_mod.asset", outData); } }
public SpriteAssetData(BinaryReader reader, int _length) { long start = reader.BaseStream.Position; name = reader.ReadAlignedString(); // Rect, Vector2, Vector4, float, Vector2 floats = new float[13]; for (int i = 0; i < floats.Length; i++) { floats[i] = reader.ReadSingle(); } extrude = reader.ReadUInt32(); isPolygon = reader.ReadBoolean(); reader.AlignStream(); guid = reader.ReadBytes(16); second = reader.ReadInt64(); atlasTags = reader.ReadPrefixedList(r => new AssetPtr(r)); spriteAtlas = new AssetPtr(reader); // SpriteAtlas texture = new AssetPtr(reader); bytesAfterTexture = reader.ReadBytes((int)(_length - (reader.BaseStream.Position - start))); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("arguments: pathToAPKFileToModify levelFolders..."); return; } string apkPath = args[0]; using (Apk apk = new Apk(apkPath)) { apk.PatchSignatureCheck(); byte[] data = apk.ReadEntireEntry(Apk.MainAssetsFile); SerializedAssets assets = SerializedAssets.FromBytes(data); HashSet <string> existingLevels = assets.ExistingLevelIDs(); LevelCollectionBehaviorData extrasCollection = assets.FindExtrasLevelCollection(); for (int i = 1; i < args.Length; i++) { Utils.FindLevels(args[i], levelFolder => { JsonLevel level = JsonLevel.LoadFromFolder(levelFolder); string levelID = level.LevelID(); if (existingLevels.Contains(levelID)) { Console.WriteLine($"Present: {level._songName}"); } else { Console.WriteLine($"Adding: {level._songName}"); AssetPtr levelPtr = level.AddToAssets(assets, apk); extrasCollection.levels.Add(levelPtr); existingLevels.Add(levelID); } }); } byte[] outData = assets.ToBytes(); apk.ReplaceAssetsFile(Apk.MainAssetsFile, outData); } }
private void RenderingFieldsGUI(ref VerticalGUIRect guiRect, BlockData block) { MainWnd.BlockMeshes.ElementGUI(guiRect.Next, s_MeshContent, ref block.Mesh); AssetPtr meshPtr = MainWnd.BlockMeshes[block.Mesh]; BlockMesh mesh = EditorAssetUtility.LoadAssetByGUID <BlockMesh>(meshPtr.AssetGUID); if (!mesh) { EditorGUI.HelpBox(guiRect.GetNext(40, true, true), "You should assign an empty mesh if you do not want this block to be rendered.", MessageType.Error); } else if (mesh.Faces.Length == 0) { EditorGUI.HelpBox(guiRect.GetNext(40, true, true), "This block will never be rendered.", MessageType.Warning); } else { MainWnd.BlockMaterials.ElementGUI(guiRect.Next, s_MaterialContent, ref block.Material); BlockMesh.FaceData[] faces = mesh.Faces; ArrayUtility.EnsureArrayReferenceAndSize(ref block.Textures, faces.Length, true); for (int i = 0; i < faces.Length; i++) { BlockFace face = faces[i].Face; EditorGUI.LabelField(guiRect.Next, face.ToString(), EditorStyles.boldLabel); ArrayUtility.EnsureArrayReferenceAndSize(ref block.Textures[i], 3, true); EditorGUI.indentLevel++; for (int j = 0; j < 3; j++) { MainWnd.BlockTextures.ElementGUI(guiRect.Next, s_TextureContents[j], ref block.Textures[i][j]); } EditorGUI.indentLevel--; } } }
public void TestBigFile() { using (Apk apk = new Apk(baseAPKPath)) { byte[] data = apk.ReadEntireEntry(Apk.MainAssetsFile); var assets = TestRoundTrips(data, "big"); var existing = assets.ExistingLevelIDs(); Assert.NotEmpty(existing); Assert.False(existing.Contains("BUBBLETEA"), "Run tests on a non-patched APK"); JsonLevel level = JsonLevel.LoadFromFolder(repoPath("testdata/bubble_tea_song/")); var assetsTxn = new SerializedAssets.Transaction(assets); var apkTxn = new Apk.Transaction(); AssetPtr levelPtr = level.AddToAssets(assetsTxn, apkTxn, level.GenerateBasicLevelID()); assetsTxn.ApplyTo(assets); // don't apply apkTxn so our tests don't modify the APK LevelCollectionBehaviorData extrasCollection = assets.FindExtrasLevelCollection(); extrasCollection.levels.Add(levelPtr); byte[] outData = assets.ToBytes(); File.WriteAllBytes($"../../../../testoutput/bubble_tea_mod.asset", outData); } }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("arguments: pathToAPKFileToModify levelFolders..."); return; } string apkPath = args[0]; using (Apk apk = new Apk(apkPath)) { apk.PatchSignatureCheck(); byte[] data = apk.ReadEntireEntry(apk.MainAssetsFile()); SerializedAssets assets = SerializedAssets.FromBytes(data, apk.version); HashSet <string> existingLevels = assets.ExistingLevelIDs(); LevelCollectionBehaviorData extrasCollection = assets.FindExtrasLevelCollection(); for (int i = 1; i < args.Length; i++) { Utils.FindLevels(args[i], levelFolder => { try { JsonLevel level = JsonLevel.LoadFromFolder(levelFolder); string levelID = level.GenerateBasicLevelID(); if (existingLevels.Contains(levelID)) { Console.WriteLine($"Present: {level._songName}"); } else { Console.WriteLine($"Adding: {level._songName}"); // We use transactions here so if these throw // an exception, which happens when levels are // invalid, then it doesn't modify the APK in // any way that might screw things up later. var assetsTxn = new SerializedAssets.Transaction(assets); var apkTxn = new Apk.Transaction(); AssetPtr levelPtr = level.AddToAssets(assetsTxn, apkTxn, levelID); // Danger should be over, nothing here should fail assetsTxn.ApplyTo(assets); extrasCollection.levels.Add(levelPtr); existingLevels.Add(levelID); apkTxn.ApplyTo(apk); } } catch (FileNotFoundException e) { Console.WriteLine("[SKIPPING] Missing file referenced by level: {0}", e.FileName); } catch (JsonReaderException e) { Console.WriteLine("[SKIPPING] Invalid level JSON: {0}", e.Message); } }); } byte[] outData = assets.ToBytes(); apk.ReplaceAssetsFile(apk.MainAssetsFile(), outData); apk.Save(); } Console.WriteLine("Signing APK..."); Signer.Sign(apkPath); }
public LocalizationAsset(BinaryReader reader) { textAsset = new AssetPtr(reader); format = reader.ReadInt32(); }
public MonoBehaviorAssetData( BinaryReader reader, int length, SerializedAssets.TypeRef typeRef, Apk.Version version ) { int startOffset = (int)reader.BaseStream.Position; gameObject = new AssetPtr(reader); enabled = reader.ReadInt32(); script = new AssetPtr(reader); name = reader.ReadAlignedString(); int headerLen = (int)reader.BaseStream.Position - startOffset; if (typeRef.scriptID.SequenceEqual(LevelBehaviorData.ScriptID)) { data = new LevelBehaviorData(reader, length - headerLen); return; } if (typeRef.scriptID.SequenceEqual(LevelCollectionBehaviorData.ScriptID)) { data = new LevelCollectionBehaviorData(reader, length - headerLen); return; } if (typeRef.scriptID.SequenceEqual(BeatmapDataBehaviorData.ScriptID)) { data = new BeatmapDataBehaviorData(reader, length - headerLen, version); return; } if (typeRef.scriptID.SequenceEqual(LevelPackBehaviorData.ScriptID)) { data = new LevelPackBehaviorData(reader, length - headerLen, version); return; } if (typeRef.scriptID.SequenceEqual(ColorManager.ScriptID)) { data = new ColorManager(reader, length - headerLen); return; } if (typeRef.scriptID.SequenceEqual(SimpleColor.ScriptID)) { data = new SimpleColor(reader, length - headerLen); return; } if (typeRef.scriptID.SequenceEqual(BeatmapLevelPackCollection.ScriptID)) { data = new BeatmapLevelPackCollection(reader, length - headerLen); return; } if (typeRef.scriptID.SequenceEqual(AlwaysOwnedBehaviorData.ScriptID)) { data = new AlwaysOwnedBehaviorData(reader, length - headerLen); return; } switch (script.pathID) { default: data = new UnknownBehaviorData(reader, length - headerLen); break; } if (!(data is UnknownBehaviorData)) { Console.WriteLine($"Type: {data.GetType()} ScriptHash: {BitConverter.ToString(typeRef.scriptID).Replace("-", "")}"); } }
public MonoBehaviorAssetData() { gameObject = new AssetPtr(0, 0); enabled = 1; }
public static AssetPtr AssetPtrField(Rect rect, GUIContent label, AssetPtr value, Type assetType) { return(AssetPtrField(rect, label, value, assetType, out _)); }
// 16, 19, 33, 36 public MeshFilterAssetData(BinaryReader reader, int _length) { gameObject = new AssetPtr(reader); mesh = new AssetPtr(reader); }