コード例 #1
0
        public InstallMapDialogue(demoreading.mapstatus status)
        {
            InitializeComponent();

            globalStat = status;

            if (status.isWorkshop)
            {
                //Download the workshop object (only info)
                workshopfile = WorkshopFile.get(new WorkshopURI(globalStat.activeParser.Map));

                //Set mapname title
                target_mapname.Content = workshopfile.response.publishedfiledetails[0].title + "   |   " + workshopfile.response.publishedfiledetails[0].file_size / 1024 / 1024 + " mb";

                //Temporarily using the description for this box right now
                string desc = workshopfile.response.publishedfiledetails[0].description;
                if (desc.Length > 128)
                {
                    desc = desc.Substring(0, 128) + "...";
                }
                target_mapcreator.Content = desc;

                //Set the preview image
                target_previewImage.Source = Workshop.downloadUGCImage(workshopfile.response.publishedfiledetails[0].preview_url);
            }
        }
コード例 #2
0
        static int Main(string[] args)
        {
            //First thing: Read the demo file header. This gives us all the information we need to run the program from
            //Since it stores stuff like length, mapname etc.

            //Do parsing
            DemoParser demofile = new DemoParser(File.OpenRead("solution.dem"));

            demofile.ParseHeader();

            //TRY AND FIND INSTANCE OF MAP ON DISK
            Debug.Info("Scanning for map on disk");

            //Do workshop check
            bool   isWorkshop = false;
            string checkPath  = "maps/";
            string localname  = demofile.Map;

            if (demofile.Map.StartsWith("workshop")) //Detected its a workshop map
            {
                isWorkshop = true;
                checkPath  = "maps/workshop/"; //Switch to the workshopped folder
                Debug.Log("Map workshopped");

                //Sets the local name to something that will not cause collisions
                string[] demoref = demofile.Map.Split('/');
                localname = demoref[1] + demoref[2];
            }

            //Go through the folder to check if the instance is still there
            foreach (string map in Directory.GetFiles(checkPath, "*.maprad"))
            {
                if (Path.GetFileNameWithoutExtension(map) == localname)
                {
                    Debug.Success("Found match on disk! {0}", map); //phew, no need to flood steam servers!

                    //Since it found a pre-downloaded instance it can just carry on with that instance + demo

                    doProcessing(serialwrite.Binary.ReadFromBinaryFile <mapData>(map), demofile);

                    //Exit the loop and method
                    Console.ReadLine();
                    return(0);
                }
            }

            //So the map wasn't found, therefore look for it on the workshop
            if (isWorkshop)
            {
                Debug.Info("Workshop map was not found on disk, downloading now...");
                WorkshopFile file = WorkshopFile.get(new WorkshopURI(demofile.Map)); //Workshop file

                Workshop.download(file, "maps/workshop/" + localname);               //Download to disk
                bspinfo.UnpackBSP("maps/workshop/" + localname, "maps/workshop/" + localname);
                Debug.Success("Finished downloading from the workshop!");

                doProcessing(serialwrite.Binary.ReadFromBinaryFile <mapData>("maps/workshop/" + localname + ".maprad"), demofile);

                Console.ReadLine();
                return(0);
            }
            else
            {
                // This bit will only occur if all three conditions are true:
                // The map has not been downloaded
                // The map is not on the workshop or is not public
                // The map is not official

                Debug.Error("There is no public known location of the map. Install the map first!");
            }

            Console.ReadLine();
            return(0);

            #region old

            /*s***e
             *
             * string mapfile = "";
             * string demofile = "";
             *
             * foreach (string str in args)
             * {
             *  if(Path.GetExtension(str) == ".dem")
             *  {
             *      demofile = str;
             *      Debug.Success("Loaded demo file");
             *  }
             *  else if(Path.GetExtension(str) == ".bsp")
             *  {
             *      mapfile = str;
             *      Debug.Success("Loaded map file");
             *  }
             * }
             *
             * if(mapfile == "" || demofile == "")
             * {
             *  Debug.Error("Not enough sufficient files were found in order to run.");
             * }
             *
             * mapdata map = new mapdata(mapfile);
             * demodata demo = new demodata(demofile);
             *
             * string generated = Environment.CurrentDirectory + "/files/" + Path.GetFileNameWithoutExtension(mapfile) + "/";
             * Debug.Log("Generate dir: {0}", generated);
             *
             * generateFlowMap(map, demo).Save(generated + "Flowmap.png");
             * generateHeatMap(map, demo.shotPositions, generated + "Shots.png");
             * generateHeatMap(map, demo.deathPositions, generated + "Deaths.png");
             * generateHeatMap(map, demo.smokePositions, generated + "Smokes.png");
             * generateHeatMap(map, demo.bombplantPositions, generated + "BombPlants.png");
             *
             * System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
             * {
             *  FileName = generated,
             *  UseShellExecute = true,
             *  Verb = "open"
             * });
             *
             * Console.ReadKey();
             * return 0;
             * }
             *
             * static Bitmap generateFlowMap(mapdata map, demodata demo)
             * {
             * Bitmap overlay = map.radarImage.ScaleImage(1024, 1024);
             * camera cam = new camera();
             * cam.offset = new vector2(map.radarDetails.pos_x, map.radarDetails.pos_y);
             * cam.scale = map.radarDetails.scale;
             *
             * Pen pen = new Pen(Color.FromArgb(10, 7, 245, 255), 1.7f);
             *
             * using (var graphics = Graphics.FromImage(overlay))
             * {
             *  int testx = 0;
             *
             *  for (int b = 0; b < 2; b++)
             *  {
             *      if (b == 1)
             *          pen = new Pen(Color.FromArgb(15, 209, 120, 12), 1.7f);
             *
             *      foreach (List<List<vector3>> player in demo.positions[b].Values.ToList())
             *      {
             *          foreach (List<vector3> list in player)
             *          {
             *              for (int i = 0; i < list.Count(); i++)
             *              {
             *
             *                  vector2 pa = list[i].worldToScreenSpace(cam);
             *                  vector2 pb = list[(i - 1).Clamp(0, list.Count())].worldToScreenSpace(cam);
             *
             *                  graphics.DrawLine(pen, pa.x, pa.y, pb.x, pb.y);
             *              }
             *          }
             *
             *          testx++;
             *          overlay.Save(testx + ".png");
             *      }
             *  }
             * }
             *
             * return overlay;
             * }
             *
             * static Bitmap generateHeatMap(mapdata map, List<vector3> data, string path)
             * {
             * //Bitmap background = map.radarImage.ScaleImage(1024, 1024);
             * Bitmap overlay = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb);
             *
             * using (var graphics = Graphics.FromImage(overlay))
             * {
             *  graphics.Clear(Color.Transparent);
             * }
             *
             * camera cam = new camera();
             * cam.offset = new vector2(map.radarDetails.pos_x, map.radarDetails.pos_y);
             * cam.scale = map.radarDetails.scale;
             *
             * Pen pen = new Pen(Color.FromArgb(32, 7, 245, 255), 2f);
             *
             * using (var graphics = Graphics.FromImage(overlay))
             * {
             *  foreach(vector3 point in data)
             *  {
             *      vector2 ssPoint = point.worldToScreenSpace(cam);
             *
             *      graphics.DrawRectangle(pen, new Rectangle((int)ssPoint.x - 1, (int)ssPoint.y - 1, 2, 2));
             *  }
             * }
             *
             * using (var imageFactory = new ImageFactory())
             * {
             *  string tempPath = Path.GetFullPath(path);
             *  imageFactory.Load(overlay).GaussianBlur(10).Save(tempPath);
             *  Debug.Log("Saved intensity map to {0}", tempPath);
             *
             *  //ImageProcessor.Imaging.ImageLayer over = new ImageProcessor.Imaging.ImageLayer();
             *  //over.Image = new Bitmap(tempPath);
             *
             *  //imageFactory.Load(background)
             *  //    .Overlay(over)
             *  //    .Save(Environment.CurrentDirectory + "/temp/test2.png");
             *
             *  //Debug.Log("Saved final map to {0}", path);
             *
             * }
             *
             * return overlay;
             */
            #endregion
        }