Skip to content
This repository was archived by the owner on Jun 23, 2024. It is now read-only.

Commit da46363

Browse files
committed
Using a new updater, also switching to load offsets from the web.
1 parent d56b622 commit da46363

24 files changed

+1027
-188
lines changed

Bundle.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ZipFiles Include="$(OutputPath)NLog.config" />
77
<ZipFiles Include="$(OutputPath)AsmjitCSharp.dll" />
88
<ZipFiles Include="$(OutputPath)Offsets.json" />
9-
<ZipFiles Include="$(OutputPath)update.ps1" />
9+
<ZipFiles Include="$(OutputPath)PaisleyParkUpdater.exe" />
1010
</ItemGroup>
1111
<Zip Files="@(ZipFiles)" WorkingDirectory="$(OutputPath)" ZipFileName="$(OutputPath)PaisleyPark.zip" />
1212
</Target>

Offsets/2019.08.21.0000.0000.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"WaymarkClassPtr": 28730672, // 1B66530
3+
"WaymarkFunc": 7739280, // 761790
4+
"Waymarks": 28731088, // 1B666D0
5+
"MapID": 222 // 333
6+
}

PaisleyPark.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
44
VisualStudioVersion = 16.0.28621.142
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaisleyPark", "PaisleyPark\PaisleyPark.csproj", "{80C7757C-B3D3-4E52-9DD8-373DE51AB450}"
7+
ProjectSection(ProjectDependencies) = postProject
8+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7} = {A19E57D4-2858-4C84-A916-E4591C8AFCD7}
9+
EndProjectSection
710
EndProject
811
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{9456CD43-203D-487F-8DE8-AD69E1043EE5}"
912
ProjectSection(SolutionItems) = preProject
@@ -15,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nhaama.FFXIV", "lib\Nhaama.
1518
EndProject
1619
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nhaama.Memory", "lib\Nhaama.Memory\Nhaama.Memory.csproj", "{933935A7-8D04-42E8-AEE5-122B3AEED820}"
1720
EndProject
21+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaisleyParkUpdater", "PaisleyParkUpdater\PaisleyParkUpdater.csproj", "{A19E57D4-2858-4C84-A916-E4591C8AFCD7}"
22+
EndProject
1823
Global
1924
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2025
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +50,14 @@ Global
4550
{933935A7-8D04-42E8-AEE5-122B3AEED820}.Release|Any CPU.ActiveCfg = Release|x64
4651
{933935A7-8D04-42E8-AEE5-122B3AEED820}.Release|x64.ActiveCfg = Release|x64
4752
{933935A7-8D04-42E8-AEE5-122B3AEED820}.Release|x64.Build.0 = Release|x64
53+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7}.Debug|x64.ActiveCfg = Debug|x64
56+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7}.Debug|x64.Build.0 = Debug|x64
57+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
58+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7}.Release|Any CPU.Build.0 = Release|Any CPU
59+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7}.Release|x64.ActiveCfg = Release|x64
60+
{A19E57D4-2858-4C84-A916-E4591C8AFCD7}.Release|x64.Build.0 = Release|x64
4861
EndGlobalSection
4962
GlobalSection(SolutionProperties) = preSolution
5063
HideSolutionNode = FALSE

PaisleyPark/Models/Settings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public class Settings : INotifyPropertyChanged
2222
/// </summary>
2323
private static readonly string SETTINGS_FILE = "settings.json";
2424

25+
/// <summary>
26+
/// The latest game version known.
27+
/// </summary>
28+
public string LatestGameVersion { get; set; }
29+
2530
/// <summary>
2631
/// Path to the game to use for various functions.
2732
/// </summary>

PaisleyPark/PaisleyPark.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -204,7 +204,7 @@
204204
<PrivateAssets>all</PrivateAssets>
205205
</PackageReference>
206206
<PackageReference Include="Markdig">
207-
<Version>0.17.0</Version>
207+
<Version>0.17.1</Version>
208208
</PackageReference>
209209
<PackageReference Include="MSBuildTasks">
210210
<Version>1.5.0.235</Version>

PaisleyPark/ViewModels/MainWindowViewModel.cs

Lines changed: 112 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ public class MainWindowViewModel : BindableBase
3737
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
3838
private NancyHost Host;
3939
private Thread WaymarkThread;
40-
private readonly Offsets Offsets;
40+
private Offsets Offsets;
4141
private readonly Version CurrentVersion;
42+
private string GameVersion;
4243
public string DiscordUri { get; private set; } = "https://discord.gg/hq3DnBa";
44+
private static readonly Uri OffsetUrl = new Uri("https://raw.githubusercontent.com/LeonBlade/PaisleyPark/master/Offsets/");
4345

4446
#pragma warning disable IDE1006 // Naming Styles
4547

@@ -73,48 +75,11 @@ public MainWindowViewModel(IEventAggregator ea)
7375
// Fetch an update.
7476
FetchUpdate();
7577

76-
logger.Info($"Loading Offsets.json from {Environment.CurrentDirectory}");
78+
// Load the settings file.
79+
UserSettings = Settings.Load();
7780

78-
// Read the offsets.json file.
79-
try
80-
{
81-
using (var r = new StreamReader(Path.Combine(Environment.CurrentDirectory, "Offsets.json")))
82-
{
83-
Offsets = JsonConvert.DeserializeObject<Offsets>(r.ReadToEnd());
84-
}
85-
}
86-
catch (Exception)
87-
{
88-
MessageBox.Show("Couldn't load the offsets file! Please select the offsets file manually.", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Exclamation);
89-
var dlg = new Microsoft.Win32.OpenFileDialog
90-
{
91-
InitialDirectory = Environment.CurrentDirectory,
92-
DefaultExt = ".json",
93-
Filter = "JSON Files (*.json)|*.json|All files (*.*)|*.*"
94-
};
95-
96-
// Show dialog.
97-
var result = dlg.ShowDialog();
98-
99-
if (result == true)
100-
{
101-
try
102-
{
103-
using (var r = new StreamReader(dlg.FileName))
104-
{
105-
Offsets = JsonConvert.DeserializeObject<Offsets>(r.ReadToEnd());
106-
}
107-
}
108-
catch (Exception)
109-
{
110-
MessageBox.Show("Could not open this offset file. Shutting down.", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Error);
111-
Application.Current.Shutdown();
112-
}
113-
}
114-
}
115-
116-
// Load the settings file.
117-
UserSettings = Settings.Load();
81+
// Get the offsets.
82+
GetOffsets();
11883

11984
// Subscribe to the waymark event from the REST server.
12085
EventAggregator.GetEvent<WaymarkEvent>().Subscribe(waymarks =>
@@ -163,106 +128,112 @@ private bool Initialize()
163128
return true;
164129
}
165130

131+
/// <summary>
132+
/// Gets the offsets for the program, also checks for a new version for this game version.
133+
/// </summary>
134+
private void GetOffsets()
135+
{
136+
// Get the current version of FFXIV.
137+
var gameDirectory = new DirectoryInfo(GameProcess.BaseProcess.MainModule.FileName);
138+
GameVersion = File.ReadAllText(Path.Combine(gameDirectory.Parent.FullName, "ffxivgame.ver"));
139+
140+
logger.Debug($"Game version is {GameVersion}");
141+
142+
// Check the game version against what we have saved in settings.
143+
if (UserSettings.LatestGameVersion != GameVersion)
144+
{
145+
logger.Info($"Latest version {GameVersion} does not match the latest game version in settings {UserSettings.LatestGameVersion}");
146+
147+
var result = MessageBox.Show("There are new offsets available from the web. Would you like to use these offsets?", "Paisley Park", MessageBoxButton.YesNo, MessageBoxImage.Question);
148+
if (result == MessageBoxResult.Yes)
149+
{
150+
logger.Info("User is downloading latest offsets.");
151+
// Create client to fetch latest version of offsets.
152+
try
153+
{
154+
using (var client = new WebClient())
155+
{
156+
// Form the URI for the game version's offsets file.
157+
var uri = new Uri(OffsetUrl, $"{GameVersion}.json");
158+
// Write the JSON to the disk overwriting the Offsets.json file used locally.
159+
File.WriteAllText(Path.Combine(Environment.CurrentDirectory, "Offsets.json"), client.DownloadString(uri));
160+
// Set the lateste version to the version downloaded.
161+
UserSettings.LatestGameVersion = GameVersion;
162+
// Save the settings.
163+
Settings.Save(UserSettings);
164+
}
165+
}
166+
catch (Exception ex)
167+
{
168+
MessageBox.Show("Couldn't fetch or save offsets from the server. Your offsets could be out of date, and if so, may cause the game to crash.", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Error);
169+
logger.Error(ex, "Couldn't fetch or save offsets from the server!");
170+
}
171+
}
172+
}
173+
174+
// Read the offsets.json file.
175+
try
176+
{
177+
using (var r = new StreamReader(Path.Combine(Environment.CurrentDirectory, "Offsets.json")))
178+
{
179+
Offsets = JsonConvert.DeserializeObject<Offsets>(r.ReadToEnd());
180+
}
181+
}
182+
catch (Exception)
183+
{
184+
MessageBox.Show("Couldn't load the offsets file! Please select the offsets file manually.", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Exclamation);
185+
var dlg = new Microsoft.Win32.OpenFileDialog
186+
{
187+
InitialDirectory = Environment.CurrentDirectory,
188+
DefaultExt = ".json",
189+
Filter = "JSON Files (*.json)|*.json|All files (*.*)|*.*"
190+
};
191+
192+
// Show dialog.
193+
var result = dlg.ShowDialog();
194+
195+
if (result == true)
196+
{
197+
try
198+
{
199+
using (var r = new StreamReader(dlg.FileName))
200+
{
201+
Offsets = JsonConvert.DeserializeObject<Offsets>(r.ReadToEnd());
202+
}
203+
}
204+
catch (Exception)
205+
{
206+
MessageBox.Show("Could not open this offset file. Shutting down.", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Error);
207+
Application.Current.Shutdown();
208+
}
209+
}
210+
}
211+
}
212+
166213
/// <summary>
167214
/// Fetch an update for the applicaton.
168215
/// </summary>
169216
private void FetchUpdate()
170217
{
171-
logger.Info("Fetching update.");
172-
173-
// Create request for Github REST API for the latest release of Paisley Park.
174-
if (WebRequest.Create("https://api.github.com/repos/LeonBlade/PaisleyPark/releases/latest") is HttpWebRequest request)
175-
{
176-
request.Method = "GET";
177-
request.UserAgent = "PaisleyPark";
178-
request.ServicePoint.Expect100Continue = false;
179-
180-
try
181-
{
182-
using (var r = new StreamReader(request.GetResponse().GetResponseStream()))
183-
{
184-
// Get the JSON as a JObject to get the properties dynamically.
185-
var json = JsonConvert.DeserializeObject<JObject>(r.ReadToEnd());
186-
// Get tag name and remove the v in front.
187-
var tag_name = json["tag_name"].Value<string>().Substring(1);
188-
// Form release version from this string.
189-
var releaseVersion = new Version(tag_name);
190-
// Check if the release is newer.
191-
if (releaseVersion > CurrentVersion)
192-
{
193-
// Create update window.
194-
var updateWindow = new Updater();
195-
// Get the view model.
196-
var vm = updateWindow.DataContext as UpdaterViewModel;
197-
// Create HTML out of the markdown in body.
198-
var html = Markdown.ToHtml(json["body"].Value<string>());
199-
// Set the update string
200-
vm.UpdateString = $"Paisley Park {releaseVersion.VersionString()} is now available, you have {CurrentVersion.VersionString()}. Would you like to download it now?";
201-
// Set HTML in the window.
202-
vm.HTML = html;
203-
204-
// We want to install.
205-
if (updateWindow.ShowDialog() == true)
206-
{
207-
using (var wc = new WebClient())
208-
{
209-
// Delete existing zip file.
210-
if (File.Exists("PaisleyPark.zip"))
211-
File.Delete("PaisleyPark.zip");
212-
213-
// Download the file.
214-
wc.DownloadFile(new Uri(json["assets"][0]["browser_download_url"].Value<string>()), "PaisleyPark.zip");
215-
216-
// Get temp path for update script to run on.
217-
var temp = Path.Combine(Path.GetTempPath(), "PaisleyPark");
218-
219-
// Create temp diretory if it doesn't exist.
220-
if (!Directory.Exists(temp))
221-
Directory.CreateDirectory(temp);
222-
223-
// Temp update file location.
224-
var script = Path.Combine(temp, "update.ps1");
225-
226-
// Delete existing script just in case.
227-
if (File.Exists(script))
228-
File.Delete(script);
229-
230-
// Copy the update script to the temp path.
231-
File.Copy(@".\update.ps1", script);
232-
233-
// Run the update script.
234-
Process.Start("powershell.exe", $"{script} \"{Environment.CurrentDirectory}\"");
235-
}
236-
}
237-
}
238-
}
239-
}
240-
catch (Exception ex)
241-
{
242-
UpdateFailed(ex);
243-
}
244-
}
245-
else
246-
{
247-
UpdateFailed();
248-
}
249-
250-
// Used for when update fails.
251-
void UpdateFailed(Exception ex = null)
252-
{
253-
var answer = MessageBox.Show(
254-
"Unable to fetch the latest release of Paisley Park. Would you like to visit the release page?",
255-
"Paisley Park",
256-
MessageBoxButton.YesNo,
257-
MessageBoxImage.Error
258-
);
259-
if (answer == MessageBoxResult.Yes)
260-
{
261-
Process.Start("https://github.com/LeonBlade/PaisleyPark/releases/latest");
262-
}
263-
264-
logger.Error(ex, "Update failed when requesting update from Github.");
265-
}
218+
try
219+
{
220+
Process.Start("PaisleyParkUpdater.exe");
221+
}
222+
catch (Exception ex)
223+
{
224+
logger.Error(ex, "Updater didn't work.");
225+
var result = MessageBox.Show(
226+
"Could not run the updater. Would you like to visit the releases page to check for a new update manually?",
227+
"Paisley Park",
228+
MessageBoxButton.YesNo,
229+
MessageBoxImage.Error
230+
);
231+
// Launch the web browser to the latest release.
232+
if (result == MessageBoxResult.Yes)
233+
{
234+
Process.Start("https://github.com/LeonBlade/PaisleyPark/releases/latest");
235+
}
236+
}
266237
}
267238

268239
/// <summary>
@@ -335,10 +306,10 @@ private bool InitializeNhaama()
335306
{
336307
GameDefinitions = Definitions.Get(GameProcess, gameVersion.ToString(), Game.GameType.Dx11);
337308
}
338-
catch (Exception ex)
309+
catch (Exception)
339310
{
340-
GameDefinitions = Definitions.Get(GameProcess, "2019.07.10.0001.0000", Game.GameType.Dx11);
341-
Console.WriteLine(ex);
311+
// Fallback to last known version.
312+
GameDefinitions = Definitions.Get(GameProcess, "2019.08.21.0000.0000", Game.GameType.Dx11);
342313
}
343314

344315
// Create new worker.
@@ -445,8 +416,6 @@ private void InjectCode()
445416
"ret"
446417
}), _newmem.AsHex(), waymarkClassPointer.AsHex(), waymarkFunc.AsHex());
447418

448-
logger.Debug("Assembly to inject:\n{0}", asm);
449-
450419
// Get bytes from AsmjitCSharp.
451420
var bytes = AsmjitCSharp.Assemble(asm);
452421

@@ -612,7 +581,7 @@ private void LoadPreset()
612581
{
613582
// Ask the user if they want to still place based on the XYZ being all 0.
614583
var result = MessageBox.Show(
615-
"It appears you might not be loaded into a zone yet. Placing Waymarks in this state will crash the game. Are you sure you want to do this?",
584+
"There is a problem loading your current position, this may cause crashing. Are you sure you want to do this?",
616585
"Paisley Park",
617586
MessageBoxButton.YesNo,
618587
MessageBoxImage.Warning

0 commit comments

Comments
 (0)