-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModCreator.cs
72 lines (68 loc) · 2.89 KB
/
ModCreator.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
using System.IO;
namespace DarkestDungeonRandomizer;
static class ModCreator
{
/// <summary>
/// Creates a mod on disk and returns the directory it's contained within.
/// If the mod already exists on disk, it will be deleted.
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
public static DirectoryInfo CreateMod(MainViewModel options)
{
var uuid = GetRandomizerUUID(options);
var modDirectory = Path.Combine(options.DDPath, "mods", $"Randomizer {uuid}");
if (Directory.Exists(modDirectory))
{
Directory.Delete(modDirectory, true);
}
var dir = Directory.CreateDirectory(modDirectory);
File.WriteAllText(Path.Combine(dir.FullName, "project.xml"),
$@"<?xml version=""1.0"" encoding=""utf-8""?>
<project>
<PreviewIconFile></PreviewIconFile>
<ItemDescriptionShort/>
<ModDataPath>{dir.FullName}</ModDataPath>
<Title>Randomizer [Tag {uuid} | Seed {options.Seed}]</Title>
<Language>english</Language>
<UpdateDetails/>
<Visibility>hidden</Visibility>
<UploadMode>dont_submit</UploadMode>
<VersionMajor>0</VersionMajor>
<VersionMinor>0</VersionMinor>
<TargetBuild>0</TargetBuild>
<Tags></Tags>
<ItemDescription>If playing the same randomizer as another player, make sure that the IDs match on both clients.</ItemDescription>
<PublishedFileId></PublishedFileId>
</project>");
return dir;
}
public static string GetRandomizerUUID(MainViewModel options)
{
int addin =
(options.RandomizeCurioEffects ? 1 : 0) +
(options.RandomizeCurioInteractions ? 1 << 1 : 0) +
(options.RandomizeCurioRegions ? 1 << 2 : 0) +
(options.IncludeShamblerAltar ? 1 << 3 : 0) +
(options.IncludeStoryCurios ? 1 << 4 : 0) +
(options.RandomizeMonsters ? 1 << 5 : 0) +
(options.RandomizeBosses ? 1 << 6 : 0) +
((int)(options.RandomizeHeroStats * 4) << 7) + /* 3 bits */
(options.RandomizeCampingSkills ? 1 << 10 : 0);
return addin.ToString("x") + options.Seed.ToString("x8");
}
public static void PopulateRandomizerOptionsFromUUID(MainViewModel model, string tag)
{
model.Seed = int.Parse(tag[^8..], System.Globalization.NumberStyles.HexNumber);
var addin = int.Parse(tag[..^8], System.Globalization.NumberStyles.HexNumber);
model.RandomizeCurioEffects = (addin & 1) != 0;
model.RandomizeCurioInteractions = (addin & (1 << 1)) != 0;
model.RandomizeCurioRegions = (addin & (1 << 2)) != 0;
model.IncludeShamblerAltar = (addin & (1 << 3)) != 0;
model.IncludeStoryCurios = (addin & (1 << 4)) != 0;
model.RandomizeMonsters = (addin & (1 << 5)) != 0;
model.RandomizeBosses = (addin & (1 << 6)) != 0;
model.RandomizeHeroStats = ((addin & (7 << 7)) >> 7) / 4d;
model.RandomizeCampingSkills = (addin & (1 << 10)) != 0;
}
}