Skip to content

Commit 8e34747

Browse files
author
CapitaineToinon
committed
Fixed logic to fix a bug with flags incorrectly being reset on quitouts
TIL, when you quitout, right before the game isn't loaded anymore, all the flags are being reset to their original values. Previous code assumed that wasn't possible and was thus resetting the state of the logic too early. New code only reset states when the game is loaded.
1 parent 0ee51ce commit 8e34747

File tree

3 files changed

+52
-124
lines changed

3 files changed

+52
-124
lines changed

Gadgetlemage/MainWindow.xaml.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,10 @@ private void AutoRefresh(CancellationToken ct)
9595
{
9696
btnCreate.IsEnabled = Model.Hooked && Model.Loaded;
9797

98-
// Automatically creates the weapon if needed
99-
bool autoCreate = cbxAutoCreate.IsChecked ?? false;
100-
if (Model.Hooked && Model.Loaded && autoCreate)
101-
{
102-
Model.AutomaticallyCreateWeapon();
103-
}
104-
105-
// Automatically delete the shield if needed
106-
bool autoDelete = cbxAutoDelete.IsChecked ?? false;
107-
if (Model.Hooked && Model.Loaded && autoDelete)
108-
{
109-
Model.AutomaticallyRemoveShield();
110-
}
98+
bool createWeapon = cbxAutoCreate.IsChecked ?? false;
99+
bool deleteShield = cbxAutoDelete.IsChecked ?? false;
111100

101+
Model.UpdateLoop(createWeapon, deleteShield);
112102
}));
113103

114104
Thread.Sleep(Model.RefreshInterval);

Gadgetlemage/Model.cs

Lines changed: 47 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Diagnostics;
55
using Gadgetlemage.DarkSouls;
6+
using System.Windows;
67

78
namespace Gadgetlemage
89
{
@@ -37,14 +38,14 @@ public class Model : PHook
3738
public DarkSouls.DarkSouls DarkSouls { get; set; }
3839

3940
/// <summary>
40-
/// Whether or not the weapon has created
41+
/// Whether or not the game was loaded on the previous loop
4142
/// </summary>
42-
public bool WeaponCreated { get; set; }
43+
public bool PreviousLoaded { get; set; }
4344

4445
/// <summary>
45-
/// Whether or not the shield was deleted
46+
/// Whether or not the black knight deaths has already been processed
4647
/// </summary>
47-
public bool ShieldDeleted { get; set; }
48+
public bool DeathProcessed { get; set; }
4849

4950
/// <summary>
5051
/// List of all available black knight weapons
@@ -72,7 +73,7 @@ public BlackKnightWeapon BlackKnightShield
7273
{
7374
get
7475
{
75-
return (Hooked) ? HOOKED_INTERVAL : UNHOOKED_INTERVAL;
76+
return (Hooked) ? HOOKED_INTERVAL : UNHOOKED_INTERVAL;
7677
}
7778
}
7879

@@ -148,8 +149,8 @@ public Model() : base(0, MIN_LIFE_SPAN, processSelector) // RefreshInterval at 0
148149
OnHooked += DarkSoulsProcess_OnHooked;
149150
OnUnhooked += DarkSoulsProcess_OnUnhooked;
150151

151-
WeaponCreated = true;
152-
ShieldDeleted = true;
152+
DeathProcessed = false;
153+
PreviousLoaded = false;
153154
}
154155

155156
/// <summary>
@@ -207,135 +208,72 @@ public void DeleteShield()
207208
}
208209

209210
/// <summary>
210-
/// Automatically delete the shield from the player's inventory
211+
/// Main update loop that will automatically create and delete black knight weapons if needed
211212
/// </summary>
212-
public void AutomaticallyRemoveShield()
213+
/// <param name="createWeapon">If it should automatically create the weapon</param>
214+
/// <param name="deleteShield">If it should automatically delete the shield</param>
215+
public void UpdateLoop(bool createWeapon, bool deleteShield)
213216
{
214-
if (Ready)
217+
bool CurrentLoaded = Loaded;
218+
219+
if (CurrentLoaded)
215220
{
216-
bool alreadyOwns = DarkSouls.FindBlackKnightWeapon(BlackKnightShield);
217221
bool IsBlackKnightDead = SelectedWeapon.IsConditionSatisfied();
222+
bool IsBlackKnightAlive = !IsBlackKnightDead;
223+
bool JustLoaded = !PreviousLoaded && CurrentLoaded;
218224

219225
/**
220-
* If the black knight is still alive, we reset the state of the Weapon
226+
* If the black knight is still alive, we reset the state of the Weapon and Shield
227+
* Only checks after the player just loaded back in because it is the only
228+
* reliable moment
221229
*/
222-
if (!IsBlackKnightDead)
223-
{
224-
ShieldDeleted = false;
225-
}
226-
// else the black knight is dead...
227-
else
230+
if (JustLoaded && IsBlackKnightAlive)
228231
{
229-
if (alreadyOwns)
230-
{
231-
if (!ShieldDeleted)
232-
{
233-
/**
234-
* If the black knight is dead and the player has the shield
235-
* so we need to delete it
236-
*/
237-
DeleteShield();
238-
ShieldDeleted = true;
239-
}
240-
else
241-
{
242-
/**
243-
* If the black knight is dead but the player still has the
244-
* shield. Maybe another black knight dropped one so we don't
245-
* do anything
246-
*/
247-
// Nothing to do here
248-
}
249-
}
250-
else
251-
{
252-
if (!ShieldDeleted)
253-
{
254-
/**
255-
* The black knight is dead and we didn't delete the shield.
256-
* Hence it didn't drop so we don't need to delete anything
257-
*/
258-
ShieldDeleted = true;
259-
}
260-
else
261-
{
262-
/**
263-
* The black knight is dead, the player doesn't have the shield
264-
* and we already removed it from the inventory. Everything's
265-
* good
266-
*/
267-
// Nothing to do here
268-
}
269-
}
232+
DeathProcessed = false;
270233
}
271-
}
272-
}
273-
274-
/// <summary>
275-
/// Automatically Get the item if needed
276-
/// </summary>
277-
public void AutomaticallyCreateWeapon()
278-
{
279-
if (Ready)
280-
{
281-
bool IsBlackKnightDead = SelectedWeapon.IsConditionSatisfied();
282234

283235
/**
284-
* If the black knight is still alive, we reset the state of the Weapon
285-
*/
286-
if (!IsBlackKnightDead)
236+
* Only run logic when the black is dead and only run that logic once,
237+
* until the black knight is alive again
238+
*/
239+
if (IsBlackKnightDead && !DeathProcessed)
287240
{
288-
WeaponCreated = false;
289-
}
290-
// else the black knight is dead...
291-
else
292-
{
293-
bool alreadyOwns = DarkSouls.FindBlackKnightWeapon(SelectedWeapon);
294-
295-
if (alreadyOwns)
296-
{
297-
if (!WeaponCreated)
298-
{
299-
/**
300-
* If the black knight is dead and the player has the weapon
301-
* but we never gave it to him then it's a legit drop
302-
*/
303-
WeaponCreated = true;
304-
}
305-
else
306-
{
307-
/**
308-
* If the black knight is dead and the player has the weapon
309-
* and we already gave it to him then it's all good and we
310-
* don't do anything
311-
*/
312-
// Nothing to do here
313-
}
314-
}
315-
else
241+
// weapon
242+
if (createWeapon)
316243
{
317-
if (!WeaponCreated)
244+
bool needsToCreate = !DarkSouls.FindBlackKnightWeapon(SelectedWeapon);
245+
246+
if (needsToCreate)
318247
{
319248
/**
320249
* If the black knight is dead, the player doesn't have the
321250
* weapon and we didn't already gave it, then we give it
322251
*/
323252
CreateWeapon();
324-
WeaponCreated = true;
325253
}
326-
else
254+
}
255+
256+
// shield
257+
if (deleteShield)
258+
{
259+
bool needsToDelete = DarkSouls.FindBlackKnightWeapon(BlackKnightShield);
260+
261+
if (needsToDelete)
327262
{
328263
/**
329-
* If the black knight is dead, the player doesn't have the
330-
* weapon but we aleady gave it, then we don't do anything.
331-
* Maybe the player intentionally removed the weapon from his
332-
* inventory.
264+
* If the black knight is dead and the player has the shield
265+
* so we need to delete it
333266
*/
334-
// Nothing to do here
267+
DeleteShield();
335268
}
336269
}
270+
271+
// only execute this once per black knight death
272+
DeathProcessed = true;
337273
}
338274
}
275+
276+
PreviousLoaded = CurrentLoaded;
339277
}
340278

341279
/// <summary>

Gadgetlemage/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
5252
// en utilisant '*', comme indiqué ci-dessous :
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("4.0.0.0")]
55-
[assembly: AssemblyFileVersion("4.0.0.0")]
54+
[assembly: AssemblyVersion("5.0.0.0")]
55+
[assembly: AssemblyFileVersion("5.0.0.0")]

0 commit comments

Comments
 (0)