Skip to content

Commit

Permalink
Support for client v2.1.0
Browse files Browse the repository at this point in the history
- Fixed broken deck editor screen
- Viewing deck mid duel (under settings menu)
- "Don't dismantle" deck editor feature
- "Boost generate" crafting changes
- Replay revamp
  • Loading branch information
pixeltris committed Nov 10, 2024
1 parent 16ccc0e commit 0f43379
Show file tree
Hide file tree
Showing 20 changed files with 723 additions and 187 deletions.
331 changes: 230 additions & 101 deletions Docs/ReflectionDump.json

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion Docs/updatediff.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Client version 2.0.0
// Client version 2.1.0
// This file is generated using the 'updatediff' command in YgoMasterClient. This information is used to determine changes between client versions which impact YgoMaster.
// Run the command, diff against the old file, and use the changes to update code.

This comment has been minimized.

Copy link
@MTHEKING69

MTHEKING69 Nov 15, 2024

This shit doesnt make any sense there are no instructions at all except run the command. I'm stupid and I need help

Expand Down Expand Up @@ -400,6 +400,7 @@ enum Category
WALLPAPER,
PACK_TICKET,
DECK_LIMIT,
REPLAY_LIMIT,
}
//==================================
// Duel.cs
Expand Down Expand Up @@ -831,6 +832,7 @@ enum DuelFinishType
Exodia3,
CiNo1000,
Sekitori,
Shukudai,
FinishError = 100,
FinishDisconnect,
FinishNoContest,
Expand Down Expand Up @@ -1368,6 +1370,7 @@ enum CraftCode
ERROR_CRAFT_LIMIT,
ERROR_UPDATE_FAILED,
ERROR_COMPENSATION_TIMELIMIT,
ERROR_BOOST_CRAFT_FAILED,
}
enum CupCode
{
Expand Down Expand Up @@ -1403,6 +1406,8 @@ enum DeckCode
CDB_SERVER_ERROR,
KONAMIID_SERVER_ERROR,
NEURON_MAINTENANCE,
NO_CONSTRUCT_DATA = 1460,
AUTO_CONSTRUCT_TIMEOUT,
}
enum DuelCode
{
Expand Down Expand Up @@ -1641,6 +1646,8 @@ enum PvPCode
VS_TEAM_DECIDED,
TEAM_MATCHING_CANCELED,
VS_TEAM_WAITING,
ERR_REPLAY_LOCK_MAX = 2150,
ERR_REPLAY_LOCK,
}
enum RankEventCode
{
Expand Down Expand Up @@ -1972,8 +1979,10 @@ enum WcsCode
//public static YgomSystem.Network.Handle Deck_set_select_deck(System.Int32 _mode_, System.Int32 _deck_id_)
//public static YgomSystem.Network.Handle Deck_CopyStructure(System.Int32 _structure_id_)
//public static YgomSystem.Network.Handle Deck_SetFavoriteCards(System.Collections.Generic.Dictionary<System.String,System.Object> _card_list_)
//public static YgomSystem.Network.Handle Deck_SetLockCards(System.Collections.Generic.Dictionary<System.String,System.Object> _card_list_)
//public static YgomSystem.Network.Handle Deck_ExportDeck(System.String _N_token_, System.Int32 _deck_id_)
//public static YgomSystem.Network.Handle Deck_GetAccessoryDetail()
//public static YgomSystem.Network.Handle Deck_get_auto_deck(System.Int32[] _card_ids_)
//public static YgomSystem.Network.Handle Download_begin()
//public static YgomSystem.Network.Handle Download_complete()
//public static YgomSystem.Network.Handle Download_progress(System.String _dl_end_)
Expand All @@ -1982,6 +1991,7 @@ enum WcsCode
//public static YgomSystem.Network.Handle Craft_generate(System.Int32 _card_id_)
//public static YgomSystem.Network.Handle Craft_generate_multi(System.Collections.Generic.Dictionary<System.String,System.Object> _card_list_, System.Boolean _check_)
//public static YgomSystem.Network.Handle Craft_get_card_route(System.Int32 _card_id_)
//public static YgomSystem.Network.Handle Craft_generate_boost(System.Int32 _card_id_, System.Int32 _premium_type_, System.Int32 _cost_cp_, System.Boolean _check_)
//public static YgomSystem.Network.Handle Friend_follow(System.Int64 _pcode_, System.Int32 _delete_)
//public static YgomSystem.Network.Handle Friend_set_pin(System.Int64 _pcode_, System.Int32 _delete_, System.Int32 _update_work_)
//public static YgomSystem.Network.Handle Friend_get_follower(System.Int64 _date_, System.Int64 _pcode_, System.Int32 _dir_)
Expand All @@ -1998,11 +2008,15 @@ enum WcsCode
//public static YgomSystem.Network.Handle PvP_watch_duel(System.Int64 _pcode_, System.Int64 _rapid_)
//public static YgomSystem.Network.Handle PvP_replay_duel(System.Int64 _pcode_, System.Int64 _did_)
//public static YgomSystem.Network.Handle PvP_save_replay(System.Int32 _mode_, System.Int64 _did_, System.Int32 _eid_)
//public static YgomSystem.Network.Handle PvP_save_replay_new(System.Int32 _mode_, System.Int64 _did_, System.Int32 _eid_, System.Boolean _open_)
//public static YgomSystem.Network.Handle PvP_remove_replay(System.Int64 _did_)
//public static YgomSystem.Network.Handle PvP_replay_duel_history(System.Int32 _idx_, System.Int32 _mode_, System.Int64 _did_, System.Int32 _eid_)
//public static YgomSystem.Network.Handle PvP_replay_duel_history_with_room(System.Int64 _did_, System.Int64 _pcode_)
//public static YgomSystem.Network.Handle PvP_duel_history(System.Int32 _mode_)
//public static YgomSystem.Network.Handle PvP_set_replay_open(System.Int64 _did_, System.Boolean _open_)
//public static YgomSystem.Network.Handle PvP_set_replay_lock(System.Int64 _did_, System.Boolean _lock_)
//public static YgomSystem.Network.Handle PvP_set_replay_tags(System.Int64 _did_, System.Int32[] _tags_)
//public static YgomSystem.Network.Handle PvP_set_replay_pick_cards(System.Int64 _did_, System.Int32 _myid_, System.Collections.Generic.Dictionary<System.String,System.Object> _pcards_)
//public static YgomSystem.Network.Handle PvP_get_history_deck(System.Int64 _did_, System.Int32 _mode_, System.Int32 _idx_)
//public static YgomSystem.Network.Handle PvP_get_replay_deck(System.Int64 _did_)
//public static YgomSystem.Network.Handle Structure_first(System.Int32 _structure_id_)
Expand Down
38 changes: 31 additions & 7 deletions YgoMasterClient/ConsoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ unsafe static void HandleCommand(string consoleInput)
{
bool.TryParse(splitted[1], out dumpInvalid);
}
Dictionary<YgomGame.Utility.ItemUtil.Category, List<string>> categories = new Dictionary<YgomGame.Utility.ItemUtil.Category, List<string>>();
Dictionary<ItemID.Category, List<string>> categories = new Dictionary<ItemID.Category, List<string>>();
IL2Class classInfo = classInfo = Assembler.GetAssembly("Assembly-CSharp").GetClass("IDS_ITEM", "YgomGame.TextIDs");
IL2Field[] fields = classInfo.GetFields();
foreach (IL2Field field in fields)
Expand All @@ -62,7 +62,7 @@ unsafe static void HandleCommand(string consoleInput)
{
continue;
}
YgomGame.Utility.ItemUtil.Category cat = YgomGame.Utility.ItemUtil.GetCategoryFromID(id);
ItemID.Category cat = YgomGame.Utility.ItemUtil.GetCategoryFromID(id);
if (!categories.ContainsKey(cat))
{
categories[cat] = new List<string>();
Expand All @@ -78,7 +78,7 @@ unsafe static void HandleCommand(string consoleInput)
}
StringBuilder res = new StringBuilder();
res.AppendLine("{");
foreach (KeyValuePair<YgomGame.Utility.ItemUtil.Category, List<string>> cat in categories.OrderBy(x => x.Key))
foreach (KeyValuePair<ItemID.Category, List<string>> cat in categories.OrderBy(x => x.Key))
{
res.AppendLine(" \"" + cat.Key + "\": [");
res.AppendLine(string.Join(Environment.NewLine, cat.Value));
Expand All @@ -91,7 +91,7 @@ unsafe static void HandleCommand(string consoleInput)
break;
case "itemid_enum":// Creates enums for values in IDS_ITEM (all item ids)
{
Dictionary<YgomGame.Utility.ItemUtil.Category, List<string>> categories = new Dictionary<YgomGame.Utility.ItemUtil.Category, List<string>>();
Dictionary<ItemID.Category, List<string>> categories = new Dictionary<ItemID.Category, List<string>>();
IL2Class classInfo = classInfo = Assembler.GetAssembly("Assembly-CSharp").GetClass("IDS_ITEM", "YgomGame.TextIDs");
IL2Field[] fields = classInfo.GetFields();
foreach (IL2Field field in fields)
Expand All @@ -101,7 +101,7 @@ unsafe static void HandleCommand(string consoleInput)
if (fieldName.StartsWith("ID") && int.TryParse(fieldName.Substring(2), out id))
{
string name = YgomGame.Utility.ItemUtil.GetItemName(id);
YgomGame.Utility.ItemUtil.Category cat = YgomGame.Utility.ItemUtil.GetCategoryFromID(id);
ItemID.Category cat = YgomGame.Utility.ItemUtil.GetCategoryFromID(id);
if (!categories.ContainsKey(cat))
{
categories[cat] = new List<string>();
Expand All @@ -113,7 +113,7 @@ unsafe static void HandleCommand(string consoleInput)
}
}
StringBuilder res = new StringBuilder();
foreach (KeyValuePair<YgomGame.Utility.ItemUtil.Category, List<string>> cat in categories)
foreach (KeyValuePair<ItemID.Category, List<string>> cat in categories)
{
res.AppendLine("public enum " + cat.Key + "{");
res.AppendLine(string.Join(Environment.NewLine, cat.Value));
Expand Down Expand Up @@ -1367,7 +1367,8 @@ unsafe static void HandleCommand(string consoleInput)
{ "p2_num", 0 }
};
}
Craft_generate_multi.Invoke(new IntPtr[] { YgomMiniJSON.Json.Deserialize(MiniJSON.Json.Serialize(cardListData)) });
csbool check = false;
Craft_generate_multi.Invoke(new IntPtr[] { YgomMiniJSON.Json.Deserialize(MiniJSON.Json.Serialize(cardListData)), new IntPtr(&check) });
}
break;
case "auto_free_pull":// Opens every pack with a free pull
Expand Down Expand Up @@ -1429,6 +1430,29 @@ unsafe static void HandleCommand(string consoleInput)
}).Start();
}
break;
case "card_base_data_size":// Get size of CardBaseData
{
IL2Assembly mscorlibAssembly = Assembler.GetAssembly("mscorlib");
IL2Method sizeOf = mscorlibAssembly.GetClass("Marshal").GetMethod("SizeOf", x => x.GetParameters().Length == 1);

IL2Assembly assembly2 = Assembler.GetAssembly("Assembly-CSharp");
IL2Class targetStruct = assembly2.GetClass("CardBaseData", "YgomGame.Deck");

Console.WriteLine("expected: " + sizeof(YgomGame.Deck.CardBaseData));
foreach (System.Reflection.FieldInfo field in typeof(YgomGame.Deck.CardBaseData).GetFields())
{
// https://stackoverflow.com/questions/30817924/obtain-non-explicit-field-offset/56512720#56512720
Console.WriteLine(field.Name + "=" + (Marshal.ReadInt32(field.FieldHandle.Value + (4 + IntPtr.Size)) & 0xFFFFFF));
}
Console.WriteLine();
int baseOffset = 0x10;// See IL2Object.GetValueRef
Console.WriteLine("sizeof(CardBaseData) = " + sizeOf.Invoke(new IntPtr[] { targetStruct.IL2Typeof() }).GetValueRef<int>());
foreach (IL2Field field in targetStruct.GetFields())
{
Console.WriteLine(field.Name + "=" + (field.Token - baseOffset));
}
}
break;
}
}

Expand Down
57 changes: 37 additions & 20 deletions YgoMasterClient/DeckEditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ unsafe static class DeckView
static IL2Field fieldMainCardDataList;
static IL2Field fieldExtraDeckCards;
static IL2Field fieldExtraCardDataList;
static IL2Method methodSetDismantleMode;
static IL2Method methodSetMode;
static IL2Method methodAddToMainDeckByID;
static IL2Method methodAddToExtraDeckByID;
static IL2Method methodRemoveCardFromMainOrExtra;
Expand All @@ -104,12 +104,22 @@ unsafe static class DeckView
delegate int Del_GetAddableType(IntPtr thisPtr, int cardID, int regulation);
static Hook<Del_GetAddableType> hookGetAddableType;

/// <summary>
/// DeckView.Mode
/// </summary>
enum Mode
{
Default,
Dismantle,
Lock
}

static DeckView()
{
IL2Assembly assembly = Assembler.GetAssembly("Assembly-CSharp");
IL2Class classInfo = assembly.GetClass("DeckView", "YgomGame.Deck");
hookGetAddableType = new Hook<Del_GetAddableType>(GetAddableType, classInfo.GetMethod("GetAddableType"));
methodSetDismantleMode = classInfo.GetMethod("SetDismantleMode");
methodSetMode = classInfo.GetMethod("SetMode");
methodAddToMainDeckByID = classInfo.GetMethod("AddToMainDeckByID");
methodAddToExtraDeckByID = classInfo.GetMethod("AddToExtraDeckByID");
methodRemoveCardFromMainOrExtra = classInfo.GetMethod("RemoveCardFromMainOrExtra");
Expand Down Expand Up @@ -137,30 +147,34 @@ static int GetAddableType(IntPtr thisPtr, int cardID, int regulation)
}
}

private static void SetMode(IntPtr thisPtr, Mode mode)
{
methodSetMode.Invoke(thisPtr, new IntPtr[] { new IntPtr(&mode) });
}

public static void AddCardWithSound(IntPtr thisPtr, int cardId, CardStyleRarity styleRarity, bool owned, bool mainDeck)
{
bool b = false;
methodSetDismantleMode.Invoke(thisPtr, new IntPtr[] { new IntPtr(&b) });
SetMode(thisPtr, Mode.Default);

IL2Method method = mainDeck ? methodAddToMainDeckByID : methodAddToExtraDeckByID;
int reg = 0;//?
int prem = (int)styleRarity;
bool sort = false;
bool isRental = false;//?
bool isAutoBuild = false;
bool isIni = false;//? isInitializeSelect?
bool noAdd = false;//?
method.Invoke(thisPtr, new IntPtr[]
{
new IntPtr(&cardId), new IntPtr(&prem), new IntPtr(&owned), new IntPtr(&isRental), new IntPtr(&reg), new IntPtr(&sort),
new IntPtr(&isIni), new IntPtr(&noAdd)
new IntPtr(&cardId), new IntPtr(&prem), new IntPtr(&owned), new IntPtr(&isRental),
new IntPtr(&isAutoBuild), new IntPtr(&reg), new IntPtr(&sort), new IntPtr(&isIni), new IntPtr(&noAdd)
});
YgomSystem.Sound.Play("SE_DECK_PLUS");
}

public static void RemoveCardWithSound(IntPtr thisPtr, int cardId, CardStyleRarity styleRarity, bool owned, bool mainDeck)
{
bool b = false;
methodSetDismantleMode.Invoke(thisPtr, new IntPtr[] { new IntPtr(&b) });
SetMode(thisPtr, Mode.Default);

CardBaseData cbd = new CardBaseData();
cbd.CardID = cardId;
Expand Down Expand Up @@ -188,8 +202,7 @@ public static void SetCards(IntPtr thisPtr, CardCollection mainDeck, CardCollect
{
// TODO: Look into ways of improving the performance of this

bool b = false;
methodSetDismantleMode.Invoke(thisPtr, new IntPtr[] { new IntPtr(&b) });
SetMode(thisPtr, Mode.Default);

IL2ListExplicit mainCardDataList = new IL2ListExplicit(fieldMainCardDataList.GetValue(thisPtr).ptr, cardBaseDataClassInfo);
IL2ListExplicit extraCardDataList = new IL2ListExplicit(fieldExtraCardDataList.GetValue(thisPtr).ptr, cardBaseDataClassInfo);
Expand Down Expand Up @@ -273,12 +286,13 @@ public static void SetCards(IntPtr thisPtr, CardCollection mainDeck, CardCollect
int reg = 0;//?
bool sort = false;
bool isRental = false;//?
bool isAutoBuild = false;
bool isIni = false;//? isInitializeSelect?
bool noAdd = false;//?
method.Invoke(thisPtr, new IntPtr[]
{
new IntPtr(&id), new IntPtr(&prem), new IntPtr(&owned), new IntPtr(&isRental), new IntPtr(&reg), new IntPtr(&sort),
new IntPtr(&isIni), new IntPtr(&noAdd)
new IntPtr(&id), new IntPtr(&prem), new IntPtr(&owned), new IntPtr(&isRental),
new IntPtr(&isAutoBuild), new IntPtr(&reg), new IntPtr(&sort), new IntPtr(&isIni), new IntPtr(&noAdd)
});
}
}
Expand Down Expand Up @@ -333,21 +347,24 @@ public static CardBaseData GetBaseData(IntPtr thisPtr)
}
}

//sizeof(CardBaseData) = 32 (0x20) - v2.1.0 (use client console command "card_base_data_size" when updating this struct)
[StructLayout(LayoutKind.Sequential)]
struct CardBaseData
{
public int CardID;
public int PremiumID;
public bool IsOwned;
public int Obtained;
public int Inventory;
public int Rarity;
public bool IsRental;
public int CardID;//0x0
public int PremiumID;//0x4
public bool IsOwned;//0x8
public int Obtained;//0xC
public int Inventory;//0x10
public int Rarity;//0x14
public csbool IsRental;//0x18
public csbool IsAutoBuild;//0x19 v2.1.0
private int padding;

public override string ToString()
{
return "cid:" + CardID + " pid:" + PremiumID + " owned:" + IsOwned + " obtained:" + Obtained + " inv:" + Inventory +
" rarity:" + Rarity + " rental:" + IsRental;
" rarity:" + Rarity + " rental:" + IsRental + " autobuild:" + IsAutoBuild;
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions YgoMasterClient/DuelReplayUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ unsafe static class ProfileReplayViewController
delegate void Del_OnItemSetData(IntPtr thisPtr, int res);
static Hook<Del_OnItemSetData> hookOnItemSetData_1;
static Hook<Del_OnItemSetData> hookOnItemSetData_2;
static Hook<Del_OnItemSetData> hookOnItemSetData_3;
static Hook<Del_OnItemSetData>[] hooks = new Hook<Del_OnItemSetData>[3];
static Hook<Del_OnItemSetData>[] hooks = new Hook<Del_OnItemSetData>[2];

static IL2Field fieldDataIndex;

Expand All @@ -113,9 +112,8 @@ static ProfileReplayViewController()
IL2Class classInfo = assembly.GetClass("ProfileReplayViewController", "YgomGame.Menu");
hookOnCreatedView = new Hook<Del_OnCreatedView>(OnCreatedView, classInfo.GetMethod("OnCreatedView"));

FindOnItemSetDataMethod(classInfo, "<OnItemSetData>b__1", ref hookOnItemSetData_1, 0);
FindOnItemSetDataMethod(classInfo, "<OnItemSetData>b__2", ref hookOnItemSetData_2, 1);
FindOnItemSetDataMethod(classInfo, "<OnItemSetData>b__3", ref hookOnItemSetData_3, 2);
FindOnItemSetDataMethod(classInfo, "<OnItemSetData>b__0", ref hookOnItemSetData_1, 0);
FindOnItemSetDataMethod(classInfo, "<OnItemSetData>b__1", ref hookOnItemSetData_2, 1);
}

static void FindOnItemSetDataMethod(IL2Class classInfo, string name, ref Hook<Del_OnItemSetData> hook, int i)
Expand Down
2 changes: 1 addition & 1 deletion YgoMasterClient/IL2CPP/ReflectionValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static string GetSignature(IL2Field field)
{
sig.Append("static ");
}
sig.Append(field.ReflectedType.Name);
sig.Append(field.Name);
return sig.ToString();
}

Expand Down
Loading

0 comments on commit 0f43379

Please sign in to comment.