コード例 #1
0
ファイル: ServerPackets.cs プロジェクト: jkloop45/Solution
 protected override void ReadPacket(BinaryReader BReader)
 {
     if (BReader.ReadBoolean())
     {
         Details = new ClientMapInfo(BReader);
     }
 }
コード例 #2
0
        public IEnumerator Start()
        {
            Logger.Log("Starting filemanager, imageDir: " + Main.ImageFolder);
            // settings are already loaded
            // get map files list from default path
            var mapPaths = Directory.GetFiles(Main.settings.defaultLoadingPath).ToList();

            // get all other paths
            foreach (var path in Main.settings.loadingPaths)
            {
                var filePaths = Directory.GetFiles(path);
                mapPaths.AddRange(filePaths);
            }
            // key=name, value=path
            var localMaps = mapPaths.ToDictionary(path => Path.GetFileName(path), path => path);


            // check for duplicates?? using hash??

            // get image files list
            // if image dir doesn't exist, create it
            if (!Directory.Exists(Main.ImageFolder))
            {
                Directory.CreateDirectory(Main.ImageFolder);
            }
            var imgPaths = Directory.GetFiles(Main.ImageFolder);
            var images   = new Dictionary <string, Texture2D>();

            foreach (var path in imgPaths)
            {
                var fileName = Path.GetFileName(path);
                var texture  = new Texture2D(1, 1);
                texture.LoadImage(File.ReadAllBytes(path));
                images[fileName] = texture;
            }
            foreach (var i in images.Keys)
            {
                Logger.Log("localImage: " + i);
            }

            // delete mapinfos if file is missing (keep only mapinfos where map is present)
            Main.settings.installedMaps = Main.settings.installedMaps.Where(m => localMaps.Keys.Contains(m.fileName)).ToList();


            // download latest json and cache it
            string text = null;

            yield return(StartCoroutine(GetURL("https://raw.githubusercontent.com/andreamatt/Skater-XL-maps/master/mapIndex.json", result => text = result)));

            Logger.Log("TEXT: " + text);
            var newIndex = text.FromJson <MapIndex>();

            Main.settings.mapIndex = newIndex;  // save new index


            // get image index
            string imagesJson = null;

            yield return(StartCoroutine(GetURL("https://api.github.com/repos/andreamatt/skater-xl-maps/contents/Images", result => imagesJson = result)));

            var imageInfoList = imagesJson.FromJson <List <ImageInfo> >();

            foreach (var ii in imageInfoList)
            {
                Logger.Log("Image: " + ii.name);
            }

            // if there are new previews download them
            // preview names are "{map file name}_*.jpg"
            var saveImage = new Action <string, Texture2D>((name, tex) => images[name] = tex);

            foreach (var ii in imageInfoList)
            {
                // if not in local, download it
                if (!images.ContainsKey(ii.name))
                {
                    // download them in parallel, maybe with coroutine, use Action to save the downloaded image in the previews dictionary (use lock for thread-safety) (load other images before this?)
                    yield return(StartCoroutine(DownloadImage(ii, saveImage)));
                }
            }


            // if there are new files without mapinfos, create mapinfos
            // using old index vs new index vs local map names
            var localMapInfoNames = Main.settings.installedMaps.Select(mi => mi.fileName);

            foreach (var localMap in localMaps)
            {
                var fileName = localMap.Key;
                var filePath = localMap.Value;
                // if localmapinfo is not present
                if (!localMapInfoNames.Contains(fileName))
                {
                    // always create badinfo and update it asap
                    var clientMapInfo = new ClientMapInfo()
                    {
                        completeInfo = false,
                        favourite    = false,
                        filePath     = filePath,
                        downloadDate = File.GetLastWriteTime(filePath).ToString(),
                        lastPlayed   = DateTime.MinValue.ToString()
                    };
                    Main.settings.installedMaps.Add(clientMapInfo);
                }
            }

            // update local mapinfos that need online info (just update all of them)
            foreach (var cmi in Main.settings.installedMaps)
            {
                var indexInfo = Main.settings.mapIndex.maps.FirstOrDefault(m => m.fileName == cmi.fileName);
                if (indexInfo != null)
                {
                    cmi.completeInfo = true;
                    cmi.UpdateBaseInfo(indexInfo);
                }
            }

            // update previews dictionary
            // add keys from localMaps and mapIndex
            foreach (var localMap in Main.settings.installedMaps)
            {
                previewIndex[localMap.fileName] = 0;
                if (!previews.ContainsKey(localMap.fileName))
                {
                    previews[localMap.fileName] = new List <Texture2D>();
                }
            }
            foreach (var map in Main.settings.mapIndex.maps)
            {
                previewIndex[map.fileName] = 0;
                if (!previews.ContainsKey(map.fileName))
                {
                    previews[map.fileName] = new List <Texture2D>();
                }
            }

            Logger.Log("Started filemanager");
        }
コード例 #3
0
        public static void LoadMap(ClientMapInfo MI)
        {
            if (MapInfo == MI)
            {
                return;
            }

            if (FloorTexture != null && !FloorTexture.Disposed)
            {
                FloorTexture.Dispose();
            }
            if (LightTexture != null && !LightTexture.Disposed)
            {
                LightTexture.Dispose();
            }

            if (MI == null)
            {
                M2CellInfo = null;
                return;
            }

            ObjectList.Add(MapObject.User);
            MapInfo = MI;

            try
            {
                string FileName = Path.Combine(Settings.MapPath, MapInfo.FileName + ".map");
                if (File.Exists(FileName))
                {
                    int          OffSet = 21;
                    Mir2CellInfo CI;
                    byte[]       FileBytes = File.ReadAllBytes(FileName);
                    int          W         = BitConverter.ToInt16(FileBytes, OffSet); OffSet += 2;
                    int          Xor       = BitConverter.ToInt16(FileBytes, OffSet); OffSet += 2;
                    int          H         = BitConverter.ToInt16(FileBytes, OffSet); OffSet += 2;
                    MapSize    = new Size((short)W ^ (short)Xor, H ^ Xor);
                    M2CellInfo = new Mir2CellInfo[MapSize.Width, MapSize.Height];

                    OffSet = 54;

                    for (int X = 0; X < MapSize.Width; X++)
                    {
                        for (int Y = 0; Y < MapSize.Height; Y++)
                        {
                            CI = new Mir2CellInfo
                            {
                                BackImage      = (int)(BitConverter.ToInt32(FileBytes, OffSet) ^ 0xAA38AA38),
                                MiddleImage    = (short)(BitConverter.ToInt16(FileBytes, OffSet += 4) ^ Xor),
                                FrontImage     = (short)(BitConverter.ToInt16(FileBytes, OffSet += 2) ^ Xor),
                                DoorIndex      = FileBytes[OffSet += 2],
                                DoorOffset     = FileBytes[++OffSet],
                                AnimationFrame = FileBytes[++OffSet],
                                AnimationTick  = FileBytes[++OffSet],
                                FileIndex      = FileBytes[++OffSet],
                                Light          = FileBytes[++OffSet],
                                Unknown        = FileBytes[++OffSet],
                            };
                            OffSet++;

                            M2CellInfo[X, Y] = CI;
                        }
                    }
                }
                else
                {
                    M2CellInfo = null;
                }
            }
            catch (Exception Ex)
            {
                if (Settings.LogErrors)
                {
                    Main.SaveError(Ex.ToString());
                }
            }
        }