Example #1
0
        public static void swapToCustom()
        {
            Dictionary <HeroType, HeroController.HeroDefinition> heroDefinition = Traverse.Create(HeroController.Instance).Field("_heroData").GetValue() as Dictionary <HeroType, HeroController.HeroDefinition>;
            Traverse oldVanDamm = Traverse.Create(HeroController.players[0].character);

            float fireRate = 0.166f;

            bro = HeroController.players[0].character.gameObject.AddComponent <CaptainAmeribro>();
            UnityEngine.Object.Destroy(HeroController.players[0].character.gameObject.GetComponent <WavyGrassEffector>());

            SpriteSM         sprite      = bro.gameObject.GetComponent <SpriteSM>();
            SoundHolder      soundholder = oldVanDamm.Field("soundHolder").GetValue() as SoundHolder;
            TestVanDammeAnim neobro      = HeroController.GetHeroPrefab(HeroType.Nebro);


            // LOADING CHARACTER SPRITE ARMLESS
            {
                string filePath = "D:\\Steam\\steamapps\\common\\Broforce\\Mods\\Development - captainameribro\\captainAmeribroArmless.png";
                var    tex      = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                tex.LoadImage(File.ReadAllBytes(filePath));
                tex.wrapMode = TextureWrapMode.Clamp;

                Texture orig = sprite.meshRender.sharedMaterial.GetTexture("_MainTex");

                tex.anisoLevel = orig.anisoLevel;
                tex.filterMode = orig.filterMode;
                tex.mipMapBias = orig.mipMapBias;
                tex.wrapMode   = orig.wrapMode;

                Material armless = Material.Instantiate(sprite.meshRender.sharedMaterial);
                armless.mainTexture = tex;
                bro.materialArmless = armless;
                //sprite.meshRender.sharedMaterial.SetTexture("_MainTex", tex);
                //bro.materialArmless = sprite.meshRender.sharedMaterial;
            }

            // LOADING CHARACTER SPRITE
            {
                string filePath = "D:\\Steam\\steamapps\\common\\Broforce\\Mods\\Development - captainameribro\\captainAmeribro.png";
                var    tex      = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                tex.LoadImage(File.ReadAllBytes(filePath));
                tex.wrapMode = TextureWrapMode.Clamp;

                Texture orig = sprite.meshRender.sharedMaterial.GetTexture("_MainTex");

                tex.anisoLevel = orig.anisoLevel;
                tex.filterMode = orig.filterMode;
                tex.mipMapBias = orig.mipMapBias;
                tex.wrapMode   = orig.wrapMode;

                sprite.meshRender.sharedMaterial.SetTexture("_MainTex", tex);
                bro.materialNormal = sprite.meshRender.sharedMaterial;
            }


            // LOADING GUN SPRITE WITHOUT SHIELD
            {
                //bro.gunSpriteNoShield = HeroController.players[0].character.gunSprite;

                string filePathGun = "D:\\Steam\\steamapps\\common\\Broforce\\Mods\\Development - captainameribro\\captainAmeribroGunNoShield.png";
                var    texGun      = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                texGun.LoadImage(File.ReadAllBytes(filePathGun));
                texGun.wrapMode = TextureWrapMode.Clamp;

                Texture origGun = neobro.gunSprite.GetComponent <Renderer>().sharedMaterial.GetTexture("_MainTex");

                SpriteSM gunSpriteCopy = SpriteSM.Instantiate(neobro.gunSprite);

                //bro.gunSpriteNoShield.Copy(gunSpriteCopy);

                texGun.anisoLevel = origGun.anisoLevel;
                texGun.filterMode = origGun.filterMode;
                texGun.mipMapBias = origGun.mipMapBias;
                texGun.wrapMode   = origGun.wrapMode;

                bro.gunTextureNoShield = texGun;
            }
            // LOADING GUN SPRITE WITH SHIELD
            {
                bro.gunSprite = HeroController.players[0].character.gunSprite;

                string filePathGun = "D:\\Steam\\steamapps\\common\\Broforce\\Mods\\Development - captainameribro\\captainAmeribroGunWithShield.png";
                var    texGun      = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                texGun.LoadImage(File.ReadAllBytes(filePathGun));
                texGun.wrapMode = TextureWrapMode.Clamp;

                Texture origGun = neobro.gunSprite.GetComponent <Renderer>().sharedMaterial.GetTexture("_MainTex");

                SpriteSM gunSpriteCopy = SpriteSM.Instantiate(neobro.gunSprite);

                bro.gunSprite.Copy(gunSpriteCopy);

                texGun.anisoLevel = origGun.anisoLevel;
                texGun.filterMode = origGun.filterMode;
                texGun.mipMapBias = origGun.mipMapBias;
                texGun.wrapMode   = origGun.wrapMode;

                bro.gunTextureWithShield = texGun;
                bro.gunSprite.GetComponent <Renderer>().material.mainTexture = texGun;
            }


            // PASSING REFERENCES TO NEW PROJECTILE
            Boomerang boom = (HeroController.players[0].character as BroMax).boomerang as Boomerang;

            //Boomerang clone = boom.Clone<Boomerang>();
            foreach (Component comp in boom.GetComponentsInParent(typeof(Component)))
            {
                Main.Log("attached: " + comp.name + " also " + comp.GetType());
            }
            Boomerang clone             = Boomerang.Instantiate(boom);
            Traverse  boomerangTraverse = Traverse.Create(clone);

            //Traverse boomerangTraverseOrig = Traverse.Create(boom);
            //BoxCollider attachBoxCollider = boomerangTraverse.Field("boomerangCollider").GetValue() as BoxCollider;

            //BoxCollider attachBoxCollider = BoxCollider.Instantiate(boomerangTraverse.Field("boomerangCollider").GetValue() as BoxCollider);
            //SoundHolder boomerangSoundHolder = boomerangTraverse.Field("soundHolder").GetValue() as SoundHolder;
            //float rotationSpeed = boomerangTraverse.Field("rotationSpeed").GetValue<float>();
            bro.attachBoxCollider    = BoxCollider.Instantiate(boomerangTraverse.Field("boomerangCollider").GetValue() as BoxCollider);
            bro.boomerangSoundHolder = boomerangTraverse.Field("soundHolder").GetValue() as SoundHolder;
            bro.rotationSpeed        = boomerangTraverse.Field("rotationSpeed").GetValue <float>();
            bro.shieldTransform      = clone.transform.parent;

            UnityEngine.Object.Destroy(clone.gameObject.GetComponent <Boomerang>());


            Shield shield = clone.gameObject.AddComponent <Shield>();

            shield.Setup(bro.attachBoxCollider, bro.shieldTransform, bro.boomerangSoundHolder, bro.rotationSpeed, false);

            //return;
            // LOADING PROJECTILE SPRITE
            //MeshRenderer meshRender = shield.gameObject.GetComponent<MeshRenderer>();
            MeshRenderer meshRender = clone.gameObject.GetComponent <MeshRenderer>();

            //Main.Log("after get component");
            {
                string filePath = "D:\\Steam\\steamapps\\common\\Broforce\\Mods\\Development - captainameribro\\captainAmeribroShield.png";
                var    tex      = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                tex.LoadImage(File.ReadAllBytes(filePath));
                //Main.Log("after load iamge");
                tex.wrapMode = TextureWrapMode.Clamp;

                Texture orig = meshRender.sharedMaterial.mainTexture;

                tex.anisoLevel = orig.anisoLevel;
                tex.filterMode = orig.filterMode;
                tex.mipMapBias = orig.mipMapBias;
                tex.wrapMode   = orig.wrapMode;
                //Main.Log("after orig texture");

                meshRender.material.mainTexture = tex;
                //meshRender.sharedMaterial.mainTexture = tex;
                //Main.Log("at end");
            }


            // PASSING REFERENCES TO NEW VAN DAMM
            bro.Setup(sprite, HeroController.players[0], HeroController.players[0].character.playerNum, shield, soundholder, fireRate);

            UnityEngine.Object.Destroy(HeroController.players[0].character.gameObject.GetComponent <BroMax>());

            //HeroController.players[0].character = bro;

            //Networking.Networking.RPC<int, HeroType, bool>(PID.TargetAll, new RpcSignature<int, HeroType, bool>(bro.SetUpHero), 0, HeroType.BroMax, true, false);
            // Give hero controller reference to new van damm
            bro.SetUpHero(0, HeroType.BroMax, true);

            isCaptainAmeribro = true;
        }