public static void Postfix(GearItem __instance) { //Logger.Log("Deserialize start"); //UnhollowerBaseLib.Il2CppReferenceArray<UnityEngine.Component> components = __instance.GetComponents(UnhollowerRuntimeLib.Il2CppType.Of<UnityEngine.Component>()); UnhollowerBaseLib.Il2CppArrayBase <UnityEngine.Component> components = __instance.GetComponents <UnityEngine.Component>(); //UnhollowerBaseLib.Il2CppArrayBase<ModSaveBehaviour> modSaveComponents = __instance.GetComponents<ModSaveBehaviour>(); foreach (UnityEngine.Component component in components) //foreach (ModSaveBehaviour modSaveBehaviour in modSaveComponents) { ModSaveBehaviour modSaveBehaviour = component.TryCast <ModSaveBehaviour>(); if (modSaveBehaviour is null) { continue; } //Logger.Log("Found ModSaveBaviour"); try { string data = SaveDataManager.GetSaveData(__instance.m_InstanceID, modSaveBehaviour.GetType()); //if (data is null) Logger.Log("Null save data for {0} of type {1}", modSaveBehaviour.name, modSaveBehaviour.GetType().ToString()); //if (!string.IsNullOrEmpty(data)) Logger.Log(data); modSaveBehaviour.Deserialize(data); //Logger.Log("Deserialized custom save data for {0} of type {1}", modSaveBehaviour.name, modSaveBehaviour.GetType().ToString()); } catch (System.Exception e) { Logger.Log("Deserializing custom save data for item {0} failed: {1}.", __instance.name, e.Message); } } /*ModSaveBehaviour modSaveBehaviour = __instance.GetComponent<ModSaveBehaviour>(); * if (modSaveBehaviour is null) * { * return; * } * * try * { * string data = SaveDataManager.GetSaveData(__instance.m_InstanceID, modSaveBehaviour.GetType()); * if (data is null) Logger.Log("Null save data for {0} of type {1}", modSaveBehaviour.name, modSaveBehaviour.GetType().ToString()); * if (!string.IsNullOrEmpty(data)) Logger.Log(data); * modSaveBehaviour.Deserialize(data); * Logger.Log("Deserialized custom save data for {0} of type {1}",modSaveBehaviour.name, modSaveBehaviour.GetType().ToString()); * } * catch (System.Exception e) * { * Logger.Log("Deserializing custom save data for item {0} failed: {1}.", __instance.name, e.Message); * }*/ //Logger.Log("Deserialize End"); }
public static void Postfix(GearItem __instance) { ModSaveBehaviour modSaveBehaviour = __instance.GetComponent <ModSaveBehaviour>(); if (modSaveBehaviour == null) { return; } try { string data = SaveDataManager.GetSaveData(__instance.m_InstanceID, modSaveBehaviour.GetType()); modSaveBehaviour.Deserialize(data); } catch (System.Exception e) { Implementation.Log("Deserializing custom save data for item {0} failed: {1}.", __instance.name, e.Message); } }