コード例 #1
0
ファイル: Reskin.cs プロジェクト: eim64/DuckGameReskins
        public static void InitializeReskins()
        {
            MonoMain.loadMessage = "loading new reskins";


            List <string> files = new List <string>(GetFiles(Directory.GetCurrentDirectory(), "*.rsk"));

            foreach (string dir in ModLoader.accessibleMods.Select(x => x?.configuration?.contentDirectory?.Replace('/', '\\')).Where(x => x != null))
            {
                files.AddRange(GetFiles(dir, "*.rsk", false));
            }

            foreach (Team team in files.Select(x => Team.Deserialize(x)))
            {
                if (team == null || !team.hasHat || team.hat.texture.height <= ReskinFile.HatHeight || team.hat.texture.width != 64)
                {
                    continue;
                }

                DevConsole.Log("trying to load skin: " + team.name, Color.Green);
                ReskinFile reskin = tryLoadReskin(team.hat.texture);
                if (reskin == null)
                {
                    continue;
                }

                string dir = CreateReskinFiles(reskin);

                ReskinFile file = new ReskinFile(reskin.Hat);
                file.OtherData.Add(new TextChunk("MD5", reskin.UID));

                if (!IsValid(GetReskin(reskinMod.ReskinPath + reskin.UID)))
                {
                    continue;
                }

                if (!hatData.ContainsKey(reskin.UID))
                {
                    hatData.Add(reskin.UID, team.customData);
                }

                team.customData = file.getHat(team.name + "md5");;

                file.Hat.Dispose();
                reskin.Hat.Dispose();

                DevConsole.Log("successfully loaded: " + reskin.UID + "/" + team.name + ", with customdatasize: " + team.customData.Length, Color.Green);

                Teams.AddExtraTeam(team);
            }

            DuckEvents.OnDuckQuack += OnDuckQuack;
            DuckEvents.OnDuckSpawn += OnDuckSpawned;

            MonoMain.loadMessage = "loading mods";
        }
コード例 #2
0
        void HatChange(Profile pro, Tex2D customHat = null)
        {
            Tex2D hat = customHat ?? pro?.team?.hat?.texture;

            resetReskin(pro);

            if (pro?.duck == null || hat == null || hat.height <= ReskinFile.HatHeight || hat.width != 64)
            {
                return;
            }


            ReskinFile file = Reskin.tryLoadReskin(hat, false);


            if (file == null)
            {
                DevConsole.Log("Error loading reskin", Color.Red);
                return;
            }


            string md5 = (file.getChunk("MD5") as TextChunk)?.Text;
            string dir;

            if (Network.isActive && md5 != null && !pro.localPlayer)
            {
                if (Reskin.Exists(md5))
                {
                    dir = reskinMod.ReskinPath + md5;
                }
                else
                {
                    requestReskin(pro, md5);

                    return;
                }
            }
            else
            {
                dir = Reskin.CreateReskinFiles(file);
            }

            Reskin r = Reskin.GetReskin(dir);

            if (!Reskin.IsValid(r))
            {
                DevConsole.Log("something is wrong with that reskin!", Color.Red); return;
            }

            DevConsole.Log("skin appied to " + pro.name, Color.Green);
            ActiveReskins.Add(pro, r);
            r.Apply(pro.duck);
        }
コード例 #3
0
ファイル: Reskin.cs プロジェクト: eim64/DuckGameReskins
        public static string CreateReskinFiles(ReskinFile file)
        {
            string folder = reskinMod.ReskinPath + file.UID + '\\';

            if (!Directory.Exists(reskinMod.ReskinPath))
            {
                Directory.CreateDirectory(reskinMod.ReskinPath);
            }
            if (Directory.Exists(folder))
            {
                return(folder);
            }
            else
            {
                Directory.CreateDirectory(folder);
            }

            foreach (var chunk in file.OtherData)
            {
                CreateFile(chunk, folder);
            }

            return(folder);
        }
コード例 #4
0
ファイル: Reskin.cs プロジェクト: eim64/DuckGameReskins
        public static ReskinFile tryLoadReskin(Tex2D texture, bool loadHat = true)
        {
            try{ return(ReskinFile.ParseFile(TextureHelper.getBitmap(texture), loadHat)); } catch { }

            return(null);
        }