Advertisement
joerkig

Untitled

Apr 14th, 2021
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.24 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Imaging;
  4. using System.Linq;
  5. using System.IO;
  6. using System.Text.RegularExpressions;
  7. using UnityEngine;
  8. using MelonLoader;
  9. using SG.Claymore.Interaction;//Where the Name and Description hide
  10. using SG.Claymore.Entities;//Health hides here
  11.  
  12. namespace SimpleInfo
  13. {
  14.     public class MyMod : MelonMod
  15.     {
  16.         static string modFolder = MelonUtils.UserDataDirectory + "\\SimpleInfo\\";
  17.         string reloadScript = "<script>function timedRefresh(timeoutPeriod) {setTimeout(\"location.reload(true); \",timeoutPeriod);} window.onload = timedRefresh(2000);</script>";
  18.         static void Blank(string file)
  19.         {
  20.             if (File.ReadAllText(modFolder + file) != null)//If not empty, empty it
  21.             {
  22.                 File.WriteAllText(modFolder + file, null);
  23.             }
  24.         }
  25.         static void CreateIfMissing(string file)
  26.         {
  27.             if (File.Exists(modFolder + file) == false)//If missing create text based file
  28.             {
  29.                 File.CreateText(modFolder + file);
  30.             }
  31.         }
  32.         static void WriteReward(string position)//Write Reward info to their txt files
  33.         {
  34.             string pattern = "(<script(\\s|\\S)*?<\\/script>)|(<style(\\s|\\S)*?<\\/style>)|(<!--(\\s|\\S)*?-->)|(<\\/?(\\s|\\S)*?>)";
  35.             GameObject gameObject = GameObject.Find("RewardSpawner/SpawnPoints/" + position);
  36.             if (gameObject != null)
  37.             {
  38.                 RewardInteractable rewardInteractable = gameObject.GetComponentInChildren<RewardInteractable>();
  39.                 if (rewardInteractable != null)
  40.                 {
  41.                     if (rewardInteractable.DisplayName.ToString() != File.ReadAllText(modFolder + "DisplayName" + position + ".txt"))
  42.                     {
  43.                         File.WriteAllText(modFolder + "DisplayName" + position + ".txt", rewardInteractable.DisplayName.ToString());
  44.                         File.WriteAllText(modFolder + "DisplayDescription" + position + ".txt", Regex.Replace(rewardInteractable.DisplayDescription.ToString(), pattern, ""));
  45.                     }
  46.                 }
  47.             }
  48.         }
  49.         public override void OnLateUpdate()
  50.         {
  51.             GameObject playerInteractor = GameObject.Find("Player/PlayerInteractor");
  52.             if (playerInteractor != null)
  53.             {
  54.                 PlayerHealth playerHealth = playerInteractor.GetComponent<PlayerHealth>();
  55.                 if (playerHealth != null)
  56.                 {
  57.                     string healthPip = "<img src=\"HealthPip.png\">";
  58.                     string healthPipCracked = "<img src=\"HealthPipCracked.png\">";
  59.                     int currentHealth = (int)Math.Ceiling(playerHealth.CurrentHealth);
  60.                     int maxHealth = (int)Math.Ceiling(playerHealth.MaxHealth);
  61.                     int emptyHealth = maxHealth - currentHealth;
  62.                     if (playerHealth.MaxHealth.ToString() != File.ReadAllText(modFolder + "MaxHealth.txt"))
  63.                     {
  64.                         File.WriteAllText(modFolder + "MaxHealth.txt", playerHealth.MaxHealth.ToString());
  65.                         File.WriteAllText(modFolder + "Health.html", "<center>" + String.Concat(Enumerable.Repeat(healthPip, currentHealth)) + String.Concat(Enumerable.Repeat(healthPipCracked, emptyHealth)) + "</center>" + reloadScript);
  66.                     }
  67.                     if (playerHealth.CurrentHealth.ToString() != File.ReadAllText(modFolder + "CurrentHealth.txt"))
  68.                     {
  69.                         File.WriteAllText(modFolder + "CurrentHealth.txt", playerHealth.CurrentHealth.ToString());
  70.                         File.WriteAllText(modFolder + "Health.html", "<center>" + String.Concat(Enumerable.Repeat(healthPip, currentHealth)) + String.Concat(Enumerable.Repeat(healthPipCracked, emptyHealth)) + "</center>" + reloadScript);
  71.                     }
  72.                 }
  73.             }
  74.  
  75.             WriteReward("Left");
  76.             WriteReward("Center");
  77.             WriteReward("Right");
  78.         }
  79.         public override void OnSceneWasLoaded(int buildIndex, string sceneName)
  80.         {
  81.             Blank("DisplayNameLeft.txt");//Remove the reward info when changing room
  82.             Blank("DisplayNameCenter.txt");
  83.             Blank("DisplayNameRight.txt");
  84.             Blank("DisplayDescriptionLeft.txt");
  85.             Blank("DisplayDescriptionCenter.txt");
  86.             Blank("DisplayDescriptionRight.txt");
  87.         }
  88.         public override void OnApplicationStart()
  89.         {
  90.             Directory.CreateDirectory(modFolder);//Create a folder just for me <3
  91.             CreateIfMissing("MaxHealth.txt");
  92.             CreateIfMissing("CurrentHealth.txt");
  93.             CreateIfMissing("DisplayNameLeft.txt");
  94.             CreateIfMissing("DisplayDescriptionLeft.txt");
  95.             CreateIfMissing("DisplayNameCenter.txt");
  96.             CreateIfMissing("DisplayDescriptionCenter.txt");
  97.             CreateIfMissing("DisplayNameRight.txt");
  98.             CreateIfMissing("DisplayDescriptionRight.txt");
  99.             if (File.Exists(modFolder + "Health.html") == false)//If missing put in all these text based files
  100.             {
  101.                 File.WriteAllText(modFolder + "Health.html", reloadScript);
  102.             }
  103.             if (File.Exists(modFolder + "HealthPip.png") == false)
  104.             {
  105.                 Bitmap img = Properties.Resources.HealthPip;
  106.                 img.Save(modFolder + "HealthPip.png", ImageFormat.Png);
  107.             }
  108.             if (File.Exists(modFolder + "HealthPipCracked.png") == false)
  109.             {
  110.                 Bitmap img = Properties.Resources.HealthPipCracked;
  111.                 img.Save(modFolder + "HealthPipCracked.png", ImageFormat.Png);
  112.             }
  113.         }
  114.         public override void OnApplicationQuit()
  115.         {
  116.             Blank("DisplayNameLeft.txt");
  117.             Blank("DisplayNameCenter.txt");
  118.             Blank("DisplayNameRight.txt");
  119.             Blank("DisplayDescriptionLeft.txt");
  120.             Blank("DisplayDescriptionCenter.txt");
  121.             Blank("DisplayDescriptionRight.txt");
  122.             Blank("MaxHealth.txt");
  123.             Blank("CurrentHealth.txt");
  124.             File.WriteAllText(modFolder + "Health.html", reloadScript);
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement