Пример #1
0
 void Start()
 {
     jumpsLeft = amountOfJumps;
     sound     = FindObjectOfType <SoundSpawn> ();
     rb        = GetComponent <Rigidbody2D> ();
     anim      = rend.GetComponent <Animator> ();
 }
Пример #2
0
    /// <summary>
    /// Play sound locally at given world position.
    /// If more than one element is specified, one will be picked at random.
    /// </summary>
    /// <param name="addressableAudioSources">Sound to be played.  If more than one is specified, one will be picked at random.</param>
    /// <param name="soundSpawnToken">The token that identifies the SoundSpawn uniquely among the server and all clients </param>
    public static async Task PlayAtPosition(List <AddressableAudioSource> addressableAudioSources, string soundSpawnToken, Vector3 worldPos, bool polyphonic = false,
                                            bool isGlobal = false, uint netId = NetId.Empty, AudioSourceParameters audioSourceParameters = null)
    {
        AddressableAudioSource addressableAudioSource = await GetAddressableAudioSourceFromCache(addressableAudioSources);

        SoundSpawn soundSpawn = Instance.GetSoundSpawn(addressableAudioSource, addressableAudioSource.AudioSource, soundSpawnToken);

        ApplyAudioSourceParameters(audioSourceParameters, soundSpawn);

        if (netId != NetId.Empty)
        {
            if (NetworkIdentity.spawned.ContainsKey(netId))
            {
                soundSpawn.transform.parent        = NetworkIdentity.spawned[netId].transform;
                soundSpawn.transform.localPosition = Vector3.zero;
            }
            else
            {
                soundSpawn.transform.parent   = Instance.transform;
                soundSpawn.transform.position = worldPos;
            }
        }
        else
        {
            soundSpawn.transform.parent   = Instance.transform;
            soundSpawn.transform.position = worldPos;
        }

        Instance.PlaySource(soundSpawn, polyphonic, isGlobal, audioSourceParameters != null && audioSourceParameters.MixerType != MixerType.Unspecified);
    }
Пример #3
0
 /// <summary>
 /// Plays a SoundSpawn.
 /// </summary>
 /// <param name="source">The SoundSpawn to be played</param>
 /// <param name="polyphonic">Should the sound be played polyphonically</param>
 /// <param name="global">Does everyone will receive the sound our just nearby players</param>
 /// <param name="mixerType">The type of mixer to use</param>
 private void PlaySource(SoundSpawn source, bool polyphonic = false, bool global = true, MixerType mixerType = MixerType.Master)
 {
     if (global == false && PlayerManager.LocalPlayer != null)
     {
         if (((PlayerManager.LocalPlayer.TileWorldPosition().To3Int() - source.transform.position.To2Int().To3Int()).magnitude > 20))
         {
             source.AudioSource.outputAudioMixerGroup = AudioManager.Instance.SFXMuffledMixer;                 //Maybe just not play?
         }
         else
         {
             if (MatrixManager.Linecast(PlayerManager.LocalPlayer.TileWorldPosition().To3Int(),
                                        LayerTypeSelection.Walls, layerMask, source.transform.position.To2Int().To3Int())
                 .ItHit)
             {
                 source.AudioSource.outputAudioMixerGroup = AudioManager.Instance.SFXMuffledMixer;
             }
         }
     }
     if (polyphonic)
     {
         source.PlayOneShot();
     }
     else
     {
         source.PlayNormally();
     }
 }
Пример #4
0
    private void PlaySource(SoundSpawn source, bool polyphonic = false, bool Global = true, bool forceMixer = false)
    {
        if (!forceMixer)
        {
            if (!Global &&
                PlayerManager.LocalPlayer != null)

            {
                if (((Vector3)(Vector2)PlayerManager.LocalPlayer.TileWorldPosition() - source.transform.position).magnitude <
                    15f)
                {
                    if (MatrixManager.Linecast((Vector2)PlayerManager.LocalPlayer.TileWorldPosition(),
                                               LayerTypeSelection.Walls, layerMask, source.transform.position).ItHit)
                    {
                        //Logger.Log("MuffledMixer");
                        source.audioSource.outputAudioMixerGroup = soundManager.MuffledMixer;
                    }
                }
                else
                {
                    source.audioSource.outputAudioMixerGroup = soundManager.MuffledMixer;
                }
            }
        }

        if (polyphonic)
        {
            source.PlayOneShot();
        }
        else
        {
            source.PlayNormally();
        }
    }
Пример #5
0
 void Start()
 {
     sound  = FindObjectOfType <SoundSpawn>();
     player = FindObjectOfType <PlayerController> ().transform;
     flash  = GameObject.Find("PentagramFlash").GetComponent <Flash>();
     shaker = FindObjectOfType <CinemachineCameraShaker>();
 }
Пример #6
0
 /// <summary>
 /// Changes the Audio Source Parameters of a sound currently playing
 /// </summary>
 /// <param name="soundSpawnToken">The Token of the sound spawn to change the parameters</param>
 /// <param name="audioSourceParameters">The Audio Source Parameters to apply</param>
 public static void ChangeAudioSourceParameters(string soundSpawnToken, AudioSourceParameters audioSourceParameters)
 {
     if (Instance.SoundSpawns.ContainsKey(soundSpawnToken))
     {
         SoundSpawn soundSpawn = Instance.SoundSpawns[soundSpawnToken];
         ApplyAudioSourceParameters(audioSourceParameters, soundSpawn);
     }
 }
Пример #7
0
 void Start()
 {
     anim        = GetComponent <Animator> ();
     player      = FindObjectOfType <PlayerController> ().transform;
     sound       = FindObjectOfType <SoundSpawn> ();
     parentShake = transform.parent.GetComponent <Shake> ();
     InvokeRepeating("Shoot", fireRate, fireRate);
 }
Пример #8
0
    /// <summary>
    /// Play a sound locally
    /// If more than one is specified, one will be picked at random.
    /// </summary>
    /// <param name="addressableAudioSources">The sound to be played.  If more than one is specified, one will be picked at random.</param>
    /// <param name="soundSpawnToken">The SoundSpawn Token that identifies the same sound spawn instance across server and clients</returns>
    /// <param name="audioSourceParameters">Parameters for how to play the sound</param>
    /// <param name="polyphonic">Should the sound be played polyphonically</param>
    public static async Task Play(List <AddressableAudioSource> addressableAudioSources, string soundSpawnToken, AudioSourceParameters audioSourceParameters, bool polyphonic = false)
    {
        AddressableAudioSource addressableAudioSource = await GetAddressableAudioSourceFromCache(addressableAudioSources);

        SoundSpawn soundSpawn = Instance.GetSoundSpawn(addressableAudioSource, addressableAudioSource.AudioSource, soundSpawnToken);

        ApplyAudioSourceParameters(audioSourceParameters, soundSpawn);

        Instance.PlaySource(soundSpawn, polyphonic, forceMixer: audioSourceParameters != null && audioSourceParameters.MixerType != MixerType.Unspecified);
    }
Пример #9
0
    /// <summary>
    /// Play a sound locally
    /// </summary>
    /// <param name="addressableAudioSource">The sound to be played.</param>
    /// <param name="soundSpawnToken">The SoundSpawn Token that identifies the same sound spawn instance across server and clients</returns>
    /// <param name="audioSourceParameters">Parameters for how to play the sound</param>
    /// <param name="polyphonic">Should the sound be played polyphonically</param>
    public static async Task Play(AddressableAudioSource addressableAudioSource, string soundSpawnToken = "",
                                  AudioSourceParameters audioSourceParameters = new AudioSourceParameters(), bool polyphonic = false)
    {
        addressableAudioSource = await GetAddressableAudioSourceFromCache(addressableAudioSource).ConfigureAwait(false);

        SoundSpawn soundSpawn =
            Instance.GetSoundSpawn(addressableAudioSource, addressableAudioSource.AudioSource, soundSpawnToken);

        ApplyAudioSourceParameters(audioSourceParameters, soundSpawn);
        Instance.PlaySource(soundSpawn, polyphonic, true, audioSourceParameters.MixerType);
    }
Пример #10
0
    /// <summary>
    /// Changes the Audio Source Parameters of a sound currently playing
    /// </summary>
    /// <param name="soundSpawnToken">The Token of the sound spawn to change the parameters</param>
    /// <param name="audioSourceParameters">The Audio Source Parameters to apply</param>
    public static void ChangeAudioSourceParameters(string soundSpawnToken, AudioSourceParameters audioSourceParameters)
    {
        if (Instance.SoundSpawns.ContainsKey(soundSpawnToken))
        {
            SoundSpawn soundSpawn = Instance.SoundSpawns[soundSpawnToken];

            if (soundSpawn == null)
            {
                Debug.LogError($"Unable to change audio parameters, soundSpawn was null");
                return;
            }

            ApplyAudioSourceParameters(audioSourceParameters, soundSpawn);
        }
    }
Пример #11
0
    /// <summary>
    /// Play a sound locally
    /// </summary>
    /// <param name="addressableAudioSource">The sound to be played.</param>
    /// <param name="soundSpawnToken">The SoundSpawn Token that identifies the same sound spawn instance across server and clients</returns>
    /// <param name="audioSourceParameters">Parameters for how to play the sound</param>
    /// <param name="polyphonic">Should the sound be played polyphonically</param>
    public static async Task Play(AddressableAudioSource addressableAudioSource, string soundSpawnToken = "",
                                  AudioSourceParameters audioSourceParameters = new AudioSourceParameters(), bool polyphonic = false)
    {
        if (GameData.IsHeadlessServer)
        {
            return;
        }

        addressableAudioSource = await AudioManager.GetAddressableAudioSourceFromCache(addressableAudioSource);

        SoundSpawn soundSpawn =
            Instance.GetSoundSpawn(addressableAudioSource, addressableAudioSource.AudioSource, soundSpawnToken);

        ApplyAudioSourceParameters(audioSourceParameters, soundSpawn);
        Instance.PlaySource(soundSpawn, polyphonic, true, audioSourceParameters.MixerType);
    }
Пример #12
0
    /// <summary>
    /// Play sound locally.
    /// If more than one is specified, one will be picked at random.
    /// </summary>
    /// <param name="addressableAudioSources">The sound to be played.  If more than one is specified, one will be picked at random.</param>
    /// <param name="soundSpawnToken">The SoundSpawn Token that identifies the same sound spawn instance across server and clients</returns>
    public static async Task Play(List <AddressableAudioSource> addressableAudioSources, string soundSpawnToken, float volume, float pitch = -1, float time = 0, bool oneShot = false,
                                  float pan = 0)
    {
        AddressableAudioSource addressableAudioSource = await GetAddressableAudioSourceFromCache(addressableAudioSources);

        SoundSpawn soundSpawn = Instance.GetSoundSpawn(addressableAudioSource, addressableAudioSource.AudioSource, soundSpawnToken);

        if (pitch > 0)
        {
            soundSpawn.AudioSource.pitch = pitch;
        }

        soundSpawn.AudioSource.time      = time;
        soundSpawn.AudioSource.volume    = volume;
        soundSpawn.AudioSource.panStereo = pan;
        Instance.PlaySource(soundSpawn, oneShot);
    }
Пример #13
0
 /// <summary>
 /// Plays a SoundSpawn.
 /// </summary>
 /// <param name="source">The SoundSpawn to be played</param>
 /// <param name="polyphonic">Should the sound be played polyphonically</param>
 /// <param name="global">Does everyone will receive the sound our just nearby players</param>
 /// <param name="mixerType">The type of mixer to use</param>
 private void PlaySource(SoundSpawn source, bool polyphonic = false, bool global = true, MixerType mixerType = MixerType.Master)
 {
     if (global == false &&
         PlayerManager.LocalPlayer != null &&
         MatrixManager.Linecast(PlayerManager.LocalPlayer.TileWorldPosition().To3Int(),
                                LayerTypeSelection.Walls, layerMask, source.transform.position.To2Int().To3Int())
         .ItHit)
     {
         source.AudioSource.outputAudioMixerGroup = soundManager.MuffledMixer;
     }
     if (polyphonic)
     {
         source.PlayOneShot();
     }
     else
     {
         source.PlayNormally();
     }
 }
Пример #14
0
    /// <summary>
    /// Generates a SoundSpawn and put it the SoundSpawns list.
    /// This copies the AudioSource settings to the new SoundSpawn instance and returns it.
    /// </summary>
    /// <param name="audioSource">The AudioSource to copy</param>
    /// <param name="soundSpawnToken">The SoundSpawn Token that identifies the same sound spawn instance across server and clients</returns>
    /// <returns>The SoundSpawn to be played</returns>
    private SoundSpawn GetNewSoundSpawn(AddressableAudioSource addressableAudioSource, AudioSource audioSource, string soundSpawnToken)
    {
        // The position doesn't matter at this point, but we need to provide one.
        GameObject soundSpawnObject = Instantiate(Instance.soundSpawnPrefab, Vector3.zero, Quaternion.identity);

        soundSpawnObject.transform.SetParent(this.gameObject.transform);
        soundSpawnObject.name = audioSource.name;
        SoundSpawn soundSpawn = soundSpawnObject.GetComponent <SoundSpawn>();

        soundSpawn.SetAudioSource(audioSource);
        soundSpawn.assetAddress = addressableAudioSource.AssetAddress;
        if (soundSpawnToken != string.Empty)
        {
            soundSpawn.Token = soundSpawnToken;
            SoundSpawns[soundSpawn.Token] = soundSpawn;
        }

        return(soundSpawn);
    }
Пример #15
0
    private void PlaySource(SoundSpawn source, bool polyphonic = false, bool Global = true, bool forceMixer = false)
    {
        if (!forceMixer)
        {
            if (!Global &&
                PlayerManager.LocalPlayer != null &&
                Physics2D.Linecast(PlayerManager.LocalPlayer.TileWorldPosition(), source.RegisterTile.WorldPositionClient.To2Int(), layerMask))
            {
                source.AudioSource.outputAudioMixerGroup = soundManager.MuffledMixer;
            }
        }

        if (polyphonic)
        {
            source.PlayOneShot();
        }
        else
        {
            source.PlayNormally();
        }
    }
Пример #16
0
    private void PlaySource(SoundSpawn source, bool polyphonic = false, bool Global = true, bool forceMixer = false)
    {
        if (!forceMixer)
        {
            if (!Global &&
                PlayerManager.LocalPlayer != null &&
                Physics2D.Linecast(PlayerManager.LocalPlayer.TileWorldPosition(), source.transform.position, layerMask))
            {
                //Logger.Log("MuffledMixer");
                source.audioSource.outputAudioMixerGroup = soundManager.MuffledMixer;
            }
        }

        if (polyphonic)
        {
            source.PlayOneShot();
        }
        else
        {
            source.PlayNormally();
        }
    }
Пример #17
0
        /// <summary>
        /// The h 2 spawn info.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void H2SpawnInfo(Map map)
        {
            map.OpenMap(MapTypes.Internal);

            // find default mc model
            map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 308;
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            map.BR.BaseStream.Position = tempr + 4;
            int tempbipdtag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
            //map.CloseMap();
            int bipdmodeltag = map.Functions.FindModelByBaseClass(tempbipdtag);

            int ctfmodeltag = -1;
            int ballmodeltag = -1;
            int juggernautdmodeltag = -1;
            int assultmodeltag = -1;

            #region  //// Find objective models ////

            try
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position =
                    map.MetaInfo.Offset[
                        map.Functions.ForMeta.FindByNameAndTagType("mulg", "multiplayer\\multiplayer_globals")] + 12;
                tempr = map.BR.ReadInt32();
                if (tempr != 0)
                {
                    tempr -= map.SecondaryMagic;
                    map.BR.BaseStream.Position = tempr + 4;
                    int tempCtftag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    map.BR.BaseStream.Position = tempr + 12;
                    int tempBalltag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                    map.BR.BaseStream.Position = tempr + 36;
                    int tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                    // I believe the Hill Shader above is not used, but just in case. Otherwise, load the usual one below
                    if (tempHillShader == -1)
                    {
                        map.BR.BaseStream.Position = tempr + 1332;
                        int tempr2 = map.BR.ReadInt32();
                        if (tempr2 != 0)
                        {
                            tempr2 -= map.SecondaryMagic;
                            map.BR.BaseStream.Position = tempr2 + 196;
                            tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                        }
                    }

                    map.BR.BaseStream.Position = tempr + 52;
                    int tempJuggernauttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    map.BR.BaseStream.Position = tempr + 60;
                    int tempAssaulttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();

                    ctfmodeltag = map.Functions.FindModelByBaseClass(tempCtftag);
                    ballmodeltag = map.Functions.FindModelByBaseClass(tempBalltag);

                    // *** This is not right. It's a shader, not a model. But I don't know how to display a shader...
                    hillshadertag = map.Functions.ForMeta.FindMetaByID(tempHillShader);

                    juggernautdmodeltag = map.Functions.FindModelByBaseClass(tempJuggernauttag);
                    assultmodeltag = map.Functions.FindModelByBaseClass(tempAssaulttag);
                }
            }
            catch (Exception e)
            {
               System.Windows.Forms.MessageBox.Show("Error loading an objective model (CTF/Juggernaut/Assault/Bomb)\n" + e.Message);
            }

            #endregion

            #region //// Player Spawns ////

            try
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 256;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    map.BR.BaseStream.Position = tempr + (52 * x);
                    PlayerSpawn ps = new PlayerSpawn();
                    ps.Read(map);

                    ps.ModelTagNumber = bipdmodeltag;
                    ps.ModelName = map.FileNames.Name[ps.ModelTagNumber];

                    Spawn.Add(ps);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading player spawns", e);
            }

            #endregion

            #region //// trigger volumes / death zones ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 264;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    DeathZone tv = new DeathZone();
                    map.BR.BaseStream.Position = tempr + (68 * x);
                    tv.Read(map);

                    Spawn.Add(tv);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading death zones", e);
            }

            #endregion

            #region //// lights ////

            try
            {
                //// palette ////
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 240;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    temppalette2[x] = tempbase;
                    temppalette[x] = tempbase;
                }

                //// placement ////
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 232;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    map.BR.BaseStream.Position = tempr + (108 * x);
                    short tempshort = map.BR.ReadInt16();

                    LightSpawn ls = new LightSpawn();
                    map.BR.BaseStream.Position = tempr + (108 * x);
                    ls.Read(map);

                    if (ls.PaletteIndex == -1)
                    {
                        continue;
                    }

                    int nameIndex = temppalette2[tempshort];
                    if (nameIndex >= 0)
                        ls.TagPath = map.FileNames.Name[nameIndex];
                    ls.ModelTagNumber = temppalette[tempshort];
                    if (ls.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    ls.ModelName = map.FileNames.Name[ls.ModelTagNumber];
                    Spawn.Add(ls);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Lights", e);
            }

            #endregion

            #region //// sounds ////

            try
            {
                //// Sound Scenery palette ////
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 224;

                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    temppalette2[x] = tempbase;
                    temppalette[x] = tempbase;
                }

                //// placement ////
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 216;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    SoundSpawn ss = new SoundSpawn();
                    map.BR.BaseStream.Position = tempr + (80 * x);
                    ss.Read(map);

                    if (ss.PaletteIndex == -1 || temppalette2[ss.PaletteIndex] == -1)
                    {
                        ss.TagPath = NullTags;
                    }
                    else
                    {
                        ss.TagPath = map.FileNames.Name[temppalette2[ss.PaletteIndex]];
                    }

                    ss.ModelTagNumber = temppalette[ss.PaletteIndex];
                    if (ss.ModelTagNumber == -1)
                    {
                        // { continue; }
                        ss.ModelName = null;
                    }
                    else
                    {
                        ss.ModelName = map.FileNames.Name[ss.ModelTagNumber];
                    }

                    Spawn.Add(ss);
                }

            }
            catch (Exception e)
            {
                throw new Exception("Error loading sounds", e);
            }

            #endregion

            #region //// objectives ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 280;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < tempc; x++)
                {
                    ObjectiveSpawn os = new ObjectiveSpawn();
                    map.BR.BaseStream.Position = tempr + (32 * x);
                    os.Read(map);

                    if (os.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.OddballSpawn && ballmodeltag != -1)
                    {
                        os.ModelTagNumber = ballmodeltag;
                    }
                    else if (os.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.CTFRespawn && ctfmodeltag != -1)
                    {
                        os.ModelTagNumber = ctfmodeltag;
                    }
                    else if (
                        os.ObjectiveType.ToString().StartsWith(
                            ObjectiveSpawn.ObjectiveTypeEnum.KingOfTheHill_1.ToString().Substring(0, 13)) &&
                        ctfmodeltag != -1)
                    {
                        os.ModelTagNumber = ctfmodeltag;
                    }
                    else if (os.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.AssaultRespawn && assultmodeltag != -1)
                    {
                        os.ModelTagNumber = assultmodeltag;
                    }
                    else
                    {
                        os.ModelTagNumber = bipdmodeltag;
                    }

                    os.ModelName = map.FileNames.Name[os.ModelTagNumber];
                    Spawn.Add(os);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading lights", e);
            }
            #endregion

            #region //// vehicles ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 120;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 112;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    VehicleSpawn vs = new VehicleSpawn();
                    map.BR.BaseStream.Position = tempr + (84 * x);
                    vs.Read(map);

                    if (vs.PaletteIndex == -1)
                    {
                        continue;
                    }

                    vs.TagPath = map.FileNames.Name[temppalette2[vs.PaletteIndex]];
                    vs.ModelTagNumber = temppalette[vs.PaletteIndex];
                    if (vs.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                    Spawn.Add(vs);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading vehicles", e);
            }

            #endregion

            #region //// equipment ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 136;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 128;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    EquipmentSpawn es = new EquipmentSpawn();
                    map.BR.BaseStream.Position = tempr + (56 * x);
                    es.Read(map);

                    if (es.PaletteIndex == -1)
                    {
                        continue;
                    }

                    es.TagPath = map.FileNames.Name[temppalette2[es.PaletteIndex]];
                    es.ModelTagNumber = temppalette[es.PaletteIndex];
                    if (es.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    es.ModelName = map.FileNames.Name[es.ModelTagNumber];
                    Spawn.Add(es);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading equipment", e);
            }

            #endregion

            #region //// bipeds ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 104;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 96;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    BipedSpawn bs = new BipedSpawn();
                    map.BR.BaseStream.Position = tempr + (84 * x);
                    bs.Read(map);

                    if (bs.PaletteIndex == -1)
                    {
                        continue;
                    }

                    bs.TagPath = map.FileNames.Name[temppalette2[bs.PaletteIndex]];
                    bs.ModelTagNumber = temppalette[bs.PaletteIndex];
                    if (bs.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    bs.ModelName = map.FileNames.Name[bs.ModelTagNumber];
                    Spawn.Add(bs);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Bipeds", e);
            }

            #endregion

            #region //// control ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 192;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 184;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    ControlSpawn cs = new ControlSpawn();
                    map.BR.BaseStream.Position = tempr + (68 * x);
                    cs.Read(map);

                    if (cs.PaletteIndex == -1)
                    {
                        continue;
                    }

                    cs.TagPath = map.FileNames.Name[temppalette2[cs.PaletteIndex]];
                    cs.ModelTagNumber = temppalette[cs.PaletteIndex];
                    if (cs.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    cs.ModelName = map.FileNames.Name[cs.ModelTagNumber];
                    Spawn.Add(cs);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Control", e);
            }

            #endregion

            #region //// machines ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 176;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 168;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    MachineSpawn ms = new MachineSpawn();
                    map.BR.BaseStream.Position = tempr + (72 * x);
                    ms.Read(map);

                    if (ms.PaletteIndex == -1)
                    {
                        continue;
                    }

                    if (temppalette2[ms.PaletteIndex] == -1 || temppalette[ms.PaletteIndex] == -1)
                    {
                        continue;
                    }

                    ms.TagPath = map.FileNames.Name[temppalette2[ms.PaletteIndex]];
                    ms.ModelTagNumber = temppalette[ms.PaletteIndex];
                    if (ms.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    ms.ModelName = map.FileNames.Name[ms.ModelTagNumber];
                    Spawn.Add(ms);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Machines", e);
            }

            #endregion

            #region //// scenery ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 88;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 80;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    ScenerySpawn ss = new ScenerySpawn();
                    map.BR.BaseStream.Position = tempr + (92 * x);
                    ss.Read(map);

                    if (ss.PaletteIndex == -1)
                    {
                        continue;
                    }

                    if (temppalette2[ss.PaletteIndex] == -1 || temppalette[ss.PaletteIndex] == -1)
                    {
                        continue;
                    }

                    ss.TagPath = map.FileNames.Name[temppalette2[ss.PaletteIndex]];
                    ss.ModelTagNumber = temppalette[ss.PaletteIndex];
                    if (ss.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    ss.ModelName = map.FileNames.Name[ss.ModelTagNumber];
                    Spawn.Add(ss);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Scenery", e);
            }

            #endregion

            #region //// weapons ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 152;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 144;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    WeaponSpawn ws = new WeaponSpawn();
                    map.BR.BaseStream.Position = tempr + (84 * x);
                    ws.Read(map);

                    if (ws.PaletteIndex == -1)
                    {
                        continue;
                    }

                    ws.TagPath = map.FileNames.Name[temppalette2[ws.PaletteIndex]];
                    ws.ModelTagNumber = temppalette[ws.PaletteIndex];
                    if (ws.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    ws.ModelName = map.FileNames.Name[ws.ModelTagNumber];
                    Spawn.Add(ws);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Weapons", e);
            }

            #endregion

            #region //// obstacles ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 816;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    //map.CloseMap();
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 808;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    ObstacleSpawn os = new ObstacleSpawn();
                    map.BR.BaseStream.Position = tempr + (76 * x);
                    os.Read(map);

                    if (os.PaletteIndex == -1)
                    {
                        continue;
                    }

                    if (temppalette2[os.PaletteIndex] == -1)
                    {
                        continue;
                    }

                    os.TagPath = map.FileNames.Name[temppalette2[os.PaletteIndex]];
                    os.ModelTagNumber = temppalette[os.PaletteIndex];
                    if (os.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    os.ModelName = map.FileNames.Name[os.ModelTagNumber];
                    Spawn.Add(os);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Obstacles", e);
            }

            #endregion

            #region //// collections ////

            try
            {
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 288;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    Collection collect = new Collection();
                    map.BR.BaseStream.Position = tempr + (144 * x);
                    collect.Read(map);

                    // ID Type
                    if (collect.TagPath == NullTags)
                    {
                        continue;
                    }

                    if (collect.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    collect.ModelName = map.FileNames.Name[collect.ModelTagNumber];
                    Spawn.Add(collect);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Collections", e);
            }

            #endregion

            #region //// cameras ////

            try
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 488;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    //map.OpenMap(MapTypes.Internal);
                    CameraSpawn cs = new CameraSpawn();
                    map.BR.BaseStream.Position = tempr + (64 * x);
                    cs.Read(map);

                    Spawn.Add(cs);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Collections", e);
            }

            #endregion

            #region //// AI_Squads ////

            try
            {
                // Reading Character Palette
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 376;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int[] temppalette2 = new int[temppalette.Length];
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;
                for (int x = 0; x < temppalette.Length; x++)
                {
                    map.BR.BaseStream.Position = tempr + (x * 8) + 4;
                    int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    temppalette2[x] = tempbase;
                    temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
                }

                // Reading ai squads reflexive
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 352;
                int tempc = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < tempc; x++)
                {
                    // Reads AI Squad character index
                    map.BR.BaseStream.Position = tempr + (x * 116) + 54;
                    short charIndex = map.BR.ReadInt16();

                    // Reading locations sub reflexive
                    map.BR.BaseStream.Position = tempr + (x * 116) + 72;
                    int locc = map.BR.ReadInt32();
                    int locr = map.BR.ReadInt32() - map.SecondaryMagic;

                    for (int y = 0; y < locc; y++)
                    {
                        AI_Squads ai = new AI_Squads(x);
                        map.BR.BaseStream.Position = locr + (100 * y);
                        ai.Read(map);

                        if (charIndex != -1)
                        {
                            ai.TagPath = map.FileNames.Name[temppalette2[charIndex]];
                            ai.ModelTagNumber = temppalette[charIndex];
                            if (ai.ModelTagNumber == -1)
                            {
                                continue;
                            }

                            // ai.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                            Spawn.Add(ai);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error loading AI Squads", e);
            }

            #endregion

            #region //// Spawn Zones ////

            try
            {
                // Reading Spawn Zone Section
                // 792 = Spawn Data
                map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 792;
                int SpawnDataCount = map.BR.ReadInt32();
                tempr = map.BR.ReadInt32() - map.SecondaryMagic;

                #region //// Inital Spawn Zones ////
                // 88 = Static Initial Spawn Zones
                map.BR.BaseStream.Position = tempr + 88;
                int[] temppalette = new int[map.BR.ReadInt32()];
                int initialR = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < temppalette.Length; x++)
                {
                    // Each Initial Spawn Zone chunk = 48 bytes
                    map.BR.BaseStream.Position = initialR + (x * 48);
                    SpawnZone spawnZone = new SpawnZone(SpawnZoneType.Inital);
                    spawnZone.Read(map);

                    Spawn.Add(spawnZone);
                }
                #endregion

                #region //// Respawn Zones ////
                // 80 = Static Respawn Zones
                map.BR.BaseStream.Position = tempr + 80;
                temppalette = new int[map.BR.ReadInt32()];
                int respawnR = map.BR.ReadInt32() - map.SecondaryMagic;

                for (int x = 0; x < temppalette.Length; x++)
                {
                    // Each Respawn Zone chunk = 48 bytes
                    map.BR.BaseStream.Position = respawnR + (x * 48);
                    SpawnZone spawnZone = new SpawnZone(SpawnZoneType.Respawn);
                    spawnZone.Read(map);

                    Spawn.Add(spawnZone);
                }
                #endregion
            }
            catch (Exception e)
            {
                throw new Exception("Error loading Spawn Zones (Initial)", e);
            }
            #endregion

            map.CloseMap();
        }
Пример #18
0
    /// <Summary>
    /// Completely overwrites AudioSourceParameters of a Sound to any value.
    /// Only use this if you have a known entry for all parameters, otherwise the sound will
    /// not play properly (eg, having no entry for pitch will make the sound never start or finish)
    /// </Summary>
    private static void ForceAudioSourceParameters(AudioSourceParameters audioSourceParameters, SoundSpawn soundSpawn)
    {
        AudioSource audioSource = soundSpawn.AudioSource;

        audioSource.volume                = audioSourceParameters.Volume;
        audioSource.pitch                 = audioSourceParameters.Pitch;
        audioSource.time                  = audioSourceParameters.Time;
        audioSource.panStereo             = audioSourceParameters.Pan;
        audioSource.spatialBlend          = audioSourceParameters.SpatialBlend;
        audioSource.minDistance           = audioSourceParameters.MinDistance;
        audioSource.maxDistance           = audioSourceParameters.MaxDistance;
        audioSource.spread                = audioSourceParameters.Spread;
        audioSource.outputAudioMixerGroup = Instance.CalcAudioMixerGroup(audioSourceParameters.MixerType);
        switch (audioSourceParameters.VolumeRolloffType)
        {
        case VolumeRolloffType.EaseInAndOut:
            audioSource.rolloffMode = AudioRolloffMode.Custom;
            audioSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff,
                                       AnimationCurve.EaseInOut(0, 1, 1, 0));
            break;

        case VolumeRolloffType.Linear:
            audioSource.rolloffMode = AudioRolloffMode.Linear;
            break;

        case VolumeRolloffType.Logarithmic:
            audioSource.rolloffMode = AudioRolloffMode.Logarithmic;
            break;
        }
    }
Пример #19
0
    /// <Summary>
    /// Used to apply incomplete AudioSourceParameters to a Sound, such as changing pitch or volume.
    /// As a Struct, AudioSourceParameters initializes zeroed out, so to prevent sounds from getting
    /// messed up some limitations apply.  For complete control use ForceAudioSourceParameters.
    /// </Summary>
    private static void ApplyAudioSourceParameters(AudioSourceParameters audioSourceParameters, SoundSpawn soundSpawn)
    {
        AudioSource audioSource = soundSpawn.AudioSource;

        //Volume can be 0 for two reasons: it is uninitialized or it is supposed to be 0.
        //If it is supposed to be 0, IsMute should be set to true.  If its not 0, that's the value
        //we want, otherwise no changes.
        if (audioSourceParameters.IsMute == true)
        {
            audioSource.volume = 0;
        }
        else if (audioSourceParameters.Volume > 0)
        {
            audioSource.volume = audioSourceParameters.Volume;
        }

        //Pitch should never be 0.  A negative pitch plays the sound backwards.
        if (audioSourceParameters.Pitch != 0)
        {
            audioSource.pitch = audioSourceParameters.Pitch;
        }
        else if (audioSource.pitch == 0)
        {
            audioSource.pitch = 1;
        }

        //The following parameters have some limitations that shouldn't really come up
        //Note if the sound's default value for a parameter is 0, the limitation does not apply.

        //Cannot seek to timestamp 0 for a sound that does not start at the beginning by default
        if (audioSourceParameters.Time != 0)
        {
            audioSource.time = audioSourceParameters.Time;
        }

        //-1 is left, 0 is center, 1 is right.
        //Cannot pan to center for sounds that are panned by default
        if (audioSourceParameters.Pan != 0)
        {
            audioSource.panStereo = audioSourceParameters.Pan;
        }

        //0 is 2D and ignores max/min distance, 1 is 3d and obeys them
        //Cannot convert sounds that are 3D by default to 2D
        if (audioSourceParameters.SpatialBlend != 0)
        {
            audioSource.spatialBlend = audioSourceParameters.SpatialBlend;
        }

        //Cannot change the minimum distance for audio falloff to 0
        if (audioSourceParameters.MinDistance != 0)
        {
            audioSource.minDistance = audioSourceParameters.MinDistance;
        }

        //Cannot change the max distance for falloff to 0 (why would you want that?)
        if (audioSourceParameters.MaxDistance != 0)
        {
            audioSource.maxDistance = audioSourceParameters.MaxDistance;
        }

        //Cannot convert non-mono sounds to mono
        if (audioSourceParameters.Spread != 0)
        {
            audioSource.spread = audioSourceParameters.Spread;
        }

        audioSource.outputAudioMixerGroup = Instance.CalcAudioMixerGroup(audioSourceParameters.MixerType);

        switch (audioSourceParameters.VolumeRolloffType)
        {
        case VolumeRolloffType.EaseInAndOut:
            audioSource.rolloffMode = AudioRolloffMode.Custom;
            audioSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff,
                                       AnimationCurve.EaseInOut(0, 1, 1, 0));
            break;

        case VolumeRolloffType.Linear:
            audioSource.rolloffMode = AudioRolloffMode.Linear;
            break;

        case VolumeRolloffType.Logarithmic:
            audioSource.rolloffMode = AudioRolloffMode.Logarithmic;
            break;
        }
    }
Пример #20
0
        /// <summary>
        /// The h 2 spawn info.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void H2SpawnInfo(Map map)
        {
            map.OpenMap(MapTypes.Internal);

            // find default mc model
            map.BR.BaseStream.Position = map.MetaInfo.Offset[0] + 308;
            int tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            map.BR.BaseStream.Position = tempr + 4;
            int tempbipdtag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
            //map.CloseMap();
            int bipdmodeltag = map.Functions.FindModelByBaseClass(tempbipdtag);

            // Find objective models
            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position =
                map.MetaInfo.Offset[
                    map.Functions.ForMeta.FindByNameAndTagType("mulg", "multiplayer\\multiplayer_globals")] + 12;
            tempr = map.BR.ReadInt32();
            int ctfmodeltag = -1;
            int ballmodeltag = -1;
            int juggernautdmodeltag = -1;
            int assultmodeltag = -1;
            if (tempr != 0)
            {
                tempr -= map.SecondaryMagic;
                map.BR.BaseStream.Position = tempr + 4;
                int tempCtftag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                map.BR.BaseStream.Position = tempr + 12;
                int tempBalltag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                map.BR.BaseStream.Position = tempr + 36;
                int tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                // I believe the Hill Shader above is not used, but just in case. Otherwise, load the usual one below
                if (tempHillShader == -1)
                {
                    map.BR.BaseStream.Position = tempr + 1332;
                    int tempr2 = map.BR.ReadInt32();
                    if (tempr2 != 0)
                    {
                        tempr2 -= map.SecondaryMagic;
                        map.BR.BaseStream.Position = tempr2 + 196;
                        tempHillShader = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    }
                }

                map.BR.BaseStream.Position = tempr + 52;
                int tempJuggernauttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                map.BR.BaseStream.Position = tempr + 60;
                int tempAssaulttag = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();

                ctfmodeltag = map.Functions.FindModelByBaseClass(tempCtftag);
                ballmodeltag = map.Functions.FindModelByBaseClass(tempBalltag);

                // *** This is not right. It's a shader, not a model. But I don't know how to display a shader...
                hillshadertag = map.Functions.ForMeta.FindMetaByID(tempHillShader);

                juggernautdmodeltag = map.Functions.FindModelByBaseClass(tempJuggernauttag);
                assultmodeltag = map.Functions.FindModelByBaseClass(tempAssaulttag);
            }

            #region //// Player Spawns ////

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 256;
            int tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (52 * x);

                PlayerSpawn ps = new PlayerSpawn();
                ps.offset = tempr + (52 * x);
                ps.X = map.BR.ReadSingle();
                ps.Y = map.BR.ReadSingle();
                ps.Z = map.BR.ReadSingle();
                ps.RotationDirection = map.BR.ReadSingle();
                ps.ModelTagNumber = bipdmodeltag;
                ps.ModelName = map.FileNames.Name[ps.ModelTagNumber];

                Spawn.Add(ps);
            }

            #endregion

            #region //// death zones ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 264;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                DeathZone ps = new DeathZone();

                // Load the deathzone name
                map.BR.BaseStream.Position = tempr + (68 * x);
                ps.Name = map.Strings.Name[map.BR.ReadInt16()];

                // We set the offset to 36 b/c we don't care about saving the name... right now anyways.
                ps.offset = tempr + (68 * x) + 36;

                // Load the deathzone coordinates
                map.BR.BaseStream.Position = tempr + (68 * x) + 36;
                ps.X = map.BR.ReadSingle();
                ps.Y = map.BR.ReadSingle();
                ps.Z = map.BR.ReadSingle();

                // Use ABS() to make sure our sizes are always positive
                ps.width = Math.Abs(map.BR.ReadSingle());
                ps.height = Math.Abs(map.BR.ReadSingle());
                ps.length = Math.Abs(map.BR.ReadSingle());

                // Deathzones are saved with a centre point and Width, Length, Height
                ps.X += ps.width / 2;
                ps.Y += ps.height / 2;
                ps.Z += ps.length / 2;

                Spawn.Add(ps);
            }

            #endregion

            #region //// lights ////

            //// palette ////
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 240;
            int[] temppalette = new int[map.BR.ReadInt32()];
            int[] temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                temppalette2[x] = tempbase;
                temppalette[x] = tempbase;
            }

            //// placement ////
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 232;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (108 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (108 * x) + 8;
                LightSpawn vs = new LightSpawn();
                vs.offset = tempr + (108 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// sounds ////

            //// Sound Scenery palette ////
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 224;

            // temppalette variables declared in Lights section above
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                temppalette2[x] = tempbase;
                temppalette[x] = tempbase;
            }

            //// placement ////
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 216;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (80 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                SoundSpawn vs = new SoundSpawn();

                map.BR.BaseStream.Position = tempr + (80 * x) + 8;
                vs.offset = tempr + (80 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                map.BR.BaseStream.Position = tempr + (80 * x) + 54;
                vs.VolumeType = map.BR.ReadInt16();
                vs.Height = map.BR.ReadSingle();
                vs.DistanceBoundsLower = map.BR.ReadSingle();
                vs.DistanceBoundsUpper = map.BR.ReadSingle();
                vs.ConeAngleLower = map.BR.ReadSingle();
                vs.ConeAngleUpper = map.BR.ReadSingle();
                vs.OuterConeGain = map.BR.ReadSingle();

                if (temppalette2[tempshort] == -1)
                {
                    vs.TagPath = "Nulled Out";
                }
                else
                {
                    vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                }

                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    // { continue; }
                    vs.ModelName = null;
                }
                else
                {
                    vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                }

                Spawn.Add(vs);
            }

            #endregion

            #region //// objectives ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 280;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < tempc; x++)
            {
                ObjectiveSpawn ps = new ObjectiveSpawn();
                ps.offset = tempr + (32 * x);
                map.BR.BaseStream.Position = tempr + (32 * x);
                ps.X = map.BR.ReadSingle();
                ps.Y = map.BR.ReadSingle();
                ps.Z = map.BR.ReadSingle();
                ps.RotationDirection = map.BR.ReadSingle();
                ps.ObjectiveType = (ObjectiveSpawn.ObjectiveTypeEnum)map.BR.ReadInt16();
                ps.Team = (ObjectiveSpawn.TeamType)map.BR.ReadInt16();
                ps.number = map.BR.ReadInt16();

                if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.OddballSpawn && ballmodeltag != -1)
                {
                    ps.ModelTagNumber = ballmodeltag;
                }
                else if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.CTFRespawn && ctfmodeltag != -1)
                {
                    ps.ModelTagNumber = ctfmodeltag;
                }
                else if (
                    ps.ObjectiveType.ToString().StartsWith(
                        ObjectiveSpawn.ObjectiveTypeEnum.KingOfTheHill_1.ToString().Substring(0, 13)) &&
                    ctfmodeltag != -1)
                {
                    ps.ModelTagNumber = ctfmodeltag;
                }
                else if (ps.ObjectiveType == ObjectiveSpawn.ObjectiveTypeEnum.AssaultRespawn && assultmodeltag != -1)
                {
                    ps.ModelTagNumber = assultmodeltag;
                }
                else
                {
                    ps.ModelTagNumber = bipdmodeltag;
                }

                ps.ModelName = map.FileNames.Name[ps.ModelTagNumber];
                Spawn.Add(ps);
            }

            #endregion

            #region //// vehicles ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 120;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 112;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (84 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (84 * x) + 8;
                VehicleSpawn vs = new VehicleSpawn();
                vs.offset = tempr + (84 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// equipment ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 136;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 128;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (56 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (56 * x) + 8;
                EquipmentSpawn vs = new EquipmentSpawn();
                vs.offset = tempr + (56 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();

                // vs.RotationDirection = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// bipeds ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 104;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 96;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (84 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (84 * x) + 8;
                BipedSpawn vs = new BipedSpawn();
                vs.offset = tempr + (84 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// control ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 192;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 184;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (68 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (68 * x) + 8;
                ControlSpawn vs = new ControlSpawn();
                vs.offset = tempr + (68 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();

                // vs.RotationDirection = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// machines ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 176;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 168;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (72 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (72 * x) + 8;
                MachineSpawn vs = new MachineSpawn();
                vs.offset = tempr + (72 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                if (temppalette2[tempshort] == -1 || temppalette[tempshort] == -1)
                {
                    continue;
                }

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// scenery ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 88;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 80;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (92 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (92 * x) + 8;
                ScenerySpawn vs = new ScenerySpawn();
                vs.offset = tempr + (92 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                if (temppalette2[tempshort] == -1 || temppalette[tempshort] == -1)
                {
                    continue;
                }

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// weapons ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 152;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 144;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (84 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (84 * x) + 8;
                WeaponSpawn vs = new WeaponSpawn();
                vs.offset = tempr + (84 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// obstacles ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 816;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                map.BR.BaseStream.Position = tempr + (x * 40) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                //map.CloseMap();
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 808;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                map.BR.BaseStream.Position = tempr + (76 * x);
                short tempshort = map.BR.ReadInt16();

                if (tempshort == -1)
                {
                    continue;
                }

                map.BR.BaseStream.Position = tempr + (76 * x) + 8;
                ObstacleSpawn vs = new ObstacleSpawn();
                vs.offset = tempr + (76 * x) + 8;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.Scale = map.BR.ReadSingle();

                if (temppalette2[tempshort] == -1)
                {
                    continue;
                }

                vs.TagPath = map.FileNames.Name[temppalette2[tempshort]];
                vs.ModelTagNumber = temppalette[tempshort];
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// collections ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 288;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                Collection vs = new Collection();
                map.BR.BaseStream.Position = tempr + (144 * x) + 4;
                vs.SpawnsInMode = (Collection.SpawnsInEnum)map.BR.ReadInt32();

                // Why do they make the offset + 64? That just confuses stuff!!
                map.BR.BaseStream.Position = tempr + (144 * x) + 64;
                vs.offset = tempr + (144 * x) + 64;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();

                // test
                // if (vs.Pitch > 0) { vs.Pitch = -vs.Pitch; vs.isWeird = true; } else { vs.isWeird = false; }
                map.BR.BaseStream.Position = tempr + (144 * x) + 88;

                // ID Type
                char[] c = map.BR.ReadChars(4);
                vs.TagType = c[3].ToString() + c[2] + c[1] + c[0];

                // Tag Path ID
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                if (tempbase == -1)
                {
                    continue;
                }

                //map.CloseMap();
                vs.TagPath = map.FileNames.Name[tempbase];
                vs.ModelTagNumber = map.Functions.FindModelByBaseClass(tempbase);
                if (vs.ModelTagNumber == -1)
                {
                    continue;
                }

                vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                Spawn.Add(vs);
            }

            #endregion

            #region //// cameras ////

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 488;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                //map.OpenMap(MapTypes.Internal);
                CameraSpawn vs = new CameraSpawn();
                map.BR.BaseStream.Position = tempr + (64 * x) + 36;
                vs.offset = tempr + (64 * x) + 36;
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();
                vs.Roll = map.BR.ReadSingle();
                vs.Pitch = map.BR.ReadSingle();
                vs.Yaw = map.BR.ReadSingle();
                vs.fov = map.BR.ReadSingle();
                vs.ModelTagNumber = -1;

                Spawn.Add(vs);
            }

            #endregion

            #region //// AI_Squads ////

            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 376;
            temppalette = new int[map.BR.ReadInt32()];
            temppalette2 = new int[temppalette.Length];
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;
            for (int x = 0; x < temppalette.Length; x++)
            {
                map.BR.BaseStream.Position = tempr + (x * 8) + 4;
                int tempbase = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                temppalette2[x] = tempbase;
                temppalette[x] = map.Functions.FindModelByBaseClass(tempbase);
            }

            // Reading ai squads reflexive
            map.BR.BaseStream.Position = map.MetaInfo.Offset[3] + 352;
            tempc = map.BR.ReadInt32();
            tempr = map.BR.ReadInt32() - map.SecondaryMagic;

            for (int x = 0; x < tempc; x++)
            {
                // Reads AI Squad palette chunk
                map.BR.BaseStream.Position = tempr + (x * 116) + 54;
                short charNum = map.BR.ReadInt16();

                // Reading locations sub reflexive
                map.BR.BaseStream.Position = tempr + 72;
                int locc = map.BR.ReadInt32();
                int locr = map.BR.ReadInt32() - map.SecondaryMagic;

                AI_Squads vs = new AI_Squads();

                // chunk size * x and starting position
                map.BR.BaseStream.Position = locr + (100 * x);
                vs.offset = tempr + (100 * x);
                vs.ModelName = map.Strings.Name[(Int16)map.BR.ReadInt32()];
                vs.X = map.BR.ReadSingle();
                vs.Y = map.BR.ReadSingle();
                vs.Z = map.BR.ReadSingle();

                // facing direction
                map.BR.BaseStream.Position = locr + (100 * x) + 20;
                vs.RotationDirection = map.BR.ReadSingle();

                if (charNum != -1)
                {
                    vs.TagPath = map.FileNames.Name[temppalette2[charNum]];
                    vs.ModelTagNumber = temppalette[charNum];
                    if (vs.ModelTagNumber == -1)
                    {
                        continue;
                    }

                    // vs.ModelName = map.FileNames.Name[vs.ModelTagNumber];
                    Spawn.Add(vs);
                }
            }

            #endregion

            map.CloseMap();
        }
Пример #21
0
    private static void ApplyAudioSourceParameters(AudioSourceParameters audioSourceParameters, SoundSpawn soundSpawn)
    {
        AudioSource audioSource = soundSpawn.AudioSource;

        if (audioSourceParameters != null)
        {
            if (audioSourceParameters.MixerType != MixerType.Unspecified)
            {
                audioSource.outputAudioMixerGroup = audioSourceParameters.MixerType == MixerType.Master ? Instance.DefaultMixer : Instance.MuffledMixer;
            }

            if (audioSourceParameters.Pitch != null)
            {
                audioSource.pitch = audioSourceParameters.Pitch.Value;
            }
            else
            {
                audioSource.pitch = 1;
            }

            if (audioSourceParameters.Time != null)
            {
                audioSource.time = audioSourceParameters.Time.Value;
            }

            if (audioSourceParameters.Volume != null)
            {
                audioSource.volume = audioSourceParameters.Volume.Value;
            }

            if (audioSourceParameters.Pan != null)
            {
                audioSource.panStereo = audioSourceParameters.Pan.Value;
            }

            if (audioSourceParameters.SpatialBlend != null)
            {
                audioSource.spatialBlend = audioSourceParameters.SpatialBlend.Value;
            }

            if (audioSourceParameters.MinDistance != null)
            {
                audioSource.minDistance = audioSourceParameters.MinDistance.Value;
            }

            if (audioSourceParameters.MaxDistance != null)
            {
                audioSource.maxDistance = audioSourceParameters.MaxDistance.Value;
            }

            if (audioSourceParameters.Spread != null)
            {
                audioSource.spread = audioSourceParameters.Spread.Value;
            }

            switch (audioSourceParameters.VolumeRolloffType)
            {
            case VolumeRolloffType.EaseInAndOut:
                audioSource.rolloffMode = AudioRolloffMode.Custom;
                audioSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.EaseInOut(0, 1, 1, 0));
                break;

            case VolumeRolloffType.Linear:
                audioSource.rolloffMode = AudioRolloffMode.Linear;
                break;

            case VolumeRolloffType.Logarithmic:
                audioSource.rolloffMode = AudioRolloffMode.Logarithmic;
                break;
            }
        }
    }