@@ -37,9 +37,11 @@ public class MainWindowViewModel : BindableBase
37
37
private static readonly NLog . Logger logger = NLog . LogManager . GetCurrentClassLogger ( ) ;
38
38
private NancyHost Host ;
39
39
private Thread WaymarkThread ;
40
- private readonly Offsets Offsets ;
40
+ private Offsets Offsets ;
41
41
private readonly Version CurrentVersion ;
42
+ private string GameVersion ;
42
43
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/" ) ;
43
45
44
46
#pragma warning disable IDE1006 // Naming Styles
45
47
@@ -73,48 +75,11 @@ public MainWindowViewModel(IEventAggregator ea)
73
75
// Fetch an update.
74
76
FetchUpdate ( ) ;
75
77
76
- logger . Info ( $ "Loading Offsets.json from { Environment . CurrentDirectory } ") ;
78
+ // Load the settings file.
79
+ UserSettings = Settings . Load ( ) ;
77
80
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 ( ) ;
118
83
119
84
// Subscribe to the waymark event from the REST server.
120
85
EventAggregator . GetEvent < WaymarkEvent > ( ) . Subscribe ( waymarks =>
@@ -163,106 +128,112 @@ private bool Initialize()
163
128
return true ;
164
129
}
165
130
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
+
166
213
/// <summary>
167
214
/// Fetch an update for the applicaton.
168
215
/// </summary>
169
216
private void FetchUpdate ( )
170
217
{
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
+ }
266
237
}
267
238
268
239
/// <summary>
@@ -335,10 +306,10 @@ private bool InitializeNhaama()
335
306
{
336
307
GameDefinitions = Definitions . Get ( GameProcess , gameVersion . ToString ( ) , Game . GameType . Dx11 ) ;
337
308
}
338
- catch ( Exception ex )
309
+ catch ( Exception )
339
310
{
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 ) ;
342
313
}
343
314
344
315
// Create new worker.
@@ -445,8 +416,6 @@ private void InjectCode()
445
416
"ret"
446
417
} ) , _newmem . AsHex ( ) , waymarkClassPointer . AsHex ( ) , waymarkFunc . AsHex ( ) ) ;
447
418
448
- logger . Debug ( "Assembly to inject:\n {0}" , asm ) ;
449
-
450
419
// Get bytes from AsmjitCSharp.
451
420
var bytes = AsmjitCSharp . Assemble ( asm ) ;
452
421
@@ -612,7 +581,7 @@ private void LoadPreset()
612
581
{
613
582
// Ask the user if they want to still place based on the XYZ being all 0.
614
583
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?" ,
616
585
"Paisley Park" ,
617
586
MessageBoxButton . YesNo ,
618
587
MessageBoxImage . Warning
0 commit comments