immcrab/Lasting-Utilla
Ownership not verified 1
Viewing main at commit a6a25ac430“Add files via upload”· 11 months ago
312 lines · 14 KBRaw on GitHub
// Decompiled with JetBrains decompiler
// Type: Utilla.Behaviours.ConductBoardManager
// Assembly: Utilla, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FDD08D98-E155-49FA-85BC-1930928C3BAA
// Assembly location: C:\Program Files (x86)\Steam\steamapps\common\Gorilla Tag\BepInEx\plugins\Utilla\Utilla.dll
using GorillaNetworking;
using GorillaTag;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;
using Utilla.Tools;
#nullable disable
namespace Utilla.Behaviours;
internal class ConductBoardManager : MonoBehaviour
{
private readonly List<ConductBoardManager.Section> boardContent = new List<ConductBoardManager.Section>();
private ModeSelectButton buttonTemplate;
private GameObject stumpRootObject;
private Transform conductTransform;
private TextMeshPro baseHeaderText;
private TextMeshPro baseBodyText;
private TextMeshPro headerText;
private TextMeshPro bodyText;
private TextMeshPro footerText;
private int currentPage;
private int PageCount => this.boardContent.Count;
public void Start()
{
GTZone startZone = PhotonNetworkController.Instance.StartZone;
UtillaGamemodeSelector gamemodeSelector;
if (!UtillaGamemodeSelector.SelectorLookup.TryGetValue(startZone, out gamemodeSelector))
return;
this.buttonTemplate = gamemodeSelector.Layout.pf_button;
this.stumpRootObject = Array.Find<GameObject>(ZoneManagement.instance.GetZoneData(startZone).rootGameObjects, (Predicate<GameObject>) (gameObject => ((Object) gameObject).name == "TreeRoom"));
this.conductTransform = OVRExtensions.FindChildRecursive(this.stumpRootObject.transform, "code of conduct");
this.baseHeaderText = ((Component) OVRExtensions.FindChildRecursive(this.stumpRootObject.transform, "CodeOfConductHeadingText"))?.GetComponent<TextMeshPro>();
if (Object.op_Equality((Object) this.baseHeaderText, (Object) null))
{
Logging.Warning((object) "COC (Code of Conduct) header text is missing");
}
else
{
GameObject gameObject1 = Object.Instantiate<GameObject>(((Component) this.baseHeaderText).gameObject);
gameObject1.transform.position = this.baseHeaderText.transform.position;
gameObject1.transform.rotation = this.baseHeaderText.transform.rotation;
gameObject1.transform.localScale = this.baseHeaderText.transform.localScale;
this.SanitizeTextObject(gameObject1);
this.headerText = gameObject1.GetComponent<TextMeshPro>();
((TMP_Text) this.headerText).fontSizeMax = ((TMP_Text) this.baseHeaderText).fontSize;
((TMP_Text) this.headerText).enableAutoSizing = true;
((TMP_Text) this.headerText).textWrappingMode = (TextWrappingModes) 0;
GameObject gameObject2 = Object.Instantiate<GameObject>(((Component) this.baseHeaderText).gameObject);
gameObject2.transform.position = this.baseHeaderText.transform.position;
gameObject2.transform.rotation = this.baseHeaderText.transform.rotation;
gameObject2.transform.localScale = this.baseHeaderText.transform.localScale;
this.SanitizeTextObject(gameObject2);
this.footerText = gameObject2.GetComponent<TextMeshPro>();
((TMP_Text) this.footerText).text = "Utilla 1.6.22".ToUpper();
((TMP_Text) this.footerText).enableAutoSizing = false;
((TMP_Text) this.footerText).fontSize = 45f;
((TMP_Text) this.footerText).margin = new Vector4(0.0f, 110f, 0.0f, 0.0f);
((TMP_Text) this.footerText).characterSpacing = -11.5f;
((Behaviour) this.footerText).enabled = true;
this.footerText.renderer.enabled = true;
this.baseBodyText = ((Component) OVRExtensions.FindChildRecursive(this.stumpRootObject.transform, "COCBodyText"))?.GetComponent<TextMeshPro>();
if (Object.op_Equality((Object) this.baseBodyText, (Object) null))
{
Logging.Warning((object) "COC (Code of Conduct) body text is missing");
}
else
{
GameObject gameObject3 = Object.Instantiate<GameObject>(((Component) this.baseBodyText).gameObject);
gameObject3.transform.position = this.baseBodyText.transform.position;
gameObject3.transform.rotation = this.baseBodyText.transform.rotation;
gameObject3.transform.localScale = this.baseBodyText.transform.localScale;
this.SanitizeTextObject(gameObject3);
this.bodyText = gameObject3.GetComponent<TextMeshPro>();
((TMP_Text) this.bodyText).fontSizeMax = ((TMP_Text) this.baseBodyText).fontSize;
((TMP_Text) this.bodyText).fontSizeMin = 0.0f;
((TMP_Text) this.bodyText).enableAutoSizing = true;
((TMP_Text) this.bodyText).margin = new Vector4(0.0f, 0.0f, 0.0f, 36f);
((TMP_Text) this.bodyText).richText = true;
this.boardContent.Insert(0, new ConductBoardManager.Section());
this.CreateButton(-1f, "-->", new Action(this.NextPage));
this.CreateButton(1f, "<--", new Action(this.PrevPage));
this.ShowPage();
this.CheckVersion();
this.DownloadEntries();
}
}
}
private void NextPage()
{
this.currentPage = (this.currentPage + 1) % this.PageCount;
this.ShowPage();
}
private void PrevPage()
{
this.currentPage = this.currentPage <= 0 ? this.PageCount - 1 : this.currentPage - 1;
this.ShowPage();
}
private void ShowPage()
{
if (Object.op_Equality((Object) this.baseHeaderText, (Object) null) || Object.op_Equality((Object) this.baseBodyText, (Object) null))
return;
ConductBoardManager.Section section = this.boardContent.ElementAtOrDefault<ConductBoardManager.Section>(Mathf.Max(0, Mathf.Min(this.currentPage, this.boardContent.Count - 1)));
if (section.UseBaseText)
{
((Behaviour) this.baseHeaderText).enabled = true;
((Behaviour) this.headerText).enabled = false;
((Behaviour) this.baseBodyText).enabled = true;
((Behaviour) this.bodyText).enabled = false;
}
else
{
((Behaviour) this.baseHeaderText).enabled = false;
((Behaviour) this.headerText).enabled = true;
((TMP_Text) this.headerText).text = section.Title;
((Behaviour) this.baseBodyText).enabled = false;
((Behaviour) this.bodyText).enabled = true;
((TMP_Text) this.bodyText).text = section.Body;
}
}
private void CreateButton(float horizontalPosition, string text, Action onButtonPressed = null)
{
// ISSUE: object of a compiler-generated type is created
// ISSUE: variable of a compiler-generated type
ConductBoardManager.\u003C\u003Ec__DisplayClass16_0 cDisplayClass160 = new ConductBoardManager.\u003C\u003Ec__DisplayClass16_0();
// ISSUE: reference to a compiler-generated field
cDisplayClass160.\u003C\u003E4__this = this;
GameObject primitive = GameObject.CreatePrimitive((PrimitiveType) 3);
primitive.transform.parent = this.conductTransform;
primitive.transform.localPosition = new Vector3(horizontalPosition, 0.52f, 0.13f);
primitive.transform.localRotation = Quaternion.Euler(353.5f, 0.0f, 0.0f);
primitive.transform.localScale = new Vector3(0.1427168f, 0.1427168f, 0.1f);
primitive.GetComponent<Renderer>().material = ((GorillaPressableButton) this.buttonTemplate).unpressedMaterial;
primitive.GetComponent<Collider>().isTrigger = true;
UnityLayerExtensions.SetLayer(primitive, (UnityLayer) 18);
TextMeshPro textMeshPro = new GameObject()
{
transform = {
parent = primitive.transform,
localPosition = Vector3.op_Multiply(Vector3.forward, 0.525f),
localRotation = Quaternion.AngleAxis(180f, Vector3.up),
localScale = Vector3.one
}
}.AddComponent<TextMeshPro>();
((TMP_Text) textMeshPro).font = ((Component) this.buttonTemplate)?.GetComponentInChildren<TMP_Text>()?.font ?? ((TMP_Text) this.stumpRootObject.GetComponentInChildren<GorillaComputerTerminal>()?.myScreenText)?.font;
((TMP_Text) textMeshPro).alignment = (TextAlignmentOptions) 514;
((TMP_Text) textMeshPro).characterSpacing = -10f;
((TMP_Text) textMeshPro).overflowMode = (TextOverflowModes) 0;
((TMP_Text) textMeshPro).fontSize = 3f;
((Graphic) textMeshPro).color = new Color(0.1960784f, 0.1960784f, 0.1960784f);
((TMP_Text) textMeshPro).text = text;
// ISSUE: reference to a compiler-generated field
cDisplayClass160.pressableButton = primitive.AddComponent<GorillaPressableButton>();
// ISSUE: reference to a compiler-generated field
cDisplayClass160.pressableButton.buttonRenderer = primitive.GetComponent<MeshRenderer>();
// ISSUE: reference to a compiler-generated field
cDisplayClass160.pressableButton.unpressedMaterial = ((GorillaPressableButton) this.buttonTemplate).unpressedMaterial;
// ISSUE: reference to a compiler-generated field
cDisplayClass160.pressableButton.pressedMaterial = ((GorillaPressableButton) this.buttonTemplate).pressedMaterial;
UnityEvent unityEvent = new UnityEvent();
// ISSUE: method pointer
unityEvent.AddListener(new UnityAction((object) cDisplayClass160, __methodptr(\u003CCreateButton\u003Eb__0)));
// ISSUE: method pointer
unityEvent.AddListener(new UnityAction((object) onButtonPressed, __methodptr(Invoke)));
// ISSUE: reference to a compiler-generated field
cDisplayClass160.pressableButton.onPressButton = unityEvent;
}
public async void CheckVersion()
{
UnityWebRequest webRequest = UnityWebRequest.Get(string.Join('/', "https://raw.githubusercontent.com/developer9998/Utilla-Info/main", "Version.txt"));
UnityWebRequest unityWebRequest = await webRequest.SendWebRequest();
if (webRequest.result != 1)
{
Logging.Fatal((object) ("Version could not be accessed from " + webRequest.url));
Logging.Info((object) webRequest.downloadHandler.error);
webRequest = (UnityWebRequest) null;
}
else
{
Version result1;
if (!Version.TryParse("1.6.22", out result1))
{
webRequest = (UnityWebRequest) null;
}
else
{
Version result2;
if (!Version.TryParse(webRequest.downloadHandler.text, out result2))
webRequest = (UnityWebRequest) null;
else if (!(result2 > result1))
{
webRequest = (UnityWebRequest) null;
}
else
{
((Graphic) this.footerText).color = Color.red;
TextMeshPro footerText = this.footerText;
((TMP_Text) footerText).fontSize = ((TMP_Text) footerText).fontSize * 0.85f;
((TMP_Text) this.footerText).text = $"{"Utilla"} {"1.6.22"} - please update to {result2}".ToUpper();
webRequest = (UnityWebRequest) null;
}
}
}
}
public async void DownloadEntries()
{
UnityWebRequest webRequest = UnityWebRequest.Get(string.Join('/', "https://raw.githubusercontent.com/developer9998/Utilla-Info/main", "ConductBoard", "Entries.json"));
UnityWebRequest unityWebRequest1 = await webRequest.SendWebRequest();
if (webRequest.result != 1)
{
Logging.Fatal((object) ("ModData could not be accessed from " + webRequest.url));
Logging.Info((object) webRequest.downloadHandler.error);
webRequest = (UnityWebRequest) null;
}
else
{
foreach (JObject jobject in ((IEnumerable) JArray.Parse(webRequest.downloadHandler.text)).Cast<JObject>())
{
JObject item = jobject;
Logging.Message((object) ((JToken) item).ToString((Formatting) 1, Array.Empty<JsonConverter>()));
webRequest = UnityWebRequest.Get(string.Join('/', "https://raw.githubusercontent.com/developer9998/Utilla-Info/main", JToken.op_Explicit(item.Property("body").Value)));
UnityWebRequest unityWebRequest2 = await webRequest.SendWebRequest();
if (webRequest.result != 1)
{
Logging.Fatal((object) ("Body text could not be accessed from " + webRequest.url));
Logging.Error((object) webRequest.downloadHandler.error);
}
else
{
this.boardContent.Add(new ConductBoardManager.Section(JToken.op_Explicit(item.Property("title").Value), webRequest.downloadHandler.text));
item = (JObject) null;
}
}
webRequest = (UnityWebRequest) null;
}
}
private IEnumerator ButtonColourUpdate(GorillaPressableButton pressableButton)
{
pressableButton.isOn = true;
pressableButton.UpdateColor();
yield return (object) new WaitForSeconds(pressableButton.debounceTime);
if ((double) pressableButton.touchTime + (double) pressableButton.debounceTime < (double) Time.time)
{
pressableButton.isOn = false;
pressableButton.UpdateColor();
}
}
private void SanitizeTextObject(GameObject gameObject)
{
Type[] source = new Type[3]
{
typeof (PlayFabTitleDataTextDisplay),
typeof (LocalizedText),
typeof (StaticLodGroup)
};
Component[] components = gameObject.GetComponents<Component>();
for (int index = 0; index < components.Length; ++index)
{
Type type = components[index].GetType();
if (((IEnumerable<Type>) source).Contains<Type>(type))
Object.Destroy((Object) components[index]);
}
}
private struct Section
{
public bool UseBaseText;
[TextArea(1, 1)]
public string Title;
[TextArea(12, 32 /*0x20*/)]
public string Body;
public Section()
{
this.Title = (string) null;
this.Body = (string) null;
this.UseBaseText = true;
}
public Section(string title, string body)
{
this.UseBaseText = false;
this.Title = title;
this.Body = body;
}
}
}
Code is shown from GitHub as-is. Linking a repository doesn’t prove that a release file on Canopy was built from it.