Пример #1
0
        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));
        }
Пример #2
0
        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}");
                }
            }
        }
Пример #3
0
    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();
 }
Пример #5
0
        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
            });
        }
Пример #6
0
        // 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);
        }
Пример #7
0
 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);
        }
Пример #10
0
 public LocalizationDocument(BinaryReader reader)
 {
     docsID          = reader.ReadAlignedString();
     sheetID         = reader.ReadAlignedString();
     format          = reader.ReadInt32();
     textAsset       = new AssetPtr(reader);
     downloadOnStart = reader.ReadBoolean();
     reader.AlignStream();
 }
Пример #11
0
 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);
 }
Пример #12
0
        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);
            }
        }
Пример #13
0
        public AssetPtr[] ToArray()
        {
            AssetPtr[] result = new AssetPtr[Elements.Count];

            for (int i = 0; i < Elements.Count; i++)
            {
                result[i] = Elements[i].Asset;
            }

            return(result);
        }
Пример #14
0
        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();
        }
Пример #15
0
        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));
        }
Пример #16
0
    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();
    }
Пример #17
0
        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);
            }
        }
Пример #18
0
        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}");
                }
            }
        }
Пример #19
0
 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));
 }
Пример #20
0
        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);
            }
        }
Пример #21
0
        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)));
        }
Пример #22
0
        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);
            }
        }
Пример #23
0
        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--;
                }
            }
        }
Пример #24
0
        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);
            }
        }
Пример #25
0
        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);
        }
Пример #26
0
 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);
        }