Skip to content

Commit

Permalink
Fix custom shop text #218
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltris committed Aug 11, 2023
1 parent 7b5c6da commit 07e1dd5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions YgoMasterClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,10 @@ unsafe static class TextData

delegate IntPtr Del_GetTextString(IntPtr textEnum, bool richTextEx);
delegate IntPtr Del_GetTextEnum(int textEnum, bool richTextEx, IntPtr methodInstance);
delegate csbool Del_ParseTextId(IntPtr fullTextId, IntPtr groupId, IntPtr textId);
static Hook<Del_GetTextString> hookGetTextString;
static Hook<Del_GetTextEnum> hookGetTextEnum;
static Hook<Del_ParseTextId> hookParseTextId;

public static Dictionary<string, string> CustomTextData = new Dictionary<string, string>();

Expand All @@ -1103,6 +1105,7 @@ static TextData()
hookGetTextString = new Hook<Del_GetTextString>(GetTextString, methodGetTextString);
methodGetTextEnum = classInfo.GetMethod("GetText").MakeGenericMethod(new IntPtr[] { CastUtils.IL2Typeof("Int32Enum", "System", "mscorlib") });
hookGetTextEnum = new Hook<Del_GetTextEnum>(GetTextEnum, methodGetTextEnum);
hookParseTextId = new Hook<Del_ParseTextId>(ParseTextId, classInfo.GetMethod("ParseTextId"));

// System.Object.ToString
methodObjectToString = Assembler.GetAssembly("mscorlib").GetClass("Object", "System").GetMethod("ToString");
Expand Down Expand Up @@ -1161,6 +1164,26 @@ public static string GetText(string id)
return new IL2String(GetTextString(new IL2String(id).ptr, false)).ToString();
}

static csbool ParseTextId(IntPtr textString, IntPtr groupId, IntPtr textId)
{
string inputString = new IL2Object(textString).GetValueObj<string>();
csbool result = hookParseTextId.Original(textString, groupId, textId);
string groupIdString = new IL2Object(Marshal.ReadIntPtr(groupId)).GetValueObj<string>();
string textIdString = new IL2Object(Marshal.ReadIntPtr(textId)).GetValueObj<string>();
//Console.WriteLine("ParseTextId " + inputString + " error:" + result + " groupId:" + groupIdString + " textId:" + textIdString);
if (!string.IsNullOrEmpty(inputString) && inputString.StartsWith(HackID))
{
// Hacky fix for card packs. They seem to be sanitizing these for some reason (but only for card packs)
// We might need to do something smarter if they add additional checks for other types of custom strings
// - PvP infinite time
// - Pack descriptions
// - Solo gate text and chapter text
Marshal.WriteIntPtr(textId, new IL2String("ID3001_NAME").ptr);
Marshal.WriteIntPtr(groupId, new IL2String("CARDPACK").ptr);
}
return result;
}

static IntPtr GetTextString(IntPtr textString, bool richTextEx)
{
string inputString = new IL2Object(textString).GetValueObj<string>();
Expand Down
2 changes: 1 addition & 1 deletion YgoMasterServer/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public static bool TryGetValue<T>(Dictionary<string, object> values, string key,
}
catch
{
System.Diagnostics.Debugger.Break();
//System.Diagnostics.Debugger.Break();
}
}
result = default(T);
Expand Down

0 comments on commit 07e1dd5

Please sign in to comment.