private static bool Postfix(bool __result, ComputerSave save, PartDesc.Type ___m_partType, string ___m_refPart, int ___m_totalPartsOfType) { if (ConfigHandler.Instance.UpgradePriceCheckRemoveBool.Value) { if (___m_partType == PartDesc.Type.MOTHERBOARD || ___m_partType == PartDesc.Type.AIR_COOLER || ___m_partType == PartDesc.Type.LIQUID_COOLER) { var successfulPartChanges = 0; foreach (var partInstance in save.GetAllParts()) { if (partInstance != null && partInstance.IsActive()) { PartDesc refPart = PartsDatabase.GetDesc(___m_refPart); var canUpgrade = partInstance.GetPart().MatchForUpgrade(refPart.m_type); SFLog.log($"{partInstance.GetPart().m_partName} | canUpgrade: {canUpgrade.ToString()}"); if (canUpgrade) { successfulPartChanges++; } } } var cond = ___m_totalPartsOfType == successfulPartChanges; SFLog.log($"totalPartsOfType: {___m_totalPartsOfType.ToString()}, successfulPartChanges: {successfulPartChanges.ToString()}, satisfied: {cond.ToString()}"); return(cond); } } return(__result); }
public static void Postfix(PartInstance __instance, ref bool __result) { if (__result) { PartsDatabase pdb = Traverse.Create <PartsDatabase>().Field("s_instance").GetValue <PartsDatabase>(); if (!pdb.m_parts.ContainsKey(__instance.GetPartId())) { logger.LogInfo(__instance.GetPartId() + "在数据库中不存在,将进行移除"); __result = false; } } }
public static void Postfix(PartsDatabase __instance) { List <OSProgramDesc> list = new List <OSProgramDesc>(); foreach (var prog in PartsDatabase.GetAllPrograms()) { list.Add(prog); } foreach (var prog in ProgramList) { list.Add(prog); } Traverse.Create(__instance).Field <OSProgramDesc[]>("m_programs").Value = list.ToArray(); }
internal void UpdatePrograms() // TODO check how OS/Desktop does this in PCBS and adapt accordingly or call directly if at all possible { foreach (ProgramIcon programIcon in os.transform.GetComponentsInChildren <ProgramIcon>()) { if (programIcon.transform.parent == os.transform) { programIcon.transform.parent = null; UnityEngine.Object.Destroy(programIcon); } } string[] programsInstalled = ReflectionUtils.Get <string[]>("m_programsInstalled", os); List <ProgramIcon> programIcons = ReflectionUtils.Get <List <ProgramIcon> >("m_icons", os); programIcons.Clear(); float num = 100f; Rect rect = (os.transform as RectTransform).rect; var spacing = 100f; float num2 = rect.height - spacing; foreach (OSProgramDesc program in PartsDatabase.GetAllPrograms()) { if (Array.Find <string>(programsInstalled, (string p) => p == program.m_id) != null) { ProgramIcon programIcon2 = UnityEngine.Object.Instantiate <ProgramIcon>(os.m_programIconPrefab); programIcon2.Init(program, false, null); programIcon2.transform.SetParent(os.transform, false); programIcon2.transform.localPosition = new Vector3(num, num2); programIcons.Add(programIcon2); num2 -= spacing; if (num2 - spacing < 0f) { num += spacing; num2 = rect.height - spacing; } } } }
public static void Postfix(PartsDatabase __instance, TextAsset asset) { HTMLTableReader htmltableReader = new HTMLTableReader(asset); DirectoryInfo dir = new DirectoryInfo(Paths.GameRootPath + "/CustomPart/" + asset.name); if (!dir.Exists) { dir.Create(); //创建文件夹 } else { //获取文件 var files = dir.GetFiles("*.txt", SearchOption.AllDirectories); foreach (var file in files) { var lines = File.ReadAllLines(file.FullName); if (lines.Length > 0) { Dictionary <string, string> partData = new Dictionary <string, string>(); foreach (var line in lines) { //切割key value var kv = line.Split('='); if (kv.Length > 1 && !string.IsNullOrEmpty(kv[0])) { partData.Add(kv[0], kv[1]); } } //判断Part Type if (!partData.ContainsKey("Part Type")) { logger.LogError(file.FullName + " 没有Part Type数据"); } //判断InGame if (!partData.ContainsKey("In Game")) { logger.LogError(file.FullName + " 没有In Game数据"); } else { //判断InGame Yes 或者 No if (partData["In Game"] == "Yes" || partData["In Game"] == "No") { PartDesc partDesc = PartDesc.Create(partData["Part Type"], new GetString(htmltableReader.Describe)); foreach (var key in partData.Keys) { try { //导入数据 partDesc.ImportProp(key, partData[key], new GetString(htmltableReader.Describe)); } catch (System.Exception e) { logger.LogError(htmltableReader.Describe() + ": " + e.ToString()); } } //判断id if (partDesc.m_id == null) { logger.LogError(file.FullName + " 的ID为空"); } if (__instance.m_parts.ContainsKey(partDesc.m_id)) { logger.LogError(file.FullName + " 的ID已经存在"); } __instance.m_parts[partDesc.m_id] = partDesc; } else { logger.LogWarning(file.FullName + " 的In Game数据不为Yes 或者 No"); } } } } } }
static void Postfix(AddProgramApp __instance) { foreach (object o in __instance.m_programList.content) { UnityEngine.Object.Destroy(((Transform)o).gameObject); } ComputerSave computer = __instance.GetComponentInParent <VirtualComputer>().GetComputer(); bool isUsbDriveInserted = computer.IsUSBDriveInserted(); if (!isUsbDriveInserted) { WorkStation componentInParent = __instance.GetComponentInParent <WorkStation>(); if (componentInParent && componentInParent.m_slot && componentInParent.m_slot.m_type == BenchSlot.Type.SHOP_COMPUTER) { isUsbDriveInserted = true; } } if (AddProgramAppLogic.InstanceFor(__instance).addMode == 1) { if (!isUsbDriveInserted) { ReflectionUtils.Run("SetMessage", __instance, new object[] { ScriptLocalization.AddPrograms.INSERT_USB }); return; } foreach (OSProgramDesc prog in PartsDatabase.GetAllPrograms()) { if (CareerStatus.Get().IsProgramAvailableForInstall(prog.m_id)) { UnityEngine.Object.Instantiate <ProgramIcon>(__instance.programIconPrefab, __instance.m_programList.content).Init(prog, false, delegate { __instance.GetComponentInParent <OS>().Launch(prog); }); } } return; } if (AddProgramAppLogic.InstanceFor(__instance).addMode == 2) { if (!isUsbDriveInserted) { ReflectionUtils.Run("SetMessage", __instance, new object[] { ScriptLocalization.AddPrograms.INSERT_USB }); return; } bool programsMissing = false; foreach (OSProgramDesc prog in PartsDatabase.GetAllPrograms()) { if (!computer.m_software.m_programs.Contains(prog.m_id) && CareerStatus.Get().IsProgramAvailableForInstall(prog.m_id)) { UnityEngine.Object.Instantiate <ProgramIcon>(__instance.programIconPrefab, __instance.m_programList.content).Init(prog, false, delegate { __instance.StartCoroutine(ReflectionUtils.Run <IEnumerator>("Install", __instance, new object[] { prog })); }); programsMissing = true; } } if (!programsMissing) { ReflectionUtils.Run("SetMessage", __instance, new object[] { ScriptLocalization.AddPrograms.ALL_INSTALLED }); return; } } else if (AddProgramAppLogic.InstanceFor(__instance).addMode == 3) { bool uninstallablePrograms = false; foreach (OSProgramDesc prog in PartsDatabase.GetAllPrograms()) { if (prog.m_canBeUninstalled && computer.m_software.m_programs.Contains(prog.m_id)) { UnityEngine.Object.Instantiate <ProgramIcon>(__instance.programIconPrefab, __instance.m_programList.content).Init(prog, false, delegate { __instance.StartCoroutine(ReflectionUtils.Run <IEnumerator>("Uninstall", __instance, new object[] { prog })); }); uninstallablePrograms = true; } } if (!uninstallablePrograms) { ReflectionUtils.Run("SetMessage", __instance, new object[] { ScriptLocalization.AddPrograms.NONE_INSTALLED }); } } }