Skip to content

Commit

Permalink
Modified tools to work with Link Evolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneff committed Mar 31, 2020
1 parent 7f1761b commit b15d72a
Show file tree
Hide file tree
Showing 9 changed files with 10,296 additions and 62 deletions.
6 changes: 3 additions & 3 deletions YGOLOTDPatchDraft/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace YGOPRODraft
{
public class Constants
{
public String LOTD_DAT_FILENAME = "YGO_DATA.dat";
public String LOTD_TOC_FILENAME = "YGO_DATA.toc";
public String LOTD_DAT_FILENAME = "YGO_2020.dat";
public String LOTD_TOC_FILENAME = "YGO_2020.toc";
public String LOTD_SAVE_FILENAME = "savegame.dat";
public String CSV_MAP_FILENAME = "card_map.csv";
public String CSV_MAP_FILENAME = "card_map_2020.csv";
public String CARD_DB_FILENAME = "cards.cdb";
public String BATTLEPACK_1_FILENAME = "bpack_BattlePack1.bin";
public String YGODATA_PACKS = "packs.zib";
Expand Down
8 changes: 7 additions & 1 deletion YGOLOTDPatchDraft/FileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ public static List<YGOPROCard> cardsFromJSON(string JSONFileName, string card_db

foreach (YGOPROCard card_obj in cards)
{
if(card_obj.m_rarity == null)
{
card_obj.m_rarity = "Common";
}

if (card_obj.m_rarity.ToLower().Contains("common"))
{
rarity_adjusted_cards.Add(card_obj);
Expand Down Expand Up @@ -490,7 +495,8 @@ public static List<List<YGOPROCard>> YDCToYGOPRODeck(byte[] ydc_binary, Dictiona
try
{
//cards[deck_index].Add()
card_names.Add(LOTD_ID_to_card_name[Reader.ReadInt16().ToString()]);
int reader_val = Reader.ReadInt16();
card_names.Add(LOTD_ID_to_card_name[reader_val.ToString()]);
}
catch (Exception ex)
{
Expand Down
5 changes: 5 additions & 0 deletions YGOLOTDPatchDraft/Notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ PACK HEADER:
length x 2 byte cards -> card IDs (same as used on the official yugioh database)

You can extend those files past their initial size without issues.


about cards that are not available -> can extract them from card names bin files...

need to use a different API for scraping the card_map.csv now. Should modify the script to only re-scrape the things that are either 65535 or simply not there
4 changes: 2 additions & 2 deletions YGOLOTDPatchDraft/Wolf/Onomatopaira.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static string ExtractYGODATA(YGOPRODraft.Constants strings)
{
var DatReader = new BinaryReader(File.Open(Path.Combine(Properties.Settings.Default.LOTDPath, strings.LOTD_DAT_FILENAME), FileMode.Open));
Reader.ReadLine(); //Dispose First Line.

char[] delim = new char[] { ' ' };
while (!Reader.EndOfStream)
{
var Line = Reader.ReadLine();
Expand All @@ -29,7 +29,7 @@ public static string ExtractYGODATA(YGOPRODraft.Constants strings)
Line = Line.TrimStart(' '); //Trim Starting Spaces.
Line = Regex.Replace(Line, @" +", " ",
RegexOptions.Compiled); //Remove All Extra Spaces.
var LineData = Line.Split(' '); //Split Into Chunks.
var LineData = Line.Split(delim, 3); //Split Into Chunks.

//Utilities.Log($"Extracting File: {new FileInfo(LineData[2]).Name} ({LineData[0]} Bytes)", Utilities.Event.Information);

Expand Down
38 changes: 6 additions & 32 deletions YGOLOTDPatchDraft/Wolf/Relinquished.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,11 @@ private static string UnpackZib(string zib_path, string old_zib_path)

switch (ZibFileName)
{
case "cardcropHD400.jpg.zib":
OffsetReadSize = 8;
SizeReadSize = 8;
FileNameReadSize = 48;
DataStartOffset = 0x69F10;
break;

case "cardcropHD401.jpg.zib":
OffsetReadSize = 8;
SizeReadSize = 8;
FileNameReadSize = 48;
DataStartOffset = 0xC810;
break;

case "busts.zib":
OffsetReadSize = 4;
SizeReadSize = 4;
FileNameReadSize = 56;
DataStartOffset = 0x2390;
break;

case "decks.zib":
OffsetReadSize = 4;
SizeReadSize = 4;
FileNameReadSize = 56;
DataStartOffset = 0x8650;
DataStartOffset = 0xB1D0;
break;

case "packs.zib":
Expand All @@ -90,24 +69,19 @@ private static string UnpackZib(string zib_path, string old_zib_path)

CurrentChunk = CurrentChunk.Skip(SizeReadSize).ToArray();
var CurrentFileName = Utilities.GetText(CurrentChunk.Take(FileNameReadSize).ToArray());

//Start Offset Is WRONG In ZIB For Some Reason, or maybe I am...
if (CurrentFileName == "adriangecko_neutral.png")
CurrentStartOffset = 0x2390;

//This also seems to be wrong in the decks zib file.

if (CurrentFileName == "1classic_01a_yugimuto.ydc")
CurrentStartOffset = 0x8650;


//This also seems to be wrong in the packs zib file.
CurrentStartOffset = 0xB1D0;

if (CurrentFileName == "bpack_BattlePack1.bin")
CurrentStartOffset = 0x750;

//Utilities.Log($"Exporting {CurrentFileName} ({CurrentFileSize} Bytes)", Utilities.Event.Information);

var SnapBack = Reader.BaseStream.Position;
Reader.BaseStream.Position = CurrentStartOffset;

System.Console.WriteLine("Current zib path: " + $"{zib_path}/" + CurrentFileName);
using (var Writer = new BinaryWriter(File.Open($"{zib_path}/" + CurrentFileName, FileMode.Create, FileAccess.Write)))
{
Writer.Write(Reader.ReadBytes(CurrentFileSize));
Expand Down
7 changes: 4 additions & 3 deletions YGOLOTDPatchDraft/Wolf/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ public static List<FileNames> ParseTocFile(string toc_file)
Reader = new StreamReader(toc_file);

Reader.ReadLine(); //Dispose First Line.
while (!Reader.EndOfStream)
char[] delim = new char[] { ' ' };
while (!Reader.EndOfStream)
{
var Line = Reader.ReadLine();
if (Line == null) continue;

Line = Line.TrimStart(' '); //Trim Starting Spaces.
Line = Regex.Replace(Line, @" +", " ", RegexOptions.Compiled); //Remove All Extra Spaces.
var LineData = Line.Split(' '); //Split Into Chunks.
LocalVarFiles.Add(new FileNames(LineData[2])); //Add To List For Manip.
var LineData = Line.Split(delim, 3); //Split Into Chunks.
LocalVarFiles.Add(new FileNames(LineData[2])); //Add To List For Manip.
}
Reader.Close();
return LocalVarFiles;
Expand Down
26 changes: 8 additions & 18 deletions YGOLOTDPatchDraft/YGOLOTDPatchDraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ private void btnPatchBattlePack_Click(object sender, EventArgs e)
string[] files = Directory.GetFiles(CONSTANTS.ADD_PACKS_FOLDER);
List<List<YGOPROCard>> list_of_card_lists = new List<List<YGOPROCard>>();

var card_name_to_LOTD_ID = FileUtilities.GetCardIDToLOTDMapFromCSV(CONSTANTS.CSV_MAP_FILENAME);
var LOTD_ID_to_card_name = FileUtilities.ReverseDict(card_name_to_LOTD_ID);

foreach (string filename in files)
{
if (ChosenPacks[filename.Split('\\')[1]] == false)
Expand All @@ -283,8 +286,7 @@ private void btnPatchBattlePack_Click(object sender, EventArgs e)
try
{
byte[] ydc_binary = FileUtilities.parseCardListMainExtraSideFromYDCFile(filename);
var list_of_main_extra_side = FileUtilities.YDCToYGOPRODeck(ydc_binary,
FileUtilities.ReverseDict(FileUtilities.GetCardIDToLOTDMapFromCSV(CONSTANTS.CSV_MAP_FILENAME)),
var list_of_main_extra_side = FileUtilities.YDCToYGOPRODeck(ydc_binary, LOTD_ID_to_card_name,
CONSTANTS.CARD_DB_FILENAME);
foreach (var deck in list_of_main_extra_side)
{
Expand Down Expand Up @@ -312,7 +314,6 @@ private void btnPatchBattlePack_Click(object sender, EventArgs e)
return;
}

var card_name_to_LOTD_ID = FileUtilities.GetCardIDToLOTDMapFromCSV(CONSTANTS.CSV_MAP_FILENAME);

LogOut(FileUtilities.WriteBattlePackBinFile(Path.Combine(CONSTANTS.PATCHED_YGODATA_OUT_FOLDER, CONSTANTS.BATTLEPACK_1_FILENAME),
CONSTANTS.BATTLEPACK_NUM_CATEGORIES, list_of_card_lists, card_name_to_LOTD_ID));
Expand Down Expand Up @@ -398,7 +399,7 @@ private void CheckSettings()
//Path is wrong or not set, ask for re-enter
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.SelectedPath = Environment.CurrentDirectory;
fbd.Description = "Choose your Yu-Gi-Oh: Legacy of the Duelist installation path! (Contains YuGiOh.exe, YGO_DATA.dat and YGO_DATA.toc)";
fbd.Description = "Choose your Yu-Gi-Oh: Legacy of the Duelist Link Evolution installation path! (Contains YuGiOh.exe, YGO_2020.dat and YGO_2020.toc)";
fbd.ShowDialog();
programSettings.LOTDPath = fbd.SelectedPath;
if (programSettings.LOTDPath == ""
Expand Down Expand Up @@ -434,7 +435,7 @@ private void CheckSettings()
}
else
{
LogOut("card_map.csv found!");
LogOut(CONSTANTS.CSV_MAP_FILENAME + " found!");
}

//Check if cards.cdb is there
Expand All @@ -445,20 +446,9 @@ private void CheckSettings()
}
else
{
LogOut("cards.cdb found!");
LogOut(CONSTANTS.CARD_DB_FILENAME + " found!");
}

//Check if cards_not_available is there
if (!CheckPathContainsFile("", CONSTANTS.CARDS_NOT_AVAILABLE))
{
MessageBox.Show("Error: " + CONSTANTS.CARDS_NOT_AVAILABLE + " is missing, but we definitely need that or the game breaks with those cards :(\nRedownload this tool, as that file should come with it!");
Application.Exit();
}
else
{
LogOut("card_map.csv found!");
}


//Check if PUT_YOUR_DECKS_HERE folder is there, otherwise create it
if (!Directory.Exists(CONSTANTS.ADD_PACKS_FOLDER))
{
Expand Down
98 changes: 95 additions & 3 deletions YGOLOTDPatchDraft/YGOPROCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class YGOPROCard
public String m_card_race;
public String m_card_type;
public Rectangle m_drawing_rect;
public String m_rarity;
public String m_rarity = "Common";
public int m_ygopro_id;

#endregion Public Fields
Expand Down Expand Up @@ -179,10 +179,12 @@ public static List<YGOPROCard> query_ygopro_ids(List<YGOJSONStruct> json_list, S
{
}

var card_list = QueryFromIDList(ids, ygopro_path);

for (int idx = 0; idx < ids.Count; idx++)
{
int id = ids[idx];
YGOPROCard card = QueryFromID(id, ygopro_path);
YGOPROCard card = card_list[idx];
YGOJSONStruct json_struct = json_list[idx];
card.m_rarity = json_struct.rarity;
cards.Add(card);
Expand Down Expand Up @@ -232,6 +234,7 @@ public static List<YGOPROCard> query_ygopro_ids_from_names(List<string> card_nam
}
catch
{
System.Console.WriteLine("Error: couldn't find " + new_name + " in YGOPRO database!");
}
}
}
Expand All @@ -241,16 +244,105 @@ public static List<YGOPROCard> query_ygopro_ids_from_names(List<string> card_nam
{
}

var card_list = QueryFromIDList(ids, ygopro_path);

for (int idx = 0; idx < ids.Count; idx++)
{
int id = ids[idx];
YGOPROCard card = QueryFromID(id, ygopro_path);
YGOPROCard card = card_list[idx];
cards.Add(card);
}

return cards;
}

public static List<YGOPROCard> QueryFromIDList(List<int> ids, String ygopro_path)
{
List<YGOPROCard> ret_list = new List<YGOPROCard>();

try
{
using (SQLiteConnection connect = new SQLiteConnection("Data Source=" + ygopro_path))
{
connect.Open();

foreach (var id in ids)
{
YGOPROCard ret_card = new YGOPROCard();
ret_card.m_ygopro_id = id;

using (SQLiteCommand fmd = connect.CreateCommand())
{
fmd.CommandText = "SELECT name, desc from texts where id = " + id;
fmd.CommandType = CommandType.Text;

SQLiteDataReader r = fmd.ExecuteReader();
try
{
if (r.Read())
{
ret_card.m_card_name = r.GetString(0);
ret_card.m_card_desc = r.GetString(1);
}
}
catch
{
}
}

using (SQLiteCommand fmd = connect.CreateCommand())
{
fmd.CommandText = "SELECT type, atk, def, level, race, attribute from datas where id = " + id;
fmd.CommandType = CommandType.Text;

SQLiteDataReader r = fmd.ExecuteReader();
try
{
if (r.Read())
{
if (CARD_TYPE_MAP.ContainsKey(r.GetInt32(0)))
ret_card.m_card_type = CARD_TYPE_MAP[r.GetInt32(0)];
else
ret_card.m_card_type = "UNKNOWN";

ret_card.m_card_atk = r.GetInt32(1);
ret_card.m_card_def = r.GetInt32(2);
ret_card.m_card_level = r.GetInt32(3);
int test = r.GetInt32(0);
ret_card.m_card_extra = (r.GetInt32(0) & YGOPROCard.ygoproIsExtraDeck) > 1;
if (CARD_RACE_MAP.ContainsKey(r.GetInt32(4)))
ret_card.m_card_race = CARD_RACE_MAP[r.GetInt32(4)];
else
ret_card.m_card_race = "UNKNOWN";

if (CARD_ATTR_MAP.ContainsKey(r.GetInt32(5)))
ret_card.m_card_attr = CARD_ATTR_MAP[r.GetInt32(5)];
else
ret_card.m_card_attr = "UNKNOWN";
}
}
catch
{
}
}

ret_list.Add(ret_card);
}


}
}
catch
{
}

//get img from ygopro path
//String trimmed = ygopro_path.TrimEnd("cards.cdb".ToCharArray());
//ret_card.m_card_image = Image.FromFile(trimmed +"\\pics\\" + id.ToString() + ".jpg");

return ret_list;
}

public static YGOPROCard QueryFromID(int id, String ygopro_path)
{
YGOPROCard ret_card = new YGOPROCard();
Expand Down
Loading

0 comments on commit b15d72a

Please sign in to comment.