Advertisement
joerkig

Untitled

Apr 14th, 2021
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.57 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 SimpleRewards
  13. {
  14.     public class MyMod : MelonMod
  15.     {
  16.         static void Blank(string file)
  17.         {
  18.             if (File.ReadAllText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\" + file) != null)
  19.             {
  20.                 File.WriteAllText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\" + file, null);
  21.             }
  22.         }
  23.         static void WriteReward(string position)
  24.         {
  25.             string pattern = "(<script(\\s|\\S)*?<\\/script>)|(<style(\\s|\\S)*?<\\/style>)|(<!--(\\s|\\S)*?-->)|(<\\/?(\\s|\\S)*?>)";
  26.             GameObject gameObject = GameObject.Find("RewardSpawner/SpawnPoints/" + position);
  27.             if (gameObject != null)
  28.             {
  29.                 RewardInteractable rewardInteractable = gameObject.GetComponentInChildren<RewardInteractable>();
  30.                 if (rewardInteractable != null)
  31.                 {
  32.                     if (rewardInteractable.DisplayName.ToString() != File.ReadAllText(MelonUtils.UserDataDirectory + "\\DisplayName" + position + ".txt"))
  33.                     {
  34.                         File.WriteAllText(MelonUtils.UserDataDirectory + "\\DisplayName" + position + ".txt", rewardInteractable.DisplayName.ToString());
  35.                         File.WriteAllText(MelonUtils.UserDataDirectory + "\\DisplayDescription" + position + ".txt", Regex.Replace(rewardInteractable.DisplayDescription.ToString(), pattern, ""));
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.         public override void OnLateUpdate()
  41.         {
  42.             GameObject playerInteractor = GameObject.Find("Player/PlayerInteractor");
  43.             if (playerInteractor != null)
  44.             {
  45.                 PlayerHealth playerHealth = playerInteractor.GetComponent<PlayerHealth>();
  46.                 if (playerHealth != null)
  47.                 {
  48.                     string healthPip = "<img src=\"HealthPip.png\">";
  49.                     string healthPipCracked = "<img src=\"HealthPipCracked.png\">";
  50.                     int currentHealth = (int)Math.Ceiling(playerHealth.CurrentHealth);
  51.                     int maxHealth = (int)Math.Ceiling(playerHealth.MaxHealth);
  52.                     int emptyHealth = maxHealth - currentHealth;
  53.                     if (playerHealth.MaxHealth.ToString() != File.ReadAllText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\MaxHealth.txt"))
  54.                     {
  55.                         File.WriteAllText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\MaxHealth.txt", playerHealth.MaxHealth.ToString());
  56.                         File.WriteAllText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\Health.html", "<center>" + String.Concat(Enumerable.Repeat(healthPip, currentHealth)) + String.Concat(Enumerable.Repeat(healthPipCracked, emptyHealth)) + "</center><script>function timedRefresh(timeoutPeriod) {setTimeout(\"location.reload(true); \",timeoutPeriod);} window.onload = timedRefresh(2000);</script>");
  57.                     }
  58.                     if (playerHealth.CurrentHealth.ToString() != File.ReadAllText(MelonUtils.UserDataDirectory + "\\CurrentHealth.txt"))
  59.                     {
  60.                         File.WriteAllText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\CurrentHealth.txt", playerHealth.CurrentHealth.ToString());
  61.                         File.WriteAllText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\Health.html", "<center>" + String.Concat(Enumerable.Repeat(healthPip, currentHealth)) + String.Concat(Enumerable.Repeat(healthPipCracked, emptyHealth)) + "</center><script>function timedRefresh(timeoutPeriod) {setTimeout(\"location.reload(true); \",timeoutPeriod);} window.onload = timedRefresh(2000);</script>");
  62.                     }
  63.                     //File.WriteAllText(MelonUtils.UserDataDirectory + "\\Health.html", "<center>" + String.Concat(Enumerable.Repeat(healthPip, currentHealth)) + String.Concat(Enumerable.Repeat(healthPipCracked, emptyHealth)) + "</center><script>function timedRefresh(timeoutPeriod) {setTimeout(\"location.reload(true); \",timeoutPeriod);} window.onload = timedRefresh(2000);</script>");
  64.                 }
  65.             }
  66.  
  67.             WriteReward("Left");
  68.             WriteReward("Center");
  69.             WriteReward("Right");
  70.         }
  71.         public override void OnSceneWasLoaded(int buildIndex, string sceneName)
  72.         {
  73.             Blank("DisplayNameLeft.txt");
  74.             Blank("DisplayNameCenter.txt");
  75.             Blank("DisplayNameRight.txt");
  76.             Blank("DisplayDescriptionLeft.txt");
  77.             Blank("DisplayDescriptionCenter.txt");
  78.             Blank("DisplayDescriptionRight.txt");
  79.         }
  80.         public override void OnApplicationStart()
  81.         {
  82.             Directory.CreateDirectory(MelonUtils.UserDataDirectory + "\\SimpleInfo\\");
  83.             if (File.Exists(MelonUtils.UserDataDirectory + "\\MaxHealth.txt") == false)
  84.             {
  85.                 File.CreateText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\MaxHealth.txt");
  86.                 File.CreateText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\CurrentHealth.txt");
  87.                 File.CreateText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\DisplayNameLeft.txt");
  88.                 File.CreateText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\DisplayDescriptionLeft.txt");
  89.                 File.CreateText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\DisplayNameCenter.txt");
  90.                 File.CreateText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\DisplayDescriptionCenter.txt");
  91.                 File.CreateText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\DisplayNameRight.txt");
  92.                 File.CreateText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\DisplayDescriptionRight.txt");
  93.             }
  94.             if (File.Exists(MelonUtils.UserDataDirectory + "\\SimpleInfo\\HealthPip.png") == false)
  95.             {
  96.                 Bitmap img = Properties.Resources.HealthPip;
  97.                 img.Save(MelonUtils.UserDataDirectory + "\\SimpleInfo\\HealthPip.png", ImageFormat.Png);
  98.                 //File.Create(MelonUtils.UserDataDirectory + "\\HealthPip.png");
  99.                 //Properties.Resources.HealthPip.Save(MelonUtils.UserDataDirectory + "\\HealthPip.png");
  100.             }
  101.             if (File.Exists(MelonUtils.UserDataDirectory + "\\SimpleInfo\\HealthPipCracked.png") == false)
  102.             {
  103.                 Bitmap img = Properties.Resources.HealthPipCracked;
  104.                 img.Save(MelonUtils.UserDataDirectory + "\\SimpleInfo\\HealthPipCracked.png", ImageFormat.Png);
  105.                 //File.Create(MelonUtils.UserDataDirectory + "\\HealthPipCracked.png");
  106.                 //Properties.Resources.HealthPipCracked.Save(MelonUtils.UserDataDirectory + "\\HealthPipCracked.png");
  107.             }
  108.         }
  109.         public override void OnApplicationQuit()
  110.         {
  111.             Blank("DisplayNameLeft.txt");
  112.             Blank("DisplayNameCenter.txt");
  113.             Blank("DisplayNameRight.txt");
  114.             Blank("DisplayDescriptionLeft.txt");
  115.             Blank("DisplayDescriptionCenter.txt");
  116.             Blank("DisplayDescriptionRight.txt");
  117.             Blank("MaxHealth.txt");
  118.             Blank("CurrentHealth.txt");
  119.             File.WriteAllText(MelonUtils.UserDataDirectory + "\\SimpleInfo\\Health.html", "<script>function timedRefresh(timeoutPeriod) {setTimeout(\"location.reload(true); \",timeoutPeriod);} window.onload = timedRefresh(2000);</script>");
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement