Exemplo n.º 1
0
        private void CollectPatches()
        {
            foreach (var pack in contentPatcher.Helper.ContentPacks.GetOwned())
            {
                var patches = pack.ReadJsonFile <PatchList>("content.json");
                foreach (var patch in patches.Changes)
                {
                    if (patch.AnimationFrameTime > 0 && patch.AnimationFrameCount > 0)
                    {
                        if (patch.LogName == "")
                        {
                            Log.error("Animated patches must specify a LogName!");
                            continue;
                        }

                        if (patch.ToArea == new Rectangle())
                        {
                            patch.ToArea = new Rectangle(0, 0, patch.FromArea.Width, patch.FromArea.Height);
                        }

                        PatchData data = new PatchData();

                        object targetPatch = null;
                        foreach (var cpPatch in cpPatches)
                        {
                            var name = (string)cpPatch.GetType().GetProperty("LogName", PublicI).GetValue(cpPatch);
                            if (name == pack.Manifest.Name + " > " + patch.LogName)
                            {
                                targetPatch = cpPatch;
                                break;
                            }
                        }
                        if (targetPatch == null)
                        {
                            Log.error("Failed to find patch with name " + patch.LogName + "!?!?");
                            continue;
                        }
                        var appliedProp = targetPatch.GetType().GetProperty("IsApplied", PublicI);
                        var sourceProp  = targetPatch.GetType().GetProperty("FromLocalAsset", PublicI);
                        var targetProp  = targetPatch.GetType().GetProperty("TargetAsset", PublicI);
                        var tokValProp  = sourceProp.GetValue(targetPatch).GetType().GetProperty("Value", PublicI);

                        data.IsActive   = () => (bool)appliedProp.GetValue(targetPatch);
                        data.SourceFunc = () => pack.LoadAsset <Texture2D>((string)tokValProp.GetValue(sourceProp.GetValue(targetPatch)));
                        data.TargetFunc = () => FindTargetTexture((string)targetProp.GetValue(targetPatch));

                        animatedPatches.Add(patch, data);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void CollectPatches()
        {
            foreach (var pack in contentPatcher.Helper.ContentPacks.GetOwned())
            {
                var patches = pack.ReadJsonFile <PatchList>("content.json");
                foreach (var patch in patches.Changes)
                {
                    if (patch.AnimationFrameTime > 0 && patch.AnimationFrameCount > 0)
                    {
                        Log.trace("Loading animated patch from content pack " + pack.Manifest.UniqueID);
                        if (patch.LogName == null || patch.LogName == "")
                        {
                            Log.error("Animated patches must specify a LogName!");
                            continue;
                        }

                        PatchData data = new PatchData();

                        object targetPatch = null;
                        foreach (var cpPatch in cpPatches)
                        {
                            var path = cpPatch.GetType().GetProperty("Path", PublicI).GetValue(cpPatch);
                            if (path.ToString() == pack.Manifest.Name + " > " + patch.LogName)
                            {
                                targetPatch = cpPatch;
                                break;
                            }
                        }
                        if (targetPatch == null)
                        {
                            Log.error("Failed to find patch with name \"" + patch.LogName + "\"!?!?");
                            continue;
                        }
                        var appliedProp = targetPatch.GetType().GetProperty("IsApplied", PublicI);
                        var sourceProp  = targetPatch.GetType().GetProperty("FromAsset", PublicI);
                        var targetProp  = targetPatch.GetType().GetProperty("TargetAsset", PublicI);

                        data.patchObj     = targetPatch;
                        data.IsActive     = () => (bool)appliedProp.GetValue(targetPatch);
                        data.SourceFunc   = () => pack.LoadAsset <Texture2D>((string)sourceProp.GetValue(targetPatch));
                        data.TargetFunc   = () => FindTargetTexture((string)targetProp.GetValue(targetPatch));
                        data.FromAreaFunc = () => GetRectangleFromPatch(targetPatch, "FromArea");
                        data.ToAreaFunc   = () => GetRectangleFromPatch(targetPatch, "ToArea", new Rectangle(0, 0, data.FromAreaFunc().Width, data.FromAreaFunc().Height));

                        animatedPatches.Add(patch, data);
                    }
                }
            }
        }