unsafe private void Save() { var buffer = new byte[Marshal.SizeOf(typeof(TweakBufferType))]; using (var stream = new FileStream(path + ".bin", FileMode.Create)) { fixed(byte *ptr = &buffer[0]) { TweakBufferType *tweakBuffer = (TweakBufferType *)ptr; tweakBuffer[0] = mem.Data; } stream.Write(buffer, 0, buffer.Length); } using (var stream = new FileStream(path + ".h", FileMode.Create)) { using (var writer = new StreamWriter(stream)) { writer.Write("#pragma once\n\n"); writer.Write("#define " + path.ToUpper() + "_SIZE " + buffer.Length + "\n\n"); writer.Write("#pragma data_seg(\"." + path + "\")\n"); writer.Write("static unsigned char " + path + "[] = {\n\t"); foreach (var b in buffer) { writer.Write("" + b + ", "); } writer.Write("\n};\n"); } } }
unsafe public DataViewModel(string path) { this.path = path; mem = new SharedMemory <TweakBufferType>(path, Marshal.SizeOf(typeof(TweakBufferType))); mem.Open(); using (var stream = new FileStream(path + ".bin", FileMode.Open)) { var buffer = new byte[Marshal.SizeOf(typeof(TweakBufferType))]; stream.Read(buffer, 0, buffer.Length); fixed(byte *ptr = &buffer[0]) { TweakBufferType *tweakBuffer = (TweakBufferType *)ptr; mem.Data = tweakBuffer[0]; } } timer = new Timer(); timer.Interval = 1000; timer.Elapsed += timer_Elapsed; timer.Start(); }