-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStructs.cs
149 lines (114 loc) · 4.62 KB
/
Structs.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
145
146
147
148
149
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using IngameOverlay.JsonConverter;
using Newtonsoft.Json;
namespace IngameOverlay
{
interface IOverlayConfig
{
void WriteTo(BinaryWriter bw);
}
public class GlobalConfig:IOverlayConfig
{
private readonly MemoryMappedFile _globalConfigMmf = MemoryMappedFile.CreateOrOpen(@"Local\rtpp-overlay-global-config", 65);
public string GlyphRanges { get; set; } = "Default"; //64b
private readonly byte[] _glyphRangesBuffer = new byte[128];
public void WriteTo(BinaryWriter bw)
{
bw.Write(false);//WasChanged(Placeholder)
bw.Write(new byte[3] { 0, 0, 0 });//Padding
int size = Encoding.UTF8.GetBytes(GlyphRanges, 0, GlyphRanges.Length, _glyphRangesBuffer,0);
_glyphRangesBuffer[size] = 0;
bw.Write(_glyphRangesBuffer, 0, 64);
bw.Seek(0,SeekOrigin.Begin);
bw.Write(true);//WasChanged
}
public void WriteToMmf()
{
this.WriteTo(_globalConfigMmf);
}
}
public class OverlayConfigItem:IOverlayConfig
{
public string Mmf { get; set; } = "rtpp-pp"; //128b
public string FontPath { get; set; } = ""; //512b
public int[] Position { get; set; } = new[] {0, 0}; //x,y 2i
[JsonConverter(typeof(RgbaStringJsonConverter))]
public float[] TextRgba { get; set; } = new[] {1f, 1f, 1f, 1f}; //4f
[JsonConverter(typeof(RgbaStringJsonConverter))]
public float[] BackgroundRgba { get; set; } = new[] { 0.06f,0.06f,0.06f,0.70f}; //4f
[JsonConverter(typeof(RgbaStringJsonConverter))]
public float[] BorderRgba { get; set; } = new[] {0.43f,0.43f,0.5f,0.5f }; //4f
public float[] Pivot { get; set; } = new[] {0f,0f}; //2f
public float FontSize { get; set; } = 10.0f;
public float FontScale { get; set; } = 1.0f;
private IList<string> _visibleStatus = new List<string>() {"Playing", "Rank"};
public delegate void VisibilityChangedEvt(IList<string> list);
public event VisibilityChangedEvt VisibilityChanged;
public bool BreakTime { get; set; } = false;
[JsonConverter(typeof(VisibleStatusJsonConverter))]
public IList<string> VisibleStatus
{
get => _visibleStatus;
set
{
_visibleStatus = value;
VisibilityChanged?.Invoke(_visibleStatus);
}
}
[JsonIgnore]
public bool Visibility { get; set; } = true;
private readonly byte[] _stringBuffer = new byte[512];
public void WriteTo(BinaryWriter bw)
{
int size = 0;
size = Encoding.UTF8.GetBytes(Mmf, 0, Mmf.Length, _stringBuffer, 0);
_stringBuffer[size] = 0;
bw.Write(_stringBuffer, 0, 128);
size = Encoding.UTF8.GetBytes(FontPath, 0, FontPath.Length, _stringBuffer, 0);
_stringBuffer[size] = 0;
bw.Write(_stringBuffer, 0, 512);
bw.Write(Position[0]);
bw.Write(Position[1]);
WriteFloatArray(TextRgba, bw);
WriteFloatArray(BackgroundRgba, bw);
WriteFloatArray(BorderRgba, bw);
WriteFloatArray(Pivot, bw);
bw.Write((int)FontSize);
bw.Write(FontScale);
bw.Write(Visibility);
bw.Write(new byte[3] { 0, 0, 0 });//Padding
}
private void WriteFloatArray(float[] arr, BinaryWriter bw)
{
Array.ForEach(arr, item => bw.Write(item));
}
};
public class OverlayConfigs:IOverlayConfig
{
public List<OverlayConfigItem> OverlayConfigItems { get; set; } = new List<OverlayConfigItem>();
private readonly MemoryMappedFile _ovetlayConfigsMmf = MemoryMappedFile.CreateOrOpen(@"Local\rtpp-overlay-configs", 65535);
private bool _needUpdateFonts = true;
public void WriteTo(BinaryWriter bw)
{
bw.Write(false);//WasChanged(Placeholder)
bw.Write(new byte[3] { 0, 0, 0 });//Padding
bw.Write(OverlayConfigItems.Count);
foreach (var item in OverlayConfigItems)
item.WriteTo(bw);
bw.Seek(0, SeekOrigin.Begin);
bw.Write(_needUpdateFonts);//WasChanged
}
public void WriteToMmf(bool updateFonts=true)
{
_needUpdateFonts = updateFonts;
this.WriteTo(_ovetlayConfigsMmf);
}
};
}