forked from UnknownX7/ReAction
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfiguration.cs
More file actions
140 lines (122 loc) · 5.11 KB
/
Configuration.cs
File metadata and controls
140 lines (122 loc) · 5.11 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using Dalamud.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace ReAction;
public class Configuration : IPluginConfiguration
{
public class Action
{
public uint ID = 0;
public bool UseAdjustedID = false;
}
public class ActionStackItem
{
public uint ID = 0;
public ActionStackManager.TargetType Target = ActionStackManager.TargetType.Target;
}
public class ActionStack
{
public string Name = string.Empty;
public List<Action> Actions = new();
public List<ActionStackItem> Items = new();
public uint ModifierKeys = 0u;
public bool BlockOriginal = false;
public bool CheckRange = false;
public bool CheckCooldown = false;
}
public class StackSerializer : DefaultSerializationBinder
{
private static readonly Type actionStackType = typeof(ActionStack);
private static readonly Type actionStackItemType = typeof(ActionStackItem);
private static readonly Type actionType = typeof(Action);
private const string actionStackShortName = "s";
private const string actionStackItemShortName = "i";
private const string actionShortName = "a";
private static readonly Dictionary<string, Type> types = new()
{
[actionStackType.FullName!] = actionStackType,
[actionStackShortName] = actionStackType,
[actionStackItemType.FullName!] = actionStackItemType,
[actionStackItemShortName] = actionStackItemType,
[actionType.FullName!] = actionType,
[actionShortName] = actionType
};
private static readonly Dictionary<Type, string> typeNames = new()
{
[actionStackType] = actionStackShortName,
[actionStackItemType] = actionStackItemShortName,
[actionType] = actionShortName
};
public override Type BindToType(string assemblyName, string typeName)
=> types.TryGetValue(typeName, out var t) ? t : base.BindToType(assemblyName, typeName);
public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
{
assemblyName = null;
if (typeNames.TryGetValue(serializedType, out var name))
typeName = name;
else
base.BindToName(serializedType, out assemblyName, out typeName);
}
}
public int Version { get; set; }
public List<ActionStack> ActionStacks = new();
public bool EnableEnhancedAutoFaceTarget = false;
public bool EnableAutoDismount = false;
public bool EnableGroundTargetQueuing = false;
public bool EnableInstantGroundTarget = false;
public bool EnableAutoCastCancel = false;
public bool EnableAutoTarget = false;
public bool EnableAutoChangeTarget = false;
public bool EnableSpellAutoAttacks = false;
public bool EnableCameraRelativeDashes = false;
public bool EnableNormalBackwardDashes = false;
public bool EnableQueuingMore = false;
public bool EnableFPSAlignment = false;
public bool EnableAutoRefocusTarget = false;
public bool EnableDecomboMeditation = false;
public bool EnableDecomboBunshin = false;
public bool EnableDecomboWanderersMinuet = false;
public bool EnableDecomboEarthlyStar = false;
public bool EnableDecomboLiturgy = false;
public void Initialize() { }
public void Save() => DalamudApi.PluginInterface.SavePluginConfig(this);
private static readonly StackSerializer serializer = new ();
public static string ExportActionStack(ActionStack stack)
=> CompressString(JsonConvert.SerializeObject(stack, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
SerializationBinder = serializer
}));
public static ActionStack ImportActionStack(string import)
=> JsonConvert.DeserializeObject<ActionStack>(DecompressString(import), new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
SerializationBinder = serializer
});
private const string exportPrefix = "RE_";
public static string CompressString(string s)
{
var bytes = Encoding.UTF8.GetBytes(s);
using var ms = new MemoryStream();
using (var gs = new GZipStream(ms, CompressionMode.Compress))
gs.Write(bytes, 0, bytes.Length);
return exportPrefix + Convert.ToBase64String(ms.ToArray());
}
public static string DecompressString(string s)
{
if (!s.StartsWith(exportPrefix))
throw new ApplicationException("This is not a ReAction export.");
var data = Convert.FromBase64String(s);
using var ms = new MemoryStream(data);
using var gs = new GZipStream(ms, CompressionMode.Decompress);
using var r = new StreamReader(gs);
return r.ReadToEnd();
}
}