Guest User

RatGungeonMod 0.261

a guest
May 4th, 2019
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.32 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using System.IO;
  6.  
  7. namespace RatGungeonMod
  8. {
  9.     internal class BecomeARat : MonoBehaviour
  10.     {
  11.         public tk2dSpriteCollectionData ratHandCollectionData;
  12.         public bool[] playerIsARat = new bool[2];
  13.         public const string RAT_COMMAND = "Ratto";
  14.  
  15.         private void Start()
  16.         {
  17.             ETGModConsole.Commands.AddGroup(RAT_COMMAND, (System.Action<string[]>)(e =>
  18.             {
  19.                 if (GameManager.Instance.CurrentLevelOverrideState == GameManager.LevelOverrideState.FOYER)
  20.                 {
  21.                     ETGModConsole.Log("ERROR: Do this in the gungeon.", false);
  22.                 }
  23.  
  24.                 bool[] swapThisPlayer = new bool[] { true, true };
  25.                 if(e.Length > 0)
  26.                 {
  27.                     if(e[0] == "1")
  28.                     {
  29.                         swapThisPlayer[0] = false;
  30.                     }
  31.                     else if(e[0]=="2")
  32.                     {
  33.                         swapThisPlayer[1] = false;
  34.                     }
  35.                     else
  36.                     {
  37.                         ETGModConsole.Log("Unrecongized command. Use 1 or 2 to designate specific player to swap rat status, or just enter " + RAT_COMMAND + " to swap both");
  38.                         return;
  39.                     }
  40.                 }
  41.                     List<PlayerController> players = new List<PlayerController>() {GameManager.Instance.SecondaryPlayer, GameManager.Instance.PrimaryPlayer };
  42.                 for (int i = 0; i < 2; i++)
  43.                 {
  44.                     PlayerController player = players[i];
  45.                     if (player != null && swapThisPlayer[i])
  46.                     {
  47.                         if (!playerIsARat[i])
  48.                         {
  49.                             player.CustomEventSynergies.Add(CustomSynergyType.RESOURCEFUL_RAT);
  50.                             player.stats.ActiveCustomSynergies.Add(CustomSynergyType.RESOURCEFUL_RAT);
  51.                             //override player texture with rat stuff found on the rat boots
  52.                             RatBootsItem booties = Gungeon.Game.Items.Get("rat_boots") as RatBootsItem;
  53.                             if (!booties) { ETGModConsole.Log("You shouldn't see this!", false); return; }
  54.                             player.OverrideAnimationLibrary = booties.RatAnimationLibrary;
  55.                             player.SetOverrideShader(ShaderCache.Acquire(player.LocalShaderName));
  56.                             if (player.characterIdentity == PlayableCharacters.Eevee)
  57.                                 player.GetComponent<CharacterAnimationRandomizer>().AddOverrideAnimLibrary(booties.RatAnimationLibrary);
  58.                             player.PlayerIsRatTransformed = true;
  59.  
  60.                             //replacing the hands comes next
  61.                             if (ratHandCollectionData == null)
  62.                             {
  63.                                 ETGModConsole.Log("Generating hand asset");
  64.                                 Texture2D rathandtexture = new Texture2D(4, 4, TextureFormat.DXT5, false);
  65.                                 byte[] ratbytesdumber = new byte[] { 255, 0, 1, 2, 0, 0, 16, 32, 41, 244, 202, 120, 85, 65, 65, 85 }; //ha ha ha this is so stupid, but hey, it works
  66.                                 rathandtexture.LoadRawTextureData(ratbytesdumber);
  67.                                 rathandtexture.filterMode = FilterMode.Point;
  68.                                 rathandtexture.name = "RatHands";
  69.                                 tk2dSpriteCollectionData RatPlayerSwap = booties.RatAnimationLibrary.FirstValidClip.frames[0].spriteCollection;
  70.                                 Rect ratRect = new Rect(new Vector2(), new Vector2(4, 4));
  71.                                 tk2dSpriteCollectionSize ratCollSize = tk2dSpriteCollectionSize.PixelsPerMeter(RatPlayerSwap.halfTargetHeight * 2.0f);
  72.                                 tk2dSpriteCollectionData rathand = tk2dSpriteCollectionData.CreateFromTexture(rathandtexture, ratCollSize, new string[] { "RatHand" }, new Rect[] { ratRect }, new Vector2[] { new Vector2() });
  73.                                 ETGMod.ReplaceTexture(rathand.FirstValidDefinition, rathandtexture); //maybe not needed but eh
  74.                                 ratHandCollectionData = rathand;
  75.                             }
  76.                             player.ChangeHandsToCustomType(ratHandCollectionData, ratHandCollectionData.FirstValidDefinitionIndex);
  77.                             playerIsARat[i] = true;
  78.                             ETGModConsole.Log("Player " + (i==0?2:1) + " has been rat-ified!");
  79.                         }
  80.                         else
  81.                         {
  82.                             RatBootsItem booties = Gungeon.Game.Items.Get("rat_boots") as RatBootsItem;
  83.                             if (!booties) { ETGModConsole.Log("You shouldn't see this!", false); return; }
  84.  
  85.                             player.CustomEventSynergies.Remove(CustomSynergyType.RESOURCEFUL_RAT);
  86.                             player.stats.ActiveCustomSynergies.Remove(CustomSynergyType.RESOURCEFUL_RAT);
  87.                             player.PlayerIsRatTransformed = false;
  88.  
  89.                             player.OverrideAnimationLibrary = (tk2dSpriteAnimation)null;
  90.                             player.OverridePlayerSwitchState = (string)null;
  91.                             player.ClearOverrideShader();
  92.                             if (player.characterIdentity == PlayableCharacters.Eevee)
  93.                                 player.GetComponent<CharacterAnimationRandomizer>().RemoveOverrideAnimLibrary(booties.RatAnimationLibrary);
  94.                             player.RevertHandsToBaseType();
  95.                             playerIsARat[i] = false;
  96.                         ETGModConsole.Log("Player " + (i == 0 ? 2:1) + "'s rat-ification has been revoked.");
  97.                         }
  98.                     }
  99.                 }
  100.             }));
  101.         }
  102.     }
  103.  
  104.  
  105.     public class RatModGungeonModule : ETGModule
  106.     {
  107.         public override void Start()
  108.         {
  109.             ETGModMainBehaviour.Instance.gameObject.AddComponent<BecomeARat>();
  110.         }
  111.  
  112.         public override void Exit()
  113.         {
  114.            
  115.         }
  116.  
  117.         public override void Init()
  118.         {
  119.          
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment