Esempio n. 1
0
        private byte[] EncodeSkinJwt(AsymmetricCipherKeyPair newKey, ECDsa signKey, string username, string x5u)
        {
            MiNET.Utils.Skins.Skin skin = new Skin
            {
                Slim             = false,
                SkinData         = Encoding.Default.GetBytes(new string('Z', 8192)),
                SkinId           = "Standard_Custom",
                CapeData         = new byte[0],
                SkinGeometryName = "geometry.humanoid.custom",
                SkinGeometry     = ""
            };

            string skin64 = Convert.ToBase64String(skin.SkinData);
            string cape64 = Convert.ToBase64String(skin.CapeData);

            string skinData = $@"
{{
	""ADRole"": 0,
	""ClientRandomId"": {new Random().Next()},
	""CurrentInputMode"": 1,
	""DefaultInputMode"": 1,
	""DeviceModel"": ""Alex"",
	""DeviceOS"": 7,
	""GameVersion"": ""{McpeProtocolInfo.GameVersion}"",
	""IsEduMode"": {Config.GetProperty("EnableEdu", false).ToString().ToLower()},
	""GuiScale"": 0,
	""LanguageCode"": ""en_US"",
	""PlatformOfflineId"": """",
	""PlatformOnlineId"": """",
	""SelfSignedId"": ""{Guid.NewGuid().ToString()}"",
	""ServerAddress"": ""{base.ServerEndpoint.Address.ToString()}:{base.ServerEndpoint.Port.ToString()}"",
	""SkinData"": ""{skin64}"",
	""SkinId"": ""{skin.SkinId}"",
    ""SkinGeometryName"": ""{skin.SkinGeometryName}"",
    ""SkinGeometry"": ""{skin.SkinGeometry}"",
    ""CapeData"": ""{cape64}"",
	""TenantId"": ""38dd6634-1031-4c50-a9b4-d16cd9d97d57"",
	""ThirdPartyName"": ""{username}"",
	""UIProfile"": 0,
	""IsAlex"": 1
}}";

            string val = JWT.Encode(skinData, signKey, JwsAlgorithm.ES384, new Dictionary <string, object> {
                { "x5u", x5u }
            }, new JwtSettings()
            {
                JsonMapper = new JWTMapper()
            });

            return(Encoding.UTF8.GetBytes(val));
        }
Esempio n. 2
0
        private void LoadSkin(Skin skin)
        {
            try
            {
                if (skin == null)
                {
                    return;
                }

                EntityModel model = null;

                if (!skin.IsPersonaSkin)
                {
                    if (!string.IsNullOrWhiteSpace(skin.GeometryData) && !skin.GeometryData.Equals(
                            "null", StringComparison.InvariantCultureIgnoreCase))
                    {
                        try
                        {
                            if (string.IsNullOrWhiteSpace(skin.ResourcePatch) || skin.ResourcePatch == "null")
                            {
                                Log.Debug($"Resourcepatch null for player {Name}");
                            }
                            else
                            {
                                var resourcePatch = JsonConvert.DeserializeObject <SkinResourcePatch>(
                                    skin.ResourcePatch, GeometrySerializationSettings);

                                Dictionary <string, EntityModel> models = new Dictionary <string, EntityModel>();
                                BedrockResourcePack.LoadEntityModel(skin.GeometryData, models);

                                var processedModels = BedrockResourcePack.ProcessEntityModels(models);

                                if (processedModels == null || processedModels.Count == 0)
                                {
                                    Log.Warn($"!! Model count was 0 for player {NameTag} !!");

                                    if (!Directory.Exists("failed"))
                                    {
                                        Directory.CreateDirectory("failed");
                                    }

                                    File.WriteAllText(
                                        Path.Combine(
                                            "failed",
                                            $"{Environment.TickCount64}-{resourcePatch.Geometry.Default}.json"),
                                        skin.GeometryData);
                                }
                                else
                                {
                                    if (resourcePatch?.Geometry != null)
                                    {
                                        if (!processedModels.TryGetValue(resourcePatch.Geometry.Default, out model))
                                        {
                                            Log.Debug(
                                                $"Invalid geometry: {resourcePatch.Geometry.Default} for player {Name}");
                                        }
                                        else
                                        {
                                        }
                                    }
                                    else
                                    {
                                        Log.Debug($"Resourcepatch geometry was null for player {Name}");
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string name = "N/A";
                            Log.Debug(ex, $"Could not create geometry ({name}): {ex.ToString()} for player {Name}");
                        }
                    }
                    else
                    {
                        //Log.Debug($"Geometry data null for player {Name}");
                    }
                }

                if (model == null)
                {
                    ModelFactory.TryGetModel(
                        skin.Slim ? "geometry.humanoid.custom" : "geometry.humanoid.customSlim", out model);

                    /*model = skin.Slim ? (EntityModel) new Models.HumanoidCustomslimModel() :
                     *      (EntityModel) new HumanoidModel();*/// new Models.HumanoidCustomGeometryHumanoidModel();
                }

                if (model != null && ValidateModel(model, Name))
                {
                    Image <Rgba32> skinBitmap = null;

                    if (!skin.TryGetBitmap(model, out skinBitmap))
                    {
                        Log.Warn($"No custom skin data for player {Name}");

                        if (Alex.Instance.Resources.TryGetBitmap("entity/alex", out var rawTexture))
                        {
                            skinBitmap = rawTexture;
                        }
                    }

                    //if (!Directory.Exists("skins"))
                    //	Directory.CreateDirectory("skins");

                    //var path = Path.Combine("skins", $"{model.Description.Identifier}-{Environment.TickCount64}");
                    //File.WriteAllText($"{path}.json", skin.GeometryData);
                    //skinBitmap.SaveAsPng($"{path}.png");

                    var modelTextureSize = new Point(
                        (int)model.Description.TextureWidth, (int)model.Description.TextureHeight);

                    var textureSize = new Point(skinBitmap.Width, skinBitmap.Height);

                    if (modelTextureSize != textureSize)
                    {
                        if (modelTextureSize.Y > textureSize.Y)
                        {
                            skinBitmap = SkinUtils.ConvertSkin(skinBitmap, modelTextureSize.X, modelTextureSize.Y);
                        }

                        /*var bitmap = skinBitmap;
                         * bitmap.Mutate<Rgba32>(xx =>
                         * {
                         *      xx.Resize(modelTextureSize.X, modelTextureSize.Y);
                         * //	xx.Flip(FlipMode.Horizontal);
                         * });
                         *
                         * skinBitmap = bitmap;*/
                    }

                    GeometryName = model.Description.Identifier;

                    var modelRenderer = new EntityModelRenderer(
                        model, TextureUtils.BitmapToTexture2D(Alex.Instance.GraphicsDevice, skinBitmap));

                    if (modelRenderer.Valid)
                    {
                        ModelRenderer = modelRenderer;
                    }
                    else
                    {
                        modelRenderer.Dispose();
                        Log.Debug($"Invalid model: for player {Name} (Disposing)");
                    }
                }
                else
                {
                    Log.Debug($"Invalid model for player {Name}");
                }
            }
            catch (Exception ex)
            {
                Log.Warn(ex, $"Error while handling player skin.");
            }
        }
Esempio n. 3
0
        public void LoadSkin(Skin skin)
        {
            //PooledTexture2D skinTexture = null;
            Image <Rgba32> skinBitmap = null;

            if (!skin.TryGetBitmap(out skinBitmap))
            {
                Log.Warn($"No custom skin data for player {Name}");

                if (Alex.Instance.Resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture))
                {
                    skinBitmap = rawTexture;
                    //skinTexture = TextureUtils.BitmapToTexture2D(AlexInstance.GraphicsDevice, rawTexture);
                }
            }

            EntityModel model = null;

            if (!skin.IsPersonaSkin)
            {
                if (!string.IsNullOrWhiteSpace(skin.GeometryData) && skin.GeometryData != "null")
                {
                    try
                    {
                        if (string.IsNullOrWhiteSpace(skin.ResourcePatch) || skin.ResourcePatch == "null")
                        {
                            Log.Warn($"Resourcepatch null for player {Name}");
                        }
                        else
                        {
                            var resourcePatch = JsonConvert.DeserializeObject <SkinResourcePatch>(
                                skin.ResourcePatch, GeometrySerializationSettings);

                            GeometryModel geometryModel = null;
                            //	Dictionary<string, EntityModel> models = new Dictionary<string, EntityModel>();

                            if (!GeometryModel.TryParse(skin.GeometryData, resourcePatch, out geometryModel))
                            {
                                Log.Warn($"Failed to parse geometry for player {Name}");
                            }

                            /*try
                             * {
                             *      geometryModel = MCJsonConvert.DeserializeObject<GeometryModel>(skin.GeometryData);
                             * }
                             * catch (Exception ex)
                             * {
                             *      Log.Warn($"Failed to parse geometry for player {Name}: {ex.ToString()}");
                             * }*/

                            if (geometryModel == null || geometryModel.Geometry.Count == 0)
                            {
                                Log.Warn($"!! Model count was 0 for player {Name} !!");
                                //EntityModel.GetEntries(r.Skin.GeometryData, models);
                            }
                            else
                            {
                                if (resourcePatch?.Geometry != null)
                                {
                                    model = geometryModel.FindGeometry(resourcePatch.Geometry.Default);

                                    if (model == null)
                                    {
                                        Log.Warn(
                                            $"Invalid geometry: {resourcePatch.Geometry.Default} for player {Name}");
                                    }
                                    else
                                    {
                                        var modelTextureSize = model.Description != null ?
                                                               new Point((int)model.Description.TextureWidth, (int)model.Description.TextureHeight) :
                                                               new Point((int)model.Texturewidth, (int)model.Textureheight);

                                        var textureSize = new Point(skinBitmap.Width, skinBitmap.Height);

                                        if (modelTextureSize != textureSize)
                                        {
                                            int newHeight = modelTextureSize.Y > textureSize.Y ? textureSize.Y : modelTextureSize.Y;
                                            int newWidth  = modelTextureSize.X > textureSize.X ? textureSize.X: modelTextureSize.X;

                                            var bitmap = skinBitmap;
                                            //	bitmap.Mutate<Rgba32>(xx => xx.Resize(newWidth, newHeight));

                                            Image <Rgba32> skinTexture = new Image <Rgba32>(modelTextureSize.X, modelTextureSize.Y);

                                            skinTexture.Mutate <Rgba32>(
                                                c =>
                                            {
                                                c.DrawImage(bitmap, new SixLabors.ImageSharp.Point(0, 0), 1f);
                                            });

                                            skinBitmap = skinTexture;
                                        }
                                    }
                                }
                                else
                                {
                                    Log.Warn($"Resourcepatch geometry was null for player {Name}");
                                }
                            }

                            /*foreach (var mm in models.ToArray())
                             * {
                             *      if (ProcessEntityModel(models, mm.Value, false))
                             *      {
                             *              models.Remove(mm.Key);
                             *      }
                             * }
                             *
                             * foreach (var mm in models.ToArray())
                             * {
                             *      if (ProcessEntityModel(models, mm.Value, true))
                             *      {
                             *              models.Remove(mm.Key);
                             *      }
                             * }*/
                        }
                    }
                    catch (Exception ex)
                    {
                        string name = "N/A";

                        /*if (r.Skin.SkinResourcePatch != null)
                         * {
                         *      name = r.Skin.SkinResourcePatch.Geometry.Default;
                         * }*/
                        Log.Warn(ex, $"Could not create geometry ({name}): {ex.ToString()} for player {Name}");

                        //	File.WriteAllBytes(Path.Combine("/home/kenny/.config/Alex/skinDebug/failed", $"failed-{Environment.TickCount}.json"), Encoding.UTF8.GetBytes(skin.GeometryData));
                    }
                }
                else
                {
                    Log.Warn($"Geometry data null for player {Name}");
                }
            }

            if (model == null)
            {
                model = skin.Slim ? (EntityModel) new Models.HumanoidCustomslimModel() : (EntityModel) new Models.HumanoidCustomGeometryHumanoidModel();
            }

            if (model != null && ValidateModel(model, Name))
            {
                var modelRenderer = new EntityModelRenderer(model, TextureUtils.BitmapToTexture2D(Alex.Instance.GraphicsDevice, skinBitmap));

                if (modelRenderer.Valid)
                {
                    ModelRenderer = modelRenderer;
                }
                else
                {
                    modelRenderer.Dispose();
                    Log.Warn($"Invalid model: for player {Name} (Disposing)");
                }
            }
            else
            {
                Log.Warn($"Invalid model for player {Name}");
            }
        }
Esempio n. 4
0
        public void LoadSkin(Skin skin)
        {
            Image <Rgba32> skinBitmap = null;

            if (!skin.TryGetBitmap(out skinBitmap))
            {
                Log.Warn($"No custom skin data for player {Name}");

                if (Alex.Instance.Resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture))
                {
                    skinBitmap = rawTexture;
                }
            }

            EntityModel model = null;

            if (!skin.IsPersonaSkin)
            {
                if (!string.IsNullOrWhiteSpace(skin.GeometryData) && skin.GeometryData != "null")
                {
                    try
                    {
                        if (string.IsNullOrWhiteSpace(skin.ResourcePatch) || skin.ResourcePatch == "null")
                        {
                            Log.Debug($"Resourcepatch null for player {Name}");
                        }
                        else
                        {
                            var resourcePatch = JsonConvert.DeserializeObject <SkinResourcePatch>(
                                skin.ResourcePatch, GeometrySerializationSettings);

                            GeometryModel geometryModel = null;
                            if (!GeometryModel.TryParse(skin.GeometryData, resourcePatch, out geometryModel))
                            {
                                Log.Debug($"Failed to parse geometry for player {Name}");
                            }

                            if (geometryModel == null || geometryModel.Geometry.Count == 0)
                            {
                                //Log.Warn($"!! Model count was 0 for player {Name} !!");
                            }
                            else
                            {
                                if (resourcePatch?.Geometry != null)
                                {
                                    model = geometryModel.FindGeometry(resourcePatch.Geometry.Default);

                                    if (model == null)
                                    {
                                        Log.Debug(
                                            $"Invalid geometry: {resourcePatch.Geometry.Default} for player {Name}");
                                    }
                                    else
                                    {
                                        var modelTextureSize = new Point((int)model.Description.TextureWidth, (int)model.Description.TextureHeight);

                                        var textureSize = new Point(skinBitmap.Width, skinBitmap.Height);

                                        if (modelTextureSize != textureSize)
                                        {
                                            int newHeight = modelTextureSize.Y > textureSize.Y ? textureSize.Y : modelTextureSize.Y;
                                            int newWidth  = modelTextureSize.X > textureSize.X ? textureSize.X: modelTextureSize.X;

                                            var bitmap = skinBitmap;
                                            bitmap.Mutate <Rgba32>(xx =>
                                            {
                                                xx.Resize(modelTextureSize.X, modelTextureSize.Y);
                                                xx.Flip(FlipMode.Horizontal);
                                            });

                                            skinBitmap = bitmap;
                                        }
                                    }
                                }
                                else
                                {
                                    Log.Debug($"Resourcepatch geometry was null for player {Name}");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string name = "N/A";
                        Log.Debug(ex, $"Could not create geometry ({name}): {ex.ToString()} for player {Name}");
                    }
                }
                else
                {
                    Log.Debug($"Geometry data null for player {Name}");
                }
            }

            if (model == null)
            {
                model = skin.Slim ? (EntityModel) new Models.HumanoidCustomslimModel() :
                        (EntityModel) new HumanoidModel();                // new Models.HumanoidCustomGeometryHumanoidModel();
            }

            if (model != null && ValidateModel(model, Name))
            {
                var modelRenderer = new EntityModelRenderer(model, TextureUtils.BitmapToTexture2D(Alex.Instance.GraphicsDevice, skinBitmap));

                if (modelRenderer.Valid)
                {
                    ModelRenderer = modelRenderer;
                }
                else
                {
                    modelRenderer.Dispose();
                    Log.Debug($"Invalid model: for player {Name} (Disposing)");
                }
            }
            else
            {
                Log.Debug($"Invalid model for player {Name}");
            }
        }