Advertisement
kubinator4321

PFBetterScreenshot Source

Oct 30th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.91 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using MonoMod;
  6.  
  7. internal class patch_GameSpace : GameSpace
  8. {
  9.     public extern Texture2D orig_GetScreenShotTexture(bool fullMap, float zoom, bool preview);
  10.     public Texture2D GetScreenShotTexture(bool fullMap, float zoom, bool preview)
  11.     {
  12.         if (fullMap && zoom == 1f)
  13.         {
  14.             zoom = 4f;
  15.  
  16.             Text[] texts = UnityEngine.Object.FindObjectsOfType<Text>();
  17.             Color[] text_colors = new Color[texts.Length];
  18.  
  19.             ResourceBar[] bars = UnityEngine.Object.FindObjectsOfType<ResourceBar>();
  20.             Color[] bar_colors = new Color[texts.Length];
  21.  
  22.             Color rep = new Color(1, 1, 1, 0);
  23.  
  24.             for (int i = 0; i < bars.Length; i++)
  25.             {
  26.                 bar_colors[i] = bars[i].barColor;
  27.                 bars[i].barColor = rep;
  28.                 bars[i].RefreshColors();
  29.             }
  30.  
  31.             for (int i = 0; i<texts.Length; i++)
  32.             {
  33.                 text_colors[i] = texts[i].color;
  34.                 texts[i].color = rep;
  35.             }
  36.  
  37.             var ret = orig_GetScreenShotTexture(fullMap, zoom, preview);
  38.  
  39.             for (int i = 0; i < texts.Length; i++)
  40.             {
  41.                 texts[i].color = text_colors[i];
  42.             }
  43.  
  44.             for (int i = 0; i < bars.Length; i++)
  45.             {
  46.                 bars[i].barColor = bar_colors[i];
  47.                 bars[i].RefreshColors();
  48.             }
  49.  
  50.             return ret;
  51.         }
  52.         else
  53.             return orig_GetScreenShotTexture(fullMap, zoom, preview);
  54.     }
  55.  
  56.     public void TakeScreenShot(bool fullMap)
  57.     {
  58.         Texture2D screenShotTexture = this.GetScreenShotTexture(fullMap, 1f);
  59.         if (screenShotTexture != null)
  60.         {
  61.             //JPGEncoder jPGEncoder = new JPGEncoder(screenShotTexture, 85f);
  62.             //byte[] bytes = jPGEncoder.GetBytes();
  63.             Texture2D newTexture = new Texture2D(screenShotTexture.width, screenShotTexture.height, TextureFormat.ARGB32, false);
  64.             newTexture.SetPixels(0, 0, screenShotTexture.width, screenShotTexture.height, screenShotTexture.GetPixels());
  65.             //newTexture = FillInClear(newTexture);
  66.             newTexture.Apply();
  67.             byte[] bytes = newTexture.EncodeToPNG();
  68.             UnityEngine.Object.DestroyImmediate(screenShotTexture);
  69.             if (bytes != null)
  70.             {
  71.                 File.WriteAllBytes(FileManager.GetScreenShotFileName(), bytes);
  72.             }
  73.             else
  74.             {
  75.                 Debug.Log("Null Screenshot data");
  76.             }
  77.         }
  78.     }
  79. }
  80.  
  81. internal class patch_FileManager : FileManager
  82. {
  83.     public static string GetScreenShotFileName()
  84.     {
  85.         string path = FileManager.GetBaseDataDir() + "screenshots/";
  86.         Directory.CreateDirectory(path);
  87.         string[] files = Directory.GetFiles(path, "*.png");
  88.         int num = 0;
  89.         string[] array = files;
  90.         for (int i = 0; i < array.Length; i++)
  91.         {
  92.             string path2 = array[i];
  93.             try
  94.             {
  95.                 string[] array2 = Path.GetFileName(path2).Split(new char[]
  96.                 {
  97.                 '.'
  98.                 });
  99.                 if (array2.Length > 0)
  100.                 {
  101.                     string[] array3 = array2[0].Split(new char[]
  102.                     {
  103.                     '_'
  104.                     });
  105.                     if (array3.Length > 1)
  106.                     {
  107.                         int num2 = int.Parse(array3[1]);
  108.                         if (num2 > num)
  109.                         {
  110.                             num = num2;
  111.                         }
  112.                     }
  113.                 }
  114.             }
  115.             catch (Exception)
  116.             {
  117.             }
  118.         }
  119.         string text = string.Concat(new object[]
  120.         {
  121.         FileManager.GetBaseDataDir(),
  122.         "screenshots/pfss_",
  123.         num + 1,
  124.         ".png"
  125.         });
  126.         Debug.Log(text);
  127.         return text;
  128.     }
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement