-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlternativeAscension.cs
145 lines (129 loc) · 5.14 KB
/
AlternativeAscension.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using HarmonyLib.Tools;
using NeedyXML;
using NGO;
using ngov3;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml.Serialization;
using UniRx;
using UnityEngine;
using NeedyEnums;
using Stream = NeedyXML.Stream;
using System.Text.RegularExpressions;
using Cysharp.Threading.Tasks;
using System.Threading;
using System.Reflection.Emit;
using Thread = NeedyXML.Thread;
using Component = UnityEngine.Component;
using TMPro;
using UnityEngine.AddressableAssets;
using ngov3.Effect;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using DG.Tweening;
using UnityEngine.Rendering;
using Extensions;
using UnityEngine.Audio;
using UnityEngine.AddressableAssets.ResourceLocators;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace AlternativeAscension
{
[BepInPlugin(id, modName, ver)]
[HarmonyDebug]
public class AltAscMod : BaseUnityPlugin
{
public const string id = "nso.altascension";
public const string modName = "Needy Streamer Overload: Alternative Ascension";
public const string ver = "1.0.0";
public const string assetdec = "NSOAltAsc";
public static string FILEPATH;
public const int SLEEPS_BEFORE_SLEEPY = 6;
public const bool SHOWANIMSTREAM = false;
private static readonly Harmony harmony = new Harmony(id);
public static ManualLogSource log;
public static ModData DATA;
private static void FillXMLData()
{
TextAsset stringXML = Addressables.LoadAssetAsync<TextAsset>("AltAsc_strings.xml").WaitForCompletion();
string asmname = Assembly.GetAssembly(typeof(AltAscMod)).GetName().Name + ".dll";
FILEPATH = Assembly.GetAssembly(typeof(AltAscMod)).Location.Replace(asmname, "");
System.Xml.Serialization.XmlSerializer serializer = new XmlSerializer(typeof(ModData));
using (StringReader sr = new StringReader(stringXML.text))
{
DATA = (ModData)serializer.Deserialize(sr);
}
}
private void SetCatalogPath()
{
Assembly asm = this.GetType().Assembly;
string catalogPath = new Uri(asm.CodeBase).LocalPath.Replace(asm.GetName().Name + ".dll", "catalog.json");
string assetPath = new Uri(asm.CodeBase).LocalPath.Replace(asm.GetName().Name + ".dll", "altasc_assets.bundle");
bool generateCatalog = true;
if (File.Exists(catalogPath))
{
try
{
AsyncOperationHandle<IResourceLocator> loadCatalogOperation = Addressables.LoadContentCatalogAsync(catalogPath);
loadCatalogOperation.WaitForCompletion();
if (loadCatalogOperation.Result == null) throw new Exception("Failed to load catalog!");
generateCatalog = false;
}
catch (Exception e)
{
log.LogMessage("Couldn't find mod addressable catalog, generating...");
}
}
if (generateCatalog)
{
AltAscMod.log.LogMessage("Fresh install, setting asset path!");
string catalogInternalAddress = Assembly.GetExecutingAssembly().GetManifestResourceNames().ToList().Find(s => s.Contains("catalog.json"));
string catalogData;
using (StreamReader sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(catalogInternalAddress)))
{
catalogData = sr.ReadToEndAsync().GetAwaiter().GetResult();
catalogData = catalogData.Replace("[NMO_ASSETS_DIRECTORY]", assetPath).Replace(@"\",@"/");
log.LogMessage(catalogPath);
}
using (StreamWriter sw = new StreamWriter(catalogPath))
{
sw.Write(catalogData);
}
Addressables.LoadContentCatalogAsync(catalogPath).WaitForCompletion();
log.LogMessage("Path is " + catalogPath);
}
AltAscMod.log.LogMessage("Loaded catalog!");
}
private async void Awake()
{
// Plugin startup logic
HarmonyFileLog.Enabled = true;
log = Logger;
SetCatalogPath();
try
{
FillXMLData();
harmony.PatchAll();
//foreach (MethodBase patch in harmony.GetPatchedMethods())
//{
// log.LogMessage($"{patch.DeclaringType}.{patch.Name}");
//}
AltAscMod.log.LogMessage($"Patched {harmony.GetPatchedMethods().Count()} methods...");
log.LogMessage("Patched NSO, press to continue...");
//Console.ReadKey();
}
catch (Exception e)
{
log.LogMessage("Failed to patch NSO, press to quit");
log.LogWarning(e);
Console.ReadKey();
System.Environment.Exit(0);
}
}
}
}