-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
91 lines (80 loc) · 3.32 KB
/
Main.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BTD_Mod_Helper;
using MelonLoader;
using Owoify;
using UnityEngine;
using Main = Owoify.Main;
[assembly: MelonInfo(typeof(Main), ModHelperData.Name, ModHelperData.Version, ModHelperData.RepoOwner)]
[assembly: MelonGame("Ninja Kiwi", "BloonsTD6")]
namespace Owoify
{
public class Main : BloonsTD6Mod
{
private static readonly Dictionary<string, string> Dict = new();
public override void OnEarlyInitialize()
{
var dllLocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var assetBundlesLocation = new DirectoryInfo(dllLocation!).Parent?.FullName
+ "\\BloonsTD6_Data\\StreamingAssets\\aa\\StandaloneWindows64\\Full\\";
var localDataLocation = Directory.GetFiles(assetBundlesLocation, "local_data_assets_all*.bundle")[0];
var localDataBundle = AssetBundle.LoadFromFile(localDataLocation);
var csvEnglish = localDataBundle.LoadAsset("Assets/Data/Languages/English.csv").Cast<TextAsset>();
var key = "";
var chainValues = new List<string>();
foreach (var line in csvEnglish.text.Split('\n'))
{
if (string.IsNullOrEmpty(line)) continue;
if (line.StartsWith("//")) continue;
var tokens = line.Split(new[] { ',' }, 2);
if (tokens.Length == 1) continue;
if (string.IsNullOrEmpty(tokens[0])) continue;
if (string.IsNullOrEmpty(tokens[1])) continue;
var endsWithQuotes = Reverse(tokens[1])[tokens.Length-1].Equals('\"'); // Don't ask me why, strings are being dumb today
if (tokens[1].StartsWith("\""))
{
key = tokens[0];
tokens[1] = tokens[1].TrimStart('"');
if (endsWithQuotes)
{
tokens[1] = tokens[1].TrimEnd('"');
chainValues.Add(tokens[1]);
}
else
{
chainValues.Add(tokens[1]);
continue;
}
}
else if (endsWithQuotes)
{
tokens[1] = tokens[1].TrimEnd('"');
chainValues.Add(tokens[1]);
}
else
{
key = tokens[0];
chainValues.Add(tokens[1]);
}
var valueString = chainValues.Aggregate("", (current, value) => current + (value + "\n"));
valueString = valueString.TrimEnd('\n');
valueString = Owoifier.Owoify(valueString, Owoifier.OwoifyLevel.Uwu);
Dict.Add(key, valueString);
chainValues.Clear();
}
localDataBundle.Unload(true);
}
public static Dictionary<string, string> GetDictionary()
{
return Dict;
}
private static string Reverse( string s)
{
var charArray = s.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
}
}