Skip to content

Commit

Permalink
endpoint configuration template
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Aug 6, 2022
1 parent 7462928 commit 516fa33
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 192 deletions.
4 changes: 2 additions & 2 deletions FModel/Creator/Bases/MV/BasePandaIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ private SKColor[] GetRarityBackground(ERewardRarity rarity)
return;

var x = 450f;
var y = Height / 2 - DisplayNamePaint.TextSize / 4;
while (DisplayNamePaint.MeasureText(DisplayName) > Width - x)
while (DisplayNamePaint.MeasureText(DisplayName) > Width - x / 1.25)
{
DisplayNamePaint.TextSize -= 1;
}

var y = Height / 2 - DisplayNamePaint.TextSize / 4;
foreach (var a in DisplayName.Select(character => character.ToString()))
{
c.DrawText(a, x, y, DisplayNamePaint);
Expand Down
6 changes: 6 additions & 0 deletions FModel/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@ public enum EIconStyle
// [Description("Community")]
// CommunityMade
}

public enum EEndpointType
{
Aes,
Mapping
}
33 changes: 33 additions & 0 deletions FModel/Framework/FEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace FModel.Framework;

public class FEndpoint : ViewModel
{
private string _url;
public string Url
{
get => _url;
set => SetProperty(ref _url, value);
}

private bool _overwrite;
public bool Overwrite
{
get => _overwrite;
set => SetProperty(ref _overwrite, value);
}

private string _path;
public string Path
{
get => _path;
set => SetProperty(ref _path, value);
}

public bool IsEnabled => !string.IsNullOrWhiteSpace(_url); // change this later

public FEndpoint() {}
public FEndpoint(string url)
{
Url = url;
}
}
59 changes: 45 additions & 14 deletions FModel/Settings/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public static void Delete()
if (File.Exists(FilePath)) File.Delete(FilePath);
}

public static bool TryGetGameCustomEndpoint(FGame game, EEndpointType type, out FEndpoint endpoint)
{
endpoint = null;
if (!Default.CustomEndpoints.TryGetValue(game, out var endpoints))
return false;

endpoint = endpoints[(int) type];
return endpoint.IsEnabled;
}

private bool _showChangelog = true;
public bool ShowChangelog
{
Expand Down Expand Up @@ -95,20 +105,6 @@ public string GameDirectory
set => SetProperty(ref _gameDirectory, value);
}

private bool _overwriteMapping;
public bool OverwriteMapping
{
get => _overwriteMapping;
set => SetProperty(ref _overwriteMapping, value);
}

private string _mappingFilePath;
public string MappingFilePath
{
get => _mappingFilePath;
set => SetProperty(ref _mappingFilePath, value);
}

private int _lastOpenedSettingTab;
public int LastOpenedSettingTab
{
Expand Down Expand Up @@ -382,6 +378,41 @@ public IDictionary<FGame, Dictionary<string, bool>> OverridedOptions
set => SetProperty(ref _overridedOptions, value);
}

private IDictionary<FGame, FEndpoint[]> _customEndpoints = new Dictionary<FGame, FEndpoint[]>
{
{FGame.Unknown, new FEndpoint[]{new (), new ()}},
{
FGame.FortniteGame, new []
{
new FEndpoint("https://fortnitecentral.gmatrixgames.ga/api/v1/aes"),
new FEndpoint("https://fortnitecentral.gmatrixgames.ga/api/v1/mappings")
}
},
{FGame.ShooterGame, new FEndpoint[]{new (), new ()}},
{FGame.DeadByDaylight, new FEndpoint[]{new (), new ()}},
{FGame.OakGame, new FEndpoint[]{new (), new ()}},
{FGame.Dungeons, new FEndpoint[]{new (), new ()}},
{FGame.WorldExplorers, new FEndpoint[]{new (), new ()}},
{FGame.g3, new FEndpoint[]{new (), new ()}},
{FGame.StateOfDecay2, new FEndpoint[]{new (), new ()}},
{FGame.Prospect, new FEndpoint[]{new (), new ()}},
{FGame.Indiana, new FEndpoint[]{new (), new ()}},
{FGame.RogueCompany, new FEndpoint[]{new (), new ()}},
{FGame.SwGame, new FEndpoint[]{new (), new ()}},
{FGame.Platform, new FEndpoint[]{new (), new ()}},
{FGame.BendGame, new FEndpoint[]{new (), new ()}},
{FGame.TslGame, new FEndpoint[]{new (), new ()}},
{FGame.PortalWars, new FEndpoint[]{new (), new ()}},
{FGame.Gameface, new FEndpoint[]{new (), new ()}},
{FGame.Athena, new FEndpoint[]{new (), new ()}},
{FGame.PandaGame, new FEndpoint[]{new (), new ()}}
};
public IDictionary<FGame, FEndpoint[]> CustomEndpoints
{
get => _customEndpoints;
set => SetProperty(ref _customEndpoints, value);
}

private IDictionary<FGame, IList<CustomDirectory>> _customDirectories = new Dictionary<FGame, IList<CustomDirectory>>
{
{FGame.Unknown, new List<CustomDirectory>()},
Expand Down
6 changes: 4 additions & 2 deletions FModel/ViewModels/ApiEndpointViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public class ApiEndpointViewModel
public ValorantApiEndpoint ValorantApi { get; }
public FortniteCentralApiEndpoint CentralApi { get; }
public EpicApiEndpoint EpicApi { get; }
public FModelApi FModelApi { get; }
public FModelApiEndpoint FModelApi { get; }
public DynamicApiEndpoint DynamicApi { get; }

public ApiEndpointViewModel()
{
FortniteApi = new FortniteApiEndpoint(_client);
ValorantApi = new ValorantApiEndpoint(_client);
CentralApi = new FortniteCentralApiEndpoint(_client);
EpicApi = new EpicApiEndpoint(_client);
FModelApi = new FModelApi(_client);
FModelApi = new FModelApiEndpoint(_client);
DynamicApi = new DynamicApiEndpoint(_client);
}

public async Task DownloadFileAsync(string fileLink, string installationPath)
Expand Down
47 changes: 47 additions & 0 deletions FModel/ViewModels/ApiEndpoints/DynamicApiEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Threading;
using System.Threading.Tasks;
using FModel.Framework;
using FModel.ViewModels.ApiEndpoints.Models;
using RestSharp;
using Serilog;

namespace FModel.ViewModels.ApiEndpoints;

public class DynamicApiEndpoint : AbstractApiProvider
{
public DynamicApiEndpoint(RestClient client) : base(client)
{
}

public async Task<AesResponse> GetAesKeysAsync(CancellationToken token, string url)
{
var request = new FRestRequest(url)
{
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
};
var response = await _client.ExecuteAsync<AesResponse>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
return response.Data;
}

public AesResponse GetAesKeys(CancellationToken token, string url)
{
return GetAesKeysAsync(token, url).GetAwaiter().GetResult();
}

public async Task<MappingsResponse[]> GetMappingsAsync(CancellationToken token, string url)
{
var request = new FRestRequest(url)
{
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
};
var response = await _client.ExecuteAsync<MappingsResponse[]>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
return response.Data;
}

public MappingsResponse[] GetMappings(CancellationToken token, string url)
{
return GetMappingsAsync(token, url).GetAwaiter().GetResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace FModel.ViewModels.ApiEndpoints;

public class FModelApi : AbstractApiProvider
public class FModelApiEndpoint : AbstractApiProvider
{
private News _news;
private Info _infos;
Expand All @@ -29,7 +29,7 @@ public class FModelApi : AbstractApiProvider
private readonly IDictionary<string, CommunityDesign> _communityDesigns = new Dictionary<string, CommunityDesign>();
private ApplicationViewModel _applicationView => ApplicationService.ApplicationView;

public FModelApi(RestClient client) : base(client)
public FModelApiEndpoint(RestClient client) : base(client)
{
}

Expand Down
33 changes: 0 additions & 33 deletions FModel/ViewModels/ApiEndpoints/FortniteCentralApiEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using FModel.Framework;
using FModel.ViewModels.ApiEndpoints.Models;
using RestSharp;
using Serilog;

Expand All @@ -14,38 +13,6 @@ public FortniteCentralApiEndpoint(RestClient client) : base(client)
{
}

public async Task<AesResponse> GetAesKeysAsync(CancellationToken token)
{
var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/aes")
{
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
};
var response = await _client.ExecuteAsync<AesResponse>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
return response.Data;
}

public AesResponse GetAesKeys(CancellationToken token)
{
return GetAesKeysAsync(token).GetAwaiter().GetResult();
}

public async Task<MappingsResponse[]> GetMappingsAsync(CancellationToken token)
{
var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/mappings")
{
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
};
var response = await _client.ExecuteAsync<MappingsResponse[]>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
return response.Data;
}

public MappingsResponse[] GetMappings(CancellationToken token)
{
return GetMappingsAsync(token).GetAwaiter().GetResult();
}

public async Task<Dictionary<string, Dictionary<string, string>>> GetHotfixesAsync(CancellationToken token, string language = "en")
{
var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/hotfixes")
Expand Down
29 changes: 16 additions & 13 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,18 @@ public void ClearProvider()

public async Task RefreshAes()
{
if (Game == FGame.FortniteGame) // game directory dependent, we don't have the provider game name yet since we don't have aes keys
// game directory dependent, we don't have the provider game name yet since we don't have aes keys
// except when this comes from the AES Manager
if (!UserSettings.TryGetGameCustomEndpoint(Game, EEndpointType.Aes, out var endpoint))
return;

await _threadWorkerView.Begin(cancellationToken =>
{
await _threadWorkerView.Begin(cancellationToken =>
{
var aes = _apiEndpointView.CentralApi.GetAesKeys(cancellationToken);
if (aes?.MainKey == null && aes?.DynamicKeys == null && aes?.Version == null) return;
var aes = _apiEndpointView.DynamicApi.GetAesKeys(cancellationToken, endpoint.Url);
if (aes?.MainKey == null && aes?.DynamicKeys == null) return;
UserSettings.Default.AesKeys[Game] = aes;
});
}
UserSettings.Default.AesKeys[Game] = aes;
});
}

public async Task InitInformation()
Expand All @@ -321,20 +323,21 @@ await _threadWorkerView.Begin(cancellationToken =>

public async Task InitBenMappings()
{
if (Game != FGame.FortniteGame) return;
if (!UserSettings.TryGetGameCustomEndpoint(Game, EEndpointType.Mapping, out var endpoint))
return;

await _threadWorkerView.Begin(cancellationToken =>
{
if (UserSettings.Default.OverwriteMapping && File.Exists(UserSettings.Default.MappingFilePath))
if (endpoint.Overwrite && File.Exists(endpoint.Path))
{
Provider.MappingsContainer = new FileUsmapTypeMappingsProvider(UserSettings.Default.MappingFilePath);
Provider.MappingsContainer = new FileUsmapTypeMappingsProvider(endpoint.Path);
FLogger.AppendInformation();
FLogger.AppendText($"Mappings pulled from '{UserSettings.Default.MappingFilePath.SubstringAfterLast("\\")}'", Constants.WHITE, true);
FLogger.AppendText($"Mappings pulled from '{endpoint.Path.SubstringAfterLast("\\")}'", Constants.WHITE, true);
}
else
{
var mappingsFolder = Path.Combine(UserSettings.Default.OutputDirectory, ".data");
var mappings = _apiEndpointView.CentralApi.GetMappings(cancellationToken);
var mappings = _apiEndpointView.DynamicApi.GetMappings(cancellationToken, endpoint.Url);
if (mappings is { Length: > 0 })
{
foreach (var mapping in mappings)
Expand Down
10 changes: 10 additions & 0 deletions FModel/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public ECompressedAudio SelectedCompressedAudio
set => SetProperty(ref _selectedCompressedAudio, value);
}

private string _currentMappingFile;
public string CurrentMappingFile // only used so that it updates the UI
{
get => _currentMappingFile;
set => SetProperty(ref _currentMappingFile, value);
}

private EIconStyle _selectedCosmeticStyle;
public EIconStyle SelectedCosmeticStyle
{
Expand Down Expand Up @@ -191,6 +198,9 @@ public void Initialize()
_optionsSnapshot = UserSettings.Default.OverridedOptions[_game];
}

if (UserSettings.TryGetGameCustomEndpoint(_game, EEndpointType.Mapping, out var endpoint))
CurrentMappingFile = endpoint.Path;

_assetLanguageSnapshot = UserSettings.Default.AssetLanguage;
_compressedAudioSnapshot = UserSettings.Default.CompressedAudioMode;
_cosmeticStyleSnapshot = UserSettings.Default.CosmeticStyle;
Expand Down
17 changes: 7 additions & 10 deletions FModel/Views/AesManager.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,13 @@
HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="OK" Click="OnClick" />
<Button Grid.Column="2" MinWidth="78" Margin="0 0 12 0" IsDefault="False" IsCancel="False"
HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="Refresh" Click="OnRefreshAes">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding CUE4Parse.Game}" Value="{x:Static local:FGame.FortniteGame}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<Button.Visibility>
<!-- if aes custom endpoint is enabled, make this visible -->
<MultiBinding Converter="{x:Static converters:EndpointToTypeConverter.Instance}">
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:Views.AesManager}}" Path="DataContext" />
<Binding Source="{x:Static local:EEndpointType.Aes}" />
</MultiBinding>
</Button.Visibility>
</Button>
</Grid>
</Border>
Expand Down
Loading

0 comments on commit 516fa33

Please sign in to comment.