-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
103 lines (82 loc) · 3.88 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
91
92
93
94
95
96
97
98
99
100
101
102
103
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Library;
using System.Xml;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
namespace CompanionOverhaul
{
public class Main : MBSubModuleBase
{
private bool isLoaded;
private UpdateBehaviour updateStatus;
public static XmlDocument bodyPropertiesFile;
protected override void OnSubModuleLoad()
{
base.OnSubModuleLoad();
bodyPropertiesFile = new XmlDocument();
bodyPropertiesFile.Load(bodyPropertiesPath);
var harmony = new Harmony("accrcd.companionoverhaul.patch");
harmony.PatchAll();
}
protected override void OnBeforeInitialModuleScreenSetAsRoot()
{
base.OnBeforeInitialModuleScreenSetAsRoot();
if (!isLoaded)
{
InformationManager.DisplayMessage(new InformationMessage("Loaded Companion Overhaul", Color.FromUint(4281584691)));
isLoaded = true;
}
}
protected override void OnGameStart(Game game, IGameStarter gameStarterObject)
{
base.OnGameStart(game, gameStarterObject);
if (Campaign.Current == null)
return;
CampaignGameStarter gameInitializer = (CampaignGameStarter)gameStarterObject;
updateStatus = new UpdateBehaviour();
gameInitializer.AddBehavior(updateStatus);
}
public static void GenerateStaticBodyProperties(string cultureCode, out StaticBodyProperties sbpMin, out StaticBodyProperties sbpMax)
{
ParseKeys(cultureCode, out string min, out string max);
if (min.Length != keyLength || max.Length != keyLength)
throw new FormatException("Keys must be of length " + keyLength);
List<ulong> minKeyParts = new List<ulong>(keyPartCount);
List<ulong> maxKeyParts = new List<ulong>(keyPartCount);
for (int i = 0; i < keyLength; i += keyPartLength)
{
minKeyParts.Add(Convert.ToUInt64(min.Substring(i, keyPartLength), keyPartLength));
maxKeyParts.Add(Convert.ToUInt64(max.Substring(i, keyPartLength), keyPartLength));
}
sbpMin = new StaticBodyProperties(minKeyParts[0], minKeyParts[1], minKeyParts[2], minKeyParts[3],
minKeyParts[4], minKeyParts[5], minKeyParts[6], minKeyParts[7]);
sbpMax = new StaticBodyProperties(maxKeyParts[0], maxKeyParts[1], maxKeyParts[2], maxKeyParts[3],
maxKeyParts[4], maxKeyParts[5], maxKeyParts[6], maxKeyParts[7]);
}
private static void ParseKeys(string cultureCode, out string min, out string max)
{
if (cultureCode == null)
throw new ArgumentNullException("CultureCode is null");
min = max = "";
foreach (XmlNode node in Main.bodyPropertiesFile.DocumentElement.ChildNodes)
if (node.Attributes["id"]?.InnerText == cultureCode)
{
min = node.FirstChild.Attributes["value"]?.InnerText;
max = node.LastChild.Attributes["value"]?.InnerText;
break;
}
if (min == null || max == null)
throw new ArgumentNullException("Returned key is null");
}
private const int keyLength = 128;
private const int keyPartCount = 8;
private const int keyPartLength = keyLength / keyPartCount;
private static readonly string bodyPropertiesPath = @"..\..\Modules\CompanionOverhaul\ModuleData\BodyProperties.xml";
public static readonly Color GREEN = Color.FromUint(4281584691);
public static readonly Color RED = Color.FromUint(4294901760);
}
}