Files
SourMesen 40335ce735 UI: Update to Avalonia 12, .NET 10 and replace ReactiveUI with MVVM community toolkit (#142)
Also fixes DX11.0 support (for Win7 PCs that aren't fully updated), which stopped working after the recent variable refresh rate changes
2026-07-03 16:04:42 +09:00

69 lines
1.9 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using Mesen.Interop;
using Mesen.Utilities;
using Mesen.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace Mesen.Config
{
public partial class GameConfig : BaseConfig<GameConfig>
{
[ObservableProperty] public partial UInt32 DipSwitches { get; set; } = 0;
[ObservableProperty] public partial bool OverrideOverscan { get; set; } = false;
[ObservableProperty] public partial OverscanConfig Overscan { get; set; } = new();
public void ApplyConfig()
{
ConfigApi.SetGameConfig(new InteropGameConfig() {
DipSwitches = DipSwitches,
OverrideOverscan = OverrideOverscan,
Overscan = Overscan.ToInterop()
});
}
public static GameConfig LoadGameConfig(RomInfo romInfo)
{
string path = Path.Combine(ConfigManager.GameConfigFolder, romInfo.GetRomName() + ".json");
GameConfig? cfg;
if(File.Exists(path)) {
string? fileData = FileHelper.ReadAllText(path);
if(fileData != null) {
try {
cfg = (GameConfig?)JsonSerializer.Deserialize(fileData, typeof(GameConfig), MesenSerializerContext.Default);
if(cfg != null) {
return cfg;
}
} catch { }
}
}
cfg = new GameConfig();
cfg.DipSwitches = DipSwitchDatabase.GetGameDipswitches(romInfo.DipSwitches).DefaultDipSwitches;
return cfg;
}
public void Save()
{
string romName = MainWindowViewModel.Instance.RomInfo.GetRomName();
string path = Path.Combine(ConfigManager.GameConfigFolder, romName + ".json");
FileHelper.WriteAllText(path, JsonSerializer.Serialize(this, typeof(GameConfig), MesenSerializerContext.Default));
}
}
public struct InteropGameConfig
{
public UInt32 DipSwitches;
[MarshalAs(UnmanagedType.I1)] public bool OverrideOverscan;
public InteropOverscanDimensions Overscan;
}
}