Skip to content

Commit

Permalink
feat: add game patch info
Browse files Browse the repository at this point in the history
  • Loading branch information
DorielRivalet committed Feb 21, 2024
1 parent 20f190e commit a7def9e
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 128 deletions.
126 changes: 126 additions & 0 deletions MHFZ_Overlay/Models/Collections/QuestsGamePatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// © 2023 The mhfz-overlay developers.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

namespace MHFZ_Overlay.Models.Collections;

using System.Collections.Generic;
using System.Collections.ObjectModel;
using MHFZ_Overlay.Models.Structures;

/// <summary>
/// The patches list.
/// </summary>
public static class QuestsGamePatches
{
public static ReadOnlyDictionary<string, Dictionary<GamePatch, GamePatchLanguage>> datHashInfo { get; } = new (new Dictionary<string, Dictionary<GamePatch, GamePatchLanguage>>
{
{ "593C418FA1408B76F655F0BB8D7DF8AA307CD89613A7734EB057A175825A4DA5", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Vanilla, GamePatchLanguage.JA }
}
},
{ "3E6FD419AD668AA973454B9AE9F1C49C739A0CA41FCE15CBF1DB1D2068E8C29D", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Seph, GamePatchLanguage.EN }
}
},
{ "F65080754B99BED5BE91BF1B4B0EC8EE61D7DED06831E3E7824F62B63F60E624", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Ezemania, GamePatchLanguage.FR }
}
},
{ "E1B0C47FE8BFA222BE1284CC232DAB63459574F40F8DA90FAE7FF20638480F96", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Otyav1_1, GamePatchLanguage.JA }
}
},
{ "735EFD86140E835E8DA2670CEA15A19154AE37ED046CBBB5A8918C39FC88B9E8", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Otyav1_1, GamePatchLanguage.EN }
}
},
{ "2B328D91626DB1DC8DD3FB9520D1AE52CF0C6F412B595D5795298DDC550FD06D", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Otyav1_1, GamePatchLanguage.FR }
}
},
{ "EE39C4776A1CF1271D0728D450F723B035144503298DB4C771C0376BF43AD4B8", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Mezelounge, GamePatchLanguage.EN }
}
},
});

public static ReadOnlyDictionary<string, Dictionary<GamePatch, GamePatchLanguage>> emdHashInfo { get; } = new(new Dictionary<string, Dictionary<GamePatch, GamePatchLanguage>>
{
{ "E68E03F1274D9D055CC8E42B0427BB99B0CEBFE9C905F951900B991F4CC8AFD1", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Vanilla, GamePatchLanguage.JA }
}
},
{ "5B70CE51EC6F95337B615C76C8BE8A0C42B16B14ED698739ADC097C4C507503E", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Vanilla, GamePatchLanguage.JA }
}
},
{ "1755B8C5DA0D488901BF4FC7179E0B036AC6F9C936C7CA5911C693119173F8E5", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Vanilla, GamePatchLanguage.JA }
}
},
{ "A90B90E6A66F1983C1807DB1298EF2BF94BFD05681021307C8F4213BBE31B890", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.FiveMusous, GamePatchLanguage.ZH }
}
},
});

public static ReadOnlyDictionary<string, Dictionary<GamePatch, GamePatchLanguage>> mhfodllHashInfo { get; } = new(new Dictionary<string, Dictionary<GamePatch, GamePatchLanguage>>
{
{ "69B65205B1F23A6989395CD811C414D410FE43D7ACD3C33A565E2C564AD184F4", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Standard, GamePatchLanguage.JA }
}
},
{ "A21322CA5864D6A4C8599FD4522FDBCC8997225C05D82D958D9AEBA2678ADFC7", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Standard, GamePatchLanguage.EN }
}
},
{ "23177AECAEB8222392461F5B6F714D810953329E4622E948F387B9B318D97589", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Mezelounge, GamePatchLanguage.EN }
}
},
{ "514DC802AABE3C7709EC1AABEB25B586839EE86E15CC9C569C87CC459E9206A0", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Tenrou, GamePatchLanguage.EN }
}
},
});

public static ReadOnlyDictionary<string, Dictionary<GamePatch, GamePatchLanguage>> mhfohddllHashInfo { get; } = new(new Dictionary<string, Dictionary<GamePatch, GamePatchLanguage>>
{
{ "95C580195F4080D2E9582C8C9DF36ABEB280476E088B6366583C5F138DA8F301", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Standard, GamePatchLanguage.JA }
}
},
{ "01F980A4B892CA0DBEBAD8EB54B224D080B32253BB8E793E23CD060089003D25", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Standard, GamePatchLanguage.EN }
}
},
{ "6FD7A31663D7AF23D9A8D903E4FFB84F45390D5AEE7BC6C70347D2F17988FA02", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Mezelounge, GamePatchLanguage.EN }
}
},
{ "5A65673537E97522E4767A32EAA8622312AC118AF3ED64F02D56751A27FE0B90", new Dictionary<GamePatch, GamePatchLanguage>()
{
{ GamePatch.Tenrou, GamePatchLanguage.EN }
}
},
});
}
23 changes: 23 additions & 0 deletions MHFZ_Overlay/Models/QuestsGamePatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// © 2023 The mhfz-overlay developers.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

namespace MHFZ_Overlay.Models;

using System;

// TODO: ORM
public sealed class QuestsGamePatch
{
public long? QuestsGamePatchID { get; set; }

public long? RunID { get; set; }

public string? mhfdatInfo { get; set; }

public string? mhfemdInfo { get; set; }

public string? mhfodllInfo { get; set; }

public string? mhfohddllInfo { get; set; }
}
15 changes: 14 additions & 1 deletion MHFZ_Overlay/Models/Structures/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ public enum DivaPrayerGemColor
Blue,
}

/// <summary>
/// Creator, origin or purpose.
/// </summary>
public enum GamePatch
{
Vanilla,
Expand All @@ -855,13 +858,23 @@ public enum GamePatch
/// TODO
/// </summary>
Standard,
FiveMusous,
}

/// <summary>
/// https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes. Could also describe the origin rather than language.
/// </summary>
public enum GamePatchLanguage
{
JP,
JA,
EN,
FR,
ZH,
ES,
PT,
RU,
EL,
DE,
}

public enum GamePatchFile
Expand Down
86 changes: 68 additions & 18 deletions MHFZ_Overlay/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8107,6 +8107,56 @@ public QuestsOverlayHash GetOverlayHash(long runID)
return data;
}

public QuestsGamePatch GetQuestsGamePatch(long runID)
{
QuestsGamePatch data = new();
if (string.IsNullOrEmpty(this.dataSource))
{
Logger.Warn(CultureInfo.InvariantCulture, "Cannot get game patch. dataSource: {0}", this.dataSource);
return data;
}

// Use a SQL query to retrieve the Quest for the specific RunID from the database
using (var conn = new SQLiteConnection(this.dataSource))
{
conn.Open();
using (var transaction = conn.BeginTransaction())
{
try
{
using (var cmd = new SQLiteCommand("SELECT * FROM QuestsGamePatch WHERE RunID = @runID", conn))
{
cmd.Parameters.AddWithValue("@runID", runID);

using (var reader = cmd.ExecuteReader())
{
if (reader.Read())
{
data = new QuestsGamePatch
{
QuestsGamePatchID = long.Parse(reader["QuestsGamePatchID"]?.ToString() ?? "0", CultureInfo.InvariantCulture),
mhfdatInfo = reader["mhfdatInfo"]?.ToString() ?? "Unknown",
mhfemdInfo = reader["mhfemdInfo"]?.ToString() ?? "Unknown",
mhfodllInfo = reader["mhfodllInfo"]?.ToString() ?? "Unknown",
mhfohddllInfo = reader["mhfohddllInfo"]?.ToString() ?? "Unknown",
RunID = long.Parse(reader["RunID"]?.ToString() ?? "0", CultureInfo.InvariantCulture),
};
}
}
}

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

return data;
}

private Quest GetLastQuest(SQLiteConnection conn)
{
Quest quest = new();
Expand Down Expand Up @@ -18045,7 +18095,7 @@ private void UpdateQuestsMonsterDictionaries(SQLiteConnection conn, DataLoader d
{
var questID = long.Parse(reader["QuestID"]?.ToString() ?? "0", CultureInfo.InvariantCulture);

if (questID != Numbers.QuestIDFirstDistrictDuremudira || questID != Numbers.QuestIDSecondDistrictDuremudira)
if (questID != Numbers.QuestIDFirstDistrictDuremudira && questID != Numbers.QuestIDSecondDistrictDuremudira && questID != Numbers.QuestIDArrogantDuremudira && questID != Numbers.QuestIDArrogantDuremudiraRepel)
{
continue;
}
Expand All @@ -18058,17 +18108,17 @@ private void UpdateQuestsMonsterDictionaries(SQLiteConnection conn, DataLoader d
}

string monster1AttackMultiplierString = reader["Monster1AttackMultiplierDictionary"].ToString() ?? "{}";
string monster1DefenseRateString = reader["Monster1DefenseRateictionary"].ToString() ?? "{}";
string monster1DefenseRateString = reader["Monster1DefenseRateDictionary"].ToString() ?? "{}";
string monster1SizeMultiplierString = reader["Monster1SizeMultiplierDictionary"].ToString() ?? "{}";
string monster1StunThresholdString = reader["Monster1StunThresholdDictionary"].ToString() ?? "{}";
string monster1PartThresholdString = reader["Monster1PartThresholdDictionary"].ToString() ?? "{}";

var runID = long.Parse(reader["RunID"]?.ToString() ?? "0", CultureInfo.InvariantCulture);

var monster1HPDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, int>>>(monster1HPString);
var monster1AttackMultiplierDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, int>>>(monster1AttackMultiplierString);
var monster1DefenseRateDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, int>>>(monster1DefenseRateString);
var monster1SizeMultiplierDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, int>>>(monster1SizeMultiplierString);
var monster1AttackMultiplierDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, double>>>(monster1AttackMultiplierString);
var monster1DefenseRateDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, double>>>(monster1DefenseRateString);
var monster1SizeMultiplierDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, double>>>(monster1SizeMultiplierString);
var monster1StunThresholdDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, int>>>(monster1StunThresholdString);
var monster1PartThresholdDictionary = JsonConvert.DeserializeObject<Dictionary<int, Dictionary<int, List<int>>>>(monster1PartThresholdString);

Expand All @@ -18078,9 +18128,9 @@ private void UpdateQuestsMonsterDictionaries(SQLiteConnection conn, DataLoader d
}

Dictionary<int, Dictionary<int, int>> newMonster1HPDictionary = new();
Dictionary<int, Dictionary<int, int>> newMonster1AttackMultiplierDictionary = new();
Dictionary<int, Dictionary<int, int>> newMonster1DefenseRateDictionary = new();
Dictionary<int, Dictionary<int, int>> newMonster1SizeMultiplierDictionary = new();
Dictionary<int, Dictionary<int, double>> newMonster1AttackMultiplierDictionary = new();
Dictionary<int, Dictionary<int, double>> newMonster1DefenseRateDictionary = new();
Dictionary<int, Dictionary<int, double>> newMonster1SizeMultiplierDictionary = new();
Dictionary<int, Dictionary<int, int>> newMonster1StunThresholdDictionary = new();
Dictionary<int, Dictionary<int, List<int>>> newMonster1PartThresholdDictionary = new();

Expand Down Expand Up @@ -18135,7 +18185,7 @@ private void UpdateQuestsMonsterDictionaries(SQLiteConnection conn, DataLoader d
}
}

Dictionary<int, int> monsterEntry = new Dictionary<int, int>()
Dictionary<int, double> monsterEntry = new Dictionary<int, double>()
{
{monsterID, entry.Value.FirstOrDefault().Value},
};
Expand Down Expand Up @@ -18165,7 +18215,7 @@ private void UpdateQuestsMonsterDictionaries(SQLiteConnection conn, DataLoader d
}
}

Dictionary<int, int> monsterEntry = new Dictionary<int, int>()
Dictionary<int, double> monsterEntry = new Dictionary<int, double>()
{
{monsterID, entry.Value.FirstOrDefault().Value},
};
Expand Down Expand Up @@ -18195,7 +18245,7 @@ private void UpdateQuestsMonsterDictionaries(SQLiteConnection conn, DataLoader d
}
}

Dictionary<int, int> monsterEntry = new Dictionary<int, int>()
Dictionary<int, double> monsterEntry = new Dictionary<int, double>()
{
{monsterID, entry.Value.FirstOrDefault().Value},
};
Expand Down Expand Up @@ -18271,18 +18321,18 @@ private void UpdateQuestsMonsterDictionaries(SQLiteConnection conn, DataLoader d
SET
Monster1HPDictionary = @Monster1HPDictionary,
Monster1AttackMultiplierDictionary = @Monster1AttackMultiplierDictionary,
Monster1DefenseRateictionary = @Monster1DefenseRateictionary,
Monster1DefenseRateDictionary = @Monster1DefenseRateDictionary,
Monster1SizeMultiplierDictionary = @Monster1SizeMultiplierDictionary,
Monster1StunThresholdDictionary = @Monster1StunThresholdDictionary,
Monster1PartThresholdDictionary = @Monster1PartThresholdDictionary WHERE
RunID = @RunID";
cmd2.Parameters.AddWithValue("@RunID", runID);
cmd2.Parameters.AddWithValue("@Monster1HPDictionary", newMonster1HPDictionary);
cmd2.Parameters.AddWithValue("@Monster1AttackMultiplierDictionary", newMonster1AttackMultiplierDictionary);
cmd2.Parameters.AddWithValue("@Monster1DefenseRateictionary", newMonster1DefenseRateDictionary);
cmd2.Parameters.AddWithValue("@Monster1SizeMultiplierDictionary", newMonster1SizeMultiplierDictionary);
cmd2.Parameters.AddWithValue("@Monster1StunThresholdDictionary", newMonster1StunThresholdDictionary);
cmd2.Parameters.AddWithValue("@Monster1PartThresholdDictionary", newMonster1PartThresholdDictionary);
cmd2.Parameters.AddWithValue("@Monster1HPDictionary", JsonConvert.SerializeObject(newMonster1HPDictionary));
cmd2.Parameters.AddWithValue("@Monster1AttackMultiplierDictionary", JsonConvert.SerializeObject(newMonster1AttackMultiplierDictionary));
cmd2.Parameters.AddWithValue("@Monster1DefenseRateDictionary", JsonConvert.SerializeObject(newMonster1DefenseRateDictionary));
cmd2.Parameters.AddWithValue("@Monster1SizeMultiplierDictionary", JsonConvert.SerializeObject(newMonster1SizeMultiplierDictionary));
cmd2.Parameters.AddWithValue("@Monster1StunThresholdDictionary", JsonConvert.SerializeObject(newMonster1StunThresholdDictionary));
cmd2.Parameters.AddWithValue("@Monster1PartThresholdDictionary", JsonConvert.SerializeObject(newMonster1PartThresholdDictionary));

cmd2.ExecuteNonQuery();
}
Expand Down
Loading

0 comments on commit a7def9e

Please sign in to comment.