Skip to content

Commit

Permalink
feat(sqlite): implement mezfes records
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Apr 20, 2023
1 parent 1bbe9b3 commit 86ed327
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 48 deletions.
2 changes: 0 additions & 2 deletions MHFZ_Overlay/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2814,8 +2814,6 @@ private void settingsPresetComboBox_SelectionChanged(object sender, SelectionCha
s.EnableKeyLogging = false;
s.EnableMap = false;

// TODO: can i even log zen quests?
//s.EnableQuestLogging = false;
s.OverlayModeWatermarkShown = false;

s.Monster1IconShown = true;
Expand Down
51 changes: 50 additions & 1 deletion MHFZ_Overlay/Core/Class/DataAccessLayer/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ FinalTimeValue ASC
"{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}",
createdAt, createdBy, runID,
gameFolderPath, mhfdatHash, mhfemdHash,
mhfinfHash, mhfsqdHash, mhfodllHash,
mhfinfHash, mhfsqdHash, mhfodllHash,
mhfohddllHash, mhfexeHash);
string gameFolderHash = CalculateStringHash(gameFolderData);

Expand Down Expand Up @@ -7517,6 +7517,54 @@ GROUP BY
return questTimeSpent;
}

public void InsertMezFesMinigameScore(DataLoader dataLoader, int previousMezFesArea, int previousMezFesScore)
{
if (!MezFesMinigame.ID.ContainsKey(previousMezFesArea) || previousMezFesScore <= 0)
{
logger.Error("DATABASE OPERATION: wrong mezfes area or empty score, area id: {0}, score: {1}", previousMezFesArea, previousMezFesScore);
return;
}

using (SQLiteConnection conn = new SQLiteConnection(dataSource))
{
conn.Open();
using (var transaction = conn.BeginTransaction())
{
try
{
string sql = @"INSERT INTO MezFes (
CreatedAt,
CreatedBy,
MezFesMinigameID,
Score
) VALUES (
@CreatedAt,
@CreatedBy,
@MezFesMinigameID,
@Score)";

using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
DateTime createdAt = DateTime.Now;
string createdBy = dataLoader.model.GetFullCurrentProgramVersion();

cmd.Parameters.AddWithValue("@CreatedAt", createdAt);
cmd.Parameters.AddWithValue("@CreatedBy", createdBy);
cmd.Parameters.AddWithValue("@MezFesMinigameID", previousMezFesArea);
cmd.Parameters.AddWithValue("@Score", previousMezFesScore);

cmd.ExecuteNonQuery();
}
transaction.Commit();
}
catch (Exception ex)
{
HandleError(transaction, ex);
}
}
}
}

private void UpdateDatabaseSchema(SQLiteConnection connection)
{
Settings s = (Settings)System.Windows.Application.Current.TryFindResource("Settings");
Expand Down Expand Up @@ -7847,6 +7895,7 @@ private string ReadPreviousVersionFromFile()
return version;
}


#endregion
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class MezFesMinigame
{
public static IReadOnlyDictionary<int, string> ID { get; } = new Dictionary<int, string>
{
{463,"Volpkun Together" },
{463,"Volpkun Together" }, // TODO
{464,"Uruki Pachinko" },
{465,"MezFes Minigame" }, // TODO
{466,"Guuku Scoop" },
Expand Down
4 changes: 4 additions & 0 deletions MHFZ_Overlay/MHFZ_Overlay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>False</Optimize>
</PropertyGroup>

<ItemGroup>
<None Remove="UI\Background\1.png" />
<None Remove="UI\Background\2.png" />
Expand Down
98 changes: 58 additions & 40 deletions MHFZ_Overlay/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ private void UpdateDiscordRPC()
break;

case 464://Uruki Pachinko
presenceTemplate.State = string.Format("Score: {0} | Chain: {1} | Fish: {2} | Mushroom: {3} | Seed: {4} | Meat: {5}", DataLoader.model.UrukiPachinkoScore(), DataLoader.model.UrukiPachinkoChain(), DataLoader.model.UrukiPachinkoFish(), DataLoader.model.UrukiPachinkoMushroom(), DataLoader.model.UrukiPachinkoSeed(), DataLoader.model.UrukiPachinkoMeat());
presenceTemplate.State = string.Format("Score: {0} | Chain: {1} | Fish: {2} | Mushroom: {3} | Seed: {4} | Meat: {5}", DataLoader.model.UrukiPachinkoScore() + DataLoader.model.UrukiPachinkoBonusScore(), DataLoader.model.UrukiPachinkoChain(), DataLoader.model.UrukiPachinkoFish(), DataLoader.model.UrukiPachinkoMushroom(), DataLoader.model.UrukiPachinkoSeed(), DataLoader.model.UrukiPachinkoMeat());
break;

case 466://Guuku Scoop
Expand Down Expand Up @@ -2882,60 +2882,78 @@ await Dispatcher.BeginInvoke(new Action(() =>
}));
}

/// <summary>
/// Gets the mezeporta festival minigame score depending on area id
/// </summary>
/// <param name="areaID"></param>
/// <returns></returns>
private int GetMezFesMinigameScore(int areaID)
{
// Read player score from corresponding memory address based on current area ID
int score = 0;
switch (areaID)
{
case 464: // Uruki Pachinko
score = DataLoader.model.UrukiPachinkoScore() + DataLoader.model.UrukiPachinkoBonusScore();
break;
case 467: // Nyanrendo
score = DataLoader.model.NyanrendoScore();
break;
case 469: // Dokkan Battle Cats
score = DataLoader.model.DokkanBattleCatsScore();
break;
case 466: // Guuku Scoop
score = DataLoader.model.GuukuScoopScore();
break;
case 468: // Panic Honey
score = DataLoader.model.PanicHoneyScore();
break;
}
return score;
}

/// <summary>
/// Checks the mezeporta festival score. At minigame end, the score is the max obtained, with the area id as the minigame id, then shortly goes to 0 score with the same area id, then switches area id to the lobby id shortly afterwards.
/// </summary>
private void CheckMezFesScore()
{
if (DataLoader.model.QuestID() != 0)
if (DataLoader.model.QuestID() != 0 || !(DataLoader.model.AreaID() == 462 || MezFesMinigame.ID.ContainsKey(DataLoader.model.AreaID())))
return;

// Check if player is in the minigame lobby
if (DataLoader.model.AreaID() == 462)
{
// Save current area ID as previous area ID
DataLoader.model.previousMezFesArea = DataLoader.model.AreaID();
}
int areaID = DataLoader.model.AreaID();

// Check if player is in a minigame area
else if (MezFesMinigame.ID.ContainsKey(DataLoader.model.AreaID()))
if (MezFesMinigame.ID.ContainsKey(areaID))
{
// Check if previous area ID was the lobby
if (DataLoader.model.previousMezFesArea == 462)
// Check if the player has entered a new minigame area
if (areaID != DataLoader.model.previousMezFesArea)
{
// Read player score from corresponding memory address based on current area ID
switch (DataLoader.model.AreaID())
{
case 464: // Uruki Pachinko
DataLoader.model.previousMezFesScore = DataLoader.model.UrukiPachinkoScore();
break;
case 467: // Nyanrendo
DataLoader.model.previousMezFesScore = DataLoader.model.NyanrendoScore();
break;
case 469: // Dokkan Battle Cats
DataLoader.model.previousMezFesScore = DataLoader.model.DokkanBattleCatsScore();
break;
case 466: // Guuku Scoop
DataLoader.model.previousMezFesScore = DataLoader.model.GuukuScoopScore();
break;
case 468: // Panic Honey
DataLoader.model.previousMezFesScore = DataLoader.model.PanicHoneyScore();
break;
default:
DataLoader.model.previousMezFesScore = 0; // If no corresponding memory address found, set score to 0
break;
}
DataLoader.model.previousMezFesArea = areaID;
DataLoader.model.previousMezFesScore = 0;
}

// Read player score from corresponding memory address based on current area ID
int score = GetMezFesMinigameScore(areaID);

// Update current score with new score if it's greater
if (score > DataLoader.model.previousMezFesScore)
{
DataLoader.model.previousMezFesScore = score;
}
}
// Check if previous area ID was a minigame area and current area ID is the lobby
else if (DataLoader.model.previousMezFesArea != -1 && DataLoader.model.AreaID() == 462)
// Check if the player has exited a minigame area and the score is 0
else if (DataLoader.model.previousMezFesArea != -1 && areaID == 462)
{
// Update player score in SQLite database with previousPlayerScore and previousAreaId
// TODO: Implement updating of player score in SQLite database with previousPlayerScore and previousAreaId
// databaseManager.InsertMezFesMinigameScore(DataLoader.model.previousMezFesArea, DataLoader.model.previousMezFesScore);
// Reset previous area ID to -1 and previous player score to 0
// Save current score and minigame area ID to database
databaseManager.InsertMezFesMinigameScore(DataLoader, DataLoader.model.previousMezFesArea, DataLoader.model.previousMezFesScore);

// Reset previousMezFesArea and previousMezFesScore
DataLoader.model.previousMezFesArea = -1;
DataLoader.model.previousMezFesScore = 0;
}
}

//TODO
//TODO: optimization
private void CheckQuestStateForDatabaseLogging()
{
Settings s = (Settings)System.Windows.Application.Current.TryFindResource("Settings");
Expand Down
1 change: 1 addition & 0 deletions MHFZ_Overlay/addresses/AddressModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public AddressModel(Mem m) {
abstract public int UrukiPachinkoMeat();
abstract public int UrukiPachinkoChain();
abstract public int UrukiPachinkoScore();
abstract public int UrukiPachinkoBonusScore();
abstract public int NyanrendoScore();
abstract public int DokkanBattleCatsScore();
abstract public int DokkanBattleCatsScale();
Expand Down
2 changes: 2 additions & 0 deletions MHFZ_Overlay/addresses/AddressModelHGE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public int LargeMonster2Road()
public override int UrukiPachinkoMeat() => M.ReadByte("mhfo-hd.dll+EE26914");
public override int UrukiPachinkoChain() => M.ReadByte("mhfo-hd.dll+EE26900");
public override int UrukiPachinkoScore() => M.Read2Byte("mhfo-hd.dll+EE2690C");
public override int UrukiPachinkoBonusScore() => M.Read2Byte("mhfo-hd.dl+EE26910");
public override int NyanrendoScore() => M.Read2Byte("mhfo-hd.dll+EE26900");
public override int DokkanBattleCatsScore() => M.Read2Byte("mhfo-hd.dll+EE268F8");
public override int DokkanBattleCatsScale() => M.ReadByte("mhfo-hd.dll+EE26A8C");
Expand All @@ -208,6 +209,7 @@ public int LargeMonster2Road()
public override int GuukuScoopGolden() => M.ReadByte("mhfo-hd.dll+EE2693C");
public override int GuukuScoopScore() => M.Read2Byte("mhfo-hd.dll+EE26924");
public override int PanicHoneyScore() => M.ReadByte("mhfo-hd.dll+EE26908");
// TODO: Volpkun Together addresses
public override int Sharpness() => M.Read2Byte("mhfo-hd.dll+DC6C276");
public override int CaravanPoints() => M.ReadInt("mhfo-hd.dll+ED3C034");
public override int MezeportaFestivalPoints() => M.ReadInt("mhfo-hd.dll+EDBA1EC");
Expand Down
5 changes: 1 addition & 4 deletions MHFZ_Overlay/addresses/AddressModelNotHGE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ public int LargeMonster2Road()
public override int DamageDealt() => M.Read2Byte("mhfo.dll+5CA3430");
public override int RoadSelectedMonster() => M.ReadByte("mhfo.dll+001B48F4,4");





//new addresses
public override int AreaID() => M.Read2Byte("mhfo.dll+5034388");
public override int RavienteAreaID() => M.Read2Byte("mhfo.dll+6124B6E");
Expand All @@ -137,6 +133,7 @@ public int LargeMonster2Road()
public override int UrukiPachinkoMeat() => M.ReadByte("mhfo.dll+61EC174");
public override int UrukiPachinkoChain() => M.ReadByte("mhfo.dll+61EC160");
public override int UrukiPachinkoScore() => M.Read2Byte("mhfo.dll+61EC16C");
public override int UrukiPachinkoBonusScore() => M.Read2Byte("mhfo.dll+61EC170");
public override int NyanrendoScore() => M.Read2Byte("mhfo.dll+61EC160");
public override int DokkanBattleCatsScore() => M.Read2Byte("mhfo.dll+61EC158");
public override int DokkanBattleCatsScale() => M.ReadByte("mhfo.dll+61EC2EC");
Expand Down

0 comments on commit 86ed327

Please sign in to comment.