Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- namespace RatGungeonMod
- {
- internal class BecomeARat : MonoBehaviour
- {
- public tk2dSpriteCollectionData ratHandCollectionData;
- public bool[] playerIsARat = new bool[2];
- public const string RAT_COMMAND = "Ratto";
- private void Start()
- {
- ETGModConsole.Commands.AddGroup(RAT_COMMAND, (System.Action<string[]>)(e =>
- {
- if (GameManager.Instance.CurrentLevelOverrideState == GameManager.LevelOverrideState.FOYER)
- {
- ETGModConsole.Log("ERROR: Do this in the gungeon.", false);
- }
- bool[] swapThisPlayer = new bool[] { true, true };
- if(e.Length > 0)
- {
- if(e[0] == "1")
- {
- swapThisPlayer[0] = false;
- }
- else if(e[0]=="2")
- {
- swapThisPlayer[1] = false;
- }
- else
- {
- ETGModConsole.Log("Unrecongized command. Use 1 or 2 to designate specific player to swap rat status, or just enter " + RAT_COMMAND + " to swap both");
- return;
- }
- }
- List<PlayerController> players = new List<PlayerController>() {GameManager.Instance.SecondaryPlayer, GameManager.Instance.PrimaryPlayer };
- for (int i = 0; i < 2; i++)
- {
- PlayerController player = players[i];
- if (player != null && swapThisPlayer[i])
- {
- if (!playerIsARat[i])
- {
- player.CustomEventSynergies.Add(CustomSynergyType.RESOURCEFUL_RAT);
- player.stats.ActiveCustomSynergies.Add(CustomSynergyType.RESOURCEFUL_RAT);
- //override player texture with rat stuff found on the rat boots
- RatBootsItem booties = Gungeon.Game.Items.Get("rat_boots") as RatBootsItem;
- if (!booties) { ETGModConsole.Log("You shouldn't see this!", false); return; }
- player.OverrideAnimationLibrary = booties.RatAnimationLibrary;
- player.SetOverrideShader(ShaderCache.Acquire(player.LocalShaderName));
- if (player.characterIdentity == PlayableCharacters.Eevee)
- player.GetComponent<CharacterAnimationRandomizer>().AddOverrideAnimLibrary(booties.RatAnimationLibrary);
- player.PlayerIsRatTransformed = true;
- //replacing the hands comes next
- if (ratHandCollectionData == null)
- {
- ETGModConsole.Log("Generating hand asset");
- Texture2D rathandtexture = new Texture2D(4, 4, TextureFormat.DXT5, false);
- 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
- rathandtexture.LoadRawTextureData(ratbytesdumber);
- rathandtexture.filterMode = FilterMode.Point;
- rathandtexture.name = "RatHands";
- tk2dSpriteCollectionData RatPlayerSwap = booties.RatAnimationLibrary.FirstValidClip.frames[0].spriteCollection;
- Rect ratRect = new Rect(new Vector2(), new Vector2(4, 4));
- tk2dSpriteCollectionSize ratCollSize = tk2dSpriteCollectionSize.PixelsPerMeter(RatPlayerSwap.halfTargetHeight * 2.0f);
- tk2dSpriteCollectionData rathand = tk2dSpriteCollectionData.CreateFromTexture(rathandtexture, ratCollSize, new string[] { "RatHand" }, new Rect[] { ratRect }, new Vector2[] { new Vector2() });
- ETGMod.ReplaceTexture(rathand.FirstValidDefinition, rathandtexture); //maybe not needed but eh
- ratHandCollectionData = rathand;
- }
- player.ChangeHandsToCustomType(ratHandCollectionData, ratHandCollectionData.FirstValidDefinitionIndex);
- playerIsARat[i] = true;
- ETGModConsole.Log("Player " + (i==0?2:1) + " has been rat-ified!");
- }
- else
- {
- RatBootsItem booties = Gungeon.Game.Items.Get("rat_boots") as RatBootsItem;
- if (!booties) { ETGModConsole.Log("You shouldn't see this!", false); return; }
- player.CustomEventSynergies.Remove(CustomSynergyType.RESOURCEFUL_RAT);
- player.stats.ActiveCustomSynergies.Remove(CustomSynergyType.RESOURCEFUL_RAT);
- player.PlayerIsRatTransformed = false;
- player.OverrideAnimationLibrary = (tk2dSpriteAnimation)null;
- player.OverridePlayerSwitchState = (string)null;
- player.ClearOverrideShader();
- if (player.characterIdentity == PlayableCharacters.Eevee)
- player.GetComponent<CharacterAnimationRandomizer>().RemoveOverrideAnimLibrary(booties.RatAnimationLibrary);
- player.RevertHandsToBaseType();
- playerIsARat[i] = false;
- ETGModConsole.Log("Player " + (i == 0 ? 2:1) + "'s rat-ification has been revoked.");
- }
- }
- }
- }));
- }
- }
- public class RatModGungeonModule : ETGModule
- {
- public override void Start()
- {
- ETGModMainBehaviour.Instance.gameObject.AddComponent<BecomeARat>();
- }
- public override void Exit()
- {
- }
- public override void Init()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment