This repository was archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAstralUdonViewer.cs
70 lines (55 loc) · 2.35 KB
/
AstralUdonViewer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using MelonLoader;
using System;
using System.IO;
using System.Linq;
using UnityEngine.SceneManagement;
using VRC.Udon;
[assembly: MelonInfo(typeof(Astrum.AstralUdonViewer), nameof(Astrum.AstralUdonViewer), "0.3.0", downloadLink: "github.com/Astrum-Project/" + nameof(Astrum.AstralUdonViewer))]
[assembly: MelonColor(ConsoleColor.DarkMagenta)]
namespace Astrum
{
public partial class AstralUdonViewer : MelonMod
{
private const string basePath = "UserData/AstralUdonDecompiler";
public override void OnApplicationStart()
{
if (!Directory.Exists(basePath))
Directory.CreateDirectory(basePath);
}
public override void OnSceneWasLoaded(int index, string name)
{
if (index == -1)
MelonCoroutines.Start(DissassembleAll());
}
public static System.Collections.IEnumerator DissassembleAll()
{
string path = $"{basePath}/{RemoveInvalid(SceneManager.GetActiveScene().name)}";
if (Directory.Exists(path)) yield break;
else Directory.CreateDirectory(path);
while (VRC.SDKBase.Networking.LocalPlayer is null)
yield return null;
// todo: change this to All
UdonBehaviour[] behaviours = UnityEngine.Object.FindObjectsOfType<UdonBehaviour>()
.GroupBy(x => x.Pointer)
.Select(x => x.FirstOrDefault())
.ToArray();
if (behaviours.Length == 0) yield break;
AstralCore.Logger.Notif($"[UdonViewer] Disassembling {behaviours.Length} UdonBehaviours");
foreach (UdonBehaviour behaviour in behaviours)
{
if (behaviour?._program is null) continue;
AstralCore.Logger.Trace($"Disassembling {behaviour.name}");
MelonCoroutines.Start(Disassembler.DisassembleProgram($"{path}/{RemoveInvalid(behaviour.name)}.uasm", behaviour));
yield return null;
}
// this is a lie! it just started the last behaviour, not finished at all
AstralCore.Logger.Notif("[UdonViewer] Finished!");
}
private static string RemoveInvalid(string str)
{
foreach (char c in Path.GetInvalidFileNameChars())
str = str.Replace(c, '_');
return str;
}
}
}