PetrosHeH

Record Player Mod code

May 4th, 2021 (edited)
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.12 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using Wolfpack;
  8.  
  9. // Token: 0x020004EE RID: 1262
  10. public class Recordplayer : W_NetworkBehaviour
  11. {
  12.     // Token: 0x06001E01 RID: 7681 RVA: 0x0000E473 File Offset: 0x0000C673
  13.     public Recordplayer()
  14.     {
  15.     }
  16.  
  17.     // Token: 0x06001E02 RID: 7682 RVA: 0x00116FDC File Offset: 0x001151DC
  18.     private void Start()
  19.     {
  20.         string text = Application.dataPath + "/Mods/Pedram/Music/";
  21.         if (Directory.Exists(text) && File.Exists(text + "list.txt"))
  22.         {
  23.             this.audioNames = File.ReadAllLines(text + "list.txt");
  24.             GameObject gameObject = GameObject.Find("Canvas");
  25.             Transform transform = gameObject.transform.GetChild(4);
  26.             if (transform.name != "MusicPanel")
  27.             {
  28.                 Transform[] componentsInChildren = gameObject.GetComponentsInChildren<Transform>();
  29.                 for (int i = 0; i < componentsInChildren.Length; i++)
  30.                 {
  31.                     if (componentsInChildren[i].name == "MusicPanel")
  32.                     {
  33.                         transform = componentsInChildren[i];
  34.                     }
  35.                 }
  36.             }
  37.             this.musicContainer = transform.GetChild(0).GetChild(0).GetChild(0).GetChild(0).gameObject;
  38.             if (this.musicContainer.GetComponent<ContentSizeFitter>() == null)
  39.             {
  40.                 this.musicContainer.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
  41.                 for (int j = 0; j < this.records.Length; j++)
  42.                 {
  43.                     this.musicContainer.transform.GetChild(j).gameObject.AddComponent<LayoutElement>().preferredHeight = 20f;
  44.                 }
  45.             }
  46.             this.musicButton = this.musicContainer.transform.GetChild(0).gameObject;
  47.             this.newlist = new AudioClip[this.audioNames.Length];
  48.             for (int k = 0; k < this.newlist.Length; k++)
  49.             {
  50.                 base.StartCoroutine(this.GetAudioClip(text + this.audioNames[k], k));
  51.             }
  52.         }
  53.         this.thisSub = base.GetComponent<W_Uboat>();
  54.         if (W_NetworkManager.instance.isServer)
  55.         {
  56.             this.OnFirstUpdate();
  57.         }
  58.     }
  59.  
  60.     // Token: 0x06001E03 RID: 7683 RVA: 0x0001441B File Offset: 0x0001261B
  61.     private LocalRecordplayer getLocal()
  62.     {
  63.         if (this.local == null)
  64.         {
  65.             this.local = UnityEngine.Object.FindObjectOfType<LocalRecordplayer>();
  66.         }
  67.         return this.local;
  68.     }
  69.  
  70.     // Token: 0x06001E04 RID: 7684 RVA: 0x00117194 File Offset: 0x00115394
  71.     public override void instantiateSyncvars(List<SyncBase> list)
  72.     {
  73.         this.b_radioRoom = new SyncedBool(list);
  74.         this.b_radioRoom.editable = true;
  75.         this.b_radioRoom.callback = new Callback(this.radioroomSpeakerOnOff);
  76.         this.b_controlRoom = new SyncedBool(list);
  77.         this.b_controlRoom.editable = true;
  78.         this.b_controlRoom.callback = new Callback(this.controlroomSpeakerOnOff);
  79.         this.b_conningTower = new SyncedBool(list);
  80.         this.b_conningTower.editable = true;
  81.         this.b_conningTower.callback = new Callback(this.conningtowerSpeakerOnOff);
  82.         this.b_outside = new SyncedBool(list);
  83.         this.b_outside.editable = true;
  84.         this.b_outside.callback = new Callback(this.outsideSpeakerOnOff);
  85.         this.playing = new SyncedBool(list);
  86.         this.playing.editable = true;
  87.         this.index = new SyncedInt(list);
  88.         this.index.editable = true;
  89.         this.position = new SyncedFloat(list);
  90.         this.position.editable = true;
  91.         this.insideVolume = new SyncedFloat(list);
  92.         this.insideVolume.editable = true;
  93.         this.insideVolume.callback = new FloatCallback(this.setInsideVolume);
  94.         this.outsideVolume = new SyncedFloat(list);
  95.         this.outsideVolume.editable = true;
  96.         this.outsideVolume.callback = new FloatCallback(this.setOutsideVolume);
  97.         if (W_NetworkManager.instance.isServer)
  98.         {
  99.             this.b_radioRoom.set(true);
  100.             this.b_controlRoom.set(true);
  101.             this.b_conningTower.set(true);
  102.             this.insideVolume.set(1f);
  103.         }
  104.     }
  105.  
  106.     // Token: 0x06001E05 RID: 7685 RVA: 0x00002AE9 File Offset: 0x00000CE9
  107.     public override void instantiateCommands(List<W_ClientCommand> list)
  108.     {
  109.     }
  110.  
  111.     // Token: 0x06001E06 RID: 7686 RVA: 0x00002AE9 File Offset: 0x00000CE9
  112.     public override void instantiateRPCS(List<W_RPC> list)
  113.     {
  114.     }
  115.  
  116.     // Token: 0x06001E07 RID: 7687 RVA: 0x0001443C File Offset: 0x0001263C
  117.     private void setInsideVolume(float old)
  118.     {
  119.         if (this.getLocal() != null)
  120.         {
  121.             this.getLocal().setInsideVolume();
  122.         }
  123.     }
  124.  
  125.     // Token: 0x06001E08 RID: 7688 RVA: 0x00117344 File Offset: 0x00115544
  126.     private void setOutsideVolume(float old)
  127.     {
  128.         if (this.getLocal() != null)
  129.         {
  130.             this.getLocal().setOutsideVolume();
  131.             this.s_outside.volume = ((!this.b_outside.get()) ? 0f : this.outsideVolume.get());
  132.         }
  133.     }
  134.  
  135.     // Token: 0x06001E09 RID: 7689 RVA: 0x00014457 File Offset: 0x00012657
  136.     private void radioroomSpeakerOnOff()
  137.     {
  138.         if (this.getLocal() != null)
  139.         {
  140.             this.getLocal().speakerRadioRoomCallback(this.b_radioRoom.get());
  141.         }
  142.     }
  143.  
  144.     // Token: 0x06001E0A RID: 7690 RVA: 0x0001447D File Offset: 0x0001267D
  145.     private void controlroomSpeakerOnOff()
  146.     {
  147.         if (this.getLocal() != null)
  148.         {
  149.             this.getLocal().speakerControlroomCallback(this.b_controlRoom.get());
  150.         }
  151.     }
  152.  
  153.     // Token: 0x06001E0B RID: 7691 RVA: 0x000144A3 File Offset: 0x000126A3
  154.     private void conningtowerSpeakerOnOff()
  155.     {
  156.         if (this.getLocal() != null)
  157.         {
  158.             this.getLocal().speakerConningtowerCallback(this.b_conningTower.get());
  159.         }
  160.     }
  161.  
  162.     // Token: 0x06001E0C RID: 7692 RVA: 0x00117394 File Offset: 0x00115594
  163.     private void outsideSpeakerOnOff()
  164.     {
  165.         if (this.getLocal() != null)
  166.         {
  167.             this.getLocal().speakerBridgeCallback(this.b_outside.get());
  168.             this.s_outside.volume = ((!this.b_outside.get()) ? 0f : this.outsideVolume.get());
  169.         }
  170.     }
  171.  
  172.     // Token: 0x06001E0D RID: 7693 RVA: 0x001173F0 File Offset: 0x001155F0
  173.     private void Update()
  174.     {
  175.         if (W_Uboat.mySub != null && this.m_playing != this.playing.get())
  176.         {
  177.             this.m_playing = this.playing.get();
  178.             if (this.m_playing)
  179.             {
  180.                 this.play(this.position.get());
  181.             }
  182.             else
  183.             {
  184.                 this.stop();
  185.             }
  186.         }
  187.         if (this.playing.get() && W_NetworkManager.instance.isServer)
  188.         {
  189.             this.position.set(this.position.get() + Time.deltaTime);
  190.             if (!this.s_outside.isPlaying)
  191.             {
  192.                 this.playing.set(false);
  193.             }
  194.         }
  195.     }
  196.  
  197.     // Token: 0x06001E0E RID: 7694 RVA: 0x001174A0 File Offset: 0x001156A0
  198.     private void play(float startPosition)
  199.     {
  200.         this.s_outside.clip = this.records[this.index.get()];
  201.         this.s_outside.time = startPosition;
  202.         this.s_outside.Play();
  203.         this.outsideSpeakerOnOff();
  204.         if (this.thisSub == W_Uboat.mySub)
  205.         {
  206.             this.getLocal().playCallback(startPosition, this.records[this.index.get()]);
  207.             this.radioroomSpeakerOnOff();
  208.             this.controlroomSpeakerOnOff();
  209.             this.conningtowerSpeakerOnOff();
  210.         }
  211.     }
  212.  
  213.     // Token: 0x06001E0F RID: 7695 RVA: 0x000144C9 File Offset: 0x000126C9
  214.     public override void OnFirstUpdate()
  215.     {
  216.         this.radioroomSpeakerOnOff();
  217.         this.controlroomSpeakerOnOff();
  218.         this.conningtowerSpeakerOnOff();
  219.         this.outsideSpeakerOnOff();
  220.         this.setInsideVolume(0f);
  221.         this.setOutsideVolume(0f);
  222.     }
  223.  
  224.     // Token: 0x06001E10 RID: 7696 RVA: 0x000144F9 File Offset: 0x000126F9
  225.     private void stop()
  226.     {
  227.         this.s_outside.Stop();
  228.         if (this.thisSub == W_Uboat.mySub)
  229.         {
  230.             this.getLocal().stopCallback();
  231.         }
  232.     }
  233.  
  234.     // Token: 0x06001E11 RID: 7697 RVA: 0x00014523 File Offset: 0x00012723
  235.     public void playRecord(int index)
  236.     {
  237.         if (index >= 0 && index < this.records.Length)
  238.         {
  239.             this.index.set(index);
  240.             this.position.set(0f);
  241.             this.playing.set(true);
  242.         }
  243.     }
  244.  
  245.     // Token: 0x06001E12 RID: 7698 RVA: 0x0001455C File Offset: 0x0001275C
  246.     public void stopRecord()
  247.     {
  248.         this.playing.set(false);
  249.     }
  250.  
  251.     // Token: 0x06001E13 RID: 7699 RVA: 0x0001456A File Offset: 0x0001276A
  252.     private IEnumerator GetAudioClip(string path, int myIndex)
  253.     {
  254.         WWW www = new WWW("file://" + path);
  255.         yield return www;
  256.         AudioClip audioClip = www.GetAudioClip(false);
  257.         if (audioClip != null)
  258.         {
  259.             this.newlist[myIndex] = audioClip;
  260.             if (myIndex == this.newlist.Length - 1)
  261.             {
  262.                 this.SetRecordList();
  263.             }
  264.         }
  265.         yield break;
  266.     }
  267.  
  268.     // Token: 0x06001E14 RID: 7700 RVA: 0x0011752C File Offset: 0x0011572C
  269.     private void SetRecordList()
  270.     {
  271.         AudioClip[] array = new AudioClip[this.newlist.Length + this.records.Length];
  272.         int num = this.records.Length;
  273.         for (int i = 0; i < this.records.Length; i++)
  274.         {
  275.             array[i] = this.records[i];
  276.         }
  277.         for (int j = 0; j < this.newlist.Length; j++)
  278.         {
  279.             array[j + this.records.Length] = this.newlist[j];
  280.         }
  281.         this.records = array;
  282.         if (this.musicContainer.transform.childCount == num)
  283.         {
  284.             for (int k = num; k < this.records.Length; k++)
  285.             {
  286.                 if (this.records[k] != null)
  287.                 {
  288.                     GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.musicButton, this.musicContainer.transform);
  289.                     gameObject.AddComponent<LayoutElement>().preferredHeight = 20f;
  290.                     gameObject.GetComponentInChildren<Text>().text = this.audioNames[k - num].Substring(0, this.audioNames[k - num].Length - 4);
  291.                     gameObject.GetComponent<RecordPlayButton>().index = k;
  292.                     gameObject.GetComponent<Button>().onClick.AddListener(delegate()
  293.                     {
  294.                         gameObject.GetComponent<RecordPlayButton>().play();
  295.                     });
  296.                 }
  297.             }
  298.         }
  299.     }
  300.  
  301.     // Token: 0x040027E3 RID: 10211
  302.     public AudioClip[] records;
  303.  
  304.     // Token: 0x040027E4 RID: 10212
  305.     public AudioSource s_outside;
  306.  
  307.     // Token: 0x040027E5 RID: 10213
  308.     public SyncedBool b_radioRoom;
  309.  
  310.     // Token: 0x040027E6 RID: 10214
  311.     public SyncedBool b_controlRoom;
  312.  
  313.     // Token: 0x040027E7 RID: 10215
  314.     public SyncedBool b_conningTower;
  315.  
  316.     // Token: 0x040027E8 RID: 10216
  317.     public SyncedBool b_outside;
  318.  
  319.     // Token: 0x040027E9 RID: 10217
  320.     public SyncedBool playing;
  321.  
  322.     // Token: 0x040027EA RID: 10218
  323.     public SyncedFloat position;
  324.  
  325.     // Token: 0x040027EB RID: 10219
  326.     public SyncedInt index;
  327.  
  328.     // Token: 0x040027EC RID: 10220
  329.     public SyncedFloat insideVolume;
  330.  
  331.     // Token: 0x040027ED RID: 10221
  332.     public SyncedFloat outsideVolume;
  333.  
  334.     // Token: 0x040027EE RID: 10222
  335.     private LocalRecordplayer local;
  336.  
  337.     // Token: 0x040027EF RID: 10223
  338.     private W_Uboat thisSub;
  339.  
  340.     // Token: 0x040027F0 RID: 10224
  341.     private bool m_playing;
  342.  
  343.     // Token: 0x040027F1 RID: 10225
  344.     private AudioClip[] newlist;
  345.  
  346.     // Token: 0x040027F2 RID: 10226
  347.     private string[] audioNames;
  348.  
  349.     // Token: 0x040027F3 RID: 10227
  350.     private GameObject musicContainer;
  351.  
  352.     // Token: 0x040027F4 RID: 10228
  353.     private GameObject musicButton;
  354. }
  355.  
Add Comment
Please, Sign In to add comment